Salome HOME
Add tools
[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       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
81       aShape->setImpl(new TopoDS_Shape(aGeneratedShape));
82       theHistory.push_back(aShape);
83     }
84   } else {
85     TopTools_ListOfShape aList;
86     if(myAlgoType == MakeShape) {
87       BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
88       aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
89     } else if(myAlgoType == BOPAlgoBuilder) {
90       BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
91       aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
92     }
93     for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
94       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
95       aShape->setImpl(new TopoDS_Shape(anIt.Value()));
96       theHistory.push_back(aShape);
97     }
98   }
99 }
100
101 //=================================================================================================
102 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
103                                      ListOfShape& theHistory)
104 {
105   TopTools_ListOfShape aList;
106   if(myAlgoType == MakeShape) {
107     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
108     aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
109   } else if(myAlgoType == BOPAlgoBuilder) {
110     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
111     aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
112   }
113   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
114     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
115     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
116     theHistory.push_back(aShape);
117   }
118 }
119
120 //=================================================================================================
121 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
122 {
123   bool isDeleted = false;
124   if(myAlgoType == MakeShape) {
125     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
126     isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
127   } else if(myAlgoType == BOPAlgoBuilder) {
128     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
129     isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
130   }
131
132   return isDeleted;
133 }