]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp
Salome HOME
Architecture changes
[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(void* theMkShape, const BuilderType theBuilderType)
18 : GeomAPI_Interface(theMkShape),
19   myBuilderType(theBuilderType),
20   myShape(new GeomAPI_Shape())
21 {
22   switch (myBuilderType) {
23     case OCCT_BRepBuilderAPI_MakeShape: {
24       myDone = implPtr<BRepBuilderAPI_MakeShape>()->IsDone() == Standard_True;
25       myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
26       break;
27     }
28     case OCCT_BOPAlgo_Builder: {
29       myDone = true;
30       myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
31       break;
32     }
33   }
34 }
35
36 //=================================================================================================
37 bool GeomAlgoAPI_MakeShape::isDone() const
38 {
39   return myDone;
40 }
41
42 //=================================================================================================
43 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
44 {
45   return myShape;
46 }
47
48 //=================================================================================================
49 void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
50                                       ListOfShape& theHistory)
51 {
52   TopTools_ListOfShape aList;
53   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
54     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
55     aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
56   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
57     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
58     aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
59   }
60   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
61     if(anIt.Value().IsNull()) {
62       continue;
63     }
64     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
65     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
66     theHistory.push_back(aShape);
67   }
68 }
69
70 //=================================================================================================
71 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
72                                      ListOfShape& theHistory)
73 {
74   TopTools_ListOfShape aList;
75   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
76     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
77     aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
78   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
79     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
80     aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
81   }
82   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
83     if(anIt.Value().IsNull()) {
84       continue;
85     }
86     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
87     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
88     theHistory.push_back(aShape);
89   }
90 }
91
92 //=================================================================================================
93 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
94 {
95   bool isDeleted = false;
96   if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
97     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
98     isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
99   } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
100     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
101     isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
102   }
103
104   return isDeleted;
105 }
106
107
108 //=================================================================================================
109 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
110 : myBuilderType(OCCT_BRepBuilderAPI_MakeShape),
111   myDone(false),
112   myShape(new GeomAPI_Shape())
113 {
114 }
115
116 //=================================================================================================
117 void GeomAlgoAPI_MakeShape::setBuilderType(const BuilderType theBuilderType)
118 {
119   myBuilderType = theBuilderType;
120 }
121
122 //=================================================================================================
123 void GeomAlgoAPI_MakeShape::setDone(const bool theFlag)
124 {
125   myDone = theFlag;
126 }
127
128 //=================================================================================================
129 void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theShape)
130 {
131   myShape = theShape;
132 }