diff --git a/src/Mod/Surface/App/FeatureBSplineSurf.cpp b/src/Mod/Surface/App/FeatureBSplineSurf.cpp index cc16f8dea8..8d67c97e62 100644 --- a/src/Mod/Surface/App/FeatureBSplineSurf.cpp +++ b/src/Mod/Surface/App/FeatureBSplineSurf.cpp @@ -35,6 +35,8 @@ #include #include #include +#include +#include #endif #include @@ -70,9 +72,9 @@ App::DocumentObjectExecReturn *BSplineSurf::execute(void) TopExp_Explorer anExp (aWire, TopAbs_EDGE); int it = 0; for (; anExp.More(); anExp.Next()) { - const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current()); + const TopoDS_Edge& edge = TopoDS::Edge (anExp.Current()); TopLoc_Location heloc; // this will be output - Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge, heloc, u1, u2); //The geometric curve + Handle_Geom_Curve c_geom = BRep_Tool::Curve(edge, heloc, u1, u2); //The geometric curve Handle_Geom_BSplineCurve b_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve if (!b_geom.IsNull()) { @@ -82,7 +84,23 @@ App::DocumentObjectExecReturn *BSplineSurf::execute(void) crvs[it] = b_geom; } else { - Standard_Failure::Raise("Curve not a BSpline Curve"); + // try to convert it into a b-spline + BRepBuilderAPI_NurbsConvert mkNurbs(edge); + TopoDS_Edge nurbs = TopoDS::Edge(mkNurbs.Shape()); + // avoid copying + TopLoc_Location heloc2; // this will be output + Handle_Geom_Curve c_geom2 = BRep_Tool::Curve(nurbs, heloc2, u1, u2); //The geometric curve + Handle_Geom_BSplineCurve b_geom2 = Handle_Geom_BSplineCurve::DownCast(c_geom2); //Try to get BSpline curve + + if (!b_geom2.IsNull()) { + gp_Trsf transf = heloc2.Transformation(); + b_geom2->Transform(transf); // apply original transformation to control points + //Store Underlying Geometry + crvs[it] = b_geom2; + } + else { + Standard_Failure::Raise("A curve was not a b-spline and could not be converted into one."); + } } it++; } @@ -103,6 +121,9 @@ App::DocumentObjectExecReturn *BSplineSurf::execute(void) // message is in a Latin language, show a normal one return new App::DocumentObjectExecReturn("Curves are disjoint."); } + catch(StdFail_NotDone) { + return new App::DocumentObjectExecReturn("A curve was not a b-spline and could not be converted into one."); + } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index d83ecaf7c8..6794f3a33d 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -190,6 +190,12 @@ bool CmdSurfaceBSurf::isActive(void) } Part::TopoShape ts = static_cast((*it).pObject)->Shape.getShape(); try { + // make sure the main shape type is edge or wire + TopAbs_ShapeEnum shapeType = ts._Shape.ShapeType(); + if(shapeType != TopAbs_WIRE && shapeType != TopAbs_EDGE) + { + return false; + } TopoDS_Shape shape = ts.getSubShape("Edge1"); if (shape.IsNull()) { @@ -206,13 +212,7 @@ bool CmdSurfaceBSurf::isActive(void) Handle_Geom_BezierCurve bez_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve if (bez_geom.IsNull()) { - // this one is not Bezier - Handle_Geom_BSplineCurve bsp_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve - if (bsp_geom.IsNull()) { - // neither Bezier, nor b-spline, fail - return false; - } - // this one is b-spline + // this one is not Bezier, we hope it can be converted into b-spline if(willBezier) { // already found the other type, fail return false;