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),
72 myPVWidgetsFlag(false)
76 PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk)
79 theInstance = new PVViewer_GUIElements(desk);
84 * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
85 * to keep this function up to date:
87 void PVViewer_GUIElements::buildPVWidgets()
89 if (!myPVWidgetsFlag) {
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);
100 if ( !propertiesPanel ) {
101 propertiesPanel = new pqPropertiesPanel(myDesktop);
106 sourcesMenu = new QMenu(0);
107 pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, myDesktop);
112 filtersMenu = new QMenu(0);
113 pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, myDesktop);
118 macrosMenu = new QMenu(0);
119 pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
124 catalystMenu = new QMenu(0);
125 pqParaViewMenuBuilders::buildCatalystMenu(*catalystMenu);
128 mainToolBar = new pqMainControlsToolbar(myDesktop)
129 << pqSetName("MainControlsToolbar");
130 mainToolBar->layout()->setSpacing(0);
132 vcrToolbar = new pqVCRToolbar(myDesktop)
133 << pqSetName("VCRToolbar");
134 vcrToolbar->layout()->setSpacing(0);
136 timeToolbar = new pqAnimationTimeToolbar(myDesktop)
137 << pqSetName("currentTimeToolbar");
138 timeToolbar->layout()->setSpacing(0);
140 colorToolbar = new pqColorToolbar(myDesktop)
141 << pqSetName("variableToolbar");
142 colorToolbar->layout()->setSpacing(0);
144 reprToolbar = new pqRepresentationToolbar(myDesktop)
145 << pqSetName("representationToolbar");
146 reprToolbar->layout()->setSpacing(0);
148 cameraToolbar = new pqCameraToolbar(myDesktop)
149 << pqSetName("cameraToolbar");
150 cameraToolbar->layout()->setSpacing(0);
152 axesToolbar = new pqAxesToolbar(myDesktop)
153 << pqSetName("axesToolbar");
154 axesToolbar->layout()->setSpacing(0);
156 // Give the macros menu to the pqPythonMacroSupervisor
157 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
158 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
160 macrosToolbar = new QToolBar("Macros Toolbars", myDesktop)
161 << pqSetName("MacrosToolbar");
162 manager->addWidgetForRunMacros(macrosToolbar);
164 commonToolbar = new QToolBar("Common", myDesktop) << pqSetName("Common");
165 commonToolbar->layout()->setSpacing(0);
167 dataToolbar = new QToolBar("DataAnalysis", myDesktop) << pqSetName("DataAnalysis");
168 dataToolbar->layout()->setSpacing(0);
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);
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();
194 // The piece od the code below is neccessary to correct update "Pipeline Browser",
195 // "Properties Panel", toolbars and menus
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*>())
201 applyBehavior->registerPanel(ppanel);
204 QMetaObject::invokeMethod( &pqActiveObjects::instance(),
207 Q_ARG( pqOutputPort*, pqActiveObjects::instance().activePort() ) );
209 QMetaObject::invokeMethod( &pqActiveObjects::instance(),
212 Q_ARG( pqView*, pqActiveObjects::instance().activeView() ) );
214 pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
215 pqServer* serv = pqActiveObjects::instance().activeServer();
218 QMetaObject::invokeMethod( smModel,
221 Q_ARG( pqServer*, serv ) );
223 QMetaObject::invokeMethod( serv,
226 Q_ARG( pqServerManagerModelItem* , NULL ) );
229 //publishExistingSources();
230 myPVWidgetsFlag = true;
234 void PVViewer_GUIElements::setToolBarVisible(bool show)
236 QCoreApplication::processEvents();
237 if (!myPVWidgetsFlag)
240 mainAction->setChecked(!show);
241 mainAction->setVisible(show);
242 mainAction->trigger();
244 setVCRTimeToolBarVisible(show);
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();
269 void PVViewer_GUIElements::setVCRTimeToolBarVisible(bool show)
271 vcrAction->setChecked(!show);
272 vcrAction->setVisible(show);
273 vcrAction->trigger();
274 timeAction->setChecked(!show);
275 timeAction->setVisible(show);
276 timeAction->trigger();
279 QList<QToolBar*> PVViewer_GUIElements::getToolbars()
283 l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar
284 << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar
285 << commonToolbar << dataToolbar;
289 void PVViewer_GUIElements::setToolBarEnabled(bool enabled)
291 if (!myPVWidgetsFlag)
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);
307 pqPropertiesPanel* PVViewer_GUIElements::getPropertiesPanel()
310 return propertiesPanel;
313 pqPipelineBrowserWidget* PVViewer_GUIElements::getPipelineBrowserWidget()
316 return pipelineBrowserWidget;
320 pqVCRToolbar* PVViewer_GUIElements::getVCRToolbar()
326 pqAnimationTimeToolbar* PVViewer_GUIElements::getTimeToolbar()
332 QMenu* PVViewer_GUIElements::getFiltersMenu() {
336 QMenu* PVViewer_GUIElements::getSourcesMenu() {
341 QMenu* PVViewer_GUIElements::getMacrosMenu() {
346 QMenu* PVViewer_GUIElements::getCatalystMenu() {
351 void PVViewer_GUIElements::publishExistingSources() {
352 vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().proxyManager();
353 pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
354 if( !pxm || !smmodel )
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,
365 Q_ARG( pqPipelineSource* , source ) );