2 //=============================================================================
4 // Created : ven nov 16 17:29:20 CET 2001
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2001
9 //=============================================================================
11 #include "SALOMEGUI_Swig.hxx"
13 #include <vtkRenderer.h>
14 #include <vtkRenderWindowInteractor.h>
15 #include <vtkPythonUtil.h>
16 #include "utilities.h"
20 static PyObject * libSalomePy_getRenderer(PyObject *self, PyObject *args);
23 static PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args)
25 if (!PyArg_ParseTuple(args, ":getRenderer"))
27 // exemple retournant systematiquement Py_None
32 static PyMethodDef Module_Methods[] =
34 {"getRenderer", libSalomePy_getRenderer, METH_VARARGS},
38 extern "C" { void initlibSalomePy();}
40 void initlibSalomePy()
42 PyObject *m, *d, *c, *md, *obj, *vtkclass;
44 static char modulename[] = "libSalomePy";
46 m = Py_InitModule(modulename, Module_Methods);
48 d = PyModule_GetDict(m);
50 // DANGEROUS : if (!d) Py_FatalError("can't get dictionary for module SalomePy!");
57 m=PyImport_ImportModule("libVTKGraphicsPython"); // import module if not already imported (new ref)
68 md = PyModule_GetDict(m); // dict of libVTKGraphicsPython (borrowed ref ; not decref)
71 vtkclass=PyDict_GetItemString(md,"vtkRenderer"); // (borrowed ref ; not decref)
72 Py_DECREF(m); // no more need of m
76 vtkRenderer *renderer = SALOMEGUI_Swig::getRenderer();
79 obj = PyVTKObject_New(vtkclass,renderer); // (new ref)
80 MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
81 PyDict_SetItemString(d,"renderer",obj); // (add a ref to obj ; has to be decref)
82 MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
83 Py_DECREF(obj); // only one ref is sufficient
84 MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
87 // vtkclass=PyDict_GetItemString(md,"vtkRenderWindowInteractor"); // (borrowed ref ; not decref)
88 // Py_DECREF(m); // no more need of m
90 // vtkRenderWindowInteractor *RWInteractor = SALOMEGUI_Swig::getRWInteractor();
92 // obj = PyVTKObject_New(vtkclass,RWInteractor); // (new ref)
93 // MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
94 // PyDict_SetItemString(d,"interactor",obj); // (add a ref to obj ; has to be decref)
95 // MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
96 // Py_DECREF(obj); // only one ref is sufficient
97 // MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp