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 <pqProxyTabWidget.h>
50 #include <pqProxyInformationWidget.h>
51 #include <pqSettings.h>
52 #include <pqDataInformationWidget.h>
53 #include <pqPVAnimationWidget.h>
54 #include <pqSelectionInspectorWidget.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>
81 class ResizeHelper : public pqPVAnimationWidget
83 // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
84 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
85 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
86 // THIS BUG IS NATURALLY FIXED BY ADDING
87 // this->updateGeometries();
89 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
90 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
91 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
94 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
96 void resizeEvent(QResizeEvent* e)
98 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
101 QApplication::sendEvent( w, &e );
103 pqPVAnimationWidget::resizeEvent( e );
108 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
109 ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
111 void PVGUI_Module::setupDockWidgets()
113 SUIT_Desktop* desk = application()->desktop();
115 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
116 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
119 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
120 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
121 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
122 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
123 pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
124 pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
125 pipelineBrowserDock->setWidget(browser);
126 myDockWidgets[pipelineBrowserDock] = true;
129 QDockWidget* objectInspectorDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
130 objectInspectorDock->setObjectName("objectInspectorDock");
131 objectInspectorDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
132 desk->addDockWidget( Qt::LeftDockWidgetArea, objectInspectorDock );
134 pqObjectInspectorWidget* objectInspectorWidget = new pqObjectInspectorWidget(objectInspectorDock);
135 objectInspectorDock->setObjectName("objectInspectorWidget");
136 objectInspectorWidget->setShowOnAccept(true);
137 objectInspectorDock->setWidget(objectInspectorWidget);
138 connect( objectInspectorWidget, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
139 myDockWidgets[objectInspectorDock] = true;
142 QDockWidget* displayDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
143 displayDock->setObjectName("displayDock");
144 QWidget* displayWidgetFrame = new QWidget(displayDock);
145 displayWidgetFrame->setObjectName("displayWidgetFrame");
146 displayDock->setWidget(displayWidgetFrame);
148 QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
149 displayScrollArea->setObjectName("displayScrollArea");
150 displayScrollArea->setWidgetResizable(true);
152 QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
153 verticalLayout->setSpacing(0);
154 verticalLayout->setContentsMargins(0, 0, 0, 0);
156 pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
157 displayWidget->setObjectName("displayWidget");
158 displayScrollArea->setWidget(displayWidget);
159 verticalLayout->addWidget(displayScrollArea);
161 myDockWidgets[displayDock] = true;
164 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
165 informationDock->setObjectName("informationDock");
167 QWidget* informationWidgetFrame = new QWidget(informationDock);
168 informationWidgetFrame->setObjectName("informationWidgetFrame");
170 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
171 verticalLayout_2->setSpacing(0);
172 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
174 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
175 informationScrollArea->setObjectName("informationScrollArea") ;
176 informationScrollArea->setWidgetResizable(true);
178 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
179 informationWidget->setObjectName("informationWidget");
180 informationWidget->setGeometry(QRect(0, 0, 77, 214));
181 informationScrollArea->setWidget(informationWidget);
183 verticalLayout_2->addWidget(informationScrollArea);
184 informationDock->setWidget(informationWidgetFrame);
186 myDockWidgets[informationDock] = true;
188 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
189 desk->tabifyDockWidget(objectInspectorDock, displayDock);
190 desk->tabifyDockWidget(objectInspectorDock, informationDock);
191 objectInspectorDock->raise();
195 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
196 statisticsViewDock->setObjectName("statisticsViewDock");
197 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
198 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
199 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
200 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
201 statisticsViewDock->setWidget(aStatWidget);
202 myDockWidgets[statisticsViewDock] = false; // hidden by default
205 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
206 animationViewDock->setObjectName("animationViewDock");
207 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
208 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
209 animationViewDock->setWidget(animation_panel);
210 myDockWidgets[animationViewDock] = false; // hidden by default
212 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
215 QDockWidget* selectionInspectorDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
216 selectionInspectorDock->setObjectName("selectionInspectorDock");
217 selectionInspectorDock->setAllowedAreas( Qt::AllDockWidgetAreas );
218 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionInspectorDock );
219 pqSelectionInspectorPanel* aSelInspector = new pqSelectionInspectorWidget(selectionInspectorDock);
220 selectionInspectorDock->setWidget(aSelInspector);
221 myDockWidgets[selectionInspectorDock] = false; // hidden by default
224 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
225 comparativePanelDock->setObjectName("comparativePanelDock");
226 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
227 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
228 comparativePanelDock->setWidget(cv_panel);
229 myDockWidgets[comparativePanelDock] = false; // hidden by default
231 // Collaboration view
232 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
233 collaborationPanelDock->setObjectName("collaborationPanelDock");
234 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
235 collaborationPanel->setObjectName("collaborationPanel");
236 collaborationPanelDock->setWidget(collaborationPanel);
237 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
238 myDockWidgets[collaborationPanelDock] = false; // hidden by default
240 // Memory inspector dock
241 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
242 memoryInspectorDock->setObjectName("memoryInspectorDock");
243 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
244 dockWidgetContents->setObjectName("dockWidgetContents");
245 memoryInspectorDock->setWidget(dockWidgetContents);
246 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
247 myDockWidgets[memoryInspectorDock] = false; // hidden by default
249 // Setup the statusbar ...
250 pqProgressManager* progress_manager =
251 pqApplicationCore::instance()->getProgressManager();
253 // Progress bar/button management
254 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
255 progress_manager->addNonBlockableObject(aProgress);
256 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
258 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
259 aProgress, SLOT(enableProgress(bool)));
261 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
262 aProgress, SLOT(setProgress(const QString&, int)));
264 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
265 aProgress, SLOT(enableAbort(bool)));
267 QObject::connect( aProgress, SIGNAL(abortPressed()),
268 progress_manager, SLOT(triggerAbort()));
270 desk->statusBar()->addPermanentWidget(aProgress);
271 aProgress->setEnabled(true);
273 // Set up the dock window corners to give the vertical docks more room.
274 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
275 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
277 // Setup the default dock configuration ...
278 statisticsViewDock->hide();
279 comparativePanelDock->hide();
280 animationViewDock->hide();
281 selectionInspectorDock->hide();
282 collaborationPanelDock->hide();
283 memoryInspectorDock->hide();
287 \brief Save states of dockable ParaView widgets.
289 void PVGUI_Module::saveDockWidgetsState()
291 SUIT_Desktop* desk = application()->desktop();
293 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
294 // ... the following code is commented...
295 // Save the state of the window ...
296 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
298 //for (int i = 0; i < myDockWidgets.size(); ++i)
299 // myDockWidgets.at(i)->setParent(0);
300 // ... and replaced - manually hide dock windows
302 // store dock widgets visibility state and hide'em all
303 QMapIterator<QWidget*, bool> it1( myDockWidgets );
304 while( it1.hasNext() ) {
306 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
307 myDockWidgets[dw] = dw->isVisible();
308 dw->setVisible( false );
309 dw->toggleViewAction()->setVisible( false );
311 // store toolbar breaks state and remove all tollbar breaks
312 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
313 while( it2.hasNext() ) {
315 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
316 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
317 if ( myToolbarBreaks[tb] )
318 desk->removeToolBarBreak( tb );
320 // store toolbars visibility state and hide'em all
321 QMapIterator<QWidget*, bool> it3( myToolbars );
322 while( it3.hasNext() ) {
324 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
325 myToolbars[tb] = tb->isVisible();
326 tb->setVisible( false );
327 tb->toggleViewAction()->setVisible( false );
332 \brief Restore states of dockable ParaView widgets.
334 void PVGUI_Module::restoreDockWidgetsState()
336 SUIT_Desktop* desk = application()->desktop();
338 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
339 // ... the following code is commented...
340 //for (int i = 0; i < myDockWidgets.size(); ++i)
341 // myDockWidgets.at(i)->setParent(desk);
343 // Restore the state of the window ...
344 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
345 // ... and replaced - manually hide dock windows
347 // restore dock widgets visibility state
348 QMapIterator<QWidget*, bool> it1( myDockWidgets );
349 while( it1.hasNext() ) {
351 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
352 dw->setVisible( it1.value() );
353 dw->toggleViewAction()->setVisible( true );
355 // restore toolbar breaks state
356 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
357 while( it2.hasNext() ) {
359 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
360 if ( myToolbarBreaks[tb] )
361 desk->insertToolBarBreak( tb );
363 // restore toolbar visibility state
364 QMapIterator<QWidget*, bool> it3( myToolbars );
365 while( it3.hasNext() ) {
367 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
368 tb->setVisible( it3.value() );
369 tb->toggleViewAction()->setVisible( true );
376 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
378 void PVGUI_Module::storeCommonWindowsState() {
379 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
380 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
381 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
382 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
383 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
384 // configuration file.
386 // But in contrast to others modules ParaVis module default settings hide some dockable
387 // windows, so to restore it at the moment of the ParaVis de-activation we call
388 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
391 SalomeApp_Application* anApp = getApp();
395 int begin = SalomeApp_Application::WT_ObjectBrowser;
396 int end = SalomeApp_Application::WT_NoteBook;
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();
424 DockWindowMap::const_iterator it = myCommonMap.begin();
425 for( ;it != myCommonMap.end(); it++ ) {
426 QWidget* wg = anApp->getWindow(it.key());
428 QDockWidget* dock = 0;
429 QWidget* w = wg->parentWidget();
430 while ( w && !dock ) {
431 dock = ::qobject_cast<QDockWidget*>( w );
432 w = w->parentWidget();
435 dock->setVisible(it.value());