Salome HOME
c70d5c5e8998374913a70eb7f69f913ad83d4e45
[modules/shaper.git] / src / GeomAPI / GeomAPI_Wire.cpp
1 // File:        GeomAPI_Wire.cpp
2 // Created:     06 Oct 2014
3 // Author:      Sergey BELASH
4
5 #include <GeomAPI_Interface.h>
6 #include <GeomAPI_Wire.h>
7
8 #include <Standard_TypeDef.hxx>
9 #include <TopAbs_ShapeEnum.hxx>
10
11 #include <TopoDS.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Wire.hxx>
14 #include <BRep_Builder.hxx>
15 #include <BRepTools_WireExplorer.hxx>
16
17 #include <list>
18
19 GeomAPI_Wire::GeomAPI_Wire() : GeomAPI_Shape()
20 {
21   TopoDS_Wire aBigWireImpl;
22   BRep_Builder aBuilder;
23   aBuilder.MakeWire(aBigWireImpl);
24   this->setImpl(new TopoDS_Shape(aBigWireImpl));
25 }
26
27 void GeomAPI_Wire::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
28 {
29   const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
30   if (anEdge.ShapeType() != TopAbs_EDGE)
31     return;
32   TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
33   BRep_Builder aBuilder;
34   aBuilder.Add(aWire, anEdge);
35 }
36
37 std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_Wire::getEdges()
38 {
39   TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
40   BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
41   std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
42   for (; aWireExp.More(); aWireExp.Next()) {
43     boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
44     anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
45     aResult.push_back(anEdge);
46   }
47   return aResult;
48 }