Salome HOME
Hide run-time warning, define to debug the cross cursor in sketch.
[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       myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
25       break;
26     }
27     case BOPAlgoBuilder: {
28       myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
29       break;
30     }
31   }
32 }
33
34 //=================================================================================================
35 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
36 {
37   return myShape;
38 }
39
40 //=================================================================================================
41 void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
42                                       ListOfShape& theHistory)
43 {
44   TopTools_ListOfShape aList;
45   if(myAlgoType == MakeShape) {
46     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
47     aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
48   } else if(myAlgoType == BOPAlgoBuilder) {
49     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
50     aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
51   }
52   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
53     if(anIt.Value().IsNull()) {
54       continue;
55     }
56     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
57     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
58     theHistory.push_back(aShape);
59   }
60 }
61
62 //=================================================================================================
63 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
64                                      ListOfShape& theHistory)
65 {
66   TopTools_ListOfShape aList;
67   if(myAlgoType == MakeShape) {
68     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
69     aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
70   } else if(myAlgoType == BOPAlgoBuilder) {
71     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
72     aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
73   }
74   for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
75     if(anIt.Value().IsNull()) {
76       continue;
77     }
78     std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
79     aShape->setImpl(new TopoDS_Shape(anIt.Value()));
80     theHistory.push_back(aShape);
81   }
82 }
83
84 //=================================================================================================
85 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
86 {
87   bool isDeleted = false;
88   if(myAlgoType == MakeShape) {
89     BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
90     isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
91   } else if(myAlgoType == BOPAlgoBuilder) {
92     BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
93     isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
94   }
95
96   return isDeleted;
97 }