1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2019 CEA/DEN, EDF R&D
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : PVGUI_Module_MenuActions.cxx
22 // Author : Margarita KARPUNINA
25 #include "PVGUI_Module.h"
26 #include "PVViewer_ViewManager.h"
27 #include "PVViewer_GUIElements.h"
29 #include <QtxActionToolMgr.h>
30 #include <LightApp_Application.h>
31 #include <SUIT_Desktop.h>
33 #include <QApplication>
35 #include <QDockWidget>
39 #include <QScrollArea>
40 #include <QVBoxLayout>
42 #include <QToolButton>
44 #include <pqAnimationViewWidget.h>
45 #include <pqAnimationWidget.h>
47 #include <pqApplicationCore.h>
48 #include <pqComparativeVisPanel.h>
49 #include <pqPipelineBrowserWidget.h>
50 #include <pqProxyInformationWidget.h>
51 #include <pqDataInformationWidget.h>
52 #include <pqPVAnimationWidget.h>
53 #include <pqFindDataSelectionDisplayFrame.h>
54 #include <pqMultiBlockInspectorWidget.h>
55 #include <pqProgressWidget.h>
56 #include <pqProgressManager.h>
57 #include <pqPropertiesPanel.h>
58 #include <pqPVApplicationCore.h>
59 #include <pqAnimationManager.h>
61 #include <pqApplicationCore.h>
62 #include <pqPluginManager.h>
63 #include <pqParaViewMenuBuilders.h>
64 #include <pqCollaborationPanel.h>
65 #include <pqMemoryInspectorPanel.h>
66 #include <pqColorMapEditor.h>
67 #include <pqDeleteReaction.h>
69 #include <vtkPVGeneralSettings.h>
70 #include <vtkSMSettings.h>
72 class ResizeHelper : public pqPVAnimationWidget
74 // TEMPORARY WORKAROUND AROUND PARAVIEW 3.14 BUG:
75 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
76 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
77 // THIS BUG IS NATURALLY FIXED BY ADDING
78 // this->updateGeometries();
80 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
81 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
82 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
85 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
87 void resizeEvent(QResizeEvent* e)
89 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
92 QApplication::sendEvent( w, &e );
94 pqPVAnimationWidget::resizeEvent( e );
99 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
100 ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
101 ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
103 void PVGUI_Module::setupDockWidgets()
105 SUIT_Desktop* desk = application()->desktop();
106 PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desk);
108 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
109 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
110 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
113 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
114 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
115 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
116 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
117 pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
118 pipelineBrowserDock->setWidget(browser);
119 myDockWidgets[pipelineBrowserDock] = true;
120 pipelineBrowserDock->hide();
122 // PROPERTIES, DISPLAY and VIEW:
123 // See ParaViewMainWindow.cxx - those three panels can be separated or grouped.
124 vtkSMSettings* settings = vtkSMSettings::GetInstance();
126 // Properties dock (previously called OBJECT_INSPECTOR)
127 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
128 propertiesDock->setObjectName("propertiesDock");
129 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
130 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
132 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
133 propertiesDock->setWidget(propertiesPanel);
134 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
135 // hook delete to pqDeleteReaction.
136 QAction* tempDeleteAction = new QAction(this);
137 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
138 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
139 myDockWidgets[propertiesDock] = true;
140 propertiesDock->hide();
142 int propertiesPanelMode = settings->GetSettingAsInt(
143 ".settings.GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE);
146 QDockWidget* displayPropertiesDock = 0;
147 if (propertiesPanelMode == vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES ||
148 propertiesPanelMode == vtkPVGeneralSettings::ALL_SEPARATE )
150 displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
151 displayPropertiesDock->setObjectName("displayPropertiesDock");
152 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
153 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
155 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
156 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
157 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
158 displayPropertiesDock->setWidget(displayPropertiesPanel);
159 myDockWidgets[displayPropertiesDock] = false;
160 displayPropertiesDock->hide();
164 QDockWidget* viewPropertiesDock = 0;
165 if (propertiesPanelMode == vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES ||
166 propertiesPanelMode == vtkPVGeneralSettings::ALL_SEPARATE )
168 viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
169 viewPropertiesDock->setObjectName("viewPropertiesDock");
170 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
171 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
173 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
174 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
175 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
176 viewPropertiesDock->setWidget(viewPropertiesPanel);
177 myDockWidgets[viewPropertiesDock] = false;
178 viewPropertiesDock->hide();
181 switch (propertiesPanelMode)
183 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
184 propertiesPanel->setPanelMode(
185 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
188 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
189 propertiesPanel->setPanelMode(
190 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
193 case vtkPVGeneralSettings::ALL_SEPARATE:
194 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
197 case vtkPVGeneralSettings::ALL_IN_ONE:
199 propertiesPanel->setPanelMode(
200 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
205 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
206 informationDock->setObjectName("informationDock");
208 QWidget* informationWidgetFrame = new QWidget(informationDock);
209 informationWidgetFrame->setObjectName("informationWidgetFrame");
211 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
212 verticalLayout_2->setSpacing(0);
213 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
215 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
216 informationScrollArea->setObjectName("informationScrollArea") ;
217 informationScrollArea->setWidgetResizable(true);
219 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
220 informationWidget->setObjectName("informationWidget");
221 informationWidget->setGeometry(QRect(0, 0, 77, 214));
222 informationScrollArea->setWidget(informationWidget);
224 verticalLayout_2->addWidget(informationScrollArea);
225 informationDock->setWidget(informationWidgetFrame);
227 myDockWidgets[informationDock] = true;
229 if ( viewPropertiesDock )
230 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
231 if ( displayPropertiesDock )
232 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
233 desk->tabifyDockWidget(propertiesDock, informationDock);
234 propertiesDock->raise();
237 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
238 statisticsViewDock->setObjectName("statisticsViewDock");
239 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
240 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
241 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
242 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
243 statisticsViewDock->setWidget(aStatWidget);
244 myDockWidgets[statisticsViewDock] = false; // hidden by default
247 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
248 animationViewDock->setObjectName("animationViewDock");
249 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
250 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
252 // RNV: Emit signal in order to make sure that animation scene is set
253 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
254 "activeSceneChanged",
255 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
257 animationViewDock->setWidget(animation_panel);
258 myDockWidgets[animationViewDock] = false; // hidden by default
260 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
262 // Selection inspector
263 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
264 selectionDisplayDock->setObjectName("selectionInspectorDock");
265 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
266 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
267 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
268 selectionDisplayDock->setWidget(aSelInspector);
269 myDockWidgets[selectionDisplayDock] = false; // hidden by default
271 // Multi-block inspector
272 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
273 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
274 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
275 pqMultiBlockInspectorWidget* mbi_panel = new pqMultiBlockInspectorWidget( multiBlockInspectorPanelDock );
276 multiBlockInspectorPanelDock->setWidget(mbi_panel);
277 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
280 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
281 comparativePanelDock->setObjectName("comparativePanelDock");
282 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
283 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
284 comparativePanelDock->setWidget(cv_panel);
285 myDockWidgets[comparativePanelDock] = false; // hidden by default
287 // Collaboration view
288 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
289 collaborationPanelDock->setObjectName("collaborationPanelDock");
290 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
291 collaborationPanel->setObjectName("collaborationPanel");
292 collaborationPanelDock->setWidget(collaborationPanel);
293 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
294 myDockWidgets[collaborationPanelDock] = false; // hidden by default
297 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
298 colorMapEditorDock->setObjectName("colorMapEditorDock");
299 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
300 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
301 colorMapEditorDock->setWidget(cmed_panel);
302 myDockWidgets[colorMapEditorDock] = false; // hidden by default
304 // Provide access to the color-editor panel for the application.
305 pqApplicationCore::instance()->registerManager(
306 "COLOR_EDITOR_PANEL", colorMapEditorDock);
308 // Memory inspector dock
309 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
310 memoryInspectorDock->setObjectName("memoryInspectorDock");
312 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
313 dockWidgetContents->setObjectName("dockWidgetContents");
314 memoryInspectorDock->setWidget(dockWidgetContents);
316 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
317 myDockWidgets[memoryInspectorDock] = false; // hidden by default
319 // Setup the statusbar ...
320 pqProgressManager* progress_manager =
321 pqApplicationCore::instance()->getProgressManager();
323 // Progress bar/button management
324 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
325 progress_manager->addNonBlockableObject(aProgress);
326 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
328 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
329 aProgress, SLOT(enableProgress(bool)));
331 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
332 aProgress, SLOT(setProgress(const QString&, int)));
334 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
335 aProgress, SLOT(enableAbort(bool)));
337 QObject::connect( aProgress, SIGNAL(abortPressed()),
338 progress_manager, SLOT(triggerAbort()));
340 desk->statusBar()->addPermanentWidget(aProgress);
341 aProgress->setEnabled(true);
343 // Set up the dock window corners to give the vertical docks more room.
344 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
345 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
347 // Setup the default dock configuration ...
348 statisticsViewDock->hide();
349 comparativePanelDock->hide();
350 animationViewDock->hide();
351 multiBlockInspectorPanelDock->hide();
352 selectionDisplayDock->hide();
353 collaborationPanelDock->hide();
354 memoryInspectorDock->hide();
355 colorMapEditorDock->hide();
359 \brief Save states of dockable ParaView widgets.
361 void PVGUI_Module::saveDockWidgetsState(bool hideWidgets)
363 SUIT_Desktop* desk = application()->desktop();
365 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
366 // ... the following code is commented...
367 // Save the state of the window ...
368 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
370 //for (int i = 0; i < myDockWidgets.size(); ++i)
371 // myDockWidgets.at(i)->setParent(0);
372 // ... and replaced - manually hide dock windows
374 // store dock widgets visibility state and hide'em all
375 QMapIterator<QWidget*, bool> it1( myDockWidgets );
376 while( it1.hasNext() ) {
378 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
379 myDockWidgets[dw] = dw->isVisible();
381 dw->setVisible( false );
382 dw->toggleViewAction()->setVisible( false );
385 // store toolbar breaks state and remove all tollbar breaks
386 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
387 while( it2.hasNext() ) {
389 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
390 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
391 if ( myToolbarBreaks[tb] && hideWidgets )
392 desk->removeToolBarBreak( tb );
394 // store toolbars visibility state and hide'em all
395 QMapIterator<QWidget*, bool> it3( myToolbars );
396 while( it3.hasNext() ) {
398 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
399 myToolbars[tb] = tb->isVisible();
401 tb->setVisible( false );
402 tb->toggleViewAction()->setVisible( false );
408 \brief Restore states of dockable ParaView widgets.
410 void PVGUI_Module::restoreDockWidgetsState()
412 SUIT_Desktop* desk = application()->desktop();
414 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
415 // ... the following code is commented...
416 //for (int i = 0; i < myDockWidgets.size(); ++i)
417 // myDockWidgets.at(i)->setParent(desk);
419 // Restore the state of the window ...
420 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
421 // ... and replaced - manually hide dock windows
423 // restore dock widgets visibility state
424 QMapIterator<QWidget*, bool> it1( myDockWidgets );
425 while( it1.hasNext() ) {
427 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
428 dw->setVisible( it1.value() );
429 dw->toggleViewAction()->setVisible( true );
432 // restore toolbar breaks state
433 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
434 while( it2.hasNext() ) {
436 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
437 if ( myToolbarBreaks[tb] )
438 desk->insertToolBarBreak( tb );
441 // restore toolbar visibility state
442 QMapIterator<QWidget*, bool> it3( myToolbars );
443 while( it3.hasNext() ) {
445 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
446 tb->setVisible( it3.value() );
447 tb->toggleViewAction()->setVisible( true );
454 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
456 void PVGUI_Module::storeCommonWindowsState() {
457 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
458 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
459 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
460 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
461 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
462 // configuration file.
464 // But in contrast to others modules ParaVis module default settings hide some dockable
465 // windows, so to restore it at the moment of the ParaVis de-activation we call
466 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
469 LightApp_Application* anApp = getApp();
473 int begin = LightApp_Application::WT_ObjectBrowser;
474 int end = LightApp_Application::WT_User;
475 for( int i = begin; i <= end; i++ ) {
476 QWidget* wg = anApp->getWindow(i);
478 QDockWidget* dock = 0;
479 QWidget* w = wg->parentWidget();
480 while ( w && !dock ) {
481 dock = ::qobject_cast<QDockWidget*>( w );
482 w = w->parentWidget();
485 if(!myCommonMap.contains(i)){
486 myCommonMap.insert(i,dock->isVisible());
488 myCommonMap[i] = dock->isVisible();
496 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
498 void PVGUI_Module::restoreCommonWindowsState() {
499 LightApp_Application* anApp = getApp();
502 DockWindowMap::const_iterator it = myCommonMap.begin();
503 for( ;it != myCommonMap.end(); it++ ) {
504 QWidget* wg = anApp->getWindow(it.key());
506 QDockWidget* dock = 0;
507 QWidget* w = wg->parentWidget();
508 while ( w && !dock ) {
509 dock = ::qobject_cast<QDockWidget*>( w );
510 w = w->parentWidget();
513 dock->setVisible(it.value());