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 <vtkPythonUtil.h>
32 #include <vtkVersion.h>
33 #include <vtkRenderer.h>
34 #include <vtkRenderWindow.h>
35 #include <vtkRenderWindowInteractor.h>
37 #include "QAD_Application.h"
38 #include "QAD_Desktop.h"
39 #include "QAD_Study.h"
40 #include "QAD_RightFrame.h"
42 #include "VTKViewer_ViewFrame.h"
43 #include "VTKViewer_RenderWindow.h"
44 #include "VTKViewer_RenderWindowInteractor.h"
46 #include "utilities.h"
51 PyObject* GetPyClass(const char* theClassName){
52 static PyObject *aVTKModule = NULL;
54 if (VTK_MAJOR_VERSION > 3)
55 aVTKModule = PyImport_ImportModule("libvtkRenderingPython");
57 aVTKModule = PyImport_ImportModule("libVTKGraphicsPython");
63 PyObject* aVTKDict = PyModule_GetDict(aVTKModule);
64 char* aClassName = const_cast<char*>(theClassName);
65 PyObject* aPyClass = PyDict_GetItemString(aVTKDict,aClassName);
66 //Py_DECREF(aVTKModule);
71 VTKViewer_ViewFrame* GetVTKViewFrame(){
72 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
73 QAD_StudyFrame* aStudyFrame = aStudy->getActiveStudyFrame();
74 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
75 return dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
79 extern "C" PyObject *libSalomePy_getRenderer(PyObject *self, PyObject *args)
81 if(VTKViewer_ViewFrame* aVTKViewFrame = GetVTKViewFrame()){
82 PyObject* aPyClass = GetPyClass("vtkRenderer");
83 vtkRenderer* aVTKObject = aVTKViewFrame->getRenderer();
84 return PyVTKObject_New(aPyClass,aVTKObject);
90 extern "C" PyObject *libSalomePy_getRenderWindow(PyObject *self, PyObject *args)
92 if(VTKViewer_ViewFrame* aVTKViewFrame = GetVTKViewFrame()){
93 PyObject* aPyClass = GetPyClass("vtkRenderWindow");
94 vtkRenderWindow* aVTKObject = aVTKViewFrame->getRW()->getRenderWindow();
95 return PyVTKObject_New(aPyClass,aVTKObject);
101 extern "C" PyObject *libSalomePy_getRenderWindowInteractor(PyObject *self, PyObject *args)
103 if(VTKViewer_ViewFrame* aVTKViewFrame = GetVTKViewFrame()){
104 PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor");
105 vtkRenderWindowInteractor* aVTKObject = aVTKViewFrame->getRWInteractor();
106 return PyVTKObject_New(aPyClass,aVTKObject);
112 static PyMethodDef Module_Methods[] =
114 {"getRenderer",libSalomePy_getRenderer,METH_NOARGS},
115 {"getRenderWindow",libSalomePy_getRenderWindow,METH_NOARGS},
116 {"getRenderWindowInteractor",libSalomePy_getRenderWindow,METH_NOARGS},
121 extern "C" void initlibSalomePy()
123 static char modulename[] = "libSalomePy";
124 PyObject* aModule = Py_InitModule(modulename, Module_Methods);
125 PyObject* aDict = PyModule_GetDict(aModule);
126 if(PyErr_Occurred()){
130 PyObject* anObj = libSalomePy_getRenderer(NULL,NULL);
131 PyDict_SetItemString(aDict,"renderer",anObj);