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_BodyBuilder.h>
9 #include <Model_Data.h>
10 #include <Model_Document.h>
11 #include <ModelAPI_AttributeIntArray.h>
13 #include <TNaming_Builder.hxx>
14 #include <TNaming_NamedShape.hxx>
15 #include <TNaming_Iterator.hxx>
16 #include <TDataStd_Name.hxx>
17 #include <TDataStd_Integer.hxx>
19 #include <TopoDS_Face.hxx>
20 #include <TDF_ChildIterator.hxx>
21 #include <TopTools_MapOfShape.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <TopTools_ListOfShape.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
25 #include <TopTools_DataMapOfShapeListOfShape.hxx>
26 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
27 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
28 #include <TopTools_MapIteratorOfMapOfShape.hxx>
29 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
30 #include <TopTools_IndexedMapOfShape.hxx>
31 #include <TopTools_DataMapOfShapeShape.hxx>
33 #include <BRepTools.hxx>
34 #include <BRep_Tool.hxx>
35 #include <GeomAPI_Shape.h>
36 #include <GeomAlgoAPI_MakeShape.h>
38 #include <Config_PropManager.h>
40 //#include <TCollection_AsciiString.hxx>
41 //#include <TDF_Tool.hxx>
42 //#define DEB_IMPORT 1
44 Model_ResultBody::Model_ResultBody()
46 myBuilder = new Model_BodyBuilder(this);
48 myIsDisabled = true; // by default it is not initialized and false to be after created
49 setIsConcealed(false);
52 void Model_ResultBody::initAttributes()
54 // append the color attribute. It is empty, the attribute will be filled by a request
55 DataPtr aData = data();
56 aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
59 void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
60 std::string& theDefault)
62 theSection = "Visualization";
63 theName = "result_body_color";
64 theDefault = DEFAULT_COLOR();
67 // Converts evolution of naming shape to selection evelution and back to avoid
68 // naming support on the disabled results. Deeply in the labels tree, recursively.
69 static void EvolutionToSelection(TDF_Label theLab, const bool theFlag) {
70 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> > aShapePairs; // to store old and new shapes
71 Handle(TNaming_NamedShape) aName;
73 if (theLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
74 TNaming_Evolution aNSEvol = aName->Evolution();
75 if ((aNSEvol == TNaming_SELECTED && theFlag) ||
76 (aNSEvol != TNaming_SELECTED && !theFlag)) { // nothing to do, it is already correct
79 anEvolution = (int)(aNSEvol);
81 Handle(TDataStd_Integer) anAttrEvol;
82 if (theLab.FindAttribute(TDataStd_Integer::GetID(), anAttrEvol)) {
83 anEvolution = anAttrEvol->Get();
86 TDataStd_Integer::Set(theLab, anEvolution);
89 for(TNaming_Iterator anIter(aName); anIter.More(); anIter.Next()) {
90 aShapePairs.push_back(std::pair<TopoDS_Shape, TopoDS_Shape>
91 (anIter.OldShape(), anIter.NewShape()));
95 TNaming_Builder aBuilder(theLab);
96 TNaming_Evolution anEvol = (TNaming_Evolution)(anEvolution);
97 std::list<std::pair<TopoDS_Shape, TopoDS_Shape> >::iterator aPairsIter = aShapePairs.begin();
98 for(; aPairsIter != aShapePairs.end(); aPairsIter++) {
99 if (theFlag) { // disabled => make selection
100 aBuilder.Select(aPairsIter->first, aPairsIter->second);
101 } else if (anEvol == TNaming_GENERATED) {
102 aBuilder.Generated(aPairsIter->first, aPairsIter->second);
103 } else if (anEvol == TNaming_MODIFY) {
104 aBuilder.Modify(aPairsIter->first, aPairsIter->second);
105 } else if (anEvol == TNaming_DELETE) {
106 aBuilder.Delete(aPairsIter->first);
107 } else if (anEvol == TNaming_PRIMITIVE) {
108 aBuilder.Generated(aPairsIter->second);
111 // recursive call for all sub-labels
112 TDF_ChildIterator anIter(theLab, Standard_False);
113 for(; anIter.More(); anIter.Next()) {
114 EvolutionToSelection(anIter.Value(), theFlag);
118 bool Model_ResultBody::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
120 bool aChanged = ModelAPI_ResultBody::setDisabled(theThis, theFlag);
121 if (aChanged) { // state is changed, so modifications are needed
122 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
123 if (!aData) // unknown case
125 TDF_Label& aShapeLab = aData->shapeLab();
126 EvolutionToSelection(aShapeLab, theFlag);
132 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
134 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
136 TDF_Label& aShapeLab = aData->shapeLab();
139 // store the new shape as primitive
140 TNaming_Builder aBuilder(aShapeLab);
143 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
145 return; // null shape inside
147 aBuilder.Generated(aShape);
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::storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
163 const std::shared_ptr<GeomAPI_Shape>& theToShape)
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 (!theFromShape || !theToShape)
174 TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
175 if (aShapeBasis.IsNull())
176 return; // null shape inside
177 TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
178 if (aShapeNew.IsNull())
179 return; // null shape inside
180 aBuilder.Generated(aShapeBasis, aShapeNew);
182 if(!aBuilder.NamedShape()->IsEmpty()) {
183 Handle(TDataStd_Name) anAttr;
184 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
185 std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
187 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
188 aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
195 void Model_ResultBody::storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
196 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag)
198 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
200 TDF_Label& aShapeLab = aData->shapeLab();
203 // store the new shape as primitive
204 TNaming_Builder aBuilder(aShapeLab);
205 if (!theOldShape || !theNewShape)
207 TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
208 if (aShapeOld.IsNull())
209 return; // null shape inside
210 TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
211 if (aShapeNew.IsNull())
212 return; // null shape inside
213 aBuilder.Modify(aShapeOld, aShapeNew);
214 if (theDecomposeSolidsTag && aShapeNew.ShapeType() == TopAbs_COMPOUND) { // make sub elements as subs
216 // register name if it is possible
217 TCollection_AsciiString aName;
218 if(!aBuilder.NamedShape()->IsEmpty()) {
219 Handle(TDataStd_Name) anAttr;
220 if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
221 aName = TCollection_AsciiString(anAttr->Get()).ToCString();
225 TopoDS_Iterator aSubIter(aShapeNew);
226 for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) {
227 TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++));
228 aSubBuilder.Generated(aSubIter.Value());
229 if(!aName.IsEmpty()) {
230 std::string aSolidName =
231 (aName + "_Solid_" + TCollection_AsciiString(aTag - theDecomposeSolidsTag)).ToCString();
232 std::shared_ptr<Model_Document> aDoc =
233 std::dynamic_pointer_cast<Model_Document>(document());
234 aDoc->addNamingName(aSubBuilder.NamedShape()->Label(), aSolidName);
235 TDataStd_Name::Set(aSubBuilder.NamedShape()->Label(), aSolidName.c_str());
242 std::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
244 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
246 TDF_Label& aShapeLab = aData->shapeLab();
247 Handle(TNaming_NamedShape) aName;
248 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
249 TopoDS_Shape aShape = aName->Get();
250 if (!aShape.IsNull()) {
251 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
252 aRes->setImpl(new TopoDS_Shape(aShape));
257 return std::shared_ptr<GeomAPI_Shape>();
260 void Model_ResultBody::clean()
262 std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
263 for(; aBuilder != myBuilders.end(); aBuilder++)
268 Model_ResultBody::~Model_ResultBody()
273 TNaming_Builder* Model_ResultBody::builder(const int theTag)
275 if (myBuilders.size() <= (unsigned int)theTag) {
276 myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
278 if (!myBuilders[theTag]) {
279 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
280 myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
281 //TCollection_AsciiString entry;//
282 //TDF_Tool::Entry(aData->shapeLab().FindChild(theTag), entry);
283 //cout << "Label = " <<entry.ToCString() <<endl;
285 return myBuilders[theTag];
288 void Model_ResultBody::buildName(const int theTag, const std::string& theName)
290 std::string aName = data()->name() + "/" + theName;
291 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
292 aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
293 TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
295 void Model_ResultBody::generated(
296 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
298 TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
299 builder(theTag)->Generated(aShape);
301 buildName(theTag, theName);
304 void Model_ResultBody::generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
305 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
307 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
308 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
309 builder(theTag)->Generated(anOldShape, aNewShape);
311 buildName(theTag, theName);
315 void Model_ResultBody::modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
316 const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
318 TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
319 TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
320 builder(theTag)->Modify(anOldShape, aNewShape);
322 buildName(theTag, theName);
325 void Model_ResultBody::deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
328 TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
329 builder(theTag)->Delete(aShape);
332 void Model_ResultBody::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
333 std::shared_ptr<GeomAPI_Shape> theShapeIn,
334 const int theKindOfShape,
337 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
338 TopTools_MapOfShape aView;
339 TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
340 for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
341 const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
342 if (!aView.Add(aRoot)) continue;
343 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
344 aRShape->setImpl((new TopoDS_Shape(aRoot)));
345 if (theMS->isDeleted (aRShape)) {
346 builder(theTag)->Delete(aRoot);
351 void Model_ResultBody::loadAndOrientModifiedShapes (
352 GeomAlgoAPI_MakeShape* theMS,
353 std::shared_ptr<GeomAPI_Shape> theShapeIn,
354 const int theKindOfShape,
356 const std::string& theName,
357 GeomAPI_DataMapOfShapeShape& theSubShapes)
359 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
360 TopTools_MapOfShape aView;
361 bool isBuilt = theName.empty();
362 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
363 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
364 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
365 if (!aView.Add(aRoot)) continue;
367 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
368 aRShape->setImpl((new TopoDS_Shape(aRoot)));
369 theMS->modified(aRShape, aList);
370 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
371 for (; anIt != aLast; anIt++) {
372 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
373 if (theSubShapes.isBound(*anIt)) {
374 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
375 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
377 if (!aRoot.IsSame (aNewShape)) {
378 builder(theTag)->Modify(aRoot,aNewShape);
380 buildName(theTag, theName);
386 void Model_ResultBody::loadAndOrientGeneratedShapes (
387 GeomAlgoAPI_MakeShape* theMS,
388 std::shared_ptr<GeomAPI_Shape> theShapeIn,
389 const int theKindOfShape,
391 const std::string& theName,
392 GeomAPI_DataMapOfShapeShape& theSubShapes)
394 TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
395 TopTools_MapOfShape aView;
396 bool isBuilt = theName.empty();
397 TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
398 for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
399 const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
400 if (!aView.Add(aRoot)) continue;
402 std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
403 aRShape->setImpl((new TopoDS_Shape(aRoot)));
404 theMS->generated(aRShape, aList);
405 std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aList.begin(), aLast = aList.end();
406 for (; anIt != aLast; anIt++) {
407 TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
408 if (theSubShapes.isBound(*anIt)) {
409 std::shared_ptr<GeomAPI_Shape> aMapShape(theSubShapes.find(*anIt));
410 aNewShape.Orientation(aMapShape->impl<TopoDS_Shape>().Orientation());
412 if (!aRoot.IsSame (aNewShape)) {
413 builder(theTag)->Generated(aRoot,aNewShape);
415 buildName(theTag, theName);
421 //=======================================================================
422 int getDangleShapes(const TopoDS_Shape& theShapeIn,
423 const TopAbs_ShapeEnum theGeneratedFrom,
424 TopTools_DataMapOfShapeShape& theDangles)
427 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
428 TopAbs_ShapeEnum GeneratedTo;
429 if (theGeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
430 else if (theGeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
431 else return Standard_False;
432 TopExp::MapShapesAndAncestors(theShapeIn, GeneratedTo, theGeneratedFrom, subShapeAndAncestors);
433 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
434 const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
435 const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
436 if (ancestors.Extent() == 1) theDangles.Bind(ancestors.First(), mayBeDangle);
438 return theDangles.Extent();
441 //=======================================================================
442 void loadGeneratedDangleShapes(
443 const TopoDS_Shape& theShapeIn,
444 const TopAbs_ShapeEnum theGeneratedFrom,
445 TNaming_Builder * theBuilder)
447 TopTools_DataMapOfShapeShape dangles;
448 if (!getDangleShapes(theShapeIn, theGeneratedFrom, dangles)) return;
449 TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
450 for (; itr.More(); itr.Next())
451 theBuilder->Generated(itr.Key(), itr.Value());
454 //=======================================================================
455 void Model_ResultBody::loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
456 const std::string& theName, int& theTag)
458 if(theShape->isNull()) return;
459 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
461 if (aShape.ShapeType() == TopAbs_SOLID) {
462 TopExp_Explorer expl(aShape, TopAbs_FACE);
463 for (; expl.More(); expl.Next()) {
464 builder(theTag)->Generated(expl.Current());
465 TCollection_AsciiString aStr(theTag);
466 aName = theName + aStr.ToCString();
467 buildName(theTag, aName);
471 else if (aShape.ShapeType() == TopAbs_SHELL || aShape.ShapeType() == TopAbs_FACE) {
472 // load faces and all the free edges
473 TopTools_IndexedMapOfShape Faces;
474 TopExp::MapShapes(aShape, TopAbs_FACE, Faces);
475 if (Faces.Extent() > 1 || (aShape.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
476 TopExp_Explorer expl(aShape, TopAbs_FACE);
477 for (; expl.More(); expl.Next()) {
478 builder(theTag)->Generated(expl.Current());
479 TCollection_AsciiString aStr(theTag);
480 aName = theName + aStr.ToCString();
481 buildName(theTag, aName);
485 TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
486 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
487 for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++)
489 const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
490 if (aLL.Extent() < 2) {
491 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeAndNeighbourFaces.FindKey(i))))
493 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
494 TCollection_AsciiString aStr(theTag);
495 aName = theName + aStr.ToCString();
496 buildName(theTag, aName);
499 TopTools_ListIteratorOfListOfShape anIter(aLL);
500 const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
502 if(aFace.IsEqual(anIter.Value())) {
503 builder(theTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
504 TCollection_AsciiString aStr(theTag);
505 aName = theName + aStr.ToCString();
506 buildName(theTag, aName);
511 } else if (aShape.ShapeType() == TopAbs_WIRE) {
512 TopTools_IndexedMapOfShape Edges;
513 BRepTools::Map3DEdges(aShape, Edges);
514 if (Edges.Extent() == 1) {
515 builder(++theTag)->Generated(Edges.FindKey(1));
516 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
517 for (; expl.More(); expl.Next()) {
518 builder(theTag)->Generated(expl.Current());
519 TCollection_AsciiString aStr(theTag);
520 aName = theName + aStr.ToCString();
521 buildName(theTag, aName);
525 TopExp_Explorer expl(aShape, TopAbs_EDGE);
526 for (; expl.More(); expl.Next()) {
527 builder(theTag)->Generated(expl.Current());
528 TCollection_AsciiString aStr(theTag);
529 aName = theName + aStr.ToCString();
530 buildName(theTag, aName);
533 // and load generated vertices.
534 TopTools_DataMapOfShapeShape generated;
535 if (getDangleShapes(aShape, TopAbs_EDGE, generated))
537 TNaming_Builder* pBuilder = builder(theTag++);
538 loadGeneratedDangleShapes(aShape, TopAbs_EDGE, pBuilder);
541 } else if (aShape.ShapeType() == TopAbs_EDGE) {
542 TopExp_Explorer expl(aShape, TopAbs_VERTEX);
543 for (; expl.More(); expl.Next()) {
544 builder(theTag)->Generated(expl.Current());
545 TCollection_AsciiString aStr(theTag);
546 aName = theName + aStr.ToCString();
547 buildName(theTag, aName);
553 //=======================================================================
554 int findAmbiguities(const TopoDS_Shape& theShapeIn,
555 TopTools_ListOfShape& theList)
559 TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
560 TopAbs_ShapeEnum aTS(TopAbs_EDGE);
561 TopAbs_ShapeEnum aTA(TopAbs_FACE);
562 TopTools_MapOfShape aMap1, aMap2; // map1 - for edge ancestors; map2 - for keys => edges
563 TopTools_ListOfShape aKeyList;
564 TopExp::MapShapesAndAncestors(theShapeIn, aTS, aTA, subShapeAndAncestors);
565 for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
566 const TopoDS_Shape& aKeyEdge1 = subShapeAndAncestors.FindKey(i);
567 const TopTools_ListOfShape& ancestors1 = subShapeAndAncestors.FindFromIndex(i);
569 TopTools_ListIteratorOfListOfShape it(ancestors1);
570 for(;it.More();it.Next()) aMap1.Add(it.Value()); // fill map with key ancestors => aKey1
571 for (Standard_Integer j = 1; j <= subShapeAndAncestors.Extent(); j++) {
572 if (i == j) continue;
573 const TopoDS_Shape& aKeyEdge2 = subShapeAndAncestors.FindKey(j);
574 const TopTools_ListOfShape& ancestors2 = subShapeAndAncestors.FindFromIndex(j);
575 if(ancestors1.Extent() == ancestors2.Extent() && ancestors1.Extent() > 1) {
576 int aNum (ancestors2.Extent());
577 TopTools_ListIteratorOfListOfShape it(ancestors2);
578 for(;it.More();it.Next())
579 if(aMap1.Contains(it.Value())) aNum--;
581 if(aMap2.Add(aKeyEdge1))
582 aKeyList.Append(aKeyEdge1);
583 if(aMap2.Add(aKeyEdge2))
584 aKeyList.Append(aKeyEdge2);
587 } // at the end ==> List of edges to be named in addition
589 aNumEdges = aKeyList.Extent();
591 theList.Assign(aKeyList);
595 //=======================================================================
596 void Model_ResultBody::loadFirstLevel(
597 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
599 if(theShape->isNull()) return;
600 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
602 if (aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_COMPSOLID) {
603 TopoDS_Iterator itr(aShape);
604 for (; itr.More(); itr.Next(),theTag++) {
605 builder(theTag)->Generated(itr.Value());
606 TCollection_AsciiString aStr(theTag);
607 aName = theName + aStr.ToCString();
608 buildName(theTag, aName);
609 if(!theName.empty()) buildName(theTag, aName);
610 if (itr.Value().ShapeType() == TopAbs_COMPOUND ||
611 itr.Value().ShapeType() == TopAbs_COMPSOLID)
613 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
614 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
615 loadFirstLevel(itrShape, theName, theTag);
617 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
618 itrShape->setImpl(new TopoDS_Shape(itr.Value()));
619 loadNextLevels(itrShape, theName, theTag);
623 std::shared_ptr<GeomAPI_Shape> itrShape(new GeomAPI_Shape());
624 itrShape->setImpl(new TopoDS_Shape(aShape));
625 loadNextLevels(itrShape, theName, theTag);
627 TopTools_ListOfShape aList;
628 if(findAmbiguities(aShape, aList)) {
629 TopTools_ListIteratorOfListOfShape it(aList);
630 for (; it.More(); it.Next(),theTag++) {
631 builder(theTag)->Generated(it.Value());
632 TCollection_AsciiString aStr(theTag);
633 aName = theName + aStr.ToCString();
634 buildName(theTag, aName);
639 //=======================================================================
640 void Model_ResultBody::loadDisconnectedEdges(
641 std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
643 if(theShape->isNull()) return;
644 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
645 TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
646 TopTools_ListOfShape empty;
647 TopExp_Explorer explF(aShape, TopAbs_FACE);
648 for (; explF.More(); explF.Next()) {
649 const TopoDS_Shape& aFace = explF.Current();
650 TopExp_Explorer explV(aFace, TopAbs_EDGE);
651 for (; explV.More(); explV.Next()) {
652 const TopoDS_Shape& anEdge = explV.Current();
653 if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
654 Standard_Boolean faceIsNew = Standard_True;
655 TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
656 for (; itrF.More(); itrF.Next()) {
657 if (itrF.Value().IsSame(aFace)) {
658 faceIsNew = Standard_False;
663 edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
667 /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
668 TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
669 for(int i=1; i <= aDM.Extent(); i++) {
670 if(aDM.FindFromIndex(i).Extent() > 1) continue;
671 if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
673 builder(theTag)->Generated(aDM.FindKey(i));
674 TCollection_AsciiString aStr(theTag);
675 std::string aName = theName + aStr.ToCString();
676 buildName(theTag, aName);
679 BRepTools::Write(aDM.FindKey(i), aName.c_str());
684 TopTools_MapOfShape anEdgesToDelete;
685 TopExp_Explorer anEx(aShape,TopAbs_EDGE);
687 for(;anEx.More();anEx.Next()) {
688 Standard_Boolean aC0 = Standard_False;
689 TopoDS_Shape anEdge1 = anEx.Current();
690 if (edgeNaborFaces.IsBound(anEdge1)) {
691 const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
692 if (aList1.Extent()<2) continue;
693 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
694 for (; itr.More(); itr.Next()) {
695 TopoDS_Shape anEdge2 = itr.Key();
696 if(anEdgesToDelete.Contains(anEdge2)) continue;
697 if (anEdge1.IsSame(anEdge2)) continue;
698 const TopTools_ListOfShape& aList2 = itr.Value();
699 // compare lists of the neighbour faces of edge1 and edge2
700 if (aList1.Extent() == aList2.Extent()) {
701 Standard_Integer aMatches = 0;
702 for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
703 for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
704 if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
705 if (aMatches == aList1.Extent()) {
707 builder(theTag)->Generated(anEdge2);
708 anEdgesToDelete.Add(anEdge2);
709 TCollection_AsciiString aStr(theTag);
710 aName = theName + aStr.ToCString();
711 buildName(theTag, aName);
716 TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
717 for(;itDelete.More();itDelete.Next())
718 edgeNaborFaces.UnBind(itDelete.Key());
719 edgeNaborFaces.UnBind(anEdge1);
722 builder(theTag)->Generated(anEdge1);
723 TCollection_AsciiString aStr(theTag);
724 aName = theName + aStr.ToCString();
725 buildName(theTag, aName);
731 void Model_ResultBody::loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int& theTag)
733 if(theShape->isNull()) return;
734 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
735 TopTools_DataMapOfShapeListOfShape vertexNaborEdges;
736 TopTools_ListOfShape empty;
737 TopExp_Explorer explF(aShape, TopAbs_EDGE);
738 for (; explF.More(); explF.Next()) {
739 const TopoDS_Shape& anEdge = explF.Current();
740 TopExp_Explorer explV(anEdge, TopAbs_VERTEX);
741 for (; explV.More(); explV.Next()) {
742 const TopoDS_Shape& aVertex = explV.Current();
743 if (!vertexNaborEdges.IsBound(aVertex)) vertexNaborEdges.Bind(aVertex, empty);
744 Standard_Boolean faceIsNew = Standard_True;
745 TopTools_ListIteratorOfListOfShape itrF(vertexNaborEdges.Find(aVertex));
746 for (; itrF.More(); itrF.Next()) {
747 if (itrF.Value().IsSame(anEdge)) {
748 faceIsNew = Standard_False;
753 vertexNaborEdges.ChangeFind(aVertex).Append(anEdge);
758 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborEdges);
759 for (; itr.More(); itr.Next()) {
760 const TopTools_ListOfShape& naborEdges = itr.Value();
761 if (naborEdges.Extent() < 2) {
762 builder(theTag)->Generated(itr.Key());
763 TCollection_AsciiString aStr(theTag);
764 aName = theName + aStr.ToCString();
765 buildName(theTag, aName);