From b5c645c8183f652a28ab71088ede7cbb706a3e5c Mon Sep 17 00:00:00 2001 From: rnv Date: Thu, 9 Jun 2016 18:04:08 +0300 Subject: [PATCH] Implementation of the "0023270: [CEA 1822] PARAVIS GUI widgets should be instanciated only when needed" feature. --- src/PVViewer/PVViewer_Behaviors.cxx | 4 + src/PVViewer/PVViewer_Core.cxx | 8 +- src/PVViewer/PVViewer_GUIElements.cxx | 273 ++++++++++++++++++-------- src/PVViewer/PVViewer_GUIElements.h | 21 +- 4 files changed, 207 insertions(+), 99 deletions(-) diff --git a/src/PVViewer/PVViewer_Behaviors.cxx b/src/PVViewer/PVViewer_Behaviors.cxx index e83ad8c17..f31a6dfd6 100644 --- a/src/PVViewer/PVViewer_Behaviors.cxx +++ b/src/PVViewer/PVViewer_Behaviors.cxx @@ -120,11 +120,15 @@ void PVViewer_Behaviors::instanciateAllBehaviors(QMainWindow * desk) new pqViewStreamingBehavior(this); new pqStandardArrayColorMapsBehavior(this); + // Move instantiation of the pqApplyBehavior to the PVViewer_GUIElements::buildPVWidgets(), + // because without pqPropertiesPanel it doesn't make sense. + /* pqApplyBehavior* applyBehavior = new pqApplyBehavior(this); foreach (pqPropertiesPanel* ppanel, desk->findChildren()) { applyBehavior->registerPanel(ppanel); } + */ BehaviorLoadingLevel = 2; } } diff --git a/src/PVViewer/PVViewer_Core.cxx b/src/PVViewer/PVViewer_Core.cxx index 7b9621847..8f9abaafc 100644 --- a/src/PVViewer/PVViewer_Core.cxx +++ b/src/PVViewer/PVViewer_Core.cxx @@ -93,9 +93,11 @@ bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop, LogWindow * logWindo free(argv[i]); delete[] argv; } - // Initialize GUI elements if needed: - PVViewer_GUIElements::GetInstance(aDesktop); - return true; + // Initialization of ParaView GUI widgets will be done when these widgets are + // really needed. + // PVViewer_GUIElements* inst = PVViewer_GUIElements::GetInstance(aDesktop); + // inst->getPropertiesPanel(); + return true; } void PVViewer_Core::ParaviewInitBehaviors(bool fullSetup, QMainWindow* aDesktop) diff --git a/src/PVViewer/PVViewer_GUIElements.cxx b/src/PVViewer/PVViewer_GUIElements.cxx index 46eb7fcc2..9e795dc55 100644 --- a/src/PVViewer/PVViewer_GUIElements.cxx +++ b/src/PVViewer/PVViewer_GUIElements.cxx @@ -19,50 +19,52 @@ // Author: Adrien Bruneton (CEA) #include "PVViewer_GUIElements.h" +#include "PVServer_ServiceWrapper.h" +#include "PVViewer_Core.h" +#include "PVViewer_ViewManager.h" -#include -#include -#include -#include -#include +#include +#include #include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include +#include #include +#include -#include -#include - +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include PVViewer_GUIElements * PVViewer_GUIElements::theInstance = 0; PVViewer_GUIElements::PVViewer_GUIElements(QMainWindow* desk) : - propertiesPanel(0), pipelineBrowserWidget(0), - sourcesMenu(0) + myDesktop(desk), + propertiesPanel(0), + pipelineBrowserWidget(0), + sourcesMenu(0), + filtersMenu(0), + macrosMenu(0), + myPVWidgetsFlag(false) { - propertiesPanel = new pqPropertiesPanel(desk); - propertiesPanel->hide(); - pipelineBrowserWidget = new pqPipelineBrowserWidget(desk); - pipelineBrowserWidget->hide(); - - sourcesMenu = new QMenu(0); - pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, desk); - filtersMenu = new QMenu(0); - pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, desk); - macrosMenu = new QMenu(0); - pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu); - - myBuildToolbars(desk); } PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk) @@ -76,56 +78,135 @@ PVViewer_GUIElements * PVViewer_GUIElements::GetInstance(QMainWindow* desk) * See ParaView source code: pqParaViewMenuBuilders::buildToolbars() * to keep this function up to date: */ -void PVViewer_GUIElements::myBuildToolbars(QMainWindow* mainWindow) +void PVViewer_GUIElements::buildPVWidgets() { - mainToolBar = new pqMainControlsToolbar(mainWindow) - << pqSetName("MainControlsToolbar"); - mainToolBar->layout()->setSpacing(0); + if (!myPVWidgetsFlag) { - vcrToolbar = new pqVCRToolbar(mainWindow) - << pqSetName("VCRToolbar"); - vcrToolbar->layout()->setSpacing(0); + //Pipeline Browser + if ( !pipelineBrowserWidget ) { + pipelineBrowserWidget = new pqPipelineBrowserWidget(myDesktop); + } - timeToolbar = new pqAnimationTimeToolbar(mainWindow) - << pqSetName("currentTimeToolbar"); - timeToolbar->layout()->setSpacing(0); + // Properties panel + if ( !propertiesPanel ) { + propertiesPanel = new pqPropertiesPanel(myDesktop); + } + + // Sources Menu + if (!sourcesMenu) { + sourcesMenu = new QMenu(0); + pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, myDesktop); + } - colorToolbar = new pqColorToolbar(mainWindow) - << pqSetName("variableToolbar"); - colorToolbar->layout()->setSpacing(0); + //Filer Menu + if (!filtersMenu) { + filtersMenu = new QMenu(0); + pqParaViewMenuBuilders::buildFiltersMenu(*filtersMenu, myDesktop); + } - reprToolbar = new pqRepresentationToolbar(mainWindow) - << pqSetName("representationToolbar"); - reprToolbar->layout()->setSpacing(0); + // Macros Menu + if (!macrosMenu) { + macrosMenu = new QMenu(0); + pqParaViewMenuBuilders::buildMacrosMenu(*macrosMenu); + } - cameraToolbar = new pqCameraToolbar(mainWindow) - << pqSetName("cameraToolbar"); - cameraToolbar->layout()->setSpacing(0); + mainToolBar = new pqMainControlsToolbar(myDesktop) + << pqSetName("MainControlsToolbar"); + mainToolBar->layout()->setSpacing(0); - axesToolbar = new pqAxesToolbar(mainWindow) - << pqSetName("axesToolbar"); - axesToolbar->layout()->setSpacing(0); + vcrToolbar = new pqVCRToolbar(myDesktop) + << pqSetName("VCRToolbar"); + vcrToolbar->layout()->setSpacing(0); - // Give the macros menu to the pqPythonMacroSupervisor - pqPythonManager* manager = qobject_cast( + timeToolbar = new pqAnimationTimeToolbar(myDesktop) + << pqSetName("currentTimeToolbar"); + timeToolbar->layout()->setSpacing(0); + + colorToolbar = new pqColorToolbar(myDesktop) + << pqSetName("variableToolbar"); + colorToolbar->layout()->setSpacing(0); + + reprToolbar = new pqRepresentationToolbar(myDesktop) + << pqSetName("representationToolbar"); + reprToolbar->layout()->setSpacing(0); + + cameraToolbar = new pqCameraToolbar(myDesktop) + << pqSetName("cameraToolbar"); + cameraToolbar->layout()->setSpacing(0); + + axesToolbar = new pqAxesToolbar(myDesktop) + << pqSetName("axesToolbar"); + axesToolbar->layout()->setSpacing(0); + + // Give the macros menu to the pqPythonMacroSupervisor + pqPythonManager* manager = qobject_cast( pqApplicationCore::instance()->manager("PYTHON_MANAGER")); - macrosToolbar = new QToolBar("Macros Toolbars", mainWindow) + macrosToolbar = new QToolBar("Macros Toolbars", myDesktop) << pqSetName("MacrosToolbar"); - manager->addWidgetForRunMacros(macrosToolbar); + manager->addWidgetForRunMacros(macrosToolbar); + + commonToolbar = new QToolBar("Common", myDesktop) << pqSetName("Common"); + commonToolbar->layout()->setSpacing(0); + + dataToolbar = new QToolBar("DataAnalysis", myDesktop) << pqSetName("DataAnalysis"); + dataToolbar->layout()->setSpacing(0); + + // add Toolbars + myDesktop->addToolBar(Qt::TopToolBarArea, mainToolBar); + myDesktop->addToolBar(Qt::TopToolBarArea, vcrToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, timeToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, colorToolbar); + myDesktop->insertToolBarBreak(colorToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, reprToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, cameraToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, axesToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, macrosToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, commonToolbar); + myDesktop->addToolBar(Qt::TopToolBarArea, dataToolbar); + + mainAction = mainToolBar->toggleViewAction(); + vcrAction = vcrToolbar->toggleViewAction(); + timeAction = timeToolbar->toggleViewAction(); + colorAction = colorToolbar->toggleViewAction(); + reprAction = reprToolbar->toggleViewAction(); + cameraAction = cameraToolbar->toggleViewAction(); + axesAction = axesToolbar->toggleViewAction(); + macrosAction = macrosToolbar->toggleViewAction(); + commonAction = commonToolbar->toggleViewAction(); + dataAction = dataToolbar->toggleViewAction(); + + // The piece od the code below is neccessary to correct update "Pipeline Browser", + // "Properties Panel", toolbars and menus + + // Initilaize pqApplyBehavior here because witout pqPropertiesPanel instance it doesn't make sence + pqApplyBehavior* applyBehavior = new pqApplyBehavior(this); + foreach (pqPropertiesPanel* ppanel, myDesktop->findChildren()) + { + applyBehavior->registerPanel(ppanel); + } + + emit pqActiveObjects::instance().portChanged(pqActiveObjects::instance().activePort()); + emit pqActiveObjects::instance().viewChanged(pqActiveObjects::instance().activeView()); - commonToolbar = new QToolBar("Common", mainWindow) << pqSetName("Common"); - commonToolbar->layout()->setSpacing(0); + pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel(); + pqServer* serv = pqActiveObjects::instance().activeServer(); - dataToolbar = new QToolBar("DataAnalysis", mainWindow) << pqSetName("DataAnalysis"); - dataToolbar->layout()->setSpacing(0); + if (serv) { + emit smModel->serverAdded(serv); + emit serv->nameChanged(NULL); + } - addToolbars(mainWindow); + myPVWidgetsFlag = true; + } } void PVViewer_GUIElements::setToolBarVisible(bool show) -{ +{ QCoreApplication::processEvents(); + if (!myPVWidgetsFlag) + return; + mainAction->setChecked(!show); mainAction->setVisible(show); mainAction->trigger(); @@ -158,34 +239,9 @@ void PVViewer_GUIElements::setToolBarVisible(bool show) dataAction->trigger(); } -void PVViewer_GUIElements::addToolbars(QMainWindow* desk) -{ - desk->addToolBar(Qt::TopToolBarArea, mainToolBar); - desk->addToolBar(Qt::TopToolBarArea, vcrToolbar); - desk->addToolBar(Qt::TopToolBarArea, timeToolbar); - desk->addToolBar(Qt::TopToolBarArea, colorToolbar); - desk->insertToolBarBreak(colorToolbar); - desk->addToolBar(Qt::TopToolBarArea, reprToolbar); - desk->addToolBar(Qt::TopToolBarArea, cameraToolbar); - desk->addToolBar(Qt::TopToolBarArea, axesToolbar); - desk->addToolBar(Qt::TopToolBarArea, macrosToolbar); - desk->addToolBar(Qt::TopToolBarArea, commonToolbar); - desk->addToolBar(Qt::TopToolBarArea, dataToolbar); - - mainAction = mainToolBar->toggleViewAction(); - vcrAction = vcrToolbar->toggleViewAction(); - timeAction = timeToolbar->toggleViewAction(); - colorAction = colorToolbar->toggleViewAction(); - reprAction = reprToolbar->toggleViewAction(); - cameraAction = cameraToolbar->toggleViewAction(); - axesAction = axesToolbar->toggleViewAction(); - macrosAction = macrosToolbar->toggleViewAction(); - commonAction = commonToolbar->toggleViewAction(); - dataAction = dataToolbar->toggleViewAction(); -} - QList PVViewer_GUIElements::getToolbars() { + buildPVWidgets(); QList l; l << mainToolBar << vcrToolbar << timeToolbar << colorToolbar << reprToolbar << cameraToolbar << axesToolbar << macrosToolbar @@ -195,6 +251,9 @@ QList PVViewer_GUIElements::getToolbars() void PVViewer_GUIElements::setToolBarEnabled(bool enabled) { + if (!myPVWidgetsFlag) + return; + mainToolBar ->setEnabled(enabled); vcrToolbar ->setEnabled(enabled); timeToolbar ->setEnabled(enabled); @@ -206,3 +265,43 @@ void PVViewer_GUIElements::setToolBarEnabled(bool enabled) commonToolbar->setEnabled(enabled); dataToolbar ->setEnabled(enabled); } + + +pqPropertiesPanel* PVViewer_GUIElements::getPropertiesPanel() +{ + buildPVWidgets(); + return propertiesPanel; +} + +pqPipelineBrowserWidget* PVViewer_GUIElements::getPipelineBrowserWidget() +{ + buildPVWidgets(); + return pipelineBrowserWidget; +} + + +pqVCRToolbar* PVViewer_GUIElements::getVCRToolbar() +{ + buildPVWidgets(); + return vcrToolbar; +} + +pqAnimationTimeToolbar* PVViewer_GUIElements::getTimeToolbar() +{ + buildPVWidgets(); + return timeToolbar; +} + +QMenu* PVViewer_GUIElements::getFiltersMenu() { + buildPVWidgets(); + return filtersMenu; +} +QMenu* PVViewer_GUIElements::getSourcesMenu() { + buildPVWidgets(); + return sourcesMenu; +} + +QMenu* PVViewer_GUIElements::getMacrosMenu() { + buildPVWidgets(); + return macrosMenu; +} diff --git a/src/PVViewer/PVViewer_GUIElements.h b/src/PVViewer/PVViewer_GUIElements.h index add85a7c2..41a058314 100644 --- a/src/PVViewer/PVViewer_GUIElements.h +++ b/src/PVViewer/PVViewer_GUIElements.h @@ -46,18 +46,16 @@ class PVVIEWER_EXPORT PVViewer_GUIElements: public QObject public: static PVViewer_GUIElements * GetInstance(QMainWindow * desk); - pqPropertiesPanel * getPropertiesPanel() { return propertiesPanel; } - pqPipelineBrowserWidget * getPipelineBrowserWidget() { return pipelineBrowserWidget; } + pqPropertiesPanel * getPropertiesPanel(); + pqPipelineBrowserWidget * getPipelineBrowserWidget(); - QMenu* getFiltersMenu() { return filtersMenu; } - QMenu* getSourcesMenu() { return sourcesMenu; } - QMenu* getMacrosMenu() { return macrosMenu; } + QMenu* getFiltersMenu(); + QMenu* getSourcesMenu(); + QMenu* getMacrosMenu(); - pqVCRToolbar* getVCRToolbar() { return vcrToolbar; } - pqAnimationTimeToolbar* getTimeToolbar() { return timeToolbar; } + pqVCRToolbar* getVCRToolbar(); + pqAnimationTimeToolbar* getTimeToolbar(); - void myBuildToolbars(QMainWindow* desk); - void addToolbars(QMainWindow* desk); void setToolBarVisible(bool show); void setToolBarEnabled(bool enabled); QList getToolbars(); @@ -68,6 +66,8 @@ private: static PVViewer_GUIElements* theInstance; + void buildPVWidgets(); + // Widgets pqPropertiesPanel* propertiesPanel; pqPipelineBrowserWidget* pipelineBrowserWidget; @@ -88,6 +88,9 @@ private: QToolBar* macrosToolbar; QToolBar* commonToolbar; QToolBar* dataToolbar; + + QMainWindow* myDesktop; + bool myPVWidgetsFlag; public: QAction* mainAction; -- 2.39.2