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