Select code page during STEP Import (#14416)

* [STEP Import]
Added the ability to select the encoding of the source file when importing.
Requires OCCT version 7.8.0 and higher

* fix compile error for OCCT < 7.8.0

* Also hide label "CodePage" for OCCT < 7.8.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix error on Ubuntu 20-04

* Fix error on Ubuntu 20-04

---------

Co-authored-by: Kuzma30 <kuzemkoa@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Kuzemko Alexsandr
2024-06-17 18:47:28 +03:00
committed by GitHub
parent f413f5d6d0
commit bf8e8b9157
8 changed files with 210 additions and 8 deletions

View File

@@ -157,9 +157,16 @@ 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());

View File

@@ -42,7 +42,11 @@ 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
#endif
{
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
@@ -51,7 +55,14 @@ void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
aReader.SetSHUOMode(true);
#if OCC_VERSION_HEX < 0x070800
if (aReader.ReadFile(name8bit.c_str()) != IFSelect_RetDone) {
#else
Handle(StepData_StepModel) aStepModel = new StepData_StepModel;
aStepModel->InternalParameters.InitFromStatic();
aStepModel->SetSourceCodePage(codePage);
if (aReader.ReadFile(name8bit.c_str(), aStepModel->InternalParameters) != IFSelect_RetDone) {
#endif
throw Base::FileException("Cannot read STEP file", file);
}

View File

@@ -27,6 +27,8 @@
#include <Mod/Import/ImportGlobal.h>
#include <Base/FileInfo.h>
#include <TDocStd_Document.hxx>
#include <StepData_StepModel.hxx>
#include <Standard_Version.hxx>
namespace Import
{
@@ -35,8 +37,11 @@ class ImportExport ReaderStep
{
public:
explicit ReaderStep(const Base::FileInfo& file);
#if OCC_VERSION_HEX < 0x070800
void read(Handle(TDocStd_Document) hDoc);
#else
void read(Handle(TDocStd_Document) hDoc, Resource_FormatType codePage);
#endif
private:
Base::FileInfo file;

View File

@@ -164,6 +164,16 @@ private:
if (mode < 0) {
mode = ocaf.getMode();
}
#if OCC_VERSION_HEX >= 0x070800
auto handle = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Import/hSTEP");
if (handle->GetBool("ReadShowDialogImport", false)) {
Gui::Command::doCommand(Gui::Command::Gui,
"Gui.showPreferences('Import-Export', 8)");
}
Part::OCAF::ImportExportSettings settings;
Resource_FormatType cp = settings.getImportCodePage();
#endif
if (mode && !pcDoc->isSaved()) {
auto gdoc = Gui::Application::Instance->getDocument(pcDoc);
if (!gdoc->save()) {
@@ -173,7 +183,11 @@ private:
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());
@@ -483,7 +497,11 @@ 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);

View File

@@ -22,7 +22,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Interface_Static.hxx>
#include <Interface_Static.hxx>
#endif
#include "ImportExportSettings.h"
@@ -99,6 +99,48 @@ 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;
for (const auto& codePageIt : codePageList) {
if (i == codePageIndex)
{
result = codePageIt.codePage;
break;
}
i++;
}
return result;
}
std::list<ImportExportSettings::CodePage> ImportExportSettings::getCodePageList() const
{
return codePageList;
}
void ImportExportSettings::setReadShowDialogImport(bool on)
{
auto grp = pGroup->GetGroup("hSTEP");
grp->SetBool("ReadShowDialogImport", on);
}
bool ImportExportSettings::getReadShowDialogImport() const
{
auto grp = pGroup->GetGroup("hSTEP");
return grp->GetBool("ReadShowDialogImport", false);
}
#endif
void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
{
//STEP handling

View File

@@ -26,7 +26,10 @@
#include <memory>
#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
{
@@ -54,7 +57,12 @@ public:
ObjectPerDocument = 3,
ObjectPerDirectory = 4,
};
#if OCC_VERSION_HEX >= 0x070800
struct CodePage {
std::string codePageName;
Resource_FormatType codePage;
};
#endif
static void initialize();
ImportExportSettings();
@@ -94,6 +102,14 @@ public:
void setImportMode(ImportMode);
ImportMode getImportMode() const;
#if OCC_VERSION_HEX >= 0x070800
void setReadShowDialogImport(bool);
bool getReadShowDialogImport() const;
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);
@@ -103,6 +119,37 @@ private:
mutable STEP::ImportExportSettingsPtr step;
mutable IGES::ImportExportSettingsPtr iges;
ParameterGrp::handle pGroup;
#if OCC_VERSION_HEX >= 0x070800
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},
};
#endif
};
} //namespace OCAF

