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 <TDataStd_Name.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Face.hxx>
17 #include <TDF_ChildIterator.hxx>
18 #include <TopTools_MapOfShape.hxx>
19 #include <TopExp_Explorer.hxx>
20 #include <TopTools_ListOfShape.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <TopTools_DataMapOfShapeListOfShape.hxx>
23 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
24 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
25 #include <TopTools_MapIteratorOfMapOfShape.hxx>
26 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <TopTools_DataMapOfShapeShape.hxx>
30 #include <BRepTools.hxx>
31 #include <BRep_Tool.hxx>
32 #include <GeomAPI_Shape.h>
33 #include <GeomAlgoAPI_MakeShape.h>
34 #include <Config_PropManager.h>
36 //#include <TCollection_AsciiString.hxx>
37 //#include <TDF_Tool.hxx>
38 //#define DEB_IMPORT 1
40 #define RESULT_BODY_COLOR "#E0A01B"
42 Model_ResultBody::Model_ResultBody()
44 setIsConcealed(false);
47 void Model_ResultBody::initAttributes()
49 // append the color attribute
50 DataPtr aData = data();
51 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
52 AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
53 std::vector<int> aRGB;
54 aRGB = Config_PropManager::color("Visualization", "result_body_color", RESULT_BODY_COLOR);
55 aColorAttr->setSize(3);
56 aColorAttr->setValue(0, aRGB[0]);
57 aColorAttr->setValue(1, aRGB[1]);
58 aColorAttr->setValue(2, aRGB[2]);
61 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
63 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
65 TDF_Label& aShapeLab = aData->shapeLab();
68 // store the new shape as primitive
69 TNaming_Builder aBuilder(aShapeLab);
72 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
74 return; // null shape inside
76 aBuilder.Generated(aShape);
78 if(!aBuilder.NamedShape()->IsEmpty()) {
79 Handle(TDataStd_Name) anAttr;
80 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
81 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
83 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
84 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
91 void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
92 const std::shared_ptr<GeomAPI_Shape>& theToShape)
94 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
96 TDF_Label& aShapeLab = aData->shapeLab();
99 // store the new shape as primitive
100 TNaming_Builder aBuilder(aShapeLab);
101 if (!theFromShape || !theToShape)
103 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
104 if (aShapeBasis.IsNull())
105 return; // null shape inside
106 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
107 if (aShapeNew.IsNull())
108 return; // null shape inside
109 aBuilder.Generated(aShapeBasis, aShapeNew);
111 if(!aBuilder.NamedShape()->IsEmpty()) {
112 Handle(TDataStd_Name) anAttr;
113 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
114 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
116 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
117 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
124 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
125 const std::shared_ptr<GeomAPI_Shape>& theNewShape)
127 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
129 TDF_Label& aShapeLab = aData->shapeLab();
132 // store the new shape as primitive
133 TNaming_Builder aBuilder(aShapeLab);
134 if (!theOldShape || !theNewShape)
136 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
137 if (aShapeOld.IsNull())
138 return; // null shape inside
139 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
140 if (aShapeNew.IsNull())
141 return; // null shape inside
142 aBuilder.Modify(aShapeOld, aShapeNew);
146 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
148 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
150 TDF_Label& aShapeLab = aData->shapeLab();
151 Handle(TNaming_NamedShape) aName;
152 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
153 TopoDS_Shape aShape = aName->Get();
154 if (!aShape.IsNull()) {
155 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
156 aRes->setImpl(new TopoDS_Shape(aShape));
161 return std::shared_ptr<GeomAPI_Shape>();
164 void Model_ResultBody::clean()
166 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
167 for(; aBuilder != myBuilders.end(); aBuilder++)
172 Model_ResultBody::~Model_ResultBody()
177 TNaming_Builder* Model_ResultBody::builder(const int theTag)
179 if (myBuilders.size() <= (unsigned int)theTag) {
180 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
182 if (!myBuilders[theTag]) {
183 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
184 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
185 //TCollection_AsciiString entry;//
186 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
187 //cout << "Label = " <<entry.ToCString() <<endl;
189 return myBuilders[theTag];
192 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
194 std::string aName = data()->name() + "/" + theName;
195 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
196 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
197 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
199 void Model_ResultBody::generated(
200 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
202 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
203 builder(theTag)->Generated(aShape);
205 buildName(theTag, theName);
208 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
209 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
211 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
212 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
213 builder(theTag)->Generated(anOldShape, aNewShape);
215 buildName(theTag, theName);
219 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
220 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
222 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
223 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
224 builder(theTag)->Modify(anOldShape, aNewShape);
226 buildName(theTag, theName);
229 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
232 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
233 builder(theTag)->Delete(aShape);
236 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
237 std::shared_ptr<GeomAPI_Shape> theShapeIn,
238 const int theKindOfShape,
241 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
242 TopTools_MapOfShape aView;
243 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
244 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
245 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
246 if (!aView.Add(aRoot)) continue;
247 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
248 aRShape->setImpl((new TopoDS_Shape(aRoot)));
249 if (theMS->isDeleted (aRShape)) {
250 builder(theTag)->Delete(aRoot);
255 void Model_ResultBody::loadAndOrientModifiedShapes (
256 GeomAlgoAPI_MakeShape* theMS,
257 std::shared_ptr<GeomAPI_Shape> theShapeIn,
258 const int theKindOfShape,
260 const std::string& theName,
261 GeomAPI_DataMapOfShapeShape& theSubShapes)
263 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
264 TopTools_MapOfShape aView;
265 bool isBuilt = theName.empty();
266 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
267 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
268 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
269 if (!aView.Add(aRoot)) continue;
271 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
272 aRShape->setImpl((new TopoDS_Shape(aRoot)));
273 theMS->modified(aRShape, aList);
274 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
275 for (; anIt != aLast; anIt++) {
276 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
277 if (theSubShapes.isBound(*anIt)) {
278 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
279 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
281 if (!aRoot.IsSame (aNewShape)) {
282 builder(theTag)->Modify(aRoot,aNewShape);
284 buildName(theTag, theName);
290 void Model_ResultBody::loadAndOrientGeneratedShapes (
291 GeomAlgoAPI_MakeShape* theMS,
292 std::shared_ptr<GeomAPI_Shape> theShapeIn,
293 const int theKindOfShape,
295 const std::string& theName,
296 GeomAPI_DataMapOfShapeShape& theSubShapes)
298 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
299 TopTools_MapOfShape aView;
300 bool isBuilt = theName.empty();
301 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
302 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
303 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
304 if (!aView.Add(aRoot)) continue;
306 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
307 aRShape->setImpl((new TopoDS_Shape(aRoot)));
308 theMS->generated(aRShape, aList);
309 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
310 for (; anIt != aLast; anIt++) {
311 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
312 if (theSubShapes.isBound(*anIt)) {
313 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
314 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
316 if (!aRoot.IsSame (aNewShape)) {
317 builder(theTag)->Generated(aRoot,aNewShape);
319 buildName(theTag, theName);
325 //=======================================================================
326 int getDangleShapes(const TopoDS_Shape& theShapeIn,
327 const TopAbs_ShapeEnum theGeneratedFrom,
328 TopTools_DataMapOfShapeShape& theDangles)
331 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
332 TopAbs_ShapeEnum GeneratedTo;
333 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
334 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
335 else return Standard_False;
336 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
337 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
338 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
339 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
340 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
342 return theDangles.Extent();
345 //=======================================================================
346 void loadGeneratedDangleShapes(
347 const TopoDS_Shape& theShapeIn,
348 const TopAbs_ShapeEnum theGeneratedFrom,
349 TNaming_Builder * theBuilder)
351 TopTools_DataMapOfShapeShape dangles;
352 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
353 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
354 for (; itr.More(); itr.Next())
355 theBuilder->Generated(itr.Key(), itr.Value());
358 //=======================================================================
359 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
360 const std::string& theName, int& theTag)
362 if(theShape->isNull()) return;
363 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
365 if (aShape.ShapeType() == TopAbs_SOLID) {
366 TopExp_Explorer expl(aShape, TopAbs_FACE);
367 for (; expl.More(); expl.Next()) {
368 builder(theTag)->Generated(expl.Current());
369 TCollection_AsciiString aStr(theTag);
370 aName = theName + aStr.ToCString();
371 buildName(theTag, aName);
375 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
376 // load faces and all the free edges
377 TopTools_IndexedMapOfShape Faces;
378 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
379 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
380 TopExp_Explorer expl(aShape, TopAbs_FACE);
381 for (; expl.More(); expl.Next()) {
382 builder(theTag)->Generated(expl.Current());
383 TCollection_AsciiString aStr(theTag);
384 aName = theName + aStr.ToCString();
385 buildName(theTag, aName);
389 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
390 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
391 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
393 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
394 if (aLL.Extent() < 2) {
395 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
397 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
398 TCollection_AsciiString aStr(theTag);
399 aName = theName + aStr.ToCString();
400 buildName(theTag, aName);
403 TopTools_ListIteratorOfListOfShape anIter(aLL);
404 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
406 if(aFace.IsEqual(anIter.Value())) {
407 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
408 TCollection_AsciiString aStr(theTag);
409 aName = theName + aStr.ToCString();
410 buildName(theTag, aName);
415 } else if (aShape.ShapeType() == TopAbs_WIRE) {
416 TopTools_IndexedMapOfShape Edges;
417 BRepTools::Map3DEdges(aShape, Edges);
418 if (Edges.Extent() == 1) {
419 builder(++theTag)->Generated(Edges.FindKey(1));
420 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
421 for (; expl.More(); expl.Next()) {
422 builder(theTag)->Generated(expl.Current());
423 TCollection_AsciiString aStr(theTag);
424 aName = theName + aStr.ToCString();
425 buildName(theTag, aName);
429 TopExp_Explorer expl(aShape, TopAbs_EDGE);
430 for (; expl.More(); expl.Next()) {
431 builder(theTag)->Generated(expl.Current());
432 TCollection_AsciiString aStr(theTag);
433 aName = theName + aStr.ToCString();
434 buildName(theTag, aName);
437 // and load generated vertices.
438 TopTools_DataMapOfShapeShape generated;
439 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
441 TNaming_Builder* pBuilder = builder(theTag++);
442 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
445 } else if (aShape.ShapeType() == TopAbs_EDGE) {
446 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
447 for (; expl.More(); expl.Next()) {
448 builder(theTag)->Generated(expl.Current());
449 TCollection_AsciiString aStr(theTag);
450 aName = theName + aStr.ToCString();
451 buildName(theTag, aName);
457 //=======================================================================
458 int findAmbiguities(const TopoDS_Shape& theShapeIn,
459 TopTools_ListOfShape& theList)
463 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
464 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
465 TopAbs_ShapeEnum aTA(TopAbs_FACE);
466 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
467 TopTools_ListOfShape aKeyList;
468 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
469 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
470 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
471 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
473 TopTools_ListIteratorOfListOfShape it(ancestors1);
474 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
475 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
476 if (i == j) continue;
477 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
478 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
479 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
480 int aNum (ancestors2.Extent());
481 TopTools_ListIteratorOfListOfShape it(ancestors2);
482 for(;it.More();it.Next())
483 if(aMap1.Contains(it.Value())) aNum--;
485 if(aMap2.Add(aKeyEdge1))
486 aKeyList.Append(aKeyEdge1);
487 if(aMap2.Add(aKeyEdge2))
488 aKeyList.Append(aKeyEdge2);
491 } // at the end ==> List of edges to be named in addition
493 aNumEdges = aKeyList.Extent();
495 theList.Assign(aKeyList);
499 //=======================================================================
500 void Model_ResultBody::loadFirstLevel(
501 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
503 if(theShape->isNull()) return;
504 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
506 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
507 TopoDS_Iterator itr(aShape);
508 for (; itr.More(); itr.Next(),theTag++) {
509 builder(theTag)->Generated(itr.Value());
510 TCollection_AsciiString aStr(theTag);
511 aName = theName + aStr.ToCString();
512 buildName(theTag, aName);
513 if(!theName.empty()) buildName(theTag, aName);
514 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
515 itr.Value().ShapeType() == TopAbs_COMPSOLID)
517 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
518 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
519 loadFirstLevel(itrShape, theName, theTag);
521 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
522 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
523 loadNextLevels(itrShape, theName, theTag);
527 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
528 itrShape->setImpl(new TopoDS_Shape(aShape));
529 loadNextLevels(itrShape, theName, theTag);
531 TopTools_ListOfShape aList;
532 if(findAmbiguities(aShape, aList)) {
533 TopTools_ListIteratorOfListOfShape it(aList);
534 for (; it.More(); it.Next(),theTag++) {
535 builder(theTag)->Generated(it.Value());
536 TCollection_AsciiString aStr(theTag);
537 aName = theName + aStr.ToCString();
538 buildName(theTag, aName);
543 //=======================================================================
544 void Model_ResultBody::loadDisconnectedEdges(
545 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
547 if(theShape->isNull()) return;
548 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
549 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
550 TopTools_ListOfShape empty;
551 TopExp_Explorer explF(aShape, TopAbs_FACE);
552 for (; explF.More(); explF.Next()) {
553 const TopoDS_Shape& aFace = explF.Current();
554 TopExp_Explorer explV(aFace, TopAbs_EDGE);
555 for (; explV.More(); explV.Next()) {
556 const TopoDS_Shape& anEdge = explV.Current();
557 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
558 Standard_Boolean faceIsNew = Standard_True;
559 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
560 for (; itrF.More(); itrF.Next()) {
561 if (itrF.Value().IsSame(aFace)) {
562 faceIsNew = Standard_False;
567 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
571 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
572 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
573 for(int i=1; i <= aDM.Extent(); i++) {
574 if(aDM.FindFromIndex(i).Extent() > 1) continue;
575 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
577 builder(theTag)->Generated(aDM.FindKey(i));
578 TCollection_AsciiString aStr(theTag);
579 std::string aName = theName + aStr.ToCString();
580 buildName(theTag, aName);
583 BRepTools::Write(aDM.FindKey(i), aName.c_str());
588 TopTools_MapOfShape anEdgesToDelete;
589 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
591 for(;anEx.More();anEx.Next()) {
592 Standard_Boolean aC0 = Standard_False;
593 TopoDS_Shape anEdge1 = anEx.Current();
594 if (edgeNaborFaces.IsBound(anEdge1)) {
595 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
596 if (aList1.Extent()<2) continue;
597 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
598 for (; itr.More(); itr.Next()) {
599 TopoDS_Shape anEdge2 = itr.Key();
600 if(anEdgesToDelete.Contains(anEdge2)) continue;
601 if (anEdge1.IsSame(anEdge2)) continue;
602 const TopTools_ListOfShape& aList2 = itr.Value();
603 // compare lists of the neighbour faces of edge1 and edge2
604 if (aList1.Extent() == aList2.Extent()) {
605 Standard_Integer aMatches = 0;
606 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
607 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
608 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
609 if (aMatches == aList1.Extent()) {
611 builder(theTag)->Generated(anEdge2);
612 anEdgesToDelete.Add(anEdge2);
613 TCollection_AsciiString aStr(theTag);
614 aName = theName + aStr.ToCString();
615 buildName(theTag, aName);
620 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
621 for(;itDelete.More();itDelete.Next())
622 edgeNaborFaces.UnBind(itDelete.Key());
623 edgeNaborFaces.UnBind(anEdge1);
626 builder(theTag)->Generated(anEdge1);
627 TCollection_AsciiString aStr(theTag);
628 aName = theName + aStr.ToCString();
629 buildName(theTag, aName);
635 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
637 if(theShape->isNull()) return;
638 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
639 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
640 TopTools_ListOfShape empty;
641 TopExp_Explorer explF(aShape, TopAbs_EDGE);
642 for (; explF.More(); explF.Next()) {
643 const TopoDS_Shape& anEdge = explF.Current();
644 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
645 for (; explV.More(); explV.Next()) {
646 const TopoDS_Shape& aVertex = explV.Current();
647 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
648 Standard_Boolean faceIsNew = Standard_True;
649 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
650 for (; itrF.More(); itrF.Next()) {
651 if (itrF.Value().IsSame(anEdge)) {
652 faceIsNew = Standard_False;
657 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
662 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
663 for (; itr.More(); itr.Next()) {
664 const TopTools_ListOfShape& naborEdges = itr.Value();
665 if (naborEdges.Extent() < 2) {
666 builder(theTag)->Generated(itr.Key());
667 TCollection_AsciiString aStr(theTag);
668 aName = theName + aStr.ToCString();
669 buildName(theTag, aName);