1 // Copyright (C) 2010-2015 CEA/DEN, EDF R&D
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_LogWindowAdapter.h"
24 #include "PVViewer_GUIElements.h"
25 #include "PVViewer_Behaviors.h"
26 #include "PVViewer_EngineWrapper.h"
27 #include "PVViewer_Core.h"
29 #include <QApplication>
30 #include <QStringList>
32 #include <QMainWindow>
36 #include <pqOptions.h>
37 #include <pqSettings.h>
38 #include <pqPVApplicationCore.h>
39 #include <pqTabbedMultiViewWidget.h>
40 #include <pqParaViewMenuBuilders.h>
41 #include <pqActiveObjects.h>
42 #include <pqPipelineBrowserWidget.h>
43 #include <pqServerDisconnectReaction.h>
46 //---------- Static init -----------------
47 pqPVApplicationCore* PVViewer_Core::MyCoreApp = 0;
48 bool PVViewer_Core::ConfigLoaded = false;
49 PVViewer_Behaviors * PVViewer_Core::ParaviewBehaviors = NULL;
51 pqPVApplicationCore * PVViewer_Core::GetPVApplication()
57 \brief Static method, performs initialization of ParaView session.
58 \param fullSetup whether to instanciate all behaviors or just the minimal ones.
59 \return \c true if ParaView has been initialized successfully, otherwise false
61 bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindow)
64 // Obtain command-line arguments
67 QString aOptions = getenv("PARAVIEW_OPTIONS");
68 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
69 argv = new char*[aOptList.size() + 1];
70 QStringList args = QApplication::arguments();
71 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
74 foreach (QString aStr, aOptList) {
75 argv[argc] = strdup( aStr.toLatin1().constData() );
78 MyCoreApp = new pqPVApplicationCore (argc, argv);
79 if (MyCoreApp->getOptions()->GetHelpSelected() ||
80 MyCoreApp->getOptions()->GetUnknownArgument() ||
81 MyCoreApp->getOptions()->GetErrorMessage() ||
82 MyCoreApp->getOptions()->GetTellVersion()) {
86 // Direct VTK log messages to our SALOME window - TODO: review this
87 PVViewer_LogWindowAdapter * w = PVViewer_LogWindowAdapter::New();
88 w->setLogWindow(logWindow);
89 vtkOutputWindow::SetInstance(w);
91 new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation
93 for (int i = 0; i < argc; i++)
97 // Initialize GUI elements if needed:
98 PVViewer_GUIElements::GetInstance(aDesktop);
102 void PVViewer_Core::ParaviewInitBehaviors(bool fullSetup, QMainWindow* aDesktop)
104 if (!ParaviewBehaviors)
105 ParaviewBehaviors = new PVViewer_Behaviors(aDesktop);
108 ParaviewBehaviors->instanciateAllBehaviors(aDesktop);
110 ParaviewBehaviors->instanciateMinimalBehaviors(aDesktop);
113 void PVViewer_Core::ParaviewLoadConfigurations(const QString & configPath, bool force)
115 if (!ConfigLoaded || force)
117 if (!configPath.isNull()) {
118 MyCoreApp->loadConfiguration(configPath + QDir::separator() + "ParaViewFilters.xml");
119 MyCoreApp->loadConfiguration(configPath + QDir::separator() + "ParaViewSources.xml");
125 void PVViewer_Core::ParaviewCleanup()
127 // Disconnect from server
128 pqServer* server = pqActiveObjects::instance().activeServer();
129 if (server && server->isRemote())
131 pqServerDisconnectReaction::disconnectFromServer();
134 pqApplicationCore::instance()->settings()->sync();
136 pqPVApplicationCore * app = GetPVApplication();
137 // Schedule destruction of PVApplication singleton: