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 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
35 if(myListOfMakeShape.empty()) {
36 return std::shared_ptr<GeomAPI_Shape>();
38 return myListOfMakeShape.back()->shape();
42 //=================================================================================================
43 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
44 ListOfShape& theHistory)
46 result(theShape, theHistory, GeomAlgoAPI_MakeShapeList::Generated);
49 //=================================================================================================
50 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
51 ListOfShape& theHistory)
53 result(theShape, theHistory, GeomAlgoAPI_MakeShapeList::Modified);
56 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
58 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
59 BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr<BRepBuilderAPI_MakeShape>();
60 if(aBuilder && (aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True)) {
68 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
69 ListOfShape& theHistory,
70 OperationType theOperationType)
72 if(myListOfMakeShape.empty()) {
76 NCollection_Map<TopoDS_Shape> anAlgoShapes;
77 NCollection_Map<TopoDS_Shape> aResultShapes;
78 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
79 aResultShapes.Add(theShape->impl<TopoDS_Shape>());
81 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
82 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
83 NCollection_Map<TopoDS_Shape> aTempShapes;
84 bool hasResults = false;
85 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
86 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
87 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
88 ListOfShape aGeneratedShapes;
89 aMakeShape->generated(aShape, aGeneratedShapes);
90 for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
91 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
92 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
95 ListOfShape aModifiedShapes;
96 aMakeShape->modified(aShape, aModifiedShapes);
97 for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
98 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
99 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
103 aResultShapes.Remove(aShape->impl<TopoDS_Shape>());
106 anAlgoShapes.Unite(aTempShapes);
109 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) {
110 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
111 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
112 theHistory.push_back(aShape);