Replace Base::Exception with appropriate subclass

This commit is contained in:
wmayer
2018-11-14 19:28:00 +01:00
parent 21d01fe6fc
commit 00de5bb7ad
23 changed files with 116 additions and 115 deletions

View File

@@ -266,7 +266,7 @@ Body* Body::findBodyOf(const App::DocumentObject* feature)
std::vector<App::DocumentObject*> Body::addObject(App::DocumentObject *feature)
{
if(!isAllowed(feature))
throw Base::Exception("Body: object is not allowed");
throw Base::ValueError("Body: object is not allowed");
//TODO: features should not add all links
@@ -299,7 +299,7 @@ std::vector< App::DocumentObject* > Body::addObjects(std::vector< App::DocumentO
void Body::insertObject(App::DocumentObject* feature, App::DocumentObject* target, bool after)
{
if (target && !hasObject (target)) {
throw Base::Exception("Body: the feature we should insert relative to is not part of that body");
throw Base::ValueError("Body: the feature we should insert relative to is not part of that body");
}
//ensure that all origin links are ok

View File

@@ -106,7 +106,7 @@ const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f)
// TODO: Other method, e.g. intersect X,Y,Z axis with the (unlimited?) face?
// Or get a "corner" point if the face is limited?
throw Base::Exception("getPointFromFace(): Not implemented yet for this case");
throw Base::NotImplementedError("getPointFromFace(): Not implemented yet for this case");
}
Part::Feature* Feature::getBaseObject(bool silent) const {
@@ -127,7 +127,7 @@ Part::Feature* Feature::getBaseObject(bool silent) const {
// If the function not in silent mode throw the exception describing the error
if (!silent && err) {
throw Base::Exception(err);
throw Base::RuntimeError(err);
}
return BaseObject;
@@ -142,10 +142,10 @@ const TopoDS_Shape& Feature::getBaseShape() const {
const TopoDS_Shape& result = BaseObject->Shape.getValue();
if (result.IsNull())
throw Base::Exception("Base feature's shape is invalid");
throw Base::ValueError("Base feature's shape is invalid");
TopExp_Explorer xp (result, TopAbs_SOLID);
if (!xp.More())
throw Base::Exception("Base feature's shape is not a solid");
throw Base::ValueError("Base feature's shape is not a solid");
return result;
}
@@ -159,7 +159,7 @@ const Part::TopoShape Feature::getBaseTopoShape() const {
const Part::TopoShape& result = BaseObject->Shape.getShape();
if (result.getShape().IsNull())
throw Base::Exception("Base feature's TopoShape is invalid");
throw Base::ValueError("Base feature's TopoShape is invalid");
return result;
}
@@ -183,7 +183,7 @@ gp_Pln Feature::makePlnFromPlane(const App::DocumentObject* obj)
{
const App::GeoFeature* plane = static_cast<const App::GeoFeature*>(obj);
if (plane == NULL)
throw Base::Exception("Feature: Null object");
throw Base::ValueError("Feature: Null object");
Base::Vector3d pos = plane->Placement.getValue().getPosition();
Base::Rotation rot = plane->Placement.getValue().getRotation();
@@ -196,7 +196,7 @@ TopoDS_Shape Feature::makeShapeFromPlane(const App::DocumentObject* obj)
{
BRepBuilderAPI_MakeFace builder(makePlnFromPlane(obj));
if (!builder.IsDone())
throw Base::Exception("Feature: Could not create shape from base plane");
throw Base::CADKernelError("Feature: Could not create shape from base plane");
return builder.Shape();
}

View File

@@ -118,7 +118,7 @@ App::DocumentObjectExecReturn *Draft::execute(void)
} else if (refDirection->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
std::vector<std::string> subStrings = PullDirection.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No pull direction reference specified");
throw Base::ValueError("No pull direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refDirection);
Part::TopoShape refShape = refFeature->Shape.getShape();
@@ -127,17 +127,17 @@ App::DocumentObjectExecReturn *Draft::execute(void)
if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract pull direction reference edge");
throw Base::ValueError("Failed to extract pull direction reference edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Pull direction reference edge must be linear");
throw Base::TypeError("Pull direction reference edge must be linear");
pullDirection = adapt.Line().Direction();
} else {
throw Base::Exception("Pull direction reference must be an edge or a datum line");
throw Base::TypeError("Pull direction reference must be an edge or a datum line");
}
} else {
throw Base::Exception("Pull direction reference must be an edge of a feature or a datum line");
throw Base::TypeError("Pull direction reference must be an edge of a feature or a datum line");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
@@ -193,7 +193,7 @@ App::DocumentObjectExecReturn *Draft::execute(void)
}
if (!found)
throw Base::Exception("No neutral plane specified and none can be guessed");
throw Base::RuntimeError("No neutral plane specified and none can be guessed");
} else {
if (refPlane->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(refPlane);
@@ -205,7 +205,7 @@ App::DocumentObjectExecReturn *Draft::execute(void)
} else if (refPlane->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
std::vector<std::string> subStrings = NeutralPlane.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No neutral plane reference specified");
throw Base::ValueError("No neutral plane reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refPlane);
Part::TopoShape refShape = refFeature->Shape.getShape();
@@ -214,10 +214,10 @@ App::DocumentObjectExecReturn *Draft::execute(void)
if (ref.ShapeType() == TopAbs_FACE) {
TopoDS_Face refFace = TopoDS::Face(ref);
if (refFace.IsNull())
throw Base::Exception("Failed to extract neutral plane reference face");
throw Base::ValueError("Failed to extract neutral plane reference face");
BRepAdaptor_Surface adapt(refFace);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Neutral plane reference face must be planar");
throw Base::TypeError("Neutral plane reference face must be planar");
neutralPlane = adapt.Plane();
} else if (ref.ShapeType() == TopAbs_EDGE) {
@@ -225,22 +225,22 @@ App::DocumentObjectExecReturn *Draft::execute(void)
// Create neutral plane through edge normal to pull direction
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract neutral plane reference edge");
throw Base::ValueError("Failed to extract neutral plane reference edge");
BRepAdaptor_Curve c(refEdge);
if (c.GetType() != GeomAbs_Line)
throw Base::Exception("Neutral plane reference edge must be linear");
throw Base::TypeError("Neutral plane reference edge must be linear");
double a = c.Line().Angle(gp_Lin(c.Value(c.FirstParameter()), pullDirection));
if (std::fabs(a - M_PI_2) > Precision::Confusion())
throw Base::Exception("Neutral plane reference edge must be normal to pull direction");
throw Base::ValueError("Neutral plane reference edge must be normal to pull direction");
neutralPlane = gp_Pln(c.Value(c.FirstParameter()), pullDirection);
} else {
throw Base::Exception("Neutral plane reference can only be an edge if pull direction is defined");
throw Base::TypeError("Neutral plane reference can only be an edge if pull direction is defined");
}
} else {
throw Base::Exception("Neutral plane reference must be a face");
throw Base::TypeError("Neutral plane reference must be a face");
}
} else {
throw Base::Exception("Neutral plane reference must be face of a feature or a datum plane");
throw Base::TypeError("Neutral plane reference must be face of a feature or a datum plane");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();

View File

@@ -84,7 +84,7 @@ Part::Feature *DressUp::getBaseObject(bool silent) const
}
if (!silent && err) {
throw Base::Exception(err);
throw Base::RuntimeError(err);
}
return rv;

View File

@@ -150,7 +150,7 @@ App::DocumentObjectExecReturn *Groove::execute(void)
BRepAlgoAPI_Cut mkCut(base, result);
// Let's check if the fusion has been successful
if (!mkCut.IsDone())
throw Base::Exception("Cut out of base feature failed");
throw Base::CADKernelError("Cut out of base feature failed");
// we have to get the solids (fuse sometimes creates compounds)
TopoDS_Shape solRes = this->getSolid(mkCut.Shape());

View File

@@ -71,21 +71,21 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
{
double distance = Length.getValue();
if (distance < Precision::Confusion())
throw Base::Exception("Pattern length too small");
throw Base::ValueError("Pattern length too small");
int occurrences = Occurrences.getValue();
if (occurrences < 2)
throw Base::Exception("At least two occurrences required");
throw Base::ValueError("At least two occurrences required");
bool reversed = Reversed.getValue();
double offset = distance / (occurrences - 1);
App::DocumentObject* refObject = Direction.getValue();
if (refObject == NULL)
throw Base::Exception("No direction reference specified");
throw Base::ValueError("No direction reference specified");
std::vector<std::string> subStrings = Direction.getSubValues();
if (subStrings.empty())
throw Base::Exception("No direction reference specified");
throw Base::ValueError("No direction reference specified");
gp_Dir dir;
if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
@@ -107,10 +107,10 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract direction edge");
throw Base::ValueError("Failed to extract direction edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Direction edge must be a straight line");
throw Base::TypeError("Direction edge must be a straight line");
gp_Pnt p = adapt.Line().Location();
gp_Dir d = adapt.Line().Direction();
@@ -135,7 +135,7 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (subStrings[0].empty())
throw Base::Exception("No direction reference specified");
throw Base::ValueError("No direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
@@ -143,26 +143,26 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
if (ref.ShapeType() == TopAbs_FACE) {
TopoDS_Face refFace = TopoDS::Face(ref);
if (refFace.IsNull())
throw Base::Exception("Failed to extract direction plane");
throw Base::ValueError("Failed to extract direction plane");
BRepAdaptor_Surface adapt(refFace);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Direction face must be planar");
throw Base::TypeError("Direction face must be planar");
dir = adapt.Plane().Axis().Direction();
} else if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract direction edge");
throw Base::ValueError("Failed to extract direction edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Direction edge must be a straight line");
throw Base::ValueError("Direction edge must be a straight line");
dir = adapt.Line().Direction();
} else {
throw Base::Exception("Direction reference must be edge or face");
throw Base::ValueError("Direction reference must be edge or face");
}
} else {
throw Base::Exception("Direction reference must be edge/face of a feature or a datum line/plane");
throw Base::ValueError("Direction reference must be edge/face of a feature or a datum line/plane");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
dir.Transform(invObjLoc.Transformation());

View File

@@ -61,10 +61,10 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
{
App::DocumentObject* refObject = MirrorPlane.getValue();
if (refObject == NULL)
throw Base::Exception("No mirror plane reference specified");
throw Base::ValueError("No mirror plane reference specified");
std::vector<std::string> subStrings = MirrorPlane.getSubValues();
if (subStrings.empty())
throw Base::Exception("No mirror plane reference specified");
throw Base::ValueError("No mirror plane reference specified");
gp_Pnt axbase;
gp_Dir axdir;
@@ -104,21 +104,21 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
axdir = gp_Dir(dir.x, dir.y, dir.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (subStrings[0].empty())
throw Base::Exception("No direction reference specified");
throw Base::ValueError("No direction reference specified");
Part::TopoShape baseShape = static_cast<Part::Feature*>(refObject)->Shape.getShape();
// TODO: Check for multiple mirror planes?
TopoDS_Shape shape = baseShape.getSubShape(subStrings[0].c_str());
TopoDS_Face face = TopoDS::Face(shape);
if (face.IsNull())
throw Base::Exception("Failed to extract mirror plane");
throw Base::ValueError("Failed to extract mirror plane");
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Mirror face must be planar");
throw Base::TypeError("Mirror face must be planar");
axbase = getPointFromFace(face);
axdir = adapt.Plane().Axis().Direction();
} else {
throw Base::Exception("Mirror plane reference must be a sketch axis, a face of a feature or a datum plane");
throw Base::ValueError("Mirror plane reference must be a sketch axis, a face of a feature or a datum plane");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();

View File

@@ -56,7 +56,7 @@ void MultiTransform::positionBySupport(void)
for (std::vector<App::DocumentObject*>::const_iterator f = transFeatures.begin();
f != transFeatures.end(); ++f) {
if (!((*f)->getTypeId().isDerivedFrom(PartDesign::Transformed::getClassTypeId())))
throw Base::Exception("Transformation features must be subclasses of Transformed");
throw Base::TypeError("Transformation features must be subclasses of Transformed");
PartDesign::Transformed* transFeature = static_cast<PartDesign::Transformed*>(*f);
transFeature->Placement.setValue(this->Placement.getValue());
@@ -102,7 +102,7 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
for (f = transFeatures.begin(); f != transFeatures.end(); ++f) {
if (!((*f)->getTypeId().isDerivedFrom(PartDesign::Transformed::getClassTypeId())))
throw Base::Exception("Transformation features must be subclasses of Transformed");
throw Base::TypeError("Transformation features must be subclasses of Transformed");
PartDesign::Transformed* transFeature = static_cast<PartDesign::Transformed*>(*f);
std::list<gp_Trsf> newTransformations = transFeature->getTransformations(originals);
@@ -131,9 +131,9 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
// oldTransformations vector
if (newTransformations.empty())
throw Base::Exception("Number of occurrences must be a divisor of previous number of occurrences");
throw Base::ValueError("Number of occurrences must be a divisor of previous number of occurrences");
if (oldTransformations.size() % newTransformations.size() != 0)
throw Base::Exception("Number of occurrences must be a divisor of previous number of occurrences");
throw Base::ValueError("Number of occurrences must be a divisor of previous number of occurrences");
unsigned sliceLength = oldTransformations.size() / newTransformations.size();
std::list<gp_Trsf>::const_iterator ot = oldTransformations.begin();

View File

@@ -470,10 +470,10 @@ void Pipe::buildPipePath(const Part::TopoShape& shape, const std::vector< std::s
TopoDS_Iterator it(shape.getShape());
for (; it.More(); it.Next()) {
if (it.Value().IsNull())
throw Base::Exception("In valid element in spine.");
throw Base::ValueError("In valid element in spine.");
if ((it.Value().ShapeType() != TopAbs_EDGE) &&
(it.Value().ShapeType() != TopAbs_WIRE)) {
throw Base::Exception("Element in spine is neither an edge nor a wire.");
throw Base::TypeError("Element in spine is neither an edge nor a wire.");
}
}
@@ -485,15 +485,15 @@ void Pipe::buildPipePath(const Part::TopoShape& shape, const std::vector< std::s
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, Precision::Confusion(), Standard_True, hWires);
int len = hWires->Length();
if (len != 1)
throw Base::Exception("Spine is not connected.");
throw Base::ValueError("Spine is not connected.");
path = hWires->Value(1);
}
else {
throw Base::Exception("Spine is neither an edge nor a wire.");
throw Base::TypeError("Spine is neither an edge nor a wire.");
}
}
catch (Standard_Failure&) {
throw Base::Exception("Invalid spine.");
throw Base::CADKernelError("Invalid spine.");
}
}
}

View File

@@ -69,10 +69,10 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
{
double angle = Angle.getValue();
if (angle < Precision::Confusion())
throw Base::Exception("Pattern angle too small");
throw Base::ValueError("Pattern angle too small");
int occurrences = Occurrences.getValue();
if (occurrences < 2)
throw Base::Exception("At least two occurrences required");
throw Base::ValueError("At least two occurrences required");
bool reversed = Reversed.getValue();
double offset;
@@ -83,10 +83,10 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
App::DocumentObject* refObject = Axis.getValue();
if (refObject == NULL)
throw Base::Exception("No axis reference specified");
throw Base::ValueError("No axis reference specified");
std::vector<std::string> subStrings = Axis.getSubValues();
if (subStrings.empty())
throw Base::Exception("No axis reference specified");
throw Base::ValueError("No axis reference specified");
gp_Pnt axbase;
gp_Dir axdir;
@@ -121,7 +121,7 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
axdir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (subStrings[0].empty())
throw Base::Exception("No axis reference specified");
throw Base::ValueError("No axis reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
@@ -129,18 +129,18 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract axis edge");
throw Base::ValueError("Failed to extract axis edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Axis edge must be a straight line");
throw Base::TypeError("Axis edge must be a straight line");
axbase = adapt.Value(adapt.FirstParameter());
axdir = adapt.Line().Direction();
} else {
throw Base::Exception("Axis reference must be an edge");
throw Base::TypeError("Axis reference must be an edge");
}
} else {
throw Base::Exception("Axis reference must be edge of a feature or datum line");
throw Base::TypeError("Axis reference must be edge of a feature or datum line");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
axbase.Transform(invObjLoc.Transformation());

View File

@@ -42,6 +42,7 @@
#include <Base/Placement.h>
#include <Base/Tools.h>
#include <Mod/Part/App/TopoShape.h>
#include "FeatureRevolution.h"
@@ -157,7 +158,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
BRepAlgoAPI_Fuse mkFuse(base, result);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
throw Base::Exception("Fusion with base feature failed");
throw Part::BooleanException("Fusion with base feature failed");
result = mkFuse.Shape();
result = refineShapeIfActive(result);
}

View File

@@ -60,10 +60,10 @@ const std::list<gp_Trsf> Scaled::getTransformations(const std::vector<App::Docum
{
double factor = Factor.getValue();
if (factor < Precision::Confusion())
throw Base::Exception("Scaling factor too small");
throw Base::ValueError("Scaling factor too small");
int occurrences = Occurrences.getValue();
if (occurrences < 2)
throw Base::Exception("At least two occurrences required");
throw Base::ValueError("At least two occurrences required");
double f = (factor - 1.0) / double(occurrences - 1);

View File

@@ -147,7 +147,7 @@ Part::Part2DObject* ProfileBased::getVerifiedSketch(bool silent) const {
}
if (!silent && err) {
throw Base::Exception (err);
throw Base::RuntimeError (err);
}
return static_cast<Part::Part2DObject*>(result);
@@ -166,7 +166,7 @@ Part::Feature* ProfileBased::getVerifiedObject(bool silent) const {
}
if (!silent && err) {
throw Base::Exception (err);
throw Base::RuntimeError (err);
}
return static_cast<Part::Feature*>(result);
@@ -214,7 +214,7 @@ TopoDS_Shape ProfileBased::getVerifiedFace(bool silent) const {
}
if (!silent && err) {
throw Base::Exception (err);
throw Base::RuntimeError (err);
}
return TopoDS_Face();
@@ -225,20 +225,20 @@ std::vector<TopoDS_Wire> ProfileBased::getProfileWires() const {
std::vector<TopoDS_Wire> result;
if(!Profile.getValue() || !Profile.getValue()->isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("No valid profile linked");
throw Base::TypeError("No valid profile linked");
TopoDS_Shape shape;
if(Profile.getValue()->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
shape = Profile.getValue<Part::Part2DObject*>()->Shape.getValue();
else {
if(Profile.getSubValues().empty())
throw Base::Exception("No valid subelement linked in Part::Feature");
throw Base::ValueError("No valid subelement linked in Part::Feature");
shape = Profile.getValue<Part::Feature*>()->Shape.getShape().getSubShape(Profile.getSubValues().front().c_str());
}
if (shape.IsNull())
throw Base::Exception("Linked shape object is empty");
throw Base::ValueError("Linked shape object is empty");
// this is a workaround for an obscure OCC bug which leads to empty tessellations
// for some faces. Making an explicit copy of the linked shape seems to fix it.
@@ -247,14 +247,14 @@ std::vector<TopoDS_Wire> ProfileBased::getProfileWires() const {
BRepBuilderAPI_Copy copy(shape);
shape = copy.Shape();
if (shape.IsNull())
throw Base::Exception("Linked shape object is empty");
throw Base::ValueError("Linked shape object is empty");
TopExp_Explorer ex;
for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
result.push_back(TopoDS::Wire(ex.Current()));
}
if (result.empty()) // there can be several wires
throw Base::Exception("Linked shape object is not a wire");
throw Base::ValueError("Linked shape object is not a wire");
return result;
}
@@ -281,19 +281,19 @@ const TopoDS_Face ProfileBased::getSupportFace() const {
// get the selected sub shape (a Face)
const Part::TopoShape &shape = part->Shape.getShape();
if (shape.getShape().IsNull())
throw Base::Exception("Sketch support shape is empty!");
throw Base::ValueError("Sketch support shape is empty!");
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());
if (sh.IsNull())
throw Base::Exception("Null shape in SketchBased::getSupportFace()!");
throw Base::ValueError("Null shape in SketchBased::getSupportFace()!");
const TopoDS_Face face = TopoDS::Face(sh);
if (face.IsNull())
throw Base::Exception("Null face in SketchBased::getSupportFace()!");
throw Base::ValueError("Null face in SketchBased::getSupportFace()!");
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("No planar face in SketchBased::getSupportFace()!");
throw Base::TypeError("No planar face in SketchBased::getSupportFace()!");
return face;
}
@@ -343,7 +343,7 @@ Part::Feature *ProfileBased::getBaseObject(bool silent) const
}
if (!silent && err) {
throw Base::Exception (err);
throw Base::RuntimeError (err);
}
return rv;
@@ -367,7 +367,7 @@ void ProfileBased::getUpToFaceFromLinkSub(TopoDS_Face& upToFace,
std::vector<std::string> subStrings = refFace.getSubValues();
if (ref == NULL)
throw Base::Exception("SketchBased: Up to face: No face selected");
throw Base::ValueError("SketchBased: Up to face: No face selected");
if (ref->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
upToFace = TopoDS::Face(makeShapeFromPlane(ref));
@@ -379,16 +379,16 @@ void ProfileBased::getUpToFaceFromLinkSub(TopoDS_Face& upToFace,
}
if (!ref->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("SketchBased: Up to face: Must be face of a feature");
throw Base::TypeError("SketchBased: Up to face: Must be face of a feature");
Part::TopoShape baseShape = static_cast<Part::Feature*>(ref)->Shape.getShape();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("SketchBased: Up to face: No face selected");
throw Base::ValueError("SketchBased: Up to face: No face selected");
// TODO: Check for multiple UpToFaces?
upToFace = TopoDS::Face(baseShape.getSubShape(subStrings[0].c_str()));
if (upToFace.IsNull())
throw Base::Exception("SketchBased: Up to face: Failed to extract face");
throw Base::ValueError("SketchBased: Up to face: Failed to extract face");
}
void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
@@ -402,11 +402,11 @@ void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
if ((method == "UpToLast") || (method == "UpToFirst")) {
// Check for valid support object
if (support.IsNull())
throw Base::Exception("SketchBased: Up to face: No support in Sketch and no base feature!");
throw Base::ValueError("SketchBased: Up to face: No support in Sketch and no base feature!");
std::vector<Part::cutFaces> cfaces = Part::findAllFacesCutBy(support, sketchshape, dir);
if (cfaces.empty())
throw Base::Exception("SketchBased: Up to face: No faces found in this direction");
throw Base::ValueError("SketchBased: Up to face: No faces found in this direction");
// Find nearest/furthest face
std::vector<Part::cutFaces>::const_iterator it, it_near, it_far;
@@ -464,7 +464,7 @@ void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
#endif
);
if (!mkFace.IsDone())
throw Base::Exception("SketchBased: Up To Face: Failed to create unlimited face");
throw Base::ValueError("SketchBased: Up To Face: Failed to create unlimited face");
upToFace = TopoDS::Face(mkFace.Shape());
upToFace.Location(loc);
}
@@ -477,13 +477,13 @@ void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
if (adapt2.GetType() == GeomAbs_Plane) {
if (adapt1.Plane().Axis().IsNormal(adapt2.Plane().Axis(), Precision::Confusion()))
throw Base::Exception("SketchBased: Up to face: Must not be parallel to extrusion direction!");
throw Base::ValueError("SketchBased: Up to face: Must not be parallel to extrusion direction!");
}
// We must measure from sketchshape, not supportface, here
BRepExtrema_DistShapeShape distSS(sketchshape, upToFace);
if (distSS.Value() < Precision::Confusion())
throw Base::Exception("SketchBased: Up to face: Must not intersect sketch!");
throw Base::ValueError("SketchBased: Up to face: Must not intersect sketch!");
// Move the face in the extrusion direction
// TODO: For non-planar faces, we could consider offsetting the surface
@@ -494,7 +494,7 @@ void ProfileBased::getUpToFace(TopoDS_Face& upToFace,
TopLoc_Location loc(mov);
upToFace.Move(loc);
} else {
throw Base::Exception("SketchBased: Up to Face: Offset not supported yet for non-planar faces");
throw Base::TypeError("SketchBased: Up to Face: Offset not supported yet for non-planar faces");
}
}
}
@@ -537,10 +537,10 @@ void ProfileBased::generatePrism(TopoDS_Shape& prism,
// resulting shape creates problems with Pocket
BRepPrimAPI_MakePrism PrismMaker(from, Ltotal*gp_Vec(dir), 0,1); // finite prism
if (!PrismMaker.IsDone())
throw Base::Exception("SketchBased: Length: Could not extrude the sketch!");
throw Base::RuntimeError("SketchBased: Length: Could not extrude the sketch!");
prism = PrismMaker.Shape();
} else {
throw Base::Exception("SketchBased: Internal error: Unknown method for generatePrism()");
throw Base::RuntimeError("SketchBased: Internal error: Unknown method for generatePrism()");
}
}
@@ -655,7 +655,7 @@ bool ProfileBased::checkLineCrossesFace(const gp_Lin &line, const TopoDS_Face &f
TopoDS_Wire outerWire = ShapeAnalysis::OuterWire(face);
BRepBuilderAPI_MakeEdge mkEdge(line);
if (!mkEdge.IsDone())
throw Base::Exception("Revolve: Unexpected OCE failure");
throw Base::RuntimeError("Revolve: Unexpected OCE failure");
BRepAdaptor_Curve axis(TopoDS::Edge(mkEdge.Shape()));
TopExp_Explorer ex;
@@ -990,7 +990,7 @@ void ProfileBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std
// Check that axis is perpendicular with sketch plane!
if (sketchplane.Axis().Direction().IsParallel(gp_Dir(dir.x, dir.y, dir.z), Precision::Angular()))
throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane");
throw Base::ValueError("Rotation axis must not be perpendicular with the sketch plane");
return;
}
@@ -1001,13 +1001,13 @@ void ProfileBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std
// Check that axis is perpendicular with sketch plane!
if (sketchplane.Axis().Direction().IsParallel(gp_Dir(dir.x, dir.y, dir.z), Precision::Angular()))
throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane");
throw Base::ValueError("Rotation axis must not be perpendicular with the sketch plane");
return;
}
if (pcReferenceAxis->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (subReferenceAxis.empty())
throw Base::Exception("No rotation axis reference specified");
throw Base::ValueError("No rotation axis reference specified");
const Part::Feature* refFeature = static_cast<const Part::Feature*>(pcReferenceAxis);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subReferenceAxis[0].c_str());
@@ -1015,10 +1015,10 @@ void ProfileBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std
if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract rotation edge");
throw Base::ValueError("Failed to extract rotation edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Rotation edge must be a straight line");
throw Base::TypeError("Rotation edge must be a straight line");
gp_Pnt b = adapt.Line().Location();
base = Base::Vector3d(b.X(), b.Y(), b.Z());
@@ -1027,14 +1027,14 @@ void ProfileBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std
// Check that axis is co-planar with sketch plane!
// Check that axis is perpendicular with sketch plane!
if (sketchplane.Axis().Direction().IsParallel(d, Precision::Angular()))
throw Base::Exception("Rotation axis must not be perpendicular with the sketch plane");
throw Base::ValueError("Rotation axis must not be perpendicular with the sketch plane");
return;
} else {
throw Base::Exception("Rotation reference must be an edge");
throw Base::TypeError("Rotation reference must be an edge");
}
}
throw Base::Exception("Rotation axis reference is invalid");
throw Base::TypeError("Rotation axis reference is invalid");
}
Base::Vector3d ProfileBased::getProfileNormal() const {

View File

@@ -102,7 +102,7 @@ Part::Feature* Transformed::getBaseObject(bool silent) const {
}
if (!silent && err) {
throw Base::Exception(err);
throw Base::RuntimeError(err);
}
return rv;

View File

@@ -102,7 +102,7 @@ bool TaskDlgFeatureParameters::accept() {
// Make sure the feature is what we are expecting
// Should be fine but you never know...
if ( !feature->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) ) {
throw Base::Exception("Bad object processed in the feature dialog.");
throw Base::TypeError("Bad object processed in the feature dialog.");
}
App::DocumentObject* previous = static_cast<PartDesign::Feature*>(feature)->getBaseObject(/* silent = */ true );
@@ -115,7 +115,7 @@ bool TaskDlgFeatureParameters::accept() {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!feature->isValid()) {
throw Base::Exception(vp->getObject()->getStatusString());
throw Base::RuntimeError(vp->getObject()->getStatusString());
}
// detach the task panel from the selection to avoid to invoke

View File

@@ -871,7 +871,7 @@ bool TaskDlgPipeParameters::accept()
try {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!vp->getObject()->isValid())
throw Base::Exception(vp->getObject()->getStatusString());
throw Base::RuntimeError(vp->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();

View File

@@ -323,7 +323,7 @@ bool TaskDlgShapeBinder::accept()
try {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!vp->getObject()->isValid())
throw Base::Exception(vp->getObject()->getStatusString());
throw Base::RuntimeError(vp->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}

View File

@@ -236,7 +236,7 @@ bool TaskDlgSketchBasedParameters::accept() {
// Make sure the feature is what we are expecting
// Should be fine but you never know...
if ( !feature->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId()) ) {
throw Base::Exception("Bad object processed in the sketch based dialog.");
throw Base::TypeError("Bad object processed in the sketch based dialog.");
}
App::DocumentObject* sketch = static_cast<PartDesign::ProfileBased*>(feature)->Profile.getValue();

View File

@@ -448,9 +448,9 @@ void ComboLinks::clear()
App::PropertyLinkSub &ComboLinks::getLink(int index) const
{
if (index < 0 || index > (ssize_t) linksInList.size()-1)
throw Base::Exception("ComboLinks::getLink:Index out of range");
throw Base::IndexError("ComboLinks::getLink:Index out of range");
if (linksInList[index]->getValue() && doc && !(doc->isIn(linksInList[index]->getValue())))
throw Base::Exception("Linked object is not in the document; it may have been deleted");
throw Base::ValueError("Linked object is not in the document; it may have been deleted");
return *(linksInList[index]);
}

View File

@@ -201,7 +201,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
const App::Document* doc = sketch->getDocument();
PartDesign::Body *body = getBodyFor(sketch, /*messageIfNot*/ 0);
if (!body) {
throw Base::Exception ("Couldn't find body for the sketch");
throw Base::RuntimeError ("Couldn't find body for the sketch");
}
// Get the Origin for the body
@@ -226,7 +226,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
else if (sketchVector == Base::Vector3d(1,0,0))
plane = origin->getYZ ();
else {
throw Base::Exception("Sketch plane cannot be migrated");
throw Base::ValueError("Sketch plane cannot be migrated");
}
assert (plane);
@@ -324,7 +324,7 @@ void relinkToBody (PartDesign::Feature *feature) {
PartDesign::Body *body = PartDesign::Body::findBodyOf ( feature );
if (!body) {
throw Base::Exception ("Couldn't find body for the feature");
throw Base::RuntimeError ("Couldn't find body for the feature");
}
std::string bodyName = body->getNameInDocument ();

View File

@@ -133,7 +133,7 @@ bool ViewProvider::setEdit(int ModNum)
if (!featureDlg) {
featureDlg = this->getEditDialog();
if (!featureDlg) { // Shouldn't generally happen
throw Base::Exception ("Failed to create new edit dialog.");
throw Base::RuntimeError ("Failed to create new edit dialog.");
}
}
@@ -146,7 +146,7 @@ bool ViewProvider::setEdit(int ModNum)
TaskDlgFeatureParameters *ViewProvider::getEditDialog() {
throw Base::Exception("getEditDialog() not implemented");
throw Base::NotImplementedError("getEditDialog() not implemented");
}

View File

@@ -335,7 +335,7 @@ void ViewProviderBody::updateOriginDatumSize () {
Gui::ViewProvider *vp = Gui::Application::Instance->getViewProvider(origin);
if (!vp) {
throw Base::Exception ("No view provider linked to the Origin");
throw Base::ValueError ("No view provider linked to the Origin");
}
assert ( vp->isDerivedFrom ( Gui::ViewProviderOrigin::getClassTypeId () ) );
vpOrigin = static_cast <Gui::ViewProviderOrigin *> ( vp );

View File

@@ -76,7 +76,7 @@ void WorkflowManager::init() {
if (!_instance) {
_instance = new WorkflowManager();
} else {
//throw Base::Exception( "Trying to init the workflow manager second time." );
//throw Base::RuntimeError( "Trying to init the workflow manager second time." );
}
}