TopoShapeVertexPyImp.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
00026 #ifndef _PreComp_
00027 # include <gp_Pnt.hxx>
00028 # include <gp_Ax1.hxx>
00029 # include <BRep_Tool.hxx>
00030 # include <TopoDS.hxx>
00031 # include <TopoDS_Vertex.hxx>
00032 # include <BRep_Builder.hxx>
00033 # include <BRepBuilderAPI_MakeVertex.hxx>
00034 #endif
00035
00036 #include <Mod/Part/App/TopoShape.h>
00037 #include <Base/VectorPy.h>
00038 #include <Base/Vector3D.h>
00039
00040 #include "TopoShapeEdgePy.h"
00041 #include "TopoShapeVertexPy.h"
00042 #include "TopoShapeVertexPy.cpp"
00043
00044 using namespace Part;
00045
00046
00047 std::string TopoShapeVertexPy::representation(void) const
00048 {
00049 std::stringstream str;
00050 str << "<Vertex object at " << getTopoShapePtr() << ">";
00051
00052 return str.str();
00053 }
00054
00055 PyObject *TopoShapeVertexPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00056 {
00057
00058 return new TopoShapeVertexPy(new TopoShape);
00059 }
00060
00061
00062 int TopoShapeVertexPy::PyInit(PyObject* args, PyObject* )
00063 {
00064 double x=0.0,y=0.0,z=0.0;
00065 PyObject *object;
00066 bool success = false;
00067 if (PyArg_ParseTuple(args, "|ddd", &x,&y,&z)) {
00068
00069 success = true;
00070 }
00071 if (!success) {
00072 PyErr_Clear();
00073 if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
00074
00075 Base::Vector3d* ptr = static_cast<Base::VectorPy*>(object)->getVectorPtr();
00076 x = ptr->x;
00077 y = ptr->y;
00078 z = ptr->z;
00079 success = true;
00080 }
00081 }
00082 if (!success) {
00083 PyErr_Clear();
00084 if (PyArg_ParseTuple(args,"O!",&(PyTuple_Type), &object)) {
00085 try {
00086 Py::Tuple tuple(object);
00087 x = (float)Py::Float(tuple.getItem(0));
00088 y = (float)Py::Float(tuple.getItem(1));
00089 z = (float)Py::Float(tuple.getItem(2));
00090 success = true;
00091 }
00092 catch (const Py::Exception&) {
00093 return -1;
00094 }
00095 }
00096 }
00097 if (!success) {
00098 PyErr_Clear();
00099 if (PyArg_ParseTuple(args,"O!",&(Part::TopoShapePy::Type), &object)) {
00100 TopoShape* ptr = static_cast<TopoShapePy*>(object)->getTopoShapePtr();
00101 TopoDS_Shape shape = ptr->_Shape;
00102 if (!shape.IsNull() && shape.ShapeType() == TopAbs_VERTEX) {
00103 TopoShapeVertexPy::PointerType vert = reinterpret_cast<TopoShapeVertexPy::PointerType>(_pcTwinPointer);
00104 vert->_Shape = ptr->_Shape;
00105 return 0;
00106 }
00107 }
00108 }
00109 if (!success) {
00110 PyErr_SetString(PyExc_TypeError, "Either three floats, tuple, vector or vertex expected");
00111 return -1;
00112 }
00113
00114 TopoShapeVertexPy::PointerType ptr = reinterpret_cast<TopoShapeVertexPy::PointerType>(_pcTwinPointer);
00115 BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(x,y,z));
00116 TopoDS_Shape s = aBuilder.Vertex();
00117 ptr->_Shape = s;
00118
00119 return 0;
00120 }
00121
00122 PyObject* TopoShapeVertexPy::setTolerance(PyObject *args)
00123 {
00124 double tol;
00125 if (!PyArg_ParseTuple(args, "d", &tol))
00126 return 0;
00127 BRep_Builder aBuilder;
00128 const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->_Shape);
00129 aBuilder.UpdateVertex(v, tol);
00130 Py_Return;
00131 }
00132
00133 Py::Float TopoShapeVertexPy::getX(void) const
00134 {
00135 const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->_Shape);
00136 return Py::Float(BRep_Tool::Pnt(v).X());
00137 }
00138
00139 Py::Float TopoShapeVertexPy::getY(void) const
00140 {
00141 const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->_Shape);
00142 return Py::Float(BRep_Tool::Pnt(v).Y());
00143 }
00144
00145 Py::Float TopoShapeVertexPy::getZ(void) const
00146 {
00147 const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->_Shape);
00148 return Py::Float(BRep_Tool::Pnt(v).Z());
00149 }
00150
00151 Py::Object TopoShapeVertexPy::getPoint(void) const
00152 {
00153 const TopoDS_Vertex& v = TopoDS::Vertex(getTopoShapePtr()->_Shape);
00154 gp_Pnt p = BRep_Tool::Pnt(v);
00155 return Py::Object(new Base::VectorPy(new Base::Vector3d(p.X(),p.Y(),p.Z())));
00156 }
00157
00158 PyObject *TopoShapeVertexPy::getCustomAttributes(const char* ) const
00159 {
00160 return 0;
00161 }
00162
00163 int TopoShapeVertexPy::setCustomAttributes(const char* , PyObject* )
00164 {
00165 return 0;
00166 }