Salome HOME
3b0d3ca8b2462b5b33812439740a31d5be284cf9
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_MakeShape.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_MakeShape.cpp
4 // Created:     20 Oct 2014
5 // Author:      Sergey ZARITCHNY
6
7 #include <GeomAlgoAPI_MakeShape.h>
8
9 #include <BOPAlgo_Builder.hxx>
10 #include <BRepBuilderAPI_MakeShape.hxx>
11 #include <BRepOffsetAPI_MakePipe.hxx>
12 #include <TopExp_Explorer.hxx>
13 #include <TopTools_ListOfShape.hxx>
14 #include <TopTools_ListIteratorOfListOfShape.hxx>
15
16 //=================================================================================================
17 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
18 : myBuilderType(OCCT_BRepBuilderAPI_MakeShape),
19   myDone(false)
20 {
21 }
22
23 //=================================================================================================
24 bool GeomAlgoAPI_MakeShape::isDone() const
25 {
26   return myDone;
27 }
28
29 //=================================================================================================
30 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
31 {
32   return myShape;
33 }
34
35 //=================================================================================================
36 void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
37                                       ListOfShape& theHistory)
38 {
39   TopTools_ListOfShape aList;
40   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
41     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
42     aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
43   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
44     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
45     aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
46   }
47   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
48     if(anIt.Value().IsNull()) {
49       continue;
50     }
51     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
52     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
53     theHistory.push_back(aShape);
54   }
55 }
56
57 //=================================================================================================
58 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
59                                      ListOfShape& theHistory)
60 {
61   TopTools_ListOfShape aList;
62   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
63     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
64     aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
65   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
66     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
67     aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
68   }
69   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
70     if(anIt.Value().IsNull()) {
71       continue;
72     }
73     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
74     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
75     theHistory.push_back(aShape);
76   }
77 }
78
79 //=================================================================================================
80 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
81 {
82   bool isDeleted = false;
83   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
84     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
85     isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
86   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
87     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
88     isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
89   }
90
91   return isDeleted;
92 }
93
94 //=================================================================================================
95 void GeomAlgoAPI_MakeShape::setBuilderType(const BuilderType theBuilderType)
96 {
97   myBuilderType = theBuilderType;
98 }
99
100 //=================================================================================================
101 void GeomAlgoAPI_MakeShape::setDone(const bool theFlag)
102 {
103   myDone = theFlag;
104 }
105
106 //=================================================================================================
107 void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theShape)
108 {
109   myShape = theShape;
110 }
111
112 //=================================================================================================
113 void GeomAlgoAPI_MakeShape::initialize() {
114   switch (myBuilderType) {
115     case OCCT_BRepBuilderAPI_MakeShape: {
116       myDone = implPtr<BRepBuilderAPI_MakeShape>()->IsDone() == Standard_True;
117       myShape.reset(new GeomAPI_Shape());
118       myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
119       break;
120     }
121     case OCCT_BOPAlgo_Builder: {
122       myDone = true;
123       myShape.reset(new GeomAPI_Shape());
124       myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
125       break;
126     }
127   }
128 }