Salome HOME
Merge branch 'akl/tests_update'
[modules/paravis.git] / src / PVGUI / PVGUI_Module_widgets.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2014  CEA/DEN, EDF R&D
4 //
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.
9 //
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.
14 //
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
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 // File   : PVGUI_Module_MenuActions.cxx
22 // Author : Margarita KARPUNINA
23 //
24
25 #include "PVGUI_Module.h"
26
27 #include <QtxActionToolMgr.h>
28 #include <LightApp_Application.h>
29 #include <SalomeApp_Application.h>
30 #include <SUIT_Desktop.h>
31
32 #include <QApplication>
33 #include <QAction>
34 #include <QDockWidget>
35 #include <QToolBar>
36 #include <QStatusBar>
37 #include <QShortcut>
38 #include <QScrollArea>
39 #include <QVBoxLayout>
40 #include <QShowEvent>
41 #include <QToolButton>
42
43 #include <pqAnimationViewWidget.h> 
44 #include <pqAnimationWidget.h> 
45
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>
59
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>
81
82 class ResizeHelper : public pqPVAnimationWidget
83 {
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();
89   // TO THE
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
93
94 public:
95   ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
96 protected:
97   void resizeEvent(QResizeEvent* e)
98   {
99     pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
100     if ( w ) { 
101       QShowEvent e;
102       QApplication::sendEvent( w, &e );
103     }
104     pqPVAnimationWidget::resizeEvent( e );
105   }
106 };
107
108 /*!
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.
111 */
112 void PVGUI_Module::setupDockWidgets()
113 {
114   SUIT_Desktop* desk = application()->desktop();
115  
116   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
117   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
118
119   // Pipeline
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;
128
129   //Object inspector
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 );
134
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;
141
142   //Display Dock
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);
148
149   QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
150   displayScrollArea->setObjectName("displayScrollArea");
151   displayScrollArea->setWidgetResizable(true);
152
153   QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
154   verticalLayout->setSpacing(0);
155   verticalLayout->setContentsMargins(0, 0, 0, 0);
156
157   pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
158   displayWidget->setObjectName("displayWidget");
159   displayScrollArea->setWidget(displayWidget);
160   verticalLayout->addWidget(displayScrollArea);
161
162   myDockWidgets[displayDock] = true;
163
164   // information dock
165   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
166   informationDock->setObjectName("informationDock");
167
168   QWidget* informationWidgetFrame = new QWidget(informationDock);
169   informationWidgetFrame->setObjectName("informationWidgetFrame");
170   
171   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
172   verticalLayout_2->setSpacing(0);
173   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
174
175   QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
176   informationScrollArea->setObjectName("informationScrollArea") ;
177   informationScrollArea->setWidgetResizable(true);
178
179   pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
180   informationWidget->setObjectName("informationWidget");
181   informationWidget->setGeometry(QRect(0, 0, 77, 214));
182   informationScrollArea->setWidget(informationWidget);
183
184   verticalLayout_2->addWidget(informationScrollArea);
185   informationDock->setWidget(informationWidgetFrame);
186
187   myDockWidgets[informationDock] = true;
188
189   desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
190   desk->tabifyDockWidget(objectInspectorDock, displayDock);
191   desk->tabifyDockWidget(objectInspectorDock, informationDock);
192   objectInspectorDock->raise();
193
194
195   // Statistic View
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
204
205   //Animation view
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
212
213   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
214
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
223
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
231
232   // Comparative View
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
239
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
248
249   // Color map editor
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
256
257   
258   // Memory inspector dock
259   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
260   memoryInspectorDock->setObjectName("memoryInspectorDock");
261 #ifndef WIN32
262   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
263   dockWidgetContents->setObjectName("dockWidgetContents");
264   memoryInspectorDock->setWidget(dockWidgetContents);
265 #endif
266   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
267   myDockWidgets[memoryInspectorDock] = false; // hidden by default
268
269   // Setup the statusbar ...
270   pqProgressManager* progress_manager =
271     pqApplicationCore::instance()->getProgressManager();
272
273   // Progress bar/button management
274   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
275   progress_manager->addNonBlockableObject(aProgress);
276   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
277   
278   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
279                     aProgress,        SLOT(enableProgress(bool)));
280
281   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
282                     aProgress,        SLOT(setProgress(const QString&, int)));
283
284   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
285                     aProgress,        SLOT(enableAbort(bool)));
286
287   QObject::connect( aProgress,        SIGNAL(abortPressed()),
288                     progress_manager, SLOT(triggerAbort()));
289
290   desk->statusBar()->addPermanentWidget(aProgress);
291   aProgress->setEnabled(true);
292
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);
296   
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();
306 }
307
308 /*!
309   \brief Save states of dockable ParaView widgets.
310 */
311 void PVGUI_Module::saveDockWidgetsState()
312 {
313   SUIT_Desktop* desk = application()->desktop();
314
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");
319   //
320   //for (int i = 0; i < myDockWidgets.size(); ++i)
321   //  myDockWidgets.at(i)->setParent(0);
322   // ... and replaced - manually hide dock windows
323
324   // store dock widgets visibility state and hide'em all
325   QMapIterator<QWidget*, bool> it1( myDockWidgets );
326   while( it1.hasNext() ) {
327     it1.next();
328     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
329     myDockWidgets[dw] = dw->isVisible();
330     dw->setVisible( false );
331     dw->toggleViewAction()->setVisible( false );
332   }
333   // store toolbar breaks state and remove all tollbar breaks 
334   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
335   while( it2.hasNext() ) {
336     it2.next();
337     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
338     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
339     if ( myToolbarBreaks[tb] )
340       desk->removeToolBarBreak( tb );
341   }
342   // store toolbars visibility state and hide'em all
343   QMapIterator<QWidget*, bool> it3( myToolbars );
344   while( it3.hasNext() ) {
345     it3.next();
346     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
347     myToolbars[tb] = tb->isVisible();
348     tb->setVisible( false );
349     tb->toggleViewAction()->setVisible( false );
350   }
351 }
352
353 /*!
354   \brief Restore states of dockable ParaView widgets.
355 */
356 void PVGUI_Module::restoreDockWidgetsState()
357 {
358   SUIT_Desktop* desk = application()->desktop();
359
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);
364   //
365   // Restore the state of the window ...
366   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
367   // ... and replaced - manually hide dock windows
368
369   // restore dock widgets visibility state
370   QMapIterator<QWidget*, bool> it1( myDockWidgets );
371   while( it1.hasNext() ) {
372     it1.next();
373     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
374     dw->setVisible( it1.value() );
375     dw->toggleViewAction()->setVisible( true );
376   }
377   // restore toolbar breaks state
378   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
379   while( it2.hasNext() ) {
380     it2.next();
381     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
382     if ( myToolbarBreaks[tb] )
383       desk->insertToolBarBreak( tb );
384   }
385   // restore toolbar visibility state
386   QMapIterator<QWidget*, bool> it3( myToolbars );
387   while( it3.hasNext() ) {
388     it3.next();
389     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
390     tb->setVisible( it3.value() );
391     tb->toggleViewAction()->setVisible( true );
392   }
393 }
394
395
396
397 /*!
398   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
399 */
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.
407   //
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 
411   //     this method.
412
413   SalomeApp_Application* anApp = getApp();
414   if(!anApp)
415     return;
416
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);
421     if(wg) {
422       QDockWidget* dock = 0;
423       QWidget* w = wg->parentWidget();
424       while ( w && !dock ) {
425         dock = ::qobject_cast<QDockWidget*>( w );
426         w = w->parentWidget();
427       }
428       if(dock){
429         if(!myCommonMap.contains(i)){
430           myCommonMap.insert(i,dock->isVisible());
431         } else {
432           myCommonMap[i] = dock->isVisible();
433         }
434       }
435     }
436   }
437 }
438
439 /*!
440   \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
441 */
442 void PVGUI_Module::restoreCommonWindowsState() {
443   SalomeApp_Application* anApp = getApp();
444   if(!anApp)
445     return;
446   DockWindowMap::const_iterator it = myCommonMap.begin();
447   for( ;it != myCommonMap.end(); it++ ) {
448     QWidget* wg = anApp->getWindow(it.key());
449     if(wg) {
450       QDockWidget* dock = 0;
451       QWidget* w = wg->parentWidget();
452       while ( w && !dock ) {
453         dock = ::qobject_cast<QDockWidget*>( w );
454         w = w->parentWidget();
455       }
456       if(dock) {
457         dock->setVisible(it.value());
458       }
459     }
460   }
461 }