TopoShapeShellPyImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <gp_Ax1.hxx>
00027 # include <BRep_Builder.hxx>
00028 # include <BRepCheck_Analyzer.hxx>
00029 # include <TopoDS.hxx>
00030 # include <TopoDS_Shell.hxx>
00031 # include <ShapeUpgrade_ShellSewing.hxx>
00032 # include <ShapeAnalysis_Shell.hxx>
00033 #endif
00034
00035 #include <BRepPrimAPI_MakeHalfSpace.hxx>
00036
00037 #include <Base/VectorPy.h>
00038 #include <Base/GeometryPyCXX.h>
00039
00040 #include "TopoShape.h"
00041 #include "TopoShapeCompoundPy.h"
00042 #include "TopoShapeCompSolidPy.h"
00043 #include "TopoShapeFacePy.h"
00044 #include "TopoShapeShellPy.h"
00045 #include "TopoShapeShellPy.cpp"
00046 #include "TopoShapeSolidPy.h"
00047
00048 using namespace Part;
00049
00050
00051 std::string TopoShapeShellPy::representation(void) const
00052 {
00053
00054
00055
00056
00057
00058
00059
00060 std::stringstream str;
00061 str << "<Shell object at " << getTopoShapePtr() << ">";
00062
00063 return str.str();
00064 }
00065
00066 PyObject *TopoShapeShellPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00067 {
00068
00069 return new TopoShapeShellPy(new TopoShape);
00070 }
00071
00072
00073 int TopoShapeShellPy::PyInit(PyObject* args, PyObject* )
00074 {
00075 PyObject *obj;
00076 if (!PyArg_ParseTuple(args, "O!", &(PyList_Type), &obj))
00077 return -1;
00078
00079 BRep_Builder builder;
00080 TopoDS_Shape shape;
00081 TopoDS_Shell shell;
00082
00083 builder.MakeShell(shell);
00084
00085 try {
00086 Py::List list(obj);
00087 for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00088 if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapeFacePy::Type))) {
00089 const TopoDS_Shape& sh = static_cast<TopoShapeFacePy*>((*it).ptr())->
00090 getTopoShapePtr()->_Shape;
00091 if (!sh.IsNull())
00092 builder.Add(shell, sh);
00093 }
00094 }
00095
00096 shape = shell;
00097 BRepCheck_Analyzer check(shell);
00098 if (!check.IsValid()) {
00099 ShapeUpgrade_ShellSewing sewShell;
00100 shape = sewShell.ApplySewing(shell);
00101 }
00102 }
00103 catch (Standard_Failure) {
00104 Handle_Standard_Failure e = Standard_Failure::Caught();
00105 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00106 return -1;
00107 }
00108
00109 getTopoShapePtr()->_Shape = shape;
00110 return 0;
00111 }
00112
00113 PyObject* TopoShapeShellPy::add(PyObject *args)
00114 {
00115 PyObject *obj;
00116 if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeFacePy::Type), &obj))
00117 return NULL;
00118
00119 BRep_Builder builder;
00120 TopoDS_Shape& shell = getTopoShapePtr()->_Shape;
00121
00122 try {
00123 const TopoDS_Shape& sh = static_cast<TopoShapeFacePy*>(obj)->
00124 getTopoShapePtr()->_Shape;
00125 if (!sh.IsNull()) {
00126 builder.Add(shell, sh);
00127 BRepCheck_Analyzer check(shell);
00128 if (!check.IsValid()) {
00129 ShapeUpgrade_ShellSewing sewShell;
00130 getTopoShapePtr()->_Shape = sewShell.ApplySewing(shell);
00131 }
00132 }
00133 else {
00134 Standard_Failure::Raise("cannot add empty shape");
00135 }
00136 }
00137 catch (Standard_Failure) {
00138 Handle_Standard_Failure e = Standard_Failure::Caught();
00139 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00140 return 0;
00141 }
00142
00143 Py_Return;
00144 }
00145
00146 PyObject* TopoShapeShellPy::getFreeEdges(PyObject *args)
00147 {
00148 if (!PyArg_ParseTuple(args, ""))
00149 return NULL;
00150 ShapeAnalysis_Shell as;
00151 as.LoadShells(getTopoShapePtr()->_Shape);
00152 #if OCC_HEX_VERSION < 0x060500
00153 as.CheckOrientedShells(getTopoShapePtr()->_Shape, Standard_True);
00154 #else
00155 as.CheckOrientedShells(getTopoShapePtr()->_Shape, Standard_True, Standard_True);
00156 #endif
00157 TopoDS_Compound comp = as.FreeEdges();
00158 return new TopoShapeCompoundPy(new TopoShape(comp));
00159 }
00160
00161 PyObject* TopoShapeShellPy::getBadEdges(PyObject *args)
00162 {
00163 if (!PyArg_ParseTuple(args, ""))
00164 return NULL;
00165 ShapeAnalysis_Shell as;
00166 as.LoadShells(getTopoShapePtr()->_Shape);
00167 #if OCC_HEX_VERSION < 0x060500
00168 as.CheckOrientedShells(getTopoShapePtr()->_Shape, Standard_True);
00169 #else
00170 as.CheckOrientedShells(getTopoShapePtr()->_Shape, Standard_True, Standard_True);
00171 #endif
00172 TopoDS_Compound comp = as.BadEdges();
00173 return new TopoShapeCompoundPy(new TopoShape(comp));
00174 }
00175
00176 PyObject* TopoShapeShellPy::makeHalfSpace(PyObject *args)
00177 {
00178 PyObject* pPnt;
00179 if (!PyArg_ParseTuple(args, "O!",&(Base::VectorPy::Type),&pPnt))
00180 return 0;
00181
00182 try {
00183 Base::Vector3d pt = Py::Vector(pPnt,false).toVector();
00184 BRepPrimAPI_MakeHalfSpace mkHS(TopoDS::Face(this->getTopoShapePtr()->_Shape), gp_Pnt(pt.x,pt.y,pt.z));
00185 return new TopoShapeSolidPy(new TopoShape(mkHS.Solid()));
00186 }
00187 catch (Standard_Failure) {
00188 Handle_Standard_Failure e = Standard_Failure::Caught();
00189 PyErr_SetString(PyExc_Exception, e->GetMessageString());
00190 return 0;
00191 }
00192 }
00193
00194 PyObject *TopoShapeShellPy::getCustomAttributes(const char* ) const
00195 {
00196 return 0;
00197 }
00198
00199 int TopoShapeShellPy::setCustomAttributes(const char* , PyObject* )
00200 {
00201 return 0;
00202 }