+ 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
{
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);
if (shapetype.size() > 4 && shapetype.substr(0,4) == "Face") {
int index=std::atoi(&shapetype[4]);
@ -376,7 +380,8 @@ TopoDS_Shape TopoShape::getSubShape(const char* Type) const
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

View File

@ -1122,7 +1122,14 @@ void SketchObject::rebuildExternalGeometry(void)
const Part::Feature *refObj=static_cast<const Part::Feature*>(Obj);
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())
{

View File

@ -45,7 +45,7 @@
</Methode>
<Methode Name="addExternal">
<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>
</Methode>
<Methode Name="delExternal">

View File

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