diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 0dbc91777e..26b07751d4 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -1266,39 +1266,7 @@ BSpline::BSpline(const TopoDS_Edge &e) // if len(first-last) == sum(len(pi - pi+1)) then it is a line bool BSpline::isLine() { - BRepAdaptor_Curve c(occEdge); - - Handle(Geom_BSplineCurve) spline = c.BSpline(); - double f = c.FirstParameter(); - double l = c.LastParameter(); - gp_Pnt s = c.Value(f); - gp_Pnt e = c.Value(l); - - bool samePnt = s.IsEqual(e, FLT_EPSILON); - if (samePnt) { - return false; - } - - Base::Vector3d vs = DrawUtil::toVector3d(s); - Base::Vector3d ve = DrawUtil::toVector3d(e); - double endLength = (vs - ve).Length(); - int low = 0; - int high = spline->NbPoles() - 1; - TColgp_Array1OfPnt poles(low, high); - spline->Poles(poles); - double lenTotal = 0.0; - for (int i = 0; i < high; i++) { - gp_Pnt p1 = poles(i); - Base::Vector3d v1 = DrawUtil::toVector3d(p1); - gp_Pnt p2 = poles(i+1); - Base::Vector3d v2 = DrawUtil::toVector3d(p2); - lenTotal += (v2-v1).Length(); - } - - if (DrawUtil::fpCompare(lenTotal, endLength)) { - return true; - } - return false; + return GeometryUtils::isLine(occEdge); } //used by DVDim for approximate dims @@ -1802,3 +1770,40 @@ TopoDS_Edge GeometryUtils::asCircle(TopoDS_Edge occEdge, bool& arc) } return result; } + +bool GeometryUtils::isLine(TopoDS_Edge occEdge) +{ + BRepAdaptor_Curve c(occEdge); + + Handle(Geom_BSplineCurve) spline = c.BSpline(); + double f = c.FirstParameter(); + double l = c.LastParameter(); + gp_Pnt s = c.Value(f); + gp_Pnt e = c.Value(l); + + bool samePnt = s.IsEqual(e, FLT_EPSILON); + if (samePnt) { + return false; + } + + Base::Vector3d vs = DrawUtil::toVector3d(s); + Base::Vector3d ve = DrawUtil::toVector3d(e); + double endLength = (vs - ve).Length(); + int low = 0; + int high = spline->NbPoles() - 1; + TColgp_Array1OfPnt poles(low, high); + spline->Poles(poles); + double lenTotal = 0.0; + for (int i = 0; i < high; i++) { + gp_Pnt p1 = poles(i); + Base::Vector3d v1 = DrawUtil::toVector3d(p1); + gp_Pnt p2 = poles(i+1); + Base::Vector3d v2 = DrawUtil::toVector3d(p2); + lenTotal += (v2-v1).Length(); + } + + if (DrawUtil::fpCompare(lenTotal, endLength)) { + return true; + } + return false; +} diff --git a/src/Mod/TechDraw/App/Geometry.h b/src/Mod/TechDraw/App/Geometry.h index 606409dd9a..ff13526280 100644 --- a/src/Mod/TechDraw/App/Geometry.h +++ b/src/Mod/TechDraw/App/Geometry.h @@ -435,6 +435,7 @@ class TechDrawExport GeometryUtils static bool isCircle(TopoDS_Edge occEdge); static bool getCircleParms(TopoDS_Edge occEdge, double& radius, Base::Vector3d& center, bool& isArc); static TopoDS_Edge asCircle(TopoDS_Edge occEdge, bool& arc); + static bool isLine(TopoDS_Edge occEdge); }; } //end namespace TechDraw