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"
28 #include "SALOMEconfig.h"
29 #include CORBA_CLIENT_HEADER(VISU_Gen)
30 #include CORBA_SERVER_HEADER(SALOMEDS)
33 #include "PARAVIS_Gen_i.hh"
35 #include "PVGUI_Module_impl.h"
36 #include "PVGUI_ProcessModuleHelper.h"
37 #include "PVGUI_ViewModel.h"
38 #include "PVGUI_ViewManager.h"
39 #include "PVGUI_ViewWindow.h"
40 #include "PVGUI_Tools.h"
41 #include "PVGUI_Trace.h"
43 #include <SUIT_Desktop.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_OverrideCursor.h>
50 #include "SALOME_LifeCycleCORBA.hxx"
51 #include "SALOME_ListIteratorOfListIO.hxx"
52 #include "SALOMEDS_SObject.hxx"
54 //#include <LightApp_Application.h>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58 #include <SALOME_ListIO.hxx>
59 #include <SALOMEDS_Tool.hxx>
61 #include <QtxActionMenuMgr.h>
62 #include <QtxActionToolMgr.h>
65 #include <QApplication>
71 #include <QInputDialog>
74 #include <QStringList>
78 #include <pqApplicationCore.h>
79 #include <pqActiveView.h>
80 #include <pqClientAboutDialog.h>
81 #include <pqObjectBuilder.h>
82 #include <pqOptions.h>
83 #include <pqRenderView.h>
84 #include <pqRubberBandHelper.h>
86 //#include <pqServerManagerModel.h>
87 //#include <pqServerResource.h>
88 #include <pqUndoStack.h>
89 #include <pqVCRController.h>
90 #include <pqViewManager.h>
91 #include <pqPipelineSource.h>
92 #include <vtkPVMain.h>
93 #include <vtkProcessModule.h>
96 * Make sure all the kits register their classes with vtkInstantiator.
97 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
98 * anyway. The instantiators will add no more code for the linker to
102 #include <vtkCommonInstantiator.h>
103 #include <vtkFilteringInstantiator.h>
104 #include <vtkGenericFilteringInstantiator.h>
105 #include <vtkIOInstantiator.h>
106 #include <vtkImagingInstantiator.h>
107 #include <vtkInfovisInstantiator.h>
108 #include <vtkGraphicsInstantiator.h>
110 #include <vtkRenderingInstantiator.h>
111 #include <vtkVolumeRenderingInstantiator.h>
112 #include <vtkHybridInstantiator.h>
113 #include <vtkParallelInstantiator.h>
115 //#include <vtkPVServerCommonInstantiator.h>
116 //#include <vtkPVFiltersInstantiator.h>
117 //#include <vtkPVServerManagerInstantiator.h>
118 //#include <vtkClientServerInterpreter.h>
122 //----------------------------------------------------------------------------
123 // ClientServer wrapper initialization functions.
124 // Taken from ParaView sources (file pqMain.cxx)
125 extern "C" void vtkCommonCS_Initialize(vtkClientServerInterpreter*);
126 extern "C" void vtkFilteringCS_Initialize(vtkClientServerInterpreter*);
127 extern "C" void vtkGenericFilteringCS_Initialize(vtkClientServerInterpreter*);
128 extern "C" void vtkImagingCS_Initialize(vtkClientServerInterpreter*);
129 extern "C" void vtkInfovisCS_Initialize(vtkClientServerInterpreter*);
130 extern "C" void vtkGraphicsCS_Initialize(vtkClientServerInterpreter*);
131 extern "C" void vtkIOCS_Initialize(vtkClientServerInterpreter*);
132 extern "C" void vtkRenderingCS_Initialize(vtkClientServerInterpreter*);
133 extern "C" void vtkVolumeRenderingCS_Initialize(vtkClientServerInterpreter*);
134 extern "C" void vtkHybridCS_Initialize(vtkClientServerInterpreter*);
135 extern "C" void vtkWidgetsCS_Initialize(vtkClientServerInterpreter*);
136 extern "C" void vtkParallelCS_Initialize(vtkClientServerInterpreter*);
137 extern "C" void vtkPVServerCommonCS_Initialize(vtkClientServerInterpreter*);
138 extern "C" void vtkPVFiltersCS_Initialize(vtkClientServerInterpreter*);
139 extern "C" void vtkXdmfCS_Initialize(vtkClientServerInterpreter *);
142 //----------------------------------------------------------------------------
143 void ParaViewInitializeInterpreter(vtkProcessModule* pm)
145 vtkClientServerInterpreter* interp = pm->GetInterpreter();
146 // Initialize built-in wrapper modules.
147 vtkCommonCS_Initialize(interp);
148 vtkFilteringCS_Initialize(interp);
149 vtkGenericFilteringCS_Initialize(interp);
150 vtkImagingCS_Initialize(interp);
151 vtkInfovisCS_Initialize(interp);
152 vtkGraphicsCS_Initialize(interp);
153 vtkIOCS_Initialize(interp);
154 vtkRenderingCS_Initialize(interp);
155 vtkVolumeRenderingCS_Initialize(interp);
156 vtkHybridCS_Initialize(interp);
157 vtkWidgetsCS_Initialize(interp);
158 vtkParallelCS_Initialize(interp);
159 vtkPVServerCommonCS_Initialize(interp);
160 vtkPVFiltersCS_Initialize(interp);
161 vtkXdmfCS_Initialize(interp);
164 vtkPVMain* PVGUI_Module::pqImplementation::myPVMain = 0;
165 pqOptions* PVGUI_Module::pqImplementation::myPVOptions = 0;
166 PVGUI_ProcessModuleHelper* PVGUI_Module::pqImplementation::myPVHelper = 0;
168 PVGUI_Module* ParavisModule = 0;
173 <h2>Building and installing PARAVIS</h2>
174 As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
175 installation directory.
176 Other variables needed for correct detection of ParaView location:
177 \li PVHOME - points at the ParaView installation directory tree
178 \li PVVERSION - number of ParaView version
180 It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
182 As soon as the environment is set, excute the following commands in a shell:
186 ../PARAVIS_SRC/build_configure
187 ../PARAVIS_SRC/configure --prefix=${PARAVIS_ROOT_DIR} -with-paraview
193 PARAVIS module can be launched using the following commands:
194 \li Full SALOME configuration
196 runSalome --modules="PARAVIS"
199 <h2>ParaView GUI integration</h2>
200 <h3>ParaView GUI integration overview</h3>
202 The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
203 between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
205 \li SALOME GUI executable and Qt event loop
206 \li SALOME GUI desktop
207 \li Dock windows areas
208 \li SALOME menu and toolbar managers
210 Major part of the integration is implemented in PVGUI_Module class.
212 <h3>ParaView client initalization</h3>
214 ParaView client initalization is performed when an instance of PVGUI_Module class has been created
215 and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
216 The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
217 It simulates actions perfomed by pqMain::Run( QApplication&, pqProcessModuleGUIHelper* ) method.
219 Custom PVGUI_ProcessModuleHelper class derived from %pqProcessModuleGUIHelper base is the main actor in ParaView
220 client initialization. It initializes the client that uses the main window (SALOME desktop) supplied from the outside,
221 it does not start Qt event loop as this is done in SALOME GUI executable (SUITApp or SALOME_Session_Server), and after all
222 it redirects ParaView diagnostic output to SALOME LogWindow with help of PVGUI_OutputWindowAdapter class.
223 This is achieved by reimplementing \link PVGUI_ProcessModuleHelper::InitializeApplication() InitializeApplication()\endlink,
224 \link PVGUI_ProcessModuleHelper::appExec() appExec()\endlink, \link PVGUI_ProcessModuleHelper::postAppExec() postAppExec()\endlink
225 virtual methods as well as those responsible for main window management.
227 <h3>ParaView GUI connection to SALOME desktop</h3>
229 ParaView Qt components include pqMainWindowCore class that handles most ParaView GUI client actions,
230 updates menu states and connects many GUI components.
231 After the client initalization \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method creates
232 an instance of internal PVGUI_Module::pqImplementation class (declared PVGUI_Module_impl.h) that wraps some ParaView GUI components:
233 pqMainWindowCore, pqServer, etc. Instance of SALOME desktop widget is passed to pqMainWindowCore instead of ParaView main window.
235 Basically it simulates constructor of ParaView client's %MainWindow class (src/Applications/Client/MainWindow.cxx). It creates the same
236 menu and toolbar commands using SALOME menu and toolbar managers, connecting the actions to %pqMainWindowCore slots or to the module's
237 slots in some cases. It also sets up dock widgets for ParaView widgets, such as object inspector, pipeline browser, etc.
239 ParaView GUI resources (icons) are reused directly from the ParaView resource directory, they are loaded into SALOME GUI
240 resource manager, the path to these icons is specified in PARAVIS configuration XML files (LightApp.xml and SlomeApp.xml).
242 As both SALOME destop and ParaView main window classes inherit QMainWindow and %pqMainWindowCore deals with QMainWindow API to control
243 menus, tollbars and dock widgets, its integration into SALOME GUI is straightforward and smooth.
245 <h3>Multi-view manager</h3>
247 SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
250 \li PVGUI_ViewManager - view manager class
251 \li PVGUI_Viewer - view model class
252 \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
254 Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
255 PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
256 when the module is deactivated (the user switches to another module or a study is closed).
257 A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
258 with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
259 \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
260 of %pqViewManager widget that would break %pqMainWindowCore class.
262 <h3>ParaView plugins</h3>
263 ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
264 As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
266 <h2>Limitations of 2008 year prototype</h2>
267 \li SALOME persistence (possibility to save the module data into a tsudy file) is not implemented for PARAVIS module.
268 \li As a light module, PARAVIS does not have a CORBA engine that follows SALOME rules, however PARAVIS can use load a CORBA engine
269 on its own if needed.
274 \brief Implementation of light (no-CORBA-engine)
275 SALOME module wrapping ParaView GUI.
279 \brief Constructor. Sets the default name for the module.
281 PVGUI_Module::PVGUI_Module()
282 : SalomeApp_Module( "PARAVIS" ),
283 LightApp_Module( "PARAVIS" ),
285 mySelectionControlsTb( -1 ),
286 mySourcesMenuId( -1 ),
287 myFiltersMenuId( -1 )
289 ParavisModule = this;
295 PVGUI_Module::~PVGUI_Module()
300 \brief Initialize module. Creates menus, prepares context menu, etc.
301 \param app SALOME GUI application instance
303 void PVGUI_Module::initialize( CAM_Application* app )
305 SalomeApp_Module::initialize( app );
307 // Uncomment to debug ParaView initialization
308 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
316 // Initialize ParaView client
319 // Create GUI elements (menus, toolbars, dock widgets)
320 if ( !Implementation ){
321 SalomeApp_Application* anApp = getApp();
323 // Simulate ParaView client main window
324 Implementation = new pqImplementation( anApp->desktop() );
332 setupDockWidgetsContextMenu();
334 // Now that we're ready, initialize everything ...
335 Implementation->Core.initializeStates();
337 // Force creation of engine
338 PARAVIS::GetParavisGen(this);
342 QCoreApplication::processEvents();
344 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
345 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
347 QTimer::singleShot(500, this, SLOT(activateTrace()));
352 void PVGUI_Module::activateTrace()
360 \brief Get list of compliant dockable GUI elements
361 \param m map to be filled in ("type":"default_position")
363 void PVGUI_Module::windows( QMap<int, int>& m ) const
365 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
366 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
367 // ParaView diagnostic output redirected here
368 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
372 \brief Static method, performs initialization of ParaView session.
373 \return \c true if ParaView has been initialized successfully, otherwise false
375 bool PVGUI_Module::pvInit()
377 if ( !pqImplementation::myPVMain ){
378 // Obtain command-line arguments
380 QStringList args = QApplication::arguments();
381 char** argv = new char*[args.size()];
382 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ )
383 argv[argc] = strdup( (*it).toLatin1().constData() );
385 vtkPVMain::SetUseMPI(0); // pvClient never runs with MPI.
386 vtkPVMain::Initialize(&argc, &argv); // Perform any initializations.
388 // TODO: Set plugin dir from preferences
389 //QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
391 pqImplementation::myPVMain = vtkPVMain::New();
392 if ( !pqImplementation::myPVOptions )
393 pqImplementation::myPVOptions = pqOptions::New();
394 if ( !pqImplementation::myPVHelper )
395 pqImplementation::myPVHelper = PVGUI_ProcessModuleHelper::New();
397 pqImplementation::myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
399 // This creates the Process Module and initializes it.
400 int ret = pqImplementation::myPVMain->Initialize(pqImplementation::myPVOptions,
401 pqImplementation::myPVHelper,
402 ParaViewInitializeInterpreter,
405 // Tell process module that we support Multiple connections.
406 // This must be set before starting the event loop.
407 vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
408 ret = pqImplementation::myPVHelper->Run(pqImplementation::myPVOptions);
412 free(argv[0]); // because in creation argc < 1
421 \brief Static method, cleans up ParaView session at application exit.
423 void PVGUI_Module::pvShutdown()
425 if ( pqImplementation::myPVHelper )
426 pqImplementation::myPVHelper->finalize();
430 \brief Shows (toShow = true) or hides ParaView view window
432 void PVGUI_Module::showView( bool toShow )
434 SalomeApp_Application* anApp = getApp();
435 PVGUI_ViewManager* viewMgr = dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
437 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
438 anApp->addViewManager( viewMgr );
439 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
440 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
443 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
445 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
446 pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() );
449 pvWnd->setShown( toShow );
453 \brief Manage the label of Undo operation.
455 void PVGUI_Module::onUndoLabel( const QString& label )
457 action(UndoId)->setText(
458 label.isEmpty() ? tr("MEN_CANTUNDO") : QString(tr("MEN_UNDO_ACTION")).arg(label));
459 action(UndoId)->setStatusTip(
460 label.isEmpty() ? tr("MEN_CANTUNDO") : QString(tr("MEN_UNDO_ACTION_TIP")).arg(label));
464 \brief Manage the label of Redo operation.
466 void PVGUI_Module::onRedoLabel( const QString& label )
468 action(RedoId)->setText(
469 label.isEmpty() ? tr("MEN_CANTREDO") : QString(tr("MEN_REDO_ACTION")).arg(label));
470 action(RedoId)->setStatusTip(
471 label.isEmpty() ? tr("MEN_CANTREDO") : QString(tr("MEN_REDO_ACTION_TIP")).arg(label));
475 \brief Manage the label of Undo Camera operation.
477 void PVGUI_Module::onCameraUndoLabel( const QString& label )
479 action(CameraUndoId)->setText(
480 label.isEmpty() ? tr("MEN_CANT_CAMERA_UNDO") : QString(tr("MEN_CAMERA_UNDO_ACTION")).arg(label));
481 action(CameraUndoId)->setStatusTip(
482 label.isEmpty() ? tr("MEN_CANT_CAMERA_UNDO") : QString(tr("MEN_CAMERA_UNDO_ACTION_TIP")).arg(label));
486 \brief Manage the label of Redo Camera operation.
488 void PVGUI_Module::onCameraRedoLabel( const QString& label )
490 action(CameraRedoId)->setText(
491 label.isEmpty() ? tr("MEN_CANT_CAMERA_REDO") : QString(tr("MEN_CAMERA_REDO_ACTION")).arg(label));
492 action(CameraRedoId)->setStatusTip(
493 label.isEmpty() ? tr("MEN_CANT_CAMERA_REDO") : QString(tr("MEN_CAMERA_REDO_ACTION_TIP")).arg(label));
497 \brief Slot to delete all objects.
499 void PVGUI_Module::onDeleteAll()
501 pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
502 Implementation->Core.getApplicationUndoStack()->beginUndoSet("Delete All");
503 builder->destroyPipelineProxies();
504 Implementation->Core.getApplicationUndoStack()->endUndoSet();
508 \brief Slot to check/uncheck the action for corresponding selection mode.
510 void PVGUI_Module::onSelectionModeChanged( int mode )
512 if( toolMgr()->toolBar( mySelectionControlsTb )->isEnabled() ) {
513 if(mode == pqRubberBandHelper::SELECT) //surface selection
514 action(SelectCellsOnId)->setChecked(true);
515 else if(mode == pqRubberBandHelper::SELECT_POINTS) //surface selection
516 action(SelectPointsOnId)->setChecked(true);
517 else if(mode == pqRubberBandHelper::FRUSTUM)
518 action(SelectCellsThroughId)->setChecked(true);
519 else if(mode == pqRubberBandHelper::FRUSTUM_POINTS)
520 action(SelectPointsThroughId)->setChecked(true);
521 else if (mode == pqRubberBandHelper::BLOCKS)
522 action(SelectBlockId)->setChecked(true);
524 action(InteractId)->setChecked(true);
529 \brief Slot to manage the change of axis center.
531 void PVGUI_Module::onShowCenterAxisChanged( bool enabled )
533 action(ShowCenterId)->setEnabled(enabled);
534 action(ShowCenterId)->blockSignals(true);
535 pqRenderView* renView = qobject_cast<pqRenderView*>(
536 pqActiveView::instance().current());
537 action(ShowCenterId)->setChecked( renView ? renView->getCenterAxesVisibility() : false);
538 action(ShowCenterId)->blockSignals(false);
542 \brief Slot to set tooltips for the first anf the last frames, i.e. a time range of animation.
544 void PVGUI_Module::setTimeRanges( double start, double end )
546 action(FirstFrameId)->setToolTip(QString("First Frame (%1)").arg(start, 0, 'g'));
547 action(LastFrameId)->setToolTip(QString("Last Frame (%1)").arg(end, 0, 'g'));
551 void PVGUI_Module::connectToPlay()
553 connect( action(PlayId), SIGNAL( triggered() ), &Implementation->Core.VCRController(), SLOT( onPlay() ) );
558 \brief Slot to manage the plaing process of animation.
560 void PVGUI_Module::onPlaying( bool playing )
562 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
564 disconnect( action(PlayId), SIGNAL( triggered() ),&Implementation->Core.VCRController(), SLOT( onPlay() ) );
565 connect( action(PlayId), SIGNAL( triggered() ), &Implementation->Core.VCRController(), SLOT( onPause() ) );
566 action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PAUSE"),false)));
567 action(PlayId)->setText("Pa&use");
570 // Immediate connecting toPlay doubles event
571 QTimer::singleShot(10, this, SLOT(connectToPlay()));
572 //connect( action(PlayId), SIGNAL( triggered() ), &Implementation->Core.VCRController(), SLOT( onPlay() ) );
573 disconnect( action(PlayId), SIGNAL( triggered() ), &Implementation->Core.VCRController(), SLOT( onPause() ) );
574 action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PLAY"),false)));
575 action(PlayId)->setText("&Play");
578 Implementation->Core.setSelectiveEnabledState(!playing);
582 \brief Slot to add camera link.
584 void PVGUI_Module::onAddCameraLink()
586 pqView* vm = pqActiveView::instance().current();
587 pqRenderView* rm = qobject_cast<pqRenderView*>(vm);
588 if(rm) rm->linkToOtherView();
589 else SUIT_MessageBox::warning(getApp()->desktop(),
590 tr("WARNING"), tr("WRN_ADD_CAMERA_LINK"));
594 \brief Slot to show information about ParaView.
596 void PVGUI_Module::onHelpAbout()
598 pqClientAboutDialog* const dialog = new pqClientAboutDialog(getApp()->desktop());
599 dialog->setAttribute(Qt::WA_DeleteOnClose);
604 \brief Slot to show native ParaView user documentation.
606 void PVGUI_Module::onParaViewHelp()
608 showHelpForProxy("index");
612 \brief Slot to show help for proxy.
614 void PVGUI_Module::showHelpForProxy( const QString& proxy )
616 // make sure assistant is ready
617 this->makeAssistant();
619 if(this->Implementation->myHelpWindow) {
620 this->Implementation->myHelpWindow->show();
621 this->Implementation->myHelpWindow->raise();
623 /* if(this->Implementation->AssistantClient) {
624 this->Implementation->AssistantClient->openAssistant();
625 QString page("%1/Documentation/%2.html");
626 page = page.arg(this->Implementation->DocumentationDir);
627 page = page.arg(proxy);
628 this->Implementation->AssistantClient->showPage(page);
632 QString Locate( const QString& appName )
634 QString app_dir = QCoreApplication::applicationDirPath();
635 const char* inst_dirs[] = {
641 for (const char** dir = inst_dirs; *dir; ++dir) {
642 QString path = app_dir;
645 //cout << "Checking : " << path.toAscii().data() << " ... ";
647 QFileInfo finfo (path);
648 if (finfo.exists()) {
649 //cout << " Success!" << endl;
652 //cout << " Failed" << endl;
654 return app_dir + QDir::separator() + appName;
658 \brief Initialized an assistant client.
660 void PVGUI_Module::makeAssistant()
662 if (this->Implementation->myHelpWindow)
665 pqHelpWindow* helpWindow = new pqHelpWindow("ParaView Online Help", getApp()->desktop());
666 QObject::connect(helpWindow, SIGNAL(helpWarnings(const QString&)),
667 this, SLOT(assistantError(const QString&)));
668 helpWindow->registerDocumentation(":/ParaViewResources/pqClient.qch");
669 this->Implementation->myHelpWindow = helpWindow;
670 this->Implementation->myHelpWindow->showPage("qthelp://paraview.org/paraview/Documentation/index.html");
674 \brief Slot to call the message handler with the critical message.
676 void PVGUI_Module::assistantError( const QString& error )
678 qCritical(error.toAscii().data());
682 \brief Slot to show the waiting state.
684 void PVGUI_Module::onPreAccept()
686 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
687 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
691 \brief Slot to show the ready state.
693 void PVGUI_Module::onPostAccept()
695 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
696 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
700 \brief Slot to switch off wait cursor.
702 void PVGUI_Module::endWaitCursor()
704 QApplication::restoreOverrideCursor();
708 \brief Returns the ParaView multi-view manager.
710 pqViewManager* PVGUI_Module::getMultiViewManager() const
712 pqViewManager* aMVM = 0;
713 if ( Implementation )
714 aMVM = &Implementation->Core.multiViewManager();
719 \brief Processes QEvent::ActionAdded and QEvent::ActionRemoved from Lookmarks toolbar
720 in order to register/unregister this action in/from QtxActionToolMgr.
722 bool PVGUI_Module::eventFilter( QObject* theObject, QEvent* theEvent )
724 QToolBar* aTB = toolMgr()->toolBar(tr("TOOL_LOOKMARKS"));
725 if ( theObject == aTB ) {
727 if ( theEvent->type() == QEvent::ActionAdded ) {
728 QList<QAction*> anActns = aTB->actions();
729 for (int i = 0; i < anActns.size(); ++i)
730 if ( toolMgr()->actionId(anActns.at(i)) == -1 ) {
731 toolMgr()->setUpdatesEnabled(false);
732 createTool( anActns.at(i), tr("TOOL_LOOKMARKS") );
733 toolMgr()->setUpdatesEnabled(true);
737 if ( theEvent->type() == QEvent::ActionRemoved ) {
738 QList<QAction*> anActns = aTB->actions();
739 QIntList aIDL = toolMgr()->idList();
740 for (int i = 0; i < aIDL.size(); ++i) {
741 if ( toolMgr()->action(aIDL.at(i))->parent() == aTB
743 !anActns.contains( toolMgr()->action(aIDL.at(i)) ) ) {
744 toolMgr()->setUpdatesEnabled(false);
745 toolMgr()->unRegisterAction( aIDL.at(i) );
746 toolMgr()->remove( aIDL.at(i), tr("TOOL_LOOKMARKS") );
747 toolMgr()->setUpdatesEnabled(true);
754 return QObject::eventFilter( theObject, theEvent );
758 \brief Activate module.
759 \param study current study
760 \return \c true if activaion is done successfully or 0 to prevent
763 bool PVGUI_Module::activateModule( SUIT_Study* study )
765 bool isDone = SalomeApp_Module::activateModule( study );
766 if ( !isDone ) return false;
770 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
771 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
772 setMenuShown( true );
773 setToolShown( true );
775 toolMgr()->toolBar(tr("TOOL_LOOKMARKS"))->installEventFilter(this);
777 // Make default server connection
778 if ( Implementation )
779 Implementation->Core.makeDefaultConnectionIfNoneExists();
781 restoreDockWidgetsState();
788 \brief Deactivate module.
789 \param study current study
790 \return \c true if deactivaion is done successfully or 0 to prevent
791 deactivation on error
793 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
795 toolMgr()->toolBar(tr("TOOL_LOOKMARKS"))->removeEventFilter(this);
800 menuMgr()->hide(mySourcesMenuId);
801 menuMgr()->hide(myFiltersMenuId);
802 setMenuShown( false );
803 setToolShown( false );
805 saveDockWidgetsState();
807 return SalomeApp_Module::deactivateModule( study );
811 \brief Called when application is closed.
813 Process finalize application functionality from ParaView in order to save server settings
814 and nullify application pointer if the application is being closed.
816 \param theApp application
818 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
820 int aAppsNb = SUIT_Session::session()->applications().size();
822 deleteTemporaryFiles();
825 CAM_Module::onApplicationClosed(theApp);
829 \brief Compares the contents of the window with the given reference image,
830 returns true if they "match" within some tolerance.
832 bool PVGUI_Module::compareView( const QString& ReferenceImage, double Threshold,
833 std::ostream& Output, const QString& TempDirectory )
835 if ( Implementation )
836 return Implementation->Core.compareView( ReferenceImage, Threshold, Output, TempDirectory );
840 QString PVGUI_Module::engineIOR() const
842 CORBA::String_var anIOR = PARAVIS::GetParavisGen(this)->GetIOR();
843 return QString(anIOR.in());
846 void PVGUI_Module::onOpenFile()
848 // This avoids an immediate exception on wrong MED file opening
849 Implementation->Core.onFileOpen();
853 \brief Open file of format supported by ParaView
855 void PVGUI_Module::openFile(const char* theName)
859 Implementation->Core.createReaderOnActiveServer(aFiles);
863 \brief Returns trace string
865 QString PVGUI_Module::printTrace()
867 return get_trace_string();
871 \brief Saves trace string to disk file
873 void PVGUI_Module::saveTrace(const char* theName)
879 \brief Saves ParaView state to a disk file
881 void PVGUI_Module::saveParaviewState(const char* theFileName)
885 Implementation->Core.onFileSaveServerState(aFiles);
889 \brief Restores ParaView state from a disk file
891 void PVGUI_Module::loadParaviewState(const char* theFileName)
895 Implementation->Core.onFileLoadServerState(aFiles);
899 \brief Imports MED data from VISU module by data entry
901 void PVGUI_Module::onImportFromVisu(QString theEntry)
903 SUIT_OverrideCursor aWaitCursor;
906 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
907 if(!activeStudy) return;
909 // get SALOMEDS client study
910 _PTR(Study) aStudy = activeStudy->studyDS();
913 // find VISU component in a study
914 _PTR(SComponent) aVisuComp = aStudy->FindComponent( "VISU" );
915 if(!aVisuComp) return;
917 // get SObject client by entry
918 _PTR(SObject) aSObj = aStudy->FindObjectID(qPrintable(theEntry));
922 SALOMEDS_SObject* aSObject = _CAST(SObject, aSObj);
923 if ( !aSObject ) return;
926 SALOME_NamingService* aNamingService = SalomeApp_Application::namingService();
927 SALOME_LifeCycleCORBA aLCC(aNamingService);
929 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
930 VISU::VISU_Gen_var aVISU = VISU::VISU_Gen::_narrow(aComponent);
931 if(CORBA::is_nil(aVISU)) return;
933 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
934 aStudyBuilder->LoadWith( aVisuComp, SalomeApp_Application::orb()->object_to_string(aVISU) );
936 // set current study to VISU engine
937 //aVISU->SetCurrentStudy(aStudyVar);
939 // get VISU result object
940 CORBA::Object_var aResultObject = aSObject->GetObject();
941 if (CORBA::is_nil(aResultObject)) return;
942 VISU::Result_var aResult = VISU::Result::_narrow( aResultObject );
943 if (CORBA::is_nil(aResult)) return;
945 // export VISU result to the MED file
946 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
947 std::string aFileName = aSObject->GetName();
948 std::string aFilePath = aTmpDir + aFileName;
950 if (aResult->ExportMED(aFilePath.c_str())) {
951 openFile(aFilePath.c_str());
952 myTemporaryFiles.append(QString(aFilePath.c_str()));
957 \brief Deletes temporary files created during import operation from VISU
959 void PVGUI_Module::deleteTemporaryFiles()
961 foreach(QString aFile, myTemporaryFiles) {
962 if (QFile::exists(aFile)) {
963 QFile::remove(aFile);
970 \brief Returns current active ParaView server
972 pqServer* PVGUI_Module::getActiveServer()
974 return Implementation->Core.getActiveServer();
979 \brief Creates PARAVIS preference pane
981 void PVGUI_Module::createPreferences()
983 int TraceTab = addPreference( tr( "TIT_TRACE" ) );
984 addPreference( tr( "PREF_STOP_TRACE" ), TraceTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
990 \fn CAM_Module* createModule();
991 \brief Export module instance (factory function).
992 \return new created instance of the module
996 #define PVGUI_EXPORT __declspec(dllexport)
1002 PVGUI_EXPORT CAM_Module* createModule() {
1003 return new PVGUI_Module();