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;
118 pipelineBrowserDock->hide();
120 // Properties dock (previously called OBJECT_INSPECTOR)
121 QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
122 propertiesDock->setObjectName("propertiesDock");
123 propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
124 desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
126 pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
127 propertiesDock->setWidget(propertiesPanel);
128 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
129 // hook delete to pqDeleteReaction.
130 QAction* tempDeleteAction = new QAction(this);
131 pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
132 handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
133 myDockWidgets[propertiesDock] = true;
134 propertiesDock->hide();
137 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
138 informationDock->setObjectName("informationDock");
140 QWidget* informationWidgetFrame = new QWidget(informationDock);
141 informationWidgetFrame->setObjectName("informationWidgetFrame");
143 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
144 verticalLayout_2->setSpacing(0);
145 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
147 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
148 informationScrollArea->setObjectName("informationScrollArea") ;
149 informationScrollArea->setWidgetResizable(true);
151 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
152 informationWidget->setObjectName("informationWidget");
153 informationWidget->setGeometry(QRect(0, 0, 77, 214));
154 informationScrollArea->setWidget(informationWidget);
156 verticalLayout_2->addWidget(informationScrollArea);
157 informationDock->setWidget(informationWidgetFrame);
159 myDockWidgets[informationDock] = true;
162 desk->tabifyDockWidget(informationDock, propertiesDock);
163 desk->tabifyDockWidget(propertiesDock, pipelineBrowserDock);
164 //propertiesDock->raise();
167 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
168 statisticsViewDock->setObjectName("statisticsViewDock");
169 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
170 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
171 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
172 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
173 statisticsViewDock->setWidget(aStatWidget);
174 myDockWidgets[statisticsViewDock] = false; // hidden by default
177 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
178 animationViewDock->setObjectName("animationViewDock");
179 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
180 pqPVAnimationWidget* animation_panel = new pqPVAnimationWidget(animationViewDock); // [ABN] was resizeHelper
181 animationViewDock->setWidget(animation_panel);
182 myDockWidgets[animationViewDock] = false; // hidden by default
184 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
186 // Selection inspector
187 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
188 selectionDisplayDock->setObjectName("selectionInspectorDock");
189 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
190 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
191 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
192 selectionDisplayDock->setWidget(aSelInspector);
193 myDockWidgets[selectionDisplayDock] = false; // hidden by default
195 // Multi-block inspector
196 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
197 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
198 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
199 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
200 multiBlockInspectorPanelDock->setWidget(mbi_panel);
201 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
204 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
205 comparativePanelDock->setObjectName("comparativePanelDock");
206 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
207 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
208 comparativePanelDock->setWidget(cv_panel);
209 myDockWidgets[comparativePanelDock] = false; // hidden by default
211 // Collaboration view
212 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
213 collaborationPanelDock->setObjectName("collaborationPanelDock");
214 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
215 collaborationPanel->setObjectName("collaborationPanel");
216 collaborationPanelDock->setWidget(collaborationPanel);
217 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
218 myDockWidgets[collaborationPanelDock] = false; // hidden by default
221 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
222 colorMapEditorDock->setObjectName("colorMapEditorDock");
223 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
224 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
225 colorMapEditorDock->setWidget(cmed_panel);
226 myDockWidgets[colorMapEditorDock] = false; // hidden by default
228 // Provide access to the color-editor panel for the application.
229 pqApplicationCore::instance()->registerManager(
230 "COLOR_EDITOR_PANEL", colorMapEditorDock);
232 // Memory inspector dock
233 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
234 memoryInspectorDock->setObjectName("memoryInspectorDock");
236 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
237 dockWidgetContents->setObjectName("dockWidgetContents");
238 memoryInspectorDock->setWidget(dockWidgetContents);
240 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
241 myDockWidgets[memoryInspectorDock] = false; // hidden by default
243 // Setup the statusbar ...
244 pqProgressManager* progress_manager =
245 pqApplicationCore::instance()->getProgressManager();
247 // Progress bar/button management
248 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
249 progress_manager->addNonBlockableObject(aProgress);
250 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
252 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
253 aProgress, SLOT(enableProgress(bool)));
255 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
256 aProgress, SLOT(setProgress(const QString&, int)));
258 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
259 aProgress, SLOT(enableAbort(bool)));
261 QObject::connect( aProgress, SIGNAL(abortPressed()),
262 progress_manager, SLOT(triggerAbort()));
264 desk->statusBar()->addPermanentWidget(aProgress);
265 aProgress->setEnabled(true);
267 // Set up the dock window corners to give the vertical docks more room.
268 // desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
269 // desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
271 // Setup the default dock configuration ...
272 statisticsViewDock->hide();
273 comparativePanelDock->hide();
274 animationViewDock->hide();
275 multiBlockInspectorPanelDock->hide();
276 selectionDisplayDock->hide();
277 collaborationPanelDock->hide();
278 memoryInspectorDock->hide();
279 colorMapEditorDock->hide();
283 \brief Save states of dockable ParaView widgets.
285 void PVGUI_Module::saveDockWidgetsState()
287 SUIT_Desktop* desk = application()->desktop();
289 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
290 // ... the following code is commented...
291 // Save the state of the window ...
292 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
294 //for (int i = 0; i < myDockWidgets.size(); ++i)
295 // myDockWidgets.at(i)->setParent(0);
296 // ... and replaced - manually hide dock windows
298 // store dock widgets visibility state and hide'em all
299 QMapIterator<QWidget*, bool> it1( myDockWidgets );
300 while( it1.hasNext() ) {
302 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
303 myDockWidgets[dw] = dw->isVisible();
304 dw->setVisible( false );
305 dw->toggleViewAction()->setVisible( false );
307 // store toolbar breaks state and remove all tollbar breaks
308 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
309 while( it2.hasNext() ) {
311 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
312 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
313 if ( myToolbarBreaks[tb] )
314 desk->removeToolBarBreak( tb );
316 // store toolbars visibility state and hide'em all
317 QMapIterator<QWidget*, bool> it3( myToolbars );
318 while( it3.hasNext() ) {
320 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
321 myToolbars[tb] = tb->isVisible();
322 tb->setVisible( false );
323 tb->toggleViewAction()->setVisible( false );
328 \brief Restore states of dockable ParaView widgets.
330 void PVGUI_Module::restoreDockWidgetsState()
332 SUIT_Desktop* desk = application()->desktop();
334 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
335 // ... the following code is commented...
336 //for (int i = 0; i < myDockWidgets.size(); ++i)
337 // myDockWidgets.at(i)->setParent(desk);
339 // Restore the state of the window ...
340 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
341 // ... and replaced - manually hide dock windows
343 // restore dock widgets visibility state
344 QMapIterator<QWidget*, bool> it1( myDockWidgets );
345 while( it1.hasNext() ) {
347 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
348 dw->setVisible( it1.value() );
349 dw->toggleViewAction()->setVisible( true );
352 // restore toolbar breaks state
353 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
354 while( it2.hasNext() ) {
356 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
357 if ( myToolbarBreaks[tb] )
358 desk->insertToolBarBreak( tb );
361 // restore toolbar visibility state
362 QMapIterator<QWidget*, bool> it3( myToolbars );
363 while( it3.hasNext() ) {
365 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
366 tb->setVisible( it3.value() );
367 tb->toggleViewAction()->setVisible( true );
374 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
376 void PVGUI_Module::storeCommonWindowsState() {
377 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
378 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
379 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
380 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
381 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
382 // configuration file.
384 // But in contrast to others modules ParaVis module default settings hide some dockable
385 // windows, so to restore it at the moment of the ParaVis de-activation we call
386 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
389 //LightApp_Application* anApp = getApp();
390 SalomeApp_Application* anApp = getApp();
394 // int begin = SalomeApp_Application::WT_ObjectBrowser;
395 // int end = SalomeApp_Application::WT_NoteBook;
396 int begin = LightApp_Application::WT_ObjectBrowser;
397 int end = LightApp_Application::WT_User;
398 for( int i = begin; i <= end; i++ ) {
399 QWidget* wg = anApp->getWindow(i);
401 QDockWidget* dock = 0;
402 QWidget* w = wg->parentWidget();
403 while ( w && !dock ) {
404 dock = ::qobject_cast<QDockWidget*>( w );
405 w = w->parentWidget();
408 if(!myCommonMap.contains(i)){
409 myCommonMap.insert(i,dock->isVisible());
411 myCommonMap[i] = dock->isVisible();
419 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
421 void PVGUI_Module::restoreCommonWindowsState() {
422 SalomeApp_Application* anApp = getApp();
423 // LightApp_Application* anApp = getApp();
426 DockWindowMap::const_iterator it = myCommonMap.begin();
427 for( ;it != myCommonMap.end(); it++ ) {
428 QWidget* wg = anApp->getWindow(it.key());
430 QDockWidget* dock = 0;
431 QWidget* w = wg->parentWidget();
432 while ( w && !dock ) {
433 dock = ::qobject_cast<QDockWidget*>( w );
434 w = w->parentWidget();
437 dock->setVisible(it.value());