Import: move STEP reader & writer to own classes
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wextra-semi"
|
||||
#endif
|
||||
#include <APIHeaderSection_MakeHeader.hxx>
|
||||
#include <IGESCAFControl_Reader.hxx>
|
||||
#include <IGESCAFControl_Writer.hxx>
|
||||
#include <IGESControl_Controller.hxx>
|
||||
@@ -39,8 +38,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 <TDocStd_Document.hxx>
|
||||
@@ -74,7 +71,9 @@
|
||||
|
||||
#include "ImportOCAF2.h"
|
||||
#include "ReaderGltf.h"
|
||||
#include "ReaderStep.h"
|
||||
#include "WriterGltf.h"
|
||||
#include "WriterStep.h"
|
||||
|
||||
namespace Import
|
||||
{
|
||||
@@ -177,25 +176,8 @@ private:
|
||||
|
||||
if (file.hasExtension({"stp", "step"})) {
|
||||
try {
|
||||
STEPCAFControl_Reader aReader;
|
||||
aReader.SetColorMode(true);
|
||||
aReader.SetNameMode(true);
|
||||
aReader.SetLayerMode(true);
|
||||
if (aReader.ReadFile((Standard_CString)(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());
|
||||
@@ -389,35 +371,8 @@ private:
|
||||
|
||||
Base::FileInfo file(Utf8Name.c_str());
|
||||
if (file.hasExtension({"stp", "step"})) {
|
||||
STEPCAFControl_Writer writer;
|
||||
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
|
||||
writer.Transfer(hDoc, STEPControl_AsIs);
|
||||
|
||||
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();
|
||||
|
||||
@@ -37,6 +37,8 @@ SET(Import_SRCS
|
||||
#ImportOCAFAssembly.h
|
||||
ReaderGltf.cpp
|
||||
ReaderGltf.h
|
||||
ReaderStep.cpp
|
||||
ReaderStep.h
|
||||
StepShapePy.xml
|
||||
StepShape.h
|
||||
StepShape.cpp
|
||||
@@ -45,6 +47,8 @@ SET(Import_SRCS
|
||||
PreCompiled.h
|
||||
WriterGltf.cpp
|
||||
WriterGltf.h
|
||||
WriterStep.cpp
|
||||
WriterStep.h
|
||||
dxf/ImpExpDxf.cpp
|
||||
dxf/ImpExpDxf.h
|
||||
dxf/dxf.cpp
|
||||
|
||||
67
src/Mod/Import/App/ReaderStep.cpp
Normal file
67
src/Mod/Import/App/ReaderStep.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <Standard_Version.hxx>
|
||||
#include <STEPCAFControl_Reader.hxx>
|
||||
#include <XSControl_TransferReader.hxx>
|
||||
#include <XSControl_WorkSession.hxx>
|
||||
#endif
|
||||
|
||||
#include "ReaderStep.h"
|
||||
#include <Base/Exception.h>
|
||||
#include <Mod/Part/App/encodeFilename.h>
|
||||
#include <Mod/Part/App/ProgressIndicator.h>
|
||||
|
||||
using namespace Import;
|
||||
|
||||
ReaderStep::ReaderStep(const Base::FileInfo& file) // NOLINT
|
||||
: file {file}
|
||||
{}
|
||||
|
||||
void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT
|
||||
{
|
||||
std::string utf8Name = file.filePath();
|
||||
std::string name8bit = Part::encodeFilename(utf8Name);
|
||||
STEPCAFControl_Reader aReader;
|
||||
aReader.SetColorMode(true);
|
||||
aReader.SetNameMode(true);
|
||||
aReader.SetLayerMode(true);
|
||||
aReader.SetSHUOMode(true);
|
||||
if (aReader.ReadFile(name8bit.c_str()) != IFSelect_RetDone) {
|
||||
throw Base::FileException("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
|
||||
}
|
||||
47
src/Mod/Import/App/ReaderStep.h
Normal file
47
src/Mod/Import/App/ReaderStep.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef IMPORT_READER_STEP_H
|
||||
#define IMPORT_READER_STEP_H
|
||||
|
||||
#include <Mod/Import/ImportGlobal.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <TDocStd_Document.hxx>
|
||||
|
||||
namespace Import
|
||||
{
|
||||
|
||||
class ImportExport ReaderStep
|
||||
{
|
||||
public:
|
||||
explicit ReaderStep(const Base::FileInfo& file);
|
||||
|
||||
void read(Handle(TDocStd_Document) hDoc);
|
||||
|
||||
private:
|
||||
Base::FileInfo file;
|
||||
};
|
||||
|
||||
} // namespace Import
|
||||
|
||||
#endif // IMPORT_READER_STEP_H
|
||||
72
src/Mod/Import/App/WriterStep.cpp
Normal file
72
src/Mod/Import/App/WriterStep.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <APIHeaderSection_MakeHeader.hxx>
|
||||
#include <STEPCAFControl_Writer.hxx>
|
||||
#endif
|
||||
|
||||
#include "WriterStep.h"
|
||||
#include <Base/Exception.h>
|
||||
#include <App/Application.h>
|
||||
#include <Mod/Part/App/Interface.h>
|
||||
|
||||
using namespace Import;
|
||||
|
||||
WriterStep::WriterStep(const Base::FileInfo& file) // NOLINT
|
||||
: file {file}
|
||||
{}
|
||||
|
||||
void WriterStep::write(Handle(TDocStd_Document) hDoc) const // NOLINT
|
||||
{
|
||||
STEPCAFControl_Writer writer;
|
||||
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
|
||||
writer.Transfer(hDoc, STEPControl_AsIs);
|
||||
|
||||
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) {
|
||||
std::string utf8Name = file.filePath();
|
||||
throw Base::FileException("Cannot open file '%s'", utf8Name.c_str());
|
||||
}
|
||||
}
|
||||
47
src/Mod/Import/App/WriterStep.h
Normal file
47
src/Mod/Import/App/WriterStep.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of FreeCAD. *
|
||||
* *
|
||||
* FreeCAD is free software: you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 2.1 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* FreeCAD 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with FreeCAD. If not, see *
|
||||
* <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef IMPORT_WRITER_STEP_H
|
||||
#define IMPORT_WRITER_STEP_H
|
||||
|
||||
#include <Mod/Import/ImportGlobal.h>
|
||||
#include <Base/FileInfo.h>
|
||||
#include <TDocStd_Document.hxx>
|
||||
|
||||
namespace Import
|
||||
{
|
||||
|
||||
class ImportExport WriterStep
|
||||
{
|
||||
public:
|
||||
WriterStep(const Base::FileInfo& file);
|
||||
|
||||
void write(Handle(TDocStd_Document) hDoc) const;
|
||||
|
||||
private:
|
||||
std::string name8bit;
|
||||
Base::FileInfo file;
|
||||
};
|
||||
} // namespace Import
|
||||
|
||||
#endif // IMPORT_WRITER_GLTF_H
|
||||
@@ -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