Skip to content

Commit

Permalink
Import: Simplify handling of Resource_FormatType
Browse files Browse the repository at this point in the history
The type Resource_FormatType already exists since 2015. So, its usage doesn't require pre-processor macros everywhere.
  • Loading branch information
wwmayer authored and chennes committed Jun 19, 2024
1 parent b38f62f commit e804320
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 70 deletions.
7 changes: 0 additions & 7 deletions src/Mod/Import/App/AppImportPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,9 @@ class Module: public Py::ExtensionModule<Module>
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);

if (file.hasExtension({"stp", "step"})) {
#if OCC_VERSION_HEX >= 0x070800
Resource_FormatType cp = Resource_FormatType_UTF8;
#endif
try {
Import::ReaderStep reader(file);
#if OCC_VERSION_HEX < 0x070800
reader.read(hDoc);
#else
reader.read(hDoc, cp);
#endif
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
Expand Down
10 changes: 5 additions & 5 deletions src/Mod/Import/App/ReaderStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ using namespace Import;

ReaderStep::ReaderStep(const Base::FileInfo& file) // NOLINT
: file {file}
{}
{
#if OCC_VERSION_HEX >= 0x070800
codePage = Resource_FormatType_UTF8;
#endif
}

#if OCC_VERSION_HEX < 0x070800
void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT
#else
void ReaderStep::read(Handle(TDocStd_Document) hDoc, Resource_FormatType codePage) // NOLINT
#endif
{
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
Expand Down
10 changes: 6 additions & 4 deletions src/Mod/Import/App/ReaderStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <Mod/Import/ImportGlobal.h>
#include <Base/FileInfo.h>
#include <Resource_FormatType.hxx>
#include <TDocStd_Document.hxx>
#include <StepData_StepModel.hxx>
#include <Standard_Version.hxx>
Expand All @@ -37,14 +38,15 @@ class ImportExport ReaderStep
{
public:
explicit ReaderStep(const Base::FileInfo& file);
#if OCC_VERSION_HEX < 0x070800
void setCodePage(Resource_FormatType cp)
{
codePage = cp;
}
void read(Handle(TDocStd_Document) hDoc);
#else
void read(Handle(TDocStd_Document) hDoc, Resource_FormatType codePage);
#endif

private:
Base::FileInfo file;
Resource_FormatType codePage {};
};

} // namespace Import
Expand Down
15 changes: 5 additions & 10 deletions src/Mod/Import/Gui/AppImportGuiPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ class Module: public Py::ExtensionModule<Module>
if (options.hasKey("mode")) {
ocaf.setMode(static_cast<int>(Py::Long(options.getItem("mode"))));
}
if (options.hasKey("codePage")) {
#if OCC_VERSION_HEX >= 0x070800
if (options.hasKey("codePage")) {
int codePage = static_cast<int>(Py::Long(options.getItem("codePage")));
if (codePage >= 0) {
cp = static_cast<Resource_FormatType>(codePage);
}
#endif
}
#endif
}

if (mode && !pcDoc->isSaved()) {
Expand All @@ -263,11 +263,10 @@ class Module: public Py::ExtensionModule<Module>

try {
Import::ReaderStep reader(file);
#if OCC_VERSION_HEX < 0x070800
reader.read(hDoc);
#else
reader.read(hDoc, cp);
#if OCC_VERSION_HEX >= 0x070800
reader.setCodePage(cp);
#endif
reader.read(hDoc);
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
Expand Down Expand Up @@ -577,11 +576,7 @@ class Module: public Py::ExtensionModule<Module>

if (file.hasExtension({"stp", "step"})) {
Import::ReaderStep reader(file);
#if OCC_VERSION_HEX < 0x070800
reader.read(hDoc);
#else
reader.read(hDoc, Resource_FormatType_UTF8);
#endif
}
else if (file.hasExtension({"igs", "iges"})) {
Import::ReaderIges reader(file);
Expand Down
13 changes: 4 additions & 9 deletions src/Mod/Part/App/OCAF/ImportExportSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,18 @@ void ImportExportSettings::initIGES(Base::Reference<ParameterGrp> hGrp)
}
}

#if OCC_VERSION_HEX >= 0x070800

void ImportExportSettings::setImportCodePage(int cpIndex)
{
pGroup->SetInt("ImportCodePage", cpIndex);
}

Resource_FormatType ImportExportSettings::getImportCodePage() const
{
Resource_FormatType result;
int codePageIndex = pGroup->GetInt("ImportCodePage", 0);
int i=0;
Resource_FormatType result {};
long codePageIndex = pGroup->GetInt("ImportCodePage", 0L);
long i = 0L;
for (const auto& codePageIt : codePageList) {
if (i == codePageIndex)
{
if (i == codePageIndex) {
result = codePageIt.codePage;
break;
}
Expand All @@ -127,8 +124,6 @@ std::list<ImportExportSettings::CodePage> ImportExportSettings::getCodePageList(
return codePageList;
}

#endif

void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
{
//STEP handling
Expand Down
67 changes: 32 additions & 35 deletions src/Mod/Part/App/OCAF/ImportExportSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#include <Mod/Part/App/Interface.h>
#include <Base/Parameter.h>
#include <Standard_Version.hxx>
#if OCC_VERSION_HEX >= 0x070800
#include <Resource_FormatType.hxx>
#endif

namespace Part
{
Expand Down Expand Up @@ -57,12 +55,10 @@ class PartExport ImportExportSettings
ObjectPerDocument = 3,
ObjectPerDirectory = 4,
};
#if OCC_VERSION_HEX >= 0x070800
struct CodePage {
std::string codePageName;
Resource_FormatType codePage;
};
#endif
static void initialize();
ImportExportSettings();

Expand Down Expand Up @@ -102,11 +98,10 @@ class PartExport ImportExportSettings
void setImportMode(ImportMode);
ImportMode getImportMode() const;

#if OCC_VERSION_HEX >= 0x070800
void setImportCodePage(int);
Resource_FormatType getImportCodePage() const;
std::list<ImportExportSettings::CodePage> getCodePageList() const;
#endif

private:
static void initGeneral(Base::Reference<ParameterGrp> hGrp);
static void initSTEP(Base::Reference<ParameterGrp> hGrp);
Expand All @@ -116,37 +111,39 @@ class PartExport ImportExportSettings
mutable STEP::ImportExportSettingsPtr step;
mutable IGES::ImportExportSettingsPtr iges;
ParameterGrp::handle pGroup;
#if OCC_VERSION_HEX >= 0x070800
// clang-format off
std::list<CodePage> codePageList {
{"No conversion", Resource_FormatType_NoConversion},
{"Multi-byte UTF-8 encoding", Resource_FormatType_UTF8},
{"SJIS (Shift Japanese Industrial Standards) encoding", Resource_FormatType_SJIS},
{"EUC (Extended Unix Code) ", Resource_FormatType_EUC},
{"GB (Guobiao) encoding for Simplified Chinese", Resource_FormatType_GB},
{"GBK (Unified Chinese) encoding", Resource_FormatType_GBK},
{"Big5 (Traditional Chinese) encoding", Resource_FormatType_Big5},
//{"active system-defined locale; this value is strongly NOT recommended to use", Resource_FormatType_SystemLocale},
{"ISO 8859-1 (Western European) encoding", Resource_FormatType_iso8859_1},
{"ISO 8859-2 (Central European) encoding", Resource_FormatType_iso8859_2},
{"ISO 8859-3 (Turkish) encoding", Resource_FormatType_iso8859_3},
{"ISO 8859-4 (Northern European) encoding", Resource_FormatType_iso8859_4},
{"ISO 8859-5 (Cyrillic) encoding", Resource_FormatType_iso8859_5},
{"ISO 8859-6 (Arabic) encoding", Resource_FormatType_iso8859_6},
{"ISO 8859-7 (Greek) encoding", Resource_FormatType_iso8859_7},
{"ISO 8859-8 (Hebrew) encoding", Resource_FormatType_iso8859_8},
{"ISO 8859-9 (Turkish) encoding", Resource_FormatType_iso8859_9},
{"ISO 850 (Western European) encoding", Resource_FormatType_CP850},
{"CP1250 (Central European) encoding", Resource_FormatType_CP1250},
{"CP1251 (Cyrillic) encoding", Resource_FormatType_CP1251},
{"CP1252 (Western European) encoding", Resource_FormatType_CP1252},
{"CP1253 (Greek) encoding", Resource_FormatType_CP1253},
{"CP1254 (Turkish) encoding", Resource_FormatType_CP1254},
{"CP1255 (Hebrew) encoding", Resource_FormatType_CP1255},
{"CP1256 (Arabic) encoding", Resource_FormatType_CP1256},
{"CP1257 (Baltic) encoding", Resource_FormatType_CP1257},
{"CP1258 (Vietnamese) encoding", Resource_FormatType_CP1258},
};
#if OCC_VERSION_HEX >= 0x070800
{"No conversion", Resource_FormatType_NoConversion},
{"Multi-byte UTF-8 encoding", Resource_FormatType_UTF8},
{"SJIS (Shift Japanese Industrial Standards) encoding", Resource_FormatType_SJIS},
{"EUC (Extended Unix Code) ", Resource_FormatType_EUC},
{"GB (Guobiao) encoding for Simplified Chinese", Resource_FormatType_GB},
{"GBK (Unified Chinese) encoding", Resource_FormatType_GBK},
{"Big5 (Traditional Chinese) encoding", Resource_FormatType_Big5},
//{"active system-defined locale; this value is strongly NOT recommended to use", Resource_FormatType_SystemLocale},
{"ISO 8859-1 (Western European) encoding", Resource_FormatType_iso8859_1},
{"ISO 8859-2 (Central European) encoding", Resource_FormatType_iso8859_2},
{"ISO 8859-3 (Turkish) encoding", Resource_FormatType_iso8859_3},
{"ISO 8859-4 (Northern European) encoding", Resource_FormatType_iso8859_4},
{"ISO 8859-5 (Cyrillic) encoding", Resource_FormatType_iso8859_5},
{"ISO 8859-6 (Arabic) encoding", Resource_FormatType_iso8859_6},
{"ISO 8859-7 (Greek) encoding", Resource_FormatType_iso8859_7},
{"ISO 8859-8 (Hebrew) encoding", Resource_FormatType_iso8859_8},
{"ISO 8859-9 (Turkish) encoding", Resource_FormatType_iso8859_9},
{"ISO 850 (Western European) encoding", Resource_FormatType_CP850},
{"CP1250 (Central European) encoding", Resource_FormatType_CP1250},
{"CP1251 (Cyrillic) encoding", Resource_FormatType_CP1251},
{"CP1252 (Western European) encoding", Resource_FormatType_CP1252},
{"CP1253 (Greek) encoding", Resource_FormatType_CP1253},
{"CP1254 (Turkish) encoding", Resource_FormatType_CP1254},
{"CP1255 (Hebrew) encoding", Resource_FormatType_CP1255},
{"CP1256 (Arabic) encoding", Resource_FormatType_CP1256},
{"CP1257 (Baltic) encoding", Resource_FormatType_CP1257},
{"CP1258 (Vietnamese) encoding", Resource_FormatType_CP1258},
#endif
};
// clang-format on
};

} //namespace OCAF
Expand Down

0 comments on commit e804320

Please sign in to comment.