]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp
Salome HOME
e997004567c9ce9b33abe1795d938968112d8333
[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 #include <BRepBuilderAPI_MakeShape.hxx>
9 #include <BRepOffsetAPI_MakePipe.hxx>
10 #include <TopExp_Explorer.hxx>
11 #include <TopTools_ListOfShape.hxx>
12 #include <TopTools_ListIteratorOfListOfShape.hxx>
13
14 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
15   : GeomAPI_Interface(theMkShape),myShape(new GeomAPI_Shape())
16 {
17   myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
18 }
19
20 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape,
21                                              const std::shared_ptr<GeomAPI_Shape> theWire,
22                                              const std::shared_ptr<GeomAPI_Shape> theBaseShape)
23 : GeomAPI_Interface(theMkShape),
24   myShape(new GeomAPI_Shape()),
25   myWire(theWire),
26   myBaseShape(theBaseShape)
27 {
28   myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
29 }
30
31 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
32   : GeomAPI_Interface(),myShape(new GeomAPI_Shape())
33 {}
34
35 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
36 {
37   return myShape;
38 }
39
40 void GeomAlgoAPI_MakeShape::generated(
41   const std::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
42 {
43   if(!myWire.get()) {
44     BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
45     if(aBuilder) {
46       const TopTools_ListOfShape& aList =  aBuilder->Generated(theShape->impl<TopoDS_Shape>());
47       TopTools_ListIteratorOfListOfShape it(aList);
48       for(;it.More();it.Next()) {
49         std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
50         aShape->setImpl(new TopoDS_Shape(it.Value()));
51         theHistory.push_back(aShape);
52       }
53     }
54   } else { // Pipe builder
55     BRepOffsetAPI_MakePipe* aPipeBuilder = implPtr<BRepOffsetAPI_MakePipe>();
56     if(aPipeBuilder) {
57       TopExp_Explorer aShapeExplorer(myWire->impl<TopoDS_Wire>(), TopAbs_EDGE);
58       for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
59         const TopoDS_Shape& aSpine = aShapeExplorer.Current();
60         const TopoDS_Shape& aProfile = theShape->impl<TopoDS_Shape>();
61         if(aProfile.ShapeType() != TopAbs_EDGE && aProfile.ShapeType() != TopAbs_VERTEX) {
62             return;
63         }
64         const TopoDS_Shape& aBaseShape = myBaseShape->impl<TopoDS_Shape>();
65         TopExp_Explorer anExp(aBaseShape, aProfile.ShapeType());
66         Standard_Boolean hasShape = Standard_False;
67         for(; anExp.More(); anExp.Next()) {
68           if(anExp.Current().IsSame(aProfile)) {
69             hasShape = Standard_True;
70             break;
71           }
72         }
73         if(!hasShape) {
74           return;
75         }
76         const TopoDS_Shape& aGeneratedShape = aPipeBuilder->Generated(aSpine, aProfile);
77         std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
78         aShape->setImpl(new TopoDS_Shape(aGeneratedShape));
79         theHistory.push_back(aShape);
80       }
81     }
82   }
83 }
84
85 void GeomAlgoAPI_MakeShape::modified(
86   const std::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
87 {
88   BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
89   if(aBuilder) {
90     const TopTools_ListOfShape& aList =  aBuilder->Modified(theShape->impl<TopoDS_Shape>());
91     TopTools_ListIteratorOfListOfShape it(aList);
92     for(;it.More();it.Next()) {
93       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
94       aShape->setImpl(new TopoDS_Shape(it.Value()));
95       theHistory.push_back(aShape);
96     }
97   }
98 }
99
100 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
101 {
102   bool isDeleted(false);
103   BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
104   if(aBuilder) {
105     isDeleted = aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
106   }
107   return isDeleted;
108 }