Salome HOME
Copyright update 2022
[modules/paravis.git] / test / standalone / gui / PVViewer_GUIElements.cxx
1 // Copyright (C) 2010-2022  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 <iostream>
22
23 #include "PVViewer_GUIElements.h"
24 #include "PVViewer_Core.h"
25
26 #include <pqPVApplicationCore.h>
27 #include <pqActiveObjects.h>
28 #include <pqObjectBuilder.h>
29
30 #include <pqPropertiesPanel.h>
31 #include <pqPipelineBrowserWidget.h>
32 #include <pqTabbedMultiViewWidget.h>
33 #include <pqParaViewMenuBuilders.h>
34 #include <pqMainControlsToolbar.h>
35 #include <pqVCRToolbar.h>
36 #include <pqAnimationTimeToolbar.h>
37 #include <pqColorToolbar.h>
38 #include <pqRepresentationToolbar.h>
39 #include <pqCameraToolbar.h>
40 #include <pqAxesToolbar.h>
41 #include <pqSetName.h>
42
43 #include <pqPythonManager.h>
44 #include <pqApplicationCore.h>
45
46 #include <QMainWindow>
47 #include <QMenu>
48 #include <QList>
49 #include <QAction>
50 #include <QToolBar>
51 #include <QLayout>
52
53 #include <QCoreApplication>
54
55 PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0;
56
57 PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) :
58   propertiesPanel(0), pipelineBrowserWidget(0),
59   sourcesMenu(0)
60 {
61   propertiesPanel = new pqPropertiesPanel(desk);
62   propertiesPanel->hide();
63   pipelineBrowserWidget  = new pqPipelineBrowserWidget(desk);
64   pipelineBrowserWidget->hide();
65
66   sourcesMenu = new QMenu(0);
67   pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, desk);
68   filtersMenu = new QMenu(0);
69   pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, desk);
70   macrosMenu = new QMenu(0);
71   pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
72
73 //  myBuildToolbars(desk);
74 }
75
76 PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk)
77 {
78   if (! theInstance)
79     theInstance = new PVViewer_GUIElements(desk);
80   return theInstance;
81 }
82
83
84 pqTabbedMultiViewWidget * PVViewer_GUIElements::getTabbedMultiViewWidget()
85 {
86   pqTabbedMultiViewWidget * multiv =
87         qobject_cast<pqTabbedMultiViewWidget*>(PVViewer_Core::GetPVApplication()->manager("MULTIVIEW_WIDGET"));
88
89   // If not found, instanciate it. It will then register automatically as a MULTIVIEW_WIDGET.
90   // Also create a single view that will be attached by the tabbedMultiView automatically
91   // (in PV this is done automatically upon server connection event).
92   if (!multiv)
93     {
94       multiv = new pqTabbedMultiViewWidget();
95
96       // Create a new view proxy on the server
97       pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
98       pqServer* active_serv = pqActiveObjects::instance().activeServer();
99       /*pqView * pqview = */builder->createView(QString("RenderView"), active_serv); // todo: unused
100     }
101
102   return multiv;
103 }
104
105
106 /**
107  * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
108  * to keep this function up to date:
109  */
110 void PVViewer_GUIElements::myBuildToolbars(QMainWindow* mainWindow)
111 {
112   mainToolBar = new pqMainControlsToolbar(mainWindow)
113     << pqSetName("MainControlsToolbar");
114   mainToolBar->layout()->setSpacing(0);
115
116   vcrToolbar = new pqVCRToolbar(mainWindow)
117     << pqSetName("VCRToolbar");
118   vcrToolbar->layout()->setSpacing(0);
119
120   timeToolbar = new pqAnimationTimeToolbar(mainWindow)
121     << pqSetName("currentTimeToolbar");
122   timeToolbar->layout()->setSpacing(0);
123
124   colorToolbar = new pqColorToolbar(mainWindow)
125     << pqSetName("variableToolbar");
126   colorToolbar->layout()->setSpacing(0);
127
128   reprToolbar = new pqRepresentationToolbar(mainWindow)
129     << pqSetName("representationToolbar");
130   reprToolbar->layout()->setSpacing(0);
131
132   cameraToolbar = new pqCameraToolbar(mainWindow)
133     << pqSetName("cameraToolbar");
134   cameraToolbar->layout()->setSpacing(0);
135
136   axesToolbar = new pqAxesToolbar(mainWindow)
137     << pqSetName("axesToolbar");
138   axesToolbar->layout()->setSpacing(0);
139
140   // Give the macros menu to the pqPythonMacroSupervisor
141   pqPythonManager* manager = qobject_cast<pqPythonManager*>(
142     pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
143
144   macrosToolbar = new QToolBar("Macros Toolbars", mainWindow)
145       << pqSetName("MacrosToolbar");
146   manager->addWidgetForRunMacros(macrosToolbar);
147
148   commonToolbar = new QToolBar("Common", mainWindow) << pqSetName("Common");
149   commonToolbar->layout()->setSpacing(0);
150
151   dataToolbar = new QToolBar("DataAnalysis", mainWindow) << pqSetName("DataAnalysis");
152   dataToolbar->layout()->setSpacing(0);
153
154   //addToolbars(mainWindow);
155 }
156
157 void PVViewer_GUIElements::setToolBarVisible(bool show)
158 {
159   QCoreApplication::processEvents();
160   mainAction->setChecked(!show);
161   mainAction->setVisible(show);
162   mainAction->trigger();
163   vcrAction->setChecked(!show);
164   vcrAction->setVisible(show);
165   vcrAction->trigger();
166   timeAction->setChecked(!show);
167   timeAction->setVisible(show);
168   timeAction->trigger();
169   colorAction->setChecked(!show);
170   colorAction->setVisible(show);
171   colorAction->trigger();
172   reprAction->setChecked(!show);
173   reprAction->setVisible(show);
174   reprAction->trigger();
175   cameraAction->setChecked(!show);
176   cameraAction->setVisible(show);
177   cameraAction->trigger();
178   axesAction->setChecked(!show);
179   axesAction->setVisible(show);
180   axesAction->trigger();
181   macrosAction->setChecked(!show);
182   macrosAction->setVisible(show);
183   macrosAction->trigger();
184   commonAction->setChecked(!show);
185   commonAction->setVisible(show);
186   commonAction->trigger();
187   dataAction->setChecked(!show);
188   dataAction->setVisible(show);
189   dataAction->trigger();
190 }
191
192 void PVViewer_GUIElements::addToolbars(QMainWindow* desk)
193 {
194   desk->addToolBar(Qt::TopToolBarArea, mainToolBar);
195   desk->addToolBar(Qt::TopToolBarArea, vcrToolbar);
196   desk->addToolBar(Qt::TopToolBarArea, timeToolbar);
197   desk->addToolBar(Qt::TopToolBarArea, colorToolbar);
198   desk->insertToolBarBreak(colorToolbar);
199   desk->addToolBar(Qt::TopToolBarArea, reprToolbar);
200   desk->addToolBar(Qt::TopToolBarArea, cameraToolbar);
201   desk->addToolBar(Qt::TopToolBarArea, axesToolbar);
202   desk->addToolBar(Qt::TopToolBarArea, macrosToolbar);
203   desk->addToolBar(Qt::TopToolBarArea, commonToolbar);
204   desk->addToolBar(Qt::TopToolBarArea, dataToolbar);
205
206   mainAction = mainToolBar->toggleViewAction();
207   vcrAction = vcrToolbar->toggleViewAction();
208   timeAction = timeToolbar->toggleViewAction();
209   colorAction = colorToolbar->toggleViewAction();
210   reprAction = reprToolbar->toggleViewAction();
211   cameraAction = cameraToolbar->toggleViewAction();
212   axesAction = axesToolbar->toggleViewAction();
213   macrosAction = macrosToolbar->toggleViewAction();
214   commonAction = commonToolbar->toggleViewAction();
215   dataAction = dataToolbar->toggleViewAction();
216 }
217
218 void PVViewer_GUIElements::onEmulateApply()
219 {
220   if (propertiesPanel)
221     propertiesPanel->apply();
222 }
223
224 QList<QToolBar*> PVViewer_GUIElements::getToolbars()
225 {
226   QList<QToolBar*> l;
227   l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar
228     << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar
229     << commonToolbar << dataToolbar;
230   return l;
231 }
232
233 void PVViewer_GUIElements::setToolBarEnabled(bool enabled)
234 {
235   mainToolBar  ->setEnabled(enabled);
236   vcrToolbar   ->setEnabled(enabled);
237   timeToolbar  ->setEnabled(enabled);
238   colorToolbar ->setEnabled(enabled);
239   reprToolbar  ->setEnabled(enabled);
240   cameraToolbar->setEnabled(enabled);
241   axesToolbar  ->setEnabled(enabled);
242   macrosToolbar->setEnabled(enabled);
243   commonToolbar->setEnabled(enabled);
244   dataToolbar  ->setEnabled(enabled);
245 }