Import: STEP export preserve body names (#25042)

This commit is contained in:
Chris
2025-11-17 22:23:21 -06:00
committed by GitHub
parent 0a73f53990
commit f218c5f25c
3 changed files with 22 additions and 9 deletions

View File

@@ -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<PartDesign::Body*>(obj);
App::DocumentObject* tip = body->Tip.getValue();
@@ -190,7 +194,9 @@ int ExportOCAF::exportObject(
std::vector<Base::Color> 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<Base::Color>& colors,
std::vector<TDF_Label>& hierarchical_label,
std::vector<TopLoc_Location>& hierarchical_loc,
std::vector<App::DocumentObject*>& hierarchical_part
std::vector<App::DocumentObject*>& 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) {

View File

@@ -72,7 +72,8 @@ public:
const std::vector<Base::Color>&,
std::vector<TDF_Label>& hierarchical_label,
std::vector<TopLoc_Location>& hierarchical_loc,
std::vector<App::DocumentObject*>& hierarchical_part
std::vector<App::DocumentObject*>& hierarchical_part,
const char* labelOverride = nullptr
);
void getPartColors(
std::vector<App::DocumentObject*> hierarchical_part,

View File

@@ -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<PartDesign::Body*>(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;
}