1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_MakeShapeListList.h
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 myMakeShapeList = theMakeShapeList;
32 //=================================================================================================
33 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShapeList::shape() const
35 if(myMakeShapeList.empty()) {
36 return std::shared_ptr<GeomAPI_Shape>();
38 return myMakeShapeList.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 void GeomAlgoAPI_MakeShapeList::result(const std::shared_ptr<GeomAPI_Shape> theShape,
57 ListOfShape& theHistory,
58 OperationType theOperationType)
60 if(myMakeShapeList.empty()) {
64 NCollection_Map<TopoDS_Shape> aTempShapes;
65 NCollection_Map<TopoDS_Shape> aResultShapes;
66 aTempShapes.Add(theShape->impl<TopoDS_Shape>());
68 for(ListOfMakeShape::iterator aBuilderIt = myMakeShapeList.begin(); aBuilderIt != myMakeShapeList.end(); aBuilderIt++) {
69 BRepBuilderAPI_MakeShape* aBuilder = (*aBuilderIt)->implPtr<BRepBuilderAPI_MakeShape>();
70 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aTempShapes); aShapeIt.More(); aShapeIt.Next()) {
71 const TopoDS_Shape& aShape = aShapeIt.Value();
72 const TopTools_ListOfShape& aList = theOperationType == GeomAlgoAPI_MakeShapeList::Generated ?
73 aBuilder->Generated(aShape) : aBuilder->Modified(aShape);
74 bool prevResRemoved = false;
75 for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
76 aTempShapes.Add(anIt.Value());
77 aResultShapes.Add(anIt.Value());
79 aResultShapes.Remove(aShape);
80 prevResRemoved = true;
86 for(NCollection_Map<TopoDS_Shape>::Iterator aShapeIt(aResultShapes); aShapeIt.More(); aShapeIt.Next()) {
87 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
88 aShape->setImpl(new TopoDS_Shape(aShapeIt.Value()));
89 theHistory.push_back(aShape);