]> SALOME platform Git repositories - modules/gui.git/blob - src/PVViewer/PVViewer_GUIElements.cxx
Salome HOME
1d5c3e6ad66542fbcbd04747af75fb2e2ed8091b
[modules/gui.git] / src / PVViewer / PVViewer_GUIElements.cxx
1 // Copyright (C) 2010-2014  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 #include "SUIT_Desktop.h"
23
24 #include <pqPropertiesPanel.h>
25 #include <pqPipelineBrowserWidget.h>
26 #include <pqParaViewMenuBuilders.h>
27 #include <pqMainControlsToolbar.h>
28 #include <pqVCRToolbar.h>
29 #include <pqAnimationTimeToolbar.h>
30 #include <pqColorToolbar.h>
31 #include <pqRepresentationToolbar.h>
32 #include <pqCameraToolbar.h>
33 #include <pqAxesToolbar.h>
34 #include <pqSetName.h>
35
36 #include <pqPythonManager.h>
37 #include <pqApplicationCore.h>
38
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(SUIT_Desktop* 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   macrosMenu = new QMenu(0);
63   pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
64
65   myBuildToolbars(desk);
66 }
67
68 PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(SUIT_Desktop* desk)
69 {
70   if (! theInstance)
71     theInstance = new PVViewer_GUIElements(desk);
72   return theInstance;
73 }
74
75 /**
76  * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
77  * to keep this function up to date:
78  */
79 void PVViewer_GUIElements::myBuildToolbars(SUIT_Desktop* mainWindow)
80 {
81   mainToolBar = new pqMainControlsToolbar(mainWindow)
82     << pqSetName("MainControlsToolbar");
83   mainToolBar->layout()->setSpacing(0);
84
85   vcrToolbar = new pqVCRToolbar(mainWindow)
86     << pqSetName("VCRToolbar");
87   vcrToolbar->layout()->setSpacing(0);
88
89   timeToolbar = new pqAnimationTimeToolbar(mainWindow)
90     << pqSetName("currentTimeToolbar");
91   timeToolbar->layout()->setSpacing(0);
92
93   colorToolbar = new pqColorToolbar(mainWindow)
94     << pqSetName("variableToolbar");
95   colorToolbar->layout()->setSpacing(0);
96
97   reprToolbar = new pqRepresentationToolbar(mainWindow)
98     << pqSetName("representationToolbar");
99   reprToolbar->layout()->setSpacing(0);
100
101   cameraToolbar = new pqCameraToolbar(mainWindow)
102     << pqSetName("cameraToolbar");
103   cameraToolbar->layout()->setSpacing(0);
104
105   axesToolbar = new pqAxesToolbar(mainWindow)
106     << pqSetName("axesToolbar");
107   axesToolbar->layout()->setSpacing(0);
108
109   // Give the macros menu to the pqPythonMacroSupervisor
110   pqPythonManager* manager = qobject_cast<pqPythonManager*>(
111     pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
112
113   macrosToolbar = new QToolBar("Macros Toolbars", mainWindow)
114       << pqSetName("MacrosToolbar");
115     manager->addWidgetForRunMacros(macrosToolbar);
116
117   addToolbars(mainWindow);
118 }
119
120 void PVViewer_GUIElements::setToolBarVisible(bool show)
121 {
122   QCoreApplication::processEvents();
123   mainAction->setChecked(!show);
124   mainAction->trigger();
125   vcrAction->setChecked(!show);
126   vcrAction->trigger();
127   timeAction->setChecked(!show);
128   timeAction->trigger();
129   colorAction->setChecked(!show);
130   colorAction->trigger();
131   reprAction->setChecked(!show);
132   reprAction->trigger();
133   cameraAction->setChecked(!show);
134   cameraAction->trigger();
135   axesAction->setChecked(!show);
136   axesAction->trigger();
137   macrosAction->setChecked(!show);
138   macrosAction->trigger();
139 }
140
141 void PVViewer_GUIElements::addToolbars(SUIT_Desktop* desk)
142 {
143   desk->addToolBar(Qt::TopToolBarArea, mainToolBar);
144   desk->addToolBar(Qt::TopToolBarArea, vcrToolbar);
145   desk->addToolBar(Qt::TopToolBarArea, timeToolbar);
146   desk->addToolBar(Qt::TopToolBarArea, colorToolbar);
147   desk->insertToolBarBreak(colorToolbar);
148   desk->addToolBar(Qt::TopToolBarArea, reprToolbar);
149   desk->addToolBar(Qt::TopToolBarArea, cameraToolbar);
150   desk->addToolBar(Qt::TopToolBarArea, axesToolbar);
151   desk->addToolBar(Qt::TopToolBarArea, macrosToolbar);
152
153   mainAction = mainToolBar->toggleViewAction();
154   vcrAction = vcrToolbar->toggleViewAction();
155   timeAction = timeToolbar->toggleViewAction();
156   colorAction = colorToolbar->toggleViewAction();
157   reprAction = reprToolbar->toggleViewAction();
158   cameraAction = cameraToolbar->toggleViewAction();
159   axesAction = axesToolbar->toggleViewAction();
160   macrosAction = macrosToolbar->toggleViewAction();
161 }
162
163 void PVViewer_GUIElements::onEmulateApply()
164 {
165   if (propertiesPanel)
166     propertiesPanel->apply();
167 }