Salome HOME
NRI : Add KERNEL_ROOT_DIR in addition to SALOME_[ROOT, SITE]_DIR.
[modules/kernel.git] / src / SALOME_PY / SalomePy.cxx
1 using namespace std;
2 //=============================================================================
3 //  File      : SalomePy.cxx
4 //  Created   : ven nov 16 17:29:20 CET 2001
5 //  Author    : Paul RASCLE, EDF
6 //  Project   : SALOME
7 //  Copyright : EDF 2001
8 //  $Header$
9 //=============================================================================
10
11 #include "SALOMEGUI_Swig.hxx"
12 #include <Python.h>
13 #include <vtkRenderer.h>
14 #include <vtkRenderWindowInteractor.h>
15 #include <vtkPythonUtil.h>
16 #include "utilities.h"
17
18 extern "C"
19
20   static PyObject * libSalomePy_getRenderer(PyObject *self, PyObject *args);
21 }
22
23 static PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args)
24 {
25   if (!PyArg_ParseTuple(args, ":getRenderer"))
26     return NULL;
27   // exemple retournant systematiquement  Py_None
28   Py_INCREF(Py_None);
29   return Py_None;
30 }
31
32 static PyMethodDef Module_Methods[] = 
33   {
34     {"getRenderer",         libSalomePy_getRenderer,         METH_VARARGS},
35     {NULL, NULL}
36   };
37
38 extern "C" { void initlibSalomePy();}
39
40 void initlibSalomePy()
41 {
42   PyObject *m, *d, *c, *md, *obj, *vtkclass;
43
44   static char modulename[] = "libSalomePy";
45   MESSAGE("---");
46   m = Py_InitModule(modulename, Module_Methods);
47   MESSAGE("---");
48   d = PyModule_GetDict(m);
49   MESSAGE("---");
50   // DANGEROUS : if (!d) Py_FatalError("can't get dictionary for module SalomePy!");
51   if (PyErr_Occurred())
52     {
53       MESSAGE("---");
54       return;
55     }
56
57   m=PyImport_ImportModule("libVTKGraphicsPython"); // import module if not already imported (new ref)
58   MESSAGE("---");
59
60   if (PyErr_Occurred())
61     {
62       PyErr_Print();
63       MESSAGE("---");
64       return;
65     }
66
67   if ( m ) {
68     md = PyModule_GetDict(m);                        // dict of libVTKGraphicsPython (borrowed ref ; not decref)
69     MESSAGE("---");
70
71     vtkclass=PyDict_GetItemString(md,"vtkRenderer"); // (borrowed ref ; not decref)
72     Py_DECREF(m);                                    // no more need of m
73     MESSAGE("---");
74   }
75 //NRI
76   vtkRenderer *renderer = SALOMEGUI_Swig::getRenderer();
77
78   MESSAGE("---");
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
85 //NRI
86
87 //   vtkclass=PyDict_GetItemString(md,"vtkRenderWindowInteractor"); // (borrowed ref ; not decref)
88 //   Py_DECREF(m);                                    // no more need of m
89 //   MESSAGE("---");
90 //   vtkRenderWindowInteractor *RWInteractor = SALOMEGUI_Swig::getRWInteractor();
91 //   MESSAGE("---");
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
98 }
99
100