Salome HOME
PV version is now bfaf7b82ed22ee (master of 17th of january 2019)
[modules/paravis.git] / src / PVGUI / PVGUI_Module.cxx
index 342af676ab75f1572a9931a45c5f801de88a4a52..02cc591668d560bb81929f488c044615f8ac326e 100644 (file)
@@ -1,6 +1,6 @@
 // PARAVIS : ParaView wrapper SALOME module
 //
-// Copyright (C) 2010-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2019  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
@@ -87,7 +87,6 @@
 #include <vtkProcessModule.h>
 #include <vtkPVSession.h>
 #include <vtkPVProgressHandler.h>
-#include <vtkOutputWindow.h>
 #include <vtkEventQtSlotConnect.h>
 #include <vtkNew.h>
 #include <vtkSMProxy.h>
 #include <pqActiveObjects.h>
 #include <pqHelpReaction.h>
 #include <pqPluginManager.h>
-#include <pqPythonDialog.h>
+//#include <pqPythonDialog.h>
 #include <pqPythonManager.h>
 #include <pqLoadDataReaction.h>
 #include <pqPythonScriptEditor.h>
 #include <pqAnimationScene.h>
 #include <pqServerManagerModel.h>
 #include <pqAnimationTimeToolbar.h>
+#include <pqPipelineBrowserWidget.h>
+#include <pqCoreUtilities.h>
 
 #if PY_VERSION_HEX < 0x03050000
 static char*
@@ -191,20 +192,6 @@ PVGUI_Module::PVGUI_Module()
   Q_INIT_RESOURCE( PVGUI );
 #endif
   ParavisModule = this;
-
-  // Clear old copies of embedded macros files
-  QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
-  QStringList aFilter;
-  aFilter << "*.py";
-
-  QDir aDestDir(aDestPath);
-  QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
-  foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
-    QString aMacrosName = QFileInfo(aMacrosPath).fileName();
-    if (aDestFiles.contains(aMacrosName)) {
-      aDestDir.remove(aMacrosName);
-    }
-  }
 }
 
 /*!
@@ -269,9 +256,26 @@ void PVGUI_Module::initialize( CAM_Application* app )
 
   // Initialize ParaView client and associated behaviors
   // and connect to externally launched pvserver
-  PVViewer_Core::ParaviewInitApp(aDesktop, anApp->logWindow());
+  PVViewer_Core::ParaviewInitApp(aDesktop);
+
+  // Clear old copies of embedded macros files
+  //QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
+  QString aDestPath = pqCoreUtilities::getParaViewUserDirectory() + "/Macros";
+  QStringList aFilter;
+  aFilter << "*.py";
+
+  QDir aDestDir(aDestPath);
+  QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
+  foreach(QString aMacrosPath, getEmbeddedMacrosList()) {
+         QString aMacrosName = QFileInfo(aMacrosPath).fileName();
+         if (aDestFiles.contains(aMacrosName)) {
+                 aDestDir.remove(aMacrosName);
+         }
+  }
+
   myGuiElements = PVViewer_GUIElements::GetInstance(aDesktop);
 
+
   // [ABN]: careful with the order of the GUI element creation, the loading of the configuration
   // and the connection to the server. This order is very sensitive if one wants to make
   // sure all menus, etc ... are correctly populated.
@@ -478,7 +482,7 @@ void PVGUI_Module::showView( bool toShow )
   PVViewer_ViewManager* viewMgr =
     dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), false ) );
   if ( !viewMgr ) {
-    viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop(), anApp->logWindow() );
+    viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop() );
     anApp->addViewManager( viewMgr );
     connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
              anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
@@ -527,51 +531,7 @@ void PVGUI_Module::endWaitCursor()
 {
   QApplication::restoreOverrideCursor();
 }
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-/*!
-  \brief Handler method for the output of messages.
-*/
-static void ParavisMessageOutput(QtMsgType type, const char *msg)
-{
-  switch(type)
-    {
-  case QtDebugMsg:
-    vtkOutputWindow::GetInstance()->DisplayText(msg);
-    break;
-  case QtWarningMsg:
-    vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
-    break;
-  case QtCriticalMsg:
-    vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
-    break;
-  case QtFatalMsg:
-    vtkOutputWindow::GetInstance()->DisplayErrorText(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
@@ -580,11 +540,6 @@ static void ParavisMessageOutput(QtMsgType type, const QMessageLogContext &conte
 */
 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();
@@ -629,7 +584,13 @@ bool PVGUI_Module::activateModule( SUIT_Study* study )
   }
 
   if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
-  
+
+  // VSR 18/10/2018 - 0023170: Workaround to re-select current index after module activation
+  QItemSelectionModel* selection_model = myGuiElements->getPipelineBrowserWidget()->getSelectionModel();
+  QModelIndex idx = selection_model->currentIndex();
+  selection_model->clearCurrentIndex();
+  selection_model->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
+
   return isDone;
 }
 
@@ -684,11 +645,8 @@ 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 );
@@ -776,6 +734,19 @@ void PVGUI_Module::stopTrace()
 */
 void PVGUI_Module::executeScript( const char* script )
 {
+  // ???
+  // Not sure this is the right fix, but the PYTHON_MANAGER has a function named
+  // executeScript() which seems to do what the runScript on pyShellDialog() class
+  // was doing.
+#ifndef WNT
+  pqPythonManager* manager =
+    qobject_cast<pqPythonManager*>(pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
+
+  if ( manager )  {
+    manager->executeScript(script);
+  }
+#endif
+  /*
 #ifndef WNT
   pqPythonManager* manager = qobject_cast<pqPythonManager*>(
                              pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
@@ -786,6 +757,7 @@ void PVGUI_Module::executeScript( const char* script )
     }
   }
 #endif
+  */
 }
 
 ///**