1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author: Adrien Bruneton (CEA)
21 #include "PVViewer_GUIElements.h"
22 #include "PVServer_ServiceWrapper.h"
23 #include "PVViewer_Core.h"
24 #include "PVViewer_ViewManager.h"
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>
49 #include <vtkSMSessionProxyManager.h>
50 #include <vtkSMProxyIterator.h>
53 #include <QCoreApplication>
56 #include <QMainWindow>
61 PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0;
63 PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) :
66 pipelineBrowserWidget(0),
70 myPVWidgetsFlag(false)
74 PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk)
77 theInstance = new PVViewer_GUIElements(desk);
82 * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
83 * to keep this function up to date:
85 void PVViewer_GUIElements::buildPVWidgets()
87 if (!myPVWidgetsFlag) {
90 if ( !pipelineBrowserWidget ) {
91 pipelineBrowserWidget = new pqPipelineBrowserWidget(myDesktop);
95 if ( !propertiesPanel ) {
96 propertiesPanel = new pqPropertiesPanel(myDesktop);
101 sourcesMenu = new QMenu(0);
102 pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, myDesktop);
107 filtersMenu = new QMenu(0);
108 pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, myDesktop);
113 macrosMenu = new QMenu(0);
114 pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
117 mainToolBar = new pqMainControlsToolbar(myDesktop)
118 << pqSetName("MainControlsToolbar");
119 mainToolBar->layout()->setSpacing(0);
121 vcrToolbar = new pqVCRToolbar(myDesktop)
122 << pqSetName("VCRToolbar");
123 vcrToolbar->layout()->setSpacing(0);
125 timeToolbar = new pqAnimationTimeToolbar(myDesktop)
126 << pqSetName("currentTimeToolbar");
127 timeToolbar->layout()->setSpacing(0);
129 colorToolbar = new pqColorToolbar(myDesktop)
130 << pqSetName("variableToolbar");
131 colorToolbar->layout()->setSpacing(0);
133 reprToolbar = new pqRepresentationToolbar(myDesktop)
134 << pqSetName("representationToolbar");
135 reprToolbar->layout()->setSpacing(0);
137 cameraToolbar = new pqCameraToolbar(myDesktop)
138 << pqSetName("cameraToolbar");
139 cameraToolbar->layout()->setSpacing(0);
141 axesToolbar = new pqAxesToolbar(myDesktop)
142 << pqSetName("axesToolbar");
143 axesToolbar->layout()->setSpacing(0);
145 // Give the macros menu to the pqPythonMacroSupervisor
146 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
147 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
149 macrosToolbar = new QToolBar("Macros Toolbars", myDesktop)
150 << pqSetName("MacrosToolbar");
151 manager->addWidgetForRunMacros(macrosToolbar);
153 commonToolbar = new QToolBar("Common", myDesktop) << pqSetName("Common");
154 commonToolbar->layout()->setSpacing(0);
156 dataToolbar = new QToolBar("DataAnalysis", myDesktop) << pqSetName("DataAnalysis");
157 dataToolbar->layout()->setSpacing(0);
160 myDesktop->addToolBar(Qt::TopToolBarArea, mainToolBar);
161 myDesktop->addToolBar(Qt::TopToolBarArea, vcrToolbar);
162 myDesktop->addToolBar(Qt::TopToolBarArea, timeToolbar);
163 myDesktop->addToolBar(Qt::TopToolBarArea, colorToolbar);
164 myDesktop->insertToolBarBreak(colorToolbar);
165 myDesktop->addToolBar(Qt::TopToolBarArea, reprToolbar);
166 myDesktop->addToolBar(Qt::TopToolBarArea, cameraToolbar);
167 myDesktop->addToolBar(Qt::TopToolBarArea, axesToolbar);
168 myDesktop->addToolBar(Qt::TopToolBarArea, macrosToolbar);
169 myDesktop->addToolBar(Qt::TopToolBarArea, commonToolbar);
170 myDesktop->addToolBar(Qt::TopToolBarArea, dataToolbar);
172 mainAction = mainToolBar->toggleViewAction();
173 vcrAction = vcrToolbar->toggleViewAction();
174 timeAction = timeToolbar->toggleViewAction();
175 colorAction = colorToolbar->toggleViewAction();
176 reprAction = reprToolbar->toggleViewAction();
177 cameraAction = cameraToolbar->toggleViewAction();
178 axesAction = axesToolbar->toggleViewAction();
179 macrosAction = macrosToolbar->toggleViewAction();
180 commonAction = commonToolbar->toggleViewAction();
181 dataAction = dataToolbar->toggleViewAction();
183 // The piece od the code below is neccessary to correct update "Pipeline Browser",
184 // "Properties Panel", toolbars and menus
186 // Initilaize pqApplyBehavior here because witout pqPropertiesPanel instance it doesn't make sence
187 pqApplyBehavior* applyBehavior = new pqApplyBehavior(this);
188 foreach (pqPropertiesPanel* ppanel, myDesktop->findChildren<pqPropertiesPanel*>())
190 applyBehavior->registerPanel(ppanel);
193 QMetaObject::invokeMethod( &pqActiveObjects::instance(),
196 Q_ARG( pqOutputPort*, pqActiveObjects::instance().activePort() ) );
198 QMetaObject::invokeMethod( &pqActiveObjects::instance(),
201 Q_ARG( pqView*, pqActiveObjects::instance().activeView() ) );
203 pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
204 pqServer* serv = pqActiveObjects::instance().activeServer();
207 QMetaObject::invokeMethod( smModel,
210 Q_ARG( pqServer*, serv ) );
212 QMetaObject::invokeMethod( serv,
215 Q_ARG( pqServerManagerModelItem* , NULL ) );
218 publishExistingSources();
219 myPVWidgetsFlag = true;
223 void PVViewer_GUIElements::setToolBarVisible(bool show)
225 QCoreApplication::processEvents();
226 if (!myPVWidgetsFlag)
229 mainAction->setChecked(!show);
230 mainAction->setVisible(show);
231 mainAction->trigger();
233 setVCRTimeToolBarVisible(show);
235 colorAction->setChecked(!show);
236 colorAction->setVisible(show);
237 colorAction->trigger();
238 reprAction->setChecked(!show);
239 reprAction->setVisible(show);
240 reprAction->trigger();
241 cameraAction->setChecked(!show);
242 cameraAction->setVisible(show);
243 cameraAction->trigger();
244 axesAction->setChecked(!show);
245 axesAction->setVisible(show);
246 axesAction->trigger();
247 macrosAction->setChecked(!show);
248 macrosAction->setVisible(show);
249 macrosAction->trigger();
250 commonAction->setChecked(!show);
251 commonAction->setVisible(show);
252 commonAction->trigger();
253 dataAction->setChecked(!show);
254 dataAction->setVisible(show);
255 dataAction->trigger();
258 void PVViewer_GUIElements::setVCRTimeToolBarVisible(bool show)
260 vcrAction->setChecked(!show);
261 vcrAction->setVisible(show);
262 vcrAction->trigger();
263 timeAction->setChecked(!show);
264 timeAction->setVisible(show);
265 timeAction->trigger();
268 QList<QToolBar*> PVViewer_GUIElements::getToolbars()
272 l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar
273 << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar
274 << commonToolbar << dataToolbar;
278 void PVViewer_GUIElements::setToolBarEnabled(bool enabled)
280 if (!myPVWidgetsFlag)
283 mainToolBar ->setEnabled(enabled);
284 vcrToolbar ->setEnabled(enabled);
285 timeToolbar ->setEnabled(enabled);
286 colorToolbar ->setEnabled(enabled);
287 reprToolbar ->setEnabled(enabled);
288 cameraToolbar->setEnabled(enabled);
289 axesToolbar ->setEnabled(enabled);
290 macrosToolbar->setEnabled(enabled);
291 commonToolbar->setEnabled(enabled);
292 dataToolbar ->setEnabled(enabled);
296 pqPropertiesPanel* PVViewer_GUIElements::getPropertiesPanel()
299 return propertiesPanel;
302 pqPipelineBrowserWidget* PVViewer_GUIElements::getPipelineBrowserWidget()
305 return pipelineBrowserWidget;
309 pqVCRToolbar* PVViewer_GUIElements::getVCRToolbar()
315 pqAnimationTimeToolbar* PVViewer_GUIElements::getTimeToolbar()
321 QMenu* PVViewer_GUIElements::getFiltersMenu() {
325 QMenu* PVViewer_GUIElements::getSourcesMenu() {
330 QMenu* PVViewer_GUIElements::getMacrosMenu() {
335 void PVViewer_GUIElements::publishExistingSources() {
336 vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().proxyManager();
337 pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
338 if( !pxm || !smmodel )
340 vtkSMProxyIterator* iter = vtkSMProxyIterator::New();
341 iter->SetModeToOneGroup();
342 iter->SetSessionProxyManager( pxm );
343 for ( iter->Begin( "sources" ); !iter->IsAtEnd(); iter->Next() ) {
344 if ( pqProxy* item = smmodel->findItem<pqProxy*>( iter->GetProxy() ) ) {
345 pqPipelineSource* source = qobject_cast<pqPipelineSource*>( item );
346 QMetaObject::invokeMethod( smmodel,
349 Q_ARG( pqPipelineSource* , source ) );