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)
27 myListOfMakeShape = theMakeShapeList;
30 //=================================================================================================
31 void GeomAlgoAPI_MakeShapeList::appendAlgo(const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape)
33 myListOfMakeShape.push_back(theMakeShape);
36 //=================================================================================================
37 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
39 std::shared_ptr<GeomAPI_Shape> aShape = GeomAlgoAPI_MakeShape::shape();
40 if(aShape.get() && !aShape->impl<TopoDS_Shape>().IsNull()) {
42 } else if(!myListOfMakeShape.empty()) {
43 return myListOfMakeShape.back()->shape();
45 return std::shared_ptr<GeomAPI_Shape>();
48 //=================================================================================================
49 void GeomAlgoAPI_MakeShapeList::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
50 ListOfShape& theHistory)
52 result(theShape, GeomAlgoAPI_MakeShapeList::Generated, theHistory);
55 //=================================================================================================
56 void GeomAlgoAPI_MakeShapeList::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
57 ListOfShape& theHistory)
59 result(theShape, GeomAlgoAPI_MakeShapeList::Modified, theHistory);
62 bool GeomAlgoAPI_MakeShapeList::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
64 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
65 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
66 if(aMakeShape->isDeleted(theShape)) {
74 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
75 OperationType theOperationType,
76 ListOfShape& theHistory)
78 if(myListOfMakeShape.empty()) {
82 NCollection_Map<TopoDS_Shape> anAlgoShapes;
83 NCollection_Map<TopoDS_Shape> aResultShapes;
84 anAlgoShapes.Add(theShape->impl<TopoDS_Shape>());
85 aResultShapes.Add(theShape->impl<TopoDS_Shape>());
87 for(ListOfMakeShape::iterator aBuilderIt = myListOfMakeShape.begin(); aBuilderIt != myListOfMakeShape.end(); aBuilderIt++) {
88 std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape = *aBuilderIt;
89 NCollection_Map<TopoDS_Shape> aTempShapes;
90 bool hasResults = false;
91 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(anAlgoShapes); aShapeIt.More(); aShapeIt.Next()) {
92 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
93 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
94 ListOfShape aGeneratedShapes;
95 aMakeShape->generated(aShape, aGeneratedShapes);
96 for(ListOfShape::const_iterator anIt = aGeneratedShapes.cbegin(); anIt != aGeneratedShapes.cend(); anIt++) {
97 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
98 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
101 ListOfShape aModifiedShapes;
102 aMakeShape->modified(aShape, aModifiedShapes);
103 for(ListOfShape::const_iterator anIt = aModifiedShapes.cbegin(); anIt != aModifiedShapes.cend(); anIt++) {
104 aTempShapes.Add((*anIt)->impl<TopoDS_Shape>());
105 aResultShapes.Add((*anIt)->impl<TopoDS_Shape>());
109 aResultShapes.Remove(aShape->impl<TopoDS_Shape>());
112 anAlgoShapes.Unite(aTempShapes);
115 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) {
116 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
117 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
118 theHistory.push_back(aShape);