1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <Model_BodyBuilder.h>
23 #include <Model_Data.h>
24 #include <Model_Document.h>
25 #include <TNaming_Builder.hxx>
26 #include <TNaming_NamedShape.hxx>
27 #include <TNaming_Iterator.hxx>
28 #include <TNaming_Tool.hxx>
29 #include <TDataStd_Name.hxx>
30 #include <TDataStd_Integer.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TDF_ChildIterator.hxx>
34 #include <TDF_ChildIDIterator.hxx>
35 #include <TDF_Reference.hxx>
36 #include <TopTools_MapOfShape.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <TopTools_DataMapOfShapeListOfShape.hxx>
41 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
43 #include <TopTools_MapIteratorOfMapOfShape.hxx>
44 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TopTools_DataMapOfShapeShape.hxx>
48 #include <BRepTools.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BRepTools_History.hxx>
51 #include <GeomAPI_Shape.h>
52 #include <GeomAlgoAPI_MakeShape.h>
53 #include <GeomAlgoAPI_SortListOfShapes.h>
54 #include <Config_PropManager.h>
56 //#include <TCollection_AsciiString.hxx>
57 //#include <TDF_Tool.hxx>
58 //#define DEB_IMPORT 1
60 Model_BodyBuilder::Model_BodyBuilder(ModelAPI_Object* theOwner)
61 : ModelAPI_BodyBuilder(theOwner),
69 // Converts evolution of naming shape to selection evelution and back to avoid
70 // naming support on the disabled results. Deeply in the labels tree, recursively.
71 static void evolutionToSelectionRec(TDF_Label theLab, const bool theFlag) {
72 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
73 Handle(TNaming_NamedShape) aName;
75 if (theLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
76 TNaming_Evolution aNSEvol = aName->Evolution();
77 if ((aNSEvol == TNaming_SELECTED && theFlag) ||
78 (aNSEvol != TNaming_SELECTED && !theFlag)) { // nothing to do, it is already correct
81 anEvolution = (int)(aNSEvol);
83 Handle(TDataStd_Integer) anAttrEvol;
84 if (theLab.FindAttribute(TDataStd_Integer::GetID(), anAttrEvol)) {
85 anEvolution = anAttrEvol->Get();
88 TDataStd_Integer::Set(theLab, anEvolution);
91 for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
92 // iterator goes in reversed order relatively to the Builder, to, make the list reversed
93 aShapePairs.push_front(std::pair<TopoDS_Shape, TopoDS_Shape>
94 (anIter.OldShape(), anIter.NewShape()));
98 TNaming_Builder aBuilder(theLab);
99 TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
100 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
101 for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
102 if (theFlag) { // disabled => make selection
103 if (anEvolution == TNaming_DELETE) // issue 2274 : don't put too many same null shapes
104 aBuilder.Select(aPairsIter->first, aPairsIter->first);
105 else if (anEvolution == TNaming_PRIMITIVE)
106 aBuilder.Select(aPairsIter->second, aPairsIter->second);
108 aBuilder.Select(aPairsIter->second, aPairsIter->first);
109 } else if (anEvol == TNaming_GENERATED) {
110 aBuilder.Generated(aPairsIter->first, aPairsIter->second);
111 } else if (anEvol == TNaming_MODIFY) {
112 aBuilder.Modify(aPairsIter->first, aPairsIter->second);
113 } else if (anEvol == TNaming_DELETE) {
114 aBuilder.Delete(aPairsIter->first);
115 } else if (anEvol == TNaming_PRIMITIVE) {
116 aBuilder.Generated(aPairsIter->second);
117 } else if (anEvol == TNaming_SELECTED) {
118 aBuilder.Select(aPairsIter->second, aPairsIter->first);
122 // recursive call for all sub-labels
123 TDF_ChildIterator anIter(theLab, Standard_False);
124 for(; anIter.More(); anIter.Next()) {
125 evolutionToSelectionRec(anIter.Value(), theFlag);
129 void Model_BodyBuilder::evolutionToSelection(const bool theFlag)
131 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
132 if (!aData || !aData->isValid()) // unknown case
134 TDF_Label& aShapeLab = aData->shapeLab();
135 evolutionToSelectionRec(aShapeLab, theFlag);
138 void Model_BodyBuilder::store(const std::shared_ptr<GeomAPI_Shape>& theShape,
139 const bool theIsStoreSameShapes)
141 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
143 TDF_Label& aShapeLab = aData->shapeLab();
146 // store the new shape as primitive
147 TNaming_Builder aBuilder(aShapeLab);
150 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
152 return; // null shape inside
154 if(!theIsStoreSameShapes) {
155 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab);
156 if(!aNS.IsNull() && !aNS->IsEmpty()) {
157 // This shape is already in document, store reference instead of shape;
158 const TDF_Label aFoundLabel = aNS->Label();
159 TDF_Reference::Set(aShapeLab, aFoundLabel);
160 aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
165 aBuilder.Generated(aShape);
167 aShapeLab.ForgetAttribute(TDF_Reference::GetID());
168 if(!aBuilder.NamedShape()->IsEmpty()) {
169 Handle(TDataStd_Name) anAttr;
170 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
171 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
173 std::shared_ptr<Model_Document> aDoc =
174 std::dynamic_pointer_cast<Model_Document>(document());
175 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
182 void Model_BodyBuilder::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
183 const std::shared_ptr<GeomAPI_Shape>& theToShape)
185 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
187 TDF_Label& aShapeLab = aData->shapeLab();
190 // store the new shape as primitive
191 TNaming_Builder aBuilder(aShapeLab);
192 if (!theFromShape || !theToShape)
194 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
195 if (aShapeBasis.IsNull())
196 return; // null shape inside
197 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
198 if (aShapeNew.IsNull())
199 return; // null shape inside
200 aBuilder.Generated(aShapeBasis, aShapeNew);
202 if(!aBuilder.NamedShape()->IsEmpty()) {
203 Handle(TDataStd_Name) anAttr;
204 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
205 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
207 std::shared_ptr<Model_Document> aDoc =
208 std::dynamic_pointer_cast<Model_Document>(document());
209 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
216 TNaming_Builder* Model_BodyBuilder::builder(const int theTag)
218 std::map<int, TNaming_Builder*>::iterator aFind = myBuilders.find(theTag);
219 if (aFind == myBuilders.end()) {
220 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
221 myBuilders[theTag] = new TNaming_Builder(
222 theTag == 0 ? aData->shapeLab() : aData->shapeLab().FindChild(theTag));
223 aFind = myBuilders.find(theTag);
225 return aFind->second;
228 void Model_BodyBuilder::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
229 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
231 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
233 TDF_Label& aShapeLab = aData->shapeLab();
235 if (theDecomposeSolidsTag != -2)
237 // store the new shape as primitive
238 TNaming_Builder* aBuilder = builder(0);
239 if (!theOldShape || !theNewShape)
241 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
242 if (aShapeOld.IsNull())
243 return; // null shape inside
244 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
245 if (aShapeNew.IsNull())
246 return; // null shape inside
247 aBuilder->Modify(aShapeOld, aShapeNew);
248 if(!aBuilder->NamedShape()->IsEmpty()) {
249 Handle(TDataStd_Name) anAttr;
250 if(aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
251 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
253 std::shared_ptr<Model_Document> aDoc =
254 std::dynamic_pointer_cast<Model_Document>(document());
255 aDoc->addNamingName(aBuilder->NamedShape()->Label(), aName);
262 void Model_BodyBuilder::storeWithoutNaming(const std::shared_ptr<GeomAPI_Shape>& theShape)
264 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
269 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
271 return; // null shape inside
272 TNaming_Builder aBuilder(aData->shapeLab());
273 aBuilder.Select(aShape, aShape);
277 void Model_BodyBuilder::clean()
279 TDF_Label aLab = std::dynamic_pointer_cast<Model_Data>(data())->shapeLab();
282 std::map<int, TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
283 for(; aBuilder != myBuilders.end(); aBuilder++) {
284 delete aBuilder->second;
285 // clear also shapes on cleaned sub-labels (#2241)
286 Handle(TNaming_NamedShape) aNS;
287 if (aLab.FindChild(aBuilder->first).FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
292 // remove the old reference (if any)
293 aLab.ForgetAttribute(TDF_Reference::GetID());
300 Model_BodyBuilder::~Model_BodyBuilder()
305 void Model_BodyBuilder::buildName(const int theTag, const std::string& theName)
307 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
308 //aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), theName);
309 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), theName.c_str());
311 void Model_BodyBuilder::generated(
312 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
314 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
315 builder(theTag)->Generated(aShape);
317 buildName(theTag, theName);
320 void Model_BodyBuilder::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
321 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
323 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
324 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
325 builder(theTag)->Generated(anOldShape, aNewShape);
327 buildName(theTag, theName);
328 TopAbs_ShapeEnum aGenShapeType = aNewShape.ShapeType();
329 if(aGenShapeType == TopAbs_WIRE || aGenShapeType == TopAbs_SHELL) {
330 TopAbs_ShapeEnum anExplodeShapeType = aGenShapeType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE;
331 const TDF_Label aLabel = builder(theTag)->NamedShape()->Label();
333 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
334 for(TopExp_Explorer anExp(aNewShape, anExplodeShapeType); anExp.More(); anExp.Next()) {
335 TDF_Label aChildLabel = aLabel.FindChild(aTag);
336 TNaming_Builder aBuilder(aChildLabel);
337 aBuilder.Generated(anOldShape, anExp.Current());
338 TCollection_AsciiString aChildName = TCollection_AsciiString((theName + "_").c_str()) + aTag;
339 //aDoc->addNamingName(aChildLabel, aChildName.ToCString());
340 TDataStd_Name::Set(aChildLabel, aChildName.ToCString());
347 void Model_BodyBuilder::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
348 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
350 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
351 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
352 builder(theTag)->Modify(anOldShape, aNewShape);
354 buildName(theTag, theName);
357 void Model_BodyBuilder::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
360 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
361 builder(theTag)->Delete(aShape);
364 void Model_BodyBuilder::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
365 std::shared_ptr<GeomAPI_Shape> theShapeIn,
366 const int theKindOfShape,
369 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
370 TopTools_MapOfShape aView;
371 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
372 GeomShapePtr aResultShape = shape();
373 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
374 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
375 if (!aView.Add(aRoot)) continue;
376 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
377 aRShape->setImpl((new TopoDS_Shape(aRoot)));
378 if (theMS->isDeleted (aRShape)) {
379 if (!aResultShape->isSubShape(aRShape, false)) {
381 if (BRepTools_History::IsSupportedType(aRoot)) // to avoid crash in #2572
382 theMS->modified(aRShape, aHist);
383 if (aHist.size() == 0 || (aHist.size() == 1 && aHist.front()->isSame(aRShape)))
384 builder(theTag)->Delete(aRoot);
390 static void removeBadShapes(ListOfShape& theShapes)
392 ListOfShape::iterator anIt = theShapes.begin();
393 while (anIt != theShapes.end()) {
394 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
395 bool aSkip = aNewShape.IsNull()
396 || (aNewShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aNewShape)));
398 ListOfShape::iterator aRemoveIt = anIt++;
399 theShapes.erase(aRemoveIt);
406 // Keep only the shapes with minimal shape type
407 static void keepTopLevelShapes(ListOfShape& theShapes, const TopoDS_Shape& theRoot,
408 const GeomShapePtr& theResultShape = GeomShapePtr())
410 GeomAPI_Shape::ShapeType aKeepShapeType = GeomAPI_Shape::SHAPE;
411 ListOfShape::iterator anIt = theShapes.begin();
412 while (anIt != theShapes.end()) {
413 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
414 bool aSkip = aNewShape.IsNull() ||
415 (aNewShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aNewShape)));
416 if (aSkip || theRoot.IsSame(aNewShape) || (theResultShape &&
417 (!theResultShape->isSubShape(*anIt, false) || theResultShape->isSame(*anIt)))) {
418 ListOfShape::iterator aRemoveIt = anIt++;
419 theShapes.erase(aRemoveIt);
421 GeomAPI_Shape::ShapeType aType = (*anIt)->shapeType();
422 if (aType < aKeepShapeType) {
423 // found a shape with lesser shape type => remove all previous shapes
424 aKeepShapeType = aType;
425 theShapes.erase(theShapes.begin(), anIt);
427 } else if (aType > aKeepShapeType) {
428 // shapes with greater shape type should be removed from the list
429 ListOfShape::iterator aRemoveIt = anIt++;
430 theShapes.erase(aRemoveIt);
437 // returns an ancestor shape-type thaty used for naming-definition of the sub-type
438 TopAbs_ShapeEnum typeOfAncestor(const TopAbs_ShapeEnum theSubType) {
439 if (theSubType == TopAbs_VERTEX)
441 if (theSubType == TopAbs_EDGE)
443 return TopAbs_VERTEX; // bad case
446 void Model_BodyBuilder::loadAndOrientModifiedShapes (
447 GeomAlgoAPI_MakeShape* theMS,
448 std::shared_ptr<GeomAPI_Shape> theShapeIn,
449 const int theKindOfShape,
451 const std::string& theName,
452 GeomAPI_DataMapOfShapeShape& theSubShapes,
453 const bool theIsStoreSeparate,
454 const bool theIsStoreAsGenerated)
456 static const int THE_ANCHOR_TAG = 100000;
460 bool isBuilt = !theName.empty();
461 std::string aName = theName;
462 std::ostringstream aStream;
463 GeomShapePtr aResultShape = shape();
464 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
465 TopTools_MapOfShape aView;
466 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
467 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
468 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
469 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
470 if (!aView.Add(aRoot)) continue;
473 TNaming_Tool::NamedShape(aRoot, aData->shapeLab()).IsNull();
474 if (aNotInTree && !theIsStoreSeparate) {
475 // there is no sense to write history if old shape does not exist in the document
476 continue; // but if it is stored separately, it will be builded as a primitive
479 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
480 aRShape->setImpl((new TopoDS_Shape(aRoot)));
481 theMS->modified(aRShape, aList);
482 if (!theIsStoreSeparate) {
483 //keepTopLevelShapes(aList, aRoot, aResultShape);
484 removeBadShapes(aList);
486 // sort the list of images before naming
487 GeomAlgoAPI_SortListOfShapes::sort(aList);
489 // to trace situation where several objects are produced by one parent (#2317)
490 int aSameParentShapes = (aShapeIn.ShapeType() == TopAbs_WIRE
491 || aShapeIn.ShapeType() == TopAbs_SHELL
492 || aShapeIn.ShapeType() == TopAbs_COMPOUND) ? 0 : -1;
493 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator
494 anIt = aList.begin(), aLast = aList.end();
495 for (; anIt != aLast; anIt++) {
496 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
497 if (theSubShapes.isBound(*anIt)) {
498 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
499 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
501 isBuilt = !theName.empty();
502 if(!aRoot.IsSame(aNewShape)
503 && aResultShape->isSubShape((*anIt), false)
504 && !aResultShape->isSame(*anIt)) // to avoid put of same shape on main label and sub
506 if (!theIsStoreSeparate) {
508 } else if (aNotInTree) // check this new shape can not be represented as
509 // a sub-shape of higher level sub-shapes
511 TopAbs_ShapeEnum aNewType = aNewShape.ShapeType();
512 TopAbs_ShapeEnum anAncestorType = typeOfAncestor(aNewType);
513 if (anAncestorType != TopAbs_VERTEX) {
515 TopoDS_Shape aResultTShape = aResultShape->impl<TopoDS_Shape>();
516 TopExp_Explorer anAncestorExp(aResultTShape, anAncestorType);
517 for(; anAncestorExp.More() && !aFound; anAncestorExp.Next()) {
518 if (aResultTShape.IsSame(anAncestorExp.Current()))
520 TopExp_Explorer aSubExp(anAncestorExp.Current(), aNewType);
521 for(; aSubExp.More(); aSubExp.Next()) {
522 if (aNewShape.IsSame(aSubExp.Current())) {
529 continue; // not need to store this shape in the BRep structure
535 bool isFoundSameOld = false;
536 bool isFoundDiffOld = false;
538 // Check if new shape was already stored.
539 for (std::map<int, TNaming_Builder*>::iterator aBuildersIt = myBuilders.begin();
540 aBuildersIt != myBuilders.end();
543 TNaming_Builder* aBuilder = aBuildersIt->second;
544 for (TNaming_Iterator aNamingIt(aBuilder->NamedShape());
548 if (aNamingIt.NewShape().IsSame(aNewShape))
550 aNamingIt.OldShape().IsSame(aRoot) ? isFoundSameOld = true
551 : isFoundDiffOld = true;
552 aFoundTag = aBuildersIt->first;
556 if (isFoundSameOld || isFoundDiffOld) break;
559 if (isFoundSameOld) {
560 // Builder already contains same old->new shapes, don't store it twice.
564 int aBuilderTag = aSameParentShapes > 0 ? THE_ANCHOR_TAG : aTag;
566 int aCurShapeType = (int)((*anIt)->shapeType());
567 bool needSuffix = false; // suffix for the name based on the shape type
568 if (aCurShapeType != theKindOfShape) {
569 // modified shape has different type => set another tag
570 // to avoid shapes of different types on the same label
571 aBuilderTag = THE_ANCHOR_TAG;
576 switch (aCurShapeType) {
577 case GeomAPI_Shape::VERTEX: aSuffix = "_v_" + std::to_string(myVIndex++); break;
578 case GeomAPI_Shape::EDGE: aSuffix = "_e_" + std::to_string(myEIndex++); break;
579 case GeomAPI_Shape::FACE: aSuffix = "_f_" + std::to_string(myFIndex++); break;
584 std::vector<std::pair<TopoDS_Shape, TopoDS_Shape>> aKeepShapes, aMoveShapes;
585 if (isFoundDiffOld) {
586 // Found same new shape with different old shape.
587 if (aFoundTag >= THE_ANCHOR_TAG) {
588 // Found on separated tag.
589 aBuilderTag = aFoundTag; // Store it on the same tag.
590 isBuilt = false; // Don't change name;
592 // Found on previous tag.
593 if (aBuilderTag < THE_ANCHOR_TAG) {
594 // New shape shouls not be separated.
595 aBuilderTag = aFoundTag; // Store it on the same tag.
596 isBuilt = false; // Don't change name;
598 // New shape should be separated from others. Move shapes from found tag to new tag.
599 while (myBuilders.find(aBuilderTag) != myBuilders.end()) {
603 TNaming_Builder* aFoundBuilder = myBuilders.at(aFoundTag);
604 Handle(TNaming_NamedShape) aFoundNamedShape = aFoundBuilder->NamedShape();
605 TDF_Label aFoundLabel = aFoundNamedShape->Label();
606 TNaming_Evolution anEvolution = aFoundNamedShape->Evolution();
607 for (TNaming_Iterator aNamingIt(aFoundNamedShape);
611 std::pair<TopoDS_Shape, TopoDS_Shape> aShapesPair =
612 std::make_pair(aNamingIt.OldShape(), aNamingIt.NewShape());
613 aNamingIt.NewShape().IsSame(aNewShape) ? aMoveShapes.push_back(aShapesPair)
614 : aKeepShapes.push_back(aShapesPair);
617 aFoundNamedShape->Clear();
618 for (std::vector<std::pair<TopoDS_Shape, TopoDS_Shape>>::iterator aKeepIt =
620 aKeepIt != aKeepShapes.end();
623 if (anEvolution == TNaming_GENERATED) {
624 aFoundBuilder->Generated(aKeepIt->first, aKeepIt->second);
626 aFoundBuilder->Modify(aKeepIt->first, aKeepIt->second);
631 } else if (aBuilderTag == THE_ANCHOR_TAG) {
632 while (myBuilders.find(aBuilderTag) != myBuilders.end()) {
637 if(theIsStoreAsGenerated) {
638 // Here we store shapes as generated, to avoid problem when one parent shape produce
639 // several child shapes. In this case naming could not determine which shape to select.
640 builder(aBuilderTag)->Generated(aRoot, aNewShape);
641 for (std::vector<std::pair<TopoDS_Shape, TopoDS_Shape>>::iterator aMoveIt =
643 aMoveIt != aMoveShapes.end();
646 builder(aBuilderTag)->Generated(aMoveIt->first, aMoveIt->second);
648 } else if (aNotInTree) {
649 // not in tree -> store as primitive (stored as separated)
650 builder(aBuilderTag)->Generated(aNewShape);
651 } else if (aCurShapeType != theKindOfShape) {
652 // if different shape type is produced, make it as generated
653 builder(aBuilderTag)->Generated(aRoot, aNewShape);
655 builder(aBuilderTag)->Modify(aRoot, aNewShape);
656 for (std::vector<std::pair<TopoDS_Shape, TopoDS_Shape>>::iterator aMoveIt =
658 aMoveIt != aMoveShapes.end();
660 builder(aBuilderTag)->Modify(aMoveIt->first, aMoveIt->second);
664 aStream.str(std::string());
667 if (theIsStoreSeparate && !isFoundDiffOld)
668 aStream << "_" << anIndex++;
670 if (aSameParentShapes > 0) {
671 aStream.str(std::string());
673 aStream << aName << "_" << "divided" << "_" << myDividedIndex++;
677 buildName(aBuilderTag, aStream.str());
679 if(theIsStoreSeparate && !isFoundDiffOld) {
682 } else if (aResultShape->isSame(*anIt)) {
683 // keep the modification evolution on the root level (2241 - history propagation issue)
684 TNaming_Builder* aBuilder = builder(0);
685 TDF_Label aShapeLab = aBuilder->NamedShape()->Label();
686 Handle(TDF_Reference) aRef;
687 // Store only in case if it does not have reference.
688 if (!aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
689 if (theIsStoreAsGenerated) {
690 TNaming_Builder* aBuilder = builder(0);
691 if (!aBuilder->NamedShape().IsNull() &&
692 aBuilder->NamedShape()->Evolution() != TNaming_GENERATED) {
693 myBuilders.erase(0); // clear old builder to avoid different evolutions crash
695 builder(0)->Generated(aRoot, aNewShape);
697 TNaming_Builder* aBuilder = builder(0);
698 if (!aBuilder->NamedShape().IsNull() &&
699 aBuilder->NamedShape()->Evolution() != TNaming_MODIFY) {
700 myBuilders.erase(0); // clear old builder to avoid different evolutions crash
702 builder(0)->Modify(aRoot, aNewShape);
710 void Model_BodyBuilder::loadAndOrientGeneratedShapes (
711 GeomAlgoAPI_MakeShape* theMS,
712 std::shared_ptr<GeomAPI_Shape> theShapeIn,
713 const int theKindOfShape,
715 const std::string& theName,
716 GeomAPI_DataMapOfShapeShape& theSubShapes)
718 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
719 TopTools_MapOfShape aView;
720 bool isBuilt = !theName.empty();
721 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
722 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
723 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
724 if (!aView.Add(aRoot)) continue;
725 //if (TNaming_Tool::NamedShape(aRoot, builder(theTag)->NamedShape()->Label()).IsNull())
726 // continue; // there is no sense to write history if old shape does not exist in the document
728 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
729 aRShape->setImpl((new TopoDS_Shape(aRoot)));
730 theMS->generated(aRShape, aList);
731 keepTopLevelShapes(aList, aRoot);
732 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator
733 anIt = aList.begin(), aLast = aList.end();
734 for (; anIt != aLast; anIt++) {
735 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
736 if (theSubShapes.isBound(*anIt)) {
737 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
738 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
740 if (!aRoot.IsSame (aNewShape)) {
741 builder(theTag)->Generated(aRoot,aNewShape);
743 buildName(theTag, theName);
745 TopAbs_ShapeEnum aGenShapeType = aNewShape.ShapeType();
746 if(aGenShapeType == TopAbs_WIRE || aGenShapeType == TopAbs_SHELL) {
747 TopAbs_ShapeEnum anExplodeShapeType =
748 aGenShapeType == TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE;
749 const TDF_Label aLabel = builder(theTag)->NamedShape()->Label();
751 std::shared_ptr<Model_Document> aDoc =
752 std::dynamic_pointer_cast<Model_Document>(document());
753 for(TopExp_Explorer anExp(aNewShape, anExplodeShapeType); anExp.More(); anExp.Next()) {
754 TDF_Label aChildLabel = aLabel.FindChild(aTag);
755 TNaming_Builder aBuilder(aChildLabel);
756 aBuilder.Generated(aRoot, anExp.Current());
757 TCollection_AsciiString aChildName =
758 TCollection_AsciiString((theName + "_").c_str()) + aTag;
759 TDataStd_Name::Set(aChildLabel, aChildName.ToCString());
767 //=======================================================================
768 int getDangleShapes(const TopoDS_Shape& theShapeIn,
769 const TopAbs_ShapeEnum theGeneratedFrom,
770 TopTools_DataMapOfShapeShape& theDangles)
773 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
774 TopAbs_ShapeEnum GeneratedTo;
775 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
776 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
777 else return Standard_False;
778 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
779 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
780 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
781 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
782 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
784 return theDangles.Extent();
787 //=======================================================================
788 void loadGeneratedDangleShapes(
789 const TopoDS_Shape& theShapeIn,
790 const TopAbs_ShapeEnum theGeneratedFrom,
791 TNaming_Builder * theBuilder)
793 TopTools_DataMapOfShapeShape dangles;
794 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
795 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
796 for (; itr.More(); itr.Next())
797 theBuilder->Generated(itr.Key(), itr.Value());
800 //=======================================================================
801 void Model_BodyBuilder::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
802 const std::string& theName, int& theTag)
804 if(theShape->isNull()) return;
805 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
807 if (aShape.ShapeType() == TopAbs_SOLID) {
808 TopExp_Explorer expl(aShape, TopAbs_FACE);
809 for (; expl.More(); expl.Next()) {
810 builder(theTag)->Generated(expl.Current());
811 TCollection_AsciiString aStr(theTag);
812 aName = theName + aStr.ToCString();
813 buildName(theTag, aName);
817 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
818 // load faces and all the free edges
819 TopTools_IndexedMapOfShape Faces;
820 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
821 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
822 TopExp_Explorer expl(aShape, TopAbs_FACE);
823 for (; expl.More(); expl.Next()) {
824 builder(theTag)->Generated(expl.Current());
825 TCollection_AsciiString aStr(theTag);
826 aName = theName + aStr.ToCString();
827 buildName(theTag, aName);
831 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
832 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
833 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
835 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
836 if (aLL.Extent() < 2) {
837 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
839 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
840 TCollection_AsciiString aStr(theTag);
841 aName = theName + aStr.ToCString();
842 buildName(theTag, aName);
845 TopTools_ListIteratorOfListOfShape anIter(aLL);
846 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
848 if(aFace.IsEqual(anIter.Value())) {
849 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
850 TCollection_AsciiString aStr(theTag);
851 aName = theName + aStr.ToCString();
852 buildName(theTag, aName);
857 } else if (aShape.ShapeType() == TopAbs_WIRE) {
858 TopTools_IndexedMapOfShape Edges;
859 BRepTools::Map3DEdges(aShape, Edges);
860 if (Edges.Extent() == 1) {
861 builder(theTag++)->Generated(Edges.FindKey(1));
862 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
863 for (; expl.More(); expl.Next()) {
864 builder(theTag)->Generated(expl.Current());
865 TCollection_AsciiString aStr(theTag);
866 aName = theName + aStr.ToCString();
867 buildName(theTag, aName);
871 TopExp_Explorer expl(aShape, TopAbs_EDGE);
872 for (; expl.More(); expl.Next()) {
873 builder(theTag)->Generated(expl.Current());
874 TCollection_AsciiString aStr(theTag);
875 aName = theName + aStr.ToCString();
876 buildName(theTag, aName);
879 // and load generated vertices.
880 TopTools_DataMapOfShapeShape generated;
881 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
883 TNaming_Builder* pBuilder = builder(theTag++);
884 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
887 } else if (aShape.ShapeType() == TopAbs_EDGE) {
888 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
889 for (; expl.More(); expl.Next()) {
890 builder(theTag)->Generated(expl.Current());
891 TCollection_AsciiString aStr(theTag);
892 aName = theName + aStr.ToCString();
893 buildName(theTag, aName);
899 //=======================================================================
900 int findAmbiguities(const TopoDS_Shape& theShapeIn,
901 TopTools_ListOfShape& theList)
904 // edges -> ancestor faces list
905 TopTools_IndexedDataMapOfShapeListOfShape aSubShapeAndAncestors;
906 TopExp::MapShapesAndAncestors(theShapeIn, TopAbs_EDGE, TopAbs_FACE, aSubShapeAndAncestors);
907 // keeps the shapes which are already in the resulting list
908 TopTools_MapOfShape alreadyThere;
909 // map from faces identifier (combination of hash-codes) to list of edges produced such ID
910 NCollection_DataMap<int, NCollection_List<TopoDS_Shape> > aFacesIDs;
912 TopTools_IndexedDataMapOfShapeListOfShape::Iterator anAncestorsIter(aSubShapeAndAncestors);
913 for (; anAncestorsIter.More(); anAncestorsIter.Next()) {
914 const TopTools_ListOfShape& ancestors = anAncestorsIter.Value();
915 if (ancestors.Extent() < 2)
917 Standard_Integer anID = 0;
918 for(TopTools_ListIteratorOfListOfShape aFaceIt(ancestors); aFaceIt.More(); aFaceIt.Next()) {
919 anID ^= HashCode(aFaceIt.ChangeValue(), 1990657); // Pierpont prime
921 if (aFacesIDs.IsBound(anID)) { // there found same edge, check they really have same faces
922 const NCollection_List<TopoDS_Shape>& aSameFaces1 =
923 aSubShapeAndAncestors.FindFromKey(anAncestorsIter.Key());
924 NCollection_List<TopoDS_Shape>::Iterator aSameEdge(aFacesIDs.ChangeFind(anID));
925 for(; aSameEdge.More(); aSameEdge.Next()) {
926 const NCollection_List<TopoDS_Shape>& aSameFaces2 =
927 aSubShapeAndAncestors.FindFromKey(aSameEdge.Value());
928 if (aSameFaces2.Extent() != aSameFaces1.Extent()) // the number of faces is different
931 NCollection_List<TopoDS_Shape>::Iterator aFaceIter1(aSameFaces1);
932 for(; aFaceIter1.More(); aFaceIter1.Next()) {
933 NCollection_List<TopoDS_Shape>::Iterator aFaceIter2(aSameFaces2);
934 for(; aFaceIter2.More(); aFaceIter2.Next()) {
935 if (aFaceIter1.Value().IsSame(aFaceIter2.Value()))
938 if (!aFaceIter2.More()) // aFaceIter1 contains a face, which is not in aFaceIter2
941 if (!aFaceIter1.More()) { // all the faces are same => put to the result
942 if (alreadyThere.Add(aSameEdge.Value()))
943 theList.Append(aSameEdge.Value());
944 if (alreadyThere.Add(anAncestorsIter.Key()))
945 theList.Append(anAncestorsIter.Key());
948 } else { // ID is unique, just add this edge
949 aFacesIDs.Bind(anID, NCollection_List<TopoDS_Shape>());
951 aFacesIDs.ChangeFind(anID).Append(anAncestorsIter.Key()); // add to the list anyway
953 return theList.Extent();
956 //=======================================================================
957 void Model_BodyBuilder::loadFirstLevel(
958 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
960 if(theShape->isNull()) return;
961 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
963 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
964 TopoDS_Iterator itr(aShape);
965 for (; itr.More(); itr.Next()) {
966 builder(theTag)->Generated(itr.Value());
967 TCollection_AsciiString aStr(theTag);
968 aName = theName + aStr.ToCString();
969 buildName(theTag, aName);
970 if(!theName.empty()) buildName(theTag, aName);
972 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
973 itr.Value().ShapeType() == TopAbs_COMPSOLID)
975 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
976 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
977 loadFirstLevel(itrShape, theName, theTag);
979 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
980 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
981 loadNextLevels(itrShape, theName, theTag);
985 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
986 itrShape->setImpl(new TopoDS_Shape(aShape));
987 loadNextLevels(itrShape, theName, theTag);
989 TopTools_ListOfShape aList;
990 if(findAmbiguities(aShape, aList)) {
991 TopTools_ListIteratorOfListOfShape it(aList);
992 for (; it.More(); it.Next(),theTag++) {
993 builder(theTag)->Generated(it.Value());
994 TCollection_AsciiString aStr(theTag);
995 aName = theName + aStr.ToCString();
996 buildName(theTag, aName);
1001 //=======================================================================
1002 void Model_BodyBuilder::loadDisconnectedEdges(
1003 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
1005 if(theShape->isNull()) return;
1006 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
1007 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
1008 TopTools_ListOfShape empty;
1009 TopExp_Explorer explF(aShape, TopAbs_FACE);
1010 for (; explF.More(); explF.Next()) {
1011 const TopoDS_Shape& aFace = explF.Current();
1012 TopExp_Explorer explV(aFace, TopAbs_EDGE);
1013 for (; explV.More(); explV.Next()) {
1014 const TopoDS_Shape& anEdge = explV.Current();
1015 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
1016 Standard_Boolean faceIsNew = Standard_True;
1017 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
1018 for (; itrF.More(); itrF.Next()) {
1019 if (itrF.Value().IsSame(aFace)) {
1020 faceIsNew = Standard_False;
1025 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
1029 TopTools_MapOfShape anEdgesToDelete;
1030 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
1032 for(;anEx.More();anEx.Next()) {
1033 Standard_Boolean aC0 = Standard_False;
1034 TopoDS_Shape anEdge1 = anEx.Current();
1035 if (edgeNaborFaces.IsBound(anEdge1)) {
1036 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
1037 if (aList1.Extent()<2) continue;
1038 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
1039 for (; itr.More(); itr.Next()) {
1040 TopoDS_Shape anEdge2 = itr.Key();
1041 if(anEdgesToDelete.Contains(anEdge2)) continue;
1042 if (anEdge1.IsSame(anEdge2)) continue;
1043 const TopTools_ListOfShape& aList2 = itr.Value();
1044 // compare lists of the neighbour faces of edge1 and edge2
1045 if (aList1.Extent() == aList2.Extent()) {
1046 Standard_Integer aMatches = 0;
1047 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
1048 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
1049 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
1050 if (aMatches == aList1.Extent()) {
1052 builder(theTag)->Generated(anEdge2);
1053 anEdgesToDelete.Add(anEdge2);
1054 TCollection_AsciiString aStr(theTag);
1055 aName = theName + aStr.ToCString();
1056 buildName(theTag, aName);
1061 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
1062 for(;itDelete.More();itDelete.Next())
1063 edgeNaborFaces.UnBind(itDelete.Key());
1064 edgeNaborFaces.UnBind(anEdge1);
1067 builder(theTag)->Generated(anEdge1);
1068 TCollection_AsciiString aStr(theTag);
1069 aName = theName + aStr.ToCString();
1070 buildName(theTag, aName);
1076 void Model_BodyBuilder::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape,
1077 const std::string& theName, int& theTag)
1079 if(theShape->isNull()) return;
1080 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
1081 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
1082 TopTools_ListOfShape empty;
1083 TopExp_Explorer explF(aShape, TopAbs_EDGE);
1084 for (; explF.More(); explF.Next()) {
1085 const TopoDS_Shape& anEdge = explF.Current();
1086 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
1087 for (; explV.More(); explV.Next()) {
1088 const TopoDS_Shape& aVertex = explV.Current();
1089 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
1090 Standard_Boolean faceIsNew = Standard_True;
1091 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
1092 for (; itrF.More(); itrF.Next()) {
1093 if (itrF.Value().IsSame(anEdge)) {
1094 faceIsNew = Standard_False;
1099 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
1104 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
1105 for (; itr.More(); itr.Next()) {
1106 const TopTools_ListOfShape& naborEdges = itr.Value();
1107 if (naborEdges.Extent() < 2) {
1108 builder(theTag)->Generated(itr.Key());
1109 TCollection_AsciiString aStr(theTag);
1110 aName = theName + aStr.ToCString();
1111 buildName(theTag, aName);
1117 std::shared_ptr<GeomAPI_Shape> Model_BodyBuilder::shape()
1119 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
1120 if (aData && aData->isValid()) {
1121 TDF_Label aShapeLab = aData->shapeLab();
1122 Handle(TDF_Reference) aRef;
1123 if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
1124 aShapeLab = aRef->Get();
1126 Handle(TNaming_NamedShape) aName;
1127 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
1128 TopoDS_Shape aShape = aName->Get();
1129 if (!aShape.IsNull()) {
1130 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
1131 aRes->setImpl(new TopoDS_Shape(aShape));
1136 return std::shared_ptr<GeomAPI_Shape>();
1139 bool Model_BodyBuilder::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
1141 if (theShape.get()) {
1142 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
1143 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
1145 TDF_Label& aShapeLab = aData->shapeLab();
1146 Handle(TNaming_NamedShape) aName;
1147 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
1148 TopoDS_Shape aLatest = TNaming_Tool::CurrentShape(aName);
1149 if (aLatest.IsNull())
1151 if (aLatest.IsEqual(aShape))
1153 // check sub-shapes for comp-solids:
1154 for (TopExp_Explorer anExp(aShape, aLatest.ShapeType()); anExp.More(); anExp.Next()) {
1155 if (aLatest.IsEqual(anExp.Current()))