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