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 <BRepBuilderAPI_MakeShape.hxx>
10 #include <NCollection_Map.hxx>
11 #include <TopTools_ListOfShape.hxx>
12 #include <TopTools_ListIteratorOfListOfShape.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)
29 myListOfMakeShape = theMakeShapeList;
32 //=================================================================================================
33 void GeomAlgoAPI_MakeShapeList::append(const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
35 myListOfMakeShape.push_back(theMakeShape);
38 //=================================================================================================
39 void GeomAlgoAPI_MakeShapeList::append(const GeomAlgoAPI_MakeShapeList& theMakeShapeList)
41 for(ListOfMakeShape::const_iterator anIt = theMakeShapeList.myListOfMakeShape.cbegin();
42 anIt != theMakeShapeList.myListOfMakeShape.cend(); anIt++) {
43 myListOfMakeShape.push_back(*anIt);
47 //=================================================================================================
48 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
50 if(myListOfMakeShape.empty()) {
51 return std::shared_ptr<GeomAPI_Shape>();
53 return myListOfMakeShape.back()->shape();
57 //=================================================================================================
58 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
59 ListOfShape& theHistory)
61 result(theShape, theHistory, GeomAlgoAPI_MakeShapeList::Generated);
64 //=================================================================================================
65 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
66 ListOfShape& theHistory)
68 result(theShape, theHistory, GeomAlgoAPI_MakeShapeList::Modified);
71 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
73 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
74 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
75 if(aMakeShape->isDeleted(theShape)) {
83 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
84 ListOfShape& theHistory,
85 OperationType theOperationType)
87 if(myListOfMakeShape.empty()) {
91 NCollection_Map<TopoDS_Shape> anAlgoShapes;
92 NCollection_Map<TopoDS_Shape> aResultShapes;
93 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
94 aResultShapes.Add(theShape->impl<TopoDS_Shape>());
96 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
97 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
98 NCollection_Map<TopoDS_Shape> aTempShapes;
99 bool hasResults = false;
100 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
101 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
102 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
103 ListOfShape aGeneratedShapes;
104 const TopoDS_Shape& aSh = aShape->impl<TopoDS_Shape>();
105 aMakeShape->generated(aShape, aGeneratedShapes);
106 for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
107 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
108 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
111 ListOfShape aModifiedShapes;
112 aMakeShape->modified(aShape, aModifiedShapes);
113 for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
114 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
115 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
119 aResultShapes.Remove(aShape->impl<TopoDS_Shape>());
122 anAlgoShapes.Unite(aTempShapes);
125 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) {
126 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
127 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
128 theHistory.push_back(aShape);