+ make try/catch block around sortEdges

+ set shape immutable when getting from feature
+ no use of tuples in removeShape

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5402 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2012-01-12 14:04:19 +00:00
parent 7feebeb5a2
commit d3af186c1c
3 changed files with 46 additions and 34 deletions

View File

@ -1320,14 +1320,21 @@ static PyObject * sortEdges(PyObject *self, PyObject *args)
}
}
std::list<TopoDS_Edge> sorted = sort_Edges(Precision::Confusion(), edges);
try {
std::list<TopoDS_Edge> sorted = sort_Edges(Precision::Confusion(), edges);
Py::List sorted_list;
for (std::list<TopoDS_Edge>::iterator it = sorted.begin(); it != sorted.end(); ++it) {
sorted_list.append(Py::Object(new TopoShapeEdgePy(new TopoShape(*it)),true));
Py::List sorted_list;
for (std::list<TopoDS_Edge>::iterator it = sorted.begin(); it != sorted.end(); ++it) {
sorted_list.append(Py::Object(new TopoShapeEdgePy(new TopoShape(*it)),true));
}
return Py::new_reference_to(sorted_list);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
return Py::new_reference_to(sorted_list);
}
static PyObject * cast_to_shape(PyObject *self, PyObject *args)

View File

@ -147,34 +147,40 @@ void PropertyPartShape::transformGeometry(const Base::Matrix4D &rclTrf)
PyObject *PropertyPartShape::getPyObject(void)
{
Base::PyObjectBase* prop;
const TopoDS_Shape& sh = _Shape._Shape;
if (sh.IsNull())
return new TopoShapePy(new TopoShape(sh));
TopAbs_ShapeEnum type = sh.ShapeType();
switch (type)
{
case TopAbs_COMPOUND:
return new TopoShapeCompoundPy(new TopoShape(sh));
case TopAbs_COMPSOLID:
return new TopoShapeCompSolidPy(new TopoShape(sh));
case TopAbs_SOLID:
return new TopoShapeSolidPy(new TopoShape(sh));
case TopAbs_SHELL:
return new TopoShapeShellPy(new TopoShape(sh));
case TopAbs_FACE:
return new TopoShapeFacePy(new TopoShape(sh));
case TopAbs_WIRE:
return new TopoShapeWirePy(new TopoShape(sh));
case TopAbs_EDGE:
return new TopoShapeEdgePy(new TopoShape(sh));
case TopAbs_VERTEX:
return new TopoShapeVertexPy(new TopoShape(sh));
case TopAbs_SHAPE:
default:
return new TopoShapePy(new TopoShape(sh));
break;
if (sh.IsNull()) {
prop = new TopoShapePy(new TopoShape(sh));
}
else {
TopAbs_ShapeEnum type = sh.ShapeType();
switch (type)
{
case TopAbs_COMPOUND:
prop = new TopoShapeCompoundPy(new TopoShape(sh));
case TopAbs_COMPSOLID:
prop = new TopoShapeCompSolidPy(new TopoShape(sh));
case TopAbs_SOLID:
prop = new TopoShapeSolidPy(new TopoShape(sh));
case TopAbs_SHELL:
prop = new TopoShapeShellPy(new TopoShape(sh));
case TopAbs_FACE:
prop = new TopoShapeFacePy(new TopoShape(sh));
case TopAbs_WIRE:
prop = new TopoShapeWirePy(new TopoShape(sh));
case TopAbs_EDGE:
prop = new TopoShapeEdgePy(new TopoShape(sh));
case TopAbs_VERTEX:
prop = new TopoShapeVertexPy(new TopoShape(sh));
case TopAbs_SHAPE:
default:
prop = new TopoShapePy(new TopoShape(sh));
break;
}
}
if (prop) prop->setConst();
return prop;
}
void PropertyPartShape::setPyObject(PyObject *value)

View File

@ -208,8 +208,7 @@ PyObject* TopoShapePy::removeShape(PyObject *args)
Py::List list(l);
std::vector<TopoDS_Shape> shapes;
for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
Py::Tuple tuple(*it);
Py::TopoShape sh(tuple[0]);
Py::TopoShape sh(*it);
shapes.push_back(
sh.extensionObject()->getTopoShapePtr()->_Shape
);