1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Adrien Bruneton (CEA)
22 #include "PVViewer_Core.h"
23 #include "PVViewer_OutputWindow.h"
24 #include "PVViewer_GUIElements.h"
25 #include "PVViewer_Behaviors.h"
26 #include "PVViewer_Core.h"
30 #include <QApplication>
31 #include <QStringList>
33 #include <QMainWindow>
34 #include <QStandardPaths>
38 #include <pqOptions.h>
39 #include <pqSettings.h>
40 #include <pqPVApplicationCore.h>
41 #include <pqTabbedMultiViewWidget.h>
42 #include <pqParaViewMenuBuilders.h>
43 #include <pqActiveObjects.h>
44 #include <pqPipelineBrowserWidget.h>
45 #include <pqServerDisconnectReaction.h>
48 //---------- Static init -----------------
49 pqPVApplicationCore* PVViewer_Core::MyCoreApp = 0;
50 bool PVViewer_Core::ConfigLoaded = false;
51 PVViewer_Behaviors * PVViewer_Core::ParaviewBehaviors = NULL;
53 pqPVApplicationCore * PVViewer_Core::GetPVApplication()
59 \brief Static method, performs initialization of ParaView session.
60 \param fullSetup whether to instanciate all behaviors or just the minimal ones.
61 \return \c true if ParaView has been initialized successfully, otherwise false
63 bool PVViewer_Core::ParaviewInitApp(QMainWindow * /*aDesktop*/)
66 // Obtain command-line arguments
69 QString aOptions = Qtx::getenv("PARAVIEW_OPTIONS");
70 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
71 argv = new char*[aOptList.size() + 4]; // add one, MPI requires argv[argc] = 0!
72 for (int i =0; i< aOptList.size() + 4; i++)
74 QStringList args = QApplication::arguments();
75 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
78 foreach (QString aStr, aOptList) {
79 argv[argc] = strdup( aStr.toLatin1().constData() );
82 argv[argc++] = strdup("--multi-servers");
83 // Make salome sharing the same server configuration than external one with "salome shell paraview"
84 QStringList li(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation));
85 foreach(QString pathConfig,li)
87 QFileInfo fi(QDir(pathConfig),QString("ParaView"));
88 if(fi.exists() && fi.isDir())
90 QFileInfo fi2(fi.canonicalFilePath(),"servers.pvsc");
91 if(fi2.exists() && fi2.isFile())
93 QString addEntry(QString("--servers-file=%1").arg(fi2.canonicalFilePath()));
94 std::string addEntry2(addEntry.toStdString());
95 argv[argc++] = strdup(addEntry2.c_str());
101 MyCoreApp = new pqPVApplicationCore (argc, argv);
102 if (MyCoreApp->getOptions()->GetHelpSelected() ||
103 MyCoreApp->getOptions()->GetUnknownArgument() ||
104 MyCoreApp->getOptions()->GetErrorMessage() ||
105 MyCoreApp->getOptions()->GetTellVersion()) {
109 // Direct VTK log messages to our SALOME window - TODO: review this
110 PVViewer_OutputWindow * w = PVViewer_OutputWindow::New();
111 vtkOutputWindow::SetInstance(w);
113 new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation
115 for (int i = 0; i < argc; i++)
119 // Initialization of ParaView GUI widgets will be done when these widgets are
121 // PVViewer_GUIElements* inst = PVViewer_GUIElements::GetInstance(aDesktop);
122 // inst->getPropertiesPanel();
126 void PVViewer_Core::ParaviewInitBehaviors(bool fullSetup, QMainWindow* aDesktop)
128 if (!ParaviewBehaviors)
129 ParaviewBehaviors = new PVViewer_Behaviors(aDesktop);
132 ParaviewBehaviors->instanciateAllBehaviors(aDesktop);
134 ParaviewBehaviors->instanciateMinimalBehaviors(aDesktop);
137 void PVViewer_Core::ParaviewLoadConfigurations(const QString & configPath, bool force)
139 if (!ConfigLoaded || force)
141 if (!configPath.isNull()) {
142 MyCoreApp->loadConfiguration(configPath + QDir::separator() + "ParaViewFilters.xml");
143 MyCoreApp->loadConfiguration(configPath + QDir::separator() + "ParaViewSources.xml");
149 void PVViewer_Core::ParaviewCleanup()
151 // Disconnect from server
152 pqServer* server = pqActiveObjects::instance().activeServer();
153 if (server && server->isRemote())
155 pqServerDisconnectReaction::disconnectFromServer();
158 pqApplicationCore::instance()->settings()->sync();
160 pqPVApplicationCore * app = GetPVApplication();
161 // Schedule destruction of PVApplication singleton: