diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 1d29282757..8ec250198e 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #include @@ -355,7 +356,7 @@ private: if (file.hasExtension("stp") || file.hasExtension("step")) { //Interface_Static::SetCVal("write.step.schema", "AP214IS"); STEPCAFControl_Writer writer; - Interface_Static::SetIVal("write.step.assembly",1); + Part::Interface::writeStepAssembly(Part::Interface::Assembly::On); // writer.SetColorMode(Standard_False); writer.Transfer(hDoc, STEPControl_AsIs); @@ -379,9 +380,9 @@ private: IGESControl_Controller::Init(); IGESCAFControl_Writer writer; IGESData_GlobalSection header = writer.Model()->GlobalSection(); - header.SetAuthorName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.author"))); - header.SetCompanyName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.company"))); - header.SetSendName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product"))); + header.SetAuthorName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderAuthor())); + header.SetCompanyName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderCompany())); + header.SetSendName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderProduct())); writer.Model()->SetGlobalSection(header); writer.Transfer(hDoc); Standard_Boolean ret = writer.Write(name8bit.c_str()); diff --git a/src/Mod/Import/App/ExportOCAF.cpp b/src/Mod/Import/App/ExportOCAF.cpp index b237a4213c..3bff495ec4 100644 --- a/src/Mod/Import/App/ExportOCAF.cpp +++ b/src/Mod/Import/App/ExportOCAF.cpp @@ -87,6 +87,7 @@ #include #include #include +#include #include #include @@ -117,7 +118,7 @@ ExportOCAF::ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement) if (keepExplicitPlacement) { // rootLabel = aShapeTool->NewShape(); // TDataStd_Name::Set(rootLabel, "ASSEMBLY"); - Interface_Static::SetIVal("write.step.assembly",2); + Part::Interface::writeStepAssembly(Part::Interface::Assembly::Auto); } else { rootLabel = TDF_TagSource::NewChild(pDoc->Main()); diff --git a/src/Mod/Import/App/ImportOCAF2.cpp b/src/Mod/Import/App/ImportOCAF2.cpp index cf90d6c502..074b936501 100644 --- a/src/Mod/Import/App/ImportOCAF2.cpp +++ b/src/Mod/Import/App/ImportOCAF2.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -925,7 +926,7 @@ ExportOCAF2::ExportOCAF2(Handle(TDocStd_Document) h, GetShapeColorsFunc func) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(pDoc->Main()); aColorTool = XCAFDoc_DocumentTool::ColorTool(pDoc->Main()); - Interface_Static::SetIVal("write.step.assembly",2); + Part::Interface::writeStepAssembly(Part::Interface::Assembly::Auto); } /*! diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 9f27aaceb8..b5340a55cf 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -629,13 +630,13 @@ private: Base::FileInfo file(Utf8Name.c_str()); if (file.hasExtension("stp") || file.hasExtension("step")) { ParameterGrp::handle hGrp_stp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part/STEP"); - std::string scheme = hGrp_stp->GetASCII("Scheme", Interface_Static::CVal("write.step.schema")); + std::string scheme = hGrp_stp->GetASCII("Scheme", Part::Interface::writeStepScheme()); std::list supported = Part::supportedSTEPSchemes(); if (std::find(supported.begin(), supported.end(), scheme) != supported.end()) - Interface_Static::SetCVal("write.step.schema", scheme.c_str()); + Part::Interface::writeStepScheme(scheme.c_str()); STEPCAFControl_Writer writer; - Interface_Static::SetIVal("write.step.assembly",1); + Part::Interface::writeStepAssembly(Part::Interface::Assembly::On); // writer.SetColorMode(Standard_False); writer.Transfer(hDoc, STEPControl_AsIs); @@ -661,9 +662,9 @@ private: IGESControl_Controller::Init(); IGESCAFControl_Writer writer; IGESData_GlobalSection header = writer.Model()->GlobalSection(); - header.SetAuthorName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.author"))); - header.SetCompanyName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.company"))); - header.SetSendName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product"))); + header.SetAuthorName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderAuthor())); + header.SetCompanyName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderCompany())); + header.SetSendName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderProduct())); writer.Model()->SetGlobalSection(header); writer.Transfer(hDoc); Standard_Boolean ret = writer.Write((const char*)name8bit.c_str()); diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index de5b3a6a82..07d816e0ab 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -88,6 +88,7 @@ #include "GeometryPy.h" #include "ImportIges.h" #include "ImportStep.h" +#include "Interface.h" #include "modelRefine.h" #include "OCCError.h" #include "PartFeature.h" @@ -2103,17 +2104,17 @@ private: throw Py::Exception(); if (unit) { - if (!Interface_Static::SetCVal("write.iges.unit",unit)) { + if (!Interface::writeIgesUnit(unit)) { throw Py::RuntimeError("Failed to set 'write.iges.unit'"); } - if (!Interface_Static::SetCVal("write.step.unit",unit)) { + if (!Interface::writeStepUnit(unit)) { throw Py::RuntimeError("Failed to set 'write.step.unit'"); } } Py::Dict dict; - dict.setItem("write.iges.unit", Py::String(Interface_Static::CVal("write.iges.unit"))); - dict.setItem("write.step.unit", Py::String(Interface_Static::CVal("write.step.unit"))); + dict.setItem("write.iges.unit", Py::String(Interface::writeIgesUnit())); + dict.setItem("write.step.unit", Py::String(Interface::writeStepUnit())); return dict; } Py::Object setStaticValue(const Py::Tuple& args) diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index ecf13f8eba..8709bd8947 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -519,6 +519,8 @@ SET(Part_SRCS ImportIges.h ImportStep.cpp ImportStep.h + Interface.cpp + Interface.h PreCompiled.cpp PreCompiled.h ProgressIndicator.cpp diff --git a/src/Mod/Part/App/Interface.cpp b/src/Mod/Part/App/Interface.cpp new file mode 100644 index 0000000000..2127c4f445 --- /dev/null +++ b/src/Mod/Part/App/Interface.cpp @@ -0,0 +1,118 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include "Interface.h" + + +using namespace Part; + +void Interface::writeStepAssembly(Interface::Assembly mode) +{ + Interface_Static::SetIVal("write.step.assembly", static_cast(mode)); +} + +Standard_CString Interface::writeStepScheme() +{ + return Interface_Static::CVal("write.step.schema"); +} + +bool Interface::writeStepScheme(Standard_CString scheme) +{ + return Interface_Static::SetCVal("write.step.schema", scheme); +} + +bool Interface::writeStepUnit(Standard_CString unit) +{ + return Interface_Static::SetCVal("write.step.unit", unit); +} + +Standard_CString Interface::writeStepUnit() +{ + return Interface_Static::CVal("write.step.unit"); +} + +Standard_CString Interface::writeIgesHeaderAuthor() +{ + return Interface_Static::CVal("write.iges.header.author"); +} + +bool Interface::writeIgesHeaderAuthor(Standard_CString name) +{ + return Interface_Static::SetCVal("write.iges.header.author", name); +} + +Standard_CString Interface::writeIgesHeaderCompany() +{ + return Interface_Static::CVal("write.iges.header.company"); +} + +bool Interface::writeIgesHeaderCompany(Standard_CString name) +{ + return Interface_Static::SetCVal("write.iges.header.company", name); +} + +Standard_CString Interface::writeIgesHeaderProduct() +{ + return Interface_Static::CVal("write.iges.header.product"); +} + +bool Interface::writeIgesHeaderProduct(Standard_CString name) +{ + return Interface_Static::SetCVal("write.iges.header.product", name); +} + +bool Interface::writeIgesUnit(Standard_CString unit) +{ + return Interface_Static::SetCVal("write.iges.unit", unit); +} + +bool Interface::writeIgesUnit(Interface::Unit unit) +{ + switch (unit) { + case Unit::Meter: + return Interface_Static::SetCVal("write.iges.unit","M"); + case Unit::Inch: + return Interface_Static::SetCVal("write.iges.unit","INCH"); + default: + return Interface_Static::SetCVal("write.iges.unit","MM"); + } +} + +Standard_CString Interface::writeIgesUnit() +{ + return Interface_Static::CVal("write.iges.unit"); +} + +int Interface::writeIgesBrepMode() +{ + return Interface_Static::IVal("write.iges.brep.mode"); +} + +bool Interface::writeIgesBrepMode(int mode) +{ + return Interface_Static::SetIVal("write.iges.brep.mode", mode); +} diff --git a/src/Mod/Part/App/Interface.h b/src/Mod/Part/App/Interface.h new file mode 100644 index 0000000000..953159d90f --- /dev/null +++ b/src/Mod/Part/App/Interface.h @@ -0,0 +1,71 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef PART_INTERFACE_H +#define PART_INTERFACE_H + +#include +#include + + +namespace Part +{ + +class PartExport Interface +{ +public: + // See https://dev.opencascade.org/doc/overview/html/occt_user_guides__step.html + enum class Assembly { + Off = 0, /**< (Default) writes STEP files without assemblies */ + On = 1, /**< writes all shapes in the form of STEP assemblies */ + Auto = 2, /**< writes shapes having a structure of (possibly nested) + TopoDS_Compounds in the form of STEP assemblies, single + shapes are written without assembly structures */ + }; + enum class Unit { + Millimeter = 0, + Meter = 1, + Inch = 2, + }; + + static void writeStepAssembly(Assembly); + static Standard_CString writeStepScheme(); + static bool writeStepScheme(Standard_CString); + static Standard_CString writeStepUnit(); + static bool writeStepUnit(Standard_CString); + + static Standard_CString writeIgesHeaderAuthor(); + static bool writeIgesHeaderAuthor(Standard_CString); + static Standard_CString writeIgesHeaderCompany(); + static bool writeIgesHeaderCompany(Standard_CString); + static Standard_CString writeIgesHeaderProduct(); + static bool writeIgesHeaderProduct(Standard_CString); + static Standard_CString writeIgesUnit(); + static bool writeIgesUnit(Standard_CString); + static bool writeIgesUnit(Unit); + static int writeIgesBrepMode(); + static bool writeIgesBrepMode(int); +}; + +} //namespace Part + +#endif diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 24096e8ab3..f327a59dff 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -177,6 +177,7 @@ #include "CrossSection.h" #include "encodeFilename.h" #include "FaceMakerBullseye.h" +#include "Interface.h" #include "modelRefine.h" #include "PartPyCXX.h" #include "ProgressIndicator.h" @@ -911,9 +912,9 @@ void TopoShape::exportIges(const char *filename) const IGESControl_Controller::Init(); IGESControl_Writer aWriter; IGESData_GlobalSection header = aWriter.Model()->GlobalSection(); - header.SetAuthorName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.author"))); - header.SetCompanyName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.company"))); - header.SetSendName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product"))); + header.SetAuthorName(new TCollection_HAsciiString(Interface::writeIgesHeaderAuthor())); + header.SetCompanyName(new TCollection_HAsciiString(Interface::writeIgesHeaderCompany())); + header.SetSendName(new TCollection_HAsciiString(Interface::writeIgesHeaderProduct())); aWriter.Model()->SetGlobalSection(header); aWriter.AddShape(this->_Shape); aWriter.ComputeModel(); @@ -930,7 +931,7 @@ void TopoShape::exportStep(const char *filename) const try { // Fixes issue #6282 // Do not write out any assembly information when using the simplified STEP export - Interface_Static::SetIVal("write.step.assembly", 0); + Interface::writeStepAssembly(Interface::Assembly::Off); // write step file STEPControl_Writer aWriter; diff --git a/src/Mod/Part/Gui/DlgSettingsGeneral.cpp b/src/Mod/Part/Gui/DlgSettingsGeneral.cpp index 43b1e97a50..7ae06c77f0 100644 --- a/src/Mod/Part/Gui/DlgSettingsGeneral.cpp +++ b/src/Mod/Part/Gui/DlgSettingsGeneral.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "DlgSettingsGeneral.h" #include "ui_DlgSettingsGeneral.h" @@ -119,20 +120,10 @@ void DlgImportExportIges::saveSettings() Base::Reference hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("IGES"); hGrp->SetInt("Unit", unit); - switch (unit) { - 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; - } + Part::Interface::writeIgesUnit(static_cast(unit)); hGrp->SetBool("BrepMode", bg->checkedId() == 1); - Interface_Static::SetIVal("write.iges.brep.mode", bg->checkedId()); + Part::Interface::writeIgesBrepMode(bg->checkedId()); // Import hGrp->SetBool("SkipBlankEntities", ui->checkSkipBlank->isChecked()); @@ -140,11 +131,9 @@ void DlgImportExportIges::saveSettings() // header info hGrp->SetASCII("Company", ui->lineEditCompany->text().toLatin1()); hGrp->SetASCII("Author", ui->lineEditAuthor->text().toLatin1()); - //hGrp->SetASCII("Product", ui->lineEditProduct->text().toLatin1()); - Interface_Static::SetCVal("write.iges.header.company", ui->lineEditCompany->text().toLatin1()); - Interface_Static::SetCVal("write.iges.header.author", ui->lineEditAuthor->text().toLatin1()); - //Interface_Static::SetCVal("write.iges.header.product", ui->lineEditProduct->text().toLatin1()); + Part::Interface::writeIgesHeaderAuthor(ui->lineEditAuthor->text().toLatin1()); + Part::Interface::writeIgesHeaderCompany(ui->lineEditCompany->text().toLatin1()); } void DlgImportExportIges::loadSettings() @@ -154,7 +143,7 @@ void DlgImportExportIges::loadSettings() int unit = hGrp->GetInt("Unit", 0); ui->comboBoxUnits->setCurrentIndex(unit); - int value = Interface_Static::IVal("write.iges.brep.mode"); + int value = Part::Interface::writeIgesBrepMode(); bool brep = hGrp->GetBool("BrepMode", value > 0); if (brep) ui->radioButtonBRepOn->setChecked(true); @@ -166,12 +155,11 @@ void DlgImportExportIges::loadSettings() // header info ui->lineEditCompany->setText(QString::fromStdString(hGrp->GetASCII("Company", - Interface_Static::CVal("write.iges.header.company")))); + Part::Interface::writeIgesHeaderCompany()))); ui->lineEditAuthor->setText(QString::fromStdString(hGrp->GetASCII("Author", - Interface_Static::CVal("write.iges.header.author")))); - //ui->lineEditProduct->setText(QString::fromStdString(hGrp->GetASCII("Product"))); + Part::Interface::writeIgesHeaderAuthor()))); ui->lineEditProduct->setText(QString::fromLatin1( - Interface_Static::CVal("write.iges.header.product"))); + Part::Interface::writeIgesHeaderProduct())); } /**