Skip to content

Commit 7da6467

Browse files
chenneskadet1090
authored andcommitted
Import: Revert recent STEP file object naming work
After discussion in several recent PR review meetings the Maintainer team has decided to roll back some recent work on object naming in STEP files. Inadequate automated testing has led to a situation where every change made to address one bug introduces another someplace else. It is difficult to determine which, if any, of these fixes represent an appropriate path forward, versus fixing a symptom rather than the underlying problem. --- Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" This reverts commit 5971511. Revert "core: fix various issues exporting step files, ie. FreeCAD#25540 FreeCAD#24962 FreeCAD#25567" This reverts commit e226e9b. Revert "export: step file preserve last feature when exporting step file, fix issue FreeCAD#25567" This reverts commit 9c48c9a. Revert "core: preserve body name in step file when exporting part that contains body with feature, fixes FreeCAD#24962" This reverts commit 246218b. Revert "Import: STEP export preserve body names (FreeCAD#25042)" This reverts commit f218c5f. Revert "Import: Export tip when body is selected (FreeCAD#24678)" This reverts commit 6fd6558.
1 parent a4bff81 commit 7da6467

File tree

4 files changed

+13
-86
lines changed

4 files changed

+13
-86
lines changed

src/Mod/Import/App/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
set(Import_LIBS
44
Part
5-
PartDesign
65
${OCC_OCAF_LIBRARIES}
76
${OCC_OCAF_DEBUG_LIBRARIES}
87
)

src/Mod/Import/App/ExportOCAF.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <App/Part.h>
4848
#include <Mod/Part/App/Interface.h>
4949
#include <Mod/Part/App/PartFeature.h>
50-
#include <Mod/PartDesign/App/Body.h>
5150

5251
#include "ExportOCAF.h"
5352
#include "Tools.h"
@@ -177,26 +176,12 @@ int ExportOCAF::exportObject(
177176
return_label = root_id;
178177
}
179178

180-
// keep a copy of the original object for naming purposes
181-
App::DocumentObject* originalObj = obj;
182-
183-
if (obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) {
184-
PartDesign::Body* body = static_cast<PartDesign::Body*>(obj);
185-
App::DocumentObject* tip = body->Tip.getValue();
186-
if (tip && tip->isDerivedFrom<Part::Feature>()) {
187-
// use the tip instead of the body for export
188-
obj = tip;
189-
}
190-
}
191-
192179
if (obj->isDerivedFrom<Part::Feature>()) {
193180
Part::Feature* part = static_cast<Part::Feature*>(obj);
194181
std::vector<Base::Color> colors;
195182
findColors(part, colors);
196183

197-
const char* label = (originalObj != obj) ? originalObj->Label.getValue() : nullptr;
198-
return_label
199-
= saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part, label);
184+
return_label = saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part);
200185
}
201186

202187
return return_label;
@@ -240,8 +225,7 @@ int ExportOCAF::saveShape(
240225
const std::vector<Base::Color>& colors,
241226
std::vector<TDF_Label>& hierarchical_label,
242227
std::vector<TopLoc_Location>& hierarchical_loc,
243-
std::vector<App::DocumentObject*>& hierarchical_part,
244-
const char* labelOverride
228+
std::vector<App::DocumentObject*>& hierarchical_part
245229
)
246230
{
247231
const TopoDS_Shape& shape = part->Shape.getValue();
@@ -276,8 +260,8 @@ int ExportOCAF::saveShape(
276260
TDF_Label shapeLabel = aShapeTool->NewShape();
277261
aShapeTool->SetShape(shapeLabel, baseShape);
278262

279-
const char* labelToUse = labelOverride ? labelOverride : part->Label.getValue();
280-
TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(labelToUse, true));
263+
TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), true));
264+
281265

