ViewProviderPyImp.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 <Inventor/nodes/SoSeparator.h>
00027 #endif
00028
00029 #include <Inventor/SoDB.h>
00030 #include <Inventor/actions/SoWriteAction.h>
00031 #include <Inventor/nodes/SoCone.h>
00032 #include <Inventor/nodes/SoSeparator.h>
00033
00034 #include "ViewProvider.h"
00035
00036
00037 #include "ViewProviderPy.h"
00038 #include "ViewProviderPy.cpp"
00039 #include <Base/Interpreter.h>
00040 #include <Base/Matrix.h>
00041 #include <Base/MatrixPy.h>
00042 #include <Base/Placement.h>
00043 #include <Base/PlacementPy.h>
00044
00045 using namespace Gui;
00046
00047
00048 std::string ViewProviderPy::representation(void) const
00049 {
00050 return "<View provider object>";
00051 }
00052
00053 PyObject* ViewProviderPy::show(PyObject *args)
00054 {
00055 if (!PyArg_ParseTuple(args, ""))
00056 return NULL;
00057 PY_TRY {
00058 getViewProviderPtr()->show();
00059 Py_Return;
00060 } PY_CATCH;
00061 }
00062
00063 PyObject* ViewProviderPy::hide(PyObject *args)
00064 {
00065 if (!PyArg_ParseTuple(args, ""))
00066 return NULL;
00067 PY_TRY {
00068 getViewProviderPtr()->hide();
00069 Py_Return;
00070 } PY_CATCH;
00071 }
00072
00073 PyObject* ViewProviderPy::isVisible(PyObject *args)
00074 {
00075 if (!PyArg_ParseTuple(args, ""))
00076 return NULL;
00077 PY_TRY {
00078 return Py_BuildValue("O", (getViewProviderPtr()->isShow() ? Py_True : Py_False));
00079 } PY_CATCH;
00080 }
00081
00082 PyObject* ViewProviderPy::listDisplayModes(PyObject *args)
00083 {
00084 if (!PyArg_ParseTuple(args, ""))
00085 return NULL;
00086 PY_TRY {
00087 std::vector<std::string> modes = getViewProviderPtr()->getDisplayModes();
00088 PyObject* pyList = PyList_New(modes.size());
00089 int i=0;
00090
00091 for ( std::vector<std::string>::iterator it = modes.begin(); it != modes.end(); ++it ) {
00092 PyObject* str = PyString_FromString(it->c_str());
00093 PyList_SetItem(pyList, i++, str);
00094 }
00095
00096 return pyList;
00097 } PY_CATCH;
00098 }
00099
00100 PyObject* ViewProviderPy::toString(PyObject *args)
00101 {
00102 if (!PyArg_ParseTuple(args, ""))
00103 return NULL;
00104 PY_TRY {
00105 std::string buffer = getViewProviderPtr()->toString();
00106 return Py::new_reference_to(Py::String(buffer));
00107 } PY_CATCH;
00108 }
00109
00110 PyObject* ViewProviderPy::startEditing(PyObject *args)
00111 {
00112 int mode=0;
00113 if (!PyArg_ParseTuple(args, "|i", &mode))
00114 return NULL;
00115 bool edit = getViewProviderPtr()->startEditing(mode);
00116 Py::Boolean ok(edit);
00117 return Py::new_reference_to(ok);
00118 }
00119
00120 PyObject* ViewProviderPy::finishEditing(PyObject *args)
00121 {
00122 if (!PyArg_ParseTuple(args, ""))
00123 return NULL;
00124 getViewProviderPtr()->finishEditing();
00125 Py_Return;
00126 }
00127
00128 PyObject* ViewProviderPy::isEditing(PyObject *args)
00129 {
00130 if (!PyArg_ParseTuple(args, ""))
00131 return NULL;
00132 bool edit = getViewProviderPtr()->isEditing();
00133 Py::Boolean ok(edit);
00134 return Py::new_reference_to(ok);
00135 }
00136
00137 PyObject* ViewProviderPy::setTransformation(PyObject *args)
00138 {
00139 PyObject* p;
00140 Base::Matrix4D mat;
00141 if (PyArg_ParseTuple(args, "O!",&(Base::MatrixPy::Type),&p)) {
00142 mat = *static_cast<Base::MatrixPy*>(p)->getMatrixPtr();
00143 getViewProviderPtr()->setTransformation(mat);
00144 Py_Return;
00145 }
00146 PyErr_Clear();
00147 if (PyArg_ParseTuple(args, "O!",&(Base::PlacementPy::Type),&p)) {
00148 Base::PlacementPy* plc = static_cast<Base::PlacementPy*>(p);
00149 getViewProviderPtr()->setTransformation(plc->getPlacementPtr()->toMatrix());
00150 Py_Return;
00151 }
00152
00153 PyErr_SetString(PyExc_Exception, "Either set matrix or placement to set transformation");
00154 return 0;
00155 }
00156
00157 PyObject *ViewProviderPy::getCustomAttributes(const char* attr) const
00158 {
00159 return 0;
00160 }
00161
00162 int ViewProviderPy::setCustomAttributes(const char* attr, PyObject *obj)
00163 {
00164 return 0;
00165 }
00166
00167 Py::Object ViewProviderPy::getAnnotation(void) const
00168 {
00169 try {
00170 SoNode* node = getViewProviderPtr()->getAnnotation();
00171 PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoSeparator *", node, 1);
00172 node->ref();
00173 return Py::Object(Ptr, true);
00174 }
00175 catch (const Base::Exception& e) {
00176 throw Py::Exception(e.what());
00177 }
00178 }
00179
00180 void ViewProviderPy::setAnnotation(Py::Object arg)
00181 {
00182
00183 }
00184
00185 Py::Object ViewProviderPy::getRootNode(void) const
00186 {
00187 try {
00188 SoNode* node = getViewProviderPtr()->getRoot();
00189 PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","SoSeparator *", node, 1);
00190 node->ref();
00191 return Py::Object(Ptr, true);
00192 }
00193 catch (const Base::Exception& e) {
00194 throw Py::Exception(e.what());
00195 }
00196 }
00197
00198 void ViewProviderPy::setRootNode(Py::Object arg)
00199 {
00200
00201 }
00202
00203 static char * buffer;
00204 static size_t buffer_size = 0;
00205
00206 static void *
00207 buffer_realloc(void * bufptr, size_t size)
00208 {
00209 buffer = (char *)realloc(bufptr, size);
00210 buffer_size = size;
00211 return buffer;
00212 }
00213
00214 static SbString
00215 buffer_writeaction(SoNode * root)
00216 {
00217 SoOutput out;
00218 buffer = (char *)malloc(1024);
00219 buffer_size = 1024;
00220 out.setBuffer(buffer, buffer_size, buffer_realloc);
00221
00222 SoWriteAction wa(&out);
00223 wa.apply(root);
00224
00225 SbString s(buffer);
00226 free(buffer);
00227 return s;
00228 }
00229
00230 Py::String ViewProviderPy::getIV(void) const
00231 {
00232 SbString buf = buffer_writeaction(getViewProviderPtr()->getRoot());
00233 return Py::String(buf.getString());
00234 }