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"
27 #include <QtxActionToolMgr.h>
28 #include <LightApp_Application.h>
29 #include <SalomeApp_Application.h>
30 #include <SUIT_Desktop.h>
32 #include <QApplication>
34 #include <QDockWidget>
38 #include <QScrollArea>
39 #include <QVBoxLayout>
41 #include <QToolButton>
43 #include <pqAnimationViewWidget.h>
44 #include <pqAnimationWidget.h>
46 #include <pqApplicationCore.h>
47 #include <pqComparativeVisPanel.h>
48 #include <pqPipelineBrowserWidget.h>
49 #include <pqProxyInformationWidget.h>
50 #include <pqSettings.h>
51 #include <pqDataInformationWidget.h>
52 #include <pqPVAnimationWidget.h>
53 #include <pqFindDataSelectionDisplayFrame.h>
54 #include <pqMultiBlockInspectorPanel.h>
55 #include <pqProgressWidget.h>
56 #include <pqProgressManager.h>
57 //#include <pqDisplayProxyEditorWidget.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 class ResizeHelper : public pqPVAnimationWidget
70 // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
71 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
72 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
73 // THIS BUG IS NATURALLY FIXED BY ADDING
74 // this->updateGeometries();
76 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
77 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
78 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
81 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
83 void resizeEvent(QResizeEvent* e)
85 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
88 QApplication::sendEvent( w, &e );
90 pqPVAnimationWidget::resizeEvent( e );
95 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
96 ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
97 ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
99 void PVGUI_Module::setupDockWidgets()
101 SUIT_Desktop* desk = application()->desktop();
103 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
104 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
107 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
108 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
109 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
110 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
111 pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
112 pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
113 pipelineBrowserDock->setWidget(browser);
114 myDockWidgets[pipelineBrowserDock] = true;
116 // Properties dock (previously called OBJECT_INSPECTOR)
117 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
118 propertiesDock->setObjectName("propertiesDock");
119 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
120 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
122 pqPropertiesPanel* propertiesPanel = new pqPropertiesPanel(propertiesDock);
123 propertiesDock->setObjectName("propertiesPanel");
124 propertiesDock->setWidget(propertiesPanel);
125 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
126 // hook delete to pqDeleteReaction.
127 QAction* tempDeleteAction = new QAction(this);
128 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
129 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
131 myDockWidgets[propertiesDock] = true;
134 // QDockWidget* displayDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
135 // displayDock->setObjectName("displayDock");
136 // QWidget* displayWidgetFrame = new QWidget(displayDock);
137 // displayWidgetFrame->setObjectName("displayWidgetFrame");
138 // displayDock->setWidget(displayWidgetFrame);
140 // QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
141 // displayScrollArea->setObjectName("displayScrollArea");
142 // displayScrollArea->setWidgetResizable(true);
144 // QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
145 // verticalLayout->setSpacing(0);
146 // verticalLayout->setContentsMargins(0, 0, 0, 0);
148 // pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
149 // displayWidget->setObjectName("displayWidget");
150 // displayScrollArea->setWidget(displayWidget);
151 // verticalLayout->addWidget(displayScrollArea);
153 // myDockWidgets[displayDock] = true;
156 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
157 informationDock->setObjectName("informationDock");
159 QWidget* informationWidgetFrame = new QWidget(informationDock);
160 informationWidgetFrame->setObjectName("informationWidgetFrame");
162 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
163 verticalLayout_2->setSpacing(0);
164 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
166 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
167 informationScrollArea->setObjectName("informationScrollArea") ;
168 informationScrollArea->setWidgetResizable(true);
170 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
171 informationWidget->setObjectName("informationWidget");
172 informationWidget->setGeometry(QRect(0, 0, 77, 214));
173 informationScrollArea->setWidget(informationWidget);
175 verticalLayout_2->addWidget(informationScrollArea);
176 informationDock->setWidget(informationWidgetFrame);
178 myDockWidgets[informationDock] = true;
180 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
181 desk->tabifyDockWidget(propertiesDock, informationDock);
182 propertiesDock->raise();
185 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
186 statisticsViewDock->setObjectName("statisticsViewDock");
187 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
188 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
189 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
190 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
191 statisticsViewDock->setWidget(aStatWidget);
192 myDockWidgets[statisticsViewDock] = false; // hidden by default
195 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
196 animationViewDock->setObjectName("animationViewDock");
197 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
198 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
199 animationViewDock->setWidget(animation_panel);
200 myDockWidgets[animationViewDock] = false; // hidden by default
202 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
204 // Selection inspector
205 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
206 selectionDisplayDock->setObjectName("selectionInspectorDock");
207 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
208 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
209 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
210 selectionDisplayDock->setWidget(aSelInspector);
211 myDockWidgets[selectionDisplayDock] = false; // hidden by default
213 // Multi-block inspector
214 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
215 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
216 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
217 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
218 multiBlockInspectorPanelDock->setWidget(mbi_panel);
219 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
222 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
223 comparativePanelDock->setObjectName("comparativePanelDock");
224 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
225 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
226 comparativePanelDock->setWidget(cv_panel);
227 myDockWidgets[comparativePanelDock] = false; // hidden by default
229 // Collaboration view
230 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
231 collaborationPanelDock->setObjectName("collaborationPanelDock");
232 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
233 collaborationPanel->setObjectName("collaborationPanel");
234 collaborationPanelDock->setWidget(collaborationPanel);
235 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
236 myDockWidgets[collaborationPanelDock] = false; // hidden by default
239 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
240 colorMapEditorDock->setObjectName("colorMapEditorDock");
241 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
242 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
243 colorMapEditorDock->setWidget(cmed_panel);
244 myDockWidgets[colorMapEditorDock] = false; // hidden by default
246 // Provide access to the color-editor panel for the application.
247 pqApplicationCore::instance()->registerManager(
248 "COLOR_EDITOR_PANEL", colorMapEditorDock);
250 // Memory inspector dock
251 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
252 memoryInspectorDock->setObjectName("memoryInspectorDock");
254 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
255 dockWidgetContents->setObjectName("dockWidgetContents");
256 memoryInspectorDock->setWidget(dockWidgetContents);
258 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
259 myDockWidgets[memoryInspectorDock] = false; // hidden by default
261 // Setup the statusbar ...
262 pqProgressManager* progress_manager =
263 pqApplicationCore::instance()->getProgressManager();
265 // Progress bar/button management
266 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
267 progress_manager->addNonBlockableObject(aProgress);
268 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
270 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
271 aProgress, SLOT(enableProgress(bool)));
273 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
274 aProgress, SLOT(setProgress(const QString&, int)));
276 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
277 aProgress, SLOT(enableAbort(bool)));
279 QObject::connect( aProgress, SIGNAL(abortPressed()),
280 progress_manager, SLOT(triggerAbort()));
282 desk->statusBar()->addPermanentWidget(aProgress);
283 aProgress->setEnabled(true);
285 // Set up the dock window corners to give the vertical docks more room.
286 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
287 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
289 // Setup the default dock configuration ...
290 statisticsViewDock->hide();
291 comparativePanelDock->hide();
292 animationViewDock->hide();
293 multiBlockInspectorPanelDock->hide();
294 selectionDisplayDock->hide();
295 collaborationPanelDock->hide();
296 memoryInspectorDock->hide();
297 colorMapEditorDock->hide();
301 \brief Save states of dockable ParaView widgets.
303 void PVGUI_Module::saveDockWidgetsState()
305 SUIT_Desktop* desk = application()->desktop();
307 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
308 // ... the following code is commented...
309 // Save the state of the window ...
310 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
312 //for (int i = 0; i < myDockWidgets.size(); ++i)
313 // myDockWidgets.at(i)->setParent(0);
314 // ... and replaced - manually hide dock windows
316 // store dock widgets visibility state and hide'em all
317 QMapIterator<QWidget*, bool> it1( myDockWidgets );
318 while( it1.hasNext() ) {
320 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
321 myDockWidgets[dw] = dw->isVisible();
322 dw->setVisible( false );
323 dw->toggleViewAction()->setVisible( false );
325 // store toolbar breaks state and remove all tollbar breaks
326 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
327 while( it2.hasNext() ) {
329 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
330 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
331 if ( myToolbarBreaks[tb] )
332 desk->removeToolBarBreak( tb );
334 // store toolbars visibility state and hide'em all
335 QMapIterator<QWidget*, bool> it3( myToolbars );
336 while( it3.hasNext() ) {
338 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
339 myToolbars[tb] = tb->isVisible();
340 tb->setVisible( false );
341 tb->toggleViewAction()->setVisible( false );
346 \brief Restore states of dockable ParaView widgets.
348 void PVGUI_Module::restoreDockWidgetsState()
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 //for (int i = 0; i < myDockWidgets.size(); ++i)
355 // myDockWidgets.at(i)->setParent(desk);
357 // Restore the state of the window ...
358 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
359 // ... and replaced - manually hide dock windows
361 // restore dock widgets visibility state
362 QMapIterator<QWidget*, bool> it1( myDockWidgets );
363 while( it1.hasNext() ) {
365 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
366 dw->setVisible( it1.value() );
367 dw->toggleViewAction()->setVisible( true );
369 // restore toolbar breaks state
370 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
371 while( it2.hasNext() ) {
373 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
374 if ( myToolbarBreaks[tb] )
375 desk->insertToolBarBreak( tb );
377 // restore toolbar visibility state
378 QMapIterator<QWidget*, bool> it3( myToolbars );
379 while( it3.hasNext() ) {
381 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
382 tb->setVisible( it3.value() );
383 tb->toggleViewAction()->setVisible( true );
390 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
392 void PVGUI_Module::storeCommonWindowsState() {
393 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
394 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
395 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
396 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
397 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
398 // configuration file.
400 // But in contrast to others modules ParaVis module default settings hide some dockable
401 // windows, so to restore it at the moment of the ParaVis de-activation we call
402 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
405 SalomeApp_Application* anApp = getApp();
409 int begin = SalomeApp_Application::WT_ObjectBrowser;
410 int end = SalomeApp_Application::WT_NoteBook;
411 for( int i = begin; i <= end; i++ ) {
412 QWidget* wg = anApp->getWindow(i);
414 QDockWidget* dock = 0;
415 QWidget* w = wg->parentWidget();
416 while ( w && !dock ) {
417 dock = ::qobject_cast<QDockWidget*>( w );
418 w = w->parentWidget();
421 if(!myCommonMap.contains(i)){
422 myCommonMap.insert(i,dock->isVisible());
424 myCommonMap[i] = dock->isVisible();
432 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
434 void PVGUI_Module::restoreCommonWindowsState() {
435 SalomeApp_Application* anApp = getApp();
438 DockWindowMap::const_iterator it = myCommonMap.begin();
439 for( ;it != myCommonMap.end(); it++ ) {
440 QWidget* wg = anApp->getWindow(it.key());
442 QDockWidget* dock = 0;
443 QWidget* w = wg->parentWidget();
444 while ( w && !dock ) {
445 dock = ::qobject_cast<QDockWidget*>( w );
446 w = w->parentWidget();
449 dock->setVisible(it.value());