Salome HOME
Update copyrights 2014.
[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 <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>
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
81 class ResizeHelper : public pqPVAnimationWidget
82 {
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();
88   // TO THE
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
92
93 public:
94   ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
95 protected:
96   void resizeEvent(QResizeEvent* e)
97   {
98     pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
99     if ( w ) { 
100       QShowEvent e;
101       QApplication::sendEvent( w, &e );
102     }
103     pqPVAnimationWidget::resizeEvent( e );
104   }
105 };
106
107 /*!
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.
110 */
111 void PVGUI_Module::setupDockWidgets()
112 {
113   SUIT_Desktop* desk = application()->desktop();
114  
115   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
116   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
117
118   // Pipeline
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;
127
128   //Object inspector
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 );
133
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;
140
141   //Display Dock
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);
147
148   QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
149   displayScrollArea->setObjectName("displayScrollArea");
150   displayScrollArea->setWidgetResizable(true);
151
152   QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
153   verticalLayout->setSpacing(0);
154   verticalLayout->setContentsMargins(0, 0, 0, 0);
155
156   pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
157   displayWidget->setObjectName("displayWidget");
158   displayScrollArea->setWidget(displayWidget);
159   verticalLayout->addWidget(displayScrollArea);
160
161   myDockWidgets[displayDock] = true;
162
163   // information dock
164   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
165   informationDock->setObjectName("informationDock");
166
167   QWidget* informationWidgetFrame = new QWidget(informationDock);
168   informationWidgetFrame->setObjectName("informationWidgetFrame");
169   
170   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
171   verticalLayout_2->setSpacing(0);
172   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
173
174   QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
175   informationScrollArea->setObjectName("informationScrollArea") ;
176   informationScrollArea->setWidgetResizable(true);
177
178   pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
179   informationWidget->setObjectName("informationWidget");
180   informationWidget->setGeometry(QRect(0, 0, 77, 214));
181   informationScrollArea->setWidget(informationWidget);
182
183   verticalLayout_2->addWidget(informationScrollArea);
184   informationDock->setWidget(informationWidgetFrame);
185
186   myDockWidgets[informationDock] = true;
187
188   desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
189   desk->tabifyDockWidget(objectInspectorDock, displayDock);
190   desk->tabifyDockWidget(objectInspectorDock, informationDock);
191   objectInspectorDock->raise();
192
193
194   // Statistic View
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
203
204   //Animation view
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
211
212   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
213
214   // Selection view
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
222
223   // Comparative View
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
230
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
239   
240   // Memory inspector dock
241   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
242   memoryInspectorDock->setObjectName("memoryInspectorDock");
243 #ifndef WIN32
244   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
245   dockWidgetContents->setObjectName("dockWidgetContents");
246   memoryInspectorDock->setWidget(dockWidgetContents);
247 #endif
248   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
249   myDockWidgets[memoryInspectorDock] = false; // hidden by default
250
251   // Setup the statusbar ...
252   pqProgressManager* progress_manager =
253     pqApplicationCore::instance()->getProgressManager();
254
255   // Progress bar/button management
256   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
257   progress_manager->addNonBlockableObject(aProgress);
258   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
259   
260   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
261                     aProgress,        SLOT(enableProgress(bool)));
262
263   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
264                     aProgress,        SLOT(setProgress(const QString&, int)));
265
266   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
267                     aProgress,        SLOT(enableAbort(bool)));
268
269   QObject::connect( aProgress,        SIGNAL(abortPressed()),
270                     progress_manager, SLOT(triggerAbort()));
271
272   desk->statusBar()->addPermanentWidget(aProgress);
273   aProgress->setEnabled(true);
274
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);
278   
279   // Setup the default dock configuration ...
280   statisticsViewDock->hide();
281   comparativePanelDock->hide();
282   animationViewDock->hide();
283   selectionInspectorDock->hide();
284   collaborationPanelDock->hide();
285   memoryInspectorDock->hide();
286 }
287
288 /*!
289   \brief Save states of dockable ParaView widgets.
290 */
291 void PVGUI_Module::saveDockWidgetsState()
292 {
293   SUIT_Desktop* desk = application()->desktop();
294
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");
299   //
300   //for (int i = 0; i < myDockWidgets.size(); ++i)
301   //  myDockWidgets.at(i)->setParent(0);
302   // ... and replaced - manually hide dock windows
303
304   // store dock widgets visibility state and hide'em all
305   QMapIterator<QWidget*, bool> it1( myDockWidgets );
306   while( it1.hasNext() ) {
307     it1.next();
308     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
309     myDockWidgets[dw] = dw->isVisible();
310     dw->setVisible( false );
311     dw->toggleViewAction()->setVisible( false );
312   }
313   // store toolbar breaks state and remove all tollbar breaks 
314   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
315   while( it2.hasNext() ) {
316     it2.next();
317     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
318     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
319     if ( myToolbarBreaks[tb] )
320       desk->removeToolBarBreak( tb );
321   }
322   // store toolbars visibility state and hide'em all
323   QMapIterator<QWidget*, bool> it3( myToolbars );
324   while( it3.hasNext() ) {
325     it3.next();
326     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
327     myToolbars[tb] = tb->isVisible();
328     tb->setVisible( false );
329     tb->toggleViewAction()->setVisible( false );
330   }
331 }
332
333 /*!
334   \brief Restore states of dockable ParaView widgets.
335 */
336 void PVGUI_Module::restoreDockWidgetsState()
337 {
338   SUIT_Desktop* desk = application()->desktop();
339
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);
344   //
345   // Restore the state of the window ...
346   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
347   // ... and replaced - manually hide dock windows
348
349   // restore dock widgets visibility state
350   QMapIterator<QWidget*, bool> it1( myDockWidgets );
351   while( it1.hasNext() ) {
352     it1.next();
353     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
354     dw->setVisible( it1.value() );
355     dw->toggleViewAction()->setVisible( true );
356   }
357   // restore toolbar breaks state
358   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
359   while( it2.hasNext() ) {
360     it2.next();
361     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
362     if ( myToolbarBreaks[tb] )
363       desk->insertToolBarBreak( tb );
364   }
365   // restore toolbar visibility state
366   QMapIterator<QWidget*, bool> it3( myToolbars );
367   while( it3.hasNext() ) {
368     it3.next();
369     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
370     tb->setVisible( it3.value() );
371     tb->toggleViewAction()->setVisible( true );
372   }
373 }
374
375
376
377 /*!
378   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
379 */
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.
387   //
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 
391   //     this method.
392
393   SalomeApp_Application* anApp = getApp();
394   if(!anApp)
395     return;
396
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);
401     if(wg) {
402       QDockWidget* dock = 0;
403       QWidget* w = wg->parentWidget();
404       while ( w && !dock ) {
405         dock = ::qobject_cast<QDockWidget*>( w );
406         w = w->parentWidget();
407       }
408       if(dock){
409         if(!myCommonMap.contains(i)){
410           myCommonMap.insert(i,dock->isVisible());
411         } else {
412           myCommonMap[i] = dock->isVisible();
413         }
414       }
415     }
416   }
417 }
418
419 /*!
420   \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
421 */
422 void PVGUI_Module::restoreCommonWindowsState() {
423   SalomeApp_Application* anApp = getApp();
424   if(!anApp)
425     return;
426   DockWindowMap::const_iterator it = myCommonMap.begin();
427   for( ;it != myCommonMap.end(); it++ ) {
428     QWidget* wg = anApp->getWindow(it.key());
429     if(wg) {
430       QDockWidget* dock = 0;
431       QWidget* w = wg->parentWidget();
432       while ( w && !dock ) {
433         dock = ::qobject_cast<QDockWidget*>( w );
434         w = w->parentWidget();
435       }
436       if(dock) {
437         dock->setVisible(it.value());
438       }
439     }
440   }
441 }