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_Wire.h"
22 #include "GeomAPI_Pnt.h"
24 #include <BRep_Builder.hxx>
25 #include <BRepTools_WireExplorer.hxx>
26 #include <Geom_Line.hxx>
27 #include <Precision.hxx>
28 #include <Standard_Type.hxx>
30 #include <TopoDS_Wire.hxx>
32 //==================================================================================================
33 GeomAPI_Wire::GeomAPI_Wire()
35 TopoDS_Wire* aWire = new TopoDS_Wire();
37 BRep_Builder aBuilder;
38 aBuilder.MakeWire(*aWire);
43 //==================================================================================================
44 GeomAPI_Wire::GeomAPI_Wire(const std::shared_ptr<GeomAPI_Shape>& theShape)
46 if (!theShape->isNull() && theShape->isWire()) {
47 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
51 //==================================================================================================
52 bool GeomAPI_Wire::isClosed() const
54 return BRep_Tool::IsClosed(impl<TopoDS_Shape>());
57 //==================================================================================================
58 bool GeomAPI_Wire::isPolygon(std::list<GeomPointPtr>& thePoints) const
60 const TopoDS_Wire& aWire = TopoDS::Wire(impl<TopoDS_Shape>());
62 bool isPolygon = true;
63 const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line);
64 for (BRepTools_WireExplorer anExp(aWire); anExp.More() && isPolygon; anExp.Next()) {
65 const TopoDS_Edge& anEdge = anExp.Current();
67 Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2);
68 if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) {
69 gp_Pnt aCorner = BRep_Tool::Pnt(anExp.CurrentVertex());
70 thePoints.push_back(GeomPointPtr(new GeomAPI_Pnt(aCorner.X(), aCorner.Y(), aCorner.Z())));
81 //==================================================================================================
82 bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
84 const TopoDS_Wire& aWire = TopoDS::Wire(impl<TopoDS_Shape>());
85 const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line);
87 gp_XYZ aPrevDir(0, 0, 0);
89 for (BRepTools_WireExplorer anExp(aWire); anExp.More(); anExp.Next()) {
90 const TopoDS_Edge& anEdge = anExp.Current();
92 Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2);
93 if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) {
94 gp_Pnt aCorner = BRep_Tool::Pnt(anExp.CurrentVertex());
95 thePoints.push_back(GeomPointPtr(new GeomAPI_Pnt(aCorner.X(), aCorner.Y(), aCorner.Z())));
100 if (thePoints.size() > 4)
103 // collect length of the edge
104 gp_Pnt aStart = aC3D->Value(aT1);
105 gp_Pnt aEnd = aC3D->Value(aT2);
107 // check the edge is orthogonal to the previous
108 gp_XYZ aCurDir = (aEnd.XYZ() - aStart.XYZ()).Normalized();
109 if (aPrevDir.Dot(aCurDir) < Precision::Confusion())