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 // TEMPORARILY 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 );
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 pqSettings *settings = pqApplicationCore::instance()->settings();
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 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
140 myDockWidgets[propertiesDock] = true;
141 propertiesDock->hide();
144 QDockWidget* displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
145 displayPropertiesDock->setObjectName("displayPropertiesDock");
146 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
147 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
149 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
150 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
151 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
152 displayPropertiesDock->setWidget(displayPropertiesPanel);
153 myDockWidgets[displayPropertiesDock] = false;
154 displayPropertiesDock->hide();
157 QDockWidget* viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
158 viewPropertiesDock->setObjectName("viewPropertiesDock");
159 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
160 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
162 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
163 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
164 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
165 viewPropertiesDock->setWidget(viewPropertiesPanel);
166 myDockWidgets[viewPropertiesDock] = false;
167 viewPropertiesDock->hide();
169 // Taken from ParaViewMainWindow.cxx:
170 int propertiesPanelMode = settings->value(
171 "GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE).toInt();
172 switch (propertiesPanelMode)
174 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
175 viewPropertiesDock->hide();
176 propertiesPanel->setPanelMode(
177 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
180 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
181 displayPropertiesDock->hide();
182 propertiesPanel->setPanelMode(
183 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
186 case vtkPVGeneralSettings::ALL_SEPARATE:
187 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
190 case vtkPVGeneralSettings::ALL_IN_ONE:
192 propertiesPanel->setPanelMode(
193 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
194 viewPropertiesDock->hide();
195 displayPropertiesDock->hide();
200 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
201 informationDock->setObjectName("informationDock");
203 QWidget* informationWidgetFrame = new QWidget(informationDock);
204 informationWidgetFrame->setObjectName("informationWidgetFrame");
206 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
207 verticalLayout_2->setSpacing(0);
208 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
210 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
211 informationScrollArea->setObjectName("informationScrollArea") ;
212 informationScrollArea->setWidgetResizable(true);
214 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
215 informationWidget->setObjectName("informationWidget");
216 informationWidget->setGeometry(QRect(0, 0, 77, 214));
217 informationScrollArea->setWidget(informationWidget);
219 verticalLayout_2->addWidget(informationScrollArea);
220 informationDock->setWidget(informationWidgetFrame);
222 myDockWidgets[informationDock] = true;
224 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
225 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
226 desk->tabifyDockWidget(propertiesDock, informationDock);
227 propertiesDock->raise();
230 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
231 statisticsViewDock->setObjectName("statisticsViewDock");
232 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
233 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
234 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
235 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
236 statisticsViewDock->setWidget(aStatWidget);
237 myDockWidgets[statisticsViewDock] = false; // hidden by default
240 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
241 animationViewDock->setObjectName("animationViewDock");
242 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
243 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
244 animationViewDock->setWidget(animation_panel);
245 myDockWidgets[animationViewDock] = false; // hidden by default
247 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
249 // Selection inspector
250 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
251 selectionDisplayDock->setObjectName("selectionInspectorDock");
252 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
253 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
254 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
255 selectionDisplayDock->setWidget(aSelInspector);
256 myDockWidgets[selectionDisplayDock] = false; // hidden by default
258 // Multi-block inspector
259 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
260 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
261 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
262 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
263 multiBlockInspectorPanelDock->setWidget(mbi_panel);
264 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
267 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
268 comparativePanelDock->setObjectName("comparativePanelDock");
269 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
270 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
271 comparativePanelDock->setWidget(cv_panel);
272 myDockWidgets[comparativePanelDock] = false; // hidden by default
274 // Collaboration view
275 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
276 collaborationPanelDock->setObjectName("collaborationPanelDock");
277 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
278 collaborationPanel->setObjectName("collaborationPanel");
279 collaborationPanelDock->setWidget(collaborationPanel);
280 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
281 myDockWidgets[collaborationPanelDock] = false; // hidden by default
284 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
285 colorMapEditorDock->setObjectName("colorMapEditorDock");
286 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
287 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
288 colorMapEditorDock->setWidget(cmed_panel);
289 myDockWidgets[colorMapEditorDock] = false; // hidden by default
291 // Provide access to the color-editor panel for the application.
292 pqApplicationCore::instance()->registerManager(
293 "COLOR_EDITOR_PANEL", colorMapEditorDock);
295 // Memory inspector dock
296 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
297 memoryInspectorDock->setObjectName("memoryInspectorDock");
299 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
300 dockWidgetContents->setObjectName("dockWidgetContents");
301 memoryInspectorDock->setWidget(dockWidgetContents);
303 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
304 myDockWidgets[memoryInspectorDock] = false; // hidden by default
306 // Setup the statusbar ...
307 pqProgressManager* progress_manager =
308 pqApplicationCore::instance()->getProgressManager();
310 // Progress bar/button management
311 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
312 progress_manager->addNonBlockableObject(aProgress);
313 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
315 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
316 aProgress, SLOT(enableProgress(bool)));
318 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
319 aProgress, SLOT(setProgress(const QString&, int)));
321 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
322 aProgress, SLOT(enableAbort(bool)));
324 QObject::connect( aProgress, SIGNAL(abortPressed()),
325 progress_manager, SLOT(triggerAbort()));
327 desk->statusBar()->addPermanentWidget(aProgress);
328 aProgress->setEnabled(true);
330 // Set up the dock window corners to give the vertical docks more room.
331 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
332 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
334 // Setup the default dock configuration ...
335 statisticsViewDock->hide();
336 comparativePanelDock->hide();
337 animationViewDock->hide();
338 multiBlockInspectorPanelDock->hide();
339 selectionDisplayDock->hide();
340 collaborationPanelDock->hide();
341 memoryInspectorDock->hide();
342 colorMapEditorDock->hide();
346 \brief Save states of dockable ParaView widgets.
348 void PVGUI_Module::saveDockWidgetsState()
350 SUIT_Desktop* desk = application()->desktop();
352 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
353 // ... the following code is commented...
354 // Save the state of the window ...
355 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
357 //for (int i = 0; i < myDockWidgets.size(); ++i)
358 // myDockWidgets.at(i)->setParent(0);
359 // ... and replaced - manually hide dock windows
361 // store dock widgets visibility state and hide'em all
362 QMapIterator<QWidget*, bool> it1( myDockWidgets );
363 while( it1.hasNext() ) {
365 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
366 myDockWidgets[dw] = dw->isVisible();
367 dw->setVisible( false );
368 dw->toggleViewAction()->setVisible( false );
370 // store toolbar breaks state and remove all tollbar breaks
371 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
372 while( it2.hasNext() ) {
374 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
375 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
376 if ( myToolbarBreaks[tb] )
377 desk->removeToolBarBreak( tb );
379 // store toolbars visibility state and hide'em all
380 QMapIterator<QWidget*, bool> it3( myToolbars );
381 while( it3.hasNext() ) {
383 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
384 myToolbars[tb] = tb->isVisible();
385 tb->setVisible( false );
386 tb->toggleViewAction()->setVisible( false );
391 \brief Restore states of dockable ParaView widgets.
393 void PVGUI_Module::restoreDockWidgetsState()
395 SUIT_Desktop* desk = application()->desktop();
397 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
398 // ... the following code is commented...
399 //for (int i = 0; i < myDockWidgets.size(); ++i)
400 // myDockWidgets.at(i)->setParent(desk);
402 // Restore the state of the window ...
403 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
404 // ... and replaced - manually hide dock windows
406 // restore dock widgets visibility state
407 QMapIterator<QWidget*, bool> it1( myDockWidgets );
408 while( it1.hasNext() ) {
410 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
411 dw->setVisible( it1.value() );
412 dw->toggleViewAction()->setVisible( true );
415 // restore toolbar breaks state
416 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
417 while( it2.hasNext() ) {
419 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
420 if ( myToolbarBreaks[tb] )
421 desk->insertToolBarBreak( tb );
424 // restore toolbar visibility state
425 QMapIterator<QWidget*, bool> it3( myToolbars );
426 while( it3.hasNext() ) {
428 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
429 tb->setVisible( it3.value() );
430 tb->toggleViewAction()->setVisible( true );
437 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
439 void PVGUI_Module::storeCommonWindowsState() {
440 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
441 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
442 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
443 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
444 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
445 // configuration file.
447 // But in contrast to others modules ParaVis module default settings hide some dockable
448 // windows, so to restore it at the moment of the ParaVis de-activation we call
449 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
452 //LightApp_Application* anApp = getApp();
453 SalomeApp_Application* anApp = getApp();
457 // int begin = SalomeApp_Application::WT_ObjectBrowser;
458 // int end = SalomeApp_Application::WT_NoteBook;
459 int begin = LightApp_Application::WT_ObjectBrowser;
460 int end = LightApp_Application::WT_User;
461 for( int i = begin; i <= end; i++ ) {
462 QWidget* wg = anApp->getWindow(i);
464 QDockWidget* dock = 0;
465 QWidget* w = wg->parentWidget();
466 while ( w && !dock ) {
467 dock = ::qobject_cast<QDockWidget*>( w );
468 w = w->parentWidget();
471 if(!myCommonMap.contains(i)){
472 myCommonMap.insert(i,dock->isVisible());
474 myCommonMap[i] = dock->isVisible();
482 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
484 void PVGUI_Module::restoreCommonWindowsState() {
485 SalomeApp_Application* anApp = getApp();
486 // LightApp_Application* anApp = getApp();
489 DockWindowMap::const_iterator it = myCommonMap.begin();
490 for( ;it != myCommonMap.end(); it++ ) {
491 QWidget* wg = anApp->getWindow(it.key());
493 QDockWidget* dock = 0;
494 QWidget* w = wg->parentWidget();
495 while ( w && !dock ) {
496 dock = ::qobject_cast<QDockWidget*>( w );
497 w = w->parentWidget();
500 dock->setVisible(it.value());