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