1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_ResultBody.cpp
4 // Created: 08 Jul 2014
5 // Author: Mikhail PONIKAROV
7 #include <Model_ResultBody.h>
8 #include <Model_Data.h>
9 #include <Model_Document.h>
10 #include <ModelAPI_AttributeIntArray.h>
11 #include <TNaming_Builder.hxx>
12 #include <TNaming_NamedShape.hxx>
13 #include <TNaming_Iterator.hxx>
14 #include <TDataStd_Name.hxx>
15 #include <TDataStd_Integer.hxx>
17 #include <TopoDS_Face.hxx>
18 #include <TDF_ChildIterator.hxx>
19 #include <TopTools_MapOfShape.hxx>
20 #include <TopExp_Explorer.hxx>
21 #include <TopTools_ListOfShape.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopTools_DataMapOfShapeListOfShape.hxx>
24 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
25 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
26 #include <TopTools_MapIteratorOfMapOfShape.hxx>
27 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
28 #include <TopTools_IndexedMapOfShape.hxx>
29 #include <TopTools_DataMapOfShapeShape.hxx>
31 #include <BRepTools.hxx>
32 #include <BRep_Tool.hxx>
33 #include <GeomAPI_Shape.h>
34 #include <GeomAlgoAPI_MakeShape.h>
35 #include <Config_PropManager.h>
37 //#include <TCollection_AsciiString.hxx>
38 //#include <TDF_Tool.hxx>
39 //#define DEB_IMPORT 1
41 Model_ResultBody::Model_ResultBody()
43 myIsDisabled = true; // by default it is not initialized and false to be after created
44 setIsConcealed(false);
47 void Model_ResultBody::initAttributes()
49 // append the color attribute. It is empty, the attribute will be filled by a request
50 DataPtr aData = data();
51 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
54 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
55 std::string& theDefault)
57 theSection = "Visualization";
58 theName = "result_body_color";
59 theDefault = DEFAULT_COLOR();
62 // Converts evolution of naming shape to selection evelution and back to avoid
63 // naming support on the disabled results. Deeply in the labels tree, recursively.
64 static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) {
65 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
66 Handle(TNaming_NamedShape) aName;
68 if (theLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
69 TNaming_Evolution aNSEvol = aName->Evolution();
70 if ((aNSEvol == TNaming_SELECTED && theFlag) ||
71 (aNSEvol != TNaming_SELECTED && !theFlag)) { // nothing to do, it is already correct
74 anEvolution = (int)(aNSEvol);
76 Handle(TDataStd_Integer) anAttrEvol;
77 if (theLab.FindAttribute(TDataStd_Integer::GetID(), anAttrEvol)) {
78 anEvolution = anAttrEvol->Get();
81 TDataStd_Integer::Set(theLab, anEvolution);
84 for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
85 aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
86 (anIter.OldShape(), anIter.NewShape()));
90 TNaming_Builder aBuilder(theLab);
91 TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
92 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
93 for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
94 if (theFlag) { // disabled => make selection
95 aBuilder.Select(aPairsIter->first, aPairsIter->second);
96 } else if (anEvol == TNaming_GENERATED) {
97 aBuilder.Generated(aPairsIter->first, aPairsIter->second);
98 } else if (anEvol == TNaming_MODIFY) {
99 aBuilder.Modify(aPairsIter->first, aPairsIter->second);
100 } else if (anEvol == TNaming_DELETE) {
101 aBuilder.Delete(aPairsIter->first);
102 } else if (anEvol == TNaming_PRIMITIVE) {
103 aBuilder.Generated(aPairsIter->second);
106 // recursive call for all sub-labels
107 TDF_ChildIterator anIter(theLab, Standard_False);
108 for(; anIter.More(); anIter.Next()) {
109 EvolutionToSelection(anIter.Value(), theFlag);
113 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
115 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
116 if (aChanged) { // state is changed, so modifications are needed
117 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
118 if (!aData) // unknown case
120 TDF_Label& aShapeLab = aData->shapeLab();
121 EvolutionToSelection(aShapeLab, theFlag);
126 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
128 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
130 TDF_Label& aShapeLab = aData->shapeLab();
133 // store the new shape as primitive
134 TNaming_Builder aBuilder(aShapeLab);
137 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
139 return; // null shape inside
141 aBuilder.Generated(aShape);
143 if(!aBuilder.NamedShape()->IsEmpty()) {
144 Handle(TDataStd_Name) anAttr;
145 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
146 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
148 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
149 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
156 void Model_ResultBody::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
157 const std::shared_ptr<GeomAPI_Shape>& theToShape)
159 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
161 TDF_Label& aShapeLab = aData->shapeLab();
164 // store the new shape as primitive
165 TNaming_Builder aBuilder(aShapeLab);
166 if (!theFromShape || !theToShape)
168 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
169 if (aShapeBasis.IsNull())
170 return; // null shape inside
171 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
172 if (aShapeNew.IsNull())
173 return; // null shape inside
174 aBuilder.Generated(aShapeBasis, aShapeNew);
176 if(!aBuilder.NamedShape()->IsEmpty()) {
177 Handle(TDataStd_Name) anAttr;
178 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
179 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
181 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
182 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
189 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
190 const std::shared_ptr<GeomAPI_Shape>& theNewShape)
192 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
194 TDF_Label& aShapeLab = aData->shapeLab();
197 // store the new shape as primitive
198 TNaming_Builder aBuilder(aShapeLab);
199 if (!theOldShape || !theNewShape)
201 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
202 if (aShapeOld.IsNull())
203 return; // null shape inside
204 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
205 if (aShapeNew.IsNull())
206 return; // null shape inside
207 aBuilder.Modify(aShapeOld, aShapeNew);
211 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
213 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
215 TDF_Label& aShapeLab = aData->shapeLab();
216 Handle(TNaming_NamedShape) aName;
217 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
218 TopoDS_Shape aShape = aName->Get();
219 if (!aShape.IsNull()) {
220 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
221 aRes->setImpl(new TopoDS_Shape(aShape));
226 return std::shared_ptr<GeomAPI_Shape>();
229 void Model_ResultBody::clean()
231 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
232 for(; aBuilder != myBuilders.end(); aBuilder++)
237 Model_ResultBody::~Model_ResultBody()
242 TNaming_Builder* Model_ResultBody::builder(const int theTag)
244 if (myBuilders.size() <= (unsigned int)theTag) {
245 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
247 if (!myBuilders[theTag]) {
248 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
249 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
250 //TCollection_AsciiString entry;//
251 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
252 //cout << "Label = " <<entry.ToCString() <<endl;
254 return myBuilders[theTag];
257 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
259 std::string aName = data()->name() + "/" + theName;
260 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
261 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
262 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
264 void Model_ResultBody::generated(
265 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
267 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
268 builder(theTag)->Generated(aShape);
270 buildName(theTag, theName);
273 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
274 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
276 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
277 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
278 builder(theTag)->Generated(anOldShape, aNewShape);
280 buildName(theTag, theName);
284 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
285 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
287 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
288 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
289 builder(theTag)->Modify(anOldShape, aNewShape);
291 buildName(theTag, theName);
294 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
297 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
298 builder(theTag)->Delete(aShape);
301 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
302 std::shared_ptr<GeomAPI_Shape> theShapeIn,
303 const int theKindOfShape,
306 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
307 TopTools_MapOfShape aView;
308 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
309 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
310 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
311 if (!aView.Add(aRoot)) continue;
312 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
313 aRShape->setImpl((new TopoDS_Shape(aRoot)));
314 if (theMS->isDeleted (aRShape)) {
315 builder(theTag)->Delete(aRoot);
320 void Model_ResultBody::loadAndOrientModifiedShapes (
321 GeomAlgoAPI_MakeShape* theMS,
322 std::shared_ptr<GeomAPI_Shape> theShapeIn,
323 const int theKindOfShape,
325 const std::string& theName,
326 GeomAPI_DataMapOfShapeShape& theSubShapes)
328 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
329 TopTools_MapOfShape aView;
330 bool isBuilt = theName.empty();
331 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
332 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
333 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
334 if (!aView.Add(aRoot)) continue;
336 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
337 aRShape->setImpl((new TopoDS_Shape(aRoot)));
338 theMS->modified(aRShape, aList);
339 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
340 for (; anIt != aLast; anIt++) {
341 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
342 if (theSubShapes.isBound(*anIt)) {
343 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
344 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
346 if (!aRoot.IsSame (aNewShape)) {
347 builder(theTag)->Modify(aRoot,aNewShape);
349 buildName(theTag, theName);
355 void Model_ResultBody::loadAndOrientGeneratedShapes (
356 GeomAlgoAPI_MakeShape* theMS,
357 std::shared_ptr<GeomAPI_Shape> theShapeIn,
358 const int theKindOfShape,
360 const std::string& theName,
361 GeomAPI_DataMapOfShapeShape& theSubShapes)
363 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
364 TopTools_MapOfShape aView;
365 bool isBuilt = theName.empty();
366 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
367 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
368 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
369 if (!aView.Add(aRoot)) continue;
371 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
372 aRShape->setImpl((new TopoDS_Shape(aRoot)));
373 theMS->generated(aRShape, aList);
374 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
375 for (; anIt != aLast; anIt++) {
376 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
377 if (theSubShapes.isBound(*anIt)) {
378 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
379 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
381 if (!aRoot.IsSame (aNewShape)) {
382 builder(theTag)->Generated(aRoot,aNewShape);
384 buildName(theTag, theName);
390 //=======================================================================
391 int getDangleShapes(const TopoDS_Shape& theShapeIn,
392 const TopAbs_ShapeEnum theGeneratedFrom,
393 TopTools_DataMapOfShapeShape& theDangles)
396 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
397 TopAbs_ShapeEnum GeneratedTo;
398 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
399 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
400 else return Standard_False;
401 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
402 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
403 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
404 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
405 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
407 return theDangles.Extent();
410 //=======================================================================
411 void loadGeneratedDangleShapes(
412 const TopoDS_Shape& theShapeIn,
413 const TopAbs_ShapeEnum theGeneratedFrom,
414 TNaming_Builder * theBuilder)
416 TopTools_DataMapOfShapeShape dangles;
417 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
418 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
419 for (; itr.More(); itr.Next())
420 theBuilder->Generated(itr.Key(), itr.Value());
423 //=======================================================================
424 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
425 const std::string& theName, int& theTag)
427 if(theShape->isNull()) return;
428 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
430 if (aShape.ShapeType() == TopAbs_SOLID) {
431 TopExp_Explorer expl(aShape, TopAbs_FACE);
432 for (; expl.More(); expl.Next()) {
433 builder(theTag)->Generated(expl.Current());
434 TCollection_AsciiString aStr(theTag);
435 aName = theName + aStr.ToCString();
436 buildName(theTag, aName);
440 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
441 // load faces and all the free edges
442 TopTools_IndexedMapOfShape Faces;
443 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
444 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
445 TopExp_Explorer expl(aShape, TopAbs_FACE);
446 for (; expl.More(); expl.Next()) {
447 builder(theTag)->Generated(expl.Current());
448 TCollection_AsciiString aStr(theTag);
449 aName = theName + aStr.ToCString();
450 buildName(theTag, aName);
454 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
455 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
456 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
458 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
459 if (aLL.Extent() < 2) {
460 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
462 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
463 TCollection_AsciiString aStr(theTag);
464 aName = theName + aStr.ToCString();
465 buildName(theTag, aName);
468 TopTools_ListIteratorOfListOfShape anIter(aLL);
469 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
471 if(aFace.IsEqual(anIter.Value())) {
472 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
473 TCollection_AsciiString aStr(theTag);
474 aName = theName + aStr.ToCString();
475 buildName(theTag, aName);
480 } else if (aShape.ShapeType() == TopAbs_WIRE) {
481 TopTools_IndexedMapOfShape Edges;
482 BRepTools::Map3DEdges(aShape, Edges);
483 if (Edges.Extent() == 1) {
484 builder(++theTag)->Generated(Edges.FindKey(1));
485 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
486 for (; expl.More(); expl.Next()) {
487 builder(theTag)->Generated(expl.Current());
488 TCollection_AsciiString aStr(theTag);
489 aName = theName + aStr.ToCString();
490 buildName(theTag, aName);
494 TopExp_Explorer expl(aShape, TopAbs_EDGE);
495 for (; expl.More(); expl.Next()) {
496 builder(theTag)->Generated(expl.Current());
497 TCollection_AsciiString aStr(theTag);
498 aName = theName + aStr.ToCString();
499 buildName(theTag, aName);
502 // and load generated vertices.
503 TopTools_DataMapOfShapeShape generated;
504 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
506 TNaming_Builder* pBuilder = builder(theTag++);
507 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
510 } else if (aShape.ShapeType() == TopAbs_EDGE) {
511 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
512 for (; expl.More(); expl.Next()) {
513 builder(theTag)->Generated(expl.Current());
514 TCollection_AsciiString aStr(theTag);
515 aName = theName + aStr.ToCString();
516 buildName(theTag, aName);
522 //=======================================================================
523 int findAmbiguities(const TopoDS_Shape& theShapeIn,
524 TopTools_ListOfShape& theList)
528 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
529 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
530 TopAbs_ShapeEnum aTA(TopAbs_FACE);
531 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
532 TopTools_ListOfShape aKeyList;
533 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
534 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
535 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
536 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
538 TopTools_ListIteratorOfListOfShape it(ancestors1);
539 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
540 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
541 if (i == j) continue;
542 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
543 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
544 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
545 int aNum (ancestors2.Extent());
546 TopTools_ListIteratorOfListOfShape it(ancestors2);
547 for(;it.More();it.Next())
548 if(aMap1.Contains(it.Value())) aNum--;
550 if(aMap2.Add(aKeyEdge1))
551 aKeyList.Append(aKeyEdge1);
552 if(aMap2.Add(aKeyEdge2))
553 aKeyList.Append(aKeyEdge2);
556 } // at the end ==> List of edges to be named in addition
558 aNumEdges = aKeyList.Extent();
560 theList.Assign(aKeyList);
564 //=======================================================================
565 void Model_ResultBody::loadFirstLevel(
566 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
568 if(theShape->isNull()) return;
569 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
571 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
572 TopoDS_Iterator itr(aShape);
573 for (; itr.More(); itr.Next(),theTag++) {
574 builder(theTag)->Generated(itr.Value());
575 TCollection_AsciiString aStr(theTag);
576 aName = theName + aStr.ToCString();
577 buildName(theTag, aName);
578 if(!theName.empty()) buildName(theTag, aName);
579 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
580 itr.Value().ShapeType() == TopAbs_COMPSOLID)
582 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
583 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
584 loadFirstLevel(itrShape, theName, theTag);
586 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
587 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
588 loadNextLevels(itrShape, theName, theTag);
592 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
593 itrShape->setImpl(new TopoDS_Shape(aShape));
594 loadNextLevels(itrShape, theName, theTag);
596 TopTools_ListOfShape aList;
597 if(findAmbiguities(aShape, aList)) {
598 TopTools_ListIteratorOfListOfShape it(aList);
599 for (; it.More(); it.Next(),theTag++) {
600 builder(theTag)->Generated(it.Value());
601 TCollection_AsciiString aStr(theTag);
602 aName = theName + aStr.ToCString();
603 buildName(theTag, aName);
608 //=======================================================================
609 void Model_ResultBody::loadDisconnectedEdges(
610 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
612 if(theShape->isNull()) return;
613 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
614 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
615 TopTools_ListOfShape empty;
616 TopExp_Explorer explF(aShape, TopAbs_FACE);
617 for (; explF.More(); explF.Next()) {
618 const TopoDS_Shape& aFace = explF.Current();
619 TopExp_Explorer explV(aFace, TopAbs_EDGE);
620 for (; explV.More(); explV.Next()) {
621 const TopoDS_Shape& anEdge = explV.Current();
622 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
623 Standard_Boolean faceIsNew = Standard_True;
624 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
625 for (; itrF.More(); itrF.Next()) {
626 if (itrF.Value().IsSame(aFace)) {
627 faceIsNew = Standard_False;
632 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
636 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
637 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
638 for(int i=1; i <= aDM.Extent(); i++) {
639 if(aDM.FindFromIndex(i).Extent() > 1) continue;
640 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
642 builder(theTag)->Generated(aDM.FindKey(i));
643 TCollection_AsciiString aStr(theTag);
644 std::string aName = theName + aStr.ToCString();
645 buildName(theTag, aName);
648 BRepTools::Write(aDM.FindKey(i), aName.c_str());
653 TopTools_MapOfShape anEdgesToDelete;
654 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
656 for(;anEx.More();anEx.Next()) {
657 Standard_Boolean aC0 = Standard_False;
658 TopoDS_Shape anEdge1 = anEx.Current();
659 if (edgeNaborFaces.IsBound(anEdge1)) {
660 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
661 if (aList1.Extent()<2) continue;
662 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
663 for (; itr.More(); itr.Next()) {
664 TopoDS_Shape anEdge2 = itr.Key();
665 if(anEdgesToDelete.Contains(anEdge2)) continue;
666 if (anEdge1.IsSame(anEdge2)) continue;
667 const TopTools_ListOfShape& aList2 = itr.Value();
668 // compare lists of the neighbour faces of edge1 and edge2
669 if (aList1.Extent() == aList2.Extent()) {
670 Standard_Integer aMatches = 0;
671 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
672 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
673 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
674 if (aMatches == aList1.Extent()) {
676 builder(theTag)->Generated(anEdge2);
677 anEdgesToDelete.Add(anEdge2);
678 TCollection_AsciiString aStr(theTag);
679 aName = theName + aStr.ToCString();
680 buildName(theTag, aName);
685 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
686 for(;itDelete.More();itDelete.Next())
687 edgeNaborFaces.UnBind(itDelete.Key());
688 edgeNaborFaces.UnBind(anEdge1);
691 builder(theTag)->Generated(anEdge1);
692 TCollection_AsciiString aStr(theTag);
693 aName = theName + aStr.ToCString();
694 buildName(theTag, aName);
700 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
702 if(theShape->isNull()) return;
703 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
704 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
705 TopTools_ListOfShape empty;
706 TopExp_Explorer explF(aShape, TopAbs_EDGE);
707 for (; explF.More(); explF.Next()) {
708 const TopoDS_Shape& anEdge = explF.Current();
709 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
710 for (; explV.More(); explV.Next()) {
711 const TopoDS_Shape& aVertex = explV.Current();
712 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
713 Standard_Boolean faceIsNew = Standard_True;
714 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
715 for (; itrF.More(); itrF.Next()) {
716 if (itrF.Value().IsSame(anEdge)) {
717 faceIsNew = Standard_False;
722 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
727 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
728 for (; itr.More(); itr.Next()) {
729 const TopTools_ListOfShape& naborEdges = itr.Value();
730 if (naborEdges.Extent() < 2) {
731 builder(theTag)->Generated(itr.Key());
732 TCollection_AsciiString aStr(theTag);
733 aName = theName + aStr.ToCString();
734 buildName(theTag, aName);