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(const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
46 myListOfMakeShape.push_back(theMakeShape);
48 myMap.reset(new GeomAPI_DataMapOfShapeShape());
50 myMap->merge(theMakeShape->mapOfSubShapes());
53 //=================================================================================================
54 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
56 std::shared_ptr<GeomAPI_Shape> aShape = GeomAlgoAPI_MakeShape::shape();
57 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
59 } else if(!myListOfMakeShape.empty()) {
60 return myListOfMakeShape.back()->shape();
62 return std::shared_ptr<GeomAPI_Shape>();
65 //=================================================================================================
66 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
67 ListOfShape& theHistory)
69 result(theShape, GeomAlgoAPI_MakeShapeList::Generated, theHistory);
72 //=================================================================================================
73 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
74 ListOfShape& theHistory)
76 result(theShape, GeomAlgoAPI_MakeShapeList::Modified, theHistory);
79 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
81 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
82 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
83 if(aMakeShape->isDeleted(theShape)) {
91 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
92 OperationType theOperationType,
93 ListOfShape& theHistory)
95 if(myListOfMakeShape.empty()) {
99 NCollection_Map<TopoDS_Shape> anAlgoShapes;
100 NCollection_Map<TopoDS_Shape> aResultShapesMap;
101 NCollection_List<TopoDS_Shape> aResultShapesList;
102 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
103 aResultShapesMap.Add(theShape->impl<TopoDS_Shape>());
104 aResultShapesList.Append(theShape->impl<TopoDS_Shape>());
106 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
107 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
108 NCollection_Map<TopoDS_Shape> aTempShapes;
109 bool hasResults = false;
110 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
111 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
112 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
113 ListOfShape aGeneratedShapes;
114 aMakeShape->generated(aShape, aGeneratedShapes);
115 for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
116 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
117 aTempShapes.Add(anItShape);
118 if(aResultShapesMap.Add(anItShape) == Standard_True) {
119 aResultShapesList.Append(anItShape);
123 ListOfShape aModifiedShapes;
124 aMakeShape->modified(aShape, aModifiedShapes);
125 for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
126 const TopoDS_Shape& anItShape = (*anIt)->impl<TopoDS_Shape>();
127 aTempShapes.Add(anItShape);
128 if(aResultShapesMap.Add(anItShape) == Standard_True) {
129 aResultShapesList.Append(anItShape);
134 const TopoDS_Shape& aTopoDSShape = aShapeIt.Value();
135 if(aResultShapesMap.Remove(aTopoDSShape) == Standard_True) {
136 for(NCollection_List<TopoDS_Shape>::Iterator aResIt(aResultShapesList); aResIt.More(); aResIt.Next()) {
137 if(aTopoDSShape.IsEqual(aResIt.Value())) {
138 aResultShapesList.Remove(aResIt);
145 anAlgoShapes.Unite(aTempShapes);
148 for(NCollection_List<TopoDS_Shape>::Iterator aShapeIt(aResultShapesList); aShapeIt.More(); aShapeIt.Next()) {
149 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
150 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
151 theHistory.push_back(aShape);