From f5e9fedd434c9ef8a2fefa9c2a82715ca11f2ee4 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 21 Jan 2021 11:33:11 +0300 Subject: [PATCH] From Community Forum: libSalomePy.getRenderer() does not work --- src/SALOME_PY/CMakeLists.txt | 4 ++++ src/SALOME_PY/SalomePy.cxx | 14 +------------- src/SALOME_PY/test_vtk_rendering_module.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 src/SALOME_PY/test_vtk_rendering_module.py diff --git a/src/SALOME_PY/CMakeLists.txt b/src/SALOME_PY/CMakeLists.txt index ec5b16d43..e7825e2a0 100644 --- a/src/SALOME_PY/CMakeLists.txt +++ b/src/SALOME_PY/CMakeLists.txt @@ -62,3 +62,7 @@ IF(WIN32) ENDIF(WIN32) # TODO: check if PYTHON_ADD_MODULE() macro can be used to build this target + +# --- tests --- + +ADD_TEST(NAME GUI_libSalomePy COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/test_vtk_rendering_module.py) diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 3bf9cf31f..3087b1eb7 100644 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -118,7 +118,7 @@ static PyTypeObject* GetPyClass( const char* theClassName ) static PyObject* aVTKModule = 0; PyObject* aPyClass = 0; if( !aVTKModule ) { - aVTKModule = PyImport_ImportModule( "vtk.vtkRenderingCorePython" ); + aVTKModule = PyImport_ImportModule( "vtk.vtkRenderingCore" ); if( PyErr_Occurred() ) { PyErr_Print(); } @@ -221,11 +221,7 @@ public: ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate, myKeepDetached ); if( aVTKViewWindow && aPyClass ) { vtkRenderer* aVTKObject = aVTKViewWindow->getRenderer(); -#if VTK_XVERSION < 50700 - myResult = PyVTKObject_New( aPyClass, aVTKObject ); -#else myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject ); -#endif } } }; @@ -276,11 +272,7 @@ public: ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate, myKeepDetached ); if( aVTKViewWindow && aPyClass ) { vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow(); -#if VTK_XVERSION < 50700 - myResult = PyVTKObject_New( aPyClass, aVTKObject ); -#else myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject ); -#endif } } }; @@ -331,11 +323,7 @@ public: ::GetVTKViewWindow( myCreate ? __Create : __FindOrCreate, myKeepDetached ); if( aVTKViewWindow && aPyClass ) { vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor(); -#if VTK_XVERSION < 50700 - myResult = PyVTKObject_New( aPyClass, aVTKObject ); -#else myResult = PyVTKObject_FromPointer( aPyClass, NULL, aVTKObject ); -#endif } } }; diff --git a/src/SALOME_PY/test_vtk_rendering_module.py b/src/SALOME_PY/test_vtk_rendering_module.py new file mode 100644 index 000000000..25b466a26 --- /dev/null +++ b/src/SALOME_PY/test_vtk_rendering_module.py @@ -0,0 +1,14 @@ +import sys + +# Try importing the same VTK module as used by libSalomePy +try: + import vtk.vtkRenderingCore + ok = True +except Exception as e: + ok = False + +# VTK rendering Python module might change in newer versions of ParaView +# In this case ask developers to modify SalomePy.cxx correspondingly +if not ok: + print("VTK Rendering Python module seems to have changed, libSalomePy may not work, please correct this!") + sys.exit(1) -- 2.39.2