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 = false; // 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 anEvolution = (int)(aName->Evolution());
70 for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
71 aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
72 (anIter.OldShape(), anIter.NewShape()));
76 theLab.ForgetAttribute(TNaming_NamedShape::GetID());
78 TNaming_Builder aBuilder(theLab);
79 TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
80 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
81 for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
82 if (theFlag) { // disabled => make selection
83 aBuilder.Select(aPairsIter->first, aPairsIter->second);
84 } else if (anEvol == TNaming_GENERATED) {
85 aBuilder.Generated(aPairsIter->first, aPairsIter->second);
86 } else if (anEvol == TNaming_MODIFY) {
87 aBuilder.Modify(aPairsIter->first, aPairsIter->second);
88 } else if (anEvol == TNaming_DELETE) {
89 aBuilder.Delete(aPairsIter->first);
90 } else if (anEvol == TNaming_PRIMITIVE) {
91 aBuilder.Generated(aPairsIter->second);
94 // recursive call for all sub-labels
95 TDF_ChildIterator anIter(theLab, Standard_False);
96 for(; anIter.More(); anIter.Next()) {
97 EvolutionToSelection(anIter.Value(), theFlag);
101 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
103 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
104 if (aChanged) { // state is changed, so modifications are needed
105 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
106 if (!aData) // unknown case
108 TDF_Label& aShapeLab = aData->shapeLab();
109 EvolutionToSelection(aShapeLab, theFlag);
114 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
116 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
118 TDF_Label& aShapeLab = aData->shapeLab();
121 // store the new shape as primitive
122 TNaming_Builder aBuilder(aShapeLab);
125 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
127 return; // null shape inside
129 aBuilder.Generated(aShape);
131 if(!aBuilder.NamedShape()->IsEmpty()) {
132 Handle(TDataStd_Name) anAttr;
133 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
134 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
136 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
137 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
144 void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
145 const std::shared_ptr<GeomAPI_Shape>& theToShape)
147 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
149 TDF_Label& aShapeLab = aData->shapeLab();
152 // store the new shape as primitive
153 TNaming_Builder aBuilder(aShapeLab);
154 if (!theFromShape || !theToShape)
156 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
157 if (aShapeBasis.IsNull())
158 return; // null shape inside
159 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
160 if (aShapeNew.IsNull())
161 return; // null shape inside
162 aBuilder.Generated(aShapeBasis, aShapeNew);
164 if(!aBuilder.NamedShape()->IsEmpty()) {
165 Handle(TDataStd_Name) anAttr;
166 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
167 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
169 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
170 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
177 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
178 const std::shared_ptr<GeomAPI_Shape>& theNewShape)
180 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
182 TDF_Label& aShapeLab = aData->shapeLab();
185 // store the new shape as primitive
186 TNaming_Builder aBuilder(aShapeLab);
187 if (!theOldShape || !theNewShape)
189 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
190 if (aShapeOld.IsNull())
191 return; // null shape inside
192 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
193 if (aShapeNew.IsNull())
194 return; // null shape inside
195 aBuilder.Modify(aShapeOld, aShapeNew);
199 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
201 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
203 TDF_Label& aShapeLab = aData->shapeLab();
204 Handle(TNaming_NamedShape) aName;
205 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
206 TopoDS_Shape aShape = aName->Get();
207 if (!aShape.IsNull()) {
208 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
209 aRes->setImpl(new TopoDS_Shape(aShape));
214 return std::shared_ptr<GeomAPI_Shape>();
217 void Model_ResultBody::clean()
219 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
220 for(; aBuilder != myBuilders.end(); aBuilder++)
225 Model_ResultBody::~Model_ResultBody()
230 TNaming_Builder* Model_ResultBody::builder(const int theTag)
232 if (myBuilders.size() <= (unsigned int)theTag) {
233 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
235 if (!myBuilders[theTag]) {
236 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
237 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
238 //TCollection_AsciiString entry;//
239 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
240 //cout << "Label = " <<entry.ToCString() <<endl;
242 return myBuilders[theTag];
245 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
247 std::string aName = data()->name() + "/" + theName;
248 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
249 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
250 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
252 void Model_ResultBody::generated(
253 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
255 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
256 builder(theTag)->Generated(aShape);
258 buildName(theTag, theName);
261 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
262 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
264 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
265 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
266 builder(theTag)->Generated(anOldShape, aNewShape);
268 buildName(theTag, theName);
272 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
273 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
275 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
276 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
277 builder(theTag)->Modify(anOldShape, aNewShape);
279 buildName(theTag, theName);
282 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
285 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
286 builder(theTag)->Delete(aShape);
289 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
290 std::shared_ptr<GeomAPI_Shape> theShapeIn,
291 const int theKindOfShape,
294 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
295 TopTools_MapOfShape aView;
296 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
297 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
298 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
299 if (!aView.Add(aRoot)) continue;
300 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
301 aRShape->setImpl((new TopoDS_Shape(aRoot)));
302 if (theMS->isDeleted (aRShape)) {
303 builder(theTag)->Delete(aRoot);
308 void Model_ResultBody::loadAndOrientModifiedShapes (
309 GeomAlgoAPI_MakeShape* theMS,
310 std::shared_ptr<GeomAPI_Shape> theShapeIn,
311 const int theKindOfShape,
313 const std::string& theName,
314 GeomAPI_DataMapOfShapeShape& theSubShapes)
316 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
317 TopTools_MapOfShape aView;
318 bool isBuilt = theName.empty();
319 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
320 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
321 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
322 if (!aView.Add(aRoot)) continue;
324 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
325 aRShape->setImpl((new TopoDS_Shape(aRoot)));
326 theMS->modified(aRShape, aList);
327 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
328 for (; anIt != aLast; anIt++) {
329 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
330 if (theSubShapes.isBound(*anIt)) {
331 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
332 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
334 if (!aRoot.IsSame (aNewShape)) {
335 builder(theTag)->Modify(aRoot,aNewShape);
337 buildName(theTag, theName);
343 void Model_ResultBody::loadAndOrientGeneratedShapes (
344 GeomAlgoAPI_MakeShape* theMS,
345 std::shared_ptr<GeomAPI_Shape> theShapeIn,
346 const int theKindOfShape,
348 const std::string& theName,
349 GeomAPI_DataMapOfShapeShape& theSubShapes)
351 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
352 TopTools_MapOfShape aView;
353 bool isBuilt = theName.empty();
354 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
355 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
356 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
357 if (!aView.Add(aRoot)) continue;
359 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
360 aRShape->setImpl((new TopoDS_Shape(aRoot)));
361 theMS->generated(aRShape, aList);
362 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
363 for (; anIt != aLast; anIt++) {
364 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
365 if (theSubShapes.isBound(*anIt)) {
366 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
367 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
369 if (!aRoot.IsSame (aNewShape)) {
370 builder(theTag)->Generated(aRoot,aNewShape);
372 buildName(theTag, theName);
378 //=======================================================================
379 int getDangleShapes(const TopoDS_Shape& theShapeIn,
380 const TopAbs_ShapeEnum theGeneratedFrom,
381 TopTools_DataMapOfShapeShape& theDangles)
384 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
385 TopAbs_ShapeEnum GeneratedTo;
386 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
387 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
388 else return Standard_False;
389 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
390 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
391 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
392 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
393 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
395 return theDangles.Extent();
398 //=======================================================================
399 void loadGeneratedDangleShapes(
400 const TopoDS_Shape& theShapeIn,
401 const TopAbs_ShapeEnum theGeneratedFrom,
402 TNaming_Builder * theBuilder)
404 TopTools_DataMapOfShapeShape dangles;
405 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
406 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
407 for (; itr.More(); itr.Next())
408 theBuilder->Generated(itr.Key(), itr.Value());
411 //=======================================================================
412 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
413 const std::string& theName, int& theTag)
415 if(theShape->isNull()) return;
416 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
418 if (aShape.ShapeType() == TopAbs_SOLID) {
419 TopExp_Explorer expl(aShape, TopAbs_FACE);
420 for (; expl.More(); expl.Next()) {
421 builder(theTag)->Generated(expl.Current());
422 TCollection_AsciiString aStr(theTag);
423 aName = theName + aStr.ToCString();
424 buildName(theTag, aName);
428 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
429 // load faces and all the free edges
430 TopTools_IndexedMapOfShape Faces;
431 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
432 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
433 TopExp_Explorer expl(aShape, TopAbs_FACE);
434 for (; expl.More(); expl.Next()) {
435 builder(theTag)->Generated(expl.Current());
436 TCollection_AsciiString aStr(theTag);
437 aName = theName + aStr.ToCString();
438 buildName(theTag, aName);
442 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
443 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
444 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
446 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
447 if (aLL.Extent() < 2) {
448 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
450 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
451 TCollection_AsciiString aStr(theTag);
452 aName = theName + aStr.ToCString();
453 buildName(theTag, aName);
456 TopTools_ListIteratorOfListOfShape anIter(aLL);
457 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
459 if(aFace.IsEqual(anIter.Value())) {
460 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
461 TCollection_AsciiString aStr(theTag);
462 aName = theName + aStr.ToCString();
463 buildName(theTag, aName);
468 } else if (aShape.ShapeType() == TopAbs_WIRE) {
469 TopTools_IndexedMapOfShape Edges;
470 BRepTools::Map3DEdges(aShape, Edges);
471 if (Edges.Extent() == 1) {
472 builder(++theTag)->Generated(Edges.FindKey(1));
473 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
474 for (; expl.More(); expl.Next()) {
475 builder(theTag)->Generated(expl.Current());
476 TCollection_AsciiString aStr(theTag);
477 aName = theName + aStr.ToCString();
478 buildName(theTag, aName);
482 TopExp_Explorer expl(aShape, TopAbs_EDGE);
483 for (; expl.More(); expl.Next()) {
484 builder(theTag)->Generated(expl.Current());
485 TCollection_AsciiString aStr(theTag);
486 aName = theName + aStr.ToCString();
487 buildName(theTag, aName);
490 // and load generated vertices.
491 TopTools_DataMapOfShapeShape generated;
492 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
494 TNaming_Builder* pBuilder = builder(theTag++);
495 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
498 } else if (aShape.ShapeType() == TopAbs_EDGE) {
499 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
500 for (; expl.More(); expl.Next()) {
501 builder(theTag)->Generated(expl.Current());
502 TCollection_AsciiString aStr(theTag);
503 aName = theName + aStr.ToCString();
504 buildName(theTag, aName);
510 //=======================================================================
511 int findAmbiguities(const TopoDS_Shape& theShapeIn,
512 TopTools_ListOfShape& theList)
516 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
517 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
518 TopAbs_ShapeEnum aTA(TopAbs_FACE);
519 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
520 TopTools_ListOfShape aKeyList;
521 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
522 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
523 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
524 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
526 TopTools_ListIteratorOfListOfShape it(ancestors1);
527 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
528 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
529 if (i == j) continue;
530 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
531 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
532 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
533 int aNum (ancestors2.Extent());
534 TopTools_ListIteratorOfListOfShape it(ancestors2);
535 for(;it.More();it.Next())
536 if(aMap1.Contains(it.Value())) aNum--;
538 if(aMap2.Add(aKeyEdge1))
539 aKeyList.Append(aKeyEdge1);
540 if(aMap2.Add(aKeyEdge2))
541 aKeyList.Append(aKeyEdge2);
544 } // at the end ==> List of edges to be named in addition
546 aNumEdges = aKeyList.Extent();
548 theList.Assign(aKeyList);
552 //=======================================================================
553 void Model_ResultBody::loadFirstLevel(
554 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
556 if(theShape->isNull()) return;
557 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
559 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
560 TopoDS_Iterator itr(aShape);
561 for (; itr.More(); itr.Next(),theTag++) {
562 builder(theTag)->Generated(itr.Value());
563 TCollection_AsciiString aStr(theTag);
564 aName = theName + aStr.ToCString();
565 buildName(theTag, aName);
566 if(!theName.empty()) buildName(theTag, aName);
567 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
568 itr.Value().ShapeType() == TopAbs_COMPSOLID)
570 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
571 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
572 loadFirstLevel(itrShape, theName, theTag);
574 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
575 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
576 loadNextLevels(itrShape, theName, theTag);
580 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
581 itrShape->setImpl(new TopoDS_Shape(aShape));
582 loadNextLevels(itrShape, theName, theTag);
584 TopTools_ListOfShape aList;
585 if(findAmbiguities(aShape, aList)) {
586 TopTools_ListIteratorOfListOfShape it(aList);
587 for (; it.More(); it.Next(),theTag++) {
588 builder(theTag)->Generated(it.Value());
589 TCollection_AsciiString aStr(theTag);
590 aName = theName + aStr.ToCString();
591 buildName(theTag, aName);
596 //=======================================================================
597 void Model_ResultBody::loadDisconnectedEdges(
598 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
600 if(theShape->isNull()) return;
601 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
602 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
603 TopTools_ListOfShape empty;
604 TopExp_Explorer explF(aShape, TopAbs_FACE);
605 for (; explF.More(); explF.Next()) {
606 const TopoDS_Shape& aFace = explF.Current();
607 TopExp_Explorer explV(aFace, TopAbs_EDGE);
608 for (; explV.More(); explV.Next()) {
609 const TopoDS_Shape& anEdge = explV.Current();
610 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
611 Standard_Boolean faceIsNew = Standard_True;
612 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
613 for (; itrF.More(); itrF.Next()) {
614 if (itrF.Value().IsSame(aFace)) {
615 faceIsNew = Standard_False;
620 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
624 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
625 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
626 for(int i=1; i <= aDM.Extent(); i++) {
627 if(aDM.FindFromIndex(i).Extent() > 1) continue;
628 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
630 builder(theTag)->Generated(aDM.FindKey(i));
631 TCollection_AsciiString aStr(theTag);
632 std::string aName = theName + aStr.ToCString();
633 buildName(theTag, aName);
636 BRepTools::Write(aDM.FindKey(i), aName.c_str());
641 TopTools_MapOfShape anEdgesToDelete;
642 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
644 for(;anEx.More();anEx.Next()) {
645 Standard_Boolean aC0 = Standard_False;
646 TopoDS_Shape anEdge1 = anEx.Current();
647 if (edgeNaborFaces.IsBound(anEdge1)) {
648 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
649 if (aList1.Extent()<2) continue;
650 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
651 for (; itr.More(); itr.Next()) {
652 TopoDS_Shape anEdge2 = itr.Key();
653 if(anEdgesToDelete.Contains(anEdge2)) continue;
654 if (anEdge1.IsSame(anEdge2)) continue;
655 const TopTools_ListOfShape& aList2 = itr.Value();
656 // compare lists of the neighbour faces of edge1 and edge2
657 if (aList1.Extent() == aList2.Extent()) {
658 Standard_Integer aMatches = 0;
659 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
660 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
661 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
662 if (aMatches == aList1.Extent()) {
664 builder(theTag)->Generated(anEdge2);
665 anEdgesToDelete.Add(anEdge2);
666 TCollection_AsciiString aStr(theTag);
667 aName = theName + aStr.ToCString();
668 buildName(theTag, aName);
673 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
674 for(;itDelete.More();itDelete.Next())
675 edgeNaborFaces.UnBind(itDelete.Key());
676 edgeNaborFaces.UnBind(anEdge1);
679 builder(theTag)->Generated(anEdge1);
680 TCollection_AsciiString aStr(theTag);
681 aName = theName + aStr.ToCString();
682 buildName(theTag, aName);
688 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
690 if(theShape->isNull()) return;
691 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
692 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
693 TopTools_ListOfShape empty;
694 TopExp_Explorer explF(aShape, TopAbs_EDGE);
695 for (; explF.More(); explF.Next()) {
696 const TopoDS_Shape& anEdge = explF.Current();
697 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
698 for (; explV.More(); explV.Next()) {
699 const TopoDS_Shape& aVertex = explV.Current();
700 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
701 Standard_Boolean faceIsNew = Standard_True;
702 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
703 for (; itrF.More(); itrF.Next()) {
704 if (itrF.Value().IsSame(anEdge)) {
705 faceIsNew = Standard_False;
710 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
715 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
716 for (; itr.More(); itr.Next()) {
717 const TopTools_ListOfShape& naborEdges = itr.Value();
718 if (naborEdges.Extent() < 2) {
719 builder(theTag)->Generated(itr.Key());
720 TCollection_AsciiString aStr(theTag);
721 aName = theName + aStr.ToCString();
722 buildName(theTag, aName);