1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2015 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 <SalomeApp_Application.h> // // should ultimately be a LightApp only
32 #include <SUIT_Desktop.h>
34 #include <QApplication>
36 #include <QDockWidget>
40 #include <QScrollArea>
41 #include <QVBoxLayout>
43 #include <QToolButton>
45 #include <pqAnimationViewWidget.h>
46 #include <pqAnimationWidget.h>
48 #include <pqApplicationCore.h>
49 #include <pqComparativeVisPanel.h>
50 #include <pqPipelineBrowserWidget.h>
51 #include <pqProxyInformationWidget.h>
52 #include <pqSettings.h>
53 #include <pqDataInformationWidget.h>
54 #include <pqPVAnimationWidget.h>
55 #include <pqFindDataSelectionDisplayFrame.h>
56 #include <pqMultiBlockInspectorPanel.h>
57 #include <pqProgressWidget.h>
58 #include <pqProgressManager.h>
59 #include <pqPropertiesPanel.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>
71 class ResizeHelper : public pqPVAnimationWidget
73 // TEMPORARY WORKAROUND AROUND PARAVIEW 3.14 BUG:
74 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
75 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
76 // THIS BUG IS NATURALLY FIXED BY ADDING
77 // this->updateGeometries();
79 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
80 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
81 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
84 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
86 void resizeEvent(QResizeEvent* e)
88 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
91 QApplication::sendEvent( w, &e );
93 pqPVAnimationWidget::resizeEvent( e );
98 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
99 ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
100 ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
102 void PVGUI_Module::setupDockWidgets()
104 SUIT_Desktop* desk = application()->desktop();
105 PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desk);
107 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
108 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
109 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
112 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
113 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
114 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
115 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
116 pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
117 pipelineBrowserDock->setWidget(browser);
118 myDockWidgets[pipelineBrowserDock] = true;
119 pipelineBrowserDock->hide();
121 // PROPERTIES, DISPLAY and VIEW:
122 // See ParaViewMainWindow.cxx - those three panels can be separated or grouped.
123 pqSettings *settings = pqApplicationCore::instance()->settings();
125 // Properties dock (previously called OBJECT_INSPECTOR)
126 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
127 propertiesDock->setObjectName("propertiesDock");
128 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
129 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
131 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
132 propertiesDock->setWidget(propertiesPanel);
133 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
134 // hook delete to pqDeleteReaction.
135 QAction* tempDeleteAction = new QAction(this);
136 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
137 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
138 myDockWidgets[propertiesDock] = true;
139 propertiesDock->hide();
142 QDockWidget* displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
143 displayPropertiesDock->setObjectName("displayPropertiesDock");
144 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
145 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
147 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
148 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
149 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
150 displayPropertiesDock->setWidget(displayPropertiesPanel);
151 myDockWidgets[displayPropertiesDock] = false;
152 displayPropertiesDock->hide();
155 QDockWidget* viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
156 viewPropertiesDock->setObjectName("viewPropertiesDock");
157 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
158 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
160 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
161 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
162 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
163 viewPropertiesDock->setWidget(viewPropertiesPanel);
164 myDockWidgets[viewPropertiesDock] = false;
165 viewPropertiesDock->hide();
167 // Taken from ParaViewMainWindow.cxx:
168 int propertiesPanelMode = settings->value(
169 "GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE).toInt();
170 switch (propertiesPanelMode)
172 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
173 viewPropertiesDock->hide();
174 propertiesPanel->setPanelMode(
175 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
178 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
179 displayPropertiesDock->hide();
180 propertiesPanel->setPanelMode(
181 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
184 case vtkPVGeneralSettings::ALL_SEPARATE:
185 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
188 case vtkPVGeneralSettings::ALL_IN_ONE:
190 propertiesPanel->setPanelMode(
191 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
192 viewPropertiesDock->hide();
193 displayPropertiesDock->hide();
198 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
199 informationDock->setObjectName("informationDock");
201 QWidget* informationWidgetFrame = new QWidget(informationDock);
202 informationWidgetFrame->setObjectName("informationWidgetFrame");
204 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
205 verticalLayout_2->setSpacing(0);
206 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
208 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
209 informationScrollArea->setObjectName("informationScrollArea") ;
210 informationScrollArea->setWidgetResizable(true);
212 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
213 informationWidget->setObjectName("informationWidget");
214 informationWidget->setGeometry(QRect(0, 0, 77, 214));
215 informationScrollArea->setWidget(informationWidget);
217 verticalLayout_2->addWidget(informationScrollArea);
218 informationDock->setWidget(informationWidgetFrame);
220 myDockWidgets[informationDock] = true;
222 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
223 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
224 desk->tabifyDockWidget(propertiesDock, informationDock);
225 propertiesDock->raise();
228 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
229 statisticsViewDock->setObjectName("statisticsViewDock");
230 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
231 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
232 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
233 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
234 statisticsViewDock->setWidget(aStatWidget);
235 myDockWidgets[statisticsViewDock] = false; // hidden by default
238 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
239 animationViewDock->setObjectName("animationViewDock");
240 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
241 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
242 animationViewDock->setWidget(animation_panel);
243 myDockWidgets[animationViewDock] = false; // hidden by default
245 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
247 // Selection inspector
248 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
249 selectionDisplayDock->setObjectName("selectionInspectorDock");
250 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
251 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
252 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
253 selectionDisplayDock->setWidget(aSelInspector);
254 myDockWidgets[selectionDisplayDock] = false; // hidden by default
256 // Multi-block inspector
257 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
258 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
259 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
260 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
261 multiBlockInspectorPanelDock->setWidget(mbi_panel);
262 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
265 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
266 comparativePanelDock->setObjectName("comparativePanelDock");
267 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
268 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
269 comparativePanelDock->setWidget(cv_panel);
270 myDockWidgets[comparativePanelDock] = false; // hidden by default
272 // Collaboration view
273 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
274 collaborationPanelDock->setObjectName("collaborationPanelDock");
275 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
276 collaborationPanel->setObjectName("collaborationPanel");
277 collaborationPanelDock->setWidget(collaborationPanel);
278 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
279 myDockWidgets[collaborationPanelDock] = false; // hidden by default
282 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
283 colorMapEditorDock->setObjectName("colorMapEditorDock");
284 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
285 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
286 colorMapEditorDock->setWidget(cmed_panel);
287 myDockWidgets[colorMapEditorDock] = false; // hidden by default
289 // Provide access to the color-editor panel for the application.
290 pqApplicationCore::instance()->registerManager(
291 "COLOR_EDITOR_PANEL", colorMapEditorDock);
293 // Memory inspector dock
294 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
295 memoryInspectorDock->setObjectName("memoryInspectorDock");
297 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
298 dockWidgetContents->setObjectName("dockWidgetContents");
299 memoryInspectorDock->setWidget(dockWidgetContents);
301 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
302 myDockWidgets[memoryInspectorDock] = false; // hidden by default
304 // Setup the statusbar ...
305 pqProgressManager* progress_manager =
306 pqApplicationCore::instance()->getProgressManager();
308 // Progress bar/button management
309 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
310 progress_manager->addNonBlockableObject(aProgress);
311 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
313 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
314 aProgress, SLOT(enableProgress(bool)));
316 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
317 aProgress, SLOT(setProgress(const QString&, int)));
319 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
320 aProgress, SLOT(enableAbort(bool)));
322 QObject::connect( aProgress, SIGNAL(abortPressed()),
323 progress_manager, SLOT(triggerAbort()));
325 desk->statusBar()->addPermanentWidget(aProgress);
326 aProgress->setEnabled(true);
328 // Set up the dock window corners to give the vertical docks more room.
329 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
330 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
332 // Setup the default dock configuration ...
333 statisticsViewDock->hide();
334 comparativePanelDock->hide();
335 animationViewDock->hide();
336 multiBlockInspectorPanelDock->hide();
337 selectionDisplayDock->hide();
338 collaborationPanelDock->hide();
339 memoryInspectorDock->hide();
340 colorMapEditorDock->hide();
344 \brief Save states of dockable ParaView widgets.
346 void PVGUI_Module::saveDockWidgetsState()
348 SUIT_Desktop* desk = application()->desktop();
350 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
351 // ... the following code is commented...
352 // Save the state of the window ...
353 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
355 //for (int i = 0; i < myDockWidgets.size(); ++i)
356 // myDockWidgets.at(i)->setParent(0);
357 // ... and replaced - manually hide dock windows
359 // store dock widgets visibility state and hide'em all
360 QMapIterator<QWidget*, bool> it1( myDockWidgets );
361 while( it1.hasNext() ) {
363 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
364 myDockWidgets[dw] = dw->isVisible();
365 dw->setVisible( false );
366 dw->toggleViewAction()->setVisible( false );
368 // store toolbar breaks state and remove all tollbar breaks
369 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
370 while( it2.hasNext() ) {
372 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
373 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
374 if ( myToolbarBreaks[tb] )
375 desk->removeToolBarBreak( tb );
377 // store toolbars visibility state and hide'em all
378 QMapIterator<QWidget*, bool> it3( myToolbars );
379 while( it3.hasNext() ) {
381 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
382 myToolbars[tb] = tb->isVisible();
383 tb->setVisible( false );
384 tb->toggleViewAction()->setVisible( false );
389 \brief Restore states of dockable ParaView widgets.
391 void PVGUI_Module::restoreDockWidgetsState()
393 SUIT_Desktop* desk = application()->desktop();
395 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
396 // ... the following code is commented...
397 //for (int i = 0; i < myDockWidgets.size(); ++i)
398 // myDockWidgets.at(i)->setParent(desk);
400 // Restore the state of the window ...
401 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
402 // ... and replaced - manually hide dock windows
404 // restore dock widgets visibility state
405 QMapIterator<QWidget*, bool> it1( myDockWidgets );
406 while( it1.hasNext() ) {
408 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
409 dw->setVisible( it1.value() );
410 dw->toggleViewAction()->setVisible( true );
413 // restore toolbar breaks state
414 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
415 while( it2.hasNext() ) {
417 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
418 if ( myToolbarBreaks[tb] )
419 desk->insertToolBarBreak( tb );
422 // restore toolbar visibility state
423 QMapIterator<QWidget*, bool> it3( myToolbars );
424 while( it3.hasNext() ) {
426 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
427 tb->setVisible( it3.value() );
428 tb->toggleViewAction()->setVisible( true );
435 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
437 void PVGUI_Module::storeCommonWindowsState() {
438 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
439 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
440 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
441 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
442 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
443 // configuration file.
445 // But in contrast to others modules ParaVis module default settings hide some dockable
446 // windows, so to restore it at the moment of the ParaVis de-activation we call
447 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
450 //LightApp_Application* anApp = getApp();
451 SalomeApp_Application* anApp = getApp();
455 // int begin = SalomeApp_Application::WT_ObjectBrowser;
456 // int end = SalomeApp_Application::WT_NoteBook;
457 int begin = LightApp_Application::WT_ObjectBrowser;
458 int end = LightApp_Application::WT_User;
459 for( int i = begin; i <= end; i++ ) {
460 QWidget* wg = anApp->getWindow(i);
462 QDockWidget* dock = 0;
463 QWidget* w = wg->parentWidget();
464 while ( w && !dock ) {
465 dock = ::qobject_cast<QDockWidget*>( w );
466 w = w->parentWidget();
469 if(!myCommonMap.contains(i)){
470 myCommonMap.insert(i,dock->isVisible());
472 myCommonMap[i] = dock->isVisible();
480 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
482 void PVGUI_Module::restoreCommonWindowsState() {
483 SalomeApp_Application* anApp = getApp();
484 // LightApp_Application* anApp = getApp();
487 DockWindowMap::const_iterator it = myCommonMap.begin();
488 for( ;it != myCommonMap.end(); it++ ) {
489 QWidget* wg = anApp->getWindow(it.key());
491 QDockWidget* dock = 0;
492 QWidget* w = wg->parentWidget();
493 while ( w && !dock ) {
494 dock = ::qobject_cast<QDockWidget*>( w );
495 w = w->parentWidget();
498 dock->setVisible(it.value());