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 <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");
244 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
245 dockWidgetContents->setObjectName("dockWidgetContents");
246 memoryInspectorDock->setWidget(dockWidgetContents);
248 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
249 myDockWidgets[memoryInspectorDock] = false; // hidden by default
251 // Setup the statusbar ...
252 pqProgressManager* progress_manager =
253 pqApplicationCore::instance()->getProgressManager();
255 // Progress bar/button management
256 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
257 progress_manager->addNonBlockableObject(aProgress);
258 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
260 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
261 aProgress, SLOT(enableProgress(bool)));
263 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
264 aProgress, SLOT(setProgress(const QString&, int)));
266 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
267 aProgress, SLOT(enableAbort(bool)));
269 QObject::connect( aProgress, SIGNAL(abortPressed()),
270 progress_manager, SLOT(triggerAbort()));
272 desk->statusBar()->addPermanentWidget(aProgress);
273 aProgress->setEnabled(true);
275 // Set up the dock window corners to give the vertical docks more room.
276 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
277 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
279 // Setup the default dock configuration ...
280 statisticsViewDock->hide();
281 comparativePanelDock->hide();
282 animationViewDock->hide();
283 selectionInspectorDock->hide();
284 collaborationPanelDock->hide();
285 memoryInspectorDock->hide();
289 \brief Save states of dockable ParaView widgets.
291 void PVGUI_Module::saveDockWidgetsState()
293 SUIT_Desktop* desk = application()->desktop();
295 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
296 // ... the following code is commented...
297 // Save the state of the window ...
298 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
300 //for (int i = 0; i < myDockWidgets.size(); ++i)
301 // myDockWidgets.at(i)->setParent(0);
302 // ... and replaced - manually hide dock windows
304 // store dock widgets visibility state and hide'em all
305 QMapIterator<QWidget*, bool> it1( myDockWidgets );
306 while( it1.hasNext() ) {
308 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
309 myDockWidgets[dw] = dw->isVisible();
310 dw->setVisible( false );
311 dw->toggleViewAction()->setVisible( false );
313 // store toolbar breaks state and remove all tollbar breaks
314 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
315 while( it2.hasNext() ) {
317 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
318 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
319 if ( myToolbarBreaks[tb] )
320 desk->removeToolBarBreak( tb );
322 // store toolbars visibility state and hide'em all
323 QMapIterator<QWidget*, bool> it3( myToolbars );
324 while( it3.hasNext() ) {
326 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
327 myToolbars[tb] = tb->isVisible();
328 tb->setVisible( false );
329 tb->toggleViewAction()->setVisible( false );
334 \brief Restore states of dockable ParaView widgets.
336 void PVGUI_Module::restoreDockWidgetsState()
338 SUIT_Desktop* desk = application()->desktop();
340 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
341 // ... the following code is commented...
342 //for (int i = 0; i < myDockWidgets.size(); ++i)
343 // myDockWidgets.at(i)->setParent(desk);
345 // Restore the state of the window ...
346 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
347 // ... and replaced - manually hide dock windows
349 // restore dock widgets visibility state
350 QMapIterator<QWidget*, bool> it1( myDockWidgets );
351 while( it1.hasNext() ) {
353 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
354 dw->setVisible( it1.value() );
355 dw->toggleViewAction()->setVisible( true );
357 // restore toolbar breaks state
358 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
359 while( it2.hasNext() ) {
361 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
362 if ( myToolbarBreaks[tb] )
363 desk->insertToolBarBreak( tb );
365 // restore toolbar visibility state
366 QMapIterator<QWidget*, bool> it3( myToolbars );
367 while( it3.hasNext() ) {
369 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
370 tb->setVisible( it3.value() );
371 tb->toggleViewAction()->setVisible( true );
378 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
380 void PVGUI_Module::storeCommonWindowsState() {
381 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
382 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
383 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
384 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
385 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
386 // configuration file.
388 // But in contrast to others modules ParaVis module default settings hide some dockable
389 // windows, so to restore it at the moment of the ParaVis de-activation we call
390 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
393 SalomeApp_Application* anApp = getApp();
397 int begin = SalomeApp_Application::WT_ObjectBrowser;
398 int end = SalomeApp_Application::WT_NoteBook;
399 for( int i = begin; i <= end; i++ ) {
400 QWidget* wg = anApp->getWindow(i);
402 QDockWidget* dock = 0;
403 QWidget* w = wg->parentWidget();
404 while ( w && !dock ) {
405 dock = ::qobject_cast<QDockWidget*>( w );
406 w = w->parentWidget();
409 if(!myCommonMap.contains(i)){
410 myCommonMap.insert(i,dock->isVisible());
412 myCommonMap[i] = dock->isVisible();
420 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
422 void PVGUI_Module::restoreCommonWindowsState() {
423 SalomeApp_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());