Part: TopoShapePy: made Solid constructor accept CompSolid
Part.Solid(shape) now accepts compsolid as input, and creates a solid by joining the compsolid. Same done to Part.makeSolid(). + change exception handling to expose the error message.
This commit is contained in:
parent
885fecb1ea
commit
ca0a640aed
|
@ -256,7 +256,7 @@ public:
|
|||
"makeFilledFace(list) -- Create a face out of a list of edges."
|
||||
);
|
||||
add_varargs_method("makeSolid",&Module::makeSolid,
|
||||
"makeSolid(shape) -- Create a solid out of the shells inside a shape."
|
||||
"makeSolid(shape): Create a solid out of shells of shape. If shape is a compsolid, the overall volume solid is created."
|
||||
);
|
||||
add_varargs_method("makePlane",&Module::makePlane,
|
||||
"makePlane(length,width,[pnt,dirZ,dirX]) -- Make a plane\n"
|
||||
|
@ -693,25 +693,47 @@ private:
|
|||
throw Py::Exception();
|
||||
|
||||
try {
|
||||
BRepBuilderAPI_MakeSolid mkSolid;
|
||||
const TopoDS_Shape& shape = static_cast<TopoShapePy*>(obj)
|
||||
->getTopoShapePtr()->_Shape;
|
||||
TopExp_Explorer anExp (shape, TopAbs_SHELL);
|
||||
//first, if we were given a compsolid, try making a solid out of it
|
||||
TopExp_Explorer CSExp (shape, TopAbs_COMPSOLID);
|
||||
TopoDS_CompSolid compsolid;
|
||||
int count=0;
|
||||
for (; anExp.More(); anExp.Next()) {
|
||||
for (; CSExp.More(); CSExp.Next()) {
|
||||
++count;
|
||||
mkSolid.Add(TopoDS::Shell(anExp.Current()));
|
||||
compsolid = TopoDS::CompSolid(CSExp.Current());
|
||||
if (count > 1)
|
||||
break;
|
||||
}
|
||||
if (count == 0) {
|
||||
//no compsolids. Get shells...
|
||||
BRepBuilderAPI_MakeSolid mkSolid;
|
||||
TopExp_Explorer anExp (shape, TopAbs_SHELL);
|
||||
count=0;
|
||||
for (; anExp.More(); anExp.Next()) {
|
||||
++count;
|
||||
mkSolid.Add(TopoDS::Shell(anExp.Current()));
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
Standard_Failure::Raise("No shells found in shape");
|
||||
if (count == 0)//no shells?
|
||||
Standard_Failure::Raise("No shells or compsolids found in shape");
|
||||
|
||||
TopoDS_Solid solid = mkSolid.Solid();
|
||||
BRepLib::OrientClosedSolid(solid);
|
||||
return Py::asObject(new TopoShapeSolidPy(new TopoShape(solid)));
|
||||
TopoDS_Solid solid = mkSolid.Solid();
|
||||
BRepLib::OrientClosedSolid(solid);
|
||||
return Py::asObject(new TopoShapeSolidPy(new TopoShape(solid)));
|
||||
} else if (count == 1) {
|
||||
BRepBuilderAPI_MakeSolid mkSolid(compsolid);
|
||||
TopoDS_Solid solid = mkSolid.Solid();
|
||||
return Py::asObject(new TopoShapeSolidPy(new TopoShape(solid)));
|
||||
} else { // if (count > 1)
|
||||
Standard_Failure::Raise("Only one compsolid can be accepted. Provided shape has more than one compsolid.");
|
||||
return Py::None(); //prevents compiler warning
|
||||
}
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
throw Py::Exception(PartExceptionOCCError, "creation of solid failed");
|
||||
catch (Standard_Failure err) {
|
||||
std::stringstream errmsg;
|
||||
errmsg << "Creation of solid failed: " << err.GetMessageString();
|
||||
throw Py::Exception(PartExceptionOCCError, errmsg.str().c_str());
|
||||
}
|
||||
}
|
||||
Py::Object makePlane(const Py::Tuple& args)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="Juergen.Riegel@web.de" />
|
||||
<UserDocu>Create a solid out of the shells of a shape</UserDocu>
|
||||
<UserDocu>Part.Solid(shape): Create a solid out of shells of shape. If shape is a compsolid, the overall volume solid is created.</UserDocu>
|
||||
</Documentation>
|
||||
<Attribute Name="Mass" ReadOnly="true">
|
||||
<Documentation>
|
||||
|
@ -101,4 +101,4 @@ solid.offsetFaces((solid.Faces[0],solid.Faces[1]), 1.5)
|
|||
</Documentation>
|
||||
</Methode>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
</GenerateModel>
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Solid.hxx>
|
||||
#include <TopoDS_Shell.hxx>
|
||||
#include <TopoDS_CompSolid.hxx>
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
|
@ -81,25 +82,47 @@ int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
|||
return -1;
|
||||
|
||||
try {
|
||||
BRepBuilderAPI_MakeSolid mkSolid;
|
||||
const TopoDS_Shape& shape = static_cast<TopoShapePy*>(obj)
|
||||
->getTopoShapePtr()->_Shape;
|
||||
TopExp_Explorer anExp (shape, TopAbs_SHELL);
|
||||
//first, if we were given a compsolid, try making a solid out of it
|
||||
TopExp_Explorer CSExp (shape, TopAbs_COMPSOLID);
|
||||
TopoDS_CompSolid compsolid;
|
||||
int count=0;
|
||||
for (; anExp.More(); anExp.Next()) {
|
||||
for (; CSExp.More(); CSExp.Next()) {
|
||||
++count;
|
||||
mkSolid.Add(TopoDS::Shell(anExp.Current()));
|
||||
compsolid = TopoDS::CompSolid(CSExp.Current());
|
||||
if (count > 1)
|
||||
break;
|
||||
}
|
||||
if (count == 0) {
|
||||
//no compsolids. Get shells...
|
||||
BRepBuilderAPI_MakeSolid mkSolid;
|
||||
TopExp_Explorer anExp (shape, TopAbs_SHELL);
|
||||
count=0;
|
||||
for (; anExp.More(); anExp.Next()) {
|
||||
++count;
|
||||
mkSolid.Add(TopoDS::Shell(anExp.Current()));
|
||||
}
|
||||
|
||||
if (count == 0)//no shells?
|
||||
Standard_Failure::Raise("No shells or compsolids found in shape");
|
||||
|
||||
TopoDS_Solid solid = mkSolid.Solid();
|
||||
BRepLib::OrientClosedSolid(solid);
|
||||
getTopoShapePtr()->_Shape = solid;
|
||||
} else if (count == 1) {
|
||||
BRepBuilderAPI_MakeSolid mkSolid(compsolid);
|
||||
TopoDS_Solid solid = mkSolid.Solid();
|
||||
getTopoShapePtr()->_Shape = solid;
|
||||
} else if (count > 1) {
|
||||
Standard_Failure::Raise("Only one compsolid can be accepted. Provided shape has more than one compsolid.");
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
Standard_Failure::Raise("No shells found in shape");
|
||||
|
||||
TopoDS_Solid solid = mkSolid.Solid();
|
||||
BRepLib::OrientClosedSolid(solid);
|
||||
getTopoShapePtr()->_Shape = solid;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
PyErr_SetString(PartExceptionOCCError, "creation of solid failed");
|
||||
catch (Standard_Failure err) {
|
||||
std::stringstream errmsg;
|
||||
errmsg << "Creation of solid failed: " << err.GetMessageString();
|
||||
PyErr_SetString(PartExceptionOCCError, errmsg.str().c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user