- TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
- BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
- std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
- for (; aWireExp.More(); aWireExp.Next()) {
- boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
- anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
- aResult.push_back(anEdge);
+ thePoints.clear();
+
+ const TopoDS_Wire& aWire = TopoDS::Wire(impl<TopoDS_Shape>());
+ const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line);
+
+ gp_XYZ aPrevDir(0, 0, 0);
+
+ for (BRepTools_WireExplorer anExp(aWire); anExp.More(); anExp.Next()) {
+ const TopoDS_Edge& anEdge = anExp.Current();
+ double aT1, aT2;
+ Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2);
+ if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) {
+ gp_Pnt aCorner = BRep_Tool::Pnt(anExp.CurrentVertex());
+ thePoints.push_back(GeomPointPtr(new GeomAPI_Pnt(aCorner.X(), aCorner.Y(), aCorner.Z())));
+ }
+ else
+ return false;
+
+ if (thePoints.size() > 4)
+ return false;
+
+ // collect length of the edge
+ gp_Pnt aStart = aC3D->Value(aT1);
+ gp_Pnt aEnd = aC3D->Value(aT2);
+
+ // check the edge is orthogonal to the previous
+ gp_XYZ aCurDir = (aEnd.XYZ() - aStart.XYZ()).Normalized();
+ if (aPrevDir.Dot(aCurDir) < Precision::Confusion())
+ aPrevDir = aCurDir;
+ else
+ return false;