View File

@@ -27,7 +27,7 @@
#include "DlgImportStep.h"
#include "ui_DlgImportStep.h"
#include <Standard_Version.hxx>
using namespace PartGui;
@@ -36,7 +36,6 @@ DlgImportStep::DlgImportStep(QWidget* parent)
, ui(new Ui_DlgImportStep)
{
ui->setupUi(this);
Part::OCAF::ImportExportSettings settings;
ui->checkBoxMergeCompound->setChecked(settings.getReadShapeCompoundMode());
ui->checkBoxImportHiddenObj->setChecked(settings.getImportHiddenObject());
@@ -45,6 +44,20 @@ DlgImportStep::DlgImportStep(QWidget* parent)
ui->checkBoxReduceObjects->setChecked(settings.getReduceObjects());
ui->checkBoxExpandCompound->setChecked(settings.getExpandCompound());
ui->checkBoxShowProgress->setChecked(settings.getShowProgress());
#if OCC_VERSION_HEX >= 0x070800
ui->checkBoxShowOnImport->setChecked(settings.getReadShowDialogImport());
std::list<Part::OCAF::ImportExportSettings::CodePage> codepagelist;
codepagelist = settings.getCodePageList();
for (const auto& codePage : codepagelist) {
ui->comboBoxImportCodePage->addItem(QString::fromStdString(codePage.codePageName));
}
#else
// hide options that not supported in this OCCT version (7.8.0)
ui->label_6->hide();
ui->checkBoxShowOnImport->hide();
ui->comboBoxImportCodePage->hide();
#endif
}
/**
@@ -55,6 +68,10 @@ DlgImportStep::~DlgImportStep() = default;
void DlgImportStep::saveSettings()
{
// (h)STEP of Import module
#if OCC_VERSION_HEX >= 0x070800
ui->checkBoxShowOnImport->onSave();
ui->comboBoxImportCodePage->onSave();
#endif
ui->checkBoxMergeCompound->onSave();
ui->checkBoxImportHiddenObj->onSave();
ui->checkBoxUseLinkGroup->onSave();
@@ -68,6 +85,10 @@ void DlgImportStep::saveSettings()
void DlgImportStep::loadSettings()
{
// (h)STEP of Import module
#if OCC_VERSION_HEX >= 0x070800
ui->checkBoxShowOnImport->onRestore();
ui->comboBoxImportCodePage->onRestore();
#endif
ui->checkBoxMergeCompound->onRestore();
ui->checkBoxImportHiddenObj->onRestore();
ui->checkBoxUseLinkGroup->onRestore();

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>445</width>
<height>292</height>
<height>365</height>
</rect>
</property>
<property name="windowTitle">
@@ -20,6 +20,22 @@
<string>Import</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxShowOnImport">
<property name="toolTip">
<string>If checked, this Dialog will be shown during Import</string>
</property>
<property name="text">
<string>Show this Dialog when importing</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ReadShowDialogImport</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Import/hSTEP</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBoxMergeCompound">
<property name="toolTip">
@@ -133,6 +149,42 @@ during file reading (slower but higher details).</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_6">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>197</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>CodePage</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBoxImportCodePage">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="prefEntry" stdset="0">
<cstring>ImportCodePage</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Import</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -208,7 +260,6 @@ during file reading (slower but higher details).</string>
<tabstop>checkBoxImportHiddenObj</tabstop>
<tabstop>checkBoxReduceObjects</tabstop>
<tabstop>checkBoxExpandCompound</tabstop>
<tabstop>checkBoxShowProgress</tabstop>
<tabstop>checkBoxUseBaseName</tabstop>
<tabstop>comboBoxImportMode</tabstop>
</tabstops>