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