Salome HOME
Re-wrote PARAVIS CORBA engine
[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   // Provide access to the color-editor panel for the application.
258   pqApplicationCore::instance()->registerManager(
259     "COLOR_EDITOR_PANEL", colorMapEditorDock);
260   
261   // Memory inspector dock
262   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
263   memoryInspectorDock->setObjectName("memoryInspectorDock");
264 #ifndef WIN32
265   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
266   dockWidgetContents->setObjectName("dockWidgetContents");
267   memoryInspectorDock->setWidget(dockWidgetContents);
268 #endif
269   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
270   myDockWidgets[memoryInspectorDock] = false; // hidden by default
271
272   // Setup the statusbar ...
273   pqProgressManager* progress_manager =
274     pqApplicationCore::instance()->getProgressManager();
275
276   // Progress bar/button management
277   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
278   progress_manager->addNonBlockableObject(aProgress);
279   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
280   
281   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
282                     aProgress,        SLOT(enableProgress(bool)));
283
284   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
285                     aProgress,        SLOT(setProgress(const QString&, int)));
286
287   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
288                     aProgress,        SLOT(enableAbort(bool)));
289
290   QObject::connect( aProgress,        SIGNAL(abortPressed()),
291                     progress_manager, SLOT(triggerAbort()));
292
293   desk->statusBar()->addPermanentWidget(aProgress);
294   aProgress->setEnabled(true);
295
296   // Set up the dock window corners to give the vertical docks more room.
297   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
298   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
299   
300   // Setup the default dock configuration ...
301   statisticsViewDock->hide();
302   comparativePanelDock->hide();
303   animationViewDock->hide();
304   multiBlockInspectorPanelDock->hide();
305   selectionDisplayDock->hide();
306   collaborationPanelDock->hide();
307   memoryInspectorDock->hide();
308   colorMapEditorDock->hide();
309 }
310
311 /*!
312   \brief Save states of dockable ParaView widgets.
313 */
314 void PVGUI_Module::saveDockWidgetsState()
315 {
316   SUIT_Desktop* desk = application()->desktop();
317
318   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
319   // ... the following code is commented...
320   // Save the state of the window ...
321   // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
322   //
323   //for (int i = 0; i < myDockWidgets.size(); ++i)
324   //  myDockWidgets.at(i)->setParent(0);
325   // ... and replaced - manually hide dock windows
326
327   // store dock widgets visibility state and hide'em all
328   QMapIterator<QWidget*, bool> it1( myDockWidgets );
329   while( it1.hasNext() ) {
330     it1.next();
331     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
332     myDockWidgets[dw] = dw->isVisible();
333     dw->setVisible( false );
334     dw->toggleViewAction()->setVisible( false );
335   }
336   // store toolbar breaks state and remove all tollbar breaks 
337   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
338   while( it2.hasNext() ) {
339     it2.next();
340     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
341     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
342     if ( myToolbarBreaks[tb] )
343       desk->removeToolBarBreak( tb );
344   }
345   // store toolbars visibility state and hide'em all
346   QMapIterator<QWidget*, bool> it3( myToolbars );
347   while( it3.hasNext() ) {
348     it3.next();
349     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
350     myToolbars[tb] = tb->isVisible();
351     tb->setVisible( false );
352     tb->toggleViewAction()->setVisible( false );
353   }
354 }
355
356 /*!
357   \brief Restore states of dockable ParaView widgets.
358 */
359 void PVGUI_Module::restoreDockWidgetsState()
360 {
361   SUIT_Desktop* desk = application()->desktop();
362
363   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
364   // ... the following code is commented...
365   //for (int i = 0; i < myDockWidgets.size(); ++i)
366   //  myDockWidgets.at(i)->setParent(desk);
367   //
368   // Restore the state of the window ...
369   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
370   // ... and replaced - manually hide dock windows
371
372   // restore dock widgets visibility state
373   QMapIterator<QWidget*, bool> it1( myDockWidgets );
374   while( it1.hasNext() ) {
375     it1.next();
376     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
377     dw->setVisible( it1.value() );
378     dw->toggleViewAction()->setVisible( true );
379   }
380
381     // restore toolbar breaks state
382     QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
383     while( it2.hasNext() ) {
384         it2.next();
385         QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
386         if ( myToolbarBreaks[tb] )
387           desk->insertToolBarBreak( tb );
388     }
389
390   // restore toolbar visibility state
391   QMapIterator<QWidget*, bool> it3( myToolbars );
392   while( it3.hasNext() ) {
393     it3.next();
394     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
395     tb->setVisible( it3.value() );
396     tb->toggleViewAction()->setVisible( true );
397   }
398 }
399
400
401
402 /*!
403   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
404 */
405 void PVGUI_Module::storeCommonWindowsState() {  
406   //rnv: Make behaviour of the dockable windows and toolbars coherent with others
407   //     modules: if 'Save position of the windows' or 'Save position of the toolbars' 
408   //     in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
409   //     are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
410   //     Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
411   //     configuration file.
412   //
413   //     But in contrast to others modules ParaVis module default settings hide some dockable
414   //     windows, so to restore it at the moment of the ParaVis de-activation we call 
415   //     restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call 
416   //     this method.
417
418   SalomeApp_Application* anApp = getApp();
419   if(!anApp)
420     return;
421
422   int begin = SalomeApp_Application::WT_ObjectBrowser;
423   int end = SalomeApp_Application::WT_NoteBook;
424   for( int i = begin; i <= end; i++ ) {
425     QWidget* wg = anApp->getWindow(i);
426     if(wg) {
427       QDockWidget* dock = 0;
428       QWidget* w = wg->parentWidget();
429       while ( w && !dock ) {
430           dock = ::qobject_cast<QDockWidget*>( w );
431           w = w->parentWidget();
432       }
433       if(dock){
434           if(!myCommonMap.contains(i)){
435               myCommonMap.insert(i,dock->isVisible());
436           } else {
437               myCommonMap[i] = dock->isVisible();
438           }
439       }
440     }
441   }
442 }
443
444 /*!
445   \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
446 */
447 void PVGUI_Module::restoreCommonWindowsState() {
448   SalomeApp_Application* anApp = getApp();
449   if(!anApp)
450     return;
451   DockWindowMap::const_iterator it = myCommonMap.begin();
452   for( ;it != myCommonMap.end(); it++ ) {
453     QWidget* wg = anApp->getWindow(it.key());
454     if(wg) {
455       QDockWidget* dock = 0;
456       QWidget* w = wg->parentWidget();
457       while ( w && !dock ) {
458           dock = ::qobject_cast<QDockWidget*>( w );
459           w = w->parentWidget();
460       }
461       if(dock) {
462           dock->setVisible(it.value());
463       }
464     }
465   }
466 }