1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2016 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 <pqSettings.h>
52 #include <pqDataInformationWidget.h>
53 #include <pqPVAnimationWidget.h>
54 #include <pqFindDataSelectionDisplayFrame.h>
55 #include <pqMultiBlockInspectorWidget.h>
56 #include <pqProgressWidget.h>
57 #include <pqProgressManager.h>
58 #include <pqPropertiesPanel.h>
59 #include <pqPVApplicationCore.h>
60 #include <pqAnimationManager.h>
62 #include <pqApplicationCore.h>
63 #include <pqPluginManager.h>
64 #include <pqParaViewMenuBuilders.h>
65 #include <pqCollaborationPanel.h>
66 #include <pqMemoryInspectorPanel.h>
67 #include <pqColorMapEditor.h>
68 #include <pqDeleteReaction.h>
70 #include <vtkPVGeneralSettings.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 pqSettings *settings = pqApplicationCore::instance()->settings();
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();
143 QDockWidget* displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
144 displayPropertiesDock->setObjectName("displayPropertiesDock");
145 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
146 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
148 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
149 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
150 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
151 displayPropertiesDock->setWidget(displayPropertiesPanel);
152 myDockWidgets[displayPropertiesDock] = false;
153 displayPropertiesDock->hide();
156 QDockWidget* viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
157 viewPropertiesDock->setObjectName("viewPropertiesDock");
158 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
159 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
161 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
162 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
163 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
164 viewPropertiesDock->setWidget(viewPropertiesPanel);
165 myDockWidgets[viewPropertiesDock] = false;
166 viewPropertiesDock->hide();
168 // Taken from ParaViewMainWindow.cxx:
169 int propertiesPanelMode = settings->value(
170 "GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE).toInt();
171 switch (propertiesPanelMode)
173 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
174 viewPropertiesDock->hide();
175 propertiesPanel->setPanelMode(
176 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
179 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
180 displayPropertiesDock->hide();
181 propertiesPanel->setPanelMode(
182 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
185 case vtkPVGeneralSettings::ALL_SEPARATE:
186 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
189 case vtkPVGeneralSettings::ALL_IN_ONE:
191 propertiesPanel->setPanelMode(
192 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
193 viewPropertiesDock->hide();
194 displayPropertiesDock->hide();
199 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
200 informationDock->setObjectName("informationDock");
202 QWidget* informationWidgetFrame = new QWidget(informationDock);
203 informationWidgetFrame->setObjectName("informationWidgetFrame");
205 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
206 verticalLayout_2->setSpacing(0);
207 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
209 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
210 informationScrollArea->setObjectName("informationScrollArea") ;
211 informationScrollArea->setWidgetResizable(true);
213 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
214 informationWidget->setObjectName("informationWidget");
215 informationWidget->setGeometry(QRect(0, 0, 77, 214));
216 informationScrollArea->setWidget(informationWidget);
218 verticalLayout_2->addWidget(informationScrollArea);
219 informationDock->setWidget(informationWidgetFrame);
221 myDockWidgets[informationDock] = true;
223 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
224 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
225 desk->tabifyDockWidget(propertiesDock, informationDock);
226 propertiesDock->raise();
229 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
230 statisticsViewDock->setObjectName("statisticsViewDock");
231 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
232 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
233 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
234 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
235 statisticsViewDock->setWidget(aStatWidget);
236 myDockWidgets[statisticsViewDock] = false; // hidden by default
239 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
240 animationViewDock->setObjectName("animationViewDock");
241 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
242 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
244 // RNV: Emit signal in order to make sure that animation scene is set
245 QMetaObject::invokeMethod( pqPVApplicationCore::instance()->animationManager(),
246 "activeSceneChanged",
247 Q_ARG( pqAnimationScene*, pqPVApplicationCore::instance()->animationManager()->getActiveScene() ) );
249 animationViewDock->setWidget(animation_panel);
250 myDockWidgets[animationViewDock] = false; // hidden by default
252 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
254 // Selection inspector
255 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
256 selectionDisplayDock->setObjectName("selectionInspectorDock");
257 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
258 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
259 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
260 selectionDisplayDock->setWidget(aSelInspector);
261 myDockWidgets[selectionDisplayDock] = false; // hidden by default
263 // Multi-block inspector
264 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
265 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
266 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
267 pqMultiBlockInspectorWidget* mbi_panel = new pqMultiBlockInspectorWidget( multiBlockInspectorPanelDock );
268 multiBlockInspectorPanelDock->setWidget(mbi_panel);
269 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
272 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
273 comparativePanelDock->setObjectName("comparativePanelDock");
274 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
275 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
276 comparativePanelDock->setWidget(cv_panel);
277 myDockWidgets[comparativePanelDock] = false; // hidden by default
279 // Collaboration view
280 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
281 collaborationPanelDock->setObjectName("collaborationPanelDock");
282 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
283 collaborationPanel->setObjectName("collaborationPanel");
284 collaborationPanelDock->setWidget(collaborationPanel);
285 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
286 myDockWidgets[collaborationPanelDock] = false; // hidden by default
289 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
290 colorMapEditorDock->setObjectName("colorMapEditorDock");
291 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
292 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
293 colorMapEditorDock->setWidget(cmed_panel);
294 myDockWidgets[colorMapEditorDock] = false; // hidden by default
296 // Provide access to the color-editor panel for the application.
297 pqApplicationCore::instance()->registerManager(
298 "COLOR_EDITOR_PANEL", colorMapEditorDock);
300 // Memory inspector dock
301 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
302 memoryInspectorDock->setObjectName("memoryInspectorDock");
304 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
305 dockWidgetContents->setObjectName("dockWidgetContents");
306 memoryInspectorDock->setWidget(dockWidgetContents);
308 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
309 myDockWidgets[memoryInspectorDock] = false; // hidden by default
311 // Setup the statusbar ...
312 pqProgressManager* progress_manager =
313 pqApplicationCore::instance()->getProgressManager();
315 // Progress bar/button management
316 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
317 progress_manager->addNonBlockableObject(aProgress);
318 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
320 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
321 aProgress, SLOT(enableProgress(bool)));
323 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
324 aProgress, SLOT(setProgress(const QString&, int)));
326 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
327 aProgress, SLOT(enableAbort(bool)));
329 QObject::connect( aProgress, SIGNAL(abortPressed()),
330 progress_manager, SLOT(triggerAbort()));
332 desk->statusBar()->addPermanentWidget(aProgress);
333 aProgress->setEnabled(true);
335 // Set up the dock window corners to give the vertical docks more room.
336 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
337 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
339 // Setup the default dock configuration ...
340 statisticsViewDock->hide();
341 comparativePanelDock->hide();
342 animationViewDock->hide();
343 multiBlockInspectorPanelDock->hide();
344 selectionDisplayDock->hide();
345 collaborationPanelDock->hide();
346 memoryInspectorDock->hide();
347 colorMapEditorDock->hide();
351 \brief Save states of dockable ParaView widgets.
353 void PVGUI_Module::saveDockWidgetsState(bool hideWidgets)
355 SUIT_Desktop* desk = application()->desktop();
357 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
358 // ... the following code is commented...
359 // Save the state of the window ...
360 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
362 //for (int i = 0; i < myDockWidgets.size(); ++i)
363 // myDockWidgets.at(i)->setParent(0);
364 // ... and replaced - manually hide dock windows
366 // store dock widgets visibility state and hide'em all
367 QMapIterator<QWidget*, bool> it1( myDockWidgets );
368 while( it1.hasNext() ) {
370 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
371 myDockWidgets[dw] = dw->isVisible();
373 dw->setVisible( false );
374 dw->toggleViewAction()->setVisible( false );
377 // store toolbar breaks state and remove all tollbar breaks
378 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
379 while( it2.hasNext() ) {
381 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
382 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
383 if ( myToolbarBreaks[tb] && hideWidgets )
384 desk->removeToolBarBreak( tb );
386 // store toolbars visibility state and hide'em all
387 QMapIterator<QWidget*, bool> it3( myToolbars );
388 while( it3.hasNext() ) {
390 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
391 myToolbars[tb] = tb->isVisible();
393 tb->setVisible( false );
394 tb->toggleViewAction()->setVisible( false );
400 \brief Restore states of dockable ParaView widgets.
402 void PVGUI_Module::restoreDockWidgetsState()
404 SUIT_Desktop* desk = application()->desktop();
406 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
407 // ... the following code is commented...
408 //for (int i = 0; i < myDockWidgets.size(); ++i)
409 // myDockWidgets.at(i)->setParent(desk);
411 // Restore the state of the window ...
412 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
413 // ... and replaced - manually hide dock windows
415 // restore dock widgets visibility state
416 QMapIterator<QWidget*, bool> it1( myDockWidgets );
417 while( it1.hasNext() ) {
419 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
420 dw->setVisible( it1.value() );
421 dw->toggleViewAction()->setVisible( true );
424 // restore toolbar breaks state
425 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
426 while( it2.hasNext() ) {
428 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
429 if ( myToolbarBreaks[tb] )
430 desk->insertToolBarBreak( tb );
433 // restore toolbar visibility state
434 QMapIterator<QWidget*, bool> it3( myToolbars );
435 while( it3.hasNext() ) {
437 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
438 tb->setVisible( it3.value() );
439 tb->toggleViewAction()->setVisible( true );
446 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
448 void PVGUI_Module::storeCommonWindowsState() {
449 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
450 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
451 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
452 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
453 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
454 // configuration file.
456 // But in contrast to others modules ParaVis module default settings hide some dockable
457 // windows, so to restore it at the moment of the ParaVis de-activation we call
458 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
461 LightApp_Application* anApp = getApp();
465 int begin = LightApp_Application::WT_ObjectBrowser;
466 int end = LightApp_Application::WT_User;
467 for( int i = begin; i <= end; i++ ) {
468 QWidget* wg = anApp->getWindow(i);
470 QDockWidget* dock = 0;
471 QWidget* w = wg->parentWidget();
472 while ( w && !dock ) {
473 dock = ::qobject_cast<QDockWidget*>( w );
474 w = w->parentWidget();
477 if(!myCommonMap.contains(i)){
478 myCommonMap.insert(i,dock->isVisible());
480 myCommonMap[i] = dock->isVisible();
488 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
490 void PVGUI_Module::restoreCommonWindowsState() {
491 LightApp_Application* anApp = getApp();
494 DockWindowMap::const_iterator it = myCommonMap.begin();
495 for( ;it != myCommonMap.end(); it++ ) {
496 QWidget* wg = anApp->getWindow(it.key());
498 QDockWidget* dock = 0;
499 QWidget* w = wg->parentWidget();
500 while ( w && !dock ) {
501 dock = ::qobject_cast<QDockWidget*>( w );
502 w = w->parentWidget();
505 dock->setVisible(it.value());