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