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_Wire.h"
21 #include "GeomAPI_Pnt.h"
23 #include <BRep_Builder.hxx>
24 #include <BRepTools_WireExplorer.hxx>
25 #include <Geom_Line.hxx>
26 #include <Precision.hxx>
27 #include <Standard_Type.hxx>
29 #include <TopoDS_Wire.hxx>
31 //==================================================================================================
32 GeomAPI_Wire::GeomAPI_Wire()
34 TopoDS_Wire* aWire = new TopoDS_Wire();
36 BRep_Builder aBuilder;
37 aBuilder.MakeWire(*aWire);
42 //==================================================================================================
43 GeomAPI_Wire::GeomAPI_Wire(const std::shared_ptr<GeomAPI_Shape>& theShape)
45 if (!theShape->isNull() && theShape->isWire()) {
46 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
50 //==================================================================================================
51 bool GeomAPI_Wire::isClosed() const
53 return BRep_Tool::IsClosed(impl<TopoDS_Shape>());
56 //==================================================================================================
57 bool GeomAPI_Wire::isPolygon(std::list<GeomPointPtr>& thePoints) const
59 const TopoDS_Wire& aWire = TopoDS::Wire(impl<TopoDS_Shape>());
61 bool isPolygon = true;
62 const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line);
63 for (BRepTools_WireExplorer anExp(aWire); anExp.More() && isPolygon; anExp.Next()) {
64 const TopoDS_Edge& anEdge = anExp.Current();
66 Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2);
67 if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) {
68 gp_Pnt aCorner = BRep_Tool::Pnt(anExp.CurrentVertex());
69 thePoints.push_back(GeomPointPtr(new GeomAPI_Pnt(aCorner.X(), aCorner.Y(), aCorner.Z())));
80 //==================================================================================================
81 bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
85 const TopoDS_Wire& aWire = TopoDS::Wire(impl<TopoDS_Shape>());
86 const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line);
88 gp_XYZ aPrevDir(0, 0, 0);
90 for (BRepTools_WireExplorer anExp(aWire); anExp.More(); anExp.Next()) {
91 const TopoDS_Edge& anEdge = anExp.Current();
93 Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2);
94 if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) {
95 gp_Pnt aCorner = BRep_Tool::Pnt(anExp.CurrentVertex());
96 thePoints.push_back(GeomPointPtr(new GeomAPI_Pnt(aCorner.X(), aCorner.Y(), aCorner.Z())));
101 if (thePoints.size() > 4)
104 // collect length of the edge
105 gp_Pnt aStart = aC3D->Value(aT1);
106 gp_Pnt aEnd = aC3D->Value(aT2);
108 if (aStart.Distance(aEnd) <= Precision::Confusion())
111 // check the edge is orthogonal to the previous
112 gp_XYZ aCurDir = (aEnd.XYZ() - aStart.XYZ()).Normalized();
113 if (aPrevDir.Dot(aCurDir) < Precision::Confusion())
121 //==================================================================================================
122 GeomPointPtr GeomAPI_Wire::middlePoint() const
124 // find middle edge in the wire
125 std::list<GeomShapePtr> aSubs = subShapes(EDGE);
126 size_t aNbSubs = aSubs.size();
128 return GeomPointPtr();
131 for (; aNbSubs > 0; --aNbSubs)
134 // compute middle point on the middle edge
135 return aSubs.front()->middlePoint();