Salome HOME
Fix for crash and invisible bodies on Debian Squeeze SALOME version.
[modules/shaper.git] / src / GeomAPI / GeomAPI_PlanarEdges.cpp
1 // File:        GeomAPI_PlanarEdges.cpp
2 // Created:     06 Oct 2014
3 // Author:      Sergey BELASH
4
5 #include <GeomAPI_Interface.h>
6 #include <GeomAPI_PlanarEdges.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 #include <TopExp_Explorer.hxx>
17
18 #include <list>
19
20 GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
21 {
22   TopoDS_Compound aBigWireImpl;
23   BRep_Builder aBuilder;
24   aBuilder.MakeCompound(aBigWireImpl);
25   this->setImpl(new TopoDS_Shape(aBigWireImpl));
26 }
27
28 void GeomAPI_PlanarEdges::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
29 {
30   const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
31   if (anEdge.ShapeType() != TopAbs_EDGE)
32     return;
33   TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
34   BRep_Builder aBuilder;
35   aBuilder.Add(aWire, anEdge);
36 }
37
38 std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
39 {
40   TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
41   //BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
42   TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
43   std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
44   for (; aWireExp.More(); aWireExp.Next()) {
45     boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
46     anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
47     aResult.push_back(anEdge);
48   }
49   return aResult;
50 }
51
52 bool GeomAPI_PlanarEdges::hasPlane() const {
53   return myOrigin && myNorm && myDirX && myDirY;
54 }
55
56 bool GeomAPI_PlanarEdges::isVertex() const {
57   return false;
58 }
59
60 bool GeomAPI_PlanarEdges::isEdge() const {
61   return false;
62 }
63
64 void GeomAPI_PlanarEdges::setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin)
65 {
66   myOrigin = theOrigin;
67 }
68 boost::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const {
69   return myOrigin;
70 }
71 void GeomAPI_PlanarEdges::setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) {
72   myDirX = theDirX;
73 }
74 boost::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const {
75   return myDirX;
76 }
77 void GeomAPI_PlanarEdges::setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) {
78   myDirY = theDirY;
79 }
80 boost::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const {
81   return myDirY;
82 }
83 void GeomAPI_PlanarEdges::setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) {
84   myNorm = theNorm;
85 }
86 boost::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const {
87   return myNorm;
88 }