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>
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);
110 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
111 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
112 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
113 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
114 pqPipelineBrowserWidget* browser = guiElements->getPipelineBrowserWidget();
115 pipelineBrowserDock->setWidget(browser);
116 myDockWidgets[pipelineBrowserDock] = true;
118 // Properties dock (previously called OBJECT_INSPECTOR)
119 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
120 propertiesDock->setObjectName("propertiesDock");
121 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
122 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
124 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
125 propertiesDock->setWidget(propertiesPanel);
126 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
127 // hook delete to pqDeleteReaction.
128 QAction* tempDeleteAction = new QAction(this);
129 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
130 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
132 myDockWidgets[propertiesDock] = true;
135 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
136 informationDock->setObjectName("informationDock");
138 QWidget* informationWidgetFrame = new QWidget(informationDock);
139 informationWidgetFrame->setObjectName("informationWidgetFrame");
141 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
142 verticalLayout_2->setSpacing(0);
143 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
145 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
146 informationScrollArea->setObjectName("informationScrollArea") ;
147 informationScrollArea->setWidgetResizable(true);
149 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
150 informationWidget->setObjectName("informationWidget");
151 informationWidget->setGeometry(QRect(0, 0, 77, 214));
152 informationScrollArea->setWidget(informationWidget);
154 verticalLayout_2->addWidget(informationScrollArea);
155 informationDock->setWidget(informationWidgetFrame);
157 myDockWidgets[informationDock] = true;
159 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
160 desk->tabifyDockWidget(informationDock, propertiesDock);
161 desk->tabifyDockWidget(propertiesDock, pipelineBrowserDock);
162 //propertiesDock->raise();
165 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
166 statisticsViewDock->setObjectName("statisticsViewDock");
167 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
168 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
169 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
170 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
171 statisticsViewDock->setWidget(aStatWidget);
172 myDockWidgets[statisticsViewDock] = false; // hidden by default
175 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
176 animationViewDock->setObjectName("animationViewDock");
177 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
178 pqPVAnimationWidget* animation_panel = new pqPVAnimationWidget(animationViewDock); // [ABN] was resizeHelper
179 animationViewDock->setWidget(animation_panel);
180 myDockWidgets[animationViewDock] = false; // hidden by default
182 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
184 // Selection inspector
185 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
186 selectionDisplayDock->setObjectName("selectionInspectorDock");
187 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
188 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
189 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
190 selectionDisplayDock->setWidget(aSelInspector);
191 myDockWidgets[selectionDisplayDock] = false; // hidden by default
193 // Multi-block inspector
194 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
195 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
196 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
197 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
198 multiBlockInspectorPanelDock->setWidget(mbi_panel);
199 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
202 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
203 comparativePanelDock->setObjectName("comparativePanelDock");
204 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
205 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
206 comparativePanelDock->setWidget(cv_panel);
207 myDockWidgets[comparativePanelDock] = false; // hidden by default
209 // Collaboration view
210 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
211 collaborationPanelDock->setObjectName("collaborationPanelDock");
212 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
213 collaborationPanel->setObjectName("collaborationPanel");
214 collaborationPanelDock->setWidget(collaborationPanel);
215 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
216 myDockWidgets[collaborationPanelDock] = false; // hidden by default
219 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
220 colorMapEditorDock->setObjectName("colorMapEditorDock");
221 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
222 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
223 colorMapEditorDock->setWidget(cmed_panel);
224 myDockWidgets[colorMapEditorDock] = false; // hidden by default
226 // Provide access to the color-editor panel for the application.
227 pqApplicationCore::instance()->registerManager(
228 "COLOR_EDITOR_PANEL", colorMapEditorDock);
230 // Memory inspector dock
231 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
232 memoryInspectorDock->setObjectName("memoryInspectorDock");
234 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
235 dockWidgetContents->setObjectName("dockWidgetContents");
236 memoryInspectorDock->setWidget(dockWidgetContents);
238 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
239 myDockWidgets[memoryInspectorDock] = false; // hidden by default
241 // Setup the statusbar ...
242 pqProgressManager* progress_manager =
243 pqApplicationCore::instance()->getProgressManager();
245 // Progress bar/button management
246 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
247 progress_manager->addNonBlockableObject(aProgress);
248 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
250 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
251 aProgress, SLOT(enableProgress(bool)));
253 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
254 aProgress, SLOT(setProgress(const QString&, int)));
256 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
257 aProgress, SLOT(enableAbort(bool)));
259 QObject::connect( aProgress, SIGNAL(abortPressed()),
260 progress_manager, SLOT(triggerAbort()));
262 desk->statusBar()->addPermanentWidget(aProgress);
263 aProgress->setEnabled(true);
265 // Set up the dock window corners to give the vertical docks more room.
266 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
267 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
269 // Setup the default dock configuration ...
270 statisticsViewDock->hide();
271 comparativePanelDock->hide();
272 animationViewDock->hide();
273 multiBlockInspectorPanelDock->hide();
274 selectionDisplayDock->hide();
275 collaborationPanelDock->hide();
276 memoryInspectorDock->hide();
277 colorMapEditorDock->hide();
281 \brief Save states of dockable ParaView widgets.
283 void PVGUI_Module::saveDockWidgetsState()
285 SUIT_Desktop* desk = application()->desktop();
287 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
288 // ... the following code is commented...
289 // Save the state of the window ...
290 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
292 //for (int i = 0; i < myDockWidgets.size(); ++i)
293 // myDockWidgets.at(i)->setParent(0);
294 // ... and replaced - manually hide dock windows
296 // store dock widgets visibility state and hide'em all
297 QMapIterator<QWidget*, bool> it1( myDockWidgets );
298 while( it1.hasNext() ) {
300 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
301 myDockWidgets[dw] = dw->isVisible();
302 dw->setVisible( false );
303 dw->toggleViewAction()->setVisible( false );
305 // store toolbar breaks state and remove all tollbar breaks
306 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
307 while( it2.hasNext() ) {
309 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
310 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
311 if ( myToolbarBreaks[tb] )
312 desk->removeToolBarBreak( tb );
314 // store toolbars visibility state and hide'em all
315 QMapIterator<QWidget*, bool> it3( myToolbars );
316 while( it3.hasNext() ) {
318 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
319 myToolbars[tb] = tb->isVisible();
320 tb->setVisible( false );
321 tb->toggleViewAction()->setVisible( false );
326 \brief Restore states of dockable ParaView widgets.
328 void PVGUI_Module::restoreDockWidgetsState()
330 SUIT_Desktop* desk = application()->desktop();
332 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
333 // ... the following code is commented...
334 //for (int i = 0; i < myDockWidgets.size(); ++i)
335 // myDockWidgets.at(i)->setParent(desk);
337 // Restore the state of the window ...
338 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
339 // ... and replaced - manually hide dock windows
341 // restore dock widgets visibility state
342 QMapIterator<QWidget*, bool> it1( myDockWidgets );
343 while( it1.hasNext() ) {
345 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
346 dw->setVisible( it1.value() );
347 dw->toggleViewAction()->setVisible( true );
350 // restore toolbar breaks state
351 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
352 while( it2.hasNext() ) {
354 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
355 if ( myToolbarBreaks[tb] )
356 desk->insertToolBarBreak( tb );
359 // restore toolbar visibility state
360 QMapIterator<QWidget*, bool> it3( myToolbars );
361 while( it3.hasNext() ) {
363 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
364 tb->setVisible( it3.value() );
365 tb->toggleViewAction()->setVisible( true );
372 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
374 void PVGUI_Module::storeCommonWindowsState() {
375 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
376 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
377 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
378 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
379 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
380 // configuration file.
382 // But in contrast to others modules ParaVis module default settings hide some dockable
383 // windows, so to restore it at the moment of the ParaVis de-activation we call
384 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
387 SalomeApp_Application* anApp = getApp();
391 int begin = SalomeApp_Application::WT_ObjectBrowser;
392 int end = SalomeApp_Application::WT_NoteBook;
393 for( int i = begin; i <= end; i++ ) {
394 QWidget* wg = anApp->getWindow(i);
396 QDockWidget* dock = 0;
397 QWidget* w = wg->parentWidget();
398 while ( w && !dock ) {
399 dock = ::qobject_cast<QDockWidget*>( w );
400 w = w->parentWidget();
403 if(!myCommonMap.contains(i)){
404 myCommonMap.insert(i,dock->isVisible());
406 myCommonMap[i] = dock->isVisible();
414 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
416 void PVGUI_Module::restoreCommonWindowsState() {
417 SalomeApp_Application* anApp = getApp();
420 DockWindowMap::const_iterator it = myCommonMap.begin();
421 for( ;it != myCommonMap.end(); it++ ) {
422 QWidget* wg = anApp->getWindow(it.key());
424 QDockWidget* dock = 0;
425 QWidget* w = wg->parentWidget();
426 while ( w && !dock ) {
427 dock = ::qobject_cast<QDockWidget*>( w );
428 w = w->parentWidget();
431 dock->setVisible(it.value());