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 <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
258 // Memory inspector dock
259 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
260 memoryInspectorDock->setObjectName("memoryInspectorDock");
262 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
263 dockWidgetContents->setObjectName("dockWidgetContents");
264 memoryInspectorDock->setWidget(dockWidgetContents);
266 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
267 myDockWidgets[memoryInspectorDock] = false; // hidden by default
269 // Setup the statusbar ...
270 pqProgressManager* progress_manager =
271 pqApplicationCore::instance()->getProgressManager();
273 // Progress bar/button management
274 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
275 progress_manager->addNonBlockableObject(aProgress);
276 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
278 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
279 aProgress, SLOT(enableProgress(bool)));
281 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
282 aProgress, SLOT(setProgress(const QString&, int)));
284 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
285 aProgress, SLOT(enableAbort(bool)));
287 QObject::connect( aProgress, SIGNAL(abortPressed()),
288 progress_manager, SLOT(triggerAbort()));
290 desk->statusBar()->addPermanentWidget(aProgress);
291 aProgress->setEnabled(true);
293 // Set up the dock window corners to give the vertical docks more room.
294 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
295 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
297 // Setup the default dock configuration ...
298 statisticsViewDock->hide();
299 comparativePanelDock->hide();
300 animationViewDock->hide();
301 multiBlockInspectorPanelDock->hide();
302 selectionDisplayDock->hide();
303 collaborationPanelDock->hide();
304 memoryInspectorDock->hide();
305 colorMapEditorDock->hide();
309 \brief Save states of dockable ParaView widgets.
311 void PVGUI_Module::saveDockWidgetsState()
313 SUIT_Desktop* desk = application()->desktop();
315 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
316 // ... the following code is commented...
317 // Save the state of the window ...
318 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
320 //for (int i = 0; i < myDockWidgets.size(); ++i)
321 // myDockWidgets.at(i)->setParent(0);
322 // ... and replaced - manually hide dock windows
324 // store dock widgets visibility state and hide'em all
325 QMapIterator<QWidget*, bool> it1( myDockWidgets );
326 while( it1.hasNext() ) {
328 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
329 myDockWidgets[dw] = dw->isVisible();
330 dw->setVisible( false );
331 dw->toggleViewAction()->setVisible( false );
333 // store toolbar breaks state and remove all tollbar breaks
334 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
335 while( it2.hasNext() ) {
337 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
338 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
339 if ( myToolbarBreaks[tb] )
340 desk->removeToolBarBreak( tb );
342 // store toolbars visibility state and hide'em all
343 QMapIterator<QWidget*, bool> it3( myToolbars );
344 while( it3.hasNext() ) {
346 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
347 myToolbars[tb] = tb->isVisible();
348 tb->setVisible( false );
349 tb->toggleViewAction()->setVisible( false );
354 \brief Restore states of dockable ParaView widgets.
356 void PVGUI_Module::restoreDockWidgetsState()
358 SUIT_Desktop* desk = application()->desktop();
360 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
361 // ... the following code is commented...
362 //for (int i = 0; i < myDockWidgets.size(); ++i)
363 // myDockWidgets.at(i)->setParent(desk);
365 // Restore the state of the window ...
366 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
367 // ... and replaced - manually hide dock windows
369 // restore dock widgets visibility state
370 QMapIterator<QWidget*, bool> it1( myDockWidgets );
371 while( it1.hasNext() ) {
373 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
374 dw->setVisible( it1.value() );
375 dw->toggleViewAction()->setVisible( true );
377 // restore toolbar breaks state
378 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
379 while( it2.hasNext() ) {
381 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
382 if ( myToolbarBreaks[tb] )
383 desk->insertToolBarBreak( tb );
385 // restore toolbar visibility state
386 QMapIterator<QWidget*, bool> it3( myToolbars );
387 while( it3.hasNext() ) {
389 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
390 tb->setVisible( it3.value() );
391 tb->toggleViewAction()->setVisible( true );
398 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
400 void PVGUI_Module::storeCommonWindowsState() {
401 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
402 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
403 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
404 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
405 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
406 // configuration file.
408 // But in contrast to others modules ParaVis module default settings hide some dockable
409 // windows, so to restore it at the moment of the ParaVis de-activation we call
410 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
413 SalomeApp_Application* anApp = getApp();
417 int begin = SalomeApp_Application::WT_ObjectBrowser;
418 int end = SalomeApp_Application::WT_NoteBook;
419 for( int i = begin; i <= end; i++ ) {
420 QWidget* wg = anApp->getWindow(i);
422 QDockWidget* dock = 0;
423 QWidget* w = wg->parentWidget();
424 while ( w && !dock ) {
425 dock = ::qobject_cast<QDockWidget*>( w );
426 w = w->parentWidget();
429 if(!myCommonMap.contains(i)){
430 myCommonMap.insert(i,dock->isVisible());
432 myCommonMap[i] = dock->isVisible();
440 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
442 void PVGUI_Module::restoreCommonWindowsState() {
443 SalomeApp_Application* anApp = getApp();
446 DockWindowMap::const_iterator it = myCommonMap.begin();
447 for( ;it != myCommonMap.end(); it++ ) {
448 QWidget* wg = anApp->getWindow(it.key());
450 QDockWidget* dock = 0;
451 QWidget* w = wg->parentWidget();
452 while ( w && !dock ) {
453 dock = ::qobject_cast<QDockWidget*>( w );
454 w = w->parentWidget();
457 dock->setVisible(it.value());