1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2013 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.
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 <pqObjectInspectorWidget.h>
58 #include <pqDisplayProxyEditorWidget.h>
60 #include <pqAlwaysConnectedBehavior.h>
61 #include <pqApplicationCore.h>
62 #include <pqAutoLoadPluginXMLBehavior.h>
63 #include <pqCommandLineOptionsBehavior.h>
64 #include <pqCrashRecoveryBehavior.h>
65 #include <pqDataTimeStepBehavior.h>
66 #include <pqDefaultViewBehavior.h>
67 #include <pqDeleteBehavior.h>
68 #include <pqPersistentMainWindowStateBehavior.h>
69 #include <pqPluginActionGroupBehavior.h>
70 #include <pqPluginDockWidgetsBehavior.h>
71 #include <pqPluginManager.h>
72 #include <pqPVNewSourceBehavior.h>
73 #include <pqSpreadSheetVisibilityBehavior.h>
74 #include <pqStandardViewModules.h>
75 #include <pqUndoRedoBehavior.h>
76 #include <pqViewFrameActionsBehavior.h>
77 #include <pqParaViewMenuBuilders.h>
78 #include <pqCollaborationPanel.h>
79 #include <pqMemoryInspectorPanel.h>
80 #include <pqColorMapEditor.h>
82 class ResizeHelper : public pqPVAnimationWidget
84 // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
85 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
86 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
87 // THIS BUG IS NATURALLY FIXED BY ADDING
88 // this->updateGeometries();
90 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
91 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
92 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
95 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
97 void resizeEvent(QResizeEvent* e)
99 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
102 QApplication::sendEvent( w, &e );
104 pqPVAnimationWidget::resizeEvent( e );
109 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
110 ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
112 void PVGUI_Module::setupDockWidgets()
114 SUIT_Desktop* desk = application()->desktop();
116 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
117 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
120 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
121 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
122 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
123 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
124 pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
125 pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
126 pipelineBrowserDock->setWidget(browser);
127 myDockWidgets[pipelineBrowserDock] = true;
130 QDockWidget* objectInspectorDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
131 objectInspectorDock->setObjectName("objectInspectorDock");
132 objectInspectorDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
133 desk->addDockWidget( Qt::LeftDockWidgetArea, objectInspectorDock );
135 pqObjectInspectorWidget* objectInspectorWidget = new pqObjectInspectorWidget(objectInspectorDock);
136 objectInspectorDock->setObjectName("objectInspectorWidget");
137 objectInspectorWidget->setShowOnAccept(true);
138 objectInspectorDock->setWidget(objectInspectorWidget);
139 connect( objectInspectorWidget, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
140 myDockWidgets[objectInspectorDock] = true;
143 QDockWidget* displayDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
144 displayDock->setObjectName("displayDock");
145 QWidget* displayWidgetFrame = new QWidget(displayDock);
146 displayWidgetFrame->setObjectName("displayWidgetFrame");
147 displayDock->setWidget(displayWidgetFrame);
149 QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
150 displayScrollArea->setObjectName("displayScrollArea");
151 displayScrollArea->setWidgetResizable(true);
153 QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
154 verticalLayout->setSpacing(0);
155 verticalLayout->setContentsMargins(0, 0, 0, 0);
157 pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
158 displayWidget->setObjectName("displayWidget");
159 displayScrollArea->setWidget(displayWidget);
160 verticalLayout->addWidget(displayScrollArea);
162 myDockWidgets[displayDock] = true;
165 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
166 informationDock->setObjectName("informationDock");
168 QWidget* informationWidgetFrame = new QWidget(informationDock);
169 informationWidgetFrame->setObjectName("informationWidgetFrame");
171 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
172 verticalLayout_2->setSpacing(0);
173 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
175 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
176 informationScrollArea->setObjectName("informationScrollArea") ;
177 informationScrollArea->setWidgetResizable(true);
179 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
180 informationWidget->setObjectName("informationWidget");
181 informationWidget->setGeometry(QRect(0, 0, 77, 214));
182 informationScrollArea->setWidget(informationWidget);
184 verticalLayout_2->addWidget(informationScrollArea);
185 informationDock->setWidget(informationWidgetFrame);
187 myDockWidgets[informationDock] = true;
189 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
190 desk->tabifyDockWidget(objectInspectorDock, displayDock);
191 desk->tabifyDockWidget(objectInspectorDock, informationDock);
192 objectInspectorDock->raise();
196 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
197 statisticsViewDock->setObjectName("statisticsViewDock");
198 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
199 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
200 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
201 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
202 statisticsViewDock->setWidget(aStatWidget);
203 myDockWidgets[statisticsViewDock] = false; // hidden by default
206 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
207 animationViewDock->setObjectName("animationViewDock");
208 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
209 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
210 animationViewDock->setWidget(animation_panel);
211 myDockWidgets[animationViewDock] = false; // hidden by default
213 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
215 // Selection inspector
216 QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
217 selectionDisplayDock->setObjectName("selectionInspectorDock");
218 selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
219 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
220 pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
221 selectionDisplayDock->setWidget(aSelInspector);
222 myDockWidgets[selectionDisplayDock] = false; // hidden by default
224 // Multi-block inspector
225 QDockWidget* multiBlockInspectorPanelDock = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
226 multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
227 desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
228 pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
229 multiBlockInspectorPanelDock->setWidget(mbi_panel);
230 myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
233 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
234 comparativePanelDock->setObjectName("comparativePanelDock");
235 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
236 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
237 comparativePanelDock->setWidget(cv_panel);
238 myDockWidgets[comparativePanelDock] = false; // hidden by default
240 // Collaboration view
241 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
242 collaborationPanelDock->setObjectName("collaborationPanelDock");
243 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
244 collaborationPanel->setObjectName("collaborationPanel");
245 collaborationPanelDock->setWidget(collaborationPanel);
246 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
247 myDockWidgets[collaborationPanelDock] = false; // hidden by default
250 QDockWidget* colorMapEditorDock = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
251 colorMapEditorDock->setObjectName("colorMapEditorDock");
252 desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
253 pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
254 colorMapEditorDock->setWidget(cmed_panel);
255 myDockWidgets[colorMapEditorDock] = false; // hidden by default
257 // Provide access to the color-editor panel for the application.
258 pqApplicationCore::instance()->registerManager(
259 "COLOR_EDITOR_PANEL", colorMapEditorDock);
261 // Memory inspector dock
262 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
263 memoryInspectorDock->setObjectName("memoryInspectorDock");
265 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
266 dockWidgetContents->setObjectName("dockWidgetContents");
267 memoryInspectorDock->setWidget(dockWidgetContents);
269 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
270 myDockWidgets[memoryInspectorDock] = false; // hidden by default
272 // Setup the statusbar ...
273 pqProgressManager* progress_manager =
274 pqApplicationCore::instance()->getProgressManager();
276 // Progress bar/button management
277 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
278 progress_manager->addNonBlockableObject(aProgress);
279 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
281 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
282 aProgress, SLOT(enableProgress(bool)));
284 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
285 aProgress, SLOT(setProgress(const QString&, int)));
287 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
288 aProgress, SLOT(enableAbort(bool)));
290 QObject::connect( aProgress, SIGNAL(abortPressed()),
291 progress_manager, SLOT(triggerAbort()));
293 desk->statusBar()->addPermanentWidget(aProgress);
294 aProgress->setEnabled(true);
296 // Set up the dock window corners to give the vertical docks more room.
297 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
298 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
300 // Setup the default dock configuration ...
301 statisticsViewDock->hide();
302 comparativePanelDock->hide();
303 animationViewDock->hide();
304 multiBlockInspectorPanelDock->hide();
305 selectionDisplayDock->hide();
306 collaborationPanelDock->hide();
307 memoryInspectorDock->hide();
308 colorMapEditorDock->hide();
312 \brief Save states of dockable ParaView widgets.
314 void PVGUI_Module::saveDockWidgetsState()
316 SUIT_Desktop* desk = application()->desktop();
318 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
319 // ... the following code is commented...
320 // Save the state of the window ...
321 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
323 //for (int i = 0; i < myDockWidgets.size(); ++i)
324 // myDockWidgets.at(i)->setParent(0);
325 // ... and replaced - manually hide dock windows
327 // store dock widgets visibility state and hide'em all
328 QMapIterator<QWidget*, bool> it1( myDockWidgets );
329 while( it1.hasNext() ) {
331 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
332 myDockWidgets[dw] = dw->isVisible();
333 dw->setVisible( false );
334 dw->toggleViewAction()->setVisible( false );
336 // store toolbar breaks state and remove all tollbar breaks
337 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
338 while( it2.hasNext() ) {
340 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
341 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
342 if ( myToolbarBreaks[tb] )
343 desk->removeToolBarBreak( tb );
345 // store toolbars visibility state and hide'em all
346 QMapIterator<QWidget*, bool> it3( myToolbars );
347 while( it3.hasNext() ) {
349 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
350 myToolbars[tb] = tb->isVisible();
351 tb->setVisible( false );
352 tb->toggleViewAction()->setVisible( false );
357 \brief Restore states of dockable ParaView widgets.
359 void PVGUI_Module::restoreDockWidgetsState()
361 SUIT_Desktop* desk = application()->desktop();
363 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
364 // ... the following code is commented...
365 //for (int i = 0; i < myDockWidgets.size(); ++i)
366 // myDockWidgets.at(i)->setParent(desk);
368 // Restore the state of the window ...
369 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
370 // ... and replaced - manually hide dock windows
372 // restore dock widgets visibility state
373 QMapIterator<QWidget*, bool> it1( myDockWidgets );
374 while( it1.hasNext() ) {
376 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
377 dw->setVisible( it1.value() );
378 dw->toggleViewAction()->setVisible( true );
380 // restore toolbar breaks state
381 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
382 while( it2.hasNext() ) {
384 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
385 if ( myToolbarBreaks[tb] )
386 desk->insertToolBarBreak( tb );
388 // restore toolbar visibility state
389 QMapIterator<QWidget*, bool> it3( myToolbars );
390 while( it3.hasNext() ) {
392 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
393 tb->setVisible( it3.value() );
394 tb->toggleViewAction()->setVisible( true );
401 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
403 void PVGUI_Module::storeCommonWindowsState() {
404 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
405 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
406 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
407 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
408 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
409 // configuration file.
411 // But in contrast to others modules ParaVis module default settings hide some dockable
412 // windows, so to restore it at the moment of the ParaVis de-activation we call
413 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
416 SalomeApp_Application* anApp = getApp();
420 int begin = SalomeApp_Application::WT_ObjectBrowser;
421 int end = SalomeApp_Application::WT_NoteBook;
422 for( int i = begin; i <= end; i++ ) {
423 QWidget* wg = anApp->getWindow(i);
425 QDockWidget* dock = 0;
426 QWidget* w = wg->parentWidget();
427 while ( w && !dock ) {
428 dock = ::qobject_cast<QDockWidget*>( w );
429 w = w->parentWidget();
432 if(!myCommonMap.contains(i)){
433 myCommonMap.insert(i,dock->isVisible());
435 myCommonMap[i] = dock->isVisible();
443 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
445 void PVGUI_Module::restoreCommonWindowsState() {
446 SalomeApp_Application* anApp = getApp();
449 DockWindowMap::const_iterator it = myCommonMap.begin();
450 for( ;it != myCommonMap.end(); it++ ) {
451 QWidget* wg = anApp->getWindow(it.key());
453 QDockWidget* dock = 0;
454 QWidget* w = wg->parentWidget();
455 while ( w && !dock ) {
456 dock = ::qobject_cast<QDockWidget*>( w );
457 w = w->parentWidget();
460 dock->setVisible(it.value());