Salome HOME
Merge from V6_main 01/04/2013
[modules/paravis.git] / src / PVGUI / PVGUI_Module_widgets.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2013  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.
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 <SUIT_Desktop.h>
30
31 #include <QApplication>
32 #include <QAction>
33 #include <QDockWidget>
34 #include <QToolBar>
35 #include <QStatusBar>
36 #include <QShortcut>
37 #include <QScrollArea>
38 #include <QVBoxLayout>
39 #include <QShowEvent>
40 #include <QToolButton>
41
42 #include <pqAnimationViewWidget.h> 
43 #include <pqAnimationWidget.h> 
44
45 #include <pqApplicationCore.h>
46 #include <pqComparativeVisPanel.h>
47 #include <pqObjectInspectorWidget.h>
48 #include <pqPipelineBrowserWidget.h>
49 //#include <pqProxyTabWidget.h>
50 #include <pqObjectInspectorWidget.h>
51 #include <pqProxyInformationWidget.h>
52 #include <pqDisplayProxyEditorWidget.h>
53 #include <pqSettings.h>
54 #include <pqDataInformationWidget.h>
55 #include <pqPVAnimationWidget.h>
56 #include <pqSelectionInspectorWidget.h>
57 #include <pqProgressWidget.h>
58 #include <pqProgressManager.h>
59
60 #include <pqAlwaysConnectedBehavior.h>
61 #include <pqApplicationCore.h>
62 #include <pqAutoLoadPluginXMLBehavior.h>
63 #include <pqCommandLineOptionsBehavior.h>
64 #include <pqCrashRecoveryBehavior.h>
65 #include <pqDataTimeStepBehavior.h>
66 #include <pqDefaultViewBehavior.h>
67 #include <pqDeleteBehavior.h>
68 #include <pqPersistentMainWindowStateBehavior.h>
69 #include <pqPluginActionGroupBehavior.h>
70 #include <pqPluginDockWidgetsBehavior.h>
71 #include <pqPluginManager.h>
72 #include <pqPVNewSourceBehavior.h>
73 #include <pqSpreadSheetVisibilityBehavior.h>
74 #include <pqStandardViewModules.h>
75 #include <pqUndoRedoBehavior.h>
76 #include <pqViewFrameActionsBehavior.h>
77 #include <pqParaViewMenuBuilders.h>
78 #include <pqCollaborationPanel.h>
79 #include <pqMemoryInspectorPanel.h>
80
81 class ResizeHelper : public pqPVAnimationWidget
82 {
83   // TEMPORARILY WORKAROUND AROUND PARAVIEW 3.14 BUG:
84   // WHEN ANIMATION VIEW IS RESIZED, ITS CONTENTS IS NOT PREPERLY RE-ARRANGED
85   // CAUSING SOME CONTROLS TO STAY NON-VISIBLE
86   // THIS BUG IS NATURALLY FIXED BY ADDING 
87   //      this->updateGeometries();
88   // TO THE
89   //     void pqAnimationWidget::resizeEvent(QResizeEvent* e);
90   // BUT THIS CANNOT BE DONE DIRECTLY, SINCE CORRESPONDING API IS NOT PUBLIC
91   // THE ONLY WAY TO DO THIS BY SENDING SHOW EVENT TO THE WIDGET
92
93 public:
94   ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
95 protected:
96   void resizeEvent(QResizeEvent* e)
97   {
98     pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
99     if ( w ) { 
100       QShowEvent e;
101       QApplication::sendEvent( w, &e );
102     }
103     pqPVAnimationWidget::resizeEvent( e );
104   }
105 };
106
107 /*!
108   \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
109   ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
110 */
111 void PVGUI_Module::setupDockWidgets()
112 {
113   SUIT_Desktop* desk = application()->desktop();
114  
115   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
116   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
117
118   // Pipeline
119   QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
120   pipelineBrowserDock->setObjectName("pipelineBrowserDock");
121   pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
122   desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
123   pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
124   pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
125   pipelineBrowserDock->setWidget(browser);
126   myDockWidgets[pipelineBrowserDock] = true;
127
128
129   
130
131   //Object inspector
132   QDockWidget* objectInspectorDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
133   objectInspectorDock->setObjectName("objectInspectorDock");
134   objectInspectorDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
135   desk->addDockWidget( Qt::LeftDockWidgetArea, objectInspectorDock );
136
137   pqObjectInspectorWidget* objectInspectorWidget = new pqObjectInspectorWidget(objectInspectorDock);
138   objectInspectorDock->setObjectName("objectInspectorWidget");
139   objectInspectorWidget->setShowOnAccept(true);
140   objectInspectorDock->setWidget(objectInspectorWidget);
141   connect( objectInspectorWidget, SIGNAL( helpRequested(const QString&, const QString&) ),  this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
142   myDockWidgets[objectInspectorDock] = true;
143
144   //Display Dock
145   QDockWidget* displayDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
146   displayDock->setObjectName("displayDock");
147   QWidget* displayWidgetFrame = new QWidget(displayDock);
148   displayWidgetFrame->setObjectName("displayWidgetFrame");
149   displayDock->setWidget(displayWidgetFrame);
150
151   QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
152   displayScrollArea->setObjectName("displayScrollArea");
153   displayScrollArea->setWidgetResizable(true);
154
155   QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
156   verticalLayout->setSpacing(0);
157   verticalLayout->setContentsMargins(0, 0, 0, 0);
158
159   pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
160   displayWidget->setObjectName("displayWidget");
161   displayScrollArea->setWidget(displayWidget);
162   verticalLayout->addWidget(displayScrollArea);
163
164   myDockWidgets[displayDock] = true;
165
166   // information dock
167   QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
168   informationDock->setObjectName("informationDock");
169
170   QWidget* informationWidgetFrame = new QWidget(informationDock);
171   informationWidgetFrame->setObjectName("informationWidgetFrame");
172   
173   QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
174   verticalLayout_2->setSpacing(0);
175   verticalLayout_2->setContentsMargins(0, 0, 0, 0);
176
177   QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
178   informationScrollArea->setObjectName("informationScrollArea") ;
179   informationScrollArea->setWidgetResizable(true);
180
181   pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
182   informationWidget->setObjectName("informationWidget");
183   informationWidget->setGeometry(QRect(0, 0, 77, 214));
184   informationScrollArea->setWidget(informationWidget);
185
186   verticalLayout_2->addWidget(informationScrollArea);
187   informationDock->setWidget(informationWidgetFrame);
188
189   myDockWidgets[informationDock] = true;
190
191   desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
192   desk->tabifyDockWidget(objectInspectorDock, displayDock);
193   desk->tabifyDockWidget(objectInspectorDock, informationDock);
194   objectInspectorDock->raise();
195
196   // Statistic View
197   QDockWidget* statisticsViewDock  = new QDockWidget( tr( "TTL_STATISTICS_VIEW" ), desk );
198   statisticsViewDock->setObjectName("statisticsViewDock");
199   statisticsViewDock->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::LeftDockWidgetArea|
200                                       Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
201   desk->addDockWidget( Qt::BottomDockWidgetArea, statisticsViewDock );
202   pqDataInformationWidget* aStatWidget = new pqDataInformationWidget(statisticsViewDock);
203   statisticsViewDock->setWidget(aStatWidget);
204   myDockWidgets[statisticsViewDock] = false; // hidden by default
205
206   //Animation view
207   QDockWidget* animationViewDock     = new QDockWidget( tr( "TTL_ANIMATION_VIEW" ), desk );
208   animationViewDock->setObjectName("animationViewDock");
209   desk->addDockWidget( Qt::BottomDockWidgetArea, animationViewDock );
210   pqPVAnimationWidget* animation_panel = new ResizeHelper(animationViewDock); //pqPVAnimationWidget
211   animationViewDock->setWidget(animation_panel);
212   myDockWidgets[animationViewDock] = false; // hidden by default
213
214   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
215
216   // Selection view
217   QDockWidget* selectionInspectorDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
218   selectionInspectorDock->setObjectName("selectionInspectorDock");
219   selectionInspectorDock->setAllowedAreas( Qt::AllDockWidgetAreas );
220   desk->addDockWidget( Qt::LeftDockWidgetArea, selectionInspectorDock );
221   pqSelectionInspectorPanel* aSelInspector = new pqSelectionInspectorWidget(selectionInspectorDock);
222   selectionInspectorDock->setWidget(aSelInspector);
223   myDockWidgets[selectionInspectorDock] = false; // hidden by default
224
225   // Comparative View
226   QDockWidget* comparativePanelDock  = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
227   comparativePanelDock->setObjectName("comparativePanelDock");
228   desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
229   pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
230   comparativePanelDock->setWidget(cv_panel);
231   myDockWidgets[comparativePanelDock] = false; // hidden by default
232
233   // Collaboration view
234   QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
235   collaborationPanelDock->setObjectName("collaborationPanelDock");
236   pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
237   collaborationPanel->setObjectName("collaborationPanel");
238   collaborationPanelDock->setWidget(collaborationPanel);
239   desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
240   myDockWidgets[collaborationPanelDock] = false; // hidden by default
241   
242   // Memory inspector dock
243   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
244   memoryInspectorDock->setObjectName("memoryInspectorDock");
245   pqMemoryInspectorPanel* dockWidgetContents = new pqMemoryInspectorPanel();
246   dockWidgetContents->setObjectName("dockWidgetContents");
247   memoryInspectorDock->setWidget(dockWidgetContents);
248   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
249   myDockWidgets[memoryInspectorDock] = false; // hidden by default
250
251   // Setup the statusbar ...
252   pqProgressManager* progress_manager =
253     pqApplicationCore::instance()->getProgressManager();
254
255   // Progress bar/button management
256   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
257   progress_manager->addNonBlockableObject(aProgress);
258   progress_manager->addNonBlockableObject(aProgress->getAbortButton());
259   
260   QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
261                     aProgress,        SLOT(enableProgress(bool)));
262
263   QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
264                     aProgress,        SLOT(setProgress(const QString&, int)));
265
266   QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
267                     aProgress,        SLOT(enableAbort(bool)));
268
269   QObject::connect( aProgress,        SIGNAL(abortPressed()),
270                     progress_manager, SLOT(triggerAbort()));
271
272   desk->statusBar()->addPermanentWidget(aProgress);
273   aProgress->setEnabled(true);
274
275   // Set up the dock window corners to give the vertical docks more room.
276   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
277   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
278   
279   // Setup the default dock configuration ...
280   statisticsViewDock->hide();
281   comparativePanelDock->hide();
282   animationViewDock->hide();
283   selectionInspectorDock->hide();
284   collaborationPanelDock->hide();
285   memoryInspectorDock->hide();
286
287   // Setup quick-launch shortcuts.
288   QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, desk);
289   QObject::connect(ctrlSpace, SIGNAL(activated()), pqApplicationCore::instance(), SLOT(quickLaunch()));
290   QShortcut *altSpace = new QShortcut(Qt::ALT + Qt::Key_Space, desk);
291   QObject::connect(altSpace, SIGNAL(activated()), pqApplicationCore::instance(), SLOT(quickLaunch()));
292
293 }
294
295 /*!
296   \brief Save states of dockable ParaView widgets.
297 */
298 void PVGUI_Module::saveDockWidgetsState()
299 {
300   SUIT_Desktop* desk = application()->desktop();
301
302   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
303   // ... the following code is commented...
304   // Save the state of the window ...
305   // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
306   //
307   //for (int i = 0; i < myDockWidgets.size(); ++i)
308   //  myDockWidgets.at(i)->setParent(0);
309   // ... and replaced - manually hide dock windows
310
311   // store dock widgets visibility state and hide'em all
312   QMapIterator<QWidget*, bool> it1( myDockWidgets );
313   while( it1.hasNext() ) {
314     it1.next();
315     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
316     myDockWidgets[dw] = dw->isVisible();
317     dw->setVisible( false );
318     dw->toggleViewAction()->setVisible( false );
319   }
320   // store toolbar breaks state and remove all tollbar breaks 
321   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
322   while( it2.hasNext() ) {
323     it2.next();
324     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
325     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
326     if ( myToolbarBreaks[tb] )
327       desk->removeToolBarBreak( tb );
328   }
329   // store toolbars visibility state and hide'em all
330   QMapIterator<QWidget*, bool> it3( myToolbars );
331   while( it3.hasNext() ) {
332     it3.next();
333     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
334     myToolbars[tb] = tb->isVisible();
335     tb->setVisible( false );
336     tb->toggleViewAction()->setVisible( false );
337   }
338 }
339
340 /*!
341   \brief Restore states of dockable ParaView widgets.
342 */
343 void PVGUI_Module::restoreDockWidgetsState()
344 {
345   SUIT_Desktop* desk = application()->desktop();
346
347   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
348   // ... the following code is commented...
349   //for (int i = 0; i < myDockWidgets.size(); ++i)
350   //  myDockWidgets.at(i)->setParent(desk);
351   //
352   // Restore the state of the window ...
353   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
354   // ... and replaced - manually hide dock windows
355
356   // restore dock widgets visibility state
357   QMapIterator<QWidget*, bool> it1( myDockWidgets );
358   while( it1.hasNext() ) {
359     it1.next();
360     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
361     dw->setVisible( it1.value() );
362     dw->toggleViewAction()->setVisible( true );
363   }
364   // restore toolbar breaks state
365   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
366   while( it2.hasNext() ) {
367     it2.next();
368     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
369     if ( myToolbarBreaks[tb] )
370       desk->insertToolBarBreak( tb );
371   }
372   // restore toolbar visibility state
373   QMapIterator<QWidget*, bool> it3( myToolbars );
374   while( it3.hasNext() ) {
375     it3.next();
376     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
377     tb->setVisible( it3.value() );
378     tb->toggleViewAction()->setVisible( true );
379   }
380 }