]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAPI/GeomAPI_PlanarEdges.cpp
Salome HOME
Update SketchPlugin_Projection feature (issue #1459)
[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   TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
44   std::list<std::shared_ptr<GeomAPI_Shape> > aResult;
45   for (; aWireExp.More(); aWireExp.Next()) {
46     std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
47     anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
48     aResult.push_back(anEdge);
49   }
50   return aResult;
51 }
52
53 bool GeomAPI_PlanarEdges::hasPlane() const {
54   return myPlane.get() != NULL;
55 }
56
57 bool GeomAPI_PlanarEdges::isVertex() const {
58   return false;
59 }
60
61 bool GeomAPI_PlanarEdges::isEdge() const {
62   return false;
63 }
64
65 std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const 
66 {
67   if (hasPlane())
68     return myPlane->origin();
69   return std::shared_ptr<GeomAPI_Pnt>();
70 }
71
72 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const 
73 {
74   if (hasPlane())
75     return myPlane->dirX();
76   return std::shared_ptr<GeomAPI_Dir>();
77 }
78
79 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const 
80 {
81   if (hasPlane())
82     return myPlane->dirY();
83   return std::shared_ptr<GeomAPI_Dir>();
84 }
85
86 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const 
87 {
88   if (hasPlane())
89     return myPlane->normal();
90   return std::shared_ptr<GeomAPI_Dir>();
91 }
92
93 bool GeomAPI_PlanarEdges::isPlanar() const
94 {
95   return true;
96 }
97
98 void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
99                                    const std::shared_ptr<GeomAPI_Dir>& theDirX,
100                                    const std::shared_ptr<GeomAPI_Dir>& theNorm)
101 {
102   myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theNorm));
103 }
104
105 bool GeomAPI_PlanarEdges::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
106 {
107   if (!theShape.get())
108     return false;
109   TopoDS_Shape& aMyShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
110   TopoDS_Shape aTheShape = theShape->impl<TopoDS_Shape>();
111   TopExp_Explorer aMyExp(aMyShape, TopAbs_EDGE);
112   TopExp_Explorer aTheExp(aTheShape, TopAbs_EDGE);
113   for (; aMyExp.More() && aTheExp.More(); aMyExp.Next(), aTheExp.Next()) {
114     // check that edge by edge all geometrically matches
115     std::shared_ptr<GeomAPI_Edge> aMyEdge(new GeomAPI_Edge);
116     aMyEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aMyExp.Current()));
117     std::shared_ptr<GeomAPI_Edge> aTheEdge(new GeomAPI_Edge);
118     aTheEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aTheExp.Current()));
119     if (!aMyEdge->isEqual(aTheEdge))
120       return false;
121   }
122   return !(aMyExp.More() || aTheExp.More());
123 }