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