1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2014 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 <pqDisplayProxyEditorWidget.h>
60 #include <pqPropertiesPanel.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 // TEMPORARILY 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 );
101 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
102 ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
103 ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
105 void PVGUI_Module::setupDockWidgets()
107 SUIT_Desktop* desk = application()->desktop();
108 PVViewer_GUIElements * guiElements = PVViewer_GUIElements::GetInstance(desk);
110 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
111 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
112 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
115 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
116 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
117 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
118 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
119 pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
120 pipelineBrowserDock->setWidget(browser);
121 myDockWidgets[pipelineBrowserDock] = true;
122 pipelineBrowserDock->hide();
124 // PROPERTIES, DISPLAY and VIEW:
125 // See ParaViewMainWindow.cxx - those three panels can be separated or grouped.
126 pqSettings *settings = pqApplicationCore::instance()->settings();
128 // Properties dock (previously called OBJECT_INSPECTOR)
129 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
130 propertiesDock->setObjectName("propertiesDock");
131 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
132 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
134 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
135 propertiesDock->setWidget(propertiesPanel);
136 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
137 // hook delete to pqDeleteReaction.
138 QAction* tempDeleteAction = new QAction(this);
139 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
140 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
141 myDockWidgets[propertiesDock] = true;
142 propertiesDock->hide();
145 QDockWidget* displayPropertiesDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
146 displayPropertiesDock->setObjectName("displayPropertiesDock");
147 displayPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
148 desk->addDockWidget( Qt::LeftDockWidgetArea, displayPropertiesDock );
150 pqPropertiesPanel* displayPropertiesPanel = new pqPropertiesPanel();
151 displayPropertiesPanel->setObjectName("displayPropertiesPanel");
152 displayPropertiesPanel->setProperty("panelMode", QVariant(2)); // probably to have only the Display part
153 displayPropertiesDock->setWidget(displayPropertiesPanel);
154 myDockWidgets[displayPropertiesDock] = false;
155 displayPropertiesDock->hide();
158 QDockWidget* viewPropertiesDock = new QDockWidget( tr( "TTL_VIEW_PANEL" ), desk );
159 viewPropertiesDock->setObjectName("viewPropertiesDock");
160 viewPropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
161 desk->addDockWidget( Qt::LeftDockWidgetArea, viewPropertiesDock );
163 pqPropertiesPanel* viewPropertiesPanel = new pqPropertiesPanel();
164 viewPropertiesPanel->setObjectName("viewPropertiesPanel");
165 viewPropertiesPanel->setProperty("panelMode", QVariant(4)); // probably to have only the View part
166 viewPropertiesDock->setWidget(viewPropertiesPanel);
167 myDockWidgets[viewPropertiesDock] = false;
168 viewPropertiesDock->hide();
170 // Taken from ParaViewMainWindow.cxx:
171 int propertiesPanelMode = settings->value(
172 "GeneralSettings.PropertiesPanelMode", vtkPVGeneralSettings::ALL_IN_ONE).toInt();
173 switch (propertiesPanelMode)
175 case vtkPVGeneralSettings::SEPARATE_DISPLAY_PROPERTIES:
176 viewPropertiesDock->hide();
177 propertiesPanel->setPanelMode(
178 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES);
181 case vtkPVGeneralSettings::SEPARATE_VIEW_PROPERTIES:
182 displayPropertiesDock->hide();
183 propertiesPanel->setPanelMode(
184 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
187 case vtkPVGeneralSettings::ALL_SEPARATE:
188 propertiesPanel->setPanelMode(pqPropertiesPanel::SOURCE_PROPERTIES);
191 case vtkPVGeneralSettings::ALL_IN_ONE:
193 propertiesPanel->setPanelMode(
194 pqPropertiesPanel::SOURCE_PROPERTIES|pqPropertiesPanel::VIEW_PROPERTIES|pqPropertiesPanel::DISPLAY_PROPERTIES);
195 viewPropertiesDock->hide();
196 displayPropertiesDock->hide();
201 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
202 informationDock->setObjectName("informationDock");
204 QWidget* informationWidgetFrame = new QWidget(informationDock);
205 informationWidgetFrame->setObjectName("informationWidgetFrame");
207 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
208 verticalLayout_2->setSpacing(0);
209 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
211 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
212 informationScrollArea->setObjectName("informationScrollArea") ;
213 informationScrollArea->setWidgetResizable(true);
215 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
216 informationWidget->setObjectName("informationWidget");
217 informationWidget->setGeometry(QRect(0, 0, 77, 214));
218 informationScrollArea->setWidget(informationWidget);
220 verticalLayout_2->addWidget(informationScrollArea);
221 informationDock->setWidget(informationWidgetFrame);
223 myDockWidgets[informationDock] = true;
225 desk->tabifyDockWidget(propertiesDock, viewPropertiesDock);
226 desk->tabifyDockWidget(propertiesDock, displayPropertiesDock);
227 desk->tabifyDockWidget(propertiesDock, informationDock);
228 propertiesDock->raise();
231 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
232 statisticsViewDock->setObjectName("statisticsViewDock");
233 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
234 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
235 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
236 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
237 statisticsViewDock->setWidget(aStatWidget);
238 myDockWidgets[statisticsViewDock] = false; // hidden by default
241 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
242 animationViewDock->setObjectName("animationViewDock");
243 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
244 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); // [ABN] was resizeHelper
245 animationViewDock->setWidget(animation_panel);
246 myDockWidgets[animationViewDock] = false; // hidden by default
248 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
250 // Selection inspector
251 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
252 selectionDisplayDock->setObjectName("selectionInspectorDock");
253 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
254 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
255 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
256 selectionDisplayDock->setWidget(aSelInspector);
257 myDockWidgets[selectionDisplayDock] = false; // hidden by default
259 // Multi-block inspector
260 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
261 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
262 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
263 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
264 multiBlockInspectorPanelDock->setWidget(mbi_panel);
265 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
268 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
269 comparativePanelDock->setObjectName("comparativePanelDock");
270 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
271 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
272 comparativePanelDock->setWidget(cv_panel);
273 myDockWidgets[comparativePanelDock] = false; // hidden by default
275 // Collaboration view
276 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
277 collaborationPanelDock->setObjectName("collaborationPanelDock");
278 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
279 collaborationPanel->setObjectName("collaborationPanel");
280 collaborationPanelDock->setWidget(collaborationPanel);
281 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
282 myDockWidgets[collaborationPanelDock] = false; // hidden by default
285 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
286 colorMapEditorDock->setObjectName("colorMapEditorDock");
287 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
288 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
289 colorMapEditorDock->setWidget(cmed_panel);
290 myDockWidgets[colorMapEditorDock] = false; // hidden by default
292 // Provide access to the color-editor panel for the application.
293 pqApplicationCore::instance()->registerManager(
294 "COLOR_EDITOR_PANEL", colorMapEditorDock);
296 // Memory inspector dock
297 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
298 memoryInspectorDock->setObjectName("memoryInspectorDock");
300 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
301 dockWidgetContents->setObjectName("dockWidgetContents");
302 memoryInspectorDock->setWidget(dockWidgetContents);
304 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
305 myDockWidgets[memoryInspectorDock] = false; // hidden by default
307 // Setup the statusbar ...
308 pqProgressManager* progress_manager =
309 pqApplicationCore::instance()->getProgressManager();
311 // Progress bar/button management
312 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
313 progress_manager->addNonBlockableObject(aProgress);
314 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
316 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
317 aProgress, SLOT(enableProgress(bool)));
319 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
320 aProgress, SLOT(setProgress(const QString&, int)));
322 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
323 aProgress, SLOT(enableAbort(bool)));
325 QObject::connect( aProgress, SIGNAL(abortPressed()),
326 progress_manager, SLOT(triggerAbort()));
328 desk->statusBar()->addPermanentWidget(aProgress);
329 aProgress->setEnabled(true);
331 // Set up the dock window corners to give the vertical docks more room.
332 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
333 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
335 // Setup the default dock configuration ...
336 statisticsViewDock->hide();
337 comparativePanelDock->hide();
338 animationViewDock->hide();
339 multiBlockInspectorPanelDock->hide();
340 selectionDisplayDock->hide();
341 collaborationPanelDock->hide();
342 memoryInspectorDock->hide();
343 colorMapEditorDock->hide();
347 \brief Save states of dockable ParaView widgets.
349 void PVGUI_Module::saveDockWidgetsState()
351 SUIT_Desktop* desk = application()->desktop();
353 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
354 // ... the following code is commented...
355 // Save the state of the window ...
356 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
358 //for (int i = 0; i < myDockWidgets.size(); ++i)
359 // myDockWidgets.at(i)->setParent(0);
360 // ... and replaced - manually hide dock windows
362 // store dock widgets visibility state and hide'em all
363 QMapIterator<QWidget*, bool> it1( myDockWidgets );
364 while( it1.hasNext() ) {
366 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
367 myDockWidgets[dw] = dw->isVisible();
368 dw->setVisible( false );
369 dw->toggleViewAction()->setVisible( false );
371 // store toolbar breaks state and remove all tollbar breaks
372 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
373 while( it2.hasNext() ) {
375 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
376 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
377 if ( myToolbarBreaks[tb] )
378 desk->removeToolBarBreak( tb );
380 // store toolbars visibility state and hide'em all
381 QMapIterator<QWidget*, bool> it3( myToolbars );
382 while( it3.hasNext() ) {
384 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
385 myToolbars[tb] = tb->isVisible();
386 tb->setVisible( false );
387 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();
454 SalomeApp_Application* anApp = getApp();
458 // int begin = SalomeApp_Application::WT_ObjectBrowser;
459 // int end = SalomeApp_Application::WT_NoteBook;
460 int begin = LightApp_Application::WT_ObjectBrowser;
461 int end = LightApp_Application::WT_User;
462 for( int i = begin; i <= end; i++ ) {
463 QWidget* wg = anApp->getWindow(i);
465 QDockWidget* dock = 0;
466 QWidget* w = wg->parentWidget();
467 while ( w && !dock ) {
468 dock = ::qobject_cast<QDockWidget*>( w );
469 w = w->parentWidget();
472 if(!myCommonMap.contains(i)){
473 myCommonMap.insert(i,dock->isVisible());
475 myCommonMap[i] = dock->isVisible();
483 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
485 void PVGUI_Module::restoreCommonWindowsState() {
486 SalomeApp_Application* anApp = getApp();
487 // LightApp_Application* anApp = getApp();
490 DockWindowMap::const_iterator it = myCommonMap.begin();
491 for( ;it != myCommonMap.end(); it++ ) {
492 QWidget* wg = anApp->getWindow(it.key());
494 QDockWidget* dock = 0;
495 QWidget* w = wg->parentWidget();
496 while ( w && !dock ) {
497 dock = ::qobject_cast<QDockWidget*>( w );
498 w = w->parentWidget();
501 dock->setVisible(it.value());