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* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
135 informationDock->setObjectName("informationDock");
137 QWidget* informationWidgetFrame = new QWidget(informationDock);
138 informationWidgetFrame->setObjectName("informationWidgetFrame");
140 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
141 verticalLayout_2->setSpacing(0);
142 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
144 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
145 informationScrollArea->setObjectName("informationScrollArea") ;
146 informationScrollArea->setWidgetResizable(true);
148 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
149 informationWidget->setObjectName("informationWidget");
150 informationWidget->setGeometry(QRect(0, 0, 77, 214));
151 informationScrollArea->setWidget(informationWidget);
153 verticalLayout_2->addWidget(informationScrollArea);
154 informationDock->setWidget(informationWidgetFrame);
156 myDockWidgets[informationDock] = true;
158 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
159 desk->tabifyDockWidget(informationDock, propertiesDock);
160 propertiesDock->raise();
163 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
164 statisticsViewDock->setObjectName("statisticsViewDock");
165 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
166 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
167 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
168 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
169 statisticsViewDock->setWidget(aStatWidget);
170 myDockWidgets[statisticsViewDock] = false; // hidden by default
173 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
174 animationViewDock->setObjectName("animationViewDock");
175 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
176 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
177 animationViewDock->setWidget(animation_panel);
178 myDockWidgets[animationViewDock] = false; // hidden by default
180 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
182 // Selection inspector
183 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
184 selectionDisplayDock->setObjectName("selectionInspectorDock");
185 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
186 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
187 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
188 selectionDisplayDock->setWidget(aSelInspector);
189 myDockWidgets[selectionDisplayDock] = false; // hidden by default
191 // Multi-block inspector
192 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
193 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
194 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
195 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
196 multiBlockInspectorPanelDock->setWidget(mbi_panel);
197 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
200 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
201 comparativePanelDock->setObjectName("comparativePanelDock");
202 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
203 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
204 comparativePanelDock->setWidget(cv_panel);
205 myDockWidgets[comparativePanelDock] = false; // hidden by default
207 // Collaboration view
208 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
209 collaborationPanelDock->setObjectName("collaborationPanelDock");
210 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
211 collaborationPanel->setObjectName("collaborationPanel");
212 collaborationPanelDock->setWidget(collaborationPanel);
213 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
214 myDockWidgets[collaborationPanelDock] = false; // hidden by default
217 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
218 colorMapEditorDock->setObjectName("colorMapEditorDock");
219 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
220 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
221 colorMapEditorDock->setWidget(cmed_panel);
222 myDockWidgets[colorMapEditorDock] = false; // hidden by default
224 // Provide access to the color-editor panel for the application.
225 pqApplicationCore::instance()->registerManager(
226 "COLOR_EDITOR_PANEL", colorMapEditorDock);
228 // Memory inspector dock
229 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
230 memoryInspectorDock->setObjectName("memoryInspectorDock");
232 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
233 dockWidgetContents->setObjectName("dockWidgetContents");
234 memoryInspectorDock->setWidget(dockWidgetContents);
236 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
237 myDockWidgets[memoryInspectorDock] = false; // hidden by default
239 // Setup the statusbar ...
240 pqProgressManager* progress_manager =
241 pqApplicationCore::instance()->getProgressManager();
243 // Progress bar/button management
244 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
245 progress_manager->addNonBlockableObject(aProgress);
246 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
248 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
249 aProgress, SLOT(enableProgress(bool)));
251 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
252 aProgress, SLOT(setProgress(const QString&, int)));
254 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
255 aProgress, SLOT(enableAbort(bool)));
257 QObject::connect( aProgress, SIGNAL(abortPressed()),
258 progress_manager, SLOT(triggerAbort()));
260 desk->statusBar()->addPermanentWidget(aProgress);
261 aProgress->setEnabled(true);
263 // Set up the dock window corners to give the vertical docks more room.
264 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
265 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
267 // Setup the default dock configuration ...
268 statisticsViewDock->hide();
269 comparativePanelDock->hide();
270 animationViewDock->hide();
271 multiBlockInspectorPanelDock->hide();
272 selectionDisplayDock->hide();
273 collaborationPanelDock->hide();
274 memoryInspectorDock->hide();
275 colorMapEditorDock->hide();
279 \brief Save states of dockable ParaView widgets.
281 void PVGUI_Module::saveDockWidgetsState()
283 SUIT_Desktop* desk = application()->desktop();
285 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
286 // ... the following code is commented...
287 // Save the state of the window ...
288 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
290 //for (int i = 0; i < myDockWidgets.size(); ++i)
291 // myDockWidgets.at(i)->setParent(0);
292 // ... and replaced - manually hide dock windows
294 // store dock widgets visibility state and hide'em all
295 QMapIterator<QWidget*, bool> it1( myDockWidgets );
296 while( it1.hasNext() ) {
298 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
299 myDockWidgets[dw] = dw->isVisible();
300 dw->setVisible( false );
301 dw->toggleViewAction()->setVisible( false );
303 // store toolbar breaks state and remove all tollbar breaks
304 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
305 while( it2.hasNext() ) {
307 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
308 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
309 if ( myToolbarBreaks[tb] )
310 desk->removeToolBarBreak( tb );
312 // store toolbars visibility state and hide'em all
313 QMapIterator<QWidget*, bool> it3( myToolbars );
314 while( it3.hasNext() ) {
316 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
317 myToolbars[tb] = tb->isVisible();
318 tb->setVisible( false );
319 tb->toggleViewAction()->setVisible( false );
324 \brief Restore states of dockable ParaView widgets.
326 void PVGUI_Module::restoreDockWidgetsState()
328 SUIT_Desktop* desk = application()->desktop();
330 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
331 // ... the following code is commented...
332 //for (int i = 0; i < myDockWidgets.size(); ++i)
333 // myDockWidgets.at(i)->setParent(desk);
335 // Restore the state of the window ...
336 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
337 // ... and replaced - manually hide dock windows
339 // restore dock widgets visibility state
340 QMapIterator<QWidget*, bool> it1( myDockWidgets );
341 while( it1.hasNext() ) {
343 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
344 dw->setVisible( it1.value() );
345 dw->toggleViewAction()->setVisible( true );
347 // restore toolbar breaks state
348 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
349 while( it2.hasNext() ) {
351 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
352 if ( myToolbarBreaks[tb] )
353 desk->insertToolBarBreak( tb );
355 // restore toolbar visibility state
356 QMapIterator<QWidget*, bool> it3( myToolbars );
357 while( it3.hasNext() ) {
359 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
360 tb->setVisible( it3.value() );
361 tb->toggleViewAction()->setVisible( true );
368 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
370 void PVGUI_Module::storeCommonWindowsState() {
371 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
372 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
373 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
374 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
375 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
376 // configuration file.
378 // But in contrast to others modules ParaVis module default settings hide some dockable
379 // windows, so to restore it at the moment of the ParaVis de-activation we call
380 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
383 SalomeApp_Application* anApp = getApp();
387 int begin = SalomeApp_Application::WT_ObjectBrowser;
388 int end = SalomeApp_Application::WT_NoteBook;
389 for( int i = begin; i <= end; i++ ) {
390 QWidget* wg = anApp->getWindow(i);
392 QDockWidget* dock = 0;
393 QWidget* w = wg->parentWidget();
394 while ( w && !dock ) {
395 dock = ::qobject_cast<QDockWidget*>( w );
396 w = w->parentWidget();
399 if(!myCommonMap.contains(i)){
400 myCommonMap.insert(i,dock->isVisible());
402 myCommonMap[i] = dock->isVisible();
410 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
412 void PVGUI_Module::restoreCommonWindowsState() {
413 SalomeApp_Application* anApp = getApp();
416 DockWindowMap::const_iterator it = myCommonMap.begin();
417 for( ;it != myCommonMap.end(); it++ ) {
418 QWidget* wg = anApp->getWindow(it.key());
420 QDockWidget* dock = 0;
421 QWidget* w = wg->parentWidget();
422 while ( w && !dock ) {
423 dock = ::qobject_cast<QDockWidget*>( w );
424 w = w->parentWidget();
427 dock->setVisible(it.value());