1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2013 CEA/DEN, EDF R&D
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.
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.
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
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : PVGUI_Module_MenuActions.cxx
22 // Author : Margarita KARPUNINA
25 #include "PVGUI_Module.h"
27 #include <QtxActionToolMgr.h>
28 #include <LightApp_Application.h>
29 #include <SUIT_Desktop.h>
31 #include <QApplication>
33 #include <QDockWidget>
37 #include <QScrollArea>
38 #include <QVBoxLayout>
40 #include <QToolButton>
42 #include <pqAnimationViewWidget.h>
43 #include <pqAnimationWidget.h>
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>
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>
81 class ResizeHelper : public pqPVAnimationWidget
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();
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
94 ResizeHelper( QWidget* parent ) : pqPVAnimationWidget( parent ) {}
96 void resizeEvent(QResizeEvent* e)
98 pqAnimationWidget* w = findChild<pqAnimationWidget*>( "pqAnimationWidget" );
101 QApplication::sendEvent( w, &e );
103 pqPVAnimationWidget::resizeEvent( e );
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.
111 void PVGUI_Module::setupDockWidgets()
113 SUIT_Desktop* desk = application()->desktop();
115 desk->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
116 desk->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
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;
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 );
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;
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);
151 QScrollArea* displayScrollArea = new QScrollArea(displayWidgetFrame);
152 displayScrollArea->setObjectName("displayScrollArea");
153 displayScrollArea->setWidgetResizable(true);
155 QVBoxLayout* verticalLayout = new QVBoxLayout(displayWidgetFrame);
156 verticalLayout->setSpacing(0);
157 verticalLayout->setContentsMargins(0, 0, 0, 0);
159 pqDisplayProxyEditorWidget* displayWidget = new pqDisplayProxyEditorWidget(displayDock);
160 displayWidget->setObjectName("displayWidget");
161 displayScrollArea->setWidget(displayWidget);
162 verticalLayout->addWidget(displayScrollArea);
164 myDockWidgets[displayDock] = true;
167 QDockWidget* informationDock = new QDockWidget(tr( "TTL_INFORMATION" ), desk);
168 informationDock->setObjectName("informationDock");
170 QWidget* informationWidgetFrame = new QWidget(informationDock);
171 informationWidgetFrame->setObjectName("informationWidgetFrame");
173 QVBoxLayout* verticalLayout_2 = new QVBoxLayout(informationWidgetFrame);
174 verticalLayout_2->setSpacing(0);
175 verticalLayout_2->setContentsMargins(0, 0, 0, 0);
177 QScrollArea* informationScrollArea = new QScrollArea(informationWidgetFrame);
178 informationScrollArea->setObjectName("informationScrollArea") ;
179 informationScrollArea->setWidgetResizable(true);
181 pqProxyInformationWidget* informationWidget = new pqProxyInformationWidget();
182 informationWidget->setObjectName("informationWidget");
183 informationWidget->setGeometry(QRect(0, 0, 77, 214));
184 informationScrollArea->setWidget(informationWidget);
186 verticalLayout_2->addWidget(informationScrollArea);
187 informationDock->setWidget(informationWidgetFrame);
189 myDockWidgets[informationDock] = true;
191 desk->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
192 desk->tabifyDockWidget(objectInspectorDock, displayDock);
193 desk->tabifyDockWidget(objectInspectorDock, informationDock);
194 objectInspectorDock->raise();
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
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
214 desk->tabifyDockWidget(animationViewDock, statisticsViewDock);
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
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
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
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
251 // Setup the statusbar ...
252 pqProgressManager* progress_manager =
253 pqApplicationCore::instance()->getProgressManager();
255 // Progress bar/button management
256 pqProgressWidget* aProgress = new pqProgressWidget(desk->statusBar());
257 progress_manager->addNonBlockableObject(aProgress);
258 progress_manager->addNonBlockableObject(aProgress->getAbortButton());
260 QObject::connect( progress_manager, SIGNAL(enableProgress(bool)),
261 aProgress, SLOT(enableProgress(bool)));
263 QObject::connect( progress_manager, SIGNAL(progress(const QString&, int)),
264 aProgress, SLOT(setProgress(const QString&, int)));
266 QObject::connect( progress_manager, SIGNAL(enableAbort(bool)),
267 aProgress, SLOT(enableAbort(bool)));
269 QObject::connect( aProgress, SIGNAL(abortPressed()),
270 progress_manager, SLOT(triggerAbort()));
272 desk->statusBar()->addPermanentWidget(aProgress);
273 aProgress->setEnabled(true);
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);
279 // Setup the default dock configuration ...
280 statisticsViewDock->hide();
281 comparativePanelDock->hide();
282 animationViewDock->hide();
283 selectionInspectorDock->hide();
284 collaborationPanelDock->hide();
285 memoryInspectorDock->hide();
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()));
296 \brief Save states of dockable ParaView widgets.
298 void PVGUI_Module::saveDockWidgetsState()
300 SUIT_Desktop* desk = application()->desktop();
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");
307 //for (int i = 0; i < myDockWidgets.size(); ++i)
308 // myDockWidgets.at(i)->setParent(0);
309 // ... and replaced - manually hide dock windows
311 // store dock widgets visibility state and hide'em all
312 QMapIterator<QWidget*, bool> it1( myDockWidgets );
313 while( it1.hasNext() ) {
315 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
316 myDockWidgets[dw] = dw->isVisible();
317 dw->setVisible( false );
318 dw->toggleViewAction()->setVisible( false );
320 // store toolbar breaks state and remove all tollbar breaks
321 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
322 while( it2.hasNext() ) {
324 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
325 myToolbarBreaks[tb] = desk->toolBarBreak( tb );
326 if ( myToolbarBreaks[tb] )
327 desk->removeToolBarBreak( tb );
329 // store toolbars visibility state and hide'em all
330 QMapIterator<QWidget*, bool> it3( myToolbars );
331 while( it3.hasNext() ) {
333 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
334 myToolbars[tb] = tb->isVisible();
335 tb->setVisible( false );
336 tb->toggleViewAction()->setVisible( false );
341 \brief Restore states of dockable ParaView widgets.
343 void PVGUI_Module::restoreDockWidgetsState()
345 SUIT_Desktop* desk = application()->desktop();
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);
352 // Restore the state of the window ...
353 //pqApplicationCore::instance()->settings()->restoreState("MainWindow", *desk);
354 // ... and replaced - manually hide dock windows
356 // restore dock widgets visibility state
357 QMapIterator<QWidget*, bool> it1( myDockWidgets );
358 while( it1.hasNext() ) {
360 QDockWidget* dw = qobject_cast<QDockWidget*>( it1.key() );
361 dw->setVisible( it1.value() );
362 dw->toggleViewAction()->setVisible( true );
364 // restore toolbar breaks state
365 QMapIterator<QWidget*, bool> it2( myToolbarBreaks );
366 while( it2.hasNext() ) {
368 QToolBar* tb = qobject_cast<QToolBar*>( it2.key() );
369 if ( myToolbarBreaks[tb] )
370 desk->insertToolBarBreak( tb );
372 // restore toolbar visibility state
373 QMapIterator<QWidget*, bool> it3( myToolbars );
374 while( it3.hasNext() ) {
376 QToolBar* tb = qobject_cast<QToolBar*>( it3.key() );
377 tb->setVisible( it3.value() );
378 tb->toggleViewAction()->setVisible( true );