|
|
|
|
@@ -30,6 +30,10 @@
|
|
|
|
|
# include <iostream>
|
|
|
|
|
# include <climits>
|
|
|
|
|
# include <QString>
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
|
# pragma clang diagnostic push
|
|
|
|
|
# pragma clang diagnostic ignored "-Wextra-semi"
|
|
|
|
|
#endif
|
|
|
|
|
# include <Standard_Version.hxx>
|
|
|
|
|
# include <NCollection_Vector.hxx>
|
|
|
|
|
# include <BRep_Builder.hxx>
|
|
|
|
|
@@ -70,6 +74,9 @@
|
|
|
|
|
# else
|
|
|
|
|
# include <TDataStd_Shape.hxx>
|
|
|
|
|
# endif
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
|
# pragma clang diagnostic pop
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <CXX/Extensions.hxx>
|
|
|
|
|
@@ -121,11 +128,11 @@
|
|
|
|
|
#include <Gui/Application.h>
|
|
|
|
|
#include <Gui/Document.h>
|
|
|
|
|
#include <Gui/ViewProvider.h>
|
|
|
|
|
#include <Gui/ViewProviderLink.h>
|
|
|
|
|
#include <Gui/ViewProviderLink.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FC_LOG_LEVEL_INIT("Import", true, true)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FC_LOG_LEVEL_INIT("Import", true, true)
|
|
|
|
|
|
|
|
|
|
class OCAFBrowser
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
@@ -299,57 +306,57 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual void applyFaceColors(Part::Feature* part, const std::vector<App::Color>& colors) override {
|
|
|
|
|
auto vp = dynamic_cast<PartGui::ViewProviderPartExt*>(Gui::Application::Instance->getViewProvider(part));
|
|
|
|
|
if (!vp) return;
|
|
|
|
|
if(colors.empty()) {
|
|
|
|
|
// vp->MapFaceColor.setValue(true);
|
|
|
|
|
// vp->MapLineColor.setValue(true);
|
|
|
|
|
// vp->updateColors(0,true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// vp->MapFaceColor.setValue(false);
|
|
|
|
|
if(colors.size() == 1)
|
|
|
|
|
vp->ShapeColor.setValue(colors.front());
|
|
|
|
|
else
|
|
|
|
|
vp->DiffuseColor.setValues(colors);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyEdgeColors(Part::Feature* part, const std::vector<App::Color>& colors) override {
|
|
|
|
|
auto vp = dynamic_cast<PartGui::ViewProviderPartExt*>(Gui::Application::Instance->getViewProvider(part));
|
|
|
|
|
if (!vp) return;
|
|
|
|
|
// vp->MapLineColor.setValue(false);
|
|
|
|
|
if(colors.size() == 1)
|
|
|
|
|
vp->LineColor.setValue(colors.front());
|
|
|
|
|
else
|
|
|
|
|
vp->LineColorArray.setValues(colors);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyLinkColor(App::DocumentObject *obj, int index, App::Color color) override {
|
|
|
|
|
auto vp = dynamic_cast<Gui::ViewProviderLink*>(Gui::Application::Instance->getViewProvider(obj));
|
|
|
|
|
if(!vp)
|
|
|
|
|
return;
|
|
|
|
|
if(index<0) {
|
|
|
|
|
vp->OverrideMaterial.setValue(true);
|
|
|
|
|
vp->ShapeMaterial.setDiffuseColor(color);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(vp->OverrideMaterialList.getSize()<=index)
|
|
|
|
|
vp->OverrideMaterialList.setSize(index+1);
|
|
|
|
|
vp->OverrideMaterialList.set1Value(index,true);
|
|
|
|
|
App::Material mat(App::Material::DEFAULT);
|
|
|
|
|
if(vp->MaterialList.getSize()<=index)
|
|
|
|
|
vp->MaterialList.setSize(index+1,mat);
|
|
|
|
|
mat.diffuseColor = color;
|
|
|
|
|
vp->MaterialList.set1Value(index,mat);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyElementColors(App::DocumentObject *obj,
|
|
|
|
|
const std::map<std::string,App::Color> &colors) override
|
|
|
|
|
{
|
|
|
|
|
auto vp = Gui::Application::Instance->getViewProvider(obj);
|
|
|
|
|
if(!vp)
|
|
|
|
|
return;
|
|
|
|
|
(void)colors;
|
|
|
|
|
// vp->setElementColors(colors);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyFaceColors(Part::Feature* part, const std::vector<App::Color>& colors) override {
|
|
|
|
|
auto vp = dynamic_cast<PartGui::ViewProviderPartExt*>(Gui::Application::Instance->getViewProvider(part));
|
|
|
|
|
if (!vp) return;
|
|
|
|
|
if(colors.empty()) {
|
|
|
|
|
// vp->MapFaceColor.setValue(true);
|
|
|
|
|
// vp->MapLineColor.setValue(true);
|
|
|
|
|
// vp->updateColors(0,true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// vp->MapFaceColor.setValue(false);
|
|
|
|
|
if(colors.size() == 1)
|
|
|
|
|
vp->ShapeColor.setValue(colors.front());
|
|
|
|
|
else
|
|
|
|
|
vp->DiffuseColor.setValues(colors);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyEdgeColors(Part::Feature* part, const std::vector<App::Color>& colors) override {
|
|
|
|
|
auto vp = dynamic_cast<PartGui::ViewProviderPartExt*>(Gui::Application::Instance->getViewProvider(part));
|
|
|
|
|
if (!vp) return;
|
|
|
|
|
// vp->MapLineColor.setValue(false);
|
|
|
|
|
if(colors.size() == 1)
|
|
|
|
|
vp->LineColor.setValue(colors.front());
|
|
|
|
|
else
|
|
|
|
|
vp->LineColorArray.setValues(colors);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyLinkColor(App::DocumentObject *obj, int index, App::Color color) override {
|
|
|
|
|
auto vp = dynamic_cast<Gui::ViewProviderLink*>(Gui::Application::Instance->getViewProvider(obj));
|
|
|
|
|
if(!vp)
|
|
|
|
|
return;
|
|
|
|
|
if(index<0) {
|
|
|
|
|
vp->OverrideMaterial.setValue(true);
|
|
|
|
|
vp->ShapeMaterial.setDiffuseColor(color);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(vp->OverrideMaterialList.getSize()<=index)
|
|
|
|
|
vp->OverrideMaterialList.setSize(index+1);
|
|
|
|
|
vp->OverrideMaterialList.set1Value(index,true);
|
|
|
|
|
App::Material mat(App::Material::DEFAULT);
|
|
|
|
|
if(vp->MaterialList.getSize()<=index)
|
|
|
|
|
vp->MaterialList.setSize(index+1,mat);
|
|
|
|
|
mat.diffuseColor = color;
|
|
|
|
|
vp->MaterialList.set1Value(index,mat);
|
|
|
|
|
}
|
|
|
|
|
virtual void applyElementColors(App::DocumentObject *obj,
|
|
|
|
|
const std::map<std::string,App::Color> &colors) override
|
|
|
|
|
{
|
|
|
|
|
auto vp = Gui::Application::Instance->getViewProvider(obj);
|
|
|
|
|
if(!vp)
|
|
|
|
|
return;
|
|
|
|
|
(void)colors;
|
|
|
|
|
// vp->setElementColors(colors);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ExportOCAFGui : public Import::ExportOCAF
|
|
|
|
|
@@ -398,19 +405,19 @@ private:
|
|
|
|
|
{
|
|
|
|
|
char* Name;
|
|
|
|
|
char* DocName=0;
|
|
|
|
|
PyObject *importHidden = Py_None;
|
|
|
|
|
PyObject *merge = Py_None;
|
|
|
|
|
PyObject *useLinkGroup = Py_None;
|
|
|
|
|
int mode = -1;
|
|
|
|
|
static char* kwd_list[] = {"name","docName","importHidden","merge","useLinkGroup","mode",0};
|
|
|
|
|
if(!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "et|sOOOi",
|
|
|
|
|
kwd_list,"utf-8",&Name,&DocName,&importHidden,&merge,&useLinkGroup,&mode))
|
|
|
|
|
PyObject *importHidden = Py_None;
|
|
|
|
|
PyObject *merge = Py_None;
|
|
|
|
|
PyObject *useLinkGroup = Py_None;
|
|
|
|
|
int mode = -1;
|
|
|
|
|
static char* kwd_list[] = {"name","docName","importHidden","merge","useLinkGroup","mode",0};
|
|
|
|
|
if(!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "et|sOOOi",
|
|
|
|
|
kwd_list,"utf-8",&Name,&DocName,&importHidden,&merge,&useLinkGroup,&mode))
|
|
|
|
|
throw Py::Exception();
|
|
|
|
|
|
|
|
|
|
std::string Utf8Name = std::string(Name);
|
|
|
|
|
PyMem_Free(Name);
|
|
|
|
|
std::string name8bit = Part::encodeFilename(Utf8Name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//Base::Console().Log("Insert in Part with %s",Name);
|
|
|
|
|
Base::FileInfo file(Utf8Name.c_str());
|
|
|
|
|
@@ -430,19 +437,19 @@ private:
|
|
|
|
|
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Import/hSTEP");
|
|
|
|
|
optionReadShapeCompoundMode = hGrp->GetBool("ReadShapeCompoundMode", optionReadShapeCompoundMode);
|
|
|
|
|
ImportOCAFExt ocaf(hDoc, pcDoc, file.fileNamePure());
|
|
|
|
|
FC_TIME_INIT(t);
|
|
|
|
|
FC_DURATION_DECL_INIT2(d1,d2);
|
|
|
|
|
FC_TIME_INIT(t);
|
|
|
|
|
FC_DURATION_DECL_INIT2(d1,d2);
|
|
|
|
|
|
|
|
|
|
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
|
|
|
|
|
|
|
|
|
if(mode<0)
|
|
|
|
|
mode = ocaf.getMode();
|
|
|
|
|
if(mode && !pcDoc->isSaved()) {
|
|
|
|
|
auto gdoc = Gui::Application::Instance->getDocument(pcDoc);
|
|
|
|
|
if(!gdoc->save())
|
|
|
|
|
return Py::Object();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(mode<0)
|
|
|
|
|
mode = ocaf.getMode();
|
|
|
|
|
if(mode && !pcDoc->isSaved()) {
|
|
|
|
|
auto gdoc = Gui::Application::Instance->getDocument(pcDoc);
|
|
|
|
|
if(!gdoc->save())
|
|
|
|
|
return Py::Object();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
STEPCAFControl_Reader aReader;
|
|
|
|
|
aReader.SetColorMode(true);
|
|
|
|
|
@@ -506,30 +513,30 @@ private:
|
|
|
|
|
throw Py::Exception(Base::BaseExceptionFreeCADError, "no supported file format");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FC_DURATION_PLUS(d1,t);
|
|
|
|
|
if(merge!=Py_None)
|
|
|
|
|
ocaf.setMerge(PyObject_IsTrue(merge));
|
|
|
|
|
if(importHidden!=Py_None)
|
|
|
|
|
ocaf.setImportHiddenObject(PyObject_IsTrue(importHidden));
|
|
|
|
|
if(useLinkGroup!=Py_None)
|
|
|
|
|
ocaf.setUseLinkGroup(PyObject_IsTrue(useLinkGroup));
|
|
|
|
|
ocaf.setMode(mode);
|
|
|
|
|
auto ret = ocaf.loadShapes();
|
|
|
|
|
FC_DURATION_PLUS(d1,t);
|
|
|
|
|
if(merge!=Py_None)
|
|
|
|
|
ocaf.setMerge(PyObject_IsTrue(merge));
|
|
|
|
|
if(importHidden!=Py_None)
|
|
|
|
|
ocaf.setImportHiddenObject(PyObject_IsTrue(importHidden));
|
|
|
|
|
if(useLinkGroup!=Py_None)
|
|
|
|
|
ocaf.setUseLinkGroup(PyObject_IsTrue(useLinkGroup));
|
|
|
|
|
ocaf.setMode(mode);
|
|
|
|
|
auto ret = ocaf.loadShapes();
|
|
|
|
|
hApp->Close(hDoc);
|
|
|
|
|
FC_DURATION_PLUS(d2,t);
|
|
|
|
|
FC_DURATION_MSG(d1,"file read");
|
|
|
|
|
FC_DURATION_MSG(d2,"import");
|
|
|
|
|
FC_DURATION_MSG((d1+d2),"total");
|
|
|
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
|
App::GetApplication().setActiveDocument(pcDoc);
|
|
|
|
|
auto gdoc = Gui::Application::Instance->getDocument(pcDoc);
|
|
|
|
|
if(gdoc) {
|
|
|
|
|
gdoc->setActiveView();
|
|
|
|
|
Gui::Application::Instance->commandManager().runCommandByName("Std_ViewFitAll");
|
|
|
|
|
}
|
|
|
|
|
return Py::asObject(ret->getPyObject());
|
|
|
|
|
}
|
|
|
|
|
FC_DURATION_PLUS(d2,t);
|
|
|
|
|
FC_DURATION_MSG(d1,"file read");
|
|
|
|
|
FC_DURATION_MSG(d2,"import");
|
|
|
|
|
FC_DURATION_MSG((d1+d2),"total");
|
|
|
|
|
|
|
|
|
|
if(ret) {
|
|
|
|
|
App::GetApplication().setActiveDocument(pcDoc);
|
|
|
|
|
auto gdoc = Gui::Application::Instance->getDocument(pcDoc);
|
|
|
|
|
if(gdoc) {
|
|
|
|
|
gdoc->setActiveView();
|
|
|
|
|
Gui::Application::Instance->commandManager().runCommandByName("Std_ViewFitAll");
|
|
|
|
|
}
|
|
|
|
|
return Py::asObject(ret->getPyObject());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Standard_Failure& e) {
|
|
|
|
|
throw Py::Exception(Base::BaseExceptionFreeCADError, e.GetMessageString());
|
|
|
|
|
@@ -541,23 +548,23 @@ private:
|
|
|
|
|
return Py::None();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::map<std::string, App::Color> getShapeColors(App::DocumentObject *obj, const char *subname) {
|
|
|
|
|
auto vp = Gui::Application::Instance->getViewProvider(obj);
|
|
|
|
|
if(vp)
|
|
|
|
|
return vp->getElementColors(subname);
|
|
|
|
|
return std::map<std::string,App::Color>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::map<std::string, App::Color> getShapeColors(App::DocumentObject *obj, const char *subname) {
|
|
|
|
|
auto vp = Gui::Application::Instance->getViewProvider(obj);
|
|
|
|
|
if(vp)
|
|
|
|
|
return vp->getElementColors(subname);
|
|
|
|
|
return std::map<std::string,App::Color>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 char* kwd_list[] = {"obj", "name", "exportHidden", "legacy", "keepPlacement",0};
|
|
|
|
|
if(!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "Oet|OOO",
|
|
|
|
|
kwd_list,&object,"utf-8",&Name,&exportHidden,&legacy,&keepPlacement))
|
|
|
|
|
PyObject *exportHidden = Py_None;
|
|
|
|
|
PyObject *legacy = Py_None;
|
|
|
|
|
PyObject *keepPlacement = Py_None;
|
|
|
|
|
static char* kwd_list[] = {"obj", "name", "exportHidden", "legacy", "keepPlacement",0};
|
|
|
|
|
if(!PyArg_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "Oet|OOO",
|
|
|
|
|
kwd_list,&object,"utf-8",&Name,&exportHidden,&legacy,&keepPlacement))
|
|
|
|
|
throw Py::Exception();
|
|
|
|
|
|
|
|
|
|
std::string Utf8Name = std::string(Name);
|
|
|
|
|
@@ -570,27 +577,27 @@ private:
|
|
|
|
|
Handle(TDocStd_Document) hDoc;
|
|
|
|
|
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
|
|
|
|
|
|
|
|
|
|
std::vector<App::DocumentObject *> objs;
|
|
|
|
|
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(legacy == Py_None) {
|
|
|
|
|
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
|
|
|
|
"User parameter:BaseApp/Preferences/Mod/Import");
|
|
|
|
|
legacy = hGrp->GetBool("ExportLegacy",false)?Py_True:Py_False;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type)))
|
|
|
|
|
objs.push_back(static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(legacy == Py_None) {
|
|
|
|
|
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
|
|
|
|
"User parameter:BaseApp/Preferences/Mod/Import");
|
|
|
|
|
legacy = hGrp->GetBool("ExportLegacy",false)?Py_True:Py_False;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Import::ExportOCAF2 ocaf(hDoc, &getShapeColors);
|
|
|
|
|
if(!PyObject_IsTrue(legacy) || !ocaf.canFallback(objs)) {
|
|
|
|
|
if(exportHidden!=Py_None)
|
|
|
|
|
ocaf.setExportHiddenObject(PyObject_IsTrue(exportHidden));
|
|
|
|
|
if(keepPlacement!=Py_None)
|
|
|
|
|
ocaf.setKeepPlacement(PyObject_IsTrue(keepPlacement));
|
|
|
|
|
ocaf.exportObjects(objs);
|
|
|
|
|
} else {
|
|
|
|
|
if(!PyObject_IsTrue(legacy) || !ocaf.canFallback(objs)) {
|
|
|
|
|
if(exportHidden!=Py_None)
|
|
|
|
|
ocaf.setExportHiddenObject(PyObject_IsTrue(exportHidden));
|
|
|
|
|
if(keepPlacement!=Py_None)
|
|
|
|
|
ocaf.setKeepPlacement(PyObject_IsTrue(keepPlacement));
|
|
|
|
|
ocaf.exportObjects(objs);
|
|
|
|
|
} else {
|
|
|
|
|
bool keepExplicitPlacement = objs.size() > 1;
|
|
|
|
|
keepExplicitPlacement = Standard_True;
|
|
|
|
|
ExportOCAFGui ocaf(hDoc, keepExplicitPlacement);
|
|
|
|
|
@@ -598,7 +605,7 @@ private:
|
|
|
|
|
std::vector <TDF_Label> hierarchical_label;
|
|
|
|
|
std::vector <TopLoc_Location> hierarchical_loc;
|
|
|
|
|
std::vector <App::DocumentObject*> hierarchical_part;
|
|
|
|
|
for(auto obj : objs)
|
|
|
|
|
for(auto obj : objs)
|
|
|
|
|
ocaf.exportObject(obj,hierarchical_label, hierarchical_loc,hierarchical_part);
|
|
|
|
|
|
|
|
|
|
// Free Shapes must have absolute placement and not explicit
|
|
|
|
|
@@ -615,7 +622,7 @@ private:
|
|
|
|
|
// Update is not performed automatically anymore: https://tracker.dev.opencascade.org/view.php?id=28055
|
|
|
|
|
XCAFDoc_DocumentTool::ShapeTool(hDoc->Main())->UpdateAssemblies();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Base::FileInfo file(Utf8Name.c_str());
|
|
|
|
|
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
|
|
|
|
|