1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAPI_Interface.h>
22 #include <GeomAPI_PlanarEdges.h>
24 #include <Standard_TypeDef.hxx>
25 #include <TopAbs_ShapeEnum.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>
36 GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
38 TopoDS_Compound aBigWireImpl;
39 BRep_Builder aBuilder;
40 aBuilder.MakeCompound(aBigWireImpl);
41 this->setImpl(new TopoDS_Shape(aBigWireImpl));
44 void GeomAPI_PlanarEdges::addEdge(std::shared_ptr<GeomAPI_Shape> theEdge)
46 const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
47 if (anEdge.ShapeType() != TopAbs_EDGE)
49 TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
50 BRep_Builder aBuilder;
51 aBuilder.Add(aWire, anEdge);
54 std::list<std::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
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);
67 bool GeomAPI_PlanarEdges::hasPlane() const {
68 return myPlane.get() != NULL;
71 bool GeomAPI_PlanarEdges::isVertex() const {
75 bool GeomAPI_PlanarEdges::isEdge() const {
79 std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const
82 return myPlane->origin();
83 return std::shared_ptr<GeomAPI_Pnt>();
86 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const
89 return myPlane->dirX();
90 return std::shared_ptr<GeomAPI_Dir>();
93 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const
96 return myPlane->dirY();
97 return std::shared_ptr<GeomAPI_Dir>();
100 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const
103 return myPlane->normal();
104 return std::shared_ptr<GeomAPI_Dir>();
107 bool GeomAPI_PlanarEdges::isPlanar() const
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)
116 myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theNorm));
119 bool GeomAPI_PlanarEdges::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
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))
136 return !(aMyExp.More() || aTheExp.More());