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 <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 <pqMultiBlockInspectorPanel.h>
56 #include <pqProgressWidget.h>
57 #include <pqProgressManager.h>
58 #include <pqPropertiesPanel.h>
60 #include <pqApplicationCore.h>
61 #include <pqPluginManager.h>
62 #include <pqParaViewMenuBuilders.h>
63 #include <pqCollaborationPanel.h>
64 #include <pqMemoryInspectorPanel.h>
65 #include <pqColorMapEditor.h>
66 #include <pqDeleteReaction.h>
68 #include <vtkPVGeneralSettings.h>
70 class ResizeHelper : public pqPVAnimationWidget
72 // TEMPORARY WORKAROUND AROUND PARAVIEW 3.14 BUG:
73 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
74 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
75 // THIS BUG IS NATURALLY FIXED BY ADDING
76 // this->updateGeometries();
78 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
79 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
80 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
83 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
85 void resizeEvent(QResizeEvent* e)
87 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
90 QApplication::sendEvent( w, &e );
92 pqPVAnimationWidget::resizeEvent( e );
97 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
98 ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
99 ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
101 void PVGUI_Module::setupDockWidgets()
103 SUIT_Desktop* desk = application()->desktop();
104 PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desk);
106 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
107 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
108 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
111 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
112 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
113 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
114 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
115 pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
116 pipelineBrowserDock->setWidget(browser);
117 myDockWidgets[pipelineBrowserDock] = true;
118 pipelineBrowserDock->hide();
120 // PROPERTIES, DISPLAY and VIEW:
121 // See ParaViewMainWindow.cxx - those three panels can be separated or grouped.
122 pqSettings *settings = pqApplicationCore::instance()->settings();
124 // Properties dock (previously called OBJECT_INSPECTOR)
125 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
126 propertiesDock->setObjectName("propertiesDock");
127 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
128 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
130 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
131 propertiesDock->setWidget(propertiesPanel);
132 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
133 // hook delete to pqDeleteReaction.
134 QAction* tempDeleteAction = new QAction(this);
135 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
136 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
137 myDockWidgets[propertiesDock] = true;
138 propertiesDock->hide();
141 QDockWidget* displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
142 displayPropertiesDock->setObjectName("displayPropertiesDock");
143 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
144 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
146 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
147 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
148 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
149 displayPropertiesDock->setWidget(displayPropertiesPanel);
150 myDockWidgets[displayPropertiesDock] = false;
151 displayPropertiesDock->hide();
154 QDockWidget* viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
155 viewPropertiesDock->setObjectName("viewPropertiesDock");
156 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
157 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
159 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
160 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
161 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
162 viewPropertiesDock->setWidget(viewPropertiesPanel);
163 myDockWidgets[viewPropertiesDock] = false;
164 viewPropertiesDock->hide();
166 // Taken from ParaViewMainWindow.cxx:
167 int propertiesPanelMode = settings->value(
168 "GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE).toInt();
169 switch (propertiesPanelMode)
171 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
172 viewPropertiesDock->hide();
173 propertiesPanel->setPanelMode(
174 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
177 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
178 displayPropertiesDock->hide();
179 propertiesPanel->setPanelMode(
180 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
183 case vtkPVGeneralSettings::ALL_SEPARATE:
184 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
187 case vtkPVGeneralSettings::ALL_IN_ONE:
189 propertiesPanel->setPanelMode(
190 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
191 viewPropertiesDock->hide();
192 displayPropertiesDock->hide();
197 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
198 informationDock->setObjectName("informationDock");
200 QWidget* informationWidgetFrame = new QWidget(informationDock);
201 informationWidgetFrame->setObjectName("informationWidgetFrame");
203 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
204 verticalLayout_2->setSpacing(0);
205 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
207 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
208 informationScrollArea->setObjectName("informationScrollArea") ;
209 informationScrollArea->setWidgetResizable(true);
211 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
212 informationWidget->setObjectName("informationWidget");
213 informationWidget->setGeometry(QRect(0, 0, 77, 214));
214 informationScrollArea->setWidget(informationWidget);
216 verticalLayout_2->addWidget(informationScrollArea);
217 informationDock->setWidget(informationWidgetFrame);
219 myDockWidgets[informationDock] = true;
221 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
222 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
223 desk->tabifyDockWidget(propertiesDock, informationDock);
224 propertiesDock->raise();
227 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
228 statisticsViewDock->setObjectName("statisticsViewDock");
229 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
230 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
231 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
232 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
233 statisticsViewDock->setWidget(aStatWidget);
234 myDockWidgets[statisticsViewDock] = false; // hidden by default
237 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
238 animationViewDock->setObjectName("animationViewDock");
239 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
240 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
241 animationViewDock->setWidget(animation_panel);
242 myDockWidgets[animationViewDock] = false; // hidden by default
244 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
246 // Selection inspector
247 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
248 selectionDisplayDock->setObjectName("selectionInspectorDock");
249 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
250 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
251 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
252 selectionDisplayDock->setWidget(aSelInspector);
253 myDockWidgets[selectionDisplayDock] = false; // hidden by default
255 // Multi-block inspector
256 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
257 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
258 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
259 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
260 multiBlockInspectorPanelDock->setWidget(mbi_panel);
261 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
264 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
265 comparativePanelDock->setObjectName("comparativePanelDock");
266 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
267 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
268 comparativePanelDock->setWidget(cv_panel);
269 myDockWidgets[comparativePanelDock] = false; // hidden by default
271 // Collaboration view
272 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
273 collaborationPanelDock->setObjectName("collaborationPanelDock");
274 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
275 collaborationPanel->setObjectName("collaborationPanel");
276 collaborationPanelDock->setWidget(collaborationPanel);
277 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
278 myDockWidgets[collaborationPanelDock] = false; // hidden by default
281 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
282 colorMapEditorDock->setObjectName("colorMapEditorDock");
283 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
284 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
285 colorMapEditorDock->setWidget(cmed_panel);
286 myDockWidgets[colorMapEditorDock] = false; // hidden by default
288 // Provide access to the color-editor panel for the application.
289 pqApplicationCore::instance()->registerManager(
290 "COLOR_EDITOR_PANEL", colorMapEditorDock);
292 // Memory inspector dock
293 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
294 memoryInspectorDock->setObjectName("memoryInspectorDock");
296 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
297 dockWidgetContents->setObjectName("dockWidgetContents");
298 memoryInspectorDock->setWidget(dockWidgetContents);
300 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
301 myDockWidgets[memoryInspectorDock] = false; // hidden by default
303 // Setup the statusbar ...
304 pqProgressManager* progress_manager =
305 pqApplicationCore::instance()->getProgressManager();
307 // Progress bar/button management
308 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
309 progress_manager->addNonBlockableObject(aProgress);
310 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
312 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
313 aProgress, SLOT(enableProgress(bool)));
315 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
316 aProgress, SLOT(setProgress(const QString&, int)));
318 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
319 aProgress, SLOT(enableAbort(bool)));
321 QObject::connect( aProgress, SIGNAL(abortPressed()),
322 progress_manager, SLOT(triggerAbort()));
324 desk->statusBar()->addPermanentWidget(aProgress);
325 aProgress->setEnabled(true);
327 // Set up the dock window corners to give the vertical docks more room.
328 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
329 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
331 // Setup the default dock configuration ...
332 statisticsViewDock->hide();
333 comparativePanelDock->hide();
334 animationViewDock->hide();
335 multiBlockInspectorPanelDock->hide();
336 selectionDisplayDock->hide();
337 collaborationPanelDock->hide();
338 memoryInspectorDock->hide();
339 colorMapEditorDock->hide();
343 \brief Save states of dockable ParaView widgets.
345 void PVGUI_Module::saveDockWidgetsState(bool hideWidgets)
347 SUIT_Desktop* desk = application()->desktop();
349 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
350 // ... the following code is commented...
351 // Save the state of the window ...
352 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
354 //for (int i = 0; i < myDockWidgets.size(); ++i)
355 // myDockWidgets.at(i)->setParent(0);
356 // ... and replaced - manually hide dock windows
358 // store dock widgets visibility state and hide'em all
359 QMapIterator<QWidget*, bool> it1( myDockWidgets );
360 while( it1.hasNext() ) {
362 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
363 myDockWidgets[dw] = dw->isVisible();
365 dw->setVisible( false );
366 dw->toggleViewAction()->setVisible( false );
369 // store toolbar breaks state and remove all tollbar breaks
370 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
371 while( it2.hasNext() ) {
373 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
374 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
375 if ( myToolbarBreaks[tb] && hideWidgets )
376 desk->removeToolBarBreak( tb );
378 // store toolbars visibility state and hide'em all
379 QMapIterator<QWidget*, bool> it3( myToolbars );
380 while( it3.hasNext() ) {
382 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
383 myToolbars[tb] = tb->isVisible();
385 tb->setVisible( false );
386 tb->toggleViewAction()->setVisible( false );
392 \brief Restore states of dockable ParaView widgets.
394 void PVGUI_Module::restoreDockWidgetsState()
396 SUIT_Desktop* desk = application()->desktop();
398 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
399 // ... the following code is commented...
400 //for (int i = 0; i < myDockWidgets.size(); ++i)
401 // myDockWidgets.at(i)->setParent(desk);
403 // Restore the state of the window ...
404 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
405 // ... and replaced - manually hide dock windows
407 // restore dock widgets visibility state
408 QMapIterator<QWidget*, bool> it1( myDockWidgets );
409 while( it1.hasNext() ) {
411 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
412 dw->setVisible( it1.value() );
413 dw->toggleViewAction()->setVisible( true );
416 // restore toolbar breaks state
417 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
418 while( it2.hasNext() ) {
420 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
421 if ( myToolbarBreaks[tb] )
422 desk->insertToolBarBreak( tb );
425 // restore toolbar visibility state
426 QMapIterator<QWidget*, bool> it3( myToolbars );
427 while( it3.hasNext() ) {
429 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
430 tb->setVisible( it3.value() );
431 tb->toggleViewAction()->setVisible( true );
438 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
440 void PVGUI_Module::storeCommonWindowsState() {
441 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
442 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
443 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
444 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
445 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
446 // configuration file.
448 // But in contrast to others modules ParaVis module default settings hide some dockable
449 // windows, so to restore it at the moment of the ParaVis de-activation we call
450 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
453 LightApp_Application* anApp = getApp();
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 LightApp_Application* anApp = getApp();
486 DockWindowMap::const_iterator it = myCommonMap.begin();
487 for( ;it != myCommonMap.end(); it++ ) {
488 QWidget* wg = anApp->getWindow(it.key());
490 QDockWidget* dock = 0;
491 QWidget* w = wg->parentWidget();
492 while ( w && !dock ) {
493 dock = ::qobject_cast<QDockWidget*>( w );
494 w = w->parentWidget();
497 dock->setVisible(it.value());