From 0561348bfcf2452f0abdadee6073746dd7e95269 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 26 Jul 2022 22:34:20 +0200 Subject: [PATCH] Part: move initialization of STEP/IGES reader/writer to ImportExportSettings::initialize() --- src/Mod/Part/App/AppPart.cpp | 73 +-------------------------- src/Mod/Part/App/ImportStep.cpp | 89 +++++++++++++++++++++++++++++++++ src/Mod/Part/App/ImportStep.h | 7 +++ 3 files changed, 98 insertions(+), 71 deletions(-) diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 00a3a98164..82b05ce5b1 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -94,6 +94,7 @@ #include "GeometryMigrationExtension.h" #include "GeometryStringExtensionPy.h" #include "HyperbolaPy.h" +#include "ImportStep.h" #include "LinePy.h" #include "LineSegmentPy.h" #include "OffsetCurvePy.h" @@ -537,78 +538,8 @@ PyMOD_INIT_FUNC(Part) IGESControl_Controller::Init(); STEPControl_Controller::Init(); - // set the user-defined settings - Base::Reference hGrp = App::GetApplication().GetUserParameter() - .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part"); - // General - Base::Reference hGenGrp = hGrp->GetGroup("General"); - // http://www.opencascade.org/org/forum/thread_20801/ - // read.surfacecurve.mode: - // A preference for the computation of curves in an entity which has both 2D and 3D representation. - // Each TopoDS_Edge in TopoDS_Face must have a 3D and 2D curve that references the surface. - // If both 2D and 3D representation of the entity are present, the computation of these curves depends on - // the following values of parameter: - // 0: "Default" - no preference, both curves are taken - // 3: "3DUse_Preferred" - 3D curves are used to rebuild 2D ones - // Additional modes for IGES - // 2: "2DUse_Preferred" - the 2D is used to rebuild the 3D in case of their inconsistency - // -2: "2DUse_Forced" - the 2D is always used to rebuild the 3D (even if 2D is present in the file) - // -3: "3DUse_Forced" - the 3D is always used to rebuild the 2D (even if 2D is present in the file) - int readsurfacecurve = hGenGrp->GetInt("ReadSurfaceCurveMode", 0); - Interface_Static::SetIVal("read.surfacecurve.mode", readsurfacecurve); - - // write.surfacecurve.mode (STEP-only): - // This parameter indicates whether parametric curves (curves in parametric space of surface) should be - // written into the STEP file. This parameter can be set to Off in order to minimize the size of the resulting - // STEP file. - // Off (0) : writes STEP files without pcurves. This mode decreases the size of the resulting file. - // On (1) : (default) writes pcurves to STEP file - int writesurfacecurve = hGenGrp->GetInt("WriteSurfaceCurveMode", 0); - Interface_Static::SetIVal("write.surfacecurve.mode", writesurfacecurve); - - //IGES handling - Base::Reference hIgesGrp = hGrp->GetGroup("IGES"); - int value = Interface_Static::IVal("write.iges.brep.mode"); - bool brep = hIgesGrp->GetBool("BrepMode", value > 0); - Interface_Static::SetIVal("write.iges.brep.mode",brep ? 1 : 0); - Interface_Static::SetCVal("write.iges.header.company", hIgesGrp->GetASCII("Company").c_str()); - Interface_Static::SetCVal("write.iges.header.author", hIgesGrp->GetASCII("Author").c_str()); - Interface_Static::SetCVal("write.iges.header.product", hIgesGrp->GetASCII("Product", - Interface_Static::CVal("write.iges.header.product")).c_str()); - - int unitIges = hIgesGrp->GetInt("Unit", 0); - switch (unitIges) { - case 1: - Interface_Static::SetCVal("write.iges.unit","M"); - break; - case 2: - Interface_Static::SetCVal("write.iges.unit","INCH"); - break; - default: - Interface_Static::SetCVal("write.iges.unit","MM"); - break; - } - - //STEP handling - Base::Reference hStepGrp = hGrp->GetGroup("STEP"); - int unitStep = hStepGrp->GetInt("Unit", 0); - switch (unitStep) { - case 1: - Interface_Static::SetCVal("write.step.unit","M"); - break; - case 2: - Interface_Static::SetCVal("write.step.unit","INCH"); - break; - default: - Interface_Static::SetCVal("write.step.unit","MM"); - break; - } - - std::string ap = hStepGrp->GetASCII("Scheme", Interface_Static::CVal("write.step.schema")); - Interface_Static::SetCVal("write.step.schema", ap.c_str()); - Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product", - Interface_Static::CVal("write.step.product.name")).c_str()); + ImportExportSettings::initialize(); PyMOD_Return(partModule); } diff --git a/src/Mod/Part/App/ImportStep.cpp b/src/Mod/Part/App/ImportStep.cpp index 5e94ddcd95..92624c5bf2 100644 --- a/src/Mod/Part/App/ImportStep.cpp +++ b/src/Mod/Part/App/ImportStep.cpp @@ -25,6 +25,7 @@ # include # include # include +# include # include # include # include @@ -56,6 +57,94 @@ using namespace Part; +void ImportExportSettings::initialize() +{ + // set the user-defined settings + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part"); + initGeneral(hGrp); + initSTEP(hGrp); + initIGES(hGrp); +} + +void ImportExportSettings::initGeneral(Base::Reference hGrp) +{ + // General + Base::Reference hGenGrp = hGrp->GetGroup("General"); + // http://www.opencascade.org/org/forum/thread_20801/ + // read.surfacecurve.mode: + // A preference for the computation of curves in an entity which has both 2D and 3D representation. + // Each TopoDS_Edge in TopoDS_Face must have a 3D and 2D curve that references the surface. + // If both 2D and 3D representation of the entity are present, the computation of these curves depends on + // the following values of parameter: + // 0: "Default" - no preference, both curves are taken + // 3: "3DUse_Preferred" - 3D curves are used to rebuild 2D ones + // Additional modes for IGES + // 2: "2DUse_Preferred" - the 2D is used to rebuild the 3D in case of their inconsistency + // -2: "2DUse_Forced" - the 2D is always used to rebuild the 3D (even if 2D is present in the file) + // -3: "3DUse_Forced" - the 3D is always used to rebuild the 2D (even if 2D is present in the file) + int readsurfacecurve = hGenGrp->GetInt("ReadSurfaceCurveMode", 0); + Interface_Static::SetIVal("read.surfacecurve.mode", readsurfacecurve); + + // write.surfacecurve.mode (STEP-only): + // This parameter indicates whether parametric curves (curves in parametric space of surface) should be + // written into the STEP file. This parameter can be set to Off in order to minimize the size of the resulting + // STEP file. + // Off (0) : writes STEP files without pcurves. This mode decreases the size of the resulting file. + // On (1) : (default) writes pcurves to STEP file + int writesurfacecurve = hGenGrp->GetInt("WriteSurfaceCurveMode", 0); + Interface_Static::SetIVal("write.surfacecurve.mode", writesurfacecurve); +} + +void ImportExportSettings::initIGES(Base::Reference hGrp) +{ + //IGES handling + Base::Reference hIgesGrp = hGrp->GetGroup("IGES"); + int value = Interface_Static::IVal("write.iges.brep.mode"); + bool brep = hIgesGrp->GetBool("BrepMode", value > 0); + Interface_Static::SetIVal("write.iges.brep.mode",brep ? 1 : 0); + Interface_Static::SetCVal("write.iges.header.company", hIgesGrp->GetASCII("Company").c_str()); + Interface_Static::SetCVal("write.iges.header.author", hIgesGrp->GetASCII("Author").c_str()); + Interface_Static::SetCVal("write.iges.header.product", hIgesGrp->GetASCII("Product", + Interface_Static::CVal("write.iges.header.product")).c_str()); + + int unitIges = hIgesGrp->GetInt("Unit", 0); + switch (unitIges) { + case 1: + Interface_Static::SetCVal("write.iges.unit","M"); + break; + case 2: + Interface_Static::SetCVal("write.iges.unit","INCH"); + break; + default: + Interface_Static::SetCVal("write.iges.unit","MM"); + break; + } +} + +void ImportExportSettings::initSTEP(Base::Reference hGrp) +{ + //STEP handling + Base::Reference hStepGrp = hGrp->GetGroup("STEP"); + int unitStep = hStepGrp->GetInt("Unit", 0); + switch (unitStep) { + case 1: + Interface_Static::SetCVal("write.step.unit","M"); + break; + case 2: + Interface_Static::SetCVal("write.step.unit","INCH"); + break; + default: + Interface_Static::SetCVal("write.step.unit","MM"); + break; + } + + std::string ap = hStepGrp->GetASCII("Scheme", Interface_Static::CVal("write.step.schema")); + Interface_Static::SetCVal("write.step.schema", ap.c_str()); + Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product", + Interface_Static::CVal("write.step.product.name")).c_str()); +} + ImportExportSettings::ImportExportSettings() { pGroup = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Import"); diff --git a/src/Mod/Part/App/ImportStep.h b/src/Mod/Part/App/ImportStep.h index 9815a62974..ddb984dce4 100644 --- a/src/Mod/Part/App/ImportStep.h +++ b/src/Mod/Part/App/ImportStep.h @@ -44,6 +44,8 @@ public: ObjectPerDocument = 3, ObjectPerDirectory = 4, }; + + static void initialize(); ImportExportSettings(); void setReadShapeCompoundMode(bool); bool getReadShapeCompoundMode() const; @@ -68,6 +70,11 @@ public: void setImportMode(ImportMode); ImportMode getImportMode() const; +private: + static void initGeneral(Base::Reference hGrp); + static void initSTEP(Base::Reference hGrp); + static void initIGES(Base::Reference hGrp); + private: ParameterGrp::handle pGroup; };