diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index d4c34ef965..0adf7366c6 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -233,7 +233,8 @@ private: std::vector colors; std::vector hierarchical_label; std::vector hierarchical_loc; - ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc); + std::vector hierarchical_part; + ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part); } else { Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue()); @@ -251,7 +252,8 @@ private: colors.setPyObject(item1.ptr()); std::vector hierarchical_label; std::vector hierarchical_loc; - ocaf.saveShape(part, colors.getValues(), hierarchical_label, hierarchical_loc); + std::vector hierarchical_part; + ocaf.saveShape(part, colors.getValues(), hierarchical_label, hierarchical_loc, hierarchical_part); } else { Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue()); diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index c24c62743c..ba12961c2e 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -485,7 +485,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",1); + Interface_Static::SetIVal("write.step.assembly",2); } else { rootLabel = TDF_TagSource::NewChild(pDoc->Main()); @@ -495,7 +495,7 @@ ExportOCAF::ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement) // This function create an Assembly node into an XCAF document with it's relative placement information -void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector & hierarchical_label,std::vector & hierarchical_loc) +void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part) { TDF_Label shapeLabel = aShapeTool->NewShape(); Handle(TDataStd_Name) N; @@ -516,10 +516,11 @@ void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector & colors, std::vector & hierarchical_label,std::vector & hierarchical_loc) +int ExportOCAF::saveShape(Part::Feature* part, const std::vector& colors, std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part) { const TopoDS_Shape& shape = part->Shape.getValue(); if (shape.IsNull()) @@ -553,11 +554,15 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector& co aShapeTool->SetShape(shapeLabel, baseShape); TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), 1)); + + /* if (keepExplicitPlacement) { - aShapeTool->AddComponent(rootLabel, shapeLabel, aLoc); + aShapeTool->AddComponent(aShapeTool->BaseLabel(), shapeLabel, aLoc); + XCAFDoc_Location::Set(shapeLabel,MyLoc); } */ + // Add color information Quantity_Color col; @@ -604,10 +609,38 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector& co hierarchical_label.push_back(shapeLabel); hierarchical_loc.push_back(MyLoc); + hierarchical_part.push_back(part); return(hierarchical_label.size()); } +// This function is re-allocating Free XCAF document shapes with absolute coordinate + +void ExportOCAF::reallocateFreeShape(std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part) +{ + TDF_LabelSequence FreeLabels; + aShapeTool->GetFreeShapes(FreeLabels); + int n = FreeLabels.Length(); + for (int i = 1; i <= n; i++) + { + TDF_Label label = FreeLabels.Value(i); + for ( unsigned long j = 0; j < ( hierarchical_label.size()) ; j++ ) + { + if ( label == hierarchical_label.at(j) ) + { + // hierarchical part does contain only part currently and not node I should add node + if ( hierarchical_part.at(j)->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()) ) + { + Part::Feature * part = static_cast(hierarchical_part.at(j)); + aShapeTool->SetShape(label, part->Shape.getValue()); + } + } + } + } + +} + + // This function is moving a "standard" node into an Assembly node within an XCAF doc void ExportOCAF::pushNode(int root_id, int node_id, std::vector & hierarchical_label,std::vector & hierarchical_loc) diff --git a/src/Mod/Import/App/ImportOCAF.h b/src/Mod/Import/App/ImportOCAF.h index 3b6af5b34c..08778ec76d 100644 --- a/src/Mod/Import/App/ImportOCAF.h +++ b/src/Mod/Import/App/ImportOCAF.h @@ -79,9 +79,10 @@ private: class ImportExport ExportOCAF { public: - void createNode(App::Part* part, int& root_it, std::vector & hierarchical_label,std::vector & hierarchical_loc); + void createNode(App::Part* part, int& root_it, std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part); ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement); - int saveShape(Part::Feature* part, const std::vector&, std::vector & hierarchical_label,std::vector & hierarchical_loc); + int saveShape(Part::Feature* part, const std::vector&, std::vector & hierarchical_label,std::vector & hierarchical_loc,std::vector & hierarchical_part); + void reallocateFreeShape(std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part); void pushNode(int root, int node, std::vector & hierarchical_label,std::vector & hierarchical_loc); diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index b2f1e894b0..0949828460 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -438,7 +438,8 @@ private: } int export_app_object(App::DocumentObject* obj, Import::ExportOCAF ocaf, std::vector & hierarchical_label, - std::vector & hierarchical_loc) + std::vector & hierarchical_loc, + std::vector & hierarchical_part) { std::vector local_label; int root_id; @@ -453,11 +454,11 @@ private: for ( it = entries.begin(); it != entries.end(); it++ ) { int new_label=0; - new_label=export_app_object((*it),ocaf,hierarchical_label,hierarchical_loc); + new_label=export_app_object((*it),ocaf,hierarchical_label,hierarchical_loc, hierarchical_part); local_label.push_back(new_label); } - ocaf.createNode(part,root_id,hierarchical_label,hierarchical_loc); + ocaf.createNode(part,root_id,hierarchical_label,hierarchical_loc, hierarchical_part); std::vector::iterator label_it; for (label_it = local_label.begin(); label_it != local_label.end(); ++label_it) { ocaf.pushNode(root_id,(*label_it), hierarchical_label,hierarchical_loc); @@ -476,7 +477,7 @@ private: colors.push_back(static_cast(vp)->ShapeColor.getValue()); } - return_label=ocaf.saveShape(part, colors,hierarchical_label,hierarchical_loc); + return_label=ocaf.saveShape(part, colors,hierarchical_label,hierarchical_loc,hierarchical_part); } return(return_label); @@ -504,17 +505,21 @@ private: Import::ExportOCAF ocaf(hDoc, keepExplicitPlacement); // That stuff is exporting a list of selected oject into FreeCAD Tree + std::vector hierarchical_label; + std::vector hierarchical_loc; + std::vector hierarchical_part; for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); - std::vector hierarchical_label; - std::vector hierarchical_loc; - export_app_object(obj,ocaf, hierarchical_label, hierarchical_loc); + export_app_object(obj,ocaf, hierarchical_label, hierarchical_loc,hierarchical_part); } } + // Free Shapes must have absolute placement and not explicit + ocaf.reallocateFreeShape(hierarchical_label, hierarchical_loc,hierarchical_part); + Base::FileInfo file(Utf8Name.c_str()); if (file.hasExtension("stp") || file.hasExtension("step")) { //Interface_Static::SetCVal("write.step.schema", "AP214IS"); @@ -524,10 +529,12 @@ private: optionScheme_214 = hGrp_stp->GetBool("Scheme_214",true); optionScheme_203 = hGrp_stp->GetBool("Scheme_203",false); if (optionScheme_214) - Interface_Static::SetCVal("write.step.schema", "AP214CD"); + Interface_Static::SetCVal("write.step.schema", "AP214IS"); if (optionScheme_203) Interface_Static::SetCVal("write.step.schema", "AP203"); STEPCAFControl_Writer writer; + Interface_Static::SetIVal("write.step.assembly",1); + // writer.SetColorMode(Standard_False); writer.Transfer(hDoc, STEPControl_AsIs); // edit STEP header