Salome HOME
Copyright update 2022
[modules/gui.git] / src / PVViewer / PVViewer_Core.cxx
index 5627c517a6be4a933da17db701a4a327cc51a0ca..6b4205eef762f03cbf0d57a844e7c0bce6c77228 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 
 #include "PVViewer_Core.h"
-#include "PVViewer_LogWindowAdapter.h"
+#include "PVViewer_OutputWindow.h"
 #include "PVViewer_GUIElements.h"
 #include "PVViewer_Behaviors.h"
 #include "PVViewer_Core.h"
 
+#include <Qtx.h>
+
 #include <QApplication>
 #include <QStringList>
 #include <QDir>
 #include <QMainWindow>
+#include <QStandardPaths>
 
 #include <string>
 
@@ -57,15 +60,17 @@ pqPVApplicationCore * PVViewer_Core::GetPVApplication()
   \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_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindow)
+bool PVViewer_Core::ParaviewInitApp(QMainWindow * /*aDesktop*/)
 {
   if ( ! MyCoreApp) {
       // Obtain command-line arguments
       int argc = 0;
       char** argv = 0;
-      QString aOptions = getenv("PARAVIEW_OPTIONS");
+      QString aOptions = Qtx::getenv("PARAVIEW_OPTIONS");
       QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
-      argv = new char*[aOptList.size() + 1];
+      argv = new char*[aOptList.size() + 4]; // add one, MPI requires argv[argc] = 0!
+      for (int i =0; i< aOptList.size() + 4; i++)
+          argv[i] = 0;
       QStringList args = QApplication::arguments();
       argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
       argc++;
@@ -74,6 +79,25 @@ bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindo
         argv[argc] = strdup( aStr.toLatin1().constData() );
         argc++;
       }
+      argv[argc++] = strdup("--multi-servers");
+      // Make salome sharing the same server configuration than external one with "salome shell paraview"
+      QStringList li(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation));
+      foreach(QString pathConfig,li)
+        {
+          QFileInfo fi(QDir(pathConfig),QString("ParaView"));
+          if(fi.exists() && fi.isDir())
+            {
+              QFileInfo fi2(fi.canonicalFilePath(),"servers.pvsc");
+              if(fi2.exists() && fi2.isFile())
+                {
+                  QString addEntry(QString("--servers-file=%1").arg(fi2.canonicalFilePath()));
+                  std::string addEntry2(addEntry.toStdString());
+                  argv[argc++] = strdup(addEntry2.c_str());
+                  break;
+                }
+            }
+        }
+      //
       MyCoreApp = new pqPVApplicationCore (argc, argv);
       if (MyCoreApp->getOptions()->GetHelpSelected() ||
           MyCoreApp->getOptions()->GetUnknownArgument() ||
@@ -83,8 +107,7 @@ bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindo
       }
 
       // Direct VTK log messages to our SALOME window - TODO: review this
-      PVViewer_LogWindowAdapter * w = PVViewer_LogWindowAdapter::New();
-      w->setLogWindow(logWindow);
+      PVViewer_OutputWindow * w = PVViewer_OutputWindow::New();
       vtkOutputWindow::SetInstance(w);
 
       new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation
@@ -93,9 +116,11 @@ bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindo
         free(argv[i]);
       delete[] argv;
   }
-  // Initialize GUI elements if needed:
-  PVViewer_GUIElements::GetInstance(aDesktop);
-  return true;
+   // Initialization of ParaView GUI widgets will be done when these widgets are
+   // really needed.
+   // PVViewer_GUIElements* inst = PVViewer_GUIElements::GetInstance(aDesktop);
+   // inst->getPropertiesPanel();
+   return true;
 }
 
 void PVViewer_Core::ParaviewInitBehaviors(bool fullSetup, QMainWindow* aDesktop)