diff --git a/src/Mod/Import/App/ExportOCAF.cpp b/src/Mod/Import/App/ExportOCAF.cpp index 302bef57cc..1b9e157952 100644 --- a/src/Mod/Import/App/ExportOCAF.cpp +++ b/src/Mod/Import/App/ExportOCAF.cpp @@ -176,6 +176,10 @@ int ExportOCAF::exportObject( return_label = root_id; } + + // keep a copy of the original object for naming purposes + App::DocumentObject* originalObj = obj; + if (obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) { PartDesign::Body* body = static_cast(obj); App::DocumentObject* tip = body->Tip.getValue(); @@ -190,7 +194,9 @@ int ExportOCAF::exportObject( std::vector colors; findColors(part, colors); - return_label = saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part); + const char* label = (originalObj != obj) ? originalObj->Label.getValue() : nullptr; + return_label + = saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part, label); } return return_label; @@ -234,7 +240,8 @@ int ExportOCAF::saveShape( const std::vector& colors, std::vector& hierarchical_label, std::vector& hierarchical_loc, - std::vector& hierarchical_part + std::vector& hierarchical_part, + const char* labelOverride ) { const TopoDS_Shape& shape = part->Shape.getValue(); @@ -269,8 +276,8 @@ int ExportOCAF::saveShape( TDF_Label shapeLabel = aShapeTool->NewShape(); aShapeTool->SetShape(shapeLabel, baseShape); - TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), true)); - + const char* labelToUse = labelOverride ? labelOverride : part->Label.getValue(); + TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(labelToUse, true)); /* if (keepExplicitPlacement) { diff --git a/src/Mod/Import/App/ExportOCAF.h b/src/Mod/Import/App/ExportOCAF.h index 5afa69f1b8..f1d6874c61 100644 --- a/src/Mod/Import/App/ExportOCAF.h +++ b/src/Mod/Import/App/ExportOCAF.h @@ -72,7 +72,8 @@ public: const std::vector&, std::vector& hierarchical_label, std::vector& hierarchical_loc, - std::vector& hierarchical_part + std::vector& hierarchical_part, + const char* labelOverride = nullptr ); void getPartColors( std::vector hierarchical_part, diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index e92d15b2db..a67f1e6097 100644 --- a/src/Mod/Import/App/ExportOCAF2.cpp +++ b/src/Mod/Import/App/ExportOCAF2.cpp @@ -405,6 +405,9 @@ TDF_Label ExportOCAF2::exportObject( return {}; } + // keep a copy of the original object for naming purposes + App::DocumentObject* originalObj = obj; + if (obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) { PartDesign::Body* body = static_cast(obj); App::DocumentObject* tip = body->Tip.getValue(); @@ -473,7 +476,9 @@ TDF_Label ExportOCAF2::exportObject( else { label = aShapeTool->AddShape(shape.getShape(), Standard_False, Standard_False); } - setupObject(label, name ? parentObj : obj, shape, prefix, name); + + // use originalObj to preserve name + setupObject(label, name ? parentObj : originalObj, shape, prefix, name); return label; } auto next = linked->getLinkedObject(false, nullptr, false, depth++); @@ -500,7 +505,7 @@ TDF_Label ExportOCAF2::exportObject( } label = aShapeTool->AddComponent(parent, shape.getShape(), Standard_False); - setupObject(label, name ? parentObj : obj, shape, prefix, name); + setupObject(label, name ? parentObj : originalObj, shape, prefix, name); } else { // Here means we are exporting a single non-assembly object. We must @@ -520,7 +525,7 @@ TDF_Label ExportOCAF2::exportObject( shape.setShape(shape.getShape().Located(TopLoc_Location())); } label = aShapeTool->AddShape(shape.getShape(), Standard_False, Standard_False); - auto o = name ? parentObj : obj; + auto o = name ? parentObj : originalObj; if (o != linked) { setupObject(label, linked, shape, prefix, nullptr, true); } @@ -644,7 +649,7 @@ TDF_Label ExportOCAF2::exportObject( // If we are a component, swap in the base shape but keep our location. shape.setShape(baseShape.getShape().Located(shape.getShape().Location())); label = aShapeTool->AddComponent(parent, label, shape.getShape().Location()); - setupObject(label, name ? parentObj : obj, shape, prefix, name); + setupObject(label, name ? parentObj : originalObj, shape, prefix, name); } return label; }