SketchObject:ModifyBSplineKnotMultiplicity re

written to use THROW macro and CADKernelError exception
This commit is contained in:
Abdullah Tahiri
2017-05-09 00:16:00 +02:00
committed by wmayer
parent 053300cfa1
commit 51e90dd52b
2 changed files with 14 additions and 9 deletions

View File

@@ -4099,32 +4099,32 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m
#endif
if (GeoId < 0 || GeoId > getHighestCurveIndex())
throw Base::ValueError("BSpline GeoId is out of bounds.");
THROWM(Base::ValueError,"BSpline GeoId is out of bounds.")
if (multiplicityincr == 0) // no change in multiplicity
throw Base::ValueError("You are requesting no change in knot multiplicity.");
THROWM(Base::ValueError,"You are requesting no change in knot multiplicity.")
const Part::Geometry *geo = getGeometry(GeoId);
if(geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId())
throw Base::TypeError("The GeoId provided is not a B-spline curve");
THROWM(Base::TypeError,"The GeoId provided is not a B-spline curve.");
const Part::GeomBSplineCurve *bsp = static_cast<const Part::GeomBSplineCurve *>(geo);
int degree = bsp->getDegree();
if( knotIndex > bsp->countKnots() || knotIndex < 1 ) // knotindex in OCC 1 -> countKnots
throw Base::ValueError("The knot index is out of bounds. Note that in accordance with OCC notation, the first knot has index 1 and not zero.");
THROWM(Base::ValueError,"The knot index is out of bounds. Note that in accordance with OCC notation, the first knot has index 1 and not zero.");
Part::GeomBSplineCurve *bspline;
int curmult = bsp->getMultiplicity(knotIndex);
if ( (curmult + multiplicityincr) > degree ) // zero is removing the knot, degree is just positional continuity
throw Base::ValueError("The multiplicity cannot be increased beyond the degree of the b-spline.");
THROWM(Base::ValueError,"The multiplicity cannot be increased beyond the degree of the b-spline.");
if ( (curmult + multiplicityincr) < 0) // zero is removing the knot, degree is just positional continuity
throw Base::ValueError("The multiplicity cannot be decreased beyond zero.");
THROWM(Base::ValueError,"The multiplicity cannot be decreased beyond zero.");
try {
@@ -4137,7 +4137,7 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m
bool result = bspline->removeKnot(knotIndex, curmult + multiplicityincr,1E6);
if(!result)
throw Base::RuntimeError("OCC is unable to decrease the multiplicity within the maximum tolerance.");
THROWM(Base::CADKernelError, "OCC is unable to decrease the multiplicity within the maximum tolerance.");
}
}
catch (const Base::Exception& e) {

View File

@@ -576,9 +576,14 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg)
// particularly B-spline GeoID might have changed.
}
catch (const Base::CADKernelError& e) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("CAD Kernel Error"),
QObject::tr(e.getMessage().c_str()));
getSelection().clearSelection();
}
catch (const Base::Exception& e) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Error"),
QObject::tr(getStrippedPythonExceptionString(e).c_str()));
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Input Error"),
QObject::tr(e.getMessage().c_str()));
getSelection().clearSelection();
}