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 <TNaming_Builder.hxx>
11 #include <TNaming_NamedShape.hxx>
12 #include <TDataStd_Name.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Face.hxx>
16 #include <TDF_ChildIterator.hxx>
17 #include <TopTools_MapOfShape.hxx>
18 #include <TopExp_Explorer.hxx>
19 #include <TopTools_ListOfShape.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
21 #include <TopTools_DataMapOfShapeListOfShape.hxx>
22 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
23 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
24 #include <TopTools_MapIteratorOfMapOfShape.hxx>
25 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
26 #include <TopTools_IndexedMapOfShape.hxx>
27 #include <TopTools_DataMapOfShapeShape.hxx>
29 #include <BRepTools.hxx>
30 #include <BRep_Tool.hxx>
31 #include <GeomAPI_Shape.h>
32 #include <GeomAlgoAPI_MakeShape.h>
34 //#include <TCollection_AsciiString.hxx>
35 //#include <TDF_Tool.hxx>
36 //#define DEB_IMPORT 1
38 Model_ResultBody::Model_ResultBody()
40 setIsConcealed(false);
43 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
45 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
47 TDF_Label& aShapeLab = aData->shapeLab();
50 // store the new shape as primitive
51 TNaming_Builder aBuilder(aShapeLab);
54 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
56 return; // null shape inside
58 aBuilder.Generated(aShape);
60 if(!aBuilder.NamedShape()->IsEmpty()) {
61 Handle(TDataStd_Name) anAttr;
62 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
63 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
65 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
66 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
73 void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
74 const std::shared_ptr<GeomAPI_Shape>& theToShape)
76 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
78 TDF_Label& aShapeLab = aData->shapeLab();
81 // store the new shape as primitive
82 TNaming_Builder aBuilder(aShapeLab);
83 if (!theFromShape || !theToShape)
85 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
86 if (aShapeBasis.IsNull())
87 return; // null shape inside
88 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
89 if (aShapeNew.IsNull())
90 return; // null shape inside
91 aBuilder.Generated(aShapeBasis, aShapeNew);
93 if(!aBuilder.NamedShape()->IsEmpty()) {
94 Handle(TDataStd_Name) anAttr;
95 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
96 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
98 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
99 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
106 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
107 const std::shared_ptr<GeomAPI_Shape>& theNewShape)
109 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
111 TDF_Label& aShapeLab = aData->shapeLab();
114 // store the new shape as primitive
115 TNaming_Builder aBuilder(aShapeLab);
116 if (!theOldShape || !theNewShape)
118 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
119 if (aShapeOld.IsNull())
120 return; // null shape inside
121 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
122 if (aShapeNew.IsNull())
123 return; // null shape inside
124 aBuilder.Modify(aShapeOld, aShapeNew);
128 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
130 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
132 TDF_Label& aShapeLab = aData->shapeLab();
133 Handle(TNaming_NamedShape) aName;
134 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
135 TopoDS_Shape aShape = aName->Get();
136 if (!aShape.IsNull()) {
137 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
138 aRes->setImpl(new TopoDS_Shape(aShape));
143 return std::shared_ptr<GeomAPI_Shape>();
146 void Model_ResultBody::clean()
148 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
149 for(; aBuilder != myBuilders.end(); aBuilder++)
154 Model_ResultBody::~Model_ResultBody()
159 TNaming_Builder* Model_ResultBody::builder(const int theTag)
161 if (myBuilders.size() <= (unsigned int)theTag) {
162 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
164 if (!myBuilders[theTag]) {
165 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
166 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
167 //TCollection_AsciiString entry;//
168 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
169 //cout << "Label = " <<entry.ToCString() <<endl;
171 return myBuilders[theTag];
174 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
176 std::string aName = data()->name() + "/" + theName;
177 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
178 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
179 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
181 void Model_ResultBody::generated(
182 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
184 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
185 builder(theTag)->Generated(aShape);
187 buildName(theTag, theName);
190 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
191 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
193 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
194 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
195 builder(theTag)->Generated(anOldShape, aNewShape);
197 buildName(theTag, theName);
201 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
202 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
204 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
205 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
206 builder(theTag)->Modify(anOldShape, aNewShape);
208 buildName(theTag, theName);
211 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
214 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
215 builder(theTag)->Delete(aShape);
218 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
219 std::shared_ptr<GeomAPI_Shape> theShapeIn,
220 const int theKindOfShape,
223 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
224 TopTools_MapOfShape aView;
225 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
226 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
227 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
228 if (!aView.Add(aRoot)) continue;
229 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
230 aRShape->setImpl((new TopoDS_Shape(aRoot)));
231 if (theMS->isDeleted (aRShape)) {
232 builder(theTag)->Delete(aRoot);
237 void Model_ResultBody::loadAndOrientModifiedShapes (
238 GeomAlgoAPI_MakeShape* theMS,
239 std::shared_ptr<GeomAPI_Shape> theShapeIn,
240 const int theKindOfShape,
242 const std::string& theName,
243 GeomAPI_DataMapOfShapeShape& theSubShapes)
245 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
246 TopTools_MapOfShape aView;
247 bool isBuilt = theName.empty();
248 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
249 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
250 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
251 if (!aView.Add(aRoot)) continue;
253 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
254 aRShape->setImpl((new TopoDS_Shape(aRoot)));
255 theMS->modified(aRShape, aList);
256 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
257 for (; anIt != aLast; anIt++) {
258 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
259 if (theSubShapes.isBound(*anIt)) {
260 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
261 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
263 if (!aRoot.IsSame (aNewShape)) {
264 builder(theTag)->Modify(aRoot,aNewShape);
266 buildName(theTag, theName);
272 void Model_ResultBody::loadAndOrientGeneratedShapes (
273 GeomAlgoAPI_MakeShape* theMS,
274 std::shared_ptr<GeomAPI_Shape> theShapeIn,
275 const int theKindOfShape,
277 const std::string& theName,
278 GeomAPI_DataMapOfShapeShape& theSubShapes)
280 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
281 TopTools_MapOfShape aView;
282 bool isBuilt = theName.empty();
283 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
284 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
285 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
286 if (!aView.Add(aRoot)) continue;
288 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
289 aRShape->setImpl((new TopoDS_Shape(aRoot)));
290 theMS->generated(aRShape, aList);
291 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
292 for (; anIt != aLast; anIt++) {
293 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
294 if (theSubShapes.isBound(*anIt)) {
295 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
296 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
298 if (!aRoot.IsSame (aNewShape)) {
299 builder(theTag)->Generated(aRoot,aNewShape);
301 buildName(theTag, theName);
307 //=======================================================================
308 int getDangleShapes(const TopoDS_Shape& theShapeIn,
309 const TopAbs_ShapeEnum theGeneratedFrom,
310 TopTools_DataMapOfShapeShape& theDangles)
313 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
314 TopAbs_ShapeEnum GeneratedTo;
315 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
316 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
317 else return Standard_False;
318 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
319 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
320 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
321 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
322 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
324 return theDangles.Extent();
327 //=======================================================================
328 void loadGeneratedDangleShapes(
329 const TopoDS_Shape& theShapeIn,
330 const TopAbs_ShapeEnum theGeneratedFrom,
331 TNaming_Builder * theBuilder)
333 TopTools_DataMapOfShapeShape dangles;
334 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
335 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
336 for (; itr.More(); itr.Next())
337 theBuilder->Generated(itr.Key(), itr.Value());
340 //=======================================================================
341 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
342 const std::string& theName, int& theTag)
344 if(theShape->isNull()) return;
345 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
347 if (aShape.ShapeType() == TopAbs_SOLID) {
348 TopExp_Explorer expl(aShape, TopAbs_FACE);
349 for (; expl.More(); expl.Next()) {
350 builder(theTag)->Generated(expl.Current());
351 TCollection_AsciiString aStr(theTag);
352 aName = theName + aStr.ToCString();
353 buildName(theTag, aName);
357 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
358 // load faces and all the free edges
359 TopTools_IndexedMapOfShape Faces;
360 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
361 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
362 TopExp_Explorer expl(aShape, TopAbs_FACE);
363 for (; expl.More(); expl.Next()) {
364 builder(theTag)->Generated(expl.Current());
365 TCollection_AsciiString aStr(theTag);
366 aName = theName + aStr.ToCString();
367 buildName(theTag, aName);
371 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
372 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
373 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
375 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
376 if (aLL.Extent() < 2) {
377 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
379 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
380 TCollection_AsciiString aStr(theTag);
381 aName = theName + aStr.ToCString();
382 buildName(theTag, aName);
385 TopTools_ListIteratorOfListOfShape anIter(aLL);
386 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
388 if(aFace.IsEqual(anIter.Value())) {
389 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
390 TCollection_AsciiString aStr(theTag);
391 aName = theName + aStr.ToCString();
392 buildName(theTag, aName);
397 } else if (aShape.ShapeType() == TopAbs_WIRE) {
398 TopTools_IndexedMapOfShape Edges;
399 BRepTools::Map3DEdges(aShape, Edges);
400 if (Edges.Extent() == 1) {
401 builder(++theTag)->Generated(Edges.FindKey(1));
402 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
403 for (; expl.More(); expl.Next()) {
404 builder(theTag)->Generated(expl.Current());
405 TCollection_AsciiString aStr(theTag);
406 aName = theName + aStr.ToCString();
407 buildName(theTag, aName);
411 TopExp_Explorer expl(aShape, TopAbs_EDGE);
412 for (; expl.More(); expl.Next()) {
413 builder(theTag)->Generated(expl.Current());
414 TCollection_AsciiString aStr(theTag);
415 aName = theName + aStr.ToCString();
416 buildName(theTag, aName);
419 // and load generated vertices.
420 TopTools_DataMapOfShapeShape generated;
421 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
423 TNaming_Builder* pBuilder = builder(theTag++);
424 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
427 } else if (aShape.ShapeType() == TopAbs_EDGE) {
428 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
429 for (; expl.More(); expl.Next()) {
430 builder(theTag)->Generated(expl.Current());
431 TCollection_AsciiString aStr(theTag);
432 aName = theName + aStr.ToCString();
433 buildName(theTag, aName);
439 //=======================================================================
440 int findAmbiguities(const TopoDS_Shape& theShapeIn,
441 TopTools_ListOfShape& theList)
445 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
446 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
447 TopAbs_ShapeEnum aTA(TopAbs_FACE);
448 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
449 TopTools_ListOfShape aKeyList;
450 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
451 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
452 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
453 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
455 TopTools_ListIteratorOfListOfShape it(ancestors1);
456 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
457 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
458 if (i == j) continue;
459 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
460 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
461 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
462 int aNum (ancestors2.Extent());
463 TopTools_ListIteratorOfListOfShape it(ancestors2);
464 for(;it.More();it.Next())
465 if(aMap1.Contains(it.Value())) aNum--;
467 if(aMap2.Add(aKeyEdge1))
468 aKeyList.Append(aKeyEdge1);
469 if(aMap2.Add(aKeyEdge2))
470 aKeyList.Append(aKeyEdge2);
473 } // at the end ==> List of edges to be named in addition
475 aNumEdges = aKeyList.Extent();
477 theList.Assign(aKeyList);
481 //=======================================================================
482 void Model_ResultBody::loadFirstLevel(
483 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
485 if(theShape->isNull()) return;
486 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
488 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
489 TopoDS_Iterator itr(aShape);
490 for (; itr.More(); itr.Next(),theTag++) {
491 builder(theTag)->Generated(itr.Value());
492 TCollection_AsciiString aStr(theTag);
493 aName = theName + aStr.ToCString();
494 buildName(theTag, aName);
495 if(!theName.empty()) buildName(theTag, aName);
496 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
497 itr.Value().ShapeType() == TopAbs_COMPSOLID)
499 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
500 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
501 loadFirstLevel(itrShape, theName, theTag);
503 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
504 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
505 loadNextLevels(itrShape, theName, theTag);
509 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
510 itrShape->setImpl(new TopoDS_Shape(aShape));
511 loadNextLevels(itrShape, theName, theTag);
513 TopTools_ListOfShape aList;
514 if(findAmbiguities(aShape, aList)) {
515 TopTools_ListIteratorOfListOfShape it(aList);
516 for (; it.More(); it.Next(),theTag++) {
517 builder(theTag)->Generated(it.Value());
518 TCollection_AsciiString aStr(theTag);
519 aName = theName + aStr.ToCString();
520 buildName(theTag, aName);
525 //=======================================================================
526 void Model_ResultBody::loadDisconnectedEdges(
527 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
529 if(theShape->isNull()) return;
530 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
531 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
532 TopTools_ListOfShape empty;
533 TopExp_Explorer explF(aShape, TopAbs_FACE);
534 for (; explF.More(); explF.Next()) {
535 const TopoDS_Shape& aFace = explF.Current();
536 TopExp_Explorer explV(aFace, TopAbs_EDGE);
537 for (; explV.More(); explV.Next()) {
538 const TopoDS_Shape& anEdge = explV.Current();
539 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
540 Standard_Boolean faceIsNew = Standard_True;
541 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
542 for (; itrF.More(); itrF.Next()) {
543 if (itrF.Value().IsSame(aFace)) {
544 faceIsNew = Standard_False;
549 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
553 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
554 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
555 for(int i=1; i <= aDM.Extent(); i++) {
556 if(aDM.FindFromIndex(i).Extent() > 1) continue;
557 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
559 builder(theTag)->Generated(aDM.FindKey(i));
560 TCollection_AsciiString aStr(theTag);
561 std::string aName = theName + aStr.ToCString();
562 buildName(theTag, aName);
565 BRepTools::Write(aDM.FindKey(i), aName.c_str());
570 TopTools_MapOfShape anEdgesToDelete;
571 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
573 for(;anEx.More();anEx.Next()) {
574 Standard_Boolean aC0 = Standard_False;
575 TopoDS_Shape anEdge1 = anEx.Current();
576 if (edgeNaborFaces.IsBound(anEdge1)) {
577 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
578 if (aList1.Extent()<2) continue;
579 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
580 for (; itr.More(); itr.Next()) {
581 TopoDS_Shape anEdge2 = itr.Key();
582 if(anEdgesToDelete.Contains(anEdge2)) continue;
583 if (anEdge1.IsSame(anEdge2)) continue;
584 const TopTools_ListOfShape& aList2 = itr.Value();
585 // compare lists of the neighbour faces of edge1 and edge2
586 if (aList1.Extent() == aList2.Extent()) {
587 Standard_Integer aMatches = 0;
588 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
589 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
590 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
591 if (aMatches == aList1.Extent()) {
593 builder(theTag)->Generated(anEdge2);
594 anEdgesToDelete.Add(anEdge2);
595 TCollection_AsciiString aStr(theTag);
596 aName = theName + aStr.ToCString();
597 buildName(theTag, aName);
602 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
603 for(;itDelete.More();itDelete.Next())
604 edgeNaborFaces.UnBind(itDelete.Key());
605 edgeNaborFaces.UnBind(anEdge1);
608 builder(theTag)->Generated(anEdge1);
609 TCollection_AsciiString aStr(theTag);
610 aName = theName + aStr.ToCString();
611 buildName(theTag, aName);
617 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
619 if(theShape->isNull()) return;
620 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
621 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
622 TopTools_ListOfShape empty;
623 TopExp_Explorer explF(aShape, TopAbs_EDGE);
624 for (; explF.More(); explF.Next()) {
625 const TopoDS_Shape& anEdge = explF.Current();
626 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
627 for (; explV.More(); explV.Next()) {
628 const TopoDS_Shape& aVertex = explV.Current();
629 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
630 Standard_Boolean faceIsNew = Standard_True;
631 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
632 for (; itrF.More(); itrF.Next()) {
633 if (itrF.Value().IsSame(anEdge)) {
634 faceIsNew = Standard_False;
639 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
644 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
645 for (; itr.More(); itr.Next()) {
646 const TopTools_ListOfShape& naborEdges = itr.Value();
647 if (naborEdges.Extent() < 2) {
648 builder(theTag)->Generated(itr.Key());
649 TCollection_AsciiString aStr(theTag);
650 aName = theName + aStr.ToCString();
651 buildName(theTag, aName);