diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index a67f1e6097..34a0d80f64 100644 --- a/src/Mod/Import/App/ExportOCAF2.cpp +++ b/src/Mod/Import/App/ExportOCAF2.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include "ExportOCAF2.h" @@ -390,7 +391,21 @@ TDF_Label ExportOCAF2::exportObject( const char* name ) { - App::DocumentObject* obj; + App::DocumentObject* obj = nullptr; + // keep a copy of the original object for naming purposes + App::DocumentObject* originalObj = parentObj; + + // check if this is a body and get its tip before getting the shape + if (parentObj && parentObj->isDerivedFrom(PartDesign::Body::getClassTypeId())) { + // if (obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) { + auto* body = static_cast(parentObj); + App::DocumentObject* tip = body->Tip.getValue(); + if (tip) { + // obj = tip; + parentObj = tip; + } + } + auto shape = Part::Feature::getTopoShape( parentObj, (sub ? Part::ShapeOption::NoFlag : Part::ShapeOption::Transform), @@ -405,15 +420,17 @@ 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); + // after resolution, check if obj is a body accessed via sub path and get the tip shape + if (sub && obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) { + auto* body = static_cast(obj); App::DocumentObject* tip = body->Tip.getValue(); if (tip) { - // keep the shape from the body, but use the tip's colors - // by replacing obj with tip + // reget shape from tip to ensure latest feature is included + auto tipShape = Part::Feature::getTopoShape(tip, Part::ShapeOption::Transform); + if (!tipShape.isNull()) { + shape = tipShape; + } + // use tip for colors (will be handled later in setupObject) obj = tip; } } @@ -491,7 +508,12 @@ TDF_Label ExportOCAF2::exportObject( auto subs = obj->getSubObjects(); // subs empty means obj is not a container. - if (subs.empty()) { + // treat as non container if: + // 1. no subobjects (subs.empty()) + // 2. is a partdesign feature ie. pad, pocket, boolean + // 3. is a partdesign body, should export as single shape via its tip, not as assembly + if (subs.empty() || obj->isDerivedFrom(PartDesign::Feature::getClassTypeId()) + || obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) { if (!parent.IsNull()) { // Search for non-located shape to see if we've stored the original shape before @@ -501,7 +523,10 @@ TDF_Label ExportOCAF2::exportObject( baseShape.setShape(baseShape.getShape().Located(TopLoc_Location())); label = aShapeTool->NewShape(); aShapeTool->SetShape(label, baseShape.getShape()); - setupObject(label, linked, baseShape, prefix); + if (originalObj != linked) { + setupObject(label, linked, baseShape, prefix, nullptr, false); + } + setupObject(label, originalObj, baseShape, prefix, nullptr, false); } label = aShapeTool->AddComponent(parent, shape.getShape(), Standard_False); @@ -536,6 +561,10 @@ TDF_Label ExportOCAF2::exportObject( for (auto link : links) { myObjects.emplace(link, label); } + // also cache the body if it's different from obj (the tip) + if (originalObj != obj) { + myObjects.emplace(originalObj, label); + } return label; } @@ -637,13 +666,23 @@ TDF_Label ExportOCAF2::exportObject( myObjects.emplace(link, label); } + if (originalObj != obj) { + myObjects.emplace(originalObj, label); + } + if (!parent.IsNull() && !links.empty()) { linked = links.back(); } else { linked = obj; } - setupObject(label, linked, baseShape, prefix); + // use the originalObj for naming if we changed obj to tip + App::DocumentObject* setupObj = (originalObj != obj) ? originalObj : linked; + setupObject(label, setupObj, baseShape, prefix); + +#ifdef FC_DEBUG + Base::Console().warning("assembly name set to: %s\n", linked->Label.getValue()); +#endif if (!parent.IsNull()) { // If we are a component, swap in the base shape but keep our location.