Skip to content

Commit

Permalink
First working version. User can select codepage from Preference page.…
Browse files Browse the repository at this point in the history
… Checkbox "Display this Dialog..." not working now
  • Loading branch information
KuzemkoA committed May 28, 2024
1 parent 5c26745 commit 4cfd7c3
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/Mod/Import/App/AppImportPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ class Module: public Py::ExtensionModule<Module>
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());
Expand Down
19 changes: 19 additions & 0 deletions src/Mod/Import/App/ImportOCAF2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ ImportOCAFOptions ImportOCAF2::customImportOptions()
defaultOptions.showProgress = settings.getShowProgress();
defaultOptions.expandCompound = settings.getExpandCompound();
defaultOptions.mode = static_cast<int>(settings.getImportMode());
defaultOptions.codePage = static_cast<Resource_FormatType>(settings.getImportCodePage());

auto hGrp =
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
Expand Down Expand Up @@ -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<Part::OCAF::ImportExportSettings::CodePage> 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()))
Expand Down
13 changes: 12 additions & 1 deletion src/Mod/Import/App/ImportOCAF2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "ExportOCAF.h"
#include "ImportOCAF.h"
#include "Tools.h"

#include <Resource_FormatType.hxx>

class TDF_Label;
class TopLoc_Location;
Expand All @@ -64,13 +64,15 @@ struct ImportExport ImportOCAFOptions
ImportOCAFOptions();
App::Color defaultFaceColor;
App::Color defaultEdgeColor;
bool showDialog = false;
bool merge = false;
bool useLinkGroup = false;
bool useBaseName = true;
bool importHidden = true;
bool reduceObjects = false;
bool showProgress = false;
bool expandCompound = false;
Resource_FormatType codePage = Resource_FormatType_NoConversion;
int mode = 0;
};

Expand All @@ -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;
Expand Down Expand Up @@ -123,6 +129,11 @@ class ImportExport ImportOCAF2
{
return options.mode;
}
void setImportCodePage(int cp);
Resource_FormatType getImportCodePage() const
{
return options.codePage;
}

private:
struct Info
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Import/App/ReaderStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Check failure on line 55 in src/Mod/Import/App/ReaderStep.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

no member named 'InternalParameters' in 'StepData_StepModel'

Check failure on line 55 in src/Mod/Import/App/ReaderStep.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

no member named 'InternalParameters' in 'StepData_StepModel' [clang-diagnostic-error]
aStepModel->SetSourceCodePage(Resource_FormatType_CP1251);
aStepModel->SetSourceCodePage(codePage);
if (aReader.ReadFile(name8bit.c_str(),aStepModel->InternalParameters) != IFSelect_RetDone) {

Check failure on line 57 in src/Mod/Import/App/ReaderStep.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

no member named 'InternalParameters' in 'StepData_StepModel'

Check failure on line 57 in src/Mod/Import/App/ReaderStep.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

no member named 'InternalParameters' in 'StepData_StepModel' [clang-diagnostic-error]
throw Base::FileException("Cannot read STEP file", file);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Import/App/ReaderStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/Mod/Import/Gui/AppImportGuiPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Module: public Py::ExtensionModule<Module>
PyObject* merge = Py_None;
PyObject* useLinkGroup = Py_None;
int mode = -1;

static const std::array<const char*, 7>
kwd_list {"name", "docName", "importHidden", "merge", "useLinkGroup", "mode", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(),
Expand Down Expand Up @@ -164,6 +165,7 @@ class Module: public Py::ExtensionModule<Module>
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()) {
Expand All @@ -173,7 +175,7 @@ class Module: public Py::ExtensionModule<Module>

try {
Import::ReaderStep reader(file);
reader.read(hDoc);
reader.read(hDoc, cp);
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
Expand Down Expand Up @@ -483,7 +485,7 @@ class Module: public Py::ExtensionModule<Module>

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);
Expand Down
28 changes: 28 additions & 0 deletions src/Mod/Part/App/OCAF/ImportExportSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ void ImportExportSettings::initIGES(Base::Reference<ParameterGrp> hGrp)

std::list<ImportExportSettings::CodePage> 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;
}

Expand Down Expand Up @@ -274,5 +280,27 @@ ImportExportSettings::ImportMode ImportExportSettings::getImportMode() const
return static_cast<ImportExportSettings::ImportMode>(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
21 changes: 12 additions & 9 deletions src/Mod/Part/App/OCAF/ImportExportSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class PartExport ImportExportSettings
void setImportMode(ImportMode);
ImportMode getImportMode() const;

void setImportCodePage(int);
Resource_FormatType getImportCodePage() const;

std::list<ImportExportSettings::CodePage> getCodePageList() const;

private:
Expand All @@ -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},
Expand All @@ -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},

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'?

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'?

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'?

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'?

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'?

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'?

Check failure on line 137 in src/Mod/Part/App/OCAF/ImportExportSettings.h

View workflow job for this annotation

GitHub Actions / Lint / Lint

use of undeclared identifier 'Resource_FormatType_CP850'; did you mean 'Resource_FormatType_CP1250'? [clang-diagnostic-error]
{"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},
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Part/Gui/DlgImportStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 4cfd7c3

Please sign in to comment.