Salome HOME
PVViewer: further code split between pure ParaView stuff and SALOME.
[modules/gui.git] / src / PVViewer / PVViewer_ViewManager.cxx
index 74832ce2a66b84acb801948c13de5aa7095346cd..b630ce50173a81f9fc4db20dd88a927aecd6c8a0 100644 (file)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// Author: Adrien Bruneton (CEA)
+
 #include "PVViewer_ViewManager.h"
-#include "PVViewer_ViewModel.h"
 #include "PVViewer_ViewWindow.h"
-#include "PVViewer_LogWindowAdapter.h"
+#include "PVViewer_ViewModel.h"
 #include "PVViewer_GUIElements.h"
-#include "PVViewer_Behaviors.h"
+#include "PVViewer_Core.h"
 #include "PVViewer_EngineWrapper.h"
 
 #include <utilities.h>
-#include <SUIT_MessageBox.h>
+
+#include <LogWindow.h>
 #include <SUIT_Desktop.h>
-#include <SUIT_Session.h>
 #include <SUIT_Study.h>
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
-#include <LogWindow.h>
-
-#include <QApplication>
-#include <QStringList>
-#include <QDir>
-
-#include <string>
 
-#include <pqOptions.h>
 #include <pqServer.h>
-#include <pqSettings.h>
-#include <pqServerDisconnectReaction.h>
-#include <pqPVApplicationCore.h>
-#include <pqTabbedMultiViewWidget.h>
-#include <pqActiveObjects.h>
 #include <pqServerConnectReaction.h>
-
-#include <pqParaViewMenuBuilders.h>
-#include <pqPipelineBrowserWidget.h>
-
-//---------- Static init -----------------
-pqPVApplicationCore* PVViewer_ViewManager::MyCoreApp = 0;
-bool PVViewer_ViewManager::ConfigLoaded = false;
-PVViewer_Behaviors * PVViewer_ViewManager::ParaviewBehaviors = NULL;
+#include <pqActiveObjects.h>
 
 /*!
   Constructor
@@ -64,113 +47,27 @@ PVViewer_ViewManager::PVViewer_ViewManager( SUIT_Study* study, SUIT_Desktop* des
 {
   MESSAGE("PVViewer - view manager created ...")
   setTitle( tr( "PARAVIEW_VIEW_TITLE" ) );
+
   // Initialize minimal paraview stuff (if not already done)
-  ParaviewInitApp(desk, logWindow);
+  PVViewer_Core::ParaviewInitApp(desk, logWindow);
 
   connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
            this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
 }
 
-pqPVApplicationCore * PVViewer_ViewManager::GetPVApplication()
-{
-  return MyCoreApp;
-}
 
-/*!
-  \brief Static method, performs initialization of ParaView session.
-  \param fullSetup whether to instanciate all behaviors or just the minimal ones.
-  \return \c true if ParaView has been initialized successfully, otherwise false
-*/
-bool PVViewer_ViewManager::ParaviewInitApp(SUIT_Desktop * aDesktop, LogWindow * logWindow)
-{
-  if ( ! MyCoreApp) {
-      // Obtain command-line arguments
-      int argc = 0;
-      char** argv = 0;
-      QString aOptions = getenv("PARAVIEW_OPTIONS");
-      QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
-      argv = new char*[aOptList.size() + 1];
-      QStringList args = QApplication::arguments();
-      argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
-      argc++;
-
-      foreach (QString aStr, aOptList) {
-        argv[argc] = strdup( aStr.toLatin1().constData() );
-        argc++;
-      }
-      MyCoreApp = new pqPVApplicationCore (argc, argv);
-      if (MyCoreApp->getOptions()->GetHelpSelected() ||
-          MyCoreApp->getOptions()->GetUnknownArgument() ||
-          MyCoreApp->getOptions()->GetErrorMessage() ||
-          MyCoreApp->getOptions()->GetTellVersion()) {
-          return false;
-      }
-
-      // Direct VTK log messages to our SALOME window - TODO: review this
-      PVViewer_LogWindowAdapter * w = PVViewer_LogWindowAdapter::New();
-      w->setLogWindow(logWindow);
-      vtkOutputWindow::SetInstance(w);
-
-      new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation
-
-      for (int i = 0; i < argc; i++)
-        free(argv[i]);
-      delete[] argv;
-  }
-  // Initialize GUI elements if needed:
-  PVViewer_GUIElements::GetInstance(aDesktop);
-  return true;
-}
-
-void PVViewer_ViewManager::ParaviewInitBehaviors(bool fullSetup, SUIT_Desktop* aDesktop)
-{
-  if (!ParaviewBehaviors)
-      ParaviewBehaviors = new PVViewer_Behaviors(aDesktop);
-
-  if(fullSetup)
-    ParaviewBehaviors->instanciateAllBehaviors(aDesktop);
-  else
-    ParaviewBehaviors->instanciateMinimalBehaviors(aDesktop);
-}
-
-void PVViewer_ViewManager::ParaviewLoadConfigurations(bool force)
-{
-  if (!ConfigLoaded || force)
-    {
-      SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-      QString aPath = resMgr->stringValue("resources", "PVViewer", QString());
-      if (!aPath.isNull()) {
-          MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
-          MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
-      }
-      ConfigLoaded = true;
-    }
-}
-
-void PVViewer_ViewManager::ParaviewCleanup()
+PVViewer_EngineWrapper * PVViewer_ViewManager::GetEngine()
 {
-  // Disconnect from server
-  pqServer* server = pqActiveObjects::instance().activeServer();
-  if (server && server->isRemote())
-    {
-      MESSAGE("~PVViewer_Module(): Disconnecting from remote server ...");
-      pqServerDisconnectReaction::disconnectFromServer();
-    }
-
-  pqApplicationCore::instance()->settings()->sync();
-
-  pqPVApplicationCore * app = GetPVApplication();
-  // Schedule destruction of PVApplication singleton:
-  if (app)
-    app->deleteLater();
+  return PVViewer_EngineWrapper::GetInstance();
 }
 
-PVViewer_EngineWrapper * PVViewer_ViewManager::GetEngine()
+QString PVViewer_ViewManager::GetPVConfigPath()
 {
-  return PVViewer_EngineWrapper::GetInstance();
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+  return resMgr->stringValue("resources", "PVViewer", QString());
 }
 
-bool PVViewer_ViewManager::ConnectToExternalPVServer(SUIT_Desktop* aDesktop)
+bool PVViewer_ViewManager::ConnectToExternalPVServer(QMainWindow* aDesktop)
 {
   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
   bool noConnect = aResourceMgr->booleanValue( "PARAVIS", "no_ext_pv_server", false );
@@ -231,11 +128,6 @@ bool PVViewer_ViewManager::ConnectToExternalPVServer(SUIT_Desktop* aDesktop)
   return true;
 }
 
-void PVViewer_ViewManager::onEmulateApply()
-{
-  PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desktop);
-  guiElements->onEmulateApply();
-}
 
 /*!Enable toolbars if view \a view is ParaView viewer and disable otherwise.
 */