Salome HOME
03849f8e23a38381d3cc46ebc7669bb2feace724
[modules/paravis.git] / src / PVGUI / PVGUI_Module_widgets.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2012  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 <QAction>
32 #include <QDockWidget>
33 #include <QToolBar>
34 #include <QStatusBar>
35 #include <QShortcut>
36 #include <QScrollArea>
37 #include <QVBoxLayout>
38
39 #include <pqAnimationViewWidget.h> 
40
41 #include <pqApplicationCore.h>
42 #include <pqComparativeVisPanel.h>
43 #include <pqObjectInspectorWidget.h>
44 #include <pqPipelineBrowserWidget.h>
45 //#include <pqProxyTabWidget.h>
46 #include <pqObjectInspectorWidget.h>
47 #include <pqProxyInformationWidget.h>
48 #include <pqDisplayProxyEditorWidget.h>
49 #include <pqSettings.h>
50 #include <pqDataInformationWidget.h>
51 #include <pqPVAnimationWidget.h>
52 #include <pqSelectionInspectorWidget.h>
53 #include <pqProgressWidget.h>
54
55 #include <pqAlwaysConnectedBehavior.h>
56 #include <pqApplicationCore.h>
57 #include <pqAutoLoadPluginXMLBehavior.h>
58 #include <pqCommandLineOptionsBehavior.h>
59 #include <pqCrashRecoveryBehavior.h>
60 #include <pqDataTimeStepBehavior.h>
61 #include <pqDefaultViewBehavior.h>
62 #include <pqDeleteBehavior.h>
63 #include <pqPersistentMainWindowStateBehavior.h>
64 #include <pqPluginActionGroupBehavior.h>
65 #include <pqPluginDockWidgetsBehavior.h>
66 #include <pqPluginManager.h>
67 #include <pqPVNewSourceBehavior.h>
68 #include <pqSpreadSheetVisibilityBehavior.h>
69 #include <pqStandardViewModules.h>
70 #include <pqUndoRedoBehavior.h>
71 #include <pqViewFrameActionsBehavior.h>
72 #include <pqParaViewMenuBuilders.h>
73 #include <pqCollaborationPanel.h>
74 #include <pqMemoryInspector.h>
75
76 /*!
77   \brief Create dock widgets for ParaView widgets such as object inspector, pipeline browser, etc.
78   ParaView pqMainWIndowCore class is fully responsible for these dock widgets' contents.
79 */
80 void PVGUI_Module::setupDockWidgets()
81 {
82   SUIT_Desktop* desk = application()->desktop();
83  
84   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
85   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
86
87   // Pipeline
88   QDockWidget* pipelineBrowserDock = new QDockWidget( tr( "TTL_PIPELINE_BROWSER" ), desk );
89   pipelineBrowserDock->setObjectName("pipelineBrowserDock");
90   pipelineBrowserDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
91   desk->addDockWidget( Qt::LeftDockWidgetArea, pipelineBrowserDock );
92   pqPipelineBrowserWidget* browser = new pqPipelineBrowserWidget(pipelineBrowserDock);
93   pqParaViewMenuBuilders::buildPipelineBrowserContextMenu(*browser);
94   pipelineBrowserDock->setWidget(browser);
95   myDockWidgets[pipelineBrowserDock] = true;
96
97
98   
99
100   //Object inspector
101   QDockWidget* objectInspectorDock = new QDockWidget( tr( "TTL_OBJECT_INSPECTOR" ), desk );
102   objectInspectorDock->setObjectName("objectInspectorDock");
103   objectInspectorDock->setAllowedAreas( Qt::LeftDockWidgetArea|Qt::NoDockWidgetArea|Qt::RightDockWidgetArea );
104   desk->addDockWidget( Qt::LeftDockWidgetArea, objectInspectorDock );
105
106   pqObjectInspectorWidget* objectInspectorWidget = new pqObjectInspectorWidget(objectInspectorDock);
107   objectInspectorDock->setObjectName("objectInspectorWidget");
108   objectInspectorWidget->setShowOnAccept(true);
109   objectInspectorDock->setWidget(objectInspectorWidget);
110   connect( objectInspectorWidget, SIGNAL( helpRequested(const QString&, const QString&) ),  this, SLOT( showHelpForProxy(const QString&, const QString&) ) );
111   myDockWidgets[objectInspectorDock] = true;
112
113   //Display Dock
114   QDockWidget* displayDock = new QDockWidget( tr( "TTL_DISPLAY" ), desk );
115   displayDock->setObjectName("displayDock");
116   QWidget* displayWidgetFrame = new QWidget(displayDock);
117   displayWidgetFrame->setObjectName("displayWidgetFrame");
118   displayDock->setWidget(displayWidgetFrame);
119
120   QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
121   displayScrollArea->setObjectName("displayScrollArea");
122   displayScrollArea->setWidgetResizable(true);
123
124   QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
125   verticalLayout->setSpacing(0);
126   verticalLayout->setContentsMargins(0, 0, 0, 0);
127
128   pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
129   displayWidget->setObjectName("displayWidget");
130   displayScrollArea->setWidget(displayWidget);
131   verticalLayout->addWidget(displayScrollArea);
132
133   myDockWidgets[displayDock] = 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   desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
161   desk->tabifyDockWidget(objectInspectorDock, displayDock);
162   desk->tabifyDockWidget(objectInspectorDock, informationDock);
163   objectInspectorDock->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);
180   animationViewDock->setWidget(animation_panel);
181   myDockWidgets[animationViewDock] = false; // hidden by default
182
183   desk->tabifyDockWidget(animationViewDock,  statisticsViewDock);
184
185   // Selection view
186   QDockWidget* selectionInspectorDock = new QDockWidget( tr( "TTL_SELECTION_INSPECTOR" ), desk );
187   selectionInspectorDock->setObjectName("selectionInspectorDock");
188   selectionInspectorDock->setAllowedAreas( Qt::AllDockWidgetAreas );
189   desk->addDockWidget( Qt::LeftDockWidgetArea, selectionInspectorDock );
190   pqSelectionInspectorPanel* aSelInspector = new pqSelectionInspectorWidget(selectionInspectorDock);
191   selectionInspectorDock->setWidget(aSelInspector);
192   myDockWidgets[selectionInspectorDock] = false; // hidden by default
193
194   // Comparative View
195   QDockWidget* comparativePanelDock  = new QDockWidget( tr( "TTL_COMPARATIVE_VIEW_INSPECTOR" ), desk );
196   comparativePanelDock->setObjectName("comparativePanelDock");
197   desk->addDockWidget( Qt::LeftDockWidgetArea, comparativePanelDock );
198   pqComparativeVisPanel* cv_panel = new pqComparativeVisPanel( comparativePanelDock );
199   comparativePanelDock->setWidget(cv_panel);
200   myDockWidgets[comparativePanelDock] = false; // hidden by default
201
202   // Collaboration view
203   QDockWidget* collaborationPanelDock = new QDockWidget(tr( "TTL_COLLABORATIVE_DOCK" ), desk);
204   collaborationPanelDock->setObjectName("collaborationPanelDock");
205   pqCollaborationPanel* collaborationPanel = new pqCollaborationPanel();
206   collaborationPanel->setObjectName("collaborationPanel");
207   collaborationPanelDock->setWidget(collaborationPanel);
208   desk->addDockWidget(Qt::RightDockWidgetArea, collaborationPanelDock);
209   myDockWidgets[collaborationPanelDock] = false; // hidden by default
210   
211   // Memory inspector dock
212   QDockWidget* memoryInspectorDock = new QDockWidget(tr( "TTL_MEMORY_INSPECTOR" ), desk);
213   memoryInspectorDock->setObjectName("memoryInspectorDock");
214   pqMemoryInspector* dockWidgetContents = new pqMemoryInspector();
215   dockWidgetContents->setObjectName("dockWidgetContents");
216   memoryInspectorDock->setWidget(dockWidgetContents);
217   desk->addDockWidget(Qt::RightDockWidgetArea, memoryInspectorDock);
218   myDockWidgets[memoryInspectorDock] = false; // hidden by default
219
220
221   // Setup the statusbar ...
222   pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
223   desk->statusBar()->addPermanentWidget(aProgress);
224   
225   // Set up the dock window corners to give the vertical docks more room.
226   desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
227   desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
228   
229   // Setup the default dock configuration ...
230   statisticsViewDock->hide();
231   comparativePanelDock->hide();
232   animationViewDock->hide();
233   selectionInspectorDock->hide();
234   collaborationPanelDock->hide();
235   memoryInspectorDock->hide();
236
237
238   // Setup quick-launch shortcuts.
239   QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, desk);
240   QObject::connect(ctrlSpace, SIGNAL(activated()), pqApplicationCore::instance(), SLOT(quickLaunch()));
241   QShortcut *altSpace = new QShortcut(Qt::ALT + Qt::Key_Space, desk);
242   QObject::connect(altSpace, SIGNAL(activated()), pqApplicationCore::instance(), SLOT(quickLaunch()));
243
244 }
245
246 /*!
247   \brief Save states of dockable ParaView widgets.
248 */
249 void PVGUI_Module::saveDockWidgetsState()
250 {
251   SUIT_Desktop* desk = application()->desktop();
252
253   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
254   // ... the following code is commented...
255   // Save the state of the window ...
256   // pqApplicationCore::instance()->settings()->saveState(*desk, "MainWindow");
257   //
258   //for (int i = 0; i < myDockWidgets.size(); ++i)
259   //  myDockWidgets.at(i)->setParent(0);
260   // ... and replaced - manually hide dock windows
261
262   // store dock widgets visibility state and hide'em all
263   QMapIterator<QWidget*, bool> it1( myDockWidgets );
264   while( it1.hasNext() ) {
265     it1.next();
266     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
267     myDockWidgets[dw] = dw->isVisible();
268     dw->setVisible( false );
269     dw->toggleViewAction()->setVisible( false );
270   }
271   // store toolbar breaks state and remove all tollbar breaks 
272   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
273   while( it2.hasNext() ) {
274     it2.next();
275     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
276     myToolbarBreaks[tb] = desk->toolBarBreak( tb );
277     if ( myToolbarBreaks[tb] )
278       desk->removeToolBarBreak( tb );
279   }
280   // store toolbars visibility state and hide'em all
281   QMapIterator<QWidget*, bool> it3( myToolbars );
282   while( it3.hasNext() ) {
283     it3.next();
284     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
285     myToolbars[tb] = tb->isVisible();
286     tb->setVisible( false );
287     tb->toggleViewAction()->setVisible( false );
288   }
289 }
290
291 /*!
292   \brief Restore states of dockable ParaView widgets.
293 */
294 void PVGUI_Module::restoreDockWidgetsState()
295 {
296   SUIT_Desktop* desk = application()->desktop();
297
298   // VSR: 19/06/2011: do not use Paraview's methods, since it conflicts with SALOME GUI architecture
299   // ... the following code is commented...
300   //for (int i = 0; i < myDockWidgets.size(); ++i)
301   //  myDockWidgets.at(i)->setParent(desk);
302   //
303   // Restore the state of the window ...
304   //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
305   // ... and replaced - manually hide dock windows
306
307   // restore dock widgets visibility state
308   QMapIterator<QWidget*, bool> it1( myDockWidgets );
309   while( it1.hasNext() ) {
310     it1.next();
311     QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
312     dw->setVisible( it1.value() );
313     dw->toggleViewAction()->setVisible( true );
314   }
315   // restore toolbar breaks state
316   QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
317   while( it2.hasNext() ) {
318     it2.next();
319     QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
320     if ( myToolbarBreaks[tb] )
321       desk->insertToolBarBreak( tb );
322   }
323   // restore toolbar visibility state
324   QMapIterator<QWidget*, bool> it3( myToolbars );
325   while( it3.hasNext() ) {
326     it3.next();
327     QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
328     tb->setVisible( it3.value() );
329     tb->toggleViewAction()->setVisible( true );
330   }
331 }