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