try to convert non-b-splines into b-splines; further parameter check

Non b-spline curves are converted into b-splines if possible.
This means circles, lines etc are allowed.

Further parameter checks prohibiting surfaces being accepted as input.
This commit is contained in:
balazs-bamer
2015-02-06 13:04:24 +01:00
committed by wmayer
parent 85c3aa10c1
commit 4e2eede777
2 changed files with 31 additions and 10 deletions

View File

@@ -35,6 +35,8 @@
#include <Standard_ConstructionError.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <GeomFill.hxx>
#include <BRepBuilderAPI_NurbsConvert.hxx>
#include <StdFail_NotDone.hxx>
#endif
#include <Base/Tools.h>
@@ -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());

View File

@@ -190,6 +190,12 @@ bool CmdSurfaceBSurf::isActive(void)
}
Part::TopoShape ts = static_cast<Part::Feature*>((*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;