Salome HOME
152f7dbf47af449cd487a057c8f4a084b08f33f9
[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 <pqDisplayProxyEditorWidget.h>
58 #include <pqPropertiesPanel.h>
59
60 #include <pqApplicationCore.h>
61 #include <pqPluginManager.h>
62 #include <pqParaViewMenuBuilders.h>
63 #include <pqCollaborationPanel.h>
64 #include <pqMemoryInspectorPanel.h>
65 #include <pqColorMapEditor.h>
66 #include <pqDeleteReaction.h>
67
68 class ResizeHelper : public pqPVAnimationWidget
69 {
70   // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
71   // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
72   // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
73   // THIS BUG IS NATURALLY FIXED BY ADDING 
74   //      this->updateGeometries();
75   // TO THE
76   //     void pqAnimationWidget::resizeEvent(QResizeEvent* e);
77   // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
78   // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
79
80 public:
81   ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
82 protected:
83   void resizeEvent(QResizeEvent* e)
84   {
85     pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
86     if ( w ) { 
87       QShowEvent e;
88       QApplication::sendEvent( w, &e );
89     }
90     pqPVAnimationWidget::resizeEvent( e );
91   }
92 };
93
94 /*!
95   \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
96   ParaView pqMainWindowCore class is fully responsible for these dock widgets' contents.
97   ==> To update this function, see the reference set up of ParaView in Application/Paraview/ParaviewMainWindow.ui
98 */
99 void PVGUI_Module::setupDockWidgets()
100 {
101   SUIT_Desktop* desk = application()->desktop();
102  
103   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
104   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
105
106   // Pipeline
107   QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
108   pipelineBrowserDock->setObjectName("pipelineBrowserDock");
109   pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
110   desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
111   pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
112   pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
113   pipelineBrowserDock->setWidget(browser);
114   myDockWidgets[pipelineBrowserDock] = true;
115
116   // Properties dock (previously called OBJECT_INSPECTOR)
117   QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
118   propertiesDock->setObjectName("propertiesDock");
119   propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
120   desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
121
122   pqPropertiesPanel* propertiesPanel = new pqPropertiesPanel(propertiesDock);
123   propertiesDock->setObjectName("propertiesPanel");
124   propertiesDock->setWidget(propertiesPanel);
125   connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ),  this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
126   //            hook delete to pqDeleteReaction.
127   QAction* tempDeleteAction = new QAction(this);
128   pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
129   handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
130
131   myDockWidgets[propertiesDock] = true;
132
133   //Display Dock
134 //  QDockWidget* displayDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
135 //  displayDock->setObjectName("displayDock");
136 //  QWidget* displayWidgetFrame = new QWidget(displayDock);
137 //  displayWidgetFrame->setObjectName("displayWidgetFrame");
138 //  displayDock->setWidget(displayWidgetFrame);
139 //
140 //  QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
141 //  displayScrollArea->setObjectName("displayScrollArea");
142 //  displayScrollArea->setWidgetResizable(true);
143 //
144 //  QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
145 //  verticalLayout->setSpacing(0);
146 //  verticalLayout->setContentsMargins(0, 0, 0, 0);
147 //
148 //  pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
149 //  displayWidget->setObjectName("displayWidget");
150 //  displayScrollArea->setWidget(displayWidget);
151 //  verticalLayout->addWidget(displayScrollArea);
152 //
153 //  myDockWidgets[displayDock] = true;
154
155   // information dock
156   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
157   informationDock->setObjectName("informationDock");
158
159   QWidget* informationWidgetFrame = new QWidget(informationDock);
160   informationWidgetFrame->setObjectName("informationWidgetFrame");
161   
162   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
163   verticalLayout_2->setSpacing(0);
164   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
165
166   QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
167   informationScrollArea->setObjectName("informationScrollArea") ;
168   informationScrollArea->setWidgetResizable(true);
169
170   pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
171   informationWidget->setObjectName("informationWidget");
172   informationWidget->setGeometry(QRect(0, 0, 77, 214));
173   informationScrollArea->setWidget(informationWidget);
174
175   verticalLayout_2->addWidget(informationScrollArea);
176   informationDock->setWidget(informationWidgetFrame);
177
178   myDockWidgets[informationDock] = true;
179
180   desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
181   desk->tabifyDockWidget(propertiesDock, informationDock);
182   propertiesDock->raise();
183
184   // Statistic View
185   QDockWidget* statisticsViewDock  = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
186   statisticsViewDock->setObjectName("statisticsViewDock");
187   statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
188                                       Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
189   desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
190   pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
191   statisticsViewDock->setWidget(aStatWidget);
192   myDockWidgets[statisticsViewDock] = false; // hidden by default
193
194   //Animation view
195   QDockWidget* animationViewDock     = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
196   animationViewDock->setObjectName("animationViewDock");
197   desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
198   pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
199   animationViewDock->setWidget(animation_panel);
200   myDockWidgets[animationViewDock] = false; // hidden by default
201
202   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
203
204   // Selection inspector
205   QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
206   selectionDisplayDock->setObjectName("selectionInspectorDock");
207   selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
208   desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
209   pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
210   selectionDisplayDock->setWidget(aSelInspector);
211   myDockWidgets[selectionDisplayDock] = false; // hidden by default
212
213   // Multi-block inspector
214   QDockWidget* multiBlockInspectorPanelDock  = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
215   multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
216   desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
217   pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
218   multiBlockInspectorPanelDock->setWidget(mbi_panel);
219   myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
220
221   // Comparative View
222   QDockWidget* comparativePanelDock  = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
223   comparativePanelDock->setObjectName("comparativePanelDock");
224   desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
225   pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
226   comparativePanelDock->setWidget(cv_panel);
227   myDockWidgets[comparativePanelDock] = false; // hidden by default
228
229   // Collaboration view
230   QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
231   collaborationPanelDock->setObjectName("collaborationPanelDock");
232   pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
233   collaborationPanel->setObjectName("collaborationPanel");
234   collaborationPanelDock->setWidget(collaborationPanel);
235   desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
236   myDockWidgets[collaborationPanelDock] = false; // hidden by default
237
238   // Color map editor
239   QDockWidget* colorMapEditorDock  = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
240   colorMapEditorDock->setObjectName("colorMapEditorDock");
241   desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
242   pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
243   colorMapEditorDock->setWidget(cmed_panel);
244   myDockWidgets[colorMapEditorDock] = false; // hidden by default
245
246   // Provide access to the color-editor panel for the application.
247   pqApplicationCore::instance()->registerManager(
248     "COLOR_EDITOR_PANEL", colorMapEditorDock);
249   
250   // Memory inspector dock
251   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
252   memoryInspectorDock->setObjectName("memoryInspectorDock");
253 #ifndef WIN32
254   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
255   dockWidgetContents->setObjectName("dockWidgetContents");
256   memoryInspectorDock->setWidget(dockWidgetContents);
257 #endif
258   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
259   myDockWidgets[memoryInspectorDock] = false; // hidden by default
260
261   // Setup the statusbar ...
262   pqProgressManager* progress_manager =
263     pqApplicationCore::instance()->getProgressManager();
264
265   // Progress bar/button management
266   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
267   progress_manager->addNonBlockableObject(aProgress);
268   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
269   
270   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
271                     aProgress,        SLOT(enableProgress(bool)));
272
273   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
274                     aProgress,        SLOT(setProgress(const QString&, int)));
275
276   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
277                     aProgress,        SLOT(enableAbort(bool)));
278
279   QObject::connect( aProgress,        SIGNAL(abortPressed()),
280                     progress_manager, SLOT(triggerAbort()));
281
282   desk->statusBar()->addPermanentWidget(aProgress);
283   aProgress->setEnabled(true);
284
285   // Set up the dock window corners to give the vertical docks more room.
286   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
287   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
288
289   // Setup the default dock configuration ...
290   statisticsViewDock->hide();
291   comparativePanelDock->hide();
292   animationViewDock->hide();
293   multiBlockInspectorPanelDock->hide();
294   selectionDisplayDock->hide();
295   collaborationPanelDock->hide();
296   memoryInspectorDock->hide();
297   colorMapEditorDock->hide();
298 }
299
300 /*!
301   \brief Save states of dockable ParaView widgets.
302 */
303 void PVGUI_Module::saveDockWidgetsState()
304 {
305   SUIT_Desktop* desk = application()->desktop();
306
307   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
308   // ... the following code is commented...
309   // Save the state of the window ...
310   // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
311   //
312   //for (int i = 0; i < myDockWidgets.size(); ++i)
313   //  myDockWidgets.at(i)->setParent(0);
314   // ... and replaced - manually hide dock windows
315
316   // store dock widgets visibility state and hide'em all
317   QMapIterator<QWidget*, bool> it1( myDockWidgets );
318   while( it1.hasNext() ) {
319     it1.next();
320     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
321     myDockWidgets[dw] = dw->isVisible();
322     dw->setVisible( false );
323     dw->toggleViewAction()->setVisible( false );
324   }
325   // store toolbar breaks state and remove all tollbar breaks 
326   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
327   while( it2.hasNext() ) {
328     it2.next();
329     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
330     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
331     if ( myToolbarBreaks[tb] )
332       desk->removeToolBarBreak( tb );
333   }
334   // store toolbars visibility state and hide'em all
335   QMapIterator<QWidget*, bool> it3( myToolbars );
336   while( it3.hasNext() ) {
337     it3.next();
338     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
339     myToolbars[tb] = tb->isVisible();
340     tb->setVisible( false );
341     tb->toggleViewAction()->setVisible( false );
342   }
343 }
344
345 /*!
346   \brief Restore states of dockable ParaView widgets.
347 */
348 void PVGUI_Module::restoreDockWidgetsState()
349 {
350   SUIT_Desktop* desk = application()->desktop();
351
352   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
353   // ... the following code is commented...
354   //for (int i = 0; i < myDockWidgets.size(); ++i)
355   //  myDockWidgets.at(i)->setParent(desk);
356   //
357   // Restore the state of the window ...
358   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
359   // ... and replaced - manually hide dock windows
360
361   // restore dock widgets visibility state
362   QMapIterator<QWidget*, bool> it1( myDockWidgets );
363   while( it1.hasNext() ) {
364     it1.next();
365     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
366     dw->setVisible( it1.value() );
367     dw->toggleViewAction()->setVisible( true );
368   }
369   // restore toolbar breaks state
370   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
371   while( it2.hasNext() ) {
372     it2.next();
373     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
374     if ( myToolbarBreaks[tb] )
375       desk->insertToolBarBreak( tb );
376   }
377   // restore toolbar visibility state
378   QMapIterator<QWidget*, bool> it3( myToolbars );
379   while( it3.hasNext() ) {
380     it3.next();
381     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
382     tb->setVisible( it3.value() );
383     tb->toggleViewAction()->setVisible( true );
384   }
385 }
386
387
388
389 /*!
390   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
391 */
392 void PVGUI_Module::storeCommonWindowsState() {  
393   //rnv: Make behaviour of the dockable windows and toolbars coherent with others
394   //     modules: if 'Save position of the windows' or 'Save position of the toolbars' 
395   //     in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
396   //     are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
397   //     Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
398   //     configuration file.
399   //
400   //     But in contrast to others modules ParaVis module default settings hide some dockable
401   //     windows, so to restore it at the moment of the ParaVis de-activation we call 
402   //     restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call 
403   //     this method.
404
405   SalomeApp_Application* anApp = getApp();
406   if(!anApp)
407     return;
408
409   int begin = SalomeApp_Application::WT_ObjectBrowser;
410   int end = SalomeApp_Application::WT_NoteBook;
411   for( int i = begin; i <= end; i++ ) {
412     QWidget* wg = anApp->getWindow(i);
413     if(wg) {
414       QDockWidget* dock = 0;
415       QWidget* w = wg->parentWidget();
416       while ( w && !dock ) {
417         dock = ::qobject_cast<QDockWidget*>( w );
418         w = w->parentWidget();
419       }
420       if(dock){
421         if(!myCommonMap.contains(i)){
422           myCommonMap.insert(i,dock->isVisible());
423         } else {
424           myCommonMap[i] = dock->isVisible();
425         }
426       }
427     }
428   }
429 }
430
431 /*!
432   \brief Restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
433 */
434 void PVGUI_Module::restoreCommonWindowsState() {
435   SalomeApp_Application* anApp = getApp();
436   if(!anApp)
437     return;
438   DockWindowMap::const_iterator it = myCommonMap.begin();
439   for( ;it != myCommonMap.end(); it++ ) {
440     QWidget* wg = anApp->getWindow(it.key());
441     if(wg) {
442       QDockWidget* dock = 0;
443       QWidget* w = wg->parentWidget();
444       while ( w && !dock ) {
445         dock = ::qobject_cast<QDockWidget*>( w );
446         w = w->parentWidget();
447       }
448       if(dock) {
449         dock->setVisible(it.value());
450       }
451     }
452   }
453 }