1 // Copyright (C) 2014-2019 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>
52 #include <vtkPVConfig.h>
55 #include <QCoreApplication>
58 #include <QMainWindow>
62 PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0;
64 PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desktop) :
66 pipelineBrowserWidget(0),
83 myPVWidgetsFlag(false),
97 PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk)
100 theInstance = new PVViewer_GUIElements(desk);
105 * See ParaView source code: pqParaViewMenuBuilders::buildToolbars()
106 * to keep this function up to date:
108 void PVViewer_GUIElements::buildPVWidgets()
110 if (!myPVWidgetsFlag) {
113 if ( !pipelineBrowserWidget ) {
114 pqPipelineModel* pipelineModel = new pqPipelineModel(*pqApplicationCore::instance()->getServerManagerModel(), this);
115 pipelineModel->setView(pqActiveObjects::instance().activeView());
116 pipelineBrowserWidget = new pqPipelineBrowserWidget(myDesktop);
117 pipelineBrowserWidget->setModel(pipelineModel);
121 if ( !propertiesPanel ) {
122 propertiesPanel = new pqPropertiesPanel(myDesktop);
127 sourcesMenu = new QMenu(0);
128 pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, myDesktop);
133 filtersMenu = new QMenu(0);
134 pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, myDesktop);
139 macrosMenu = new QMenu(0);
140 pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu);
145 catalystMenu = new QMenu(0);
146 #if PARAVIEW_VERSION_MAJOR==5 && PARAVIEW_VERSION_MINOR>=6
147 pqParaViewMenuBuilders::buildCatalystMenu(*catalystMenu, myDesktop);
149 pqParaViewMenuBuilders::buildCatalystMenu(*catalystMenu);
153 mainToolBar = new pqMainControlsToolbar(myDesktop)
154 << pqSetName("MainControlsToolbar");
155 mainToolBar->layout()->setSpacing(0);
157 vcrToolbar = new pqVCRToolbar(myDesktop)
158 << pqSetName("VCRToolbar");
159 vcrToolbar->layout()->setSpacing(0);
161 timeToolbar = new pqAnimationTimeToolbar(myDesktop)
162 << pqSetName("currentTimeToolbar");
163 timeToolbar->layout()->setSpacing(0);
165 colorToolbar = new pqColorToolbar(myDesktop)
166 << pqSetName("variableToolbar");
167 colorToolbar->layout()->setSpacing(0);
169 reprToolbar = new pqRepresentationToolbar(myDesktop)
170 << pqSetName("representationToolbar");
171 reprToolbar->layout()->setSpacing(0);
173 cameraToolbar = new pqCameraToolbar(myDesktop)
174 << pqSetName("cameraToolbar");
175 cameraToolbar->layout()->setSpacing(0);
177 axesToolbar = new pqAxesToolbar(myDesktop)
178 << pqSetName("axesToolbar");
179 axesToolbar->layout()->setSpacing(0);
181 // Give the macros menu to the pqPythonMacroSupervisor
182 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
183 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
185 macrosToolbar = new QToolBar("Macros Toolbars", myDesktop)
186 << pqSetName("MacrosToolbar");
187 manager->addWidgetForRunMacros(macrosToolbar);
189 commonToolbar = new QToolBar("Common", myDesktop) << pqSetName("Common");
190 commonToolbar->layout()->setSpacing(0);
192 dataToolbar = new QToolBar("DataAnalysis", myDesktop) << pqSetName("DataAnalysis");
193 dataToolbar->layout()->setSpacing(0);
196 myDesktop->addToolBar(Qt::TopToolBarArea, mainToolBar);
197 myDesktop->addToolBar(Qt::TopToolBarArea, vcrToolbar);
198 myDesktop->addToolBar(Qt::TopToolBarArea, timeToolbar);
199 myDesktop->addToolBar(Qt::TopToolBarArea, colorToolbar);
200 myDesktop->insertToolBarBreak(colorToolbar);
201 myDesktop->addToolBar(Qt::TopToolBarArea, reprToolbar);
202 myDesktop->addToolBar(Qt::TopToolBarArea, cameraToolbar);
203 myDesktop->addToolBar(Qt::TopToolBarArea, axesToolbar);
204 myDesktop->addToolBar(Qt::TopToolBarArea, macrosToolbar);
205 myDesktop->addToolBar(Qt::TopToolBarArea, commonToolbar);
206 myDesktop->addToolBar(Qt::TopToolBarArea, dataToolbar);
208 mainAction = mainToolBar->toggleViewAction();
209 vcrAction = vcrToolbar->toggleViewAction();
210 timeAction = timeToolbar->toggleViewAction();
211 colorAction = colorToolbar->toggleViewAction();
212 reprAction = reprToolbar->toggleViewAction();
213 cameraAction = cameraToolbar->toggleViewAction();
214 axesAction = axesToolbar->toggleViewAction();
215 macrosAction = macrosToolbar->toggleViewAction();
216 commonAction = commonToolbar->toggleViewAction();
217 dataAction = dataToolbar->toggleViewAction();
219 // The piece od the code below is neccessary to correct update "Pipeline Browser",
220 // "Properties Panel", toolbars and menus
222 // Initilaize pqApplyBehavior here because witout pqPropertiesPanel instance it doesn't make sence
223 pqApplyBehavior* applyBehavior = new pqApplyBehavior(this);
224 foreach (pqPropertiesPanel* ppanel, myDesktop->findChildren<pqPropertiesPanel*>())
226 applyBehavior->registerPanel(ppanel);
229 QMetaObject::invokeMethod( &pqActiveObjects::instance(),
232 Q_ARG( pqOutputPort*, pqActiveObjects::instance().activePort() ) );
234 QMetaObject::invokeMethod( &pqActiveObjects::instance(),
237 Q_ARG( pqView*, pqActiveObjects::instance().activeView() ) );
239 pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
240 pqServer* serv = pqActiveObjects::instance().activeServer();
243 QMetaObject::invokeMethod( smModel,
246 Q_ARG( pqServer*, serv ) );
248 QMetaObject::invokeMethod( serv,
251 Q_ARG( pqServerManagerModelItem* , NULL ) );
254 //publishExistingSources();
255 myPVWidgetsFlag = true;
259 void PVViewer_GUIElements::setToolBarVisible(bool show)
261 QCoreApplication::processEvents();
262 if (!myPVWidgetsFlag)
265 mainAction->setChecked(!show);
266 mainAction->setVisible(show);
267 mainAction->trigger();
269 setVCRTimeToolBarVisible(show);
271 colorAction->setChecked(!show);
272 colorAction->setVisible(show);
273 colorAction->trigger();
274 reprAction->setChecked(!show);
275 reprAction->setVisible(show);
276 reprAction->trigger();
277 cameraAction->setChecked(!show);
278 cameraAction->setVisible(show);
279 cameraAction->trigger();
280 axesAction->setChecked(!show);
281 axesAction->setVisible(show);
282 axesAction->trigger();
283 macrosAction->setChecked(!show);
284 macrosAction->setVisible(show);
285 macrosAction->trigger();
286 commonAction->setChecked(!show);
287 commonAction->setVisible(show);
288 commonAction->trigger();
289 dataAction->setChecked(!show);
290 dataAction->setVisible(show);
291 dataAction->trigger();
294 void PVViewer_GUIElements::setVCRTimeToolBarVisible(bool show)
296 vcrAction->setChecked(!show);
297 vcrAction->setVisible(show);
298 vcrAction->trigger();
299 timeAction->setChecked(!show);
300 timeAction->setVisible(show);
301 timeAction->trigger();
304 QList<QToolBar*> PVViewer_GUIElements::getToolbars()
308 l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar
309 << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar
310 << commonToolbar << dataToolbar;
314 void PVViewer_GUIElements::setToolBarEnabled(bool enabled)
316 if (!myPVWidgetsFlag)
319 mainToolBar ->setEnabled(enabled);
320 vcrToolbar ->setEnabled(enabled);
321 timeToolbar ->setEnabled(enabled);
322 colorToolbar ->setEnabled(enabled);
323 reprToolbar ->setEnabled(enabled);
324 cameraToolbar->setEnabled(enabled);
325 axesToolbar ->setEnabled(enabled);
326 macrosToolbar->setEnabled(enabled);
327 commonToolbar->setEnabled(enabled);
328 dataToolbar ->setEnabled(enabled);
332 pqPropertiesPanel* PVViewer_GUIElements::getPropertiesPanel()
335 return propertiesPanel;
338 pqPipelineBrowserWidget* PVViewer_GUIElements::getPipelineBrowserWidget()
341 return pipelineBrowserWidget;
345 pqVCRToolbar* PVViewer_GUIElements::getVCRToolbar()
351 pqAnimationTimeToolbar* PVViewer_GUIElements::getTimeToolbar()
357 QMenu* PVViewer_GUIElements::getFiltersMenu() {
361 QMenu* PVViewer_GUIElements::getSourcesMenu() {
366 QMenu* PVViewer_GUIElements::getMacrosMenu() {
371 QMenu* PVViewer_GUIElements::getCatalystMenu() {
376 void PVViewer_GUIElements::publishExistingSources() {
377 vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().proxyManager();
378 pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
379 if( !pxm || !smmodel )
381 vtkSMProxyIterator* iter = vtkSMProxyIterator::New();
382 iter->SetModeToOneGroup();
383 iter->SetSessionProxyManager( pxm );
384 for ( iter->Begin( "sources" ); !iter->IsAtEnd(); iter->Next() ) {
385 if ( pqProxy* item = smmodel->findItem<pqProxy*>( iter->GetProxy() ) ) {
386 pqPipelineSource* source = qobject_cast<pqPipelineSource*>( item );
387 QMetaObject::invokeMethod( smmodel,
390 Q_ARG( pqPipelineSource* , source ) );