1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2021 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>
71 #include <vtkPVConfig.h>
73 class ResizeHelper : public pqPVAnimationWidget
75 // TEMPORARY WORKAROUND AROUND PARAVIEW 3.14 BUG:
76 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
77 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
78 // THIS BUG IS NATURALLY FIXED BY ADDING
79 // this->updateGeometries();
81 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
82 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
83 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
86 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
88 void resizeEvent(QResizeEvent* e)
90 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
93 QApplication::sendEvent( w, &e );
95 pqPVAnimationWidget::resizeEvent( e );
100 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
101 ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
102 ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
104 void PVGUI_Module::setupDockWidgets()
106 SUIT_Desktop* desk = application()->desktop();
107 PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desk);
109 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
110 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
111 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
114 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
115 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
116 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
117 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
118 pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
119 pipelineBrowserDock->setWidget(browser);
120 myDockWidgets[pipelineBrowserDock] = true;
121 pipelineBrowserDock->hide();
123 // PROPERTIES, DISPLAY and VIEW:
124 // See ParaViewMainWindow.cxx - those three panels can be separated or grouped.
125 vtkSMSettings* settings = vtkSMSettings::GetInstance();
127 // Properties dock (previously called OBJECT_INSPECTOR)
128 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
129 propertiesDock->setObjectName("propertiesDock");
130 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
131 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
133 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
134 propertiesDock->setWidget(propertiesPanel);
135 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
136 // hook delete to pqDeleteReaction.
137 QAction* tempDeleteAction = new QAction(this);
138 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
139 #if PARAVIEW_VERSION_MAJOR==5 && PARAVIEW_VERSION_MINOR<9
140 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
142 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqProxy*)), SLOT(deleteSource(pqProxy*)));
144 myDockWidgets[propertiesDock] = true;
145 propertiesDock->hide();
147 int propertiesPanelMode = settings->GetSettingAsInt(
148 ".settings.GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE);
151 QDockWidget* displayPropertiesDock = 0;
152 if (propertiesPanelMode == vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES ||
153 propertiesPanelMode == vtkPVGeneralSettings::ALL_SEPARATE )
155 displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
156 displayPropertiesDock->setObjectName("displayPropertiesDock");
157 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
158 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
160 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
161 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
162 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
163 displayPropertiesDock->setWidget(displayPropertiesPanel);
164 myDockWidgets[displayPropertiesDock] = false;
165 displayPropertiesDock->hide();
169 QDockWidget* viewPropertiesDock = 0;
170 if (propertiesPanelMode == vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES ||
171 propertiesPanelMode == vtkPVGeneralSettings::ALL_SEPARATE )
173 viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
174 viewPropertiesDock->setObjectName("viewPropertiesDock");
175 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
176 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
178 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
179 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
180 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
181 viewPropertiesDock->setWidget(viewPropertiesPanel);
182 myDockWidgets[viewPropertiesDock] = false;
183 viewPropertiesDock->hide();
186 switch (propertiesPanelMode)
188 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
189 propertiesPanel->setPanelMode(
190 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
193 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
194 propertiesPanel->setPanelMode(
195 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
198 case vtkPVGeneralSettings::ALL_SEPARATE:
199 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
202 case vtkPVGeneralSettings::ALL_IN_ONE:
204 propertiesPanel->setPanelMode(
205 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
210 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
211 informationDock->setObjectName("informationDock");
213 QWidget* informationWidgetFrame = new QWidget(informationDock);
214 informationWidgetFrame->setObjectName("informationWidgetFrame");
216 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
217 verticalLayout_2->setSpacing(0);
218 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
220 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
221 informationScrollArea->setObjectName("informationScrollArea") ;
222 informationScrollArea->setWidgetResizable(true);
224 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
225 informationWidget->setObjectName("informationWidget");
226 informationWidget->setGeometry(QRect(0, 0, 77, 214));
227 informationScrollArea->setWidget(informationWidget);
229 verticalLayout_2->addWidget(informationScrollArea);
230 informationDock->setWidget(informationWidgetFrame);
232 myDockWidgets[informationDock] = true;
234 if ( viewPropertiesDock )
235 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
236 if ( displayPropertiesDock )
237 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
238 desk->tabifyDockWidget(propertiesDock, informationDock);
239 propertiesDock->raise();
242 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
243 statisticsViewDock->setObjectName("statisticsViewDock");
244 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
245 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
246 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
247 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
248 statisticsViewDock->setWidget(aStatWidget);
249 myDockWidgets[statisticsViewDock] = false; // hidden by default
252 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
253 animationViewDock->setObjectName("animationViewDock");
254 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
255 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
257 // RNV: Emit signal in order to make sure that animation scene is set
258 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
259 "activeSceneChanged",
260 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
262 animationViewDock->setWidget(animation_panel);
263 myDockWidgets[animationViewDock] = false; // hidden by default
265 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
267 // Selection inspector
268 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
269 selectionDisplayDock->setObjectName("selectionInspectorDock");
270 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
271 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
272 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
273 selectionDisplayDock->setWidget(aSelInspector);
274 myDockWidgets[selectionDisplayDock] = false; // hidden by default
276 // Multi-block inspector
277 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
278 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
279 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
280 pqMultiBlockInspectorWidget* mbi_panel = new pqMultiBlockInspectorWidget( multiBlockInspectorPanelDock );
281 multiBlockInspectorPanelDock->setWidget(mbi_panel);
282 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
285 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
286 comparativePanelDock->setObjectName("comparativePanelDock");
287 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
288 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
289 comparativePanelDock->setWidget(cv_panel);
290 myDockWidgets[comparativePanelDock] = false; // hidden by default
292 // Collaboration view
293 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
294 collaborationPanelDock->setObjectName("collaborationPanelDock");
295 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
296 collaborationPanel->setObjectName("collaborationPanel");
297 collaborationPanelDock->setWidget(collaborationPanel);
298 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
299 myDockWidgets[collaborationPanelDock] = false; // hidden by default
302 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
303 colorMapEditorDock->setObjectName("colorMapEditorDock");
304 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
305 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
306 colorMapEditorDock->setWidget(cmed_panel);
307 myDockWidgets[colorMapEditorDock] = false; // hidden by default
309 // Provide access to the color-editor panel for the application.
310 pqApplicationCore::instance()->registerManager(
311 "COLOR_EDITOR_PANEL", colorMapEditorDock);
313 // Memory inspector dock
314 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
315 memoryInspectorDock->setObjectName("memoryInspectorDock");
317 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
318 dockWidgetContents->setObjectName("dockWidgetContents");
319 memoryInspectorDock->setWidget(dockWidgetContents);
321 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
322 myDockWidgets[memoryInspectorDock] = false; // hidden by default
324 // Setup the statusbar ...
325 pqProgressManager* progress_manager =
326 pqApplicationCore::instance()->getProgressManager();
328 // Progress bar/button management
329 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
330 progress_manager->addNonBlockableObject(aProgress);
331 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
333 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
334 aProgress, SLOT(enableProgress(bool)));
336 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
337 aProgress, SLOT(setProgress(const QString&, int)));
339 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
340 aProgress, SLOT(enableAbort(bool)));
342 QObject::connect( aProgress, SIGNAL(abortPressed()),
343 progress_manager, SLOT(triggerAbort()));
345 desk->statusBar()->addPermanentWidget(aProgress);
346 aProgress->setEnabled(true);
348 // Set up the dock window corners to give the vertical docks more room.
349 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
350 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
352 // Setup the default dock configuration ...
353 statisticsViewDock->hide();
354 comparativePanelDock->hide();
355 animationViewDock->hide();
356 multiBlockInspectorPanelDock->hide();
357 selectionDisplayDock->hide();
358 collaborationPanelDock->hide();
359 memoryInspectorDock->hide();
360 colorMapEditorDock->hide();
364 \brief Save states of dockable ParaView widgets.
366 void PVGUI_Module::saveDockWidgetsState(bool hideWidgets)
368 SUIT_Desktop* desk = application()->desktop();
370 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
371 // ... the following code is commented...
372 // Save the state of the window ...
373 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
375 //for (int i = 0; i < myDockWidgets.size(); ++i)
376 // myDockWidgets.at(i)->setParent(0);
377 // ... and replaced - manually hide dock windows
379 // store dock widgets visibility state and hide'em all
380 QMapIterator<QWidget*, bool> it1( myDockWidgets );
381 while( it1.hasNext() ) {
383 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
384 myDockWidgets[dw] = dw->isVisible();
386 dw->setVisible( false );
387 dw->toggleViewAction()->setVisible( false );
390 // store toolbar breaks state and remove all tollbar breaks
391 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
392 while( it2.hasNext() ) {
394 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
395 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
396 if ( myToolbarBreaks[tb] && hideWidgets )
397 desk->removeToolBarBreak( tb );
399 // store toolbars visibility state and hide'em all
400 QMapIterator<QWidget*, bool> it3( myToolbars );
401 while( it3.hasNext() ) {
403 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
404 myToolbars[tb] = tb->isVisible();
406 tb->setVisible( false );
407 tb->toggleViewAction()->setVisible( false );
413 \brief Restore states of dockable ParaView widgets.
415 void PVGUI_Module::restoreDockWidgetsState()
417 SUIT_Desktop* desk = application()->desktop();
419 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
420 // ... the following code is commented...
421 //for (int i = 0; i < myDockWidgets.size(); ++i)
422 // myDockWidgets.at(i)->setParent(desk);
424 // Restore the state of the window ...
425 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
426 // ... and replaced - manually hide dock windows
428 // restore dock widgets visibility state
429 QMapIterator<QWidget*, bool> it1( myDockWidgets );
430 while( it1.hasNext() ) {
432 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
433 dw->setVisible( it1.value() );
434 dw->toggleViewAction()->setVisible( true );
437 // restore toolbar breaks state
438 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
439 while( it2.hasNext() ) {
441 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
442 if ( myToolbarBreaks[tb] )
443 desk->insertToolBarBreak( tb );
446 // restore toolbar visibility state
447 QMapIterator<QWidget*, bool> it3( myToolbars );
448 while( it3.hasNext() ) {
450 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
451 tb->setVisible( it3.value() );
452 tb->toggleViewAction()->setVisible( true );
459 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
461 void PVGUI_Module::storeCommonWindowsState() {
462 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
463 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
464 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
465 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
466 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
467 // configuration file.
469 // But in contrast to others modules ParaVis module default settings hide some dockable
470 // windows, so to restore it at the moment of the ParaVis de-activation we call
471 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
474 LightApp_Application* anApp = getApp();
478 int begin = LightApp_Application::WT_ObjectBrowser;
479 int end = LightApp_Application::WT_User;
480 for( int i = begin; i <= end; i++ ) {
481 QWidget* wg = anApp->getWindow(i);
483 QDockWidget* dock = 0;
484 QWidget* w = wg->parentWidget();
485 while ( w && !dock ) {
486 dock = ::qobject_cast<QDockWidget*>( w );
487 w = w->parentWidget();
490 if(!myCommonMap.contains(i)){
491 myCommonMap.insert(i,dock->isVisible());
493 myCommonMap[i] = dock->isVisible();
501 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
503 void PVGUI_Module::restoreCommonWindowsState() {
504 LightApp_Application* anApp = getApp();
507 DockWindowMap::const_iterator it = myCommonMap.begin();
508 for( ;it != myCommonMap.end(); it++ ) {
509 QWidget* wg = anApp->getWindow(it.key());
511 QDockWidget* dock = 0;
512 QWidget* w = wg->parentWidget();
513 while ( w && !dock ) {
514 dock = ::qobject_cast<QDockWidget*>( w );
515 w = w->parentWidget();
518 dock->setVisible(it.value());