Salome HOME
From Community Forum: libSalomePy.getRenderer() does not work
authorvsr <vsr@opencascade.com>
Thu, 21 Jan 2021 08:33:11 +0000 (11:33 +0300)
committervsr <vsr@opencascade.com>
Thu, 21 Jan 2021 08:33:11 +0000 (11:33 +0300)
src/SALOME_PY/CMakeLists.txt
src/SALOME_PY/SalomePy.cxx
src/SALOME_PY/test_vtk_rendering_module.py [new file with mode: 0644]

index ec5b16d431659bac1a09da6e3c978318f8579740..e7825e2a05ac206ab0e3523161a85bc15e8af0aa 100644 (file)
@@ -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)
index 3bf9cf31f3f8f78fc66a0031f593f221d8d56576..3087b1eb705840bed54f6c30cc841c20314b2073 100644 (file)
@@ -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 (file)
index 0000000..25b466a
--- /dev/null
@@ -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)