]> SALOME platform Git repositories - modules/paravis.git/blob - src/PVGUI/PVGUI_Module.cxx
Salome HOME
Show/hide ParaViS menus, toolbars and dockable widgets on activate/deactivate ParaViS...
[modules/paravis.git] / src / PVGUI / PVGUI_Module.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : PVGUI_Module.cxx
23 // Author : Julia DOROVSKIKH
24 //
25
26 #include "PVGUI_Module.h"
27 #include "PVGUI_Module_impl.h"
28 #include "PVGUI_ProcessModuleHelper.h"
29 #include "PVGUI_ViewModel.h"
30 #include "PVGUI_ViewManager.h"
31 #include "PVGUI_ViewWindow.h"
32
33 #include <SUIT_Desktop.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <LightApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <QtxActionMenuMgr.h>
40 #include <QtxActionToolMgr.h>
41
42 #include <QAction>
43 #include <QApplication>
44 #include <QCursor>
45 #include <QDir>
46 #include <QFile>
47 #include <QFileInfo>
48 #include <QIcon>
49 #include <QInputDialog>
50 #include <QStatusBar>
51 #include <QString>
52 #include <QStringList>
53 #include <QTimer>
54 #include <QToolBar>
55
56 #include <pqApplicationCore.h>
57 #include <pqActiveServer.h>
58 #include <pqActiveView.h>
59 #include <pqClientAboutDialog.h>
60 #include <pqObjectBuilder.h>
61 #include <pqOptions.h>
62 #include <pqRenderView.h>
63 #include <pqRubberBandHelper.h>
64 #include <pqServer.h>
65 #include <pqServerManagerModel.h>
66 #include <pqServerResource.h>
67 #include <pqUndoStack.h>
68 #include <pqVCRController.h>
69 #include <pqViewManager.h>
70 #include <vtkPVMain.h>
71 #include <vtkProcessModule.h>
72
73 /*
74  * Make sure all the kits register their classes with vtkInstantiator.
75  * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
76  * anyway.  The instantiators will add no more code for the linker to
77  * collect.
78  */
79
80 #include <vtkCommonInstantiator.h>
81 #include <vtkFilteringInstantiator.h>
82 #include <vtkGenericFilteringInstantiator.h>
83 #include <vtkIOInstantiator.h>
84 #include <vtkImagingInstantiator.h>
85 #include <vtkInfovisInstantiator.h>
86 #include <vtkGraphicsInstantiator.h>
87
88 #include <vtkRenderingInstantiator.h>
89 #include <vtkVolumeRenderingInstantiator.h>
90 #include <vtkHybridInstantiator.h>
91 #include <vtkParallelInstantiator.h>
92
93 #include <vtkPVServerCommonInstantiator.h>
94 #include <vtkPVFiltersInstantiator.h>
95 #include <vtkPVServerManagerInstantiator.h>
96 #include <vtkClientServerInterpreter.h>
97
98
99 //----------------------------------------------------------------------------
100 // ClientServer wrapper initialization functions.
101 // Taken from ParaView sources (file pqMain.cxx)
102 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
103 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
104 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
105 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
106 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
107 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
108 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
109 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
110 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
111 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
112 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
113 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
114 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
115 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
116 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
117
118 //----------------------------------------------------------------------------
119 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
120 {
121   // Initialize built-in wrapper modules.
122   vtkCommonCS_Initialize(pm->GetInterpreter());
123   vtkFilteringCS_Initialize(pm->GetInterpreter());
124   vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
125   vtkImagingCS_Initialize(pm->GetInterpreter());
126   vtkInfovisCS_Initialize(pm->GetInterpreter());
127   vtkGraphicsCS_Initialize(pm->GetInterpreter());
128   vtkIOCS_Initialize(pm->GetInterpreter());
129   vtkRenderingCS_Initialize(pm->GetInterpreter());
130   vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
131   vtkHybridCS_Initialize(pm->GetInterpreter());
132   vtkWidgetsCS_Initialize(pm->GetInterpreter());
133   vtkParallelCS_Initialize(pm->GetInterpreter());
134   vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
135   vtkPVFiltersCS_Initialize(pm->GetInterpreter());
136   vtkXdmfCS_Initialize(pm->GetInterpreter());
137 }
138
139 vtkPVMain*                 PVGUI_Module::pqImplementation::myPVMain = 0;
140 pqOptions*                 PVGUI_Module::pqImplementation::myPVOptions = 0;
141 PVGUI_ProcessModuleHelper* PVGUI_Module::pqImplementation::myPVHelper = 0;
142
143 /*!
144   \class PVGUI_Module
145   \brief Implementation of light (no-CORBA-engine) 
146          SALOME module wrapping ParaView GUI.
147 */
148
149 /*!
150   \brief Constructor. Sets the default name for the module.
151 */
152 PVGUI_Module::PVGUI_Module()
153   : LightApp_Module( "PARAVIS" ),
154     Implementation( 0 ),
155     mySelectionControlsTb( -1 ),
156     mySourcesMenuId( -1 ),
157     myFiltersMenuId( -1 )
158 {
159 }
160
161 /*!
162   \brief Destructor.
163 */
164 PVGUI_Module::~PVGUI_Module()
165 {
166 }
167
168 /*!
169   \brief Initialize module. Creates menus, prepares context menu, etc.
170   \param app application instance
171 */
172 void PVGUI_Module::initialize( CAM_Application* app )
173 {
174   LightApp_Module::initialize( app );
175
176   // Uncomment to debug ParaView initialization
177   // "aa" used instead of "i" as GDB doesn't like "i" variables :)
178   /*
179   int aa = 1;
180   while( aa ){
181     aa = aa;
182   }
183   */
184   
185   pvInit();
186
187 }
188
189 /*!
190   \brief Get list of compliant dockable GUI elements
191   \param m map to be filled in ("type":"default_position")
192 */
193 void PVGUI_Module::windows( QMap<int, int>& m ) const
194 {
195   m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
196   m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
197   // ParaView diagnostic output redirected here
198   m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
199 }
200
201 /*!
202   \brief Create custom popup menu selection object.
203   \return new selected object
204 */
205 /*LightApp_Selection* PVGUI_Module::createSelection() const
206 {
207   return new PVGUI_Selection();
208 }*/
209
210 /*!
211   \brief Create data model.
212   \return module specific data model
213 */
214 /*CAM_DataModel* PVGUI_Module::createDataModel()
215 {
216   return new PVGUI_DataModel( this );
217 }*/
218
219 /*!
220   \brief Static method, performs initialization of ParaView session.
221   \return \c true if ParaView has been initialized successfully, otherwise false
222 */
223 bool PVGUI_Module::pvInit()
224 {
225   if ( !pqImplementation::myPVMain ){
226     // Obtain command-line arguments
227     int argc = 0;
228     QStringList args = QApplication::arguments();
229     char** argv = new char*[args.size()];
230     for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
231       argv[argc] = strdup( (*it).toLatin1().constData() );
232
233     vtkPVMain::SetInitializeMPI(0);  // pvClient never runs with MPI.
234     vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
235
236     // TODO: Set plugin dir from preferences
237     //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
238
239     pqImplementation::myPVMain = vtkPVMain::New();
240     if ( !pqImplementation::myPVOptions )
241       pqImplementation::myPVOptions = pqOptions::New();
242     if ( !pqImplementation::myPVHelper )
243       pqImplementation::myPVHelper = PVGUI_ProcessModuleHelper::New();
244
245     pqImplementation::myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
246
247     // This creates the Process Module and initializes it.
248     int ret = pqImplementation::myPVMain->Initialize(pqImplementation::myPVOptions, 
249                                                      pqImplementation::myPVHelper, 
250                                                      ParaViewInitializeInterpreter,
251                                                      argc, argv);
252     if (!ret){
253       // Tell process module that we support Multiple connections.
254       // This must be set before starting the event loop.
255       vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
256       ret = pqImplementation::myPVHelper->Run(pqImplementation::myPVOptions);
257     }
258
259     delete[] argv;
260     return !ret;
261   }
262   
263   return true;
264 }
265  
266 /*!
267   \brief Static method, cleans up ParaView session at application exit.
268 */
269 void PVGUI_Module::pvShutdown()
270 {
271   // TODO...
272 }  
273
274 /*!
275   \brief Shows (toShow = true) or hides ParaView view window
276 */
277 void PVGUI_Module::showView( bool toShow )
278 {
279   // TODO: check if ParaView view already exists
280   if ( !Implementation ){
281     LightApp_Application* anApp = getApp();
282     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
283     PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
284     anApp->addViewManager( viewMgr );
285     connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
286              anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
287     //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
288     //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
289     SUIT_ViewWindow* wnd = viewMgr->createViewWindow();  
290
291     // Simulate ParaView client main window
292     Implementation = new pqImplementation( anApp->desktop() );
293     PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( wnd );
294     pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() );
295
296     setupDockWidgets();
297     
298     pvCreateActions();
299     pvCreateMenus();
300     pvCreateToolBars();
301     
302     setupDockWidgetsContextMenu();
303
304     // Now that we're ready, initialize everything ...
305     Implementation->Core.initializeStates();
306   }
307   else 
308     restoreDockWidgetsState();
309 }
310
311 /*!
312   \brief Manage the label of Undo operation.
313 */
314 void PVGUI_Module::onUndoLabel( const QString& label )
315 {
316   action(UndoId)->setText(
317     label.isEmpty() ? tr("MEN_CANTUNDO") : QString(tr("MEN_UNDO_ACTION")).arg(label));
318   action(UndoId)->setStatusTip(
319     label.isEmpty() ? tr("MEN_CANTUNDO") : QString(tr("MEN_UNDO_ACTION_TIP")).arg(label));
320 }
321
322 /*!
323   \brief Manage the label of Redo operation.
324 */
325 void PVGUI_Module::onRedoLabel( const QString& label )
326 {
327   action(RedoId)->setText(
328     label.isEmpty() ? tr("MEN_CANTREDO") : QString(tr("MEN_REDO_ACTION")).arg(label));
329   action(RedoId)->setStatusTip(
330     label.isEmpty() ? tr("MEN_CANTREDO") : QString(tr("MEN_REDO_ACTION_TIP")).arg(label));
331 }
332
333 /*!
334   \brief Manage the label of Undo Camera operation.
335 */
336 void PVGUI_Module::onCameraUndoLabel( const QString& label )
337 {
338   action(CameraUndoId)->setText(
339     label.isEmpty() ? tr("MEN_CANT_CAMERA_UNDO") : QString(tr("MEN_CAMERA_UNDO_ACTION")).arg(label));
340   action(CameraUndoId)->setStatusTip(
341     label.isEmpty() ? tr("MEN_CANT_CAMERA_UNDO") : QString(tr("MEN_CAMERA_UNDO_ACTION_TIP")).arg(label));
342 }
343
344 /*!
345   \brief Manage the label of Redo Camera operation.
346 */
347 void PVGUI_Module::onCameraRedoLabel( const QString& label )
348 {
349   action(CameraRedoId)->setText(
350     label.isEmpty() ? tr("MEN_CANT_CAMERA_REDO") : QString(tr("MEN_CAMERA_REDO_ACTION")).arg(label));
351   action(CameraRedoId)->setStatusTip(
352     label.isEmpty() ? tr("MEN_CANT_CAMERA_REDO") : QString(tr("MEN_CAMERA_REDO_ACTION_TIP")).arg(label));
353 }
354
355 /*!
356   \brief Slot to delete all objects.
357 */
358 void PVGUI_Module::onDeleteAll()
359 {
360   pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
361   Implementation->Core.getApplicationUndoStack()->beginUndoSet("Delete All");
362   builder->destroyPipelineProxies();
363   Implementation->Core.getApplicationUndoStack()->endUndoSet();
364 }
365
366 /*!
367   \brief Slot to check/uncheck the action for corresponding selection mode.
368 */
369 void PVGUI_Module::onSelectionModeChanged( int mode )
370 {
371   if( toolMgr()->toolBar( mySelectionControlsTb )->isEnabled() ) {
372     if(mode == pqRubberBandHelper::SELECT) //surface selection
373       action(SelectCellsOnId)->setChecked(true);
374     else if(mode == pqRubberBandHelper::SELECT_POINTS) //surface selection
375       action(SelectPointsOnId)->setChecked(true);
376     else if(mode == pqRubberBandHelper::FRUSTUM)
377       action(SelectCellsThroughId)->setChecked(true);
378     else if(mode == pqRubberBandHelper::FRUSTUM_POINTS)
379       action(SelectPointsThroughId)->setChecked(true);
380     else if (mode == pqRubberBandHelper::BLOCKS)
381       action(SelectBlockId)->setChecked(true);
382     else // INTERACT
383       action(InteractId)->setChecked(true);
384   }
385 }
386
387 /*!
388   \brief Slot to manage the change of axis center.
389 */
390 void PVGUI_Module::onShowCenterAxisChanged( bool enabled )
391 {
392   action(ShowCenterId)->setEnabled(enabled);
393   action(ShowCenterId)->blockSignals(true);
394   pqRenderView* renView = qobject_cast<pqRenderView*>(
395     pqActiveView::instance().current());
396   action(ShowCenterId)->setChecked( renView ? renView->getCenterAxesVisibility() : false);
397   action(ShowCenterId)->blockSignals(false);
398 }
399
400 /*!
401   \brief Slot to set tooltips for the first anf the last frames, i.e. a time range of animation.
402 */
403 void PVGUI_Module::setTimeRanges( double start, double end )
404 {
405   action(FirstFrameId)->setToolTip(QString("First Frame (%1)").arg(start, 0, 'g'));
406   action(LastFrameId)->setToolTip(QString("Last Frame (%1)").arg(end, 0, 'g'));
407 }
408
409 /*!
410   \brief Slot to manage the plaing process of animation.
411 */
412 void PVGUI_Module::onPlaying( bool playing )
413 {
414   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
415   if(playing) {
416     disconnect( action(PlayId),                        SIGNAL( triggered() ),
417                 &Implementation->Core.VCRController(), SLOT( onPlay() ) );
418     connect( action(PlayId),                        SIGNAL( triggered() ),
419              &Implementation->Core.VCRController(), SLOT( onPause() ) );
420     action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PAUSE"),false)));
421     action(PlayId)->setText("Pa&use");
422   }
423   else {
424     connect( action(PlayId),                        SIGNAL( triggered() ),
425              &Implementation->Core.VCRController(), SLOT( onPlay() ) );
426     disconnect( action(PlayId),                        SIGNAL( triggered() ),
427                 &Implementation->Core.VCRController(), SLOT( onPause() ) );
428     action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PLAY"),false)));
429     action(PlayId)->setText("&Play");
430   }
431
432   Implementation->Core.setSelectiveEnabledState(!playing);
433 }
434
435 /*!
436   \brief Slot to add camera link.
437 */
438 void PVGUI_Module::onAddCameraLink()
439 {
440   pqView* vm = pqActiveView::instance().current();
441   pqRenderView* rm = qobject_cast<pqRenderView*>(vm);
442   if(rm) rm->linkToOtherView();
443   else SUIT_MessageBox::warning(getApp()->desktop(),
444                                 tr("WARNING"), tr("WRN_ADD_CAMERA_LINK"));
445 }
446
447 /*!
448   \brief Slot to show information about ParaView.
449 */
450 void PVGUI_Module::onHelpAbout()
451 {
452   pqClientAboutDialog* const dialog = new pqClientAboutDialog(getApp()->desktop());
453   dialog->setAttribute(Qt::WA_DeleteOnClose);
454   dialog->show();
455 }
456
457 /*!
458   \brief Slot to show help for proxy.
459 */
460 void PVGUI_Module::showHelpForProxy( const QString& proxy )
461 {
462   // make sure assistant is ready
463   this->makeAssistant();
464
465   if(this->Implementation->AssistantClient) {
466     this->Implementation->AssistantClient->openAssistant();
467     QString page("%1/Documentation/%2.html");
468     page = page.arg(this->Implementation->DocumentationDir);
469     page = page.arg(proxy);
470     this->Implementation->AssistantClient->showPage(page);
471   }
472 }
473
474 QString Locate( const QString& appName )
475 {
476   QString app_dir = QCoreApplication::applicationDirPath();
477   const char* inst_dirs[] = {
478     "/./",
479     "/../bin/",
480     "/../../bin/",
481     0
482   };
483   for (const char** dir = inst_dirs; *dir; ++dir) {
484     QString path = app_dir;
485     path += *dir;
486     path += appName;
487     //cout << "Checking : " << path.toAscii().data() << " ... ";
488     //cout.flush();
489     QFileInfo finfo (path);
490     if (finfo.exists()) {
491       //cout << " Success!" << endl;
492       return path;
493     }
494     //cout << " Failed" << endl;
495   }
496   return app_dir + QDir::separator() + appName;
497 }
498
499 /*!
500   \brief Initialized an assistant client.
501 */
502 void PVGUI_Module::makeAssistant()
503 {
504   if(this->Implementation->AssistantClient)
505     return;
506   
507   QString assistantExe;
508   QString profileFile;
509   
510   const char* assistantName = "assistant";
511 #ifdef WNT
512   const char* binDir = "\\";
513   const char* binDir1 = "\\..\\";
514 #else
515   const char* binDir = "/bin/";
516   const char* binDir1 = "/bin/bin/";
517 #endif
518
519   QString helper = QString(getenv("PVHOME")) + binDir + QString("pqClientDocFinder.txt");
520   if(!QFile::exists(helper))
521     helper = QString(getenv("PVHOME")) + binDir1 + QString("pqClientDocFinder.txt");
522   if(QFile::exists(helper)) {
523     QFile file(helper);
524     if(file.open(QIODevice::ReadOnly)) {
525       assistantExe = file.readLine().trimmed();
526       profileFile = file.readLine().trimmed();
527       // CMake escapes spaces, we need to unescape those.
528       assistantExe.replace("\\ ", " ");
529       profileFile.replace("\\ ", " ");
530     }
531   }
532
533   if(assistantExe.isEmpty()) {
534     assistantExe = ::Locate(assistantName);//assistantExe = ::Locate(assistantProgName);
535     /*
536     QString assistant = QCoreApplication::applicationDirPath();
537     assistant += QDir::separator();
538     assistant += assistantName;
539     assistantExe = assistant;
540     */
541   }
542
543   this->Implementation->AssistantClient = new QAssistantClient(assistantExe, this);
544   QObject::connect(this->Implementation->AssistantClient, SIGNAL(error(const QString&)),
545                    this,                                  SLOT(assistantError(const QString&)));
546
547   QStringList args;
548   args.append(QString("-profile"));
549
550   if(profileFile.isEmpty()) {
551     // see if help is bundled up with the application
552     QString profile = ::Locate("pqClient.adp");
553     /*QCoreApplication::applicationDirPath() + QDir::separator()
554       + QString("pqClient.adp");*/
555     
556     if(QFile::exists(profile))
557       profileFile = profile;
558   }
559
560   if(profileFile.isEmpty() && getenv("PARAVIEW_HELP")) {
561     // not bundled, ask for help
562     args.append(getenv("PARAVIEW_HELP"));
563   }
564   else if(profileFile.isEmpty()) {
565     // no help, error out
566     SUIT_MessageBox::critical(getApp()->desktop(),"Help error", "Couldn't find"
567                               " pqClient.adp.\nTry setting the PARAVIEW_HELP environment variable which"
568                               " points to that file");
569     delete this->Implementation->AssistantClient;
570     return;
571   }
572
573   QFileInfo fi(profileFile);
574   this->Implementation->DocumentationDir = fi.absolutePath();
575
576   args.append(profileFile);
577
578   this->Implementation->AssistantClient->setArguments(args);
579 }
580
581 /*!
582   \brief Slot to call the message handler with the critical message.
583 */
584 void PVGUI_Module::assistantError( const QString& error )
585 {
586   qCritical(error.toAscii().data());
587 }
588
589 /*!
590   \brief Slot to show the waiting state.
591 */
592 void PVGUI_Module::onPreAccept()
593 {
594   getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
595   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
596 }
597
598 /*!
599   \brief Slot to show the ready state.
600 */
601 void PVGUI_Module::onPostAccept()
602 {
603   getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
604   QTimer::singleShot(0, this, SLOT(endWaitCursor()));
605 }
606
607 /*!
608   \brief Slot to switch off wait cursor.
609 */
610 void PVGUI_Module::endWaitCursor()
611 {
612   QApplication::restoreOverrideCursor();
613 }
614
615 /*!
616   \brief Returns the ParaView multi-view manager.
617 */
618 pqViewManager* PVGUI_Module::getMultiViewManager() const
619 {
620   pqViewManager* aMVM = 0; 
621   if ( Implementation )
622     aMVM = &Implementation->Core.multiViewManager();
623   return aMVM;
624 }
625
626 /*!
627   \brief Processes QEvent::ActionAdded and QEvent::ActionRemoved from Lookmarks toolbar
628   in order to register/unregister this action in/from QtxActionToolMgr.
629 */
630 bool PVGUI_Module::eventFilter( QObject* theObject, QEvent* theEvent )
631 {
632   QToolBar* aTB = toolMgr()->toolBar(tr("TOOL_LOOKMARKS"));
633   if ( theObject == aTB ) {
634     
635     if ( theEvent->type() == QEvent::ActionAdded ) {
636       QList<QAction*> anActns = aTB->actions();
637       for (int i = 0; i < anActns.size(); ++i)
638         if ( toolMgr()->actionId(anActns.at(i)) == -1 ) {
639           toolMgr()->setUpdatesEnabled(false);
640           createTool( anActns.at(i), tr("TOOL_LOOKMARKS") );
641           toolMgr()->setUpdatesEnabled(true);
642         }
643     }
644
645     if ( theEvent->type() == QEvent::ActionRemoved ) {
646       QList<QAction*> anActns = aTB->actions();
647       QIntList aIDL = toolMgr()->idList();
648       for (int i = 0; i < aIDL.size(); ++i) {
649         if ( toolMgr()->action(aIDL.at(i))->parent() == aTB
650              &&
651              !anActns.contains( toolMgr()->action(aIDL.at(i)) ) ) {
652           toolMgr()->setUpdatesEnabled(false);
653           toolMgr()->unRegisterAction( aIDL.at(i) );
654           toolMgr()->remove( aIDL.at(i), tr("TOOL_LOOKMARKS") );
655           toolMgr()->setUpdatesEnabled(true);
656         }
657       }
658     }
659     
660   }
661
662   return QObject::eventFilter( theObject, theEvent );
663 }
664
665 /*!
666   \brief Activate module.
667   \param study current study
668   \return \c true if activaion is done successfully or 0 to prevent
669   activation on error
670 */
671 bool PVGUI_Module::activateModule( SUIT_Study* study )
672 {
673   bool isDone = LightApp_Module::activateModule( study );
674   if ( !isDone ) return false;
675
676   if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
677   if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
678   setMenuShown( true );
679   setToolShown( true );
680
681   showView( true );
682
683   toolMgr()->toolBar(tr("TOOL_LOOKMARKS"))->installEventFilter(this);
684
685   // Make default server connection
686   if ( Implementation )
687     Implementation->Core.makeDefaultConnectionIfNoneExists();
688
689   return isDone;
690 }
691
692
693 /*!
694   \brief Deactivate module.
695   \param study current study
696   \return \c true if deactivaion is done successfully or 0 to prevent
697   deactivation on error
698 */
699 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
700 {
701   toolMgr()->toolBar(tr("TOOL_LOOKMARKS"))->removeEventFilter(this);
702
703   // hide menus
704   menuMgr()->hide(mySourcesMenuId);
705   menuMgr()->hide(myFiltersMenuId);
706   setMenuShown( false );
707   setToolShown( false );
708
709   saveDockWidgetsState();
710
711   return LightApp_Module::deactivateModule( study );
712 }
713
714 /*!
715   \fn CAM_Module* createModule();
716   \brief Export module instance (factory function).
717   \return new created instance of the module
718 */
719
720 #ifdef WNT
721 #define PVGUI_EXPORT __declspec(dllexport)
722 #else   // WNT
723 #define PVGUI_EXPORT
724 #endif  // WNT
725
726 extern "C" {
727   PVGUI_EXPORT CAM_Module* createModule() {
728     return new PVGUI_Module();
729   }
730 }