Import: Simplify handling of Resource_FormatType
The type Resource_FormatType already exists since 2015. So, its usage doesn't require pre-processor macros everywhere.
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
@@ -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
|
||||
|
||||
@@ -244,14 +244,14 @@ private:
|
||||
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()) {
|
||||
@@ -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);
|
||||
|
||||
@@ -99,8 +99,6 @@ void ImportExportSettings::initIGES(Base::Reference<ParameterGrp> 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::CodePage> ImportExportSettings::getCodePageList(
|
||||
return codePageList;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ImportExportSettings::initSTEP(Base::Reference<ParameterGrp> hGrp)
|
||||
{
|
||||
//STEP handling
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -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<ImportExportSettings::CodePage> getCodePageList() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
static void initGeneral(Base::Reference<ParameterGrp> hGrp);
|
||||
static void initSTEP(Base::Reference<ParameterGrp> 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<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
|
||||
|
||||
Reference in New Issue
Block a user