Salome HOME
refs #1458: disable chained panning on operations
[modules/gui.git] / src / PVViewer / PVViewer_Core.cxx
1 // Copyright (C) 2014-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Adrien Bruneton (CEA)
20 //
21
22 #include "PVViewer_Core.h"
23 #include "PVViewer_LogWindowAdapter.h"
24 #include "PVViewer_GUIElements.h"
25 #include "PVViewer_Behaviors.h"
26 #include "PVViewer_Core.h"
27
28 #include <QApplication>
29 #include <QStringList>
30 #include <QDir>
31 #include <QMainWindow>
32
33 #include <string>
34
35 #include <pqOptions.h>
36 #include <pqSettings.h>
37 #include <pqPVApplicationCore.h>
38 #include <pqTabbedMultiViewWidget.h>
39 #include <pqParaViewMenuBuilders.h>
40 #include <pqActiveObjects.h>
41 #include <pqPipelineBrowserWidget.h>
42 #include <pqServerDisconnectReaction.h>
43
44
45 //---------- Static init -----------------
46 pqPVApplicationCore* PVViewer_Core::MyCoreApp = 0;
47 bool PVViewer_Core::ConfigLoaded = false;
48 PVViewer_Behaviors * PVViewer_Core::ParaviewBehaviors = NULL;
49
50 pqPVApplicationCore * PVViewer_Core::GetPVApplication()
51 {
52   return MyCoreApp;
53 }
54
55 /*!
56   \brief Static method, performs initialization of ParaView session.
57   \param fullSetup whether to instanciate all behaviors or just the minimal ones.
58   \return \c true if ParaView has been initialized successfully, otherwise false
59 */
60 bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindow)
61 {
62   if ( ! MyCoreApp) {
63       // Obtain command-line arguments
64       int argc = 0;
65       char** argv = 0;
66       QString aOptions = getenv("PARAVIEW_OPTIONS");
67       QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
68       argv = new char*[aOptList.size() + 1];
69       QStringList args = QApplication::arguments();
70       argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
71       argc++;
72
73       foreach (QString aStr, aOptList) {
74         argv[argc] = strdup( aStr.toLatin1().constData() );
75         argc++;
76       }
77       MyCoreApp = new pqPVApplicationCore (argc, argv);
78       if (MyCoreApp->getOptions()->GetHelpSelected() ||
79           MyCoreApp->getOptions()->GetUnknownArgument() ||
80           MyCoreApp->getOptions()->GetErrorMessage() ||
81           MyCoreApp->getOptions()->GetTellVersion()) {
82           return false;
83       }
84
85       // Direct VTK log messages to our SALOME window - TODO: review this
86       PVViewer_LogWindowAdapter * w = PVViewer_LogWindowAdapter::New();
87       w->setLogWindow(logWindow);
88       vtkOutputWindow::SetInstance(w);
89
90       new pqTabbedMultiViewWidget(); // registers a "MULTIVIEW_WIDGET" on creation
91
92       for (int i = 0; i < argc; i++)
93         free(argv[i]);
94       delete[] argv;
95   }
96    // Initialization of ParaView GUI widgets will be done when these widgets are
97    // really needed.
98    // PVViewer_GUIElements* inst = PVViewer_GUIElements::GetInstance(aDesktop);
99    // inst->getPropertiesPanel();
100    return true;
101 }
102
103 void PVViewer_Core::ParaviewInitBehaviors(bool fullSetup, QMainWindow* aDesktop)
104 {
105   if (!ParaviewBehaviors)
106       ParaviewBehaviors = new PVViewer_Behaviors(aDesktop);
107
108   if(fullSetup)
109     ParaviewBehaviors->instanciateAllBehaviors(aDesktop);
110   else
111     ParaviewBehaviors->instanciateMinimalBehaviors(aDesktop);
112 }
113
114 void PVViewer_Core::ParaviewLoadConfigurations(const QString & configPath, bool force)
115 {
116   if (!ConfigLoaded || force)
117     {
118       if (!configPath.isNull()) {
119           MyCoreApp->loadConfiguration(configPath + QDir::separator() + "ParaViewFilters.xml");
120           MyCoreApp->loadConfiguration(configPath + QDir::separator() + "ParaViewSources.xml");
121       }
122       ConfigLoaded = true;
123     }
124 }
125
126 void PVViewer_Core::ParaviewCleanup()
127 {
128   // Disconnect from server
129   pqServer* server = pqActiveObjects::instance().activeServer();
130   if (server && server->isRemote())
131     {
132       pqServerDisconnectReaction::disconnectFromServer();
133     }
134
135   pqApplicationCore::instance()->settings()->sync();
136
137   pqPVApplicationCore * app = GetPVApplication();
138   // Schedule destruction of PVApplication singleton:
139   if (app)
140     app->deleteLater();
141 }
142