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 <vtkPython.h> // Python first
27 #include "PVGUI_Module.h"
29 #include "SALOMEconfig.h"
30 #include CORBA_CLIENT_HEADER(VISU_Gen)
31 #include CORBA_SERVER_HEADER(SALOMEDS)
34 #include "PARAVIS_Gen_i.hh"
36 #include "PVGUI_Module_impl.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_SelectionMgr.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_Study.h>
57 #include <SALOME_ListIO.hxx>
58 #include <SALOMEDS_Tool.hxx>
59 #include <PyInterp_Dispatcher.h>
61 #include <QtxActionMenuMgr.h>
62 #include <QtxActionToolMgr.h>
65 #include <QApplication>
71 #include <QInputDialog>
74 #include <QStringList>
77 #include <QTextStream>
80 #include <pqApplicationCore.h>
81 #include <pqActiveView.h>
82 #include <pqObjectBuilder.h>
83 #include <pqOptions.h>
84 #include <pqRenderView.h>
86 #include <pqUndoStack.h>
87 #include <pqVCRController.h>
88 #include <pqViewManager.h>
89 #include <pqPipelineSource.h>
90 #include <vtkPVMain.h>
91 #include <vtkProcessModule.h>
92 #include <pqParaViewBehaviors.h>
93 #include <pqHelpReaction.h>
94 #include <vtkOutputWindow.h>
95 #include <pqPluginManager.h>
96 #include <vtkPVPluginInformation.h>
97 #include <pqSettings.h>
98 #include <pqPythonDialog.h>
99 #include <pqPythonManager.h>
100 #include <pqPythonShell.h>
101 #include "pqBrandPluginsLoader.h"
102 #include <pqLoadDataReaction.h>
105 * Make sure all the kits register their classes with vtkInstantiator.
106 * Since ParaView uses Tcl wrapping, all of VTK is already compiled in
107 * anyway. The instantiators will add no more code for the linker to
111 #include <vtkCommonInstantiator.h>
112 #include <vtkFilteringInstantiator.h>
113 #include <vtkGenericFilteringInstantiator.h>
114 #include <vtkIOInstantiator.h>
115 #include <vtkImagingInstantiator.h>
116 #include <vtkInfovisInstantiator.h>
117 #include <vtkGraphicsInstantiator.h>
119 #include <vtkRenderingInstantiator.h>
120 #include <vtkVolumeRenderingInstantiator.h>
121 #include <vtkHybridInstantiator.h>
122 #include <vtkParallelInstantiator.h>
124 #include <pqAlwaysConnectedBehavior.h>
125 #include <pqApplicationCore.h>
126 #include <pqAutoLoadPluginXMLBehavior.h>
127 #include <pqCommandLineOptionsBehavior.h>
128 #include <pqCrashRecoveryBehavior.h>
129 #include <pqDataTimeStepBehavior.h>
130 #include <pqDefaultViewBehavior.h>
131 #include <pqDeleteBehavior.h>
132 #include <pqPersistentMainWindowStateBehavior.h>
133 #include <pqPluginActionGroupBehavior.h>
134 #include <pqPluginDockWidgetsBehavior.h>
135 #include <pqPluginManager.h>
136 #include <pqPVNewSourceBehavior.h>
137 //#include <pqQtMessageHandlerBehavior.h>
138 #include <pqSpreadSheetVisibilityBehavior.h>
139 #include <pqStandardViewModules.h>
140 #include <pqUndoRedoBehavior.h>
141 #include <pqViewFrameActionsBehavior.h>
144 //----------------------------------------------------------------------------
145 pqApplicationCore* PVGUI_Module::pqImplementation::Core = 0;
146 PVGUI_OutputWindowAdapter* PVGUI_Module::pqImplementation::OutputWindowAdapter = 0;
147 QPointer<pqHelpWindow> PVGUI_Module::pqImplementation::helpWindow = 0;
149 PVGUI_Module* ParavisModule = 0;
154 <h2>Building and installing PARAVIS</h2>
155 As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
156 installation directory.
157 Other variables needed for correct detection of ParaView location:
158 \li PVHOME - points at the ParaView installation directory tree
159 \li PVVERSION - number of ParaView version
161 It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
164 PARAVIS module can be launched using the following commands:
165 \li Full SALOME configuration
167 runSalome --modules="PARAVIS"
170 <h2>ParaView GUI integration</h2>
171 <h3>ParaView GUI integration overview</h3>
173 The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
174 between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
176 \li SALOME GUI executable and Qt event loop
177 \li SALOME GUI desktop
178 \li Dock windows areas
179 \li SALOME menu and toolbar managers
181 Major part of the integration is implemented in PVGUI_Module class.
183 <h3>ParaView client initalization</h3>
185 ParaView client initalization is performed when an instance of PVGUI_Module class has been created
186 and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
187 The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
190 <h3>Multi-view manager</h3>
192 SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
195 \li PVGUI_ViewManager - view manager class
196 \li PVGUI_Viewer - view model class
197 \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
199 Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
200 PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
201 when the module is deactivated (the user switches to another module or a study is closed).
202 A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
203 with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
204 \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
205 of %pqViewManager widget that would break %pqMainWindowCore class.
207 <h3>ParaView plugins</h3>
208 ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
209 As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
214 \brief Implementation
215 SALOME module wrapping ParaView GUI.
219 \brief Constructor. Sets the default name for the module.
221 PVGUI_Module::PVGUI_Module()
222 : SalomeApp_Module( "PARAVIS" ),
223 LightApp_Module( "PARAVIS" ),
225 mySelectionControlsTb( -1 ),
226 mySourcesMenuId( -1 ),
227 myFiltersMenuId( -1 ),
229 myToolbarsMenuId(-1),
232 ParavisModule = this;
238 PVGUI_Module::~PVGUI_Module()
245 \brief Initialize module. Creates menus, prepares context menu, etc.
246 \param app SALOME GUI application instance
248 void PVGUI_Module::initialize( CAM_Application* app )
250 SalomeApp_Module::initialize( app );
252 // Uncomment to debug ParaView initialization
253 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
261 // Initialize ParaView client
264 // Create GUI elements (menus, toolbars, dock widgets)
265 if ( !Implementation ){
266 SalomeApp_Application* anApp = getApp();
268 // Simulate ParaView client main window
269 Implementation = new pqImplementation( anApp->desktop() );
277 // new pqParaViewBehaviors(anApp->desktop(), this);
278 // Has to be replaced in order to exclude using of pqQtMessageHandlerBehaviour
279 // Start pqParaViewBehaviors
280 // Register ParaView interfaces.
281 pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
283 // * adds support for standard paraview views.
284 pgm->addInterface(new pqStandardViewModules(pgm));
286 // Load plugins distributed with application.
287 pqApplicationCore::instance()->loadDistributedPlugins();
289 // Define application behaviors.
290 //new pqQtMessageHandlerBehavior(this);
291 new pqDataTimeStepBehavior(this);
292 new pqViewFrameActionsBehavior(this);
293 new pqSpreadSheetVisibilityBehavior(this);
294 new pqDefaultViewBehavior(this);
295 new pqAlwaysConnectedBehavior(this);
296 new pqPVNewSourceBehavior(this);
297 new pqDeleteBehavior(this);
298 new pqUndoRedoBehavior(this);
299 new pqCrashRecoveryBehavior(this);
300 new pqAutoLoadPluginXMLBehavior(this);
301 new pqPluginDockWidgetsBehavior(getApp()->desktop());
302 new pqPluginActionGroupBehavior(getApp()->desktop());
303 new pqCommandLineOptionsBehavior(this);
304 new pqPersistentMainWindowStateBehavior(getApp()->desktop());
306 // Setup quick-launch shortcuts.
307 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space,
308 getApp()->desktop());
309 QObject::connect(ctrlSpace, SIGNAL(activated()),
310 pqApplicationCore::instance(), SLOT(quickLaunch()));
311 QShortcut *altSpace = new QShortcut(Qt::ALT + Qt::Key_Space,
312 getApp()->desktop());
313 QObject::connect(altSpace, SIGNAL(activated()),
314 pqApplicationCore::instance(), SLOT(quickLaunch()));
315 // End pqParaViewBehaviors
318 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
319 QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
320 if (!aPath.isNull()) {
321 pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
322 pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
323 pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
324 pqImplementation::Core->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
326 // Now that we're ready, initialize everything ...
329 // Force creation of engine
330 PARAVIS::GetParavisGen(this);
334 // Initialize list of toolbars
335 QCoreApplication::processEvents();
336 QList<QToolBar*> aBars = getParaViewToolbars();
337 foreach (QToolBar* aBar, aBars) {
338 myToolbarState[aBar] = true;
341 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
342 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
344 QTimer::singleShot(50, this, SLOT(activateTrace()));
348 void PVGUI_Module::activateTrace()
350 PyInterp_Dispatcher* aDispatcher = PyInterp_Dispatcher::Get();
351 if (aDispatcher->IsBusy()) {
352 QTimer::singleShot(50, this, SLOT(activateTrace()));
356 pqPythonDialog* pyDiag = 0;
357 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
358 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
360 pyDiag = manager->pythonShellDialog();
363 pyDiag->runString("try:\n"
364 " from paraview import smtrace\n"
365 " smtrace.start_trace()\n"
366 " print 'Trace started.'\n"
367 "except: raise RuntimeError('could not import paraview.smtrace')\n");
374 \brief Get list of compliant dockable GUI elements
375 \param m map to be filled in ("type":"default_position")
377 void PVGUI_Module::windows( QMap<int, int>& m ) const
379 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
380 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
381 // ParaView diagnostic output redirected here
382 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
386 \brief Static method, performs initialization of ParaView session.
387 \return \c true if ParaView has been initialized successfully, otherwise false
389 bool PVGUI_Module::pvInit()
391 if ( !pqImplementation::Core ){
392 // Obtain command-line arguments
394 QStringList args = QApplication::arguments();
395 char** argv = new char*[args.size()];
396 for ( QStringList::const_iterator it = args.begin(); argc < 1 && it != args.end(); it++, argc++ ) {
397 argv[argc] = strdup( (*it).toLatin1().constData() );
399 pqImplementation::Core = new pqPVApplicationCore (argc, argv);
400 if (pqImplementation::Core->getOptions()->GetHelpSelected() ||
401 pqImplementation::Core->getOptions()->GetUnknownArgument() ||
402 pqImplementation::Core->getOptions()->GetErrorMessage() ||
403 pqImplementation::Core->getOptions()->GetTellVersion()) {
406 // VSV: Code from Initializer - it seems that it does nothing
408 // Not sure why this is needed. Andy added this ages ago with comment saying
409 // needed for Mac apps. Need to check that it's indeed still required.
410 QDir dir(QApplication::applicationDirPath());
413 QApplication::addLibraryPath(dir.absolutePath());
414 // Load required application plugins.
415 QString plugin_string = "";
416 QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
417 pqBrandPluginsLoader loader;
418 if (loader.loadPlugins(plugin_list) == false) {
419 printf("Failed to load required plugins for this application\n");
423 // Load optional plugins.
425 plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
426 loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
428 // End of Initializer code
430 //qInstallMsgHandler(0); // switch off standard Paraview message handler
431 pqImplementation::OutputWindowAdapter = PVGUI_OutputWindowAdapter::New();
432 vtkOutputWindow::SetInstance(pqImplementation::OutputWindowAdapter);
434 //pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
435 //pgm->loadExtensions(NULL);
437 new pqViewManager(); // it registers as "MULTIVIEW_MANAGER on creation
440 free(argv[0]); // because in creation argc < 1
448 \brief Shows (toShow = true) or hides ParaView view window
450 void PVGUI_Module::showView( bool toShow )
452 SalomeApp_Application* anApp = getApp();
453 PVGUI_ViewManager* viewMgr =
454 dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
456 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
457 anApp->addViewManager( viewMgr );
458 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
459 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
462 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
464 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
467 pvWnd->setShown( toShow );
471 // void PVGUI_Module::connectToPlay()
473 // connect( action(PlayId), SIGNAL( triggered() ), &Implementation->Core.VCRController(), SLOT( onPlay() ) );
478 \brief Slot to show help for proxy.
480 void PVGUI_Module::showHelpForProxy( const QString& proxy )
482 //pqHelpReaction::showHelp(QString("qthelp://paraview.org/paraview/%1.html").arg(proxy));
483 showHelp(QString("qthelp://paraview.org/paraview/%1.html").arg(proxy));
486 void PVGUI_Module::showParaViewHelp()
491 void PVGUI_Module::showHelp(const QString& url)
493 if (pqImplementation::helpWindow) {
494 // raise assistant window;
495 pqImplementation::helpWindow->show();
496 pqImplementation::helpWindow->raise();
497 if (!url.isEmpty()) {
498 pqImplementation::helpWindow->showPage(url);
503 // * Discover help project files from the resources.
504 QString aPVHome(getenv("PVHOME"));
505 if (aPVHome.isNull()) {
506 qWarning("Wariable PVHOME is not defined");
509 QChar aSep = QDir::separator();
510 QString aFile = aPVHome + aSep + "doc" + aSep + "paraview.qch";
512 if (!QFile::exists(aFile)) {
513 qWarning("Help file do not found");
517 pqImplementation::helpWindow = new pqHelpWindow(QString("ParaView Online Help"), getApp()->desktop());
518 QString namespace_name = pqImplementation::helpWindow->registerDocumentation(aFile);
520 pqImplementation::helpWindow->showHomePage(namespace_name);
521 pqImplementation::helpWindow->show();
522 pqImplementation::helpWindow->raise();
523 if (!url.isEmpty()) {
524 pqImplementation::helpWindow->showPage(url);
531 \brief Slot to show the waiting state.
533 void PVGUI_Module::onPreAccept()
535 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
536 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
540 \brief Slot to show the ready state.
542 void PVGUI_Module::onPostAccept()
544 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
545 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
549 \brief Slot to switch off wait cursor.
551 void PVGUI_Module::endWaitCursor()
553 QApplication::restoreOverrideCursor();
557 \brief Returns the ParaView multi-view manager.
559 pqViewManager* PVGUI_Module::getMultiViewManager() const
561 return qobject_cast<pqViewManager*>(pqApplicationCore::instance()->manager("MULTIVIEW_MANAGER"));
565 static void ParavisMessageOutput(QtMsgType type, const char *msg)
570 vtkOutputWindow::GetInstance()->DisplayText(msg);
573 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
576 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
579 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
587 \brief Activate module.
588 \param study current study
589 \return \c true if activaion is done successfully or 0 to prevent
592 bool PVGUI_Module::activateModule( SUIT_Study* study )
594 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
596 bool isDone = SalomeApp_Module::activateModule( study );
597 if ( !isDone ) return false;
600 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
601 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
602 if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
603 if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
604 setMenuShown( true );
605 setToolShown( true );
607 if (myToolbarState.size() > 0) {
608 SUIT_Desktop* desk = application()->desktop();
609 QList<QToolBar*> aToolbars = myToolbarState.keys();
610 foreach(QToolBar* aBar, aToolbars) {
611 aBar->setParent(desk);
612 aBar->setVisible(myToolbarState[aBar]);
616 restoreDockWidgetsState();
623 \brief Deactivate module.
624 \param study current study
625 \return \c true if deactivaion is done successfully or 0 to prevent
626 deactivation on error
628 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
630 if (pqImplementation::helpWindow) {
631 pqImplementation::helpWindow->hide();
636 menuMgr()->hide(mySourcesMenuId);
637 menuMgr()->hide(myFiltersMenuId);
638 menuMgr()->hide(myMacrosMenuId);
639 menuMgr()->hide(myToolbarsMenuId);
640 setMenuShown( false );
641 setToolShown( false );
643 saveDockWidgetsState();
646 QList<QToolBar*> aToolbars = myToolbarState.keys();
647 foreach(QToolBar* aBar, aToolbars) {
648 myToolbarState[aBar] = aBar->isVisible();
654 qInstallMsgHandler(myOldMsgHandler);
655 return SalomeApp_Module::deactivateModule( study );
660 \brief Called when application is closed.
662 Process finalize application functionality from ParaView in order to save server settings
663 and nullify application pointer if the application is being closed.
665 \param theApp application
667 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
669 pqApplicationCore::instance()->settings()->sync();
670 int aAppsNb = SUIT_Session::session()->applications().size();
672 deleteTemporaryFiles();
675 CAM_Module::onApplicationClosed(theApp);
679 \brief Compares the contents of the window with the given reference image,
680 returns true if they "match" within some tolerance.
682 /*VSV it seems that this method is obsolete
683 bool PVGUI_Module::compareView( const QString& ReferenceImage, double Threshold,
684 std::ostream& Output, const QString& TempDirectory )
686 if ( Implementation )
687 return Implementation->Core.compareView( ReferenceImage, Threshold, Output, TempDirectory );
691 QString PVGUI_Module::engineIOR() const
693 CORBA::String_var anIOR = PARAVIS::GetParavisGen(this)->GetIOR();
694 return QString(anIOR.in());
699 \brief Open file of format supported by ParaView
701 void PVGUI_Module::openFile(const char* theName)
705 pqLoadDataReaction::loadData(aFiles);
709 \brief Returns trace string
711 QString PVGUI_Module::getTraceString()
713 pqPythonDialog* pyDiag = 0;
714 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
715 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
717 pyDiag = manager->pythonShellDialog();
722 pyDiag->runString("try:\n"
723 " from paraview import smtrace\n"
724 " __smtraceString = smtrace.get_trace_string()\n"
726 " __smtraceString = str()\n"
727 " raise RuntimeError('could not import paraview.smtrace')\n");
728 pyDiag->shell()->makeCurrent();
729 PyObject* main_module = PyImport_AddModule((char*)"__main__");
730 PyObject* global_dict = PyModule_GetDict(main_module);
731 PyObject* string_object = PyDict_GetItemString(global_dict, "__smtraceString");
732 char* string_ptr = PyString_AsString(string_object);
734 traceString = string_ptr;
736 pyDiag->shell()->releaseControl();
742 \brief Saves trace string to disk file
744 void PVGUI_Module::saveTrace(const char* theName)
746 //save_trace(theName);
748 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
749 MESSAGE( "Could not open file:" << theName );
752 QTextStream out(&file);
753 out << getTraceString();
758 \brief Saves ParaView state to a disk file
760 void PVGUI_Module::saveParaviewState(const char* theFileName)
762 Implementation->Core->saveState(theFileName);
766 \brief Restores ParaView state from a disk file
768 void PVGUI_Module::loadParaviewState(const char* theFileName)
770 Implementation->Core->loadState(theFileName, getActiveServer());
774 \brief Imports MED data from VISU module by data entry
776 void PVGUI_Module::onImportFromVisu(QString theEntry)
779 SUIT_OverrideCursor aWaitCursor;
782 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
783 if(!activeStudy) return;
785 // get SALOMEDS client study
786 _PTR(Study) aStudy = activeStudy->studyDS();
789 // find VISU component in a study
790 _PTR(SComponent) aVisuComp = aStudy->FindComponent( "VISU" );
791 if(!aVisuComp) return;
793 // get SObject client by entry
794 _PTR(SObject) aSObj = aStudy->FindObjectID(qPrintable(theEntry));
798 SALOMEDS_SObject* aSObject = _CAST(SObject, aSObj);
799 if ( !aSObject ) return;
802 SALOME_NamingService* aNamingService = SalomeApp_Application::namingService();
803 SALOME_LifeCycleCORBA aLCC(aNamingService);
805 Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
806 VISU::VISU_Gen_var aVISU = VISU::VISU_Gen::_narrow(aComponent);
807 if(CORBA::is_nil(aVISU)) return;
809 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
810 aStudyBuilder->LoadWith( aVisuComp, SalomeApp_Application::orb()->object_to_string(aVISU) );
812 // set current study to VISU engine
813 //aVISU->SetCurrentStudy(aStudyVar);
815 // get VISU result object
816 CORBA::Object_var aResultObject = aSObject->GetObject();
817 if (CORBA::is_nil(aResultObject)) return;
818 VISU::Result_var aResult = VISU::Result::_narrow( aResultObject );
819 if (CORBA::is_nil(aResult)) return;
821 // export VISU result to the MED file
822 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
823 std::string aFileName = aSObject->GetName();
824 std::string aFilePath = aTmpDir + aFileName;
826 if (aResult->ExportMED(aFilePath.c_str())) {
827 openFile(aFilePath.c_str());
828 myTemporaryFiles.append(QString(aFilePath.c_str()));
831 MESSAGE("Visu module is not found.");
836 \brief Deletes temporary files created during import operation from VISU
838 void PVGUI_Module::deleteTemporaryFiles()
840 foreach(QString aFile, myTemporaryFiles) {
841 if (QFile::exists(aFile)) {
842 QFile::remove(aFile);
849 \brief Returns current active ParaView server
851 pqServer* PVGUI_Module::getActiveServer()
853 return Implementation->Core->getActiveServer();
858 \brief Creates PARAVIS preference pane
860 void PVGUI_Module::createPreferences()
862 int TraceTab = addPreference( tr( "TIT_TRACE" ) );
863 addPreference( tr( "PREF_STOP_TRACE" ), TraceTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
865 int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), TraceTab,
866 LightApp_Preferences::Selector,
867 "PARAVIS", "savestate_type");
868 QList<QVariant> aIndices;
869 QStringList aStrings;
871 aStrings<<tr("PREF_SAVE_TYPE_0");
872 aStrings<<tr("PREF_SAVE_TYPE_1");
873 aStrings<<tr("PREF_SAVE_TYPE_2");
874 setPreferenceProperty(aSaveType, "strings", aStrings);
875 setPreferenceProperty(aSaveType, "indexes", aIndices);
881 \fn CAM_Module* createModule();
882 \brief Export module instance (factory function).
883 \return new created instance of the module
887 #define PVGUI_EXPORT __declspec(dllexport)
893 PVGUI_EXPORT CAM_Module* createModule() {
894 return new PVGUI_Module();