1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_ResultBody.cpp
4 // Created: 08 Jul 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_ResultBody.h>
8 #include <Model_Data.h>
9 #include <Model_Document.h>
10 #include <ModelAPI_AttributeIntArray.h>
11 #include <TNaming_Builder.hxx>
12 #include <TNaming_NamedShape.hxx>
13 #include <TNaming_Iterator.hxx>
14 #include <TDataStd_Name.hxx>
15 #include <TDataStd_Integer.hxx>
17 #include <TopoDS_Face.hxx>
18 #include <TDF_ChildIterator.hxx>
19 #include <TopTools_MapOfShape.hxx>
20 #include <TopExp_Explorer.hxx>
21 #include <TopTools_ListOfShape.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopTools_DataMapOfShapeListOfShape.hxx>
24 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
25 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
26 #include <TopTools_MapIteratorOfMapOfShape.hxx>
27 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
28 #include <TopTools_IndexedMapOfShape.hxx>
29 #include <TopTools_DataMapOfShapeShape.hxx>
31 #include <BRepTools.hxx>
32 #include <BRep_Tool.hxx>
33 #include <GeomAPI_Shape.h>
34 #include <GeomAlgoAPI_MakeShape.h>
35 #include <Config_PropManager.h>
37 //#include <TCollection_AsciiString.hxx>
38 //#include <TDF_Tool.hxx>
39 //#define DEB_IMPORT 1
41 Model_ResultBody::Model_ResultBody()
43 myIsDisabled = true; // by default it is not initialized and false to be after created
44 setIsConcealed(false);
47 void Model_ResultBody::initAttributes()
49 // append the color attribute. It is empty, the attribute will be filled by a request
50 DataPtr aData = data();
51 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
54 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
55 std::string& theDefault)
57 theSection = "Visualization";
58 theName = "result_body_color";
59 theDefault = DEFAULT_COLOR();
62 // Converts evolution of naming shape to selection evelution and back to avoid
63 // naming support on the disabled results. Deeply in the labels tree, recursively.
64 static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) {
65 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
66 Handle(TNaming_NamedShape) aName;
68 if (theLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
69 TNaming_Evolution aNSEvol = aName->Evolution();
70 if ((aNSEvol == TNaming_SELECTED && theFlag) ||
71 (aNSEvol != TNaming_SELECTED && !theFlag)) { // nothing to do, it is already correct
74 anEvolution = (int)(aNSEvol);
75 for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
76 aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
77 (anIter.OldShape(), anIter.NewShape()));
81 theLab.ForgetAttribute(TNaming_NamedShape::GetID());
83 TNaming_Builder aBuilder(theLab);
84 TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
85 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
86 for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
87 if (theFlag) { // disabled => make selection
88 aBuilder.Select(aPairsIter->first, aPairsIter->second);
89 } else if (anEvol == TNaming_GENERATED) {
90 aBuilder.Generated(aPairsIter->first, aPairsIter->second);
91 } else if (anEvol == TNaming_MODIFY) {
92 aBuilder.Modify(aPairsIter->first, aPairsIter->second);
93 } else if (anEvol == TNaming_DELETE) {
94 aBuilder.Delete(aPairsIter->first);
95 } else if (anEvol == TNaming_PRIMITIVE) {
96 aBuilder.Generated(aPairsIter->second);
99 // recursive call for all sub-labels
100 TDF_ChildIterator anIter(theLab, Standard_False);
101 for(; anIter.More(); anIter.Next()) {
102 EvolutionToSelection(anIter.Value(), theFlag);
106 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
108 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
109 if (aChanged) { // state is changed, so modifications are needed
110 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
111 if (!aData) // unknown case
113 TDF_Label& aShapeLab = aData->shapeLab();
114 EvolutionToSelection(aShapeLab, theFlag);
119 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
121 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
123 TDF_Label& aShapeLab = aData->shapeLab();
126 // store the new shape as primitive
127 TNaming_Builder aBuilder(aShapeLab);
130 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
132 return; // null shape inside
134 aBuilder.Generated(aShape);
136 if(!aBuilder.NamedShape()->IsEmpty()) {
137 Handle(TDataStd_Name) anAttr;
138 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
139 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
141 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
142 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
149 void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
150 const std::shared_ptr<GeomAPI_Shape>& theToShape)
152 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
154 TDF_Label& aShapeLab = aData->shapeLab();
157 // store the new shape as primitive
158 TNaming_Builder aBuilder(aShapeLab);
159 if (!theFromShape || !theToShape)
161 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
162 if (aShapeBasis.IsNull())
163 return; // null shape inside
164 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
165 if (aShapeNew.IsNull())
166 return; // null shape inside
167 aBuilder.Generated(aShapeBasis, aShapeNew);
169 if(!aBuilder.NamedShape()->IsEmpty()) {
170 Handle(TDataStd_Name) anAttr;
171 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
172 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
174 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
175 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
182 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
183 const std::shared_ptr<GeomAPI_Shape>& theNewShape)
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 (!theOldShape || !theNewShape)
194 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
195 if (aShapeOld.IsNull())
196 return; // null shape inside
197 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
198 if (aShapeNew.IsNull())
199 return; // null shape inside
200 aBuilder.Modify(aShapeOld, aShapeNew);
204 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
206 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
208 TDF_Label& aShapeLab = aData->shapeLab();
209 Handle(TNaming_NamedShape) aName;
210 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
211 TopoDS_Shape aShape = aName->Get();
212 if (!aShape.IsNull()) {
213 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
214 aRes->setImpl(new TopoDS_Shape(aShape));
219 return std::shared_ptr<GeomAPI_Shape>();
222 void Model_ResultBody::clean()
224 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
225 for(; aBuilder != myBuilders.end(); aBuilder++)
230 Model_ResultBody::~Model_ResultBody()
235 TNaming_Builder* Model_ResultBody::builder(const int theTag)
237 if (myBuilders.size() <= (unsigned int)theTag) {
238 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
240 if (!myBuilders[theTag]) {
241 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
242 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
243 //TCollection_AsciiString entry;//
244 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
245 //cout << "Label = " <<entry.ToCString() <<endl;
247 return myBuilders[theTag];
250 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
252 std::string aName = data()->name() + "/" + theName;
253 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
254 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
255 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
257 void Model_ResultBody::generated(
258 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
260 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
261 builder(theTag)->Generated(aShape);
263 buildName(theTag, theName);
266 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
267 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
269 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
270 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
271 builder(theTag)->Generated(anOldShape, aNewShape);
273 buildName(theTag, theName);
277 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
278 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
280 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
281 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
282 builder(theTag)->Modify(anOldShape, aNewShape);
284 buildName(theTag, theName);
287 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
290 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
291 builder(theTag)->Delete(aShape);
294 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
295 std::shared_ptr<GeomAPI_Shape> theShapeIn,
296 const int theKindOfShape,
299 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
300 TopTools_MapOfShape aView;
301 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
302 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
303 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
304 if (!aView.Add(aRoot)) continue;
305 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
306 aRShape->setImpl((new TopoDS_Shape(aRoot)));
307 if (theMS->isDeleted (aRShape)) {
308 builder(theTag)->Delete(aRoot);
313 void Model_ResultBody::loadAndOrientModifiedShapes (
314 GeomAlgoAPI_MakeShape* theMS,
315 std::shared_ptr<GeomAPI_Shape> theShapeIn,
316 const int theKindOfShape,
318 const std::string& theName,
319 GeomAPI_DataMapOfShapeShape& theSubShapes)
321 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
322 TopTools_MapOfShape aView;
323 bool isBuilt = theName.empty();
324 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
325 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
326 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
327 if (!aView.Add(aRoot)) continue;
329 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
330 aRShape->setImpl((new TopoDS_Shape(aRoot)));
331 theMS->modified(aRShape, aList);
332 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
333 for (; anIt != aLast; anIt++) {
334 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
335 if (theSubShapes.isBound(*anIt)) {
336 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
337 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
339 if (!aRoot.IsSame (aNewShape)) {
340 builder(theTag)->Modify(aRoot,aNewShape);
342 buildName(theTag, theName);
348 void Model_ResultBody::loadAndOrientGeneratedShapes (
349 GeomAlgoAPI_MakeShape* theMS,
350 std::shared_ptr<GeomAPI_Shape> theShapeIn,
351 const int theKindOfShape,
353 const std::string& theName,
354 GeomAPI_DataMapOfShapeShape& theSubShapes)
356 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
357 TopTools_MapOfShape aView;
358 bool isBuilt = theName.empty();
359 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
360 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
361 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
362 if (!aView.Add(aRoot)) continue;
364 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
365 aRShape->setImpl((new TopoDS_Shape(aRoot)));
366 theMS->generated(aRShape, aList);
367 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
368 for (; anIt != aLast; anIt++) {
369 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
370 if (theSubShapes.isBound(*anIt)) {
371 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
372 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
374 if (!aRoot.IsSame (aNewShape)) {
375 builder(theTag)->Generated(aRoot,aNewShape);
377 buildName(theTag, theName);
383 //=======================================================================
384 int getDangleShapes(const TopoDS_Shape& theShapeIn,
385 const TopAbs_ShapeEnum theGeneratedFrom,
386 TopTools_DataMapOfShapeShape& theDangles)
389 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
390 TopAbs_ShapeEnum GeneratedTo;
391 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
392 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
393 else return Standard_False;
394 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
395 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
396 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
397 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
398 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
400 return theDangles.Extent();
403 //=======================================================================
404 void loadGeneratedDangleShapes(
405 const TopoDS_Shape& theShapeIn,
406 const TopAbs_ShapeEnum theGeneratedFrom,
407 TNaming_Builder * theBuilder)
409 TopTools_DataMapOfShapeShape dangles;
410 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
411 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
412 for (; itr.More(); itr.Next())
413 theBuilder->Generated(itr.Key(), itr.Value());
416 //=======================================================================
417 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
418 const std::string& theName, int& theTag)
420 if(theShape->isNull()) return;
421 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
423 if (aShape.ShapeType() == TopAbs_SOLID) {
424 TopExp_Explorer expl(aShape, TopAbs_FACE);
425 for (; expl.More(); expl.Next()) {
426 builder(theTag)->Generated(expl.Current());
427 TCollection_AsciiString aStr(theTag);
428 aName = theName + aStr.ToCString();
429 buildName(theTag, aName);
433 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
434 // load faces and all the free edges
435 TopTools_IndexedMapOfShape Faces;
436 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
437 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
438 TopExp_Explorer expl(aShape, TopAbs_FACE);
439 for (; expl.More(); expl.Next()) {
440 builder(theTag)->Generated(expl.Current());
441 TCollection_AsciiString aStr(theTag);
442 aName = theName + aStr.ToCString();
443 buildName(theTag, aName);
447 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
448 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
449 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
451 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
452 if (aLL.Extent() < 2) {
453 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
455 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
456 TCollection_AsciiString aStr(theTag);
457 aName = theName + aStr.ToCString();
458 buildName(theTag, aName);
461 TopTools_ListIteratorOfListOfShape anIter(aLL);
462 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
464 if(aFace.IsEqual(anIter.Value())) {
465 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
466 TCollection_AsciiString aStr(theTag);
467 aName = theName + aStr.ToCString();
468 buildName(theTag, aName);
473 } else if (aShape.ShapeType() == TopAbs_WIRE) {
474 TopTools_IndexedMapOfShape Edges;
475 BRepTools::Map3DEdges(aShape, Edges);
476 if (Edges.Extent() == 1) {
477 builder(++theTag)->Generated(Edges.FindKey(1));
478 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
479 for (; expl.More(); expl.Next()) {
480 builder(theTag)->Generated(expl.Current());
481 TCollection_AsciiString aStr(theTag);
482 aName = theName + aStr.ToCString();
483 buildName(theTag, aName);
487 TopExp_Explorer expl(aShape, TopAbs_EDGE);
488 for (; expl.More(); expl.Next()) {
489 builder(theTag)->Generated(expl.Current());
490 TCollection_AsciiString aStr(theTag);
491 aName = theName + aStr.ToCString();
492 buildName(theTag, aName);
495 // and load generated vertices.
496 TopTools_DataMapOfShapeShape generated;
497 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
499 TNaming_Builder* pBuilder = builder(theTag++);
500 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
503 } else if (aShape.ShapeType() == TopAbs_EDGE) {
504 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
505 for (; expl.More(); expl.Next()) {
506 builder(theTag)->Generated(expl.Current());
507 TCollection_AsciiString aStr(theTag);
508 aName = theName + aStr.ToCString();
509 buildName(theTag, aName);
515 //=======================================================================
516 int findAmbiguities(const TopoDS_Shape& theShapeIn,
517 TopTools_ListOfShape& theList)
521 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
522 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
523 TopAbs_ShapeEnum aTA(TopAbs_FACE);
524 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
525 TopTools_ListOfShape aKeyList;
526 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
527 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
528 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
529 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
531 TopTools_ListIteratorOfListOfShape it(ancestors1);
532 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
533 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
534 if (i == j) continue;
535 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
536 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
537 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
538 int aNum (ancestors2.Extent());
539 TopTools_ListIteratorOfListOfShape it(ancestors2);
540 for(;it.More();it.Next())
541 if(aMap1.Contains(it.Value())) aNum--;
543 if(aMap2.Add(aKeyEdge1))
544 aKeyList.Append(aKeyEdge1);
545 if(aMap2.Add(aKeyEdge2))
546 aKeyList.Append(aKeyEdge2);
549 } // at the end ==> List of edges to be named in addition
551 aNumEdges = aKeyList.Extent();
553 theList.Assign(aKeyList);
557 //=======================================================================
558 void Model_ResultBody::loadFirstLevel(
559 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
561 if(theShape->isNull()) return;
562 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
564 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
565 TopoDS_Iterator itr(aShape);
566 for (; itr.More(); itr.Next(),theTag++) {
567 builder(theTag)->Generated(itr.Value());
568 TCollection_AsciiString aStr(theTag);
569 aName = theName + aStr.ToCString();
570 buildName(theTag, aName);
571 if(!theName.empty()) buildName(theTag, aName);
572 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
573 itr.Value().ShapeType() == TopAbs_COMPSOLID)
575 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
576 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
577 loadFirstLevel(itrShape, theName, theTag);
579 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
580 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
581 loadNextLevels(itrShape, theName, theTag);
585 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
586 itrShape->setImpl(new TopoDS_Shape(aShape));
587 loadNextLevels(itrShape, theName, theTag);
589 TopTools_ListOfShape aList;
590 if(findAmbiguities(aShape, aList)) {
591 TopTools_ListIteratorOfListOfShape it(aList);
592 for (; it.More(); it.Next(),theTag++) {
593 builder(theTag)->Generated(it.Value());
594 TCollection_AsciiString aStr(theTag);
595 aName = theName + aStr.ToCString();
596 buildName(theTag, aName);
601 //=======================================================================
602 void Model_ResultBody::loadDisconnectedEdges(
603 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
605 if(theShape->isNull()) return;
606 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
607 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
608 TopTools_ListOfShape empty;
609 TopExp_Explorer explF(aShape, TopAbs_FACE);
610 for (; explF.More(); explF.Next()) {
611 const TopoDS_Shape& aFace = explF.Current();
612 TopExp_Explorer explV(aFace, TopAbs_EDGE);
613 for (; explV.More(); explV.Next()) {
614 const TopoDS_Shape& anEdge = explV.Current();
615 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
616 Standard_Boolean faceIsNew = Standard_True;
617 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
618 for (; itrF.More(); itrF.Next()) {
619 if (itrF.Value().IsSame(aFace)) {
620 faceIsNew = Standard_False;
625 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
629 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
630 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
631 for(int i=1; i <= aDM.Extent(); i++) {
632 if(aDM.FindFromIndex(i).Extent() > 1) continue;
633 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
635 builder(theTag)->Generated(aDM.FindKey(i));
636 TCollection_AsciiString aStr(theTag);
637 std::string aName = theName + aStr.ToCString();
638 buildName(theTag, aName);
641 BRepTools::Write(aDM.FindKey(i), aName.c_str());
646 TopTools_MapOfShape anEdgesToDelete;
647 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
649 for(;anEx.More();anEx.Next()) {
650 Standard_Boolean aC0 = Standard_False;
651 TopoDS_Shape anEdge1 = anEx.Current();
652 if (edgeNaborFaces.IsBound(anEdge1)) {
653 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
654 if (aList1.Extent()<2) continue;
655 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
656 for (; itr.More(); itr.Next()) {
657 TopoDS_Shape anEdge2 = itr.Key();
658 if(anEdgesToDelete.Contains(anEdge2)) continue;
659 if (anEdge1.IsSame(anEdge2)) continue;
660 const TopTools_ListOfShape& aList2 = itr.Value();
661 // compare lists of the neighbour faces of edge1 and edge2
662 if (aList1.Extent() == aList2.Extent()) {
663 Standard_Integer aMatches = 0;
664 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
665 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
666 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
667 if (aMatches == aList1.Extent()) {
669 builder(theTag)->Generated(anEdge2);
670 anEdgesToDelete.Add(anEdge2);
671 TCollection_AsciiString aStr(theTag);
672 aName = theName + aStr.ToCString();
673 buildName(theTag, aName);
678 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
679 for(;itDelete.More();itDelete.Next())
680 edgeNaborFaces.UnBind(itDelete.Key());
681 edgeNaborFaces.UnBind(anEdge1);
684 builder(theTag)->Generated(anEdge1);
685 TCollection_AsciiString aStr(theTag);
686 aName = theName + aStr.ToCString();
687 buildName(theTag, aName);
693 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
695 if(theShape->isNull()) return;
696 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
697 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
698 TopTools_ListOfShape empty;
699 TopExp_Explorer explF(aShape, TopAbs_EDGE);
700 for (; explF.More(); explF.Next()) {
701 const TopoDS_Shape& anEdge = explF.Current();
702 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
703 for (; explV.More(); explV.Next()) {
704 const TopoDS_Shape& aVertex = explV.Current();
705 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
706 Standard_Boolean faceIsNew = Standard_True;
707 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
708 for (; itrF.More(); itrF.Next()) {
709 if (itrF.Value().IsSame(anEdge)) {
710 faceIsNew = Standard_False;
715 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
720 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
721 for (; itr.More(); itr.Next()) {
722 const TopTools_ListOfShape& naborEdges = itr.Value();
723 if (naborEdges.Extent() < 2) {
724 builder(theTag)->Generated(itr.Key());
725 TCollection_AsciiString aStr(theTag);
726 aName = theName + aStr.ToCString();
727 buildName(theTag, aName);