1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : PVGUI_Module.cxx
23 // Author : Julia DOROVSKIKH
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"
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 <QtxActionToolMgr.h>
42 #include <QApplication>
48 #include <QInputDialog>
51 #include <QStringList>
55 #include <pqApplicationCore.h>
56 #include <pqActiveServer.h>
57 #include <pqActiveView.h>
58 #include <pqClientAboutDialog.h>
59 #include <pqObjectBuilder.h>
60 #include <pqOptions.h>
61 #include <pqRenderView.h>
62 #include <pqRubberBandHelper.h>
64 #include <pqServerManagerModel.h>
65 #include <pqServerResource.h>
66 #include <pqUndoStack.h>
67 #include <pqVCRController.h>
68 #include <pqViewManager.h>
69 #include <vtkPVMain.h>
70 #include <vtkProcessModule.h>
73 * Make sure all the kits register their classes with vtkInstantiator.
74 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
75 * anyway. The instantiators will add no more code for the linker to
79 #include <vtkCommonInstantiator.h>
80 #include <vtkFilteringInstantiator.h>
81 #include <vtkGenericFilteringInstantiator.h>
82 #include <vtkIOInstantiator.h>
83 #include <vtkImagingInstantiator.h>
84 #include <vtkInfovisInstantiator.h>
85 #include <vtkGraphicsInstantiator.h>
87 #include <vtkRenderingInstantiator.h>
88 #include <vtkVolumeRenderingInstantiator.h>
89 #include <vtkHybridInstantiator.h>
90 #include <vtkParallelInstantiator.h>
92 #include <vtkPVServerCommonInstantiator.h>
93 #include <vtkPVFiltersInstantiator.h>
94 #include <vtkPVServerManagerInstantiator.h>
95 #include <vtkClientServerInterpreter.h>
98 //----------------------------------------------------------------------------
99 // ClientServer wrapper initialization functions.
100 // Taken from ParaView sources (file pqMain.cxx)
101 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
102 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
103 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
104 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
105 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
106 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
107 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
108 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
109 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
110 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
111 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
112 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
113 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
114 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
115 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
117 //----------------------------------------------------------------------------
118 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
120 // Initialize built-in wrapper modules.
121 vtkCommonCS_Initialize(pm->GetInterpreter());
122 vtkFilteringCS_Initialize(pm->GetInterpreter());
123 vtkGenericFilteringCS_Initialize(pm->GetInterpreter());
124 vtkImagingCS_Initialize(pm->GetInterpreter());
125 vtkInfovisCS_Initialize(pm->GetInterpreter());
126 vtkGraphicsCS_Initialize(pm->GetInterpreter());
127 vtkIOCS_Initialize(pm->GetInterpreter());
128 vtkRenderingCS_Initialize(pm->GetInterpreter());
129 vtkVolumeRenderingCS_Initialize(pm->GetInterpreter());
130 vtkHybridCS_Initialize(pm->GetInterpreter());
131 vtkWidgetsCS_Initialize(pm->GetInterpreter());
132 vtkParallelCS_Initialize(pm->GetInterpreter());
133 vtkPVServerCommonCS_Initialize(pm->GetInterpreter());
134 vtkPVFiltersCS_Initialize(pm->GetInterpreter());
135 vtkXdmfCS_Initialize(pm->GetInterpreter());
138 vtkPVMain* PVGUI_Module::pqImplementation::myPVMain = 0;
139 pqOptions* PVGUI_Module::pqImplementation::myPVOptions = 0;
140 PVGUI_ProcessModuleHelper* PVGUI_Module::pqImplementation::myPVHelper = 0;
144 \brief Implementation of light (no-CORBA-engine)
145 SALOME module wrapping ParaView GUI.
149 \brief Constructor. Sets the default name for the module.
151 PVGUI_Module::PVGUI_Module()
152 : LightApp_Module( "PARAVIS" ),
160 PVGUI_Module::~PVGUI_Module()
165 \brief Initialize module. Creates menus, prepares context menu, etc.
166 \param app application instance
168 void PVGUI_Module::initialize( CAM_Application* app )
170 LightApp_Module::initialize( app );
172 // Uncomment to debug ParaView initialization
173 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
186 \brief Get list of compliant dockable GUI elements
187 \param m map to be filled in ("type":"default_position")
189 void PVGUI_Module::windows( QMap<int, int>& m ) const
191 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
192 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
193 // ParaView diagnostic output redirected here
194 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
198 \brief Create custom popup menu selection object.
199 \return new selected object
201 /*LightApp_Selection* PVGUI_Module::createSelection() const
203 return new PVGUI_Selection();
207 \brief Create data model.
208 \return module specific data model
210 /*CAM_DataModel* PVGUI_Module::createDataModel()
212 return new PVGUI_DataModel( this );
216 \brief Static method, performs initialization of ParaView session.
217 \return \c true if ParaView has been initialized successfully, otherwise false
219 bool PVGUI_Module::pvInit()
221 if ( !pqImplementation::myPVMain ){
222 // Obtain command-line arguments
224 QStringList args = QApplication::arguments();
225 char** argv = new char*[args.size()];
226 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
227 argv[argc] = strdup( (*it).toLatin1().constData() );
229 vtkPVMain::SetInitializeMPI(0); // pvClient never runs with MPI.
230 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
232 // TODO: Set plugin dir from preferences
233 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
235 pqImplementation::myPVMain = vtkPVMain::New();
236 if ( !pqImplementation::myPVOptions )
237 pqImplementation::myPVOptions = pqOptions::New();
238 if ( !pqImplementation::myPVHelper )
239 pqImplementation::myPVHelper = PVGUI_ProcessModuleHelper::New();
241 pqImplementation::myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
243 // This creates the Process Module and initializes it.
244 int ret = pqImplementation::myPVMain->Initialize(pqImplementation::myPVOptions,
245 pqImplementation::myPVHelper,
246 ParaViewInitializeInterpreter,
249 // Tell process module that we support Multiple connections.
250 // This must be set before starting the event loop.
251 vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
252 ret = pqImplementation::myPVHelper->Run(pqImplementation::myPVOptions);
263 \brief Static method, cleans up ParaView session at application exit.
265 void PVGUI_Module::pvShutdown()
271 \brief Shows (toShow = true) or hides ParaView view window
273 void PVGUI_Module::showView( bool toShow )
275 // TODO: check if ParaView view already exists
276 if ( !Implementation ){
277 LightApp_Application* anApp = getApp();
278 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
279 PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
280 anApp->addViewManager( viewMgr );
281 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
282 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
283 //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
284 //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
285 SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
287 // Simulate ParaView client main window
288 Implementation = new pqImplementation( anApp->desktop() );
289 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( wnd );
290 pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() );
298 setupDockWidgetsContextMenu();
300 // Now that we're ready, initialize everything ...
301 Implementation->Core.initializeStates();
306 \brief Manage the label of Undo operation.
308 void PVGUI_Module::onUndoLabel( const QString& label )
310 action(UndoId)->setText(
311 label.isEmpty() ? tr("Can't Undo") : QString(tr("&Undo %1")).arg(label));
312 action(UndoId)->setStatusTip(
313 label.isEmpty() ? tr("Can't Undo") : QString(tr("Undo %1")).arg(label));
317 \brief Manage the label of Redo operation.
319 void PVGUI_Module::onRedoLabel( const QString& label )
321 action(RedoId)->setText(
322 label.isEmpty() ? tr("Can't Redo") : QString(tr("&Redo %1")).arg(label));
323 action(RedoId)->setStatusTip(
324 label.isEmpty() ? tr("Can't Redo") : QString(tr("Redo %1")).arg(label));
328 \brief Manage the label of Undo Camera operation.
330 void PVGUI_Module::onCameraUndoLabel( const QString& label )
332 action(CameraUndoId)->setText(
333 label.isEmpty() ? tr("Can't Undo Camera") : QString(tr("U&ndo %1")).arg(label));
334 action(CameraUndoId)->setStatusTip(
335 label.isEmpty() ? tr("Can't Undo Camera") : QString(tr("Undo %1")).arg(label));
339 \brief Manage the label of Redo Camera operation.
341 void PVGUI_Module::onCameraRedoLabel( const QString& label )
343 action(CameraRedoId)->setText(
344 label.isEmpty() ? tr("Can't Redo Camera") : QString(tr("R&edo %1")).arg(label));
345 action(CameraRedoId)->setStatusTip(
346 label.isEmpty() ? tr("Can't Redo Camera") : QString(tr("Redo %1")).arg(label));
350 \brief Slot to delete all objects.
352 void PVGUI_Module::onDeleteAll()
354 pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
355 Implementation->Core.getApplicationUndoStack()->beginUndoSet("Delete All");
356 builder->destroyPipelineProxies();
357 Implementation->Core.getApplicationUndoStack()->endUndoSet();
361 \brief Slot to check/uncheck the action for corresponding selection mode.
363 void PVGUI_Module::onSelectionModeChanged( int mode )
365 if( toolMgr()->toolBar( mySelectionControlsTb )->isEnabled() ) {
366 if(mode == pqRubberBandHelper::SELECT) //surface selection
367 action(SelectCellsOnId)->setChecked(true);
368 else if(mode == pqRubberBandHelper::SELECT_POINTS) //surface selection
369 action(SelectPointsOnId)->setChecked(true);
370 else if(mode == pqRubberBandHelper::FRUSTUM)
371 action(SelectCellsThroughId)->setChecked(true);
372 else if(mode == pqRubberBandHelper::FRUSTUM_POINTS)
373 action(SelectPointsThroughId)->setChecked(true);
374 else if (mode == pqRubberBandHelper::BLOCKS)
375 action(SelectBlockId)->setChecked(true);
377 action(InteractId)->setChecked(true);
382 \brief Slot to manage the change of axis center.
384 void PVGUI_Module::onShowCenterAxisChanged( bool enabled )
386 action(ShowCenterId)->setEnabled(enabled);
387 action(ShowCenterId)->blockSignals(true);
388 pqRenderView* renView = qobject_cast<pqRenderView*>(
389 pqActiveView::instance().current());
390 action(ShowCenterId)->setChecked( renView ? renView->getCenterAxesVisibility() : false);
391 action(ShowCenterId)->blockSignals(false);
395 \brief Slot to set tooltips for the first anf the last frames, i.e. a time range of animation.
397 void PVGUI_Module::setTimeRanges( double start, double end )
399 action(FirstFrameId)->setToolTip(QString("First Frame (%1)").arg(start, 0, 'g'));
400 action(LastFrameId)->setToolTip(QString("Last Frame (%1)").arg(end, 0, 'g'));
404 \brief Slot to manage the plaing process of animation.
406 void PVGUI_Module::onPlaying( bool playing )
408 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
410 disconnect( action(PlayId), SIGNAL( triggered() ),
411 &Implementation->Core.VCRController(), SLOT( onPlay() ) );
412 connect( action(PlayId), SIGNAL( triggered() ),
413 &Implementation->Core.VCRController(), SLOT( onPause() ) );
414 action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PAUSE"),false)));
415 action(PlayId)->setText("Pa&use");
418 connect( action(PlayId), SIGNAL( triggered() ),
419 &Implementation->Core.VCRController(), SLOT( onPlay() ) );
420 disconnect( action(PlayId), SIGNAL( triggered() ),
421 &Implementation->Core.VCRController(), SLOT( onPause() ) );
422 action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PLAY"),false)));
423 action(PlayId)->setText("&Play");
426 Implementation->Core.setSelectiveEnabledState(!playing);
430 \brief Slot to add camera link.
432 void PVGUI_Module::onAddCameraLink()
434 pqView* vm = pqActiveView::instance().current();
435 pqRenderView* rm = qobject_cast<pqRenderView*>(vm);
436 if(rm) rm->linkToOtherView();
437 else SUIT_MessageBox::warning(getApp()->desktop(),
438 tr("WARNING"), tr("WRN_ADD_CAMERA_LINK"));
442 \brief Slot to show information about ParaView.
444 void PVGUI_Module::onHelpAbout()
446 pqClientAboutDialog* const dialog = new pqClientAboutDialog(getApp()->desktop());
447 dialog->setAttribute(Qt::WA_DeleteOnClose);
452 \brief Slot to show help for proxy.
454 void PVGUI_Module::showHelpForProxy( const QString& proxy )
456 // make sure assistant is ready
457 this->makeAssistant();
459 if(this->Implementation->AssistantClient) {
460 this->Implementation->AssistantClient->openAssistant();
461 QString page("%1/Documentation/%2.html");
462 page = page.arg(this->Implementation->DocumentationDir);
463 page = page.arg(proxy);
464 this->Implementation->AssistantClient->showPage(page);
468 QString Locate( const QString& appName )
470 QString app_dir = QCoreApplication::applicationDirPath();
471 const char* inst_dirs[] = {
477 for (const char** dir = inst_dirs; *dir; ++dir) {
478 QString path = app_dir;
481 //cout << "Checking : " << path.toAscii().data() << " ... ";
483 QFileInfo finfo (path);
484 if (finfo.exists()) {
485 //cout << " Success!" << endl;
488 //cout << " Failed" << endl;
490 return app_dir + QDir::separator() + appName;
494 \brief Initialized an assistant client.
496 void PVGUI_Module::makeAssistant()
498 if(this->Implementation->AssistantClient)
501 QString assistantExe;
504 const char* assistantName = "assistant";
506 const char* binDir = "\\";
507 const char* binDir1 = "\\..\\";
509 const char* binDir = "/bin/";
510 const char* binDir1 = "/bin/bin/";
513 QString helper = QString(getenv("PVHOME")) + binDir + QString("pqClientDocFinder.txt");
514 if(!QFile::exists(helper))
515 helper = QString(getenv("PVHOME")) + binDir1 + QString("pqClientDocFinder.txt");
516 if(QFile::exists(helper)) {
518 if(file.open(QIODevice::ReadOnly)) {
519 assistantExe = file.readLine().trimmed();
520 profileFile = file.readLine().trimmed();
521 // CMake escapes spaces, we need to unescape those.
522 assistantExe.replace("\\ ", " ");
523 profileFile.replace("\\ ", " ");
527 if(assistantExe.isEmpty()) {
528 assistantExe = ::Locate(assistantName);//assistantExe = ::Locate(assistantProgName);
530 QString assistant = QCoreApplication::applicationDirPath();
531 assistant += QDir::separator();
532 assistant += assistantName;
533 assistantExe = assistant;
537 this->Implementation->AssistantClient = new QAssistantClient(assistantExe, this);
538 QObject::connect(this->Implementation->AssistantClient, SIGNAL(error(const QString&)),
539 this, SLOT(assistantError(const QString&)));
542 args.append(QString("-profile"));
544 if(profileFile.isEmpty()) {
545 // see if help is bundled up with the application
546 QString profile = ::Locate("pqClient.adp");
547 /*QCoreApplication::applicationDirPath() + QDir::separator()
548 + QString("pqClient.adp");*/
550 if(QFile::exists(profile))
551 profileFile = profile;
554 if(profileFile.isEmpty() && getenv("PARAVIEW_HELP")) {
555 // not bundled, ask for help
556 args.append(getenv("PARAVIEW_HELP"));
558 else if(profileFile.isEmpty()) {
559 // no help, error out
560 SUIT_MessageBox::critical(getApp()->desktop(),"Help error", "Couldn't find"
561 " pqClient.adp.\nTry setting the PARAVIEW_HELP environment variable which"
562 " points to that file");
563 delete this->Implementation->AssistantClient;
567 QFileInfo fi(profileFile);
568 this->Implementation->DocumentationDir = fi.absolutePath();
570 args.append(profileFile);
572 this->Implementation->AssistantClient->setArguments(args);
576 \brief Slot to call the message handler with the critical message.
578 void PVGUI_Module::assistantError( const QString& error )
580 qCritical(error.toAscii().data());
584 \brief Slot to show the waiting state.
586 void PVGUI_Module::onPreAccept()
588 getApp()->desktop()->statusBar()->showMessage(tr("Updating..."));
589 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
593 \brief Slot to show the ready state.
595 void PVGUI_Module::onPostAccept()
597 getApp()->desktop()->statusBar()->showMessage(tr("Ready"), 2000);
598 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
602 \brief Slot to switch off wait cursor.
604 void PVGUI_Module::endWaitCursor()
606 QApplication::restoreOverrideCursor();
610 \brief Returns the ParaView multi-view manager.
612 pqViewManager* PVGUI_Module::getMultiViewManager() const
614 pqViewManager* aMVM = 0;
615 if ( Implementation )
616 aMVM = &Implementation->Core.multiViewManager();
621 \brief Activate module.
622 \param study current study
623 \return \c true if activaion is done successfully or 0 to prevent
626 bool PVGUI_Module::activateModule( SUIT_Study* study )
628 bool isDone = LightApp_Module::activateModule( study );
629 if ( !isDone ) return false;
631 setMenuShown( true );
635 // Make default server connection
636 if ( Implementation )
637 Implementation->Core.makeDefaultConnectionIfNoneExists();
644 \brief Deactivate module.
645 \param study current study
646 \return \c true if deactivaion is done successfully or 0 to prevent
647 deactivation on error
649 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
652 setMenuShown( false );
654 return LightApp_Module::deactivateModule( study );
658 \fn CAM_Module* createModule();
659 \brief Export module instance (factory function).
660 \return new created instance of the module
664 #define PVGUI_EXPORT __declspec(dllexport)
670 PVGUI_EXPORT CAM_Module* createModule() {
671 return new PVGUI_Module();