Salome HOME
Suppress compiler warning.
[modules/paravis.git] / src / PVGUI / PVGUI_Module.cxx
index dbc634408e4f8420a0ef2f053881f0d56e70f1d2..6fa52dbe326922aa6be2150da2569db368740308 100644 (file)
@@ -36,7 +36,7 @@
 #include "PVViewer_ViewModel.h"
 #include "PVGUI_ParaViewSettingsPane.h"
 #include "PVViewer_GUIElements.h"
-#include "PVViewer_EngineWrapper.h"
+#include "PVServer_ServiceWrapper.h"
 #include "PVGUI_DataModel.h"
 
 // SALOME Includes
@@ -208,9 +208,9 @@ PVGUI_Module::~PVGUI_Module()
   by the PVViewer code in GUI (class PVViewer_EngineWrapper).
   \sa GetCPPEngine()
 */
-PVViewer_EngineWrapper* PVGUI_Module::GetEngine()
+PVServer_ServiceWrapper* PVGUI_Module::GetEngine()
 {
-  return PVViewer_EngineWrapper::GetInstance();
+  return PVServer_ServiceWrapper::GetInstance();
 }
 
 /*!
@@ -361,6 +361,7 @@ void PVGUI_Module::initialize( CAM_Application* app )
       }
     }
   }
+  connect( application(), SIGNAL( appClosed() ), this, SLOT( onStopTrace() ) );
 }
 
 /*!
@@ -475,7 +476,7 @@ void PVGUI_Module::showView( bool toShow )
     // this also connects to the pvserver and instantiates relevant PV behaviors
   }
 
-  pvWnd->setShown( toShow );
+  pvWnd->setVisible( toShow );
   if ( toShow ) pvWnd->setFocus();
 }
 
@@ -512,7 +513,7 @@ void PVGUI_Module::endWaitCursor()
 {
   QApplication::restoreOverrideCursor();
 }
-
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 /*!
   \brief Handler method for the output of messages.
 */
@@ -534,7 +535,29 @@ static void ParavisMessageOutput(QtMsgType type, const char *msg)
     break;
     }
 }
-
+#else
+/*!
+  \brief Handler method for the output of messages.
+*/
+static void ParavisMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+{
+  switch(type)
+    {
+  case QtDebugMsg:
+    vtkOutputWindow::GetInstance()->DisplayText(msg.toLatin1().constData());
+    break;
+  case QtWarningMsg:
+    vtkOutputWindow::GetInstance()->DisplayErrorText(msg.toLatin1().constData());
+    break;
+  case QtCriticalMsg:
+    vtkOutputWindow::GetInstance()->DisplayErrorText(msg.toLatin1().constData());
+    break;
+  case QtFatalMsg:
+    vtkOutputWindow::GetInstance()->DisplayErrorText(msg.toLatin1().constData());
+    break;
+    }
+}
+#endif
 /*!
   \brief Activate module.
   \param study current study
@@ -543,8 +566,11 @@ static void ParavisMessageOutput(QtMsgType type, const char *msg)
 */
 bool PVGUI_Module::activateModule( SUIT_Study* study )
 {
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
   myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
-  
+#else
+  myOldMsgHandler = qInstallMessageHandler(ParavisMessageOutput);
+#endif  
   SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
 
   storeCommonWindowsState();
@@ -642,8 +668,11 @@ bool PVGUI_Module::deactivateModule( SUIT_Study* study )
   SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
 
   if (myOldMsgHandler)
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     qInstallMsgHandler(myOldMsgHandler);
-
+#else
+    qInstallMessageHandler(myOldMsgHandler);
+#endif
   restoreCommonWindowsState();
   
   return LightApp_Module::deactivateModule( study );
@@ -797,24 +826,25 @@ QString PVGUI_Module::getTraceString()
   }
 
   // Save camera position to, which is no longer output by the tracer ...
-  VTK_PY_GIL_ENSURE
-  PyObject * mods(PySys_GetObject(const_cast<char*>("modules")));
-  PyObject * trace_mod(PyDict_GetItemString(mods, "paraview.smtrace"));  // module was already (really) imported by vtkSMTrace
-  if (PyModule_Check(trace_mod)) {
-      vtkSmartPyObject save_cam(PyObject_GetAttrString(trace_mod, const_cast<char*>("SaveCameras")));
-      vtkSmartPyObject camera_trace(PyObject_CallMethod(save_cam, const_cast<char*>("get_trace"), NULL));
-      // Convert to a single string
-      vtkSmartPyObject ret(PyString_FromString(end_line.toStdString().c_str()));
-      vtkSmartPyObject final_string(PyObject_CallMethod(ret, const_cast<char*>("join"),
-          const_cast<char*>("O"), (PyObject*)camera_trace));
-      if (PyString_CheckExact(final_string))
-        {
-          QString camera_qs(PyString_AsString(final_string));  // deep copy
-          traceString = traceString + end_line  + end_line + QString("#### saving camera placements for all active views")
-              + end_line + end_line + camera_qs + end_line;
-        }
-    }
-  VTK_PY_GIL_RELEASE
+  {
+    vtkPythonScopeGilEnsurer psge;
+    PyObject * mods(PySys_GetObject(const_cast<char*>("modules")));
+    PyObject * trace_mod(PyDict_GetItemString(mods, "paraview.smtrace"));  // module was already (really) imported by vtkSMTrace
+    if (PyModule_Check(trace_mod)) {
+        vtkSmartPyObject save_cam(PyObject_GetAttrString(trace_mod, const_cast<char*>("SaveCameras")));
+        vtkSmartPyObject camera_trace(PyObject_CallMethod(save_cam, const_cast<char*>("get_trace"), NULL));
+        // Convert to a single string
+        vtkSmartPyObject ret(PyString_FromString(end_line.toStdString().c_str()));
+        vtkSmartPyObject final_string(PyObject_CallMethod(ret, const_cast<char*>("join"),
+            const_cast<char*>("O"), (PyObject*)camera_trace));
+        if (PyString_CheckExact(final_string))
+          {
+            QString camera_qs(PyString_AsString(final_string));  // deep copy
+            traceString = traceString + end_line  + end_line + QString("#### saving camera placements for all active views")
+                + end_line + end_line + camera_qs + end_line;
+          }
+      }
+  } 
 
   return traceString;
 }
