]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAPI/GeomAPI_PlanarEdges.cpp
Salome HOME
Fix for the issue #2401
[modules/shaper.git] / src / GeomAPI / GeomAPI_PlanarEdges.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <GeomAPI_Interface.h>
22 #include <GeomAPI_PlanarEdges.h>
23
24 #include <Standard_TypeDef.hxx>
25 #include <TopAbs_ShapeEnum.hxx>
26
27 #include <TopoDS.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <BRep_Builder.hxx>
31 #include <BRepTools_WireExplorer.hxx>
32 #include <TopExp_Explorer.hxx>
33
34 #include <list>
35
36 GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
37 {
38   TopoDS_Compound aBigWireImpl;
39   BRep_Builder aBuilder;
40   aBuilder.MakeCompound(aBigWireImpl);
41   this->setImpl(new TopoDS_Shape(aBigWireImpl));
42 }
43
44 void GeomAPI_PlanarEdges::addEdge(std::shared_ptr<GeomAPI_Shape> theEdge)
45 {
46   const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
47   if (anEdge.ShapeType() != TopAbs_EDGE)
48     return;
49   TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
50   BRep_Builder aBuilder;
51   aBuilder.Add(aWire, anEdge);
52 }
53
54 std::list<std::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
55 {
56   TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
57   TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
58   std::list<std::shared_ptr<GeomAPI_Shape> > aResult;
59   for (; aWireExp.More(); aWireExp.Next()) {
60     std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
61     anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
62     aResult.push_back(anEdge);
63   }
64   return aResult;
65 }
66
67 bool GeomAPI_PlanarEdges::hasPlane() const {
68   return myPlane.get() != NULL;
69 }
70
71 bool GeomAPI_PlanarEdges::isVertex() const {
72   return false;
73 }
74
75 bool GeomAPI_PlanarEdges::isEdge() const {
76   return false;
77 }
78
79 std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const
80 {
81   if (hasPlane())
82     return myPlane->origin();
83   return std::shared_ptr<GeomAPI_Pnt>();
84 }
85
86 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const
87 {
88   if (hasPlane())
89     return myPlane->dirX();
90   return std::shared_ptr<GeomAPI_Dir>();
91 }
92
93 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const
94 {
95   if (hasPlane())
96     return myPlane->dirY();
97   return std::shared_ptr<GeomAPI_Dir>();
98 }
99
100 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const
101 {
102   if (hasPlane())
103     return myPlane->normal();
104   return std::shared_ptr<GeomAPI_Dir>();
105 }
106
107 bool GeomAPI_PlanarEdges::isPlanar() const
108 {
109   return true;
110 }
111
112 void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
113                                    const std::shared_ptr<GeomAPI_Dir>& theDirX,
114                                    const std::shared_ptr<GeomAPI_Dir>& theNorm)
115 {
116   myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theNorm));
117 }
118
119 bool GeomAPI_PlanarEdges::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
120 {
121   if (!theShape.get())
122     return false;
123   TopoDS_Shape& aMyShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
124   TopoDS_Shape aTheShape = theShape->impl<TopoDS_Shape>();
125   TopExp_Explorer aMyExp(aMyShape, TopAbs_EDGE);
126   TopExp_Explorer aTheExp(aTheShape, TopAbs_EDGE);
127   for (; aMyExp.More() && aTheExp.More(); aMyExp.Next(), aTheExp.Next()) {
128     // check that edge by edge all geometrically matches
129     std::shared_ptr<GeomAPI_Edge> aMyEdge(new GeomAPI_Edge);
130     aMyEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aMyExp.Current()));
131     std::shared_ptr<GeomAPI_Edge> aTheEdge(new GeomAPI_Edge);
132     aTheEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aTheExp.Current()));
133     if (!aMyEdge->isEqual(aTheEdge))
134       return false;
135   }
136   return !(aMyExp.More() || aTheExp.More());
137 }