From 06b464a9b0a44d5219807f0be31257d1f4798dac Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 18 Jun 2024 15:54:56 +0200 Subject: [PATCH] Import: Simplify handling of Resource_FormatType The type Resource_FormatType already exists since 2015. So, its usage doesn't require pre-processor macros everywhere. --- src/Mod/Import/App/AppImportPy.cpp | 7 -- src/Mod/Import/App/ReaderStep.cpp | 12 ++-- src/Mod/Import/App/ReaderStep.h | 10 +-- src/Mod/Import/Gui/AppImportGuiPy.cpp | 15 ++--- .../Part/App/OCAF/ImportExportSettings.cpp | 13 ++-- src/Mod/Part/App/OCAF/ImportExportSettings.h | 67 +++++++++---------- 6 files changed, 53 insertions(+), 71 deletions(-) diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index e233603d0a..ce5919f4c7 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -157,16 +157,9 @@ private: 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()); diff --git a/src/Mod/Import/App/ReaderStep.cpp b/src/Mod/Import/App/ReaderStep.cpp index 682a4dbf51..d7c7bf9ad7 100644 --- a/src/Mod/Import/App/ReaderStep.cpp +++ b/src/Mod/Import/App/ReaderStep.cpp @@ -40,13 +40,13 @@ using namespace Import; ReaderStep::ReaderStep(const Base::FileInfo& file) // NOLINT : file {file} -{} - -#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 +{ +#if OCC_VERSION_HEX >= 0x070800 + codePage = Resource_FormatType_UTF8; #endif +} + +void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT { std::string utf8Name = file.filePath(); std::string name8bit = Part::encodeFilename(utf8Name); diff --git a/src/Mod/Import/App/ReaderStep.h b/src/Mod/Import/App/ReaderStep.h index 7491c1f4d2..05d97f017f 100644 --- a/src/Mod/Import/App/ReaderStep.h +++ b/src/Mod/Import/App/ReaderStep.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 347b9a9fef..076b5bab8c 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -244,14 +244,14 @@ private: if (options.hasKey("mode")) { ocaf.setMode(static_cast(Py::Long(options.getItem("mode")))); } - if (options.hasKey("codePage")) { #if OCC_VERSION_HEX >= 0x070800 + if (options.hasKey("codePage")) { int codePage = static_cast(Py::Long(options.getItem("codePage"))); if (codePage >= 0) { cp = static_cast(codePage); } -#endif } +#endif } if (mode && !pcDoc->isSaved()) { @@ -263,11 +263,10 @@ private: 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()); @@ -577,11 +576,7 @@ private: 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); diff --git a/src/Mod/Part/App/OCAF/ImportExportSettings.cpp b/src/Mod/Part/App/OCAF/ImportExportSettings.cpp index 37d76ff8ac..47f5d28c0b 100644 --- a/src/Mod/Part/App/OCAF/ImportExportSettings.cpp +++ b/src/Mod/Part/App/OCAF/ImportExportSettings.cpp @@ -99,8 +99,6 @@ void ImportExportSettings::initIGES(Base::Reference hGrp) } } -#if OCC_VERSION_HEX >= 0x070800 - void ImportExportSettings::setImportCodePage(int cpIndex) { pGroup->SetInt("ImportCodePage", cpIndex); @@ -108,12 +106,11 @@ void ImportExportSettings::setImportCodePage(int 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; } @@ -127,8 +124,6 @@ std::list ImportExportSettings::getCodePageList( return codePageList; } -#endif - void ImportExportSettings::initSTEP(Base::Reference hGrp) { //STEP handling diff --git a/src/Mod/Part/App/OCAF/ImportExportSettings.h b/src/Mod/Part/App/OCAF/ImportExportSettings.h index 4bc2d30069..a3bd5b641d 100644 --- a/src/Mod/Part/App/OCAF/ImportExportSettings.h +++ b/src/Mod/Part/App/OCAF/ImportExportSettings.h @@ -27,9 +27,7 @@ #include #include #include -#if OCC_VERSION_HEX >= 0x070800 #include -#endif namespace Part { @@ -57,12 +55,10 @@ public: ObjectPerDocument = 3, ObjectPerDirectory = 4, }; -#if OCC_VERSION_HEX >= 0x070800 struct CodePage { std::string codePageName; Resource_FormatType codePage; }; -#endif static void initialize(); ImportExportSettings(); @@ -102,11 +98,10 @@ public: void setImportMode(ImportMode); ImportMode getImportMode() const; -#if OCC_VERSION_HEX >= 0x070800 void setImportCodePage(int); Resource_FormatType getImportCodePage() const; std::list getCodePageList() const; -#endif + private: static void initGeneral(Base::Reference hGrp); static void initSTEP(Base::Reference hGrp); @@ -116,37 +111,39 @@ private: mutable STEP::ImportExportSettingsPtr step; mutable IGES::ImportExportSettingsPtr iges; ParameterGrp::handle pGroup; -#if OCC_VERSION_HEX >= 0x070800 + // clang-format off std::list 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