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>
58 #include <pqAlwaysConnectedBehavior.h>
59 #include <pqApplicationCore.h>
60 #include <pqAutoLoadPluginXMLBehavior.h>
61 #include <pqCommandLineOptionsBehavior.h>
62 #include <pqCrashRecoveryBehavior.h>
63 #include <pqDataTimeStepBehavior.h>
64 #include <pqDefaultViewBehavior.h>
65 #include <pqDeleteBehavior.h>
66 #include <pqPersistentMainWindowStateBehavior.h>
67 #include <pqPluginActionGroupBehavior.h>
68 #include <pqPluginDockWidgetsBehavior.h>
69 #include <pqPluginManager.h>
70 #include <pqPVNewSourceBehavior.h>
71 #include <pqSpreadSheetVisibilityBehavior.h>
72 #include <pqStandardViewModules.h>
73 #include <pqUndoRedoBehavior.h>
74 #include <pqViewFrameActionsBehavior.h>
75 #include <pqParaViewMenuBuilders.h>
76 #include <pqCollaborationPanel.h>
77 #include <pqMemoryInspectorPanel.h>
78 #include <pqPropertiesPanel.h>
80 class ResizeHelper : public pqPVAnimationWidget
82 // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
83 // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
84 // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
85 // THIS BUG IS NATURALLY FIXED BY ADDING
86 // this->updateGeometries();
88 // void pqAnimationWidget::resizeEvent(QResizeEvent* e);
89 // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
90 // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
93 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
95 void resizeEvent(QResizeEvent* e)
97 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
100 QApplication::sendEvent( w, &e );
102 pqPVAnimationWidget::resizeEvent( e );
107 \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
108 ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
110 void PVGUI_Module::setupDockWidgets()
112 SUIT_Desktop* desk = application()->desktop();
114 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
115 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
118 QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
119 pipelineBrowserDock->setObjectName("pipelineBrowserDock");
120 pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
121 desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
122 pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
123 pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
124 pipelineBrowserDock->setWidget(browser);
125 myDockWidgets[pipelineBrowserDock] = true;
128 QDockWidget* propertiesDock = new QDockWidget(tr( "TTL_OBJECT_INSPECTOR" ), desk);
129 propertiesDock->setObjectName("propertiesDock");
130 pqPropertiesPanel* propertiesPanel = new pqPropertiesPanel();
131 propertiesPanel->setObjectName("propertiesPanel");
132 propertiesDock->setWidget(propertiesPanel);
133 desk->addDockWidget(Qt::LeftDockWidgetArea, propertiesDock);
134 connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ), this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
135 myDockWidgets[propertiesDock] = true;
138 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
139 informationDock->setObjectName("informationDock");
141 QWidget* informationWidgetFrame = new QWidget(informationDock);
142 informationWidgetFrame->setObjectName("informationWidgetFrame");
144 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
145 verticalLayout_2->setSpacing(0);
146 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
148 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
149 informationScrollArea->setObjectName("informationScrollArea") ;
150 informationScrollArea->setWidgetResizable(true);
152 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
153 informationWidget->setObjectName("informationWidget");
154 informationWidget->setGeometry(QRect(0, 0, 77, 214));
155 informationScrollArea->setWidget(informationWidget);
157 verticalLayout_2->addWidget(informationScrollArea);
158 informationDock->setWidget(informationWidgetFrame);
160 desk->addDockWidget(Qt::LeftDockWidgetArea, informationDock);
161 myDockWidgets[informationDock] = true;
163 // put 'Properties' and 'Information' widgets into tabs
164 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
165 desk->tabifyDockWidget(propertiesDock, informationDock);
166 propertiesDock->raise();
169 QDockWidget* statisticsViewDock = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
170 statisticsViewDock->setObjectName("statisticsViewDock");
171 statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
172 Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
173 desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
174 pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
175 statisticsViewDock->setWidget(aStatWidget);
176 myDockWidgets[statisticsViewDock] = false; // hidden by default
179 QDockWidget* animationViewDock = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
180 animationViewDock->setObjectName("animationViewDock");
181 desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
182 pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
183 animationViewDock->setWidget(animation_panel);
184 myDockWidgets[animationViewDock] = false; // hidden by default
186 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
189 QDockWidget* selectionInspectorDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
190 selectionInspectorDock->setObjectName("selectionInspectorDock");
191 selectionInspectorDock->setAllowedAreas( Qt::AllDockWidgetAreas );
192 desk->addDockWidget( Qt::LeftDockWidgetArea, selectionInspectorDock );
193 pqSelectionInspectorPanel* aSelInspector = new pqSelectionInspectorWidget(selectionInspectorDock);
194 selectionInspectorDock->setWidget(aSelInspector);
195 myDockWidgets[selectionInspectorDock] = false; // hidden by default
198 QDockWidget* comparativePanelDock = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
199 comparativePanelDock->setObjectName("comparativePanelDock");
200 desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
201 pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
202 comparativePanelDock->setWidget(cv_panel);
203 myDockWidgets[comparativePanelDock] = false; // hidden by default
205 // Collaboration view
206 QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
207 collaborationPanelDock->setObjectName("collaborationPanelDock");
208 pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
209 collaborationPanel->setObjectName("collaborationPanel");
210 collaborationPanelDock->setWidget(collaborationPanel);
211 desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
212 myDockWidgets[collaborationPanelDock] = false; // hidden by default
214 // Memory inspector dock
215 QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
216 memoryInspectorDock->setObjectName("memoryInspectorDock");
217 pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
218 dockWidgetContents->setObjectName("dockWidgetContents");
219 memoryInspectorDock->setWidget(dockWidgetContents);
220 desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
221 myDockWidgets[memoryInspectorDock] = false; // hidden by default
223 // Setup the statusbar ...
224 pqProgressManager* progress_manager =
225 pqApplicationCore::instance()->getProgressManager();
227 // Progress bar/button management
228 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
229 progress_manager->addNonBlockableObject(aProgress);
230 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
232 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
233 aProgress, SLOT(enableProgress(bool)));
235 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
236 aProgress, SLOT(setProgress(const QString&, int)));
238 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
239 aProgress, SLOT(enableAbort(bool)));
241 QObject::connect( aProgress, SIGNAL(abortPressed()),
242 progress_manager, SLOT(triggerAbort()));
244 desk->statusBar()->addPermanentWidget(aProgress);
245 aProgress->setEnabled(true);
247 // Set up the dock window corners to give the vertical docks more room.
248 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
249 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
251 // Setup the default dock configuration ...
252 statisticsViewDock->hide();
253 comparativePanelDock->hide();
254 animationViewDock->hide();
255 selectionInspectorDock->hide();
256 collaborationPanelDock->hide();
257 memoryInspectorDock->hide();
261 \brief Save states of dockable ParaView widgets.
263 void PVGUI_Module::saveDockWidgetsState()
265 SUIT_Desktop* desk = application()->desktop();
267 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
268 // ... the following code is commented...
269 // Save the state of the window ...
270 // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
272 //for (int i = 0; i < myDockWidgets.size(); ++i)
273 // myDockWidgets.at(i)->setParent(0);
274 // ... and replaced - manually hide dock windows
276 // store dock widgets visibility state and hide'em all
277 QMapIterator<QWidget*, bool> it1( myDockWidgets );
278 while( it1.hasNext() ) {
280 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
281 myDockWidgets[dw] = dw->isVisible();
282 dw->setVisible( false );
283 dw->toggleViewAction()->setVisible( false );
285 // store toolbar breaks state and remove all tollbar breaks
286 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
287 while( it2.hasNext() ) {
289 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
290 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
291 if ( myToolbarBreaks[tb] )
292 desk->removeToolBarBreak( tb );
294 // store toolbars visibility state and hide'em all
295 QMapIterator<QWidget*, bool> it3( myToolbars );
296 while( it3.hasNext() ) {
298 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
299 myToolbars[tb] = tb->isVisible();
300 tb->setVisible( false );
301 tb->toggleViewAction()->setVisible( false );
306 \brief Restore states of dockable ParaView widgets.
308 void PVGUI_Module::restoreDockWidgetsState()
310 SUIT_Desktop* desk = application()->desktop();
312 // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
313 // ... the following code is commented...
314 //for (int i = 0; i < myDockWidgets.size(); ++i)
315 // myDockWidgets.at(i)->setParent(desk);
317 // Restore the state of the window ...
318 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
319 // ... and replaced - manually hide dock windows
321 // restore dock widgets visibility state
322 QMapIterator<QWidget*, bool> it1( myDockWidgets );
323 while( it1.hasNext() ) {
325 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
326 dw->setVisible( it1.value() );
327 dw->toggleViewAction()->setVisible( true );
329 // restore toolbar breaks state
330 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
331 while( it2.hasNext() ) {
333 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
334 if ( myToolbarBreaks[tb] )
335 desk->insertToolBarBreak( tb );
337 // restore toolbar visibility state
338 QMapIterator<QWidget*, bool> it3( myToolbars );
339 while( it3.hasNext() ) {
341 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
342 tb->setVisible( it3.value() );
343 tb->toggleViewAction()->setVisible( true );
350 \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
352 void PVGUI_Module::storeCommonWindowsState() {
353 //rnv: Make behaviour of the dockable windows and toolbars coherent with others
354 // modules: if 'Save position of the windows' or 'Save position of the toolbars'
355 // in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
356 // are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
357 // Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
358 // configuration file.
360 // But in contrast to others modules ParaVis module default settings hide some dockable
361 // windows, so to restore it at the moment of the ParaVis de-activation we call
362 // restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call
365 SalomeApp_Application* anApp = getApp();
369 int begin = SalomeApp_Application::WT_ObjectBrowser;
370 int end = SalomeApp_Application::WT_NoteBook;
371 for( int i = begin; i <= end; i++ ) {
372 QWidget* wg = anApp->getWindow(i);
374 QDockWidget* dock = 0;
375 QWidget* w = wg->parentWidget();
376 while ( w && !dock ) {
377 dock = ::qobject_cast<QDockWidget*>( w );
378 w = w->parentWidget();
381 if(!myCommonMap.contains(i)){
382 myCommonMap.insert(i,dock->isVisible());
384 myCommonMap[i] = dock->isVisible();
392 \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
394 void PVGUI_Module::restoreCommonWindowsState() {
395 SalomeApp_Application* anApp = getApp();
398 DockWindowMap::const_iterator it = myCommonMap.begin();
399 for( ;it != myCommonMap.end(); it++ ) {
400 QWidget* wg = anApp->getWindow(it.key());
402 QDockWidget* dock = 0;
403 QWidget* w = wg->parentWidget();
404 while ( w && !dock ) {
405 dock = ::qobject_cast<QDockWidget*>( w );
406 w = w->parentWidget();
409 dock->setVisible(it.value());