]> SALOME platform Git repositories - modules/gui.git/blob - src/PVViewer/PVViewer_GUIElements.cxx
Salome HOME
Merge changes from 'master' branch.
[modules/gui.git] / src / PVViewer / PVViewer_GUIElements.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 #include "PVViewer_GUIElements.h"
22 #include "PVServer_ServiceWrapper.h"
23 #include "PVViewer_Core.h"
24 #include "PVViewer_ViewManager.h"
25
26 #include <pqActiveObjects.h>
27 #include <pqAnimationManager.h>
28 #include <pqAnimationTimeToolbar.h>
29 #include <pqApplicationCore.h>
30 #include <pqApplyBehavior.h>
31 #include <pqAxesToolbar.h>
32 #include <pqCameraToolbar.h>
33 #include <pqColorToolbar.h>
34 #include <pqMainControlsToolbar.h>
35 #include <pqPVApplicationCore.h>
36 #include <pqParaViewMenuBuilders.h>
37 #include <pqPipelineBrowserWidget.h>
38 #include <pqPipelineModel.h>
39 #include <pqPropertiesPanel.h>
40 #include <pqPythonManager.h>
41 #include <pqRepresentationToolbar.h>
42 #include <pqServerConnectReaction.h>
43 #include <pqServerManagerModel.h>
44 #include <pqServerResource.h>
45 #include <pqSetName.h>
46 #include <pqVCRToolbar.h>
47 #include <pqPipelineSource.h>
48
49 #include <vtkSMSessionProxyManager.h>
50 #include <vtkSMProxyIterator.h>
51
52 #include <QAction>
53 #include <QCoreApplication>
54 #include <QLayout>
55 #include <QList>
56 #include <QMainWindow>
57 #include <QMenu>
58 #include <QToolBar>
59
60
61 PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0;
62
63 PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) :
64   myDesktop(desk),
65   propertiesPanel(0),
66   pipelineBrowserWidget(0),
67   pipelineModel(0),
68   sourcesMenu(0),
69   filtersMenu(0),
70   macrosMenu(0),
71   catalystMenu(0),
72   myPVWidgetsFlag(false)
73 {
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  * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
85  * to keep this function up to date:
86  */
87 void PVViewer_GUIElements::buildPVWidgets()
88 {
89   if (!myPVWidgetsFlag) {
90
91     //Pipeline Browser
92     if ( !pipelineBrowserWidget ) {
93         pqPipelineModel* pipelineModel = new pqPipelineModel(*pqApplicationCore::instance()->getServerManagerModel(), this);
94         pipelineModel->setView(pqActiveObjects::instance().activeView());
95         pipelineBrowserWidget  = new pqPipelineBrowserWidget(myDesktop);
96         pipelineBrowserWidget->setModel(pipelineModel);
97     }
98
99     // Properties panel
100     if ( !propertiesPanel ) {
101       propertiesPanel = new pqPropertiesPanel(myDesktop);
102     }
103     
104     // Sources Menu
105     if (!sourcesMenu) {
106       sourcesMenu = new QMenu(0);
107       pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, myDesktop);
108     }
109
110     //Filer Menu
111     if (!filtersMenu) {
112       filtersMenu = new QMenu(0);
113       pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, myDesktop);
114     }
115
116     // Macros Menu
117     if (!macrosMenu) {
118       macrosMenu = new QMenu(0);
119       pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
120     }
121
122     // Catalyst Menu
123     if (!catalystMenu) {
124       catalystMenu = new QMenu(0);
125       pqParaViewMenuBuilders::buildCatalystMenu(*catalystMenu);
126     }
127
128     mainToolBar = new pqMainControlsToolbar(myDesktop)
129       << pqSetName("MainControlsToolbar");
130     mainToolBar->layout()->setSpacing(0);
131
132     vcrToolbar = new pqVCRToolbar(myDesktop)
133       << pqSetName("VCRToolbar");
134     vcrToolbar->layout()->setSpacing(0);
135
136     timeToolbar = new pqAnimationTimeToolbar(myDesktop)
137       << pqSetName("currentTimeToolbar");
138     timeToolbar->layout()->setSpacing(0);
139
140     colorToolbar = new pqColorToolbar(myDesktop)
141       << pqSetName("variableToolbar");
142     colorToolbar->layout()->setSpacing(0);
143
144     reprToolbar = new pqRepresentationToolbar(myDesktop)
145       << pqSetName("representationToolbar");
146     reprToolbar->layout()->setSpacing(0);
147
148     cameraToolbar = new pqCameraToolbar(myDesktop)
149       << pqSetName("cameraToolbar");
150     cameraToolbar->layout()->setSpacing(0);
151     
152     axesToolbar = new pqAxesToolbar(myDesktop)
153       << pqSetName("axesToolbar");
154     axesToolbar->layout()->setSpacing(0);
155     
156     // Give the macros menu to the pqPythonMacroSupervisor
157     pqPythonManager* manager = qobject_cast<pqPythonManager*>(
158     pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
159
160     macrosToolbar = new QToolBar("Macros Toolbars", myDesktop)
161       << pqSetName("MacrosToolbar");
162     manager->addWidgetForRunMacros(macrosToolbar);
163     
164     commonToolbar = new QToolBar("Common", myDesktop) << pqSetName("Common");
165     commonToolbar->layout()->setSpacing(0);
166     
167     dataToolbar = new QToolBar("DataAnalysis", myDesktop) << pqSetName("DataAnalysis");
168     dataToolbar->layout()->setSpacing(0);
169     
170     // add Toolbars    
171     myDesktop->addToolBar(Qt::TopToolBarArea, mainToolBar);
172     myDesktop->addToolBar(Qt::TopToolBarArea, vcrToolbar);
173     myDesktop->addToolBar(Qt::TopToolBarArea, timeToolbar);
174     myDesktop->addToolBar(Qt::TopToolBarArea, colorToolbar);
175     myDesktop->insertToolBarBreak(colorToolbar);
176     myDesktop->addToolBar(Qt::TopToolBarArea, reprToolbar);
177     myDesktop->addToolBar(Qt::TopToolBarArea, cameraToolbar);
178     myDesktop->addToolBar(Qt::TopToolBarArea, axesToolbar);
179     myDesktop->addToolBar(Qt::TopToolBarArea, macrosToolbar);
180     myDesktop->addToolBar(Qt::TopToolBarArea, commonToolbar);
181     myDesktop->addToolBar(Qt::TopToolBarArea, dataToolbar);
182     
183     mainAction = mainToolBar->toggleViewAction();
184     vcrAction = vcrToolbar->toggleViewAction();
185     timeAction = timeToolbar->toggleViewAction();
186     colorAction = colorToolbar->toggleViewAction();
187     reprAction = reprToolbar->toggleViewAction();
188     cameraAction = cameraToolbar->toggleViewAction();
189     axesAction = axesToolbar->toggleViewAction();
190     macrosAction = macrosToolbar->toggleViewAction();
191     commonAction = commonToolbar->toggleViewAction();
192     dataAction = dataToolbar->toggleViewAction();
193
194     // The piece od the code below is neccessary to correct update "Pipeline Browser",
195     // "Properties Panel", toolbars and menus
196     
197     // Initilaize pqApplyBehavior here because witout pqPropertiesPanel instance it doesn't make sence
198     pqApplyBehavior* applyBehavior = new pqApplyBehavior(this);
199     foreach (pqPropertiesPanel* ppanel, myDesktop->findChildren<pqPropertiesPanel*>())
200       {
201         applyBehavior->registerPanel(ppanel);
202       }
203     
204     QMetaObject::invokeMethod( &pqActiveObjects::instance(),
205                                "portChanged",
206                                Qt::AutoConnection,
207                                Q_ARG( pqOutputPort*, pqActiveObjects::instance().activePort() ) );
208     
209     QMetaObject::invokeMethod( &pqActiveObjects::instance(),
210                                "viewChanged",
211                                Qt::AutoConnection,
212                                Q_ARG( pqView*, pqActiveObjects::instance().activeView() ) ); 
213
214     pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
215     pqServer* serv = pqActiveObjects::instance().activeServer();    
216
217     if (serv) {
218       QMetaObject::invokeMethod( smModel,
219                                  "serverAdded",
220                                  Qt::AutoConnection,
221                                  Q_ARG( pqServer*, serv ) );
222       
223       QMetaObject::invokeMethod( serv,
224                                  "nameChanged",
225                                  Qt::AutoConnection,
226                                  Q_ARG( pqServerManagerModelItem* , NULL ) );
227     }
228     
229     //publishExistingSources();
230     myPVWidgetsFlag = true;
231   }
232 }
233
234 void PVViewer_GUIElements::setToolBarVisible(bool show)
235 {  
236   QCoreApplication::processEvents();
237   if (!myPVWidgetsFlag)
238     return;
239   
240   mainAction->setChecked(!show);
241   mainAction->setVisible(show);
242   mainAction->trigger();
243
244   setVCRTimeToolBarVisible(show);
245
246   colorAction->setChecked(!show);
247   colorAction->setVisible(show);
248   colorAction->trigger();
249   reprAction->setChecked(!show);
250   reprAction->setVisible(show);
251   reprAction->trigger();
252   cameraAction->setChecked(!show);
253   cameraAction->setVisible(show);
254   cameraAction->trigger();
255   axesAction->setChecked(!show);
256   axesAction->setVisible(show);
257   axesAction->trigger();
258   macrosAction->setChecked(!show);
259   macrosAction->setVisible(show);
260   macrosAction->trigger();
261   commonAction->setChecked(!show);
262   commonAction->setVisible(show);
263   commonAction->trigger();
264   dataAction->setChecked(!show);
265   dataAction->setVisible(show);
266   dataAction->trigger();
267 }
268
269 void PVViewer_GUIElements::setVCRTimeToolBarVisible(bool show)
270 {
271   vcrAction->setChecked(!show);
272   vcrAction->setVisible(show);
273   vcrAction->trigger();
274   timeAction->setChecked(!show);
275   timeAction->setVisible(show);
276   timeAction->trigger();
277 }
278
279 QList<QToolBar*> PVViewer_GUIElements::getToolbars()
280 {
281   buildPVWidgets();
282   QList<QToolBar*> l;
283   l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar
284     << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar
285     << commonToolbar << dataToolbar;
286   return l;
287 }
288
289 void PVViewer_GUIElements::setToolBarEnabled(bool enabled)
290 {
291   if (!myPVWidgetsFlag)
292     return;
293   
294   mainToolBar  ->setEnabled(enabled);
295   vcrToolbar   ->setEnabled(enabled);
296   timeToolbar  ->setEnabled(enabled);
297   colorToolbar ->setEnabled(enabled);
298   reprToolbar  ->setEnabled(enabled);
299   cameraToolbar->setEnabled(enabled);
300   axesToolbar  ->setEnabled(enabled);
301   macrosToolbar->setEnabled(enabled);
302   commonToolbar->setEnabled(enabled);
303   dataToolbar  ->setEnabled(enabled);
304 }
305
306
307 pqPropertiesPanel* PVViewer_GUIElements::getPropertiesPanel()
308 {
309   buildPVWidgets();
310   return propertiesPanel;
311 }
312
313 pqPipelineBrowserWidget* PVViewer_GUIElements::getPipelineBrowserWidget()
314 {
315   buildPVWidgets();
316   return pipelineBrowserWidget;   
317 }
318
319
320 pqVCRToolbar* PVViewer_GUIElements::getVCRToolbar()
321 {
322   buildPVWidgets();
323   return vcrToolbar;
324 }
325
326 pqAnimationTimeToolbar* PVViewer_GUIElements::getTimeToolbar()
327 {
328   buildPVWidgets();
329   return timeToolbar;
330 }
331
332 QMenu* PVViewer_GUIElements::getFiltersMenu() {
333   buildPVWidgets();
334   return filtersMenu;
335 }
336 QMenu* PVViewer_GUIElements::getSourcesMenu() {
337   buildPVWidgets();
338   return sourcesMenu;
339 }
340
341 QMenu* PVViewer_GUIElements::getMacrosMenu()  {
342   buildPVWidgets();
343   return macrosMenu;
344 }
345
346 QMenu* PVViewer_GUIElements::getCatalystMenu()  {
347   buildPVWidgets();
348   return catalystMenu;
349 }
350
351 void PVViewer_GUIElements::publishExistingSources() {
352   vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().proxyManager();
353   pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
354   if( !pxm || !smmodel )
355     return;
356   vtkSMProxyIterator* iter = vtkSMProxyIterator::New();
357   iter->SetModeToOneGroup();
358   iter->SetSessionProxyManager( pxm );
359   for ( iter->Begin( "sources" ); !iter->IsAtEnd(); iter->Next() ) {
360     if ( pqProxy* item = smmodel->findItem<pqProxy*>( iter->GetProxy() ) ) {
361       pqPipelineSource* source = qobject_cast<pqPipelineSource*>( item );
362       QMetaObject::invokeMethod( smmodel,
363                                  "sourceAdded",
364                                  Qt::AutoConnection,
365                                  Q_ARG( pqPipelineSource* , source ) );
366     }
367   }
368 }