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 //class ResizeHelper : public pqPVAnimationWidget
72 // // TEMPORARILY 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;
119 // Properties dock (previously called OBJECT_INSPECTOR)
120 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
121 propertiesDock->setObjectName("propertiesDock");
122 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
123 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
125 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
126 propertiesDock->setWidget(propertiesPanel);
127 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
128 // hook delete to pqDeleteReaction.
129 QAction* tempDeleteAction = new QAction(this);
130 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
131 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
133 myDockWidgets[propertiesDock] = true;
136 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
137 informationDock->setObjectName("informationDock");
139 QWidget* informationWidgetFrame = new QWidget(informationDock);
140 informationWidgetFrame->setObjectName("informationWidgetFrame");
142 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
143 verticalLayout_2->setSpacing(0);
144 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
146 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
147 informationScrollArea->setObjectName("informationScrollArea") ;
148 informationScrollArea->setWidgetResizable(true);
150 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
151 informationWidget->setObjectName("informationWidget");
152 informationWidget->setGeometry(QRect(0, 0, 77, 214));
153 informationScrollArea->setWidget(informationWidget);
155 verticalLayout_2->addWidget(informationScrollArea);
156 informationDock->setWidget(informationWidgetFrame);
158 myDockWidgets[informationDock] = true;
161 desk->tabifyDockWidget(informationDock, propertiesDock);
162 desk->tabifyDockWidget(propertiesDock, pipelineBrowserDock);
163 //propertiesDock->raise();
166 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
167 statisticsViewDock->setObjectName("statisticsViewDock");
168 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
169 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
170 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
171 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
172 statisticsViewDock->setWidget(aStatWidget);
173 myDockWidgets[statisticsViewDock] = false; // hidden by default
176 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
177 animationViewDock->setObjectName("animationViewDock");
178 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
179 pqPVAnimationWidget* animation_panel = new pqPVAnimationWidget(animationViewDock); // [ABN] was resizeHelper
180 animationViewDock->setWidget(animation_panel);
181 myDockWidgets[animationViewDock] = false; // hidden by default
183 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
185 // Selection inspector
186 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
187 selectionDisplayDock->setObjectName("selectionInspectorDock");
188 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
189 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
190 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
191 selectionDisplayDock->setWidget(aSelInspector);
192 myDockWidgets[selectionDisplayDock] = false; // hidden by default
194 // Multi-block inspector
195 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
196 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
197 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
198 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
199 multiBlockInspectorPanelDock->setWidget(mbi_panel);
200 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
203 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
204 comparativePanelDock->setObjectName("comparativePanelDock");
205 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
206 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
207 comparativePanelDock->setWidget(cv_panel);
208 myDockWidgets[comparativePanelDock] = false; // hidden by default
210 // Collaboration view
211 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
212 collaborationPanelDock->setObjectName("collaborationPanelDock");
213 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
214 collaborationPanel->setObjectName("collaborationPanel");
215 collaborationPanelDock->setWidget(collaborationPanel);
216 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
217 myDockWidgets[collaborationPanelDock] = false; // hidden by default
220 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
221 colorMapEditorDock->setObjectName("colorMapEditorDock");
222 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
223 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
224 colorMapEditorDock->setWidget(cmed_panel);
225 myDockWidgets[colorMapEditorDock] = false; // hidden by default
227 // Provide access to the color-editor panel for the application.
228 pqApplicationCore::instance()->registerManager(
229 "COLOR_EDITOR_PANEL", colorMapEditorDock);
231 // Memory inspector dock
232 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
233 memoryInspectorDock->setObjectName("memoryInspectorDock");
235 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
236 dockWidgetContents->setObjectName("dockWidgetContents");
237 memoryInspectorDock->setWidget(dockWidgetContents);
239 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
240 myDockWidgets[memoryInspectorDock] = false; // hidden by default
242 // Setup the statusbar ...
243 pqProgressManager* progress_manager =
244 pqApplicationCore::instance()->getProgressManager();
246 // Progress bar/button management
247 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
248 progress_manager->addNonBlockableObject(aProgress);
249 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
251 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
252 aProgress, SLOT(enableProgress(bool)));
254 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
255 aProgress, SLOT(setProgress(const QString&, int)));
257 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
258 aProgress, SLOT(enableAbort(bool)));
260 QObject::connect( aProgress, SIGNAL(abortPressed()),
261 progress_manager, SLOT(triggerAbort()));
263 desk->statusBar()->addPermanentWidget(aProgress);
264 aProgress->setEnabled(true);
266 // Set up the dock window corners to give the vertical docks more room.
267 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
268 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
270 // Setup the default dock configuration ...
271 statisticsViewDock->hide();
272 comparativePanelDock->hide();
273 animationViewDock->hide();
274 multiBlockInspectorPanelDock->hide();
275 selectionDisplayDock->hide();
276 collaborationPanelDock->hide();
277 memoryInspectorDock->hide();
278 colorMapEditorDock->hide();
282 \brief Save states of dockable ParaView widgets.
284 void PVGUI_Module::saveDockWidgetsState()
286 SUIT_Desktop* desk = application()->desktop();
288 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
289 // ... the following code is commented...
290 // Save the state of the window ...
291 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
293 //for (int i = 0; i < myDockWidgets.size(); ++i)
294 // myDockWidgets.at(i)->setParent(0);
295 // ... and replaced - manually hide dock windows
297 // store dock widgets visibility state and hide'em all
298 QMapIterator<QWidget*, bool> it1( myDockWidgets );
299 while( it1.hasNext() ) {
301 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
302 myDockWidgets[dw] = dw->isVisible();
303 dw->setVisible( false );
304 dw->toggleViewAction()->setVisible( false );
306 // store toolbar breaks state and remove all tollbar breaks
307 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
308 while( it2.hasNext() ) {
310 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
311 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
312 if ( myToolbarBreaks[tb] )
313 desk->removeToolBarBreak( tb );
315 // store toolbars visibility state and hide'em all
316 QMapIterator<QWidget*, bool> it3( myToolbars );
317 while( it3.hasNext() ) {
319 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
320 myToolbars[tb] = tb->isVisible();
321 tb->setVisible( false );
322 tb->toggleViewAction()->setVisible( false );
327 \brief Restore states of dockable ParaView widgets.
329 void PVGUI_Module::restoreDockWidgetsState()
331 SUIT_Desktop* desk = application()->desktop();
333 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
334 // ... the following code is commented...
335 //for (int i = 0; i < myDockWidgets.size(); ++i)
336 // myDockWidgets.at(i)->setParent(desk);
338 // Restore the state of the window ...
339 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
340 // ... and replaced - manually hide dock windows
342 // restore dock widgets visibility state
343 QMapIterator<QWidget*, bool> it1( myDockWidgets );
344 while( it1.hasNext() ) {
346 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
347 dw->setVisible( it1.value() );
348 dw->toggleViewAction()->setVisible( true );
351 // restore toolbar breaks state
352 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
353 while( it2.hasNext() ) {
355 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
356 if ( myToolbarBreaks[tb] )
357 desk->insertToolBarBreak( tb );
360 // restore toolbar visibility state
361 QMapIterator<QWidget*, bool> it3( myToolbars );
362 while( it3.hasNext() ) {
364 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
365 tb->setVisible( it3.value() );
366 tb->toggleViewAction()->setVisible( true );
373 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
375 void PVGUI_Module::storeCommonWindowsState() {
376 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
377 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
378 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
379 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
380 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
381 // configuration file.
383 // But in contrast to others modules ParaVis module default settings hide some dockable
384 // windows, so to restore it at the moment of the ParaVis de-activation we call
385 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
388 //LightApp_Application* anApp = getApp();
389 SalomeApp_Application* anApp = getApp();
393 // int begin = SalomeApp_Application::WT_ObjectBrowser;
394 // int end = SalomeApp_Application::WT_NoteBook;
395 int begin = LightApp_Application::WT_ObjectBrowser;
396 int end = LightApp_Application::WT_User;
397 for( int i = begin; i <= end; i++ ) {
398 QWidget* wg = anApp->getWindow(i);
400 QDockWidget* dock = 0;
401 QWidget* w = wg->parentWidget();
402 while ( w && !dock ) {
403 dock = ::qobject_cast<QDockWidget*>( w );
404 w = w->parentWidget();
407 if(!myCommonMap.contains(i)){
408 myCommonMap.insert(i,dock->isVisible());
410 myCommonMap[i] = dock->isVisible();
418 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
420 void PVGUI_Module::restoreCommonWindowsState() {
421 SalomeApp_Application* anApp = getApp();
422 // LightApp_Application* anApp = getApp();
425 DockWindowMap::const_iterator it = myCommonMap.begin();
426 for( ;it != myCommonMap.end(); it++ ) {
427 QWidget* wg = anApp->getWindow(it.key());
429 QDockWidget* dock = 0;
430 QWidget* w = wg->parentWidget();
431 while ( w && !dock ) {
432 dock = ::qobject_cast<QDockWidget*>( w );
433 w = w->parentWidget();
436 dock->setVisible(it.value());