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 setIsConcealed(false);
46 void Model_ResultBody::initAttributes()
48 // append the color attribute. It is empty, the attribute will be filled by a request
49 DataPtr aData = data();
50 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
53 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
54 std::string& theDefault)
56 theSection = "Visualization";
57 theName = "result_body_color";
58 theDefault = DEFAULT_COLOR();
61 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
63 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
64 if (aChanged) { // state is changed, so modifications are needed
65 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
66 if (!aData) // unknown case
68 TDF_Label& aShapeLab = aData->shapeLab();
70 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
71 Handle(TNaming_NamedShape) aName;
73 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
74 anEvolution = (int)(aName->Evolution());
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 aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
83 TNaming_Builder aBuilder(aShapeLab);
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);
99 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
101 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
103 TDF_Label& aShapeLab = aData->shapeLab();
106 // store the new shape as primitive
107 TNaming_Builder aBuilder(aShapeLab);
110 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
112 return; // null shape inside
114 aBuilder.Generated(aShape);
116 if(!aBuilder.NamedShape()->IsEmpty()) {
117 Handle(TDataStd_Name) anAttr;
118 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
119 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
121 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
122 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
129 void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
130 const std::shared_ptr<GeomAPI_Shape>& theToShape)
132 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
134 TDF_Label& aShapeLab = aData->shapeLab();
137 // store the new shape as primitive
138 TNaming_Builder aBuilder(aShapeLab);
139 if (!theFromShape || !theToShape)
141 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
142 if (aShapeBasis.IsNull())
143 return; // null shape inside
144 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
145 if (aShapeNew.IsNull())
146 return; // null shape inside
147 aBuilder.Generated(aShapeBasis, aShapeNew);
149 if(!aBuilder.NamedShape()->IsEmpty()) {
150 Handle(TDataStd_Name) anAttr;
151 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
152 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
154 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
155 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
162 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
163 const std::shared_ptr<GeomAPI_Shape>& theNewShape)
165 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
167 TDF_Label& aShapeLab = aData->shapeLab();
170 // store the new shape as primitive
171 TNaming_Builder aBuilder(aShapeLab);
172 if (!theOldShape || !theNewShape)
174 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
175 if (aShapeOld.IsNull())
176 return; // null shape inside
177 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
178 if (aShapeNew.IsNull())
179 return; // null shape inside
180 aBuilder.Modify(aShapeOld, aShapeNew);
184 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
186 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
188 TDF_Label& aShapeLab = aData->shapeLab();
189 Handle(TNaming_NamedShape) aName;
190 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
191 TopoDS_Shape aShape = aName->Get();
192 if (!aShape.IsNull()) {
193 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
194 aRes->setImpl(new TopoDS_Shape(aShape));
199 return std::shared_ptr<GeomAPI_Shape>();
202 void Model_ResultBody::clean()
204 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
205 for(; aBuilder != myBuilders.end(); aBuilder++)
210 Model_ResultBody::~Model_ResultBody()
215 TNaming_Builder* Model_ResultBody::builder(const int theTag)
217 if (myBuilders.size() <= (unsigned int)theTag) {
218 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
220 if (!myBuilders[theTag]) {
221 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
222 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
223 //TCollection_AsciiString entry;//
224 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
225 //cout << "Label = " <<entry.ToCString() <<endl;
227 return myBuilders[theTag];
230 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
232 std::string aName = data()->name() + "/" + theName;
233 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
234 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
235 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
237 void Model_ResultBody::generated(
238 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
240 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
241 builder(theTag)->Generated(aShape);
243 buildName(theTag, theName);
246 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
247 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
249 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
250 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
251 builder(theTag)->Generated(anOldShape, aNewShape);
253 buildName(theTag, theName);
257 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
258 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
260 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
261 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
262 builder(theTag)->Modify(anOldShape, aNewShape);
264 buildName(theTag, theName);
267 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
270 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
271 builder(theTag)->Delete(aShape);
274 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
275 std::shared_ptr<GeomAPI_Shape> theShapeIn,
276 const int theKindOfShape,
279 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
280 TopTools_MapOfShape aView;
281 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
282 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
283 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
284 if (!aView.Add(aRoot)) continue;
285 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
286 aRShape->setImpl((new TopoDS_Shape(aRoot)));
287 if (theMS->isDeleted (aRShape)) {
288 builder(theTag)->Delete(aRoot);
293 void Model_ResultBody::loadAndOrientModifiedShapes (
294 GeomAlgoAPI_MakeShape* theMS,
295 std::shared_ptr<GeomAPI_Shape> theShapeIn,
296 const int theKindOfShape,
298 const std::string& theName,
299 GeomAPI_DataMapOfShapeShape& theSubShapes)
301 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
302 TopTools_MapOfShape aView;
303 bool isBuilt = theName.empty();
304 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
305 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
306 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
307 if (!aView.Add(aRoot)) continue;
309 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
310 aRShape->setImpl((new TopoDS_Shape(aRoot)));
311 theMS->modified(aRShape, aList);
312 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
313 for (; anIt != aLast; anIt++) {
314 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
315 if (theSubShapes.isBound(*anIt)) {
316 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
317 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
319 if (!aRoot.IsSame (aNewShape)) {
320 builder(theTag)->Modify(aRoot,aNewShape);
322 buildName(theTag, theName);
328 void Model_ResultBody::loadAndOrientGeneratedShapes (
329 GeomAlgoAPI_MakeShape* theMS,
330 std::shared_ptr<GeomAPI_Shape> theShapeIn,
331 const int theKindOfShape,
333 const std::string& theName,
334 GeomAPI_DataMapOfShapeShape& theSubShapes)
336 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
337 TopTools_MapOfShape aView;
338 bool isBuilt = theName.empty();
339 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
340 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
341 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
342 if (!aView.Add(aRoot)) continue;
344 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
345 aRShape->setImpl((new TopoDS_Shape(aRoot)));
346 theMS->generated(aRShape, aList);
347 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
348 for (; anIt != aLast; anIt++) {
349 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
350 if (theSubShapes.isBound(*anIt)) {
351 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
352 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
354 if (!aRoot.IsSame (aNewShape)) {
355 builder(theTag)->Generated(aRoot,aNewShape);
357 buildName(theTag, theName);
363 //=======================================================================
364 int getDangleShapes(const TopoDS_Shape& theShapeIn,
365 const TopAbs_ShapeEnum theGeneratedFrom,
366 TopTools_DataMapOfShapeShape& theDangles)
369 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
370 TopAbs_ShapeEnum GeneratedTo;
371 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
372 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
373 else return Standard_False;
374 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
375 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
376 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
377 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
378 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
380 return theDangles.Extent();
383 //=======================================================================
384 void loadGeneratedDangleShapes(
385 const TopoDS_Shape& theShapeIn,
386 const TopAbs_ShapeEnum theGeneratedFrom,
387 TNaming_Builder * theBuilder)
389 TopTools_DataMapOfShapeShape dangles;
390 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
391 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
392 for (; itr.More(); itr.Next())
393 theBuilder->Generated(itr.Key(), itr.Value());
396 //=======================================================================
397 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
398 const std::string& theName, int& theTag)
400 if(theShape->isNull()) return;
401 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
403 if (aShape.ShapeType() == TopAbs_SOLID) {
404 TopExp_Explorer expl(aShape, TopAbs_FACE);
405 for (; expl.More(); expl.Next()) {
406 builder(theTag)->Generated(expl.Current());
407 TCollection_AsciiString aStr(theTag);
408 aName = theName + aStr.ToCString();
409 buildName(theTag, aName);
413 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
414 // load faces and all the free edges
415 TopTools_IndexedMapOfShape Faces;
416 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
417 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
418 TopExp_Explorer expl(aShape, TopAbs_FACE);
419 for (; expl.More(); expl.Next()) {
420 builder(theTag)->Generated(expl.Current());
421 TCollection_AsciiString aStr(theTag);
422 aName = theName + aStr.ToCString();
423 buildName(theTag, aName);
427 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
428 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
429 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
431 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
432 if (aLL.Extent() < 2) {
433 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
435 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
436 TCollection_AsciiString aStr(theTag);
437 aName = theName + aStr.ToCString();
438 buildName(theTag, aName);
441 TopTools_ListIteratorOfListOfShape anIter(aLL);
442 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
444 if(aFace.IsEqual(anIter.Value())) {
445 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
446 TCollection_AsciiString aStr(theTag);
447 aName = theName + aStr.ToCString();
448 buildName(theTag, aName);
453 } else if (aShape.ShapeType() == TopAbs_WIRE) {
454 TopTools_IndexedMapOfShape Edges;
455 BRepTools::Map3DEdges(aShape, Edges);
456 if (Edges.Extent() == 1) {
457 builder(++theTag)->Generated(Edges.FindKey(1));
458 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
459 for (; expl.More(); expl.Next()) {
460 builder(theTag)->Generated(expl.Current());
461 TCollection_AsciiString aStr(theTag);
462 aName = theName + aStr.ToCString();
463 buildName(theTag, aName);
467 TopExp_Explorer expl(aShape, TopAbs_EDGE);
468 for (; expl.More(); expl.Next()) {
469 builder(theTag)->Generated(expl.Current());
470 TCollection_AsciiString aStr(theTag);
471 aName = theName + aStr.ToCString();
472 buildName(theTag, aName);
475 // and load generated vertices.
476 TopTools_DataMapOfShapeShape generated;
477 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
479 TNaming_Builder* pBuilder = builder(theTag++);
480 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
483 } else if (aShape.ShapeType() == TopAbs_EDGE) {
484 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
485 for (; expl.More(); expl.Next()) {
486 builder(theTag)->Generated(expl.Current());
487 TCollection_AsciiString aStr(theTag);
488 aName = theName + aStr.ToCString();
489 buildName(theTag, aName);
495 //=======================================================================
496 int findAmbiguities(const TopoDS_Shape& theShapeIn,
497 TopTools_ListOfShape& theList)
501 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
502 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
503 TopAbs_ShapeEnum aTA(TopAbs_FACE);
504 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
505 TopTools_ListOfShape aKeyList;
506 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
507 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
508 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
509 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
511 TopTools_ListIteratorOfListOfShape it(ancestors1);
512 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
513 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
514 if (i == j) continue;
515 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
516 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
517 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
518 int aNum (ancestors2.Extent());
519 TopTools_ListIteratorOfListOfShape it(ancestors2);
520 for(;it.More();it.Next())
521 if(aMap1.Contains(it.Value())) aNum--;
523 if(aMap2.Add(aKeyEdge1))
524 aKeyList.Append(aKeyEdge1);
525 if(aMap2.Add(aKeyEdge2))
526 aKeyList.Append(aKeyEdge2);
529 } // at the end ==> List of edges to be named in addition
531 aNumEdges = aKeyList.Extent();
533 theList.Assign(aKeyList);
537 //=======================================================================
538 void Model_ResultBody::loadFirstLevel(
539 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
541 if(theShape->isNull()) return;
542 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
544 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
545 TopoDS_Iterator itr(aShape);
546 for (; itr.More(); itr.Next(),theTag++) {
547 builder(theTag)->Generated(itr.Value());
548 TCollection_AsciiString aStr(theTag);
549 aName = theName + aStr.ToCString();
550 buildName(theTag, aName);
551 if(!theName.empty()) buildName(theTag, aName);
552 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
553 itr.Value().ShapeType() == TopAbs_COMPSOLID)
555 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
556 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
557 loadFirstLevel(itrShape, theName, theTag);
559 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
560 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
561 loadNextLevels(itrShape, theName, theTag);
565 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
566 itrShape->setImpl(new TopoDS_Shape(aShape));
567 loadNextLevels(itrShape, theName, theTag);
569 TopTools_ListOfShape aList;
570 if(findAmbiguities(aShape, aList)) {
571 TopTools_ListIteratorOfListOfShape it(aList);
572 for (; it.More(); it.Next(),theTag++) {
573 builder(theTag)->Generated(it.Value());
574 TCollection_AsciiString aStr(theTag);
575 aName = theName + aStr.ToCString();
576 buildName(theTag, aName);
581 //=======================================================================
582 void Model_ResultBody::loadDisconnectedEdges(
583 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
585 if(theShape->isNull()) return;
586 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
587 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
588 TopTools_ListOfShape empty;
589 TopExp_Explorer explF(aShape, TopAbs_FACE);
590 for (; explF.More(); explF.Next()) {
591 const TopoDS_Shape& aFace = explF.Current();
592 TopExp_Explorer explV(aFace, TopAbs_EDGE);
593 for (; explV.More(); explV.Next()) {
594 const TopoDS_Shape& anEdge = explV.Current();
595 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
596 Standard_Boolean faceIsNew = Standard_True;
597 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
598 for (; itrF.More(); itrF.Next()) {
599 if (itrF.Value().IsSame(aFace)) {
600 faceIsNew = Standard_False;
605 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
609 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
610 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
611 for(int i=1; i <= aDM.Extent(); i++) {
612 if(aDM.FindFromIndex(i).Extent() > 1) continue;
613 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
615 builder(theTag)->Generated(aDM.FindKey(i));
616 TCollection_AsciiString aStr(theTag);
617 std::string aName = theName + aStr.ToCString();
618 buildName(theTag, aName);
621 BRepTools::Write(aDM.FindKey(i), aName.c_str());
626 TopTools_MapOfShape anEdgesToDelete;
627 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
629 for(;anEx.More();anEx.Next()) {
630 Standard_Boolean aC0 = Standard_False;
631 TopoDS_Shape anEdge1 = anEx.Current();
632 if (edgeNaborFaces.IsBound(anEdge1)) {
633 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
634 if (aList1.Extent()<2) continue;
635 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
636 for (; itr.More(); itr.Next()) {
637 TopoDS_Shape anEdge2 = itr.Key();
638 if(anEdgesToDelete.Contains(anEdge2)) continue;
639 if (anEdge1.IsSame(anEdge2)) continue;
640 const TopTools_ListOfShape& aList2 = itr.Value();
641 // compare lists of the neighbour faces of edge1 and edge2
642 if (aList1.Extent() == aList2.Extent()) {
643 Standard_Integer aMatches = 0;
644 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
645 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
646 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
647 if (aMatches == aList1.Extent()) {
649 builder(theTag)->Generated(anEdge2);
650 anEdgesToDelete.Add(anEdge2);
651 TCollection_AsciiString aStr(theTag);
652 aName = theName + aStr.ToCString();
653 buildName(theTag, aName);
658 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
659 for(;itDelete.More();itDelete.Next())
660 edgeNaborFaces.UnBind(itDelete.Key());
661 edgeNaborFaces.UnBind(anEdge1);
664 builder(theTag)->Generated(anEdge1);
665 TCollection_AsciiString aStr(theTag);
666 aName = theName + aStr.ToCString();
667 buildName(theTag, aName);
673 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
675 if(theShape->isNull()) return;
676 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
677 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
678 TopTools_ListOfShape empty;
679 TopExp_Explorer explF(aShape, TopAbs_EDGE);
680 for (; explF.More(); explF.Next()) {
681 const TopoDS_Shape& anEdge = explF.Current();
682 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
683 for (; explV.More(); explV.Next()) {
684 const TopoDS_Shape& aVertex = explV.Current();
685 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
686 Standard_Boolean faceIsNew = Standard_True;
687 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
688 for (; itrF.More(); itrF.Next()) {
689 if (itrF.Value().IsSame(anEdge)) {
690 faceIsNew = Standard_False;
695 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
700 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
701 for (; itr.More(); itr.Next()) {
702 const TopTools_ListOfShape& naborEdges = itr.Value();
703 if (naborEdges.Extent() < 2) {
704 builder(theTag)->Generated(itr.Key());
705 TCollection_AsciiString aStr(theTag);
706 aName = theName + aStr.ToCString();
707 buildName(theTag, aName);