MeshPointPyImp.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 <sstream>
00027 #endif
00028
00029 #include "Mesh.h"
00030 #include "MeshPoint.h"
00031 #include "MeshPointPy.h"
00032 #include "MeshPointPy.cpp"
00033
00034 #include <Base/VectorPy.h>
00035
00036 using namespace Mesh;
00037
00038
00039 std::string MeshPointPy::representation(void) const
00040 {
00041 MeshPointPy::PointerType ptr = getMeshPointPtr();
00042 std::stringstream str;
00043 str << "MeshPoint (";
00044 if(ptr->isBound())
00045 str << ptr->x << ", "<< ptr->y << ", "<< ptr->z << ", Idx=" << ptr->Index;
00046 else
00047 str << ptr->x << ", "<< ptr->y << ", "<< ptr->z ;
00048 str << ")";
00049
00050 return str.str();
00051 }
00052
00053 PyObject *MeshPointPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00054 {
00055
00056 return new MeshPointPy(new MeshPoint);
00057 }
00058
00059
00060 int MeshPointPy::PyInit(PyObject* args, PyObject*k)
00061 {
00062 double x=0.0,y=0.0,z=0.0;
00063 if (!PyArg_ParseTuple(args, "|ddd", &x,&y,&z))
00064 return -1;
00065
00066 getMeshPointPtr()->Set(x,y,z);
00067 return 0;
00068 }
00069
00070 PyObject* MeshPointPy::unbound(PyObject *args)
00071 {
00072 getMeshPointPtr()->Index = UINT_MAX;
00073 getMeshPointPtr()->Mesh = 0;
00074 Py_Return;
00075 }
00076
00077 PyObject* MeshPointPy::move(PyObject *args)
00078 {
00079 if (!getMeshPointPtr()->isBound())
00080 PyErr_SetString(PyExc_Exception, "This object is not bounded to a mesh, so no topological operation is possible!");
00081
00082 double x=0.0,y=0.0,z=0.0;
00083 PyObject *object;
00084 Base::Vector3d vec;
00085 if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
00086 vec.Set(x,y,z);
00087 }
00088 else if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
00089 PyErr_Clear();
00090
00091 vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
00092 }
00093 else {
00094 return 0;
00095 }
00096
00097 getMeshPointPtr()->Mesh->movePoint(getMeshPointPtr()->Index,vec);
00098 Py_Return;
00099 }
00100
00101 Py::Int MeshPointPy::getIndex(void) const
00102 {
00103 return Py::Int((long) getMeshPointPtr()->Index);
00104 }
00105
00106 Py::Boolean MeshPointPy::getBound(void) const
00107 {
00108 return Py::Boolean(getMeshPointPtr()->Index != UINT_MAX);
00109 }
00110
00111 Py::Object MeshPointPy::getNormal(void) const
00112 {
00113 if (!getMeshPointPtr()->isBound())
00114 PyErr_SetString(PyExc_Exception, "This object is not bounded to a mesh, so no topological operation is possible!");
00115
00116 Base::Vector3d* v = new Base::Vector3d(getMeshPointPtr()->Mesh->getPointNormal(getMeshPointPtr()->Index));
00117 Base::VectorPy* normal = new Base::VectorPy(v);
00118 normal->setConst();
00119 return Py::Object(normal,true);
00120 }
00121
00122 Py::Object MeshPointPy::getVector(void) const
00123 {
00124 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00125
00126 Base::VectorPy* vec = new Base::VectorPy(*ptr);
00127 vec->setConst();
00128 return Py::Object(vec,true);
00129 }
00130
00131 Py::Float MeshPointPy::getx(void) const
00132 {
00133 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00134 return Py::Float(ptr->x);
00135 }
00136
00137 void MeshPointPy::setx(Py::Float arg)
00138 {
00139 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00140 ptr->x = (double)arg;
00141
00142 if (getMeshPointPtr()->isBound()) {
00143 getMeshPointPtr()->Mesh->movePoint(getMeshPointPtr()->Index,*ptr);
00144 }
00145 }
00146
00147 Py::Float MeshPointPy::gety(void) const
00148 {
00149 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00150 return Py::Float(ptr->y);
00151 }
00152
00153 void MeshPointPy::sety(Py::Float arg)
00154 {
00155 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00156 ptr->y = (double)arg;
00157
00158 if (getMeshPointPtr()->isBound()) {
00159 getMeshPointPtr()->Mesh->movePoint(getMeshPointPtr()->Index,*ptr);
00160 }
00161 }
00162
00163 Py::Float MeshPointPy::getz(void) const
00164 {
00165 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00166 return Py::Float(ptr->z);
00167 }
00168
00169 void MeshPointPy::setz(Py::Float arg)
00170 {
00171 MeshPointPy::PointerType ptr = reinterpret_cast<MeshPointPy::PointerType>(_pcTwinPointer);
00172 ptr->z = (double)arg;
00173
00174 if (getMeshPointPtr()->isBound()) {
00175 getMeshPointPtr()->Mesh->movePoint(getMeshPointPtr()->Index,*ptr);
00176 }
00177 }
00178
00179 PyObject *MeshPointPy::getCustomAttributes(const char* attr) const
00180 {
00181 return 0;
00182 }
00183
00184 int MeshPointPy::setCustomAttributes(const char* attr, PyObject *obj)
00185 {
00186 return 0;
00187 }