1 // SALOME SALOME_PY : binding of VTK graphics and Python
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SalomePy.cxx
25 // Author : Paul RASCLE, EDF
30 #include <vtkRenderer.h>
31 #include <vtkRenderWindowInteractor.h>
32 #include <vtkPythonUtil.h>
33 #include <vtkVersion.h>
34 #include "utilities.h"
35 #include "QAD_Study.h"
36 #include "QAD_RightFrame.h"
37 #include "QAD_Application.h"
38 #include "QAD_Desktop.h"
39 #include "VTKViewer_ViewFrame.h"
44 static PyObject * libSalomePy_getRenderer(PyObject *self, PyObject *args);
47 static PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args)
49 if (!PyArg_ParseTuple(args, ":getRenderer"))
51 // exemple retournant systematiquement Py_None
56 static PyMethodDef Module_Methods[] =
58 {"getRenderer", libSalomePy_getRenderer, METH_VARARGS},
62 extern "C" { void initlibSalomePy();}
64 void initlibSalomePy()
66 PyObject *m, *d, *c, *md, *obj, *vtkclass;
68 static char modulename[] = "libSalomePy";
70 m = Py_InitModule(modulename, Module_Methods);
72 d = PyModule_GetDict(m);
74 // DANGEROUS : if (!d) Py_FatalError("can't get dictionary for module SalomePy!");
81 if (VTK_MAJOR_VERSION > 3)
82 m=PyImport_ImportModule("libvtkRenderingPython"); // import module if not already imported (new ref)
84 m=PyImport_ImportModule("libVTKGraphicsPython"); // import module if not already imported (new ref)
96 md = PyModule_GetDict(m); // dict of libvtkGraphicsPython (borrowed ref ; not decref)
99 vtkclass=PyDict_GetItemString(md,"vtkRenderer"); // (borrowed ref ; not decref)
100 Py_DECREF(m); // no more need of m
104 //san:T3.13 - move getRenderer() implementation here
105 //vtkRenderer *renderer = SALOMEGUI_Swig::getRenderer();
106 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
107 int nbStudyFrames = myStudy->getStudyFramesCount();
108 vtkRenderer *renderer = NULL;
110 if (viewId == -1) // find the first frame with VTK viewer & get renderer
113 for(i=0; i<nbStudyFrames; i++)
115 if ( myStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK )
117 renderer = ((VTKViewer_ViewFrame*)myStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getRenderer();
122 else // get the VTK renderer of a given frame
125 if ((viewId >=0) && (viewId <nbStudyFrames))
126 renderer = ((VTKViewer_ViewFrame*)myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame())->getRenderer();
128 if (renderer == NULL) INFOS("No VTK Renderer available !");
129 //san:T3.13 - move getRenderer() implementation here
132 obj = PyVTKObject_New(vtkclass,renderer); // (new ref)
133 MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
134 PyDict_SetItemString(d,"renderer",obj); // (add a ref to obj ; has to be decref)
135 MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
136 Py_DECREF(obj); // only one ref is sufficient
137 MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
140 // vtkclass=PyDict_GetItemString(md,"vtkRenderWindowInteractor"); // (borrowed ref ; not decref)
141 // Py_DECREF(m); // no more need of m
143 // vtkRenderWindowInteractor *RWInteractor = SALOMEGUI_Swig::getRWInteractor();
145 // obj = PyVTKObject_New(vtkclass,RWInteractor); // (new ref)
146 // MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
147 // PyDict_SetItemString(d,"interactor",obj); // (add a ref to obj ; has to be decref)
148 // MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp
149 // Py_DECREF(obj); // only one ref is sufficient
150 // MESSAGE( "Nombre de references sur obj : " << obj->ob_refcnt ); // sys.getrefcount(o) gives ref count + 1 in Python interp