282266
/*
283267
if (keepExplicitPlacement) {

src/Mod/Import/App/ExportOCAF.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class ImportExport ExportOCAF
7272
const std::vector<Base::Color>&,
7373
std::vector<TDF_Label>& hierarchical_label,
7474
std::vector<TopLoc_Location>& hierarchical_loc,
75-
std::vector<App::DocumentObject*>& hierarchical_part,
76-
const char* labelOverride = nullptr
75+
std::vector<App::DocumentObject*>& hierarchical_part
7776
);
7877
void getPartColors(
7978
std::vector<App::DocumentObject*> hierarchical_part,

src/Mod/Import/App/ExportOCAF2.cpp

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
#include <Mod/Part/App/PartFeature.h>
5353
#include <Mod/Part/App/Interface.h>
5454
#include <Mod/Part/App/OCAF/ImportExportSettings.h>
55-
#include <Mod/PartDesign/App/Body.h>
56-
#include <Mod/PartDesign/App/Feature.h>
5755

5856
#include "ExportOCAF2.h"
5957

@@ -391,21 +389,7 @@ TDF_Label ExportOCAF2::exportObject(
391389
const char* name
392390
)
393391
{
394-
App::DocumentObject* obj = nullptr;
395-
// keep a copy of the original object for naming purposes
396-
App::DocumentObject* originalObj = parentObj;
397-
398-
// check if this is a body and get its tip before getting the shape
399-
if (parentObj && parentObj->isDerivedFrom(PartDesign::Body::getClassTypeId())) {
400-
// if (obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) {
401-
auto* body = static_cast<PartDesign::Body*>(parentObj);
402-
App::DocumentObject* tip = body->Tip.getValue();
403-
if (tip) {
404-
// obj = tip;
405-
parentObj = tip;
406-
}
407-
}
408-
392+
App::DocumentObject* obj;
409393
auto shape = Part::Feature::getTopoShape(
410394
parentObj,
411395
(sub ? Part::ShapeOption::NoFlag : Part::ShapeOption::Transform),
@@ -420,21 +404,6 @@ TDF_Label ExportOCAF2::exportObject(
420404
return {};
421405
}
422406

423-
// after resolution, check if obj is a body accessed via sub path and get the tip shape
424-
if (sub && obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) {
425-
auto* body = static_cast<PartDesign::Body*>(obj);
426-
App::DocumentObject* tip = body->Tip.getValue();
427-
if (tip) {
428-
// reget shape from tip to ensure latest feature is included
429-
auto tipShape = Part::Feature::getTopoShape(tip, Part::ShapeOption::Transform);
430-
if (!tipShape.isNull()) {
431-
shape = tipShape;
432-
}
433-
// use tip for colors (will be handled later in setupObject)
434-
obj = tip;
435-
}
436-
}
437-
438407
// sub may contain more than one hierarchy, e.g. Assembly container may use
439408
// getSubObjects to skip some hierarchy containing constraints and stuff
440409
// when exporting. We search for extra '.', and set it as prefix if found.
@@ -493,9 +462,7 @@ TDF_Label ExportOCAF2::exportObject(
493462
else {
494463
label = aShapeTool->AddShape(shape.getShape(), Standard_False, Standard_False);
495464
}
496-
497-
// use originalObj to preserve name
498-
setupObject(label, name ? parentObj : originalObj, shape, prefix, name);
465+
setupObject(label, name ? parentObj : obj, shape, prefix, name);
499466
return label;
500467
}
501468
auto next = linked->getLinkedObject(false, nullptr, false, depth++);
@@ -508,12 +475,7 @@ TDF_Label ExportOCAF2::exportObject(
508475

509476
auto subs = obj->getSubObjects();
510477
// subs empty means obj is not a container.
511-
// treat as non container if:
512-
// 1. no subobjects (subs.empty())
513-
// 2. is a partdesign feature ie. pad, pocket, boolean
514-
// 3. is a partdesign body, should export as single shape via its tip, not as assembly
515-
if (subs.empty() || obj->isDerivedFrom(PartDesign::Feature::getClassTypeId())
516-
|| obj->isDerivedFrom(PartDesign::Body::getClassTypeId())) {
478+
if (subs.empty()) {
517479

518480
if (!parent.IsNull()) {
519481
// Search for non-located shape to see if we've stored the original shape before
@@ -523,14 +485,11 @@ TDF_Label ExportOCAF2::exportObject(
523485
baseShape.setShape(baseShape.getShape().Located(TopLoc_Location()));
524486
label = aShapeTool->NewShape();
525487
aShapeTool->SetShape(label, baseShape.getShape());
526-
if (originalObj != linked) {
527-
setupObject(label, linked, baseShape, prefix, nullptr, false);
528-
}
529-
setupObject(label, originalObj, baseShape, prefix, nullptr, false);
488+
setupObject(label, linked, baseShape, prefix);
530489
}
531490

532491
label = aShapeTool->AddComponent(parent, shape.getShape(), Standard_False);
533-
setupObject(label, name ? parentObj : originalObj, shape, prefix, name);
492+
setupObject(label, name ? parentObj : obj, shape, prefix, name);
534493
}
535494
else {
536495
// Here means we are exporting a single non-assembly object. We must
@@ -550,7 +509,7 @@ TDF_Label ExportOCAF2::exportObject(
550509
shape.setShape(shape.getShape().Located(TopLoc_Location()));
551510
}
552511
label = aShapeTool->AddShape(shape.getShape(), Standard_False, Standard_False);
553-
auto o = name ? parentObj : originalObj;
512+
auto o = name ? parentObj : obj;
554513
if (o != linked) {
555514
setupObject(label, linked, shape, prefix, nullptr, true);
556515
}
@@ -561,10 +520,6 @@ TDF_Label ExportOCAF2::exportObject(
561520
for (auto link : links) {
562521
myObjects.emplace(link, label);
563522
}
564-
// also cache the body if it's different from obj (the tip)
565-
if (originalObj != obj) {
566-
myObjects.emplace(originalObj, label);
567-
}
568523
return label;
569524
}
570525

@@ -666,29 +621,19 @@ TDF_Label ExportOCAF2::exportObject(
666621
myObjects.emplace(link, label);
667622
}
668623

669-
if (originalObj != obj) {
670-
myObjects.emplace(originalObj, label);
671-
}
672-
673624
if (!parent.IsNull() && !links.empty()) {
674625
linked = links.back();
675626
}
676627
else {
677628
linked = obj;
678629
}
679-
// use the originalObj for naming if we changed obj to tip
680-
App::DocumentObject* setupObj = (originalObj != obj) ? originalObj : linked;
681-
setupObject(label, setupObj, baseShape, prefix);
682-
683-
#ifdef FC_DEBUG
684-
Base::Console().warning("assembly name set to: %s\n", linked->Label.getValue());
685-
#endif
630+
setupObject(label, linked, baseShape, prefix);
686631

687632
if (!parent.IsNull()) {
688633
// If we are a component, swap in the base shape but keep our location.
689634
shape.setShape(baseShape.getShape().Located(shape.getShape().Location()));
690635
label = aShapeTool->AddComponent(parent, label, shape.getShape().Location());
691-
setupObject(label, name ? parentObj : originalObj, shape, prefix, name);
636+
setupObject(label, name ? parentObj : obj, shape, prefix, name);
692637
}
693638
return label;
694639
}

0 commit comments

Comments
 (0)