1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_MakeShapeListList.cpp
4 // Created: 27 May 2015
5 // Author: Dmitry Bobylev
7 #include "GeomAlgoAPI_MakeShapeList.h"
9 #include <NCollection_Map.hxx>
10 #include <TopoDS_Shape.hxx>
12 //=================================================================================================
13 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList()
14 : GeomAlgoAPI_MakeShape()
17 //=================================================================================================
18 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList(const ListOfMakeShape& theMakeShapeList)
19 : GeomAlgoAPI_MakeShape()
21 init(theMakeShapeList);
24 //=================================================================================================
25 void GeomAlgoAPI_MakeShapeList::init(const ListOfMakeShape& theMakeShapeList)
30 myMap.reset(new GeomAPI_DataMapOfShapeShape);
33 myListOfMakeShape = theMakeShapeList;
35 for(ListOfMakeShape::const_iterator anIt = theMakeShapeList.cbegin();
36 anIt != theMakeShapeList.cend(); ++anIt) {
37 myMap->merge((*anIt)->mapOfSubShapes());
41 //=================================================================================================
42 void GeomAlgoAPI_MakeShapeList::appendAlgo(const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
44 myListOfMakeShape.push_back(theMakeShape);
46 myMap.reset(new GeomAPI_DataMapOfShapeShape());
48 myMap->merge(theMakeShape->mapOfSubShapes());
51 //=================================================================================================
52 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
54 std::shared_ptr<GeomAPI_Shape> aShape = GeomAlgoAPI_MakeShape::shape();
55 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
57 } else if(!myListOfMakeShape.empty()) {
58 return myListOfMakeShape.back()->shape();
60 return std::shared_ptr<GeomAPI_Shape>();
63 //=================================================================================================
64 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
65 ListOfShape& theHistory)
67 result(theShape, GeomAlgoAPI_MakeShapeList::Generated, theHistory);
70 //=================================================================================================
71 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
72 ListOfShape& theHistory)
74 result(theShape, GeomAlgoAPI_MakeShapeList::Modified, theHistory);
77 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
79 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
80 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
81 if(aMakeShape->isDeleted(theShape)) {
89 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
90 OperationType theOperationType,
91 ListOfShape& theHistory)
93 if(myListOfMakeShape.empty()) {
97 NCollection_Map<TopoDS_Shape> anAlgoShapes;
98 NCollection_Map<TopoDS_Shape> aResultShapes;
99 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
100 aResultShapes.Add(theShape->impl<TopoDS_Shape>());
102 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
103 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
104 NCollection_Map<TopoDS_Shape> aTempShapes;
105 bool hasResults = false;
106 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
107 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
108 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
109 ListOfShape aGeneratedShapes;
110 aMakeShape->generated(aShape, aGeneratedShapes);
111 for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
112 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
113 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
116 ListOfShape aModifiedShapes;
117 aMakeShape->modified(aShape, aModifiedShapes);
118 for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
119 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
120 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
124 aResultShapes.Remove(aShape->impl<TopoDS_Shape>());
127 anAlgoShapes.Unite(aTempShapes);
130 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) {
131 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
132 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
133 theHistory.push_back(aShape);