+ raise exception in TopoShape::getSubShape() if shape is empty or wrong sub-type is given

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5349 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2011-12-27 14:39:29 +00:00
parent d83e488394
commit a402ab5320
4 changed files with 58 additions and 46 deletions

View File

@ -355,7 +355,11 @@ void TopoShape::getFacesFromSubelement(const Data::Segment* element,
TopoDS_Shape TopoShape::getSubShape(const char* Type) const TopoDS_Shape TopoShape::getSubShape(const char* Type) const
{ {
if (!Type) return TopoDS_Shape(); if (!Type)
Standard_Failure::Raise("No sub-shape type given");
if (this->_Shape.IsNull())
Standard_Failure::Raise("Cannot get sub-shape from empty shape");
std::string shapetype(Type); std::string shapetype(Type);
if (shapetype.size() > 4 && shapetype.substr(0,4) == "Face") { if (shapetype.size() > 4 && shapetype.substr(0,4) == "Face") {
int index=std::atoi(&shapetype[4]); int index=std::atoi(&shapetype[4]);
@ -376,7 +380,8 @@ TopoDS_Shape TopoShape::getSubShape(const char* Type) const
return anIndices.FindKey(index); return anIndices.FindKey(index);
} }
return TopoDS_Shape(); Standard_Failure::Raise("Not supported sub-shape type");
return TopoDS_Shape(); // avoid compiler warning
} }
unsigned long TopoShape::countSubShapes(const char* Type) const unsigned long TopoShape::countSubShapes(const char* Type) const
@ -1738,27 +1743,27 @@ TopoDS_Shape TopoShape::removeSplitter() const
Standard_Failure::Raise("Cannot remove splitter from empty shape"); Standard_Failure::Raise("Cannot remove splitter from empty shape");
if (_Shape.ShapeType() == TopAbs_SOLID) { if (_Shape.ShapeType() == TopAbs_SOLID) {
const TopoDS_Solid& solid = TopoDS::Solid(_Shape); const TopoDS_Solid& solid = TopoDS::Solid(_Shape);
ModelRefine::FaceUniter uniter(solid); ModelRefine::FaceUniter uniter(solid);
if (uniter.process()) { if (uniter.process()) {
TopoDS_Solid solidMod; TopoDS_Solid solidMod;
if (!uniter.getSolid(solidMod)) if (!uniter.getSolid(solidMod))
Standard_Failure::Raise("Getting solid failed"); Standard_Failure::Raise("Getting solid failed");
return solidMod; return solidMod;
} }
else { else {
Standard_Failure::Raise("Removing splitter failed"); Standard_Failure::Raise("Removing splitter failed");
} }
} }
else if (_Shape.ShapeType() == TopAbs_SHELL) { else if (_Shape.ShapeType() == TopAbs_SHELL) {
const TopoDS_Shell& shell = TopoDS::Shell(_Shape); const TopoDS_Shell& shell = TopoDS::Shell(_Shape);
ModelRefine::FaceUniter uniter(shell); ModelRefine::FaceUniter uniter(shell);
if (uniter.process()) { if (uniter.process()) {
return uniter.getShell(); return uniter.getShell();
} }
else { else {
Standard_Failure::Raise("Removing splitter failed"); Standard_Failure::Raise("Removing splitter failed");
} }
} }
else if (_Shape.ShapeType() == TopAbs_COMPOUND) { else if (_Shape.ShapeType() == TopAbs_COMPOUND) {
BRep_Builder builder; BRep_Builder builder;
@ -1768,21 +1773,21 @@ TopoDS_Shape TopoShape::removeSplitter() const
TopExp_Explorer xp; TopExp_Explorer xp;
// solids // solids
for (xp.Init(_Shape, TopAbs_SOLID); xp.More(); xp.Next()) { for (xp.Init(_Shape, TopAbs_SOLID); xp.More(); xp.Next()) {
const TopoDS_Solid& solid = TopoDS::Solid(xp.Current()); const TopoDS_Solid& solid = TopoDS::Solid(xp.Current());
ModelRefine::FaceUniter uniter(solid); ModelRefine::FaceUniter uniter(solid);
if (uniter.process()) { if (uniter.process()) {
TopoDS_Solid solidMod; TopoDS_Solid solidMod;
if (uniter.getSolid(solidMod)) if (uniter.getSolid(solidMod))
builder.Add(comp, solidMod); builder.Add(comp, solidMod);
} }
} }
// free shells // free shells
for (xp.Init(_Shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) { for (xp.Init(_Shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) {
const TopoDS_Shell& shell = TopoDS::Shell(xp.Current()); const TopoDS_Shell& shell = TopoDS::Shell(xp.Current());
ModelRefine::FaceUniter uniter(shell); ModelRefine::FaceUniter uniter(shell);
if (uniter.process()) { if (uniter.process()) {
builder.Add(comp, uniter.getShell()); builder.Add(comp, uniter.getShell());
} }
} }
// the rest // the rest
for (xp.Init(_Shape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) { for (xp.Init(_Shape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) {

View File

@ -92,7 +92,7 @@ App::DocumentObjectExecReturn *SketchObject::execute(void)
// setup and diagnose the sketch // setup and diagnose the sketch
rebuildExternalGeometry(); rebuildExternalGeometry();
Sketch sketch; Sketch sketch;
int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
true, getExternalGeometryCount()); true, getExternalGeometryCount());
if (dofs < 0) { // over-constrained sketch if (dofs < 0) { // over-constrained sketch
std::string msg="Over-constrained sketch\n"; std::string msg="Over-constrained sketch\n";
@ -123,7 +123,7 @@ int SketchObject::hasConflicts(void) const
{ {
// set up a sketch (including dofs counting and diagnosing of conflicts) // set up a sketch (including dofs counting and diagnosing of conflicts)
Sketch sketch; Sketch sketch;
int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
true, getExternalGeometryCount()); true, getExternalGeometryCount());
if (dofs < 0) // over-constrained sketch if (dofs < 0) // over-constrained sketch
return -2; return -2;
@ -161,7 +161,7 @@ int SketchObject::setDatum(int ConstrId, double Datum)
// set up a sketch (including dofs counting and diagnosing of conflicts) // set up a sketch (including dofs counting and diagnosing of conflicts)
Sketch sketch; Sketch sketch;
int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
true, getExternalGeometryCount()); true, getExternalGeometryCount());
int err=0; int err=0;
if (dofs < 0) // over-constrained sketch if (dofs < 0) // over-constrained sketch
@ -187,7 +187,7 @@ int SketchObject::setDatum(int ConstrId, double Datum)
int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative) int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toPoint, bool relative)
{ {
Sketch sketch; Sketch sketch;
int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(),
true, getExternalGeometryCount()); true, getExternalGeometryCount());
if (dofs < 0) // over-constrained sketch if (dofs < 0) // over-constrained sketch
return -1; return -1;
@ -668,7 +668,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none;
ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); for (std::vector<Constraint *>::const_iterator it=constraints.begin();
it != constraints.end(); ++it) { it != constraints.end(); ++it) {
Constraint *constr = *(it); Constraint *constr = *(it);
if (secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) { if (secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) {
@ -691,7 +691,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
newConstr->SecondPos = secondPos1; newConstr->SecondPos = secondPos1;
delConstraintOnPoint(GeoId1, secondPos1, false); delConstraintOnPoint(GeoId1, secondPos1, false);
} }
addConstraint(newConstr); addConstraint(newConstr);
// Reset the second pos // Reset the second pos
@ -737,7 +737,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
ConstraintType constrType = Sketcher::PointOnObject; ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none; PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); for (std::vector<Constraint *>::const_iterator it=constraints.begin();
it != constraints.end(); ++it) { it != constraints.end(); ++it) {
Constraint *constr = *(it); Constraint *constr = *(it);
if ((constr->First == GeoId1 && constr->Second == GeoId)) { if ((constr->First == GeoId1 && constr->Second == GeoId)) {
@ -818,7 +818,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none;
ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); for (std::vector<Constraint *>::const_iterator it=constraints.begin();
it != constraints.end(); ++it) { it != constraints.end(); ++it) {
Constraint *constr = *(it); Constraint *constr = *(it);
if (secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) { if (secondPos1 == Sketcher::none && (constr->First == GeoId1 && constr->Second == GeoId)) {
@ -904,7 +904,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none;
ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); for (std::vector<Constraint *>::const_iterator it=constraints.begin();
it != constraints.end(); ++it) { it != constraints.end(); ++it) {
Constraint *constr = *(it); Constraint *constr = *(it);
if (secondPos1 == Sketcher::none && if (secondPos1 == Sketcher::none &&
@ -970,7 +970,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
ConstraintType constrType = Sketcher::PointOnObject; ConstraintType constrType = Sketcher::PointOnObject;
PointPos secondPos = Sketcher::none; PointPos secondPos = Sketcher::none;
for (std::vector<Constraint *>::const_iterator it=constraints.begin(); for (std::vector<Constraint *>::const_iterator it=constraints.begin();
it != constraints.end(); ++it) { it != constraints.end(); ++it) {
Constraint *constr = *(it); Constraint *constr = *(it);
if ((constr->First == GeoId1 && constr->Second == GeoId)) { if ((constr->First == GeoId1 && constr->Second == GeoId)) {
@ -1013,7 +1013,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point)
if (constrType == Sketcher::Coincident) if (constrType == Sketcher::Coincident)
newConstr->SecondPos = secondPos; newConstr->SecondPos = secondPos;
addConstraint(newConstr); addConstraint(newConstr);
delete newConstr; delete newConstr;
return 0; return 0;
@ -1065,7 +1065,7 @@ int SketchObject::delExternal(int ExtGeoId)
return 0; return 0;
} }
const Part::Geometry* SketchObject::getGeometry(int GeoId) const const Part::Geometry* SketchObject::getGeometry(int GeoId) const
{ {
if (GeoId >= 0) { if (GeoId >= 0) {
@ -1122,7 +1122,14 @@ void SketchObject::rebuildExternalGeometry(void)
const Part::Feature *refObj=static_cast<const Part::Feature*>(Obj); const Part::Feature *refObj=static_cast<const Part::Feature*>(Obj);
const Part::TopoShape& refShape=refObj->Shape.getShape(); const Part::TopoShape& refShape=refObj->Shape.getShape();
TopoDS_Shape refSubShape=refShape.getSubShape(SubElement.c_str()); TopoDS_Shape refSubShape;
try {
refSubShape = refShape.getSubShape(SubElement.c_str());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Base::Exception(e->GetMessageString());
}
switch (refSubShape.ShapeType()) switch (refSubShape.ShapeType())
{ {

View File

@ -45,7 +45,7 @@
</Methode> </Methode>
<Methode Name="addExternal"> <Methode Name="addExternal">
<Documentation> <Documentation>
<UserDocu>add a link to a external geometry to use them in a constraint</UserDocu> <UserDocu>add a link to an external geometry to use it in a constraint</UserDocu>
</Documentation> </Documentation>
</Methode> </Methode>
<Methode Name="delExternal"> <Methode Name="delExternal">

View File

@ -143,7 +143,7 @@ PyObject* SketchObjectPy::addExternal(PyObject *args)
PyErr_SetString(PyExc_ValueError, str.str().c_str()); PyErr_SetString(PyExc_ValueError, str.str().c_str());
return 0; return 0;
} }
// check if its belong to the sketch support // check if it belongs to the sketch support
if (this->getSketchObjectPtr()->Support.getValue() != Obj) { if (this->getSketchObjectPtr()->Support.getValue() != Obj) {
std::stringstream str; std::stringstream str;
str << ObjectName << "is not supported by this sketch"; str << ObjectName << "is not supported by this sketch";