Salome HOME
f5e69c52fc1ef53430e26d4145a0427539ad6c3e
[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 AlgoType theAlgoType)
18 : GeomAPI_Interface(theMkShape),
19   myAlgoType(theAlgoType),
20   myShape(new GeomAPI_Shape())
21 {
22   switch (myAlgoType) {
23     case MakeShape:
24     case MakePipe: {
25       myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
26       break;
27     }
28     case BOPAlgoBuilder: {
29       myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
30       break;
31     }
32   }
33 }
34
35 //=================================================================================================
36 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape,
37                                              const std::shared_ptr<GeomAPI_Shape> theWire,
38                                              const std::shared_ptr<GeomAPI_Shape> theBaseShape)
39 : GeomAPI_Interface(theMkShape),
40   myAlgoType(MakePipe),
41   myShape(new GeomAPI_Shape()),
42   myWire(theWire),
43   myBaseShape(theBaseShape)
44 {
45   myShape->setImpl(new TopoDS_Shape(implPtr<BRepOffsetAPI_MakePipe>()->Shape()));
46 }
47
48 //=================================================================================================
49 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
50 {
51   return myShape;
52 }
53
54 //=================================================================================================
55 void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
56                                       ListOfShape& theHistory)
57 {
58   if(myAlgoType == MakePipe) {
59     BRepOffsetAPI_MakePipe* aMakePipe = implPtr<BRepOffsetAPI_MakePipe>();
60     TopExp_Explorer aShapeExplorer(myWire->impl<TopoDS_Wire>(), TopAbs_EDGE);
61     for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
62       const TopoDS_Shape& aSpine = aShapeExplorer.Current();
63       const TopoDS_Shape& aProfile = theShape->impl<TopoDS_Shape>();
64       if(aProfile.ShapeType() != TopAbs_EDGE && aProfile.ShapeType() != TopAbs_VERTEX) {
65           return;
66       }
67       const TopoDS_Shape& aBaseShape = myBaseShape->impl<TopoDS_Shape>();
68       TopExp_Explorer anExp(aBaseShape, aProfile.ShapeType());
69       Standard_Boolean hasShape = Standard_False;
70       for(; anExp.More(); anExp.Next()) {
71         if(anExp.Current().IsSame(aProfile)) {
72           hasShape = Standard_True;
73           break;
74         }
75       }
76       if(!hasShape) {
77         return;
78       }
79       const TopoDS_Shape& aGeneratedShape = aMakePipe->Generated(aSpine, aProfile);
80       if(aGeneratedShape.IsNull()) {
81         continue;
82       }
83       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
84       aShape->setImpl(new TopoDS_Shape(aGeneratedShape));
85       theHistory.push_back(aShape);
86     }
87   } else {
88     TopTools_ListOfShape aList;
89     if(myAlgoType == MakeShape) {
90       BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
91       aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
92     } else if(myAlgoType == BOPAlgoBuilder) {
93       BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
94       aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
95     }
96     for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
97       if(anIt.Value().IsNull()) {
98         continue;
99       }
100       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
101       aShape->setImpl(new TopoDS_Shape(anIt.Value()));
102       theHistory.push_back(aShape);
103     }
104   }
105 }
106
107 //=================================================================================================
108 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
109                                      ListOfShape& theHistory)
110 {
111   TopTools_ListOfShape aList;
112   if(myAlgoType == MakeShape) {
113     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
114     aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
115   } else if(myAlgoType == BOPAlgoBuilder) {
116     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
117     aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
118   }
119   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
120     if(anIt.Value().IsNull()) {
121       continue;
122     }
123     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
124     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
125     theHistory.push_back(aShape);
126   }
127 }
128
129 //=================================================================================================
130 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
131 {
132   bool isDeleted = false;
133   if(myAlgoType == MakeShape) {
134     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
135     isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
136   } else if(myAlgoType == BOPAlgoBuilder) {
137     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
138     isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
139   }
140
141   return isDeleted;
142 }