Import: Apply clang format
This commit is contained in:
@@ -22,121 +22,137 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#if defined(__MINGW32__)
|
||||
# define WNT // avoid conflict with GUID
|
||||
#define WNT// avoid conflict with GUID
|
||||
#endif
|
||||
#ifndef _PreComp_
|
||||
# include <climits>
|
||||
# if defined(__clang__)
|
||||
# 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>
|
||||
# include <IGESData_GlobalSection.hxx>
|
||||
# include <IGESData_IGESModel.hxx>
|
||||
# include <IGESToBRep_Actor.hxx>
|
||||
# include <Interface_Static.hxx>
|
||||
# include <OSD_Exception.hxx>
|
||||
# include <Standard_Version.hxx>
|
||||
# include <STEPCAFControl_Reader.hxx>
|
||||
# include <STEPCAFControl_Writer.hxx>
|
||||
# include <TColStd_IndexedDataMapOfStringString.hxx>
|
||||
# include <TDocStd_Document.hxx>
|
||||
# include <Transfer_TransientProcess.hxx>
|
||||
# include <XCAFApp_Application.hxx>
|
||||
# include <XCAFDoc_DocumentTool.hxx>
|
||||
# include <XSControl_TransferReader.hxx>
|
||||
# include <XSControl_WorkSession.hxx>
|
||||
# if OCC_VERSION_HEX >= 0x070500
|
||||
# include <Message_ProgressRange.hxx>
|
||||
# include <RWGltf_CafWriter.hxx>
|
||||
# endif
|
||||
# if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
# endif
|
||||
#include <climits>
|
||||
#if defined(__clang__)
|
||||
#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>
|
||||
#include <IGESData_GlobalSection.hxx>
|
||||
#include <IGESData_IGESModel.hxx>
|
||||
#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>
|
||||
#include <Transfer_TransientProcess.hxx>
|
||||
#include <XCAFApp_Application.hxx>
|
||||
#include <XCAFDoc_DocumentTool.hxx>
|
||||
#include <XSControl_TransferReader.hxx>
|
||||
#include <XSControl_WorkSession.hxx>
|
||||
#if OCC_VERSION_HEX >= 0x070500
|
||||
#include <Message_ProgressRange.hxx>
|
||||
#include <RWGltf_CafWriter.hxx>
|
||||
#endif
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "dxf/ImpExpDxf.h"
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/PyWrapParseTupleAndKeywords.h>
|
||||
#include "dxf/ImpExpDxf.h"
|
||||
#include <Mod/Part/App/encodeFilename.h>
|
||||
#include <Mod/Part/App/ImportIges.h>
|
||||
#include <Mod/Part/App/ImportStep.h>
|
||||
#include <Mod/Part/App/Interface.h>
|
||||
#include <Mod/Part/App/OCAF/ImportExportSettings.h>
|
||||
#include <Mod/Part/App/PartFeaturePy.h>
|
||||
#include <Mod/Part/App/ProgressIndicator.h>
|
||||
#include <Mod/Part/App/TopoShapePy.h>
|
||||
#include <Mod/Part/App/PartFeaturePy.h>
|
||||
#include <Mod/Part/App/OCAF/ImportExportSettings.h>
|
||||
#include <Mod/Part/App/encodeFilename.h>
|
||||
|
||||
#include "ImportOCAF2.h"
|
||||
|
||||
|
||||
namespace Import {
|
||||
namespace Import
|
||||
{
|
||||
|
||||
class ImportOCAFExt : public Import::ImportOCAF2
|
||||
class ImportOCAFExt: public Import::ImportOCAF2
|
||||
{
|
||||
public:
|
||||
ImportOCAFExt(Handle(TDocStd_Document) hStdDoc, App::Document* doc, const std::string& name)
|
||||
: ImportOCAF2(hStdDoc, doc, name)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
std::map<Part::Feature*, std::vector<App::Color> > partColors;
|
||||
std::map<Part::Feature*, std::vector<App::Color>> partColors;
|
||||
|
||||
private:
|
||||
void applyFaceColors(Part::Feature* part, const std::vector<App::Color>& colors) override {
|
||||
void applyFaceColors(Part::Feature* part, const std::vector<App::Color>& colors) override
|
||||
{
|
||||
partColors[part] = colors;
|
||||
}
|
||||
};
|
||||
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
class Module: public Py::ExtensionModule<Module>
|
||||
{
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("Import")
|
||||
Module()
|
||||
: Py::ExtensionModule<Module>("Import")
|
||||
{
|
||||
add_keyword_method("open",&Module::importer,
|
||||
"open(string) -- Open the file and create a new document."
|
||||
);
|
||||
add_keyword_method("insert",&Module::importer,
|
||||
"insert(string,string) -- Insert the file into the given document."
|
||||
);
|
||||
add_keyword_method("export",&Module::exporter,
|
||||
"export(list,string) -- Export a list of objects into a single file."
|
||||
);
|
||||
add_varargs_method("readDXF",&Module::readDXF,
|
||||
"readDXF(filename,[document,ignore_errors,option_source]): Imports a DXF file into the given document. ignore_errors is True by default."
|
||||
);
|
||||
add_varargs_method("writeDXFShape",&Module::writeDXFShape,
|
||||
"writeDXFShape([shape],filename [version,usePolyline,optionSource]): Exports Shape(s) to a DXF file."
|
||||
);
|
||||
add_varargs_method("writeDXFObject",&Module::writeDXFObject,
|
||||
"writeDXFObject([objects],filename [,version,usePolyline,optionSource]): Exports DocumentObject(s) to a DXF file."
|
||||
);
|
||||
initialize("This module is the Import module."); // register with Python
|
||||
add_keyword_method("open",
|
||||
&Module::importer,
|
||||
"open(string) -- Open the file and create a new document.");
|
||||
add_keyword_method("insert",
|
||||
&Module::importer,
|
||||
"insert(string,string) -- Insert the file into the given document.");
|
||||
add_keyword_method("export",
|
||||
&Module::exporter,
|
||||
"export(list,string) -- Export a list of objects into a single file.");
|
||||
add_varargs_method("readDXF",
|
||||
&Module::readDXF,
|
||||
"readDXF(filename,[document,ignore_errors,option_source]): Imports a "
|
||||
"DXF file into the given document. ignore_errors is True by default.");
|
||||
add_varargs_method("writeDXFShape",
|
||||
&Module::writeDXFShape,
|
||||
"writeDXFShape([shape],filename [version,usePolyline,optionSource]): "
|
||||
"Exports Shape(s) to a DXF file.");
|
||||
add_varargs_method(
|
||||
"writeDXFObject",
|
||||
&Module::writeDXFObject,
|
||||
"writeDXFObject([objects],filename [,version,usePolyline,optionSource]): Exports "
|
||||
"DocumentObject(s) to a DXF file.");
|
||||
initialize("This module is the Import module.");// register with Python
|
||||
}
|
||||
|
||||
~Module() override = default;
|
||||
|
||||
private:
|
||||
Py::Object importer(const Py::Tuple& args, const Py::Dict &kwds)
|
||||
Py::Object importer(const Py::Tuple& args, const Py::Dict& kwds)
|
||||
{
|
||||
char* Name;
|
||||
char* DocName=nullptr;
|
||||
PyObject *importHidden = Py_None;
|
||||
PyObject *merge = Py_None;
|
||||
PyObject *useLinkGroup = Py_None;
|
||||
char* DocName = nullptr;
|
||||
PyObject* importHidden = Py_None;
|
||||
PyObject* merge = Py_None;
|
||||
PyObject* useLinkGroup = Py_None;
|
||||
int mode = -1;
|
||||
static const std::array<const char *, 7> kwd_list {"name", "docName", "importHidden", "merge",
|
||||
"useLinkGroup", "mode", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "et|sO!O!O!i",
|
||||
kwd_list, "utf-8", &Name, &DocName, &PyBool_Type, &importHidden,
|
||||
&PyBool_Type, &merge,
|
||||
&PyBool_Type, &useLinkGroup, &mode)) {
|
||||
static const std::array<const char*, 7>
|
||||
kwd_list {"name", "docName", "importHidden", "merge", "useLinkGroup", "mode", nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(),
|
||||
kwds.ptr(),
|
||||
"et|sO!O!O!i",
|
||||
kwd_list,
|
||||
"utf-8",
|
||||
&Name,
|
||||
&DocName,
|
||||
&PyBool_Type,
|
||||
&importHidden,
|
||||
&PyBool_Type,
|
||||
&merge,
|
||||
&PyBool_Type,
|
||||
&useLinkGroup,
|
||||
&mode)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
@@ -147,7 +163,7 @@ private:
|
||||
try {
|
||||
Base::FileInfo file(Utf8Name.c_str());
|
||||
|
||||
App::Document *pcDoc = nullptr;
|
||||
App::Document* pcDoc = nullptr;
|
||||
if (DocName) {
|
||||
pcDoc = App::GetApplication().getDocument(DocName);
|
||||
}
|
||||
@@ -165,7 +181,8 @@ private:
|
||||
aReader.SetColorMode(true);
|
||||
aReader.SetNameMode(true);
|
||||
aReader.SetLayerMode(true);
|
||||
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
|
||||
if (aReader.ReadFile((Standard_CString)(name8bit.c_str()))
|
||||
!= IFSelect_RetDone) {
|
||||
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
|
||||
}
|
||||
|
||||
@@ -184,24 +201,29 @@ private:
|
||||
Base::Console().Error("%s\n", e.GetMessageString());
|
||||
Base::Console().Message("Try to load STEP file without colors...\n");
|
||||
|
||||
Part::ImportStepParts(pcDoc,Utf8Name.c_str());
|
||||
Part::ImportStepParts(pcDoc, Utf8Name.c_str());
|
||||
pcDoc->recompute();
|
||||
}
|
||||
}
|
||||
else if (file.hasExtension({"igs", "iges"})) {
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("IGES");
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
|
||||
.GetUserParameter()
|
||||
.GetGroup("BaseApp")
|
||||
->GetGroup("Preferences")
|
||||
->GetGroup("Mod/Part")
|
||||
->GetGroup("IGES");
|
||||
|
||||
try {
|
||||
IGESControl_Controller::Init();
|
||||
IGESCAFControl_Reader aReader;
|
||||
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
|
||||
aReader.SetReadVisible(hGrp->GetBool("SkipBlankEntities", true)
|
||||
? Standard_True : Standard_False);
|
||||
aReader.SetReadVisible(
|
||||
hGrp->GetBool("SkipBlankEntities", true) ? Standard_True : Standard_False);
|
||||
aReader.SetColorMode(true);
|
||||
aReader.SetNameMode(true);
|
||||
aReader.SetLayerMode(true);
|
||||
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
|
||||
if (aReader.ReadFile((Standard_CString)(name8bit.c_str()))
|
||||
!= IFSelect_RetDone) {
|
||||
throw Py::Exception(PyExc_IOError, "cannot read IGES file");
|
||||
}
|
||||
|
||||
@@ -217,13 +239,13 @@ private:
|
||||
#endif
|
||||
// http://opencascade.blogspot.de/2009/03/unnoticeable-memory-leaks-part-2.html
|
||||
Handle(IGESToBRep_Actor)::DownCast(aReader.WS()->TransferReader()->Actor())
|
||||
->SetModel(new IGESData_IGESModel);
|
||||
->SetModel(new IGESData_IGESModel);
|
||||
}
|
||||
catch (OSD_Exception& e) {
|
||||
Base::Console().Error("%s\n", e.GetMessageString());
|
||||
Base::Console().Message("Try to load IGES file without colors...\n");
|
||||
|
||||
Part::ImportIgesParts(pcDoc,Utf8Name.c_str());
|
||||
Part::ImportIgesParts(pcDoc, Utf8Name.c_str());
|
||||
pcDoc->recompute();
|
||||
}
|
||||
}
|
||||
@@ -233,21 +255,25 @@ private:
|
||||
|
||||
ImportOCAFExt ocaf(hDoc, pcDoc, file.fileNamePure());
|
||||
ocaf.setImportOptions(ImportOCAFExt::customImportOptions());
|
||||
if (merge != Py_None)
|
||||
if (merge != Py_None) {
|
||||
ocaf.setMerge(Base::asBoolean(merge));
|
||||
if (importHidden != Py_None)
|
||||
}
|
||||
if (importHidden != Py_None) {
|
||||
ocaf.setImportHiddenObject(Base::asBoolean(importHidden));
|
||||
if (useLinkGroup != Py_None)
|
||||
}
|
||||
if (useLinkGroup != Py_None) {
|
||||
ocaf.setUseLinkGroup(Base::asBoolean(useLinkGroup));
|
||||
if (mode >= 0)
|
||||
}
|
||||
if (mode >= 0) {
|
||||
ocaf.setMode(mode);
|
||||
}
|
||||
ocaf.loadShapes();
|
||||
|
||||
hApp->Close(hDoc);
|
||||
|
||||
if (!ocaf.partColors.empty()) {
|
||||
Py::List list;
|
||||
for (auto &it : ocaf.partColors) {
|
||||
for (auto& it : ocaf.partColors) {
|
||||
Py::Tuple tuple(2);
|
||||
tuple.setItem(0, Py::asObject(it.first->getPyObject()));
|
||||
|
||||
@@ -271,19 +297,32 @@ private:
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
Py::Object exporter(const Py::Tuple& args, const Py::Dict &kwds)
|
||||
Py::Object exporter(const Py::Tuple& args, const Py::Dict& kwds)
|
||||
{
|
||||
PyObject* object;
|
||||
char* Name;
|
||||
PyObject *exportHidden = Py_None;
|
||||
PyObject *legacy = Py_None;
|
||||
PyObject *keepPlacement = Py_None;
|
||||
static const std::array<const char *, 6> kwd_list{"obj", "name", "exportHidden", "legacy", "keepPlacement",
|
||||
PyObject* exportHidden = Py_None;
|
||||
PyObject* legacy = Py_None;
|
||||
PyObject* keepPlacement = Py_None;
|
||||
static const std::array<const char*, 6> kwd_list {"obj",
|
||||
"name",
|
||||
"exportHidden",
|
||||
"legacy",
|
||||
"keepPlacement",
|
||||
nullptr};
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "Oet|O!O!O!",
|
||||
kwd_list, &object, "utf-8", &Name, &PyBool_Type, &exportHidden,
|
||||
&PyBool_Type, &legacy,
|
||||
&PyBool_Type, &keepPlacement)) {
|
||||
if (!Base::Wrapped_ParseTupleAndKeywords(args.ptr(),
|
||||
kwds.ptr(),
|
||||
"Oet|O!O!O!",
|
||||
kwd_list,
|
||||
&object,
|
||||
"utf-8",
|
||||
&Name,
|
||||
&PyBool_Type,
|
||||
&exportHidden,
|
||||
&PyBool_Type,
|
||||
&legacy,
|
||||
&PyBool_Type,
|
||||
&keepPlacement)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
@@ -300,8 +339,10 @@ private:
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
PyObject* item = (*it).ptr();
|
||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type)))
|
||||
objs.push_back(static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr());
|
||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||
objs.push_back(
|
||||
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr());
|
||||
}
|
||||
}
|
||||
|
||||
if (legacy == Py_None) {
|
||||
@@ -313,10 +354,12 @@ private:
|
||||
if (!Base::asBoolean(legacy) || !ocaf.canFallback(objs)) {
|
||||
ocaf.setExportOptions(ExportOCAF2::customExportOptions());
|
||||
|
||||
if (exportHidden != Py_None)
|
||||
if (exportHidden != Py_None) {
|
||||
ocaf.setExportHiddenObject(Base::asBoolean(exportHidden));
|
||||
if (keepPlacement != Py_None)
|
||||
}
|
||||
if (keepPlacement != Py_None) {
|
||||
ocaf.setKeepPlacement(Base::asBoolean(keepPlacement));
|
||||
}
|
||||
|
||||
ocaf.exportObjects(objs);
|
||||
}
|
||||
@@ -324,17 +367,19 @@ private:
|
||||
bool keepExplicitPlacement = Standard_True;
|
||||
ExportOCAF ocaf(hDoc, keepExplicitPlacement);
|
||||
// That stuff is exporting a list of selected objects into FreeCAD Tree
|
||||
std::vector <TDF_Label> hierarchical_label;
|
||||
std::vector <TopLoc_Location> hierarchical_loc;
|
||||
std::vector <App::DocumentObject*> hierarchical_part;
|
||||
for(auto obj : objs)
|
||||
ocaf.exportObject(obj,hierarchical_label, hierarchical_loc,hierarchical_part);
|
||||
std::vector<TDF_Label> hierarchical_label;
|
||||
std::vector<TopLoc_Location> hierarchical_loc;
|
||||
std::vector<App::DocumentObject*> hierarchical_part;
|
||||
for (auto obj : objs) {
|
||||
ocaf.exportObject(obj, hierarchical_label, hierarchical_loc, hierarchical_part);
|
||||
}
|
||||
|
||||
// Free Shapes must have absolute placement and not explicit
|
||||
std::vector <TDF_Label> FreeLabels;
|
||||
std::vector <int> part_id;
|
||||
ocaf.getFreeLabels(hierarchical_label,FreeLabels, part_id);
|
||||
// Update is not performed automatically anymore: https://tracker.dev.opencascade.org/view.php?id=28055
|
||||
std::vector<TDF_Label> FreeLabels;
|
||||
std::vector<int> part_id;
|
||||
ocaf.getFreeLabels(hierarchical_label, FreeLabels, part_id);
|
||||
// Update is not performed automatically anymore:
|
||||
// https://tracker.dev.opencascade.org/view.php?id=28055
|
||||
XCAFDoc_DocumentTool::ShapeTool(hDoc->Main())->UpdateAssemblies();
|
||||
}
|
||||
|
||||
@@ -345,17 +390,27 @@ private:
|
||||
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");
|
||||
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.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) {
|
||||
if (ret == IFSelect_RetError || ret == IFSelect_RetFail
|
||||
|| ret == IFSelect_RetStop) {
|
||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
||||
throw Py::Exception();
|
||||
}
|
||||
@@ -364,9 +419,12 @@ private:
|
||||
IGESControl_Controller::Init();
|
||||
IGESCAFControl_Writer writer;
|
||||
IGESData_GlobalSection header = writer.Model()->GlobalSection();
|
||||
header.SetAuthorName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderAuthor()));
|
||||
header.SetCompanyName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderCompany()));
|
||||
header.SetSendName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderProduct()));
|
||||
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());
|
||||
@@ -378,15 +436,16 @@ private:
|
||||
else if (file.hasExtension({"glb", "gltf"})) {
|
||||
#if OCC_VERSION_HEX >= 0x070500
|
||||
TColStd_IndexedDataMapOfStringString aMetadata;
|
||||
RWGltf_CafWriter aWriter (name8bit.c_str(), file.hasExtension("glb"));
|
||||
aWriter.SetTransformationFormat (RWGltf_WriterTrsfFormat_Compact);
|
||||
RWGltf_CafWriter aWriter(name8bit.c_str(), file.hasExtension("glb"));
|
||||
aWriter.SetTransformationFormat(RWGltf_WriterTrsfFormat_Compact);
|
||||
// https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#coordinate-system-and-units
|
||||
aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (0.001);
|
||||
aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (RWMesh_CoordinateSystem_Zup);
|
||||
aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit(0.001);
|
||||
aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem(
|
||||
RWMesh_CoordinateSystem_Zup);
|
||||
#if OCC_VERSION_HEX >= 0x070700
|
||||
aWriter.SetParallel(true);
|
||||
#endif
|
||||
Standard_Boolean ret = aWriter.Perform (hDoc, aMetadata, Message_ProgressRange());
|
||||
Standard_Boolean ret = aWriter.Perform(hDoc, aMetadata, Message_ProgressRange());
|
||||
if (!ret) {
|
||||
PyErr_Format(PyExc_IOError, "Cannot save to file '%s'", Utf8Name.c_str());
|
||||
throw Py::Exception();
|
||||
@@ -412,34 +471,46 @@ private:
|
||||
Py::Object readDXF(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
const char* DocName=nullptr;
|
||||
const char* DocName = nullptr;
|
||||
const char* optionSource = nullptr;
|
||||
std::string defaultOptions = "User parameter:BaseApp/Preferences/Mod/Draft";
|
||||
bool IgnoreErrors=true;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et|sbs","utf-8",&Name,&DocName,&IgnoreErrors,&optionSource))
|
||||
bool IgnoreErrors = true;
|
||||
if (!PyArg_ParseTuple(args.ptr(),
|
||||
"et|sbs",
|
||||
"utf-8",
|
||||
&Name,
|
||||
&DocName,
|
||||
&IgnoreErrors,
|
||||
&optionSource)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
Base::FileInfo file(EncodedName.c_str());
|
||||
if (!file.exists())
|
||||
if (!file.exists()) {
|
||||
throw Py::RuntimeError("File doesn't exist");
|
||||
}
|
||||
|
||||
if (optionSource)
|
||||
if (optionSource) {
|
||||
defaultOptions = optionSource;
|
||||
}
|
||||
|
||||
App::Document *pcDoc;
|
||||
if (DocName)
|
||||
App::Document* pcDoc;
|
||||
if (DocName) {
|
||||
pcDoc = App::GetApplication().getDocument(DocName);
|
||||
else
|
||||
}
|
||||
else {
|
||||
pcDoc = App::GetApplication().getActiveDocument();
|
||||
if (!pcDoc)
|
||||
}
|
||||
if (!pcDoc) {
|
||||
pcDoc = App::GetApplication().newDocument(DocName);
|
||||
}
|
||||
|
||||
try {
|
||||
// read the DXF file
|
||||
ImpExpDxfRead dxf_file(EncodedName,pcDoc);
|
||||
ImpExpDxfRead dxf_file(EncodedName, pcDoc);
|
||||
dxf_file.setOptionSource(defaultOptions);
|
||||
dxf_file.setOptions();
|
||||
dxf_file.DoRead(IgnoreErrors);
|
||||
@@ -456,35 +527,36 @@ private:
|
||||
|
||||
Py::Object writeDXFShape(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *shapeObj;
|
||||
PyObject* shapeObj;
|
||||
char* fname;
|
||||
std::string filePath;
|
||||
std::string layerName;
|
||||
const char* optionSource = nullptr;
|
||||
std::string defaultOptions = "User parameter:BaseApp/Preferences/Mod/Import";
|
||||
int versionParm = -1;
|
||||
bool versionOverride = false;
|
||||
bool polyOverride = false;
|
||||
PyObject *usePolyline = Py_False;
|
||||
int versionParm = -1;
|
||||
bool versionOverride = false;
|
||||
bool polyOverride = false;
|
||||
PyObject* usePolyline = Py_False;
|
||||
|
||||
//handle list of shapes
|
||||
if (PyArg_ParseTuple(args.ptr(), "O!et|iOs", &(PyList_Type) ,
|
||||
&shapeObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
// handle list of shapes
|
||||
if (PyArg_ParseTuple(args.ptr(),
|
||||
"O!et|iOs",
|
||||
&(PyList_Type),
|
||||
&shapeObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
filePath = std::string(fname);
|
||||
layerName = "none";
|
||||
PyMem_Free(fname);
|
||||
|
||||
if ((versionParm == 12) ||
|
||||
(versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
if ((versionParm == 12) || (versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
}
|
||||
if (usePolyline == Py_True) {
|
||||
polyOverride = true;
|
||||
polyOverride = true;
|
||||
}
|
||||
if (optionSource) {
|
||||
defaultOptions = optionSource;
|
||||
@@ -503,7 +575,8 @@ private:
|
||||
Py::Sequence list(shapeObj);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapePy::Type))) {
|
||||
Part::TopoShape* ts = static_cast<Part::TopoShapePy*>((*it).ptr())->getTopoShapePtr();
|
||||
Part::TopoShape* ts =
|
||||
static_cast<Part::TopoShapePy*>((*it).ptr())->getTopoShapePtr();
|
||||
TopoDS_Shape shape = ts->getShape();
|
||||
writer.exportShape(shape);
|
||||
}
|
||||
@@ -517,23 +590,24 @@ private:
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args.ptr(), "O!et|iOs", &(Part::TopoShapePy::Type) ,
|
||||
&shapeObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
if (PyArg_ParseTuple(args.ptr(),
|
||||
"O!et|iOs",
|
||||
&(Part::TopoShapePy::Type),
|
||||
&shapeObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
filePath = std::string(fname);
|
||||
layerName = "none";
|
||||
PyMem_Free(fname);
|
||||
|
||||
if ((versionParm == 12) ||
|
||||
(versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
if ((versionParm == 12) || (versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
}
|
||||
if (usePolyline == Py_True) {
|
||||
polyOverride = true;
|
||||
polyOverride = true;
|
||||
}
|
||||
if (optionSource) {
|
||||
defaultOptions = optionSource;
|
||||
@@ -565,34 +639,35 @@ private:
|
||||
|
||||
Py::Object writeDXFObject(const Py::Tuple& args)
|
||||
{
|
||||
PyObject *docObj;
|
||||
PyObject* docObj;
|
||||
char* fname;
|
||||
std::string filePath;
|
||||
std::string layerName;
|
||||
const char* optionSource = nullptr;
|
||||
std::string defaultOptions = "User parameter:BaseApp/Preferences/Mod/Import";
|
||||
int versionParm = -1;
|
||||
bool versionOverride = false;
|
||||
bool polyOverride = false;
|
||||
PyObject *usePolyline = Py_False;
|
||||
int versionParm = -1;
|
||||
bool versionOverride = false;
|
||||
bool polyOverride = false;
|
||||
PyObject* usePolyline = Py_False;
|
||||
|
||||
if (PyArg_ParseTuple(args.ptr(), "O!et|iOs", &(PyList_Type) ,
|
||||
&docObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
if (PyArg_ParseTuple(args.ptr(),
|
||||
"O!et|iOs",
|
||||
&(PyList_Type),
|
||||
&docObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
filePath = std::string(fname);
|
||||
layerName = "none";
|
||||
PyMem_Free(fname);
|
||||
|
||||
if ((versionParm == 12) ||
|
||||
(versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
if ((versionParm == 12) || (versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
}
|
||||
if (usePolyline == Py_True) {
|
||||
polyOverride = true;
|
||||
polyOverride = true;
|
||||
}
|
||||
|
||||
if (optionSource) {
|
||||
@@ -613,7 +688,8 @@ private:
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if (PyObject_TypeCheck((*it).ptr(), &(Part::PartFeaturePy::Type))) {
|
||||
PyObject* item = (*it).ptr();
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
App::DocumentObject* obj =
|
||||
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
Part::Feature* part = static_cast<Part::Feature*>(obj);
|
||||
layerName = part->getNameInDocument();
|
||||
writer.setLayerName(layerName);
|
||||
@@ -630,29 +706,30 @@ private:
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
if (PyArg_ParseTuple(args.ptr(), "O!et|iOs", &(App::DocumentObjectPy::Type) ,
|
||||
&docObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
if (PyArg_ParseTuple(args.ptr(),
|
||||
"O!et|iOs",
|
||||
&(App::DocumentObjectPy::Type),
|
||||
&docObj,
|
||||
"utf-8",
|
||||
&fname,
|
||||
&versionParm,
|
||||
&usePolyline,
|
||||
&optionSource)) {
|
||||
filePath = std::string(fname);
|
||||
layerName = "none";
|
||||
PyMem_Free(fname);
|
||||
|
||||
if ((versionParm == 12) ||
|
||||
(versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
if ((versionParm == 12) || (versionParm == 14)) {
|
||||
versionOverride = true;
|
||||
}
|
||||
if (usePolyline == Py_True) {
|
||||
polyOverride = true;
|
||||
polyOverride = true;
|
||||
}
|
||||
|
||||
if (optionSource) {
|
||||
defaultOptions = optionSource;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
ImpExpDxfWrite writer(filePath);
|
||||
writer.setOptionSource(defaultOptions);
|
||||
@@ -663,7 +740,8 @@ private:
|
||||
writer.setPolyOverride(polyOverride);
|
||||
writer.setLayerName(layerName);
|
||||
writer.init();
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(docObj)->getDocumentObjectPtr();
|
||||
App::DocumentObject* obj =
|
||||
static_cast<App::DocumentObjectPy*>(docObj)->getDocumentObjectPtr();
|
||||
Part::Feature* part = static_cast<Part::Feature*>(obj);
|
||||
layerName = part->getNameInDocument();
|
||||
writer.setLayerName(layerName);
|
||||
@@ -687,4 +765,4 @@ PyObject* initModule()
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
}
|
||||
|
||||
} // namespace Import
|
||||
}// namespace Import
|
||||
|
||||
Reference in New Issue
Block a user