Salome HOME
[PVViewer] Add Catalyst menu
[modules/paravis.git] / src / PVGUI / PVGUI_Module.cxx
index 42cad016b7a2f7e6fe746a60a55aee73ab7d009e..8e3d3f638de701c2ea399377f6d7e7f33d194504 100644 (file)
@@ -1,6 +1,6 @@
 // PARAVIS : ParaView wrapper SALOME module
 //
-// Copyright (C) 2010-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -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
@@ -141,7 +141,7 @@ PVGUI_Module* ParavisModule = 0;
 
 /*!
   \class PVGUI_Module
-  \brief Implementation 
+  \brief Implementation
          SALOME module wrapping ParaView GUI.
 */
 
@@ -166,6 +166,9 @@ PVGUI_Module::PVGUI_Module()
   : LightApp_Module( PARAVIS_MODULE_NAME ),
     mySourcesMenuId( -1 ),
     myFiltersMenuId( -1 ),
+#ifdef PVCATALYST_ENABLED
+    myCatalystMenuId(-1),
+#endif
     myMacrosMenuId(-1),
     myRecentMenuId(-1),
     myOldMsgHandler(0),
@@ -208,9 +211,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();
 }
 
 /*!
@@ -333,7 +336,7 @@ void PVGUI_Module::initialize( CAM_Application* app )
   }
 
   updateMacros();
+
   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
   bool isStop = aResourceMgr->booleanValue( PARAVIS_MODULE_NAME, "stop_trace", false );
   if(!isStop)
@@ -347,7 +350,7 @@ void PVGUI_Module::initialize( CAM_Application* app )
     }
 
   this->VTKConnect = vtkEventQtSlotConnect::New();
-  
+
   vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
   if(pm) {
     vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
@@ -361,6 +364,7 @@ void PVGUI_Module::initialize( CAM_Application* app )
       }
     }
   }
+  connect( application(), SIGNAL( appClosed() ), this, SLOT( onStopTrace() ) );
 }
 
 /*!
@@ -388,7 +392,7 @@ void PVGUI_Module::onEndProgress()
 void PVGUI_Module::onDataRepresentationUpdated() {
   LightApp_Study* activeStudy = dynamic_cast<LightApp_Study*>(application()->activeStudy());
   if(!activeStudy) return;
-  
+
   activeStudy->Modified();
 }
 
@@ -399,7 +403,7 @@ void PVGUI_Module::onInitTimer()
 {
   startTrace();
 }
-  
+
 /*!
   \brief Get list of embedded macros files
 */
@@ -430,7 +434,7 @@ void PVGUI_Module::updateMacros()
   if(!aPythonManager)  {
     return;
   }
-  
+
   foreach (QString aStr, getEmbeddedMacrosList()) {
     aPythonManager->addMacro(aStr);
   }
@@ -475,7 +479,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 +516,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 +538,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 +569,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();
@@ -555,6 +584,9 @@ bool PVGUI_Module::activateModule( SUIT_Study* study )
   showView( true );
   if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
   if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
+#ifdef PVCATALYST_ENABLED
+  if ( myCatalystMenuId != -1 ) menuMgr()->show(myCatalystMenuId);
+#endif
   if ( myMacrosMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
 
   // Update the various menus with the content pre-loaded in myGuiElements
@@ -562,6 +594,10 @@ bool PVGUI_Module::activateModule( SUIT_Study* study )
 //  myGuiElements->updateSourcesMenu(srcMenu);
 //  QMenu* filtMenu = menuMgr()->findMenu( myFiltersMenuId );
 //  myGuiElements->updateFiltersMenu(filtMenu);
+//#ifdef PVCATALYST_ENABLED
+//  QMenu* catalystMenu = menuMgr()->findMenu( myCatalystMenuId );
+//  myGuiElements->updateCatalystMenu(catalystMenu);
+//#endif
 //  QMenu* macMenu = menuMgr()->findMenu( myMacrosMenuId );
 //  myGuiElements->updateMacrosMenu(macMenu);
 
@@ -588,7 +624,7 @@ bool PVGUI_Module::activateModule( SUIT_Study* study )
   }
 
   if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
-  
+
   return isDone;
 }
 
@@ -633,6 +669,9 @@ bool PVGUI_Module::deactivateModule( SUIT_Study* study )
   menuMgr()->hide(myRecentMenuId);
   menuMgr()->hide(mySourcesMenuId);
   menuMgr()->hide(myFiltersMenuId);
+#ifdef PVCATALYST_ENABLED
+  menuMgr()->hide(myCatalystMenuId);
+#endif
   menuMgr()->hide(myMacrosMenuId);
   setMenuShown( false );
   setToolShown( false );
@@ -642,10 +681,13 @@ 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 );
 }
 
@@ -675,7 +717,7 @@ void PVGUI_Module::studyClosed(SUIT_Study* study)
 {
   showView(false); // VSR: this seems to be not needed (all views are automatically closed)
   clearParaviewState();
-  //Re-start trace 
+  //Re-start trace
   onRestartTrace();
 
   LightApp_Module::studyClosed(study);
@@ -693,7 +735,7 @@ void PVGUI_Module::openFile( const char* theName )
 
 /*!
   \brief Starts Python trace.
+
   Start trace invoking the newly introduced C++ API (PV 4.2)
   (inspired from pqTraceReaction::start())
 */
@@ -737,7 +779,7 @@ void PVGUI_Module::executeScript( const char* script )
   if ( manager )  {
     pqPythonDialog* pyDiag = manager->pythonShellDialog();
     if ( pyDiag ) {
-      pyDiag->runString(script);  
+      pyDiag->runString(script);
     }
   }
 #endif
@@ -797,24 +839,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 +880,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 +899,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() );
 }
 
 /*!
@@ -890,10 +933,9 @@ void PVGUI_Module::createPreferences()
   // Paravis settings tab
   int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
 
-  addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab, 
+  addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab,
                  LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "no_ext_pv_server" );
 
-  /* VSR: not used
   int aSaveType = addPreference( tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
                                  LightApp_Preferences::Selector,
                                  PARAVIS_MODULE_NAME, "savestate_type" );
@@ -904,12 +946,11 @@ void PVGUI_Module::createPreferences()
   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, 
+  int stopTrace = addPreference( tr( "PREF_STOP_TRACE" ), traceGroup,
                                  LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
   setPreferenceProperty( stopTrace, "restart",  true );
 
@@ -949,13 +990,20 @@ void PVGUI_Module::onRestartTrace()
   startTrace();
 }
 
+/*!
+  \brief. Close ParaView python trace.
+*/
+void PVGUI_Module::onStopTrace()
+{
+  stopTrace();
+}
 /*!
   \brief Called when view manager is added
 */
 void PVGUI_Module::onViewManagerAdded( SUIT_ViewManager* vm )
 {
   if ( PVViewer_ViewManager* pvvm = dynamic_cast<PVViewer_ViewManager*>( vm ) ) {
-    connect( pvvm, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), 
+    connect( pvvm, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
              this, SLOT( onPVViewCreated( SUIT_ViewWindow* ) ) );
     connect( pvvm, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
              this,  SLOT( onPVViewDelete( SUIT_ViewWindow* ) ) );
@@ -1008,7 +1056,7 @@ extern "C" {
   PVGUI_EXPORT CAM_Module* createModule() {
     return new PVGUI_Module();
   }
-  
+
   PVGUI_EXPORT char* getModuleVersion() {
     return (char*)PARAVIS_VERSION_STR;
   }