From a402ab5320c6d8680ca482094888348ee8db351d Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 27 Dec 2011 14:39:29 +0000 Subject: [PATCH] + 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 --- src/Mod/Part/App/TopoShape.cpp | 67 ++++++++++++---------- src/Mod/Sketcher/App/SketchObject.cpp | 33 ++++++----- src/Mod/Sketcher/App/SketchObjectPy.xml | 2 +- src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 2 +- 4 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 0206d8569..dfe43aee7 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -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 @@ -1738,27 +1743,27 @@ TopoDS_Shape TopoShape::removeSplitter() const Standard_Failure::Raise("Cannot remove splitter from empty shape"); if (_Shape.ShapeType() == TopAbs_SOLID) { - const TopoDS_Solid& solid = TopoDS::Solid(_Shape); - ModelRefine::FaceUniter uniter(solid); - if (uniter.process()) { - TopoDS_Solid solidMod; - if (!uniter.getSolid(solidMod)) - Standard_Failure::Raise("Getting solid failed"); - return solidMod; - } - else { + const TopoDS_Solid& solid = TopoDS::Solid(_Shape); + ModelRefine::FaceUniter uniter(solid); + if (uniter.process()) { + TopoDS_Solid solidMod; + if (!uniter.getSolid(solidMod)) + Standard_Failure::Raise("Getting solid failed"); + return solidMod; + } + else { Standard_Failure::Raise("Removing splitter failed"); - } + } } else if (_Shape.ShapeType() == TopAbs_SHELL) { - const TopoDS_Shell& shell = TopoDS::Shell(_Shape); - ModelRefine::FaceUniter uniter(shell); - if (uniter.process()) { - return uniter.getShell(); - } - else { + const TopoDS_Shell& shell = TopoDS::Shell(_Shape); + ModelRefine::FaceUniter uniter(shell); + if (uniter.process()) { + return uniter.getShell(); + } + else { Standard_Failure::Raise("Removing splitter failed"); - } + } } else if (_Shape.ShapeType() == TopAbs_COMPOUND) { BRep_Builder builder; @@ -1768,21 +1773,21 @@ TopoDS_Shape TopoShape::removeSplitter() const TopExp_Explorer xp; // solids for (xp.Init(_Shape, TopAbs_SOLID); xp.More(); xp.Next()) { - const TopoDS_Solid& solid = TopoDS::Solid(xp.Current()); - ModelRefine::FaceUniter uniter(solid); - if (uniter.process()) { - TopoDS_Solid solidMod; - if (uniter.getSolid(solidMod)) - builder.Add(comp, solidMod); - } + const TopoDS_Solid& solid = TopoDS::Solid(xp.Current()); + ModelRefine::FaceUniter uniter(solid); + if (uniter.process()) { + TopoDS_Solid solidMod; + if (uniter.getSolid(solidMod)) + builder.Add(comp, solidMod); + } } // free shells for (xp.Init(_Shape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next()) { - const TopoDS_Shell& shell = TopoDS::Shell(xp.Current()); - ModelRefine::FaceUniter uniter(shell); - if (uniter.process()) { - builder.Add(comp, uniter.getShell()); - } + const TopoDS_Shell& shell = TopoDS::Shell(xp.Current()); + ModelRefine::FaceUniter uniter(shell); + if (uniter.process()) { + builder.Add(comp, uniter.getShell()); + } } // the rest for (xp.Init(_Shape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) { diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 904b8b063..4d7dce5af 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -92,7 +92,7 @@ App::DocumentObjectExecReturn *SketchObject::execute(void) // setup and diagnose the sketch rebuildExternalGeometry(); Sketch sketch; - int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), + int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), true, getExternalGeometryCount()); if (dofs < 0) { // over-constrained sketch 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) Sketch sketch; - int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), + int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), true, getExternalGeometryCount()); if (dofs < 0) // over-constrained sketch return -2; @@ -161,7 +161,7 @@ int SketchObject::setDatum(int ConstrId, double Datum) // set up a sketch (including dofs counting and diagnosing of conflicts) Sketch sketch; - int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), + int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), true, getExternalGeometryCount()); int err=0; 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) { Sketch sketch; - int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), + int dofs = sketch.setUpSketch(getCompleteGeometry(), Constraints.getValues(), true, getExternalGeometryCount()); if (dofs < 0) // over-constrained sketch return -1; @@ -668,7 +668,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) PointPos secondPos1 = Sketcher::none, secondPos2 = Sketcher::none; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; - for (std::vector::const_iterator it=constraints.begin(); + for (std::vector::const_iterator it=constraints.begin(); it != constraints.end(); ++it) { Constraint *constr = *(it); 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; delConstraintOnPoint(GeoId1, secondPos1, false); } - + addConstraint(newConstr); // Reset the second pos @@ -737,7 +737,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) ConstraintType constrType = Sketcher::PointOnObject; PointPos secondPos = Sketcher::none; - for (std::vector::const_iterator it=constraints.begin(); + for (std::vector::const_iterator it=constraints.begin(); it != constraints.end(); ++it) { Constraint *constr = *(it); 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; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; - for (std::vector::const_iterator it=constraints.begin(); + for (std::vector::const_iterator it=constraints.begin(); it != constraints.end(); ++it) { Constraint *constr = *(it); 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; ConstraintType constrType1 = Sketcher::PointOnObject, constrType2 = Sketcher::PointOnObject; - for (std::vector::const_iterator it=constraints.begin(); + for (std::vector::const_iterator it=constraints.begin(); it != constraints.end(); ++it) { Constraint *constr = *(it); if (secondPos1 == Sketcher::none && @@ -970,7 +970,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) ConstraintType constrType = Sketcher::PointOnObject; PointPos secondPos = Sketcher::none; - for (std::vector::const_iterator it=constraints.begin(); + for (std::vector::const_iterator it=constraints.begin(); it != constraints.end(); ++it) { Constraint *constr = *(it); if ((constr->First == GeoId1 && constr->Second == GeoId)) { @@ -1013,7 +1013,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) if (constrType == Sketcher::Coincident) newConstr->SecondPos = secondPos; - + addConstraint(newConstr); delete newConstr; return 0; @@ -1065,7 +1065,7 @@ int SketchObject::delExternal(int ExtGeoId) return 0; } - + const Part::Geometry* SketchObject::getGeometry(int GeoId) const { if (GeoId >= 0) { @@ -1122,7 +1122,14 @@ void SketchObject::rebuildExternalGeometry(void) const Part::Feature *refObj=static_cast(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()) { diff --git a/src/Mod/Sketcher/App/SketchObjectPy.xml b/src/Mod/Sketcher/App/SketchObjectPy.xml index e4eae9a3d..e5b93b44e 100644 --- a/src/Mod/Sketcher/App/SketchObjectPy.xml +++ b/src/Mod/Sketcher/App/SketchObjectPy.xml @@ -45,7 +45,7 @@ - add a link to a external geometry to use them in a constraint + add a link to an external geometry to use it in a constraint diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index c57e6865c..d7ecedd90 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -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";