From 4cfd7c34db5f30f3123121e28aedc0736ea6b5ac Mon Sep 17 00:00:00 2001 From: Kuzma30 Date: Tue, 28 May 2024 12:59:22 +0000 Subject: [PATCH] First working version. User can select codepage from Preference page. Checkbox "Display this Dialog..." not working now --- src/Mod/Import/App/AppImportPy.cpp | 3 +- src/Mod/Import/App/ImportOCAF2.cpp | 19 +++++++++++++ src/Mod/Import/App/ImportOCAF2.h | 13 ++++++++- src/Mod/Import/App/ReaderStep.cpp | 4 +-- src/Mod/Import/App/ReaderStep.h | 2 +- src/Mod/Import/Gui/AppImportGuiPy.cpp | 6 ++-- .../Part/App/OCAF/ImportExportSettings.cpp | 28 +++++++++++++++++++ src/Mod/Part/App/OCAF/ImportExportSettings.h | 21 ++++++++------ src/Mod/Part/Gui/DlgImportStep.cpp | 4 +-- 9 files changed, 82 insertions(+), 18 deletions(-) diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index ce5919f4c782..74da0b0b0d49 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -157,9 +157,10 @@ class Module: public Py::ExtensionModule hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc); if (file.hasExtension({"stp", "step"})) { + Resource_FormatType cp = Resource_FormatType_UTF8; try { Import::ReaderStep reader(file); - reader.read(hDoc); + reader.read(hDoc, cp); } catch (OSD_Exception& e) { Base::Console().Error("%s\n", e.GetMessageString()); diff --git a/src/Mod/Import/App/ImportOCAF2.cpp b/src/Mod/Import/App/ImportOCAF2.cpp index 939de9acd03b..511802f253fb 100644 --- a/src/Mod/Import/App/ImportOCAF2.cpp +++ b/src/Mod/Import/App/ImportOCAF2.cpp @@ -109,6 +109,7 @@ ImportOCAFOptions ImportOCAF2::customImportOptions() defaultOptions.showProgress = settings.getShowProgress(); defaultOptions.expandCompound = settings.getExpandCompound(); defaultOptions.mode = static_cast(settings.getImportMode()); + defaultOptions.codePage = static_cast(settings.getImportCodePage()); auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); @@ -158,6 +159,24 @@ void ImportOCAF2::setMode(int m) } } +void ImportOCAF2::setImportCodePage(int cp) +{ + printf("ImportOCAF2::setCodePage(%i)", cp); + Part::OCAF::ImportExportSettings settings; + std::list codePageList; + codePageList = settings.getCodePageList() ; + for (const auto& codePageIt : codePageList) { + if (codePageIt.codePage == cp) + { + options.codePage = codePageIt.codePage; + printf("ImportOCAF2::setCodePage save codepage as = %i", options.codePage); + return; + } + } + options.codePage = Resource_FormatType_UTF8; + printf("ImportOCAF2::setCodePage save codepage as = %i", options.codePage); +} + static void setPlacement(App::PropertyPlacement* prop, const TopoDS_Shape& shape) { prop->setValue(Base::Placement(Part::TopoShape::convert(shape.Location().Transformation())) diff --git a/src/Mod/Import/App/ImportOCAF2.h b/src/Mod/Import/App/ImportOCAF2.h index 8b79201e1760..ac05b5ee09cb 100644 --- a/src/Mod/Import/App/ImportOCAF2.h +++ b/src/Mod/Import/App/ImportOCAF2.h @@ -41,7 +41,7 @@ #include "ExportOCAF.h" #include "ImportOCAF.h" #include "Tools.h" - +#include class TDF_Label; class TopLoc_Location; @@ -64,6 +64,7 @@ struct ImportExport ImportOCAFOptions ImportOCAFOptions(); App::Color defaultFaceColor; App::Color defaultEdgeColor; + bool showDialog = false; bool merge = false; bool useLinkGroup = false; bool useBaseName = true; @@ -71,6 +72,7 @@ struct ImportExport ImportOCAFOptions bool reduceObjects = false; bool showProgress = false; bool expandCompound = false; + Resource_FormatType codePage = Resource_FormatType_NoConversion; int mode = 0; }; @@ -83,6 +85,10 @@ class ImportExport ImportOCAF2 static ImportOCAFOptions customImportOptions(); void setImportOptions(ImportOCAFOptions opts); + void setShowDialog(bool enable) + { + options.showDialog = enable; + } void setMerge(bool enable) { options.merge = enable; @@ -123,6 +129,11 @@ class ImportExport ImportOCAF2 { return options.mode; } + void setImportCodePage(int cp); + Resource_FormatType getImportCodePage() const + { + return options.codePage; + } private: struct Info diff --git a/src/Mod/Import/App/ReaderStep.cpp b/src/Mod/Import/App/ReaderStep.cpp index b388828b379e..579452575ec0 100644 --- a/src/Mod/Import/App/ReaderStep.cpp +++ b/src/Mod/Import/App/ReaderStep.cpp @@ -42,7 +42,7 @@ ReaderStep::ReaderStep(const Base::FileInfo& file) // NOLINT : file {file} {} -void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT +void ReaderStep::read(Handle(TDocStd_Document) hDoc, Resource_FormatType codePage) // NOLINT { std::string utf8Name = file.filePath(); std::string name8bit = Part::encodeFilename(utf8Name); @@ -53,7 +53,7 @@ void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT aReader.SetSHUOMode(true); Handle(StepData_StepModel) aStepModel = new StepData_StepModel; aStepModel->InternalParameters.InitFromStatic(); - aStepModel->SetSourceCodePage(Resource_FormatType_CP1251); + aStepModel->SetSourceCodePage(codePage); if (aReader.ReadFile(name8bit.c_str(),aStepModel->InternalParameters) != IFSelect_RetDone) { throw Base::FileException("Cannot read STEP file", file); } diff --git a/src/Mod/Import/App/ReaderStep.h b/src/Mod/Import/App/ReaderStep.h index 861d3df7aa8a..2dee50a1403d 100644 --- a/src/Mod/Import/App/ReaderStep.h +++ b/src/Mod/Import/App/ReaderStep.h @@ -37,7 +37,7 @@ class ImportExport ReaderStep public: explicit ReaderStep(const Base::FileInfo& file); - void read(Handle(TDocStd_Document) hDoc); + void read(Handle(TDocStd_Document) hDoc, Resource_FormatType codePage); private: Base::FileInfo file; diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 106cb0bd3b92..cc8d42b9c80e 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -117,6 +117,7 @@ class Module: public Py::ExtensionModule PyObject* merge = Py_None; PyObject* useLinkGroup = Py_None; int mode = -1; + static const std::array kwd_list {"name", "docName", "importHidden", "merge", "useLinkGroup", "mode", nullptr}; if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(), @@ -164,6 +165,7 @@ class Module: public Py::ExtensionModule if (mode < 0) { mode = ocaf.getMode(); } + Resource_FormatType cp = ocaf.getImportCodePage(); if (mode && !pcDoc->isSaved()) { auto gdoc = Gui::Application::Instance->getDocument(pcDoc); if (!gdoc->save()) { @@ -173,7 +175,7 @@ class Module: public Py::ExtensionModule try { Import::ReaderStep reader(file); - reader.read(hDoc); + reader.read(hDoc, cp); } catch (OSD_Exception& e) { Base::Console().Error("%s\n", e.GetMessageString()); @@ -483,7 +485,7 @@ class Module: public Py::ExtensionModule if (file.hasExtension({"stp", "step"})) { Import::ReaderStep reader(file); - reader.read(hDoc); + reader.read(hDoc, Resource_FormatType_UTF8); } 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 85504005f1ee..06b0f9d23abb 100644 --- a/src/Mod/Part/App/OCAF/ImportExportSettings.cpp +++ b/src/Mod/Part/App/OCAF/ImportExportSettings.cpp @@ -101,6 +101,12 @@ void ImportExportSettings::initIGES(Base::Reference hGrp) std::list ImportExportSettings::getCodePageList() const { + Base::Console().Message("ImportExportSettings::getCodePageList())\n"); + int i=0; + for (const auto& codePageIt : codePageList) { + Base::Console().Message("Number in List =%i Name=%s number=%i\n", i, codePageIt.codePageName, codePageIt.codePage); + i++; + } return codePageList; } @@ -274,5 +280,27 @@ ImportExportSettings::ImportMode ImportExportSettings::getImportMode() const return static_cast(pGroup->GetInt("ImportMode", 0)); } +void ImportExportSettings::setImportCodePage(int cpIndex) +{ + Base::Console().Message("ImportExportSettings::setImportCodePage(%i)", cpIndex); + pGroup->SetInt("ImportCodePage", cpIndex); +} + +Resource_FormatType ImportExportSettings::getImportCodePage() const +{ + Resource_FormatType result; + int codePageIndex = pGroup->GetInt("ImportCodePage", 0); + int i=0; + for (const auto& codePageIt : codePageList) { + if (i == codePageIndex) + { + result = codePageIt.codePage; + break; + } + i++; + } + return result; +} + } // namespace OCAF } // namespace Part diff --git a/src/Mod/Part/App/OCAF/ImportExportSettings.h b/src/Mod/Part/App/OCAF/ImportExportSettings.h index c2576868cb2e..46cc73db9789 100644 --- a/src/Mod/Part/App/OCAF/ImportExportSettings.h +++ b/src/Mod/Part/App/OCAF/ImportExportSettings.h @@ -102,6 +102,9 @@ class PartExport ImportExportSettings void setImportMode(ImportMode); ImportMode getImportMode() const; + void setImportCodePage(int); + Resource_FormatType getImportCodePage() const; + std::list getCodePageList() const; private: @@ -122,15 +125,6 @@ class PartExport ImportExportSettings {"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}, - {"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}, {"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}, @@ -141,6 +135,15 @@ class PartExport ImportExportSettings {"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}, }; }; diff --git a/src/Mod/Part/Gui/DlgImportStep.cpp b/src/Mod/Part/Gui/DlgImportStep.cpp index 6e78d11d0ecb..877a0fecd807 100644 --- a/src/Mod/Part/Gui/DlgImportStep.cpp +++ b/src/Mod/Part/Gui/DlgImportStep.cpp @@ -61,7 +61,7 @@ DlgImportStep::~DlgImportStep() = default; void DlgImportStep::saveSettings() { // (h)STEP of Import module - ui->comboBoxImportCodePage->onSave(); + ui->checkBoxShowOnImport->onSave(); ui->checkBoxMergeCompound->onSave(); ui->checkBoxImportHiddenObj->onSave(); ui->checkBoxUseLinkGroup->onSave(); @@ -76,7 +76,7 @@ void DlgImportStep::saveSettings() void DlgImportStep::loadSettings() { // (h)STEP of Import module - ui->comboBoxImportCodePage->onRestore(); + ui->checkBoxShowOnImport->onRestore(); ui->checkBoxMergeCompound->onRestore(); ui->checkBoxImportHiddenObj->onRestore(); ui->checkBoxUseLinkGroup->onRestore();