From 246218b28b7a18500cf1c9e9e794ec628bff57c3 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 21 Nov 2025 14:35:03 -0600 Subject: [PATCH 1/4] core: preserve body name in step file when exporting part that contains body with feature, fixes #24962 --- src/Mod/Import/App/ExportOCAF2.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index a67f1e6097..6e954b6c79 100644 --- a/src/Mod/Import/App/ExportOCAF2.cpp +++ b/src/Mod/Import/App/ExportOCAF2.cpp @@ -501,7 +501,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 +539,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 +644,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. From 9c48c9a3e3c4592e3c85065d74965383aa544c15 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 23 Nov 2025 15:25:33 -0600 Subject: [PATCH 2/4] export: step file preserve last feature when exporting step file, fix issue #25567 --- src/Mod/Import/App/ExportOCAF2.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index 6e954b6c79..1b4d1a04e3 100644 --- a/src/Mod/Import/App/ExportOCAF2.cpp +++ b/src/Mod/Import/App/ExportOCAF2.cpp @@ -390,7 +390,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,19 +419,6 @@ 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(); - if (tip) { - // keep the shape from the body, but use the tip's colors - // by replacing obj with tip - obj = tip; - } - } - // sub may contain more than one hierarchy, e.g. Assembly container may use // getSubObjects to skip some hierarchy containing constraints and stuff // when exporting. We search for extra '.', and set it as prefix if found. From e226e9b06e5fd813ae862c0699885b6400a75c38 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 23 Nov 2025 17:50:04 -0600 Subject: [PATCH 3/4] core: fix various issues exporting step files, ie. #25540 #24962 #25567 --- src/Mod/Import/App/ExportOCAF2.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index 1b4d1a04e3..b56152f786 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" @@ -419,6 +420,24 @@ TDF_Label ExportOCAF2::exportObject( return {}; } + // 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) { + // 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; + } + } + // sub may contain more than one hierarchy, e.g. Assembly container may use // getSubObjects to skip some hierarchy containing constraints and stuff // when exporting. We search for extra '.', and set it as prefix if found. @@ -492,7 +511,13 @@ 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 From 59715114f5a4fbf4d97f13a2f41277bb02e50cf0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 23 Nov 2025 23:51:58 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Mod/Import/App/ExportOCAF2.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Mod/Import/App/ExportOCAF2.cpp b/src/Mod/Import/App/ExportOCAF2.cpp index b56152f786..34a0d80f64 100644 --- a/src/Mod/Import/App/ExportOCAF2.cpp +++ b/src/Mod/Import/App/ExportOCAF2.cpp @@ -426,10 +426,7 @@ TDF_Label ExportOCAF2::exportObject( App::DocumentObject* tip = body->Tip.getValue(); if (tip) { // reget shape from tip to ensure latest feature is included - auto tipShape = Part::Feature::getTopoShape( - tip, - Part::ShapeOption::Transform - ); + auto tipShape = Part::Feature::getTopoShape(tip, Part::ShapeOption::Transform); if (!tipShape.isNull()) { shape = tipShape; } @@ -515,9 +512,8 @@ TDF_Label ExportOCAF2::exportObject( // 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 (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