Import: move STEP reader & writer to own classes
This commit is contained in:
@@ -45,7 +45,6 @@
|
||||
#pragma clang diagnostic ignored "-Wextra-semi"
|
||||
#endif
|
||||
|
||||
#include <APIHeaderSection_MakeHeader.hxx>
|
||||
#include <IGESCAFControl_Reader.hxx>
|
||||
#include <IGESCAFControl_Writer.hxx>
|
||||
#include <IGESControl_Controller.hxx>
|
||||
@@ -54,8 +53,6 @@
|
||||
#include <IGESToBRep_Actor.hxx>
|
||||
#include <Interface_Static.hxx>
|
||||
#include <OSD_Exception.hxx>
|
||||
#include <STEPCAFControl_Reader.hxx>
|
||||
#include <STEPCAFControl_Writer.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
#include <TColStd_IndexedDataMapOfStringString.hxx>
|
||||
#include <TDF_AttributeIterator.hxx>
|
||||
@@ -106,6 +103,8 @@
|
||||
#include <Mod/Import/App/ImportOCAF2.h>
|
||||
#include <Mod/Import/App/ReaderGltf.h>
|
||||
#include <Mod/Import/App/WriterGltf.h>
|
||||
#include <Mod/Import/App/ReaderStep.h>
|
||||
#include <Mod/Import/App/WriterStep.h>
|
||||
#include <Mod/Part/App/ImportIges.h>
|
||||
#include <Mod/Part/App/ImportStep.h>
|
||||
#include <Mod/Part/App/Interface.h>
|
||||
@@ -453,25 +452,8 @@ private:
|
||||
}
|
||||
|
||||
try {
|
||||
STEPCAFControl_Reader aReader;
|
||||
aReader.SetColorMode(true);
|
||||
aReader.SetNameMode(true);
|
||||
aReader.SetLayerMode(true);
|
||||
aReader.SetSHUOMode(true);
|
||||
if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) {
|
||||
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
|
||||
}
|
||||
|
||||
#if OCC_VERSION_HEX < 0x070500
|
||||
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
|
||||
aReader.Reader().WS()->MapReader()->SetProgress(pi);
|
||||
pi->NewScope(100, "Reading STEP file...");
|
||||
pi->Show();
|
||||
#endif
|
||||
aReader.Transfer(hDoc);
|
||||
#if OCC_VERSION_HEX < 0x070500
|
||||
pi->EndScope();
|
||||
#endif
|
||||
Import::ReaderStep reader(file);
|
||||
reader.read(hDoc);
|
||||
}
|
||||
catch (OSD_Exception& e) {
|
||||
Base::Console().Error("%s\n", e.GetMessageString());
|
||||
@@ -716,46 +698,16 @@ private:
|
||||
|
||||
Base::FileInfo file(Utf8Name.c_str());
|
||||
if (file.hasExtension({"stp", "step"})) {
|
||||
ParameterGrp::handle hGrp_stp = App::GetApplication().GetParameterGroupByPath(
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Part/STEP");
|
||||
std::string scheme =
|
||||
hGrp_stp->GetASCII("Scheme", Part::Interface::writeStepScheme());
|
||||
std::string scheme = hGrp->GetASCII("Scheme", Part::Interface::writeStepScheme());
|
||||
std::list<std::string> supported = Part::supportedSTEPSchemes();
|
||||
if (std::find(supported.begin(), supported.end(), scheme) != supported.end()) {
|
||||
Part::Interface::writeStepScheme(scheme.c_str());
|
||||
}
|
||||
|
||||
STEPCAFControl_Writer writer;
|
||||
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
|
||||
writer.Transfer(hDoc, STEPControl_AsIs);
|
||||
|
||||
// edit STEP header
|
||||
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("Mod/Part")
|
||||
->GetGroup("STEP");
|
||||
|
||||
// Don't set name because STEP doesn't support UTF-8
|
||||
// https://forum.freecad.org/viewtopic.php?f=8&t=52967
|
||||
makeHeader.SetAuthorValue(
|
||||
1,
|
||||
new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str()));
|
||||
makeHeader.SetOrganizationValue(
|
||||
1,
|
||||
new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str()));
|
||||
makeHeader.SetOriginatingSystem(
|
||||
new TCollection_HAsciiString(App::Application::getExecutableName().c_str()));
|
||||
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
||||
IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str());
|
||||
if (ret == IFSelect_RetError || ret == IFSelect_RetFail
|
||||
|| ret == IFSelect_RetStop) {
|
||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
||||
throw Py::Exception();
|
||||
}
|
||||
Import::WriterStep writer(file);
|
||||
writer.write(hDoc);
|
||||
}
|
||||
else if (file.hasExtension({"igs", "iges"})) {
|
||||
IGESControl_Controller::Init();
|
||||
@@ -807,25 +759,8 @@ private:
|
||||
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
|
||||
|
||||
if (file.hasExtension({"stp", "step"})) {
|
||||
STEPCAFControl_Reader aReader;
|
||||
aReader.SetColorMode(true);
|
||||
aReader.SetNameMode(true);
|
||||
aReader.SetLayerMode(true);
|
||||
aReader.SetSHUOMode(true);
|
||||
if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) {
|
||||
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
|
||||
}
|
||||
|
||||
#if OCC_VERSION_HEX < 0x070500
|
||||
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
|
||||
aReader.Reader().WS()->MapReader()->SetProgress(pi);
|
||||
pi->NewScope(100, "Reading STEP file...");
|
||||
pi->Show();
|
||||
#endif
|
||||
aReader.Transfer(hDoc);
|
||||
#if OCC_VERSION_HEX < 0x070500
|
||||
pi->EndScope();
|
||||
#endif
|
||||
Import::ReaderStep reader(file);
|
||||
reader.read(hDoc);
|
||||
}
|
||||
else if (file.hasExtension({"igs", "iges"})) {
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
|
||||
|
||||
Reference in New Issue
Block a user