1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <GeomAPI_Interface.h>
21 #include <GeomAPI_PlanarEdges.h>
23 #include <Standard_TypeDef.hxx>
24 #include <TopAbs_ShapeEnum.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Wire.hxx>
29 #include <BRep_Builder.hxx>
30 #include <BRepTools_WireExplorer.hxx>
31 #include <TopExp_Explorer.hxx>
35 GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
37 TopoDS_Compound aBigWireImpl;
38 BRep_Builder aBuilder;
39 aBuilder.MakeCompound(aBigWireImpl);
40 this->setImpl(new TopoDS_Shape(aBigWireImpl));
43 void GeomAPI_PlanarEdges::addEdge(std::shared_ptr<GeomAPI_Shape> theEdge)
45 const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
46 if (anEdge.ShapeType() != TopAbs_EDGE)
48 TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
49 BRep_Builder aBuilder;
50 aBuilder.Add(aWire, anEdge);
53 std::list<std::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
55 TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
56 TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
57 std::list<std::shared_ptr<GeomAPI_Shape> > aResult;
58 for (; aWireExp.More(); aWireExp.Next()) {
59 std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
60 anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
61 aResult.push_back(anEdge);
66 bool GeomAPI_PlanarEdges::hasPlane() const {
67 return myPlane.get() != NULL;
70 bool GeomAPI_PlanarEdges::isVertex() const {
74 bool GeomAPI_PlanarEdges::isEdge() const {
78 std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const
81 return myPlane->origin();
82 return std::shared_ptr<GeomAPI_Pnt>();
85 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const
88 return myPlane->dirX();
89 return std::shared_ptr<GeomAPI_Dir>();
92 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const
95 return myPlane->dirY();
96 return std::shared_ptr<GeomAPI_Dir>();
99 std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const
102 return myPlane->normal();
103 return std::shared_ptr<GeomAPI_Dir>();
106 bool GeomAPI_PlanarEdges::isPlanar() const
111 void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
112 const std::shared_ptr<GeomAPI_Dir>& theDirX,
113 const std::shared_ptr<GeomAPI_Dir>& theNorm)
115 myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theNorm));
118 bool GeomAPI_PlanarEdges::isEqual(const std::shared_ptr<GeomAPI_Shape> theShape) const
122 TopoDS_Shape& aMyShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
123 TopoDS_Shape aTheShape = theShape->impl<TopoDS_Shape>();
124 if (aMyShape.ShapeType() != aTheShape.ShapeType()) // to don't confuse by the face of same edges
126 TopExp_Explorer aMyExp(aMyShape, TopAbs_EDGE);
127 TopExp_Explorer aTheExp(aTheShape, TopAbs_EDGE);
128 for (; aMyExp.More() && aTheExp.More(); aMyExp.Next(), aTheExp.Next()) {
129 // check that edge by edge all geometrically matches
130 std::shared_ptr<GeomAPI_Edge> aMyEdge(new GeomAPI_Edge);
131 aMyEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aMyExp.Current()));
132 std::shared_ptr<GeomAPI_Edge> aTheEdge(new GeomAPI_Edge);
133 aTheEdge->setImpl<TopoDS_Shape>(new TopoDS_Shape(aTheExp.Current()));
134 if (!aMyEdge->isEqual(aTheEdge))
137 return !(aMyExp.More() || aTheExp.More());