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