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"
10 #include <NCollection_List.hxx>
11 #include <NCollection_Map.hxx>
12 #include <TopoDS_Shape.hxx>
14 //=================================================================================================
15 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList()
16 : GeomAlgoAPI_MakeShape()
19 //=================================================================================================
20 GeomAlgoAPI_MakeShapeList::GeomAlgoAPI_MakeShapeList(const ListOfMakeShape& theMakeShapeList)
21 : GeomAlgoAPI_MakeShape()
23 init(theMakeShapeList);
26 //=================================================================================================
27 void GeomAlgoAPI_MakeShapeList::init(const ListOfMakeShape& theMakeShapeList)
32 myMap.reset(new GeomAPI_DataMapOfShapeShape);
35 myListOfMakeShape = theMakeShapeList;
37 for(ListOfMakeShape::const_iterator anIt = theMakeShapeList.cbegin();
38 anIt != theMakeShapeList.cend(); ++anIt) {
39 myMap->merge((*anIt)->mapOfSubShapes());
43 //=================================================================================================
44 void GeomAlgoAPI_MakeShapeList::appendAlgo(
45 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
47 myListOfMakeShape.push_back(theMakeShape);
49 myMap.reset(new GeomAPI_DataMapOfShapeShape());
51 myMap->merge(theMakeShape->mapOfSubShapes());
54 //=================================================================================================
55 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
57 std::shared_ptr<GeomAPI_Shape> aShape = GeomAlgoAPI_MakeShape::shape();
58 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
60 } else if(!myListOfMakeShape.empty()) {
61 return myListOfMakeShape.back()->shape();
63 return std::shared_ptr<GeomAPI_Shape>();
66 //=================================================================================================
67 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
68 ListOfShape& theHistory)
70 result(theShape, GeomAlgoAPI_MakeShapeList::Generated, theHistory);
73 //=================================================================================================
74 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
75 ListOfShape& theHistory)
77 result(theShape, GeomAlgoAPI_MakeShapeList::Modified, theHistory);
80 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
82 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
83 aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
84 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
85 if(aMakeShape->isDeleted(theShape)) {
93 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
94 OperationType theOperationType,
95 ListOfShape& theHistory)
97 if(myListOfMakeShape.empty()) {
101 NCollection_Map<TopoDS_Shape> anAlgoShapes;
102 NCollection_Map<TopoDS_Shape> aResultShapesMap;
103 NCollection_List<TopoDS_Shape> aResultShapesList;
104 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
105 aResultShapesMap.Add(theShape->impl<TopoDS_Shape>());
106 aResultShapesList.Append(theShape->impl<TopoDS_Shape>());
108 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin();
109 aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
110 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
111 NCollection_Map<TopoDS_Shape> aTempShapes;
112 bool hasResults = false;
113 for(NCollection_Map<TopoDS_Shape>::Iterator
114 aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
115 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
116 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
117 ListOfShape aGeneratedShapes;
118 aMakeShape->generated(aShape, aGeneratedShapes);
119 for(ListOfShape::const_iterator
120 anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
121 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
122 aTempShapes.Add(anItShape);
123 if(aResultShapesMap.Add(anItShape) == Standard_True) {
124 aResultShapesList.Append(anItShape);
128 ListOfShape aModifiedShapes;
129 aMakeShape->modified(aShape, aModifiedShapes);
130 for(ListOfShape::const_iterator
131 anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
132 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
133 aTempShapes.Add(anItShape);
134 if(aResultShapesMap.Add(anItShape) == Standard_True) {
135 aResultShapesList.Append(anItShape);
140 const TopoDS_Shape& aTopoDSShape = aShapeIt.Value();
141 if(aResultShapesMap.Remove(aTopoDSShape) == Standard_True) {
142 for(NCollection_List<TopoDS_Shape>::Iterator
143 aResIt(aResultShapesList); aResIt.More(); aResIt.Next()) {
144 if(aTopoDSShape.IsEqual(aResIt.Value())) {
145 aResultShapesList.Remove(aResIt);
152 anAlgoShapes.Unite(aTempShapes);
155 for(NCollection_List<TopoDS_Shape>::Iterator
156 aShapeIt(aResultShapesList); aShapeIt.More(); aShapeIt.Next()) {
157 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
158 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
159 theHistory.push_back(aShape);