Salome HOME
Rollback changes related to the "0022226: [CEA 825] "Display" and "Properties" panels...
[modules/paravis.git] / src / PVGUI / PVGUI_Module_widgets.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2013  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.
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   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
248
249   // Setup the statusbar ...
250   pqProgressManager* progress_manager =
251     pqApplicationCore::instance()->getProgressManager();
252
253   // Progress bar/button management
254   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
255   progress_manager->addNonBlockableObject(aProgress);
256   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
257   
258   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
259                     aProgress,        SLOT(enableProgress(bool)));
260
261   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
262                     aProgress,        SLOT(setProgress(const QString&, int)));
263
264   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
265                     aProgress,        SLOT(enableAbort(bool)));
266
267   QObject::connect( aProgress,        SIGNAL(abortPressed()),
268                     progress_manager, SLOT(triggerAbort()));
269
270   desk->statusBar()->addPermanentWidget(aProgress);
271   aProgress->setEnabled(true);
272
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);
276   
277   // Setup the default dock configuration ...
278   statisticsViewDock->hide();
279   comparativePanelDock->hide();
280   animationViewDock->hide();
281   selectionInspectorDock->hide();
282   collaborationPanelDock->hide();
283   memoryInspectorDock->hide();
284 }
285
286 /*!
287   \brief Save states of dockable ParaView widgets.
288 */
289 void PVGUI_Module::saveDockWidgetsState()
290 {
291   SUIT_Desktop* desk = application()->desktop();
292
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");
297   //
298   //for (int i = 0; i < myDockWidgets.size(); ++i)
299   //  myDockWidgets.at(i)->setParent(0);
300   // ... and replaced - manually hide dock windows
301
302   // store dock widgets visibility state and hide'em all
303   QMapIterator<QWidget*, bool> it1( myDockWidgets );
304   while( it1.hasNext() ) {
305     it1.next();
306     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
307     myDockWidgets[dw] = dw->isVisible();
308     dw->setVisible( false );
309     dw->toggleViewAction()->setVisible( false );
310   }
311   // store toolbar breaks state and remove all tollbar breaks 
312   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
313   while( it2.hasNext() ) {
314     it2.next();
315     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
316     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
317     if ( myToolbarBreaks[tb] )
318       desk->removeToolBarBreak( tb );
319   }
320   // store toolbars visibility state and hide'em all
321   QMapIterator<QWidget*, bool> it3( myToolbars );
322   while( it3.hasNext() ) {
323     it3.next();
324     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
325     myToolbars[tb] = tb->isVisible();
326     tb->setVisible( false );
327     tb->toggleViewAction()->setVisible( false );
328   }
329 }
330
331 /*!
332   \brief Restore states of dockable ParaView widgets.
333 */
334 void PVGUI_Module::restoreDockWidgetsState()
335 {
336   SUIT_Desktop* desk = application()->desktop();
337
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);
342   //
343   // Restore the state of the window ...
344   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
345   // ... and replaced - manually hide dock windows
346
347   // restore dock widgets visibility state
348   QMapIterator<QWidget*, bool> it1( myDockWidgets );
349   while( it1.hasNext() ) {
350     it1.next();
351     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
352     dw->setVisible( it1.value() );
353     dw->toggleViewAction()->setVisible( true );
354   }
355   // restore toolbar breaks state
356   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
357   while( it2.hasNext() ) {
358     it2.next();
359     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
360     if ( myToolbarBreaks[tb] )
361       desk->insertToolBarBreak( tb );
362   }
363   // restore toolbar visibility state
364   QMapIterator<QWidget*, bool> it3( myToolbars );
365   while( it3.hasNext() ) {
366     it3.next();
367     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
368     tb->setVisible( it3.value() );
369     tb->toggleViewAction()->setVisible( true );
370   }
371 }
372
373
374
375 /*!
376   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
377 */
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.
385   //
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 
389   //     this method.
390
391   SalomeApp_Application* anApp = getApp();
392   if(!anApp)
393     return;
394
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);
399     if(wg) {
400       QDockWidget* dock = 0;
401       QWidget* w = wg->parentWidget();
402       while ( w && !dock ) {
403         dock = ::qobject_cast<QDockWidget*>( w );
404         w = w->parentWidget();
405       }
406       if(dock){
407         if(!myCommonMap.contains(i)){
408           myCommonMap.insert(i,dock->isVisible());
409         } else {
410           myCommonMap[i] = dock->isVisible();
411         }
412       }
413     }
414   }
415 }
416
417 /*!
418   \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
419 */
420 void PVGUI_Module::restoreCommonWindowsState() {
421   SalomeApp_Application* anApp = getApp();
422   if(!anApp)
423     return;
424   DockWindowMap::const_iterator it = myCommonMap.begin();
425   for( ;it != myCommonMap.end(); it++ ) {
426     QWidget* wg = anApp->getWindow(it.key());
427     if(wg) {
428       QDockWidget* dock = 0;
429       QWidget* w = wg->parentWidget();
430       while ( w && !dock ) {
431         dock = ::qobject_cast<QDockWidget*>( w );
432         w = w->parentWidget();
433       }
434       if(dock) {
435         dock->setVisible(it.value());
436       }
437     }
438   }
439 }