]> SALOME platform Git repositories - modules/gui.git/blob - src/PVViewer/PVViewer_GUIElements.cxx
Salome HOME
a30c17e5e24ef5fd4029c4677e459aa4a3cc2060
[modules/gui.git] / src / PVViewer / PVViewer_GUIElements.cxx
1 // Copyright (C) 2010-2016  CEA/DEN, EDF R&D
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 #include "PVViewer_GUIElements.h"
22
23 #include <pqPropertiesPanel.h>
24 #include <pqPipelineBrowserWidget.h>
25 #include <pqParaViewMenuBuilders.h>
26 #include <pqMainControlsToolbar.h>
27 #include <pqVCRToolbar.h>
28 #include <pqAnimationTimeToolbar.h>
29 #include <pqColorToolbar.h>
30 #include <pqRepresentationToolbar.h>
31 #include <pqCameraToolbar.h>
32 #include <pqAxesToolbar.h>
33 #include <pqSetName.h>
34
35 #include <pqPythonManager.h>
36 #include <pqApplicationCore.h>
37
38 #include <QMainWindow>
39 #include <QMenu>
40 #include <QList>
41 #include <QAction>
42 #include <QToolBar>
43 #include <QLayout>
44
45 #include <QCoreApplication>
46
47 PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0;
48
49 PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) :
50   propertiesPanel(0), pipelineBrowserWidget(0),
51   sourcesMenu(0)
52 {
53   propertiesPanel = new pqPropertiesPanel(desk);
54   propertiesPanel->hide();
55   pipelineBrowserWidget  = new pqPipelineBrowserWidget(desk);
56   pipelineBrowserWidget->hide();
57
58   sourcesMenu = new QMenu(0);
59   pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, desk);
60   filtersMenu = new QMenu(0);
61   pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, desk);
62 #ifdef PVCATALYST_ENABLED
63   catalystMenu = new QMenu(0);
64   pqParaViewMenuBuilders::buildCatalystMenu(*catalystMenu);
65 #endif
66   macrosMenu = new QMenu(0);
67   pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
68
69   myBuildToolbars(desk);
70 }
71
72 PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk)
73 {
74   if (! theInstance)
75     theInstance = new PVViewer_GUIElements(desk);
76   return theInstance;
77 }
78
79 /**
80  * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
81  * to keep this function up to date:
82  */
83 void PVViewer_GUIElements::myBuildToolbars(QMainWindow* mainWindow)
84 {
85   mainToolBar = new pqMainControlsToolbar(mainWindow)
86     << pqSetName("MainControlsToolbar");
87   mainToolBar->layout()->setSpacing(0);
88
89   vcrToolbar = new pqVCRToolbar(mainWindow)
90     << pqSetName("VCRToolbar");
91   vcrToolbar->layout()->setSpacing(0);
92
93   timeToolbar = new pqAnimationTimeToolbar(mainWindow)
94     << pqSetName("currentTimeToolbar");
95   timeToolbar->layout()->setSpacing(0);
96
97   colorToolbar = new pqColorToolbar(mainWindow)
98     << pqSetName("variableToolbar");
99   colorToolbar->layout()->setSpacing(0);
100
101   reprToolbar = new pqRepresentationToolbar(mainWindow)
102     << pqSetName("representationToolbar");
103   reprToolbar->layout()->setSpacing(0);
104
105   cameraToolbar = new pqCameraToolbar(mainWindow)
106     << pqSetName("cameraToolbar");
107   cameraToolbar->layout()->setSpacing(0);
108
109   axesToolbar = new pqAxesToolbar(mainWindow)
110     << pqSetName("axesToolbar");
111   axesToolbar->layout()->setSpacing(0);
112
113   // Give the macros menu to the pqPythonMacroSupervisor
114   pqPythonManager* manager = qobject_cast<pqPythonManager*>(
115     pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
116
117   macrosToolbar = new QToolBar("Macros Toolbars", mainWindow)
118       << pqSetName("MacrosToolbar");
119   manager->addWidgetForRunMacros(macrosToolbar);
120
121   commonToolbar = new QToolBar("Common", mainWindow) << pqSetName("Common");
122   commonToolbar->layout()->setSpacing(0);
123
124   dataToolbar = new QToolBar("DataAnalysis", mainWindow) << pqSetName("DataAnalysis");
125   dataToolbar->layout()->setSpacing(0);
126
127   addToolbars(mainWindow);
128 }
129
130 void PVViewer_GUIElements::setToolBarVisible(bool show)
131 {
132   QCoreApplication::processEvents();
133   mainAction->setChecked(!show);
134   mainAction->setVisible(show);
135   mainAction->trigger();
136   vcrAction->setChecked(!show);
137   vcrAction->setVisible(show);
138   vcrAction->trigger();
139   timeAction->setChecked(!show);
140   timeAction->setVisible(show);
141   timeAction->trigger();
142   colorAction->setChecked(!show);
143   colorAction->setVisible(show);
144   colorAction->trigger();
145   reprAction->setChecked(!show);
146   reprAction->setVisible(show);
147   reprAction->trigger();
148   cameraAction->setChecked(!show);
149   cameraAction->setVisible(show);
150   cameraAction->trigger();
151   axesAction->setChecked(!show);
152   axesAction->setVisible(show);
153   axesAction->trigger();
154   macrosAction->setChecked(!show);
155   macrosAction->setVisible(show);
156   macrosAction->trigger();
157   commonAction->setChecked(!show);
158   commonAction->setVisible(show);
159   commonAction->trigger();
160   dataAction->setChecked(!show);
161   dataAction->setVisible(show);
162   dataAction->trigger();
163 }
164
165 void PVViewer_GUIElements::addToolbars(QMainWindow* desk)
166 {
167   desk->addToolBar(Qt::TopToolBarArea, mainToolBar);
168   desk->addToolBar(Qt::TopToolBarArea, vcrToolbar);
169   desk->addToolBar(Qt::TopToolBarArea, timeToolbar);
170   desk->addToolBar(Qt::TopToolBarArea, colorToolbar);
171   desk->insertToolBarBreak(colorToolbar);
172   desk->addToolBar(Qt::TopToolBarArea, reprToolbar);
173   desk->addToolBar(Qt::TopToolBarArea, cameraToolbar);
174   desk->addToolBar(Qt::TopToolBarArea, axesToolbar);
175   desk->addToolBar(Qt::TopToolBarArea, macrosToolbar);
176   desk->addToolBar(Qt::TopToolBarArea, commonToolbar);
177   desk->addToolBar(Qt::TopToolBarArea, dataToolbar);
178
179   mainAction = mainToolBar->toggleViewAction();
180   vcrAction = vcrToolbar->toggleViewAction();
181   timeAction = timeToolbar->toggleViewAction();
182   colorAction = colorToolbar->toggleViewAction();
183   reprAction = reprToolbar->toggleViewAction();
184   cameraAction = cameraToolbar->toggleViewAction();
185   axesAction = axesToolbar->toggleViewAction();
186   macrosAction = macrosToolbar->toggleViewAction();
187   commonAction = commonToolbar->toggleViewAction();
188   dataAction = dataToolbar->toggleViewAction();
189 }
190
191 QList<QToolBar*> PVViewer_GUIElements::getToolbars()
192 {
193   QList<QToolBar*> l;
194   l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar
195     << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar
196     << commonToolbar << dataToolbar;
197   return l;
198 }
199
200 void PVViewer_GUIElements::setToolBarEnabled(bool enabled)
201 {
202   mainToolBar  ->setEnabled(enabled);
203   vcrToolbar   ->setEnabled(enabled);
204   timeToolbar  ->setEnabled(enabled);
205   colorToolbar ->setEnabled(enabled);
206   reprToolbar  ->setEnabled(enabled);
207   cameraToolbar->setEnabled(enabled);
208   axesToolbar  ->setEnabled(enabled);
209   macrosToolbar->setEnabled(enabled);
210   commonToolbar->setEnabled(enabled);
211   dataToolbar  ->setEnabled(enabled);
212 }