]> SALOME platform Git repositories - modules/paravis.git/blob - src/PVGUI/PVGUI_Module_widgets.cxx
Salome HOME
Moving resources to GUI.
[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
119   // Properties dock (previously called OBJECT_INSPECTOR)
120   QDockWidget* propertiesDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
121   propertiesDock->setObjectName("propertiesDock");
122   propertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea );
123   desk->addDockWidget( Qt::LeftDockWidgetArea, propertiesDock );
124
125   pqPropertiesPanel* propertiesPanel = guiElements->getPropertiesPanel();
126   propertiesDock->setWidget(propertiesPanel);
127   connect( propertiesPanel, SIGNAL( helpRequested(const QString&, const QString&) ),  this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
128   //            hook delete to pqDeleteReaction.
129   QAction* tempDeleteAction = new QAction(this);
130   pqDeleteReaction* handler = new pqDeleteReaction(tempDeleteAction);
131   handler->connect(propertiesPanel, SIGNAL(deleteRequested(pqPipelineSource*)), SLOT(deleteSource(pqPipelineSource*)));
132
133   myDockWidgets[propertiesDock] = true;
134
135   // Information dock
136   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
137   informationDock->setObjectName("informationDock");
138
139   QWidget* informationWidgetFrame = new QWidget(informationDock);
140   informationWidgetFrame->setObjectName("informationWidgetFrame");
141
142   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
143   verticalLayout_2->setSpacing(0);
144   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
145
146   QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
147   informationScrollArea->setObjectName("informationScrollArea") ;
148   informationScrollArea->setWidgetResizable(true);
149
150   pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
151   informationWidget->setObjectName("informationWidget");
152   informationWidget->setGeometry(QRect(0, 0, 77, 214));
153   informationScrollArea->setWidget(informationWidget);
154
155   verticalLayout_2->addWidget(informationScrollArea);
156   informationDock->setWidget(informationWidgetFrame);
157
158   myDockWidgets[informationDock] = true;
159
160
161   desk->tabifyDockWidget(informationDock, propertiesDock);
162   desk->tabifyDockWidget(propertiesDock, pipelineBrowserDock);
163   //propertiesDock->raise();
164
165   // Statistic View
166   QDockWidget* statisticsViewDock  = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
167   statisticsViewDock->setObjectName("statisticsViewDock");
168   statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
169                                       Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
170   desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
171   pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
172   statisticsViewDock->setWidget(aStatWidget);
173   myDockWidgets[statisticsViewDock] = false; // hidden by default
174
175   //Animation view
176   QDockWidget* animationViewDock     = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
177   animationViewDock->setObjectName("animationViewDock");
178   desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
179   pqPVAnimationWidget* animation_panel = new pqPVAnimationWidget(animationViewDock); // [ABN] was resizeHelper
180   animationViewDock->setWidget(animation_panel);
181   myDockWidgets[animationViewDock] = false; // hidden by default
182
183   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
184
185   // Selection inspector
186   QDockWidget* selectionDisplayDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
187   selectionDisplayDock->setObjectName("selectionInspectorDock");
188   selectionDisplayDock->setAllowedAreas( Qt::AllDockWidgetAreas );
189   desk->addDockWidget( Qt::LeftDockWidgetArea, selectionDisplayDock );
190   pqFindDataSelectionDisplayFrame* aSelInspector = new pqFindDataSelectionDisplayFrame(selectionDisplayDock);
191   selectionDisplayDock->setWidget(aSelInspector);
192   myDockWidgets[selectionDisplayDock] = false; // hidden by default
193
194   // Multi-block inspector
195   QDockWidget* multiBlockInspectorPanelDock  = new QDockWidget( tr( "TTL_MUTLI_BLOCK_INSPECTOR" ), desk );
196   multiBlockInspectorPanelDock->setObjectName("multiBlockInspectorPanelDock");
197   desk->addDockWidget( Qt::LeftDockWidgetArea, multiBlockInspectorPanelDock );
198   pqMultiBlockInspectorPanel* mbi_panel = new pqMultiBlockInspectorPanel( multiBlockInspectorPanelDock );
199   multiBlockInspectorPanelDock->setWidget(mbi_panel);
200   myDockWidgets[multiBlockInspectorPanelDock] = false; // hidden by default
201
202   // Comparative View
203   QDockWidget* comparativePanelDock  = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
204   comparativePanelDock->setObjectName("comparativePanelDock");
205   desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
206   pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
207   comparativePanelDock->setWidget(cv_panel);
208   myDockWidgets[comparativePanelDock] = false; // hidden by default
209
210   // Collaboration view
211   QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
212   collaborationPanelDock->setObjectName("collaborationPanelDock");
213   pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
214   collaborationPanel->setObjectName("collaborationPanel");
215   collaborationPanelDock->setWidget(collaborationPanel);
216   desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
217   myDockWidgets[collaborationPanelDock] = false; // hidden by default
218
219   // Color map editor
220   QDockWidget* colorMapEditorDock  = new QDockWidget( tr( "TTL_COLOR_MAP_EDITOR" ), desk );
221   colorMapEditorDock->setObjectName("colorMapEditorDock");
222   desk->addDockWidget( Qt::LeftDockWidgetArea, colorMapEditorDock );
223   pqColorMapEditor* cmed_panel = new pqColorMapEditor( colorMapEditorDock );
224   colorMapEditorDock->setWidget(cmed_panel);
225   myDockWidgets[colorMapEditorDock] = false; // hidden by default
226
227   // Provide access to the color-editor panel for the application.
228   pqApplicationCore::instance()->registerManager(
229     "COLOR_EDITOR_PANEL", colorMapEditorDock);
230   
231   // Memory inspector dock
232   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
233   memoryInspectorDock->setObjectName("memoryInspectorDock");
234 #ifndef WIN32
235   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
236   dockWidgetContents->setObjectName("dockWidgetContents");
237   memoryInspectorDock->setWidget(dockWidgetContents);
238 #endif
239   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
240   myDockWidgets[memoryInspectorDock] = false; // hidden by default
241
242   // Setup the statusbar ...
243   pqProgressManager* progress_manager =
244     pqApplicationCore::instance()->getProgressManager();
245
246   // Progress bar/button management
247   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
248   progress_manager->addNonBlockableObject(aProgress);
249   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
250   
251   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
252                     aProgress,        SLOT(enableProgress(bool)));
253
254   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
255                     aProgress,        SLOT(setProgress(const QString&, int)));
256
257   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
258                     aProgress,        SLOT(enableAbort(bool)));
259
260   QObject::connect( aProgress,        SIGNAL(abortPressed()),
261                     progress_manager, SLOT(triggerAbort()));
262
263   desk->statusBar()->addPermanentWidget(aProgress);
264   aProgress->setEnabled(true);
265
266   // Set up the dock window corners to give the vertical docks more room.
267 //  desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
268 //  desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
269
270   // Setup the default dock configuration ...
271   statisticsViewDock->hide();
272   comparativePanelDock->hide();
273   animationViewDock->hide();
274   multiBlockInspectorPanelDock->hide();
275   selectionDisplayDock->hide();
276   collaborationPanelDock->hide();
277   memoryInspectorDock->hide();
278   colorMapEditorDock->hide();
279 }
280
281 /*!
282   \brief Save states of dockable ParaView widgets.
283 */
284 void PVGUI_Module::saveDockWidgetsState()
285 {
286   SUIT_Desktop* desk = application()->desktop();
287
288   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
289   // ... the following code is commented...
290   // Save the state of the window ...
291   // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
292   //
293   //for (int i = 0; i < myDockWidgets.size(); ++i)
294   //  myDockWidgets.at(i)->setParent(0);
295   // ... and replaced - manually hide dock windows
296
297   // store dock widgets visibility state and hide'em all
298   QMapIterator<QWidget*, bool> it1( myDockWidgets );
299   while( it1.hasNext() ) {
300     it1.next();
301     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
302     myDockWidgets[dw] = dw->isVisible();
303     dw->setVisible( false );
304     dw->toggleViewAction()->setVisible( false );
305   }
306   // store toolbar breaks state and remove all tollbar breaks 
307   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
308   while( it2.hasNext() ) {
309     it2.next();
310     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
311     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
312     if ( myToolbarBreaks[tb] )
313       desk->removeToolBarBreak( tb );
314   }
315   // store toolbars visibility state and hide'em all
316   QMapIterator<QWidget*, bool> it3( myToolbars );
317   while( it3.hasNext() ) {
318     it3.next();
319     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
320     myToolbars[tb] = tb->isVisible();
321     tb->setVisible( false );
322     tb->toggleViewAction()->setVisible( false );
323   }
324 }
325
326 /*!
327   \brief Restore states of dockable ParaView widgets.
328 */
329 void PVGUI_Module::restoreDockWidgetsState()
330 {
331   SUIT_Desktop* desk = application()->desktop();
332
333   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
334   // ... the following code is commented...
335   //for (int i = 0; i < myDockWidgets.size(); ++i)
336   //  myDockWidgets.at(i)->setParent(desk);
337   //
338   // Restore the state of the window ...
339   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
340   // ... and replaced - manually hide dock windows
341
342   // restore dock widgets visibility state
343   QMapIterator<QWidget*, bool> it1( myDockWidgets );
344   while( it1.hasNext() ) {
345     it1.next();
346     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
347     dw->setVisible( it1.value() );
348     dw->toggleViewAction()->setVisible( true );
349   }
350
351     // restore toolbar breaks state
352     QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
353     while( it2.hasNext() ) {
354         it2.next();
355         QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
356         if ( myToolbarBreaks[tb] )
357           desk->insertToolBarBreak( tb );
358     }
359
360   // restore toolbar visibility state
361   QMapIterator<QWidget*, bool> it3( myToolbars );
362   while( it3.hasNext() ) {
363     it3.next();
364     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
365     tb->setVisible( it3.value() );
366     tb->toggleViewAction()->setVisible( true );
367   }
368 }
369
370
371
372 /*!
373   \brief Store visibility of the common dockable windows (OB, PyConsole, ... etc.)
374 */
375 void PVGUI_Module::storeCommonWindowsState() {  
376   //rnv: Make behaviour of the dockable windows and toolbars coherent with others
377   //     modules: if 'Save position of the windows' or 'Save position of the toolbars' 
378   //     in the General SALOME preferences are cheked, then properties of the windows and/or toolbars
379   //     are stored/restored using standard Qt saveState(...) and restoreState(...) methods.
380   //     Otherwise to the windows and toolbars applied default settins stored int the SalomeApp.xml
381   //     configuration file.
382   //
383   //     But in contrast to others modules ParaVis module default settings hide some dockable
384   //     windows, so to restore it at the moment of the ParaVis de-activation we call 
385   //     restoreCommonWindowsState() method, and at the moment of the ParaVis activation we call 
386   //     this method.
387
388   //LightApp_Application* anApp = getApp();
389   SalomeApp_Application* anApp = getApp();
390   if(!anApp)
391     return;
392
393 //  int begin = SalomeApp_Application::WT_ObjectBrowser;
394 //  int end = SalomeApp_Application::WT_NoteBook;
395   int begin = LightApp_Application::WT_ObjectBrowser;
396   int end = LightApp_Application::WT_User;
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 //  LightApp_Application* anApp = getApp();
423   if(!anApp)
424     return;
425   DockWindowMap::const_iterator it = myCommonMap.begin();
426   for( ;it != myCommonMap.end(); it++ ) {
427     QWidget* wg = anApp->getWindow(it.key());
428     if(wg) {
429       QDockWidget* dock = 0;
430       QWidget* w = wg->parentWidget();
431       while ( w && !dock ) {
432           dock = ::qobject_cast<QDockWidget*>( w );
433           w = w->parentWidget();
434       }
435       if(dock) {
436           dock->setVisible(it.value());
437       }
438     }
439   }
440 }