@@ -837,9 +867,9 @@ void PVGUI_Module::saveTrace( const char* theName )
 /*!
   \brief Saves ParaView state to a disk file
 */
-void PVGUI_Module::saveParaviewState( const char* theFileName )
+void PVGUI_Module::saveParaviewState( const QString& theFileName )
 {
-  pqApplicationCore::instance()->saveState( theFileName );
+  pqApplicationCore::instance()->saveState( theFileName.toStdString().c_str() );
 }
 
 /*!
@@ -856,9 +886,9 @@ void PVGUI_Module::clearParaviewState()
 /*!
   \brief Restores ParaView state from a disk file
 */
-void PVGUI_Module::loadParaviewState( const char* theFileName )
+void PVGUI_Module::loadParaviewState( const QString& theFileName )
 {
-  pqApplicationCore::instance()->loadState( theFileName, getActiveServer() );
+  pqApplicationCore::instance()->loadState( theFileName.toStdString().c_str(), getActiveServer() );
 }
 
 /*!
@@ -875,6 +905,9 @@ pqServer* PVGUI_Module::getActiveServer()
 */
 void PVGUI_Module::createPreferences()
 {
+  QList<QVariant> aIndices;
+  QStringList aStrings;
+
   // Paraview settings tab
   int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
 
@@ -886,8 +919,6 @@ void PVGUI_Module::createPreferences()
 
   // Paravis settings tab
   int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
-  addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab, 
-                 LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
 
   addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab, 
                  LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "no_ext_pv_server" );
@@ -896,24 +927,30 @@ void PVGUI_Module::createPreferences()
                                  LightApp_Preferences::Selector,
                                  PARAVIS_MODULE_NAME, "savestate_type" );
 
-  int aTraceType = addPreference( tr( "PREF_TRACE_TYPE_LBL" ), aParaVisSettingsTab,
-                                 LightApp_Preferences::Selector,
-                                 PARAVIS_MODULE_NAME, "tracestate_type" );
-  QList<QVariant> aIndices;
-  QStringList aStrings;
+  aStrings.clear();
+  aIndices.clear();
   aIndices << 0 << 1 << 2;
-  aStrings << tr("PREF_SAVE_TYPE_0");
-  aStrings << tr("PREF_SAVE_TYPE_1");
-  aStrings << tr("PREF_SAVE_TYPE_2");
+  aStrings << tr("PREF_SAVE_TYPE_0") << tr("PREF_SAVE_TYPE_1") << tr("PREF_SAVE_TYPE_2");
   setPreferenceProperty( aSaveType, "strings", aStrings );
   setPreferenceProperty( aSaveType, "indexes", aIndices );
 
+  // ... "Language" group <<start>>
+  int traceGroup = addPreference( tr( "PREF_GROUP_TRACE" ), aParaVisSettingsTab );
+
+  int stopTrace = addPreference( tr( "PREF_STOP_TRACE" ), traceGroup, 
+                                 LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
+  setPreferenceProperty( stopTrace, "restart",  true );
+
+  int aTraceType = addPreference( tr( "PREF_TRACE_TYPE_LBL" ), traceGroup,
+                                 LightApp_Preferences::Selector,
+                                 PARAVIS_MODULE_NAME, "tracestate_type" );
   aStrings.clear();
-  aStrings << tr("PREF_TRACE_TYPE_0");
-  aStrings << tr("PREF_TRACE_TYPE_1");
-  aStrings << tr("PREF_TRACE_TYPE_2");
+  aIndices.clear();
+  aIndices << 0 << 1 << 2;
+  aStrings << tr("PREF_TRACE_TYPE_0") << tr("PREF_TRACE_TYPE_1") << tr("PREF_TRACE_TYPE_2");
   setPreferenceProperty( aTraceType, "strings", aStrings );
   setPreferenceProperty( aTraceType, "indexes", aIndices );
+  setPreferenceProperty( aTraceType, "restart",  true );
 }
 
 /*!
@@ -940,6 +977,13 @@ void PVGUI_Module::onRestartTrace()
   startTrace();
 }
 
+/*!
+  \brief. Close ParaView python trace.
+*/
+void PVGUI_Module::onStopTrace()
+{
+  stopTrace();
+}
 /*!
   \brief Called when view manager is added
 */