1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2016 CEA/DEN, EDF R&D
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : PVGUI_Module.cxx
23 #define PARAVIS_MODULE_NAME "PARAVIS"
25 #include <Standard_math.hxx> // E.A. must be included before Python.h to fix compilation on windows
27 #undef HAVE_FINITE // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
29 #include <vtkPython.h> // Python first
31 #include "PVGUI_Module.h"
33 #include "PVViewer_ViewManager.h"
34 #include "PVViewer_Core.h"
35 #include "PVViewer_ViewWindow.h"
36 #include "PVViewer_ViewModel.h"
37 #include "PVGUI_ParaViewSettingsPane.h"
38 #include "PVViewer_GUIElements.h"
39 #include "PVServer_ServiceWrapper.h"
40 #include "PVGUI_DataModel.h"
43 #include <utilities.h>
44 #include <SUIT_DataBrowser.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_OverrideCursor.h>
50 #include <SUIT_ExceptionHandler.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <LightApp_NameDlg.h>
54 #include <LightApp_Application.h>
55 #include <LightApp_Study.h>
56 #include <SALOME_ListIO.hxx>
58 #include <QtxActionMenuMgr.h>
59 #include <QtxActionToolMgr.h>
61 #include <PARAVIS_version.h>
67 #include <QApplication>
73 #include <QInputDialog>
77 #include <QStringList>
80 #include <QTextStream>
82 #include <QDockWidget>
83 #include <QHelpEngine>
86 #include <vtkPVConfig.h> // for symbol PARAVIEW_VERSION
87 #include <vtkProcessModule.h>
88 #include <vtkPVSession.h>
89 #include <vtkPVProgressHandler.h>
90 #include <vtkEventQtSlotConnect.h>
92 #include <vtkSMProxy.h>
93 #include <vtkSmartPointer.h>
94 #include <vtkSMSession.h>
95 #include <vtkSMTrace.h>
96 #include <vtkSMSessionProxyManager.h>
97 #include <vtkSMParaViewPipelineController.h>
98 #include <vtkSmartPyObject.h>
100 #include <pqApplicationCore.h>
101 #include <pqPVApplicationCore.h>
102 #include <pqObjectBuilder.h>
103 #include <pqOptions.h>
104 #include <pqSettings.h>
105 #include <pqServer.h>
106 #include <pqUndoStack.h>
107 #include <pqTabbedMultiViewWidget.h>
108 #include <pqActiveObjects.h>
109 #include <pqHelpReaction.h>
110 #include <pqPluginManager.h>
111 #include <pqPythonDialog.h>
112 #include <pqPythonManager.h>
113 #include <pqLoadDataReaction.h>
114 #include <pqPythonScriptEditor.h>
115 #include <pqDataRepresentation.h>
116 #include <pqDisplayColorWidget.h>
117 #include <pqColorToolbar.h>
118 #include <pqScalarBarVisibilityReaction.h>
119 #include <pqServerResource.h>
120 #include <pqServerConnectReaction.h>
121 #include <pqPluginManager.h>
122 #include <pqVCRToolbar.h>
123 #include <pqAnimationScene.h>
124 #include <pqServerManagerModel.h>
125 #include <pqAnimationTimeToolbar.h>
126 #include <pqPipelineBrowserWidget.h>
128 #if PY_VERSION_HEX < 0x03050000
130 Py_EncodeLocale(const wchar_t *arg, size_t *size)
132 return _Py_wchar2char(arg, size);
135 Py_DecodeLocale(const char *arg, size_t *size)
137 return _Py_char2wchar(arg, size);
141 //----------------------------------------------------------------------------
142 PVGUI_Module* ParavisModule = 0;
146 This is the doxygen documentation of the ParaVis module.
147 If you are looking for general information about the structure of the module, you should
148 take a look at the <a href="../index.html">Sphinx documentation</a> first.
150 The integration of ParaView into SALOME is split in two parts:
151 \li the PVViewer in the GUI module (folder *src/PVViewer*)
152 \li the ParaVis module itself (the pages you are currently browsing)
157 \brief Implementation
158 SALOME module wrapping ParaView GUI.
162 \brief Clean up function
164 Used to stop ParaView progress events when
165 exception is caught by global exception handler.
167 void paravisCleanUp()
169 if ( pqApplicationCore::instance() ) {
170 pqServer* s = pqApplicationCore::instance()->getActiveServer();
171 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
176 \brief Constructor. Sets the default name for the module.
178 PVGUI_Module::PVGUI_Module()
179 : LightApp_Module( PARAVIS_MODULE_NAME ),
180 mySourcesMenuId( -1 ),
181 myFiltersMenuId( -1 ),
184 myCatalystMenuId(-1),
191 Q_INIT_RESOURCE( PVGUI );
193 ParavisModule = this;
195 // Clear old copies of embedded macros files
196 QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
200 QDir aDestDir(aDestPath);
201 QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
202 foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
203 QString aMacrosName = QFileInfo(aMacrosPath).fileName();
204 if (aDestFiles.contains(aMacrosName)) {
205 aDestDir.remove(aMacrosName);
213 PVGUI_Module::~PVGUI_Module()
220 \brief Retrieve the PVSERVER CORBA engine.
221 This uses the Python wrapper provided
222 by the PVViewer code in GUI (class PVViewer_EngineWrapper).
225 PVServer_ServiceWrapper* PVGUI_Module::GetEngine()
227 return PVServer_ServiceWrapper::GetInstance();
231 \brief Create data model.
232 \return module specific data model
234 CAM_DataModel* PVGUI_Module::createDataModel()
236 return new PVGUI_DataModel( this );
240 \brief Get the ParaView application singleton.
242 pqPVApplicationCore* PVGUI_Module::GetPVApplication()
244 return PVViewer_Core::GetPVApplication();
248 \brief Initialize module. Creates menus, prepares context menu, etc.
249 \param app SALOME GUI application instance
251 void PVGUI_Module::initialize( CAM_Application* app )
253 LightApp_Module::initialize( app );
255 // Uncomment to debug ParaView initialization
256 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
264 LightApp_Application* anApp = getApp();
265 SUIT_Desktop* aDesktop = anApp->desktop();
267 // Remember current state of desktop toolbars
268 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
270 // Initialize ParaView client and associated behaviors
271 // and connect to externally launched pvserver
272 PVViewer_Core::ParaviewInitApp(aDesktop);
273 myGuiElements = PVViewer_GUIElements::GetInstance(aDesktop);
275 // [ABN]: careful with the order of the GUI element creation, the loading of the configuration
276 // and the connection to the server. This order is very sensitive if one wants to make
277 // sure all menus, etc ... are correctly populated.
278 // Reference points are: ParaViewMainWindow.cxx and branded_paraview_initializer.cxx.in
285 PVViewer_Core::ParaviewInitBehaviors(true, aDesktop);
287 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
288 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
290 // Setup quick-launch shortcuts.
291 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
292 QObject::connect(ctrlSpace, SIGNAL(activated()),
293 pqApplicationCore::instance(), SLOT(quickLaunch()));
295 // Find Plugin Dock Widgets
296 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
297 QList<QDockWidget*>::iterator i;
298 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
299 if(!activeDocks.contains(*i)) {
300 myDockWidgets[*i] = false; // hidden by default
306 // [ABN] TODO: fix this - triggers a SEGFAULT at deactivation() time.
307 // QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
308 // QList<QMenu*>::iterator im;
309 // for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
310 // if(!activeMenus.contains(*im)) {
311 // QString s = (*im)->title();
312 // std::cout << " MENU "<< s.toStdString() << std::endl;
313 // myMenus.append(*im);
317 // Connect after toolbar creation, etc ... as some activations of the toolbars is triggered
318 // by the ServerConnection event:
319 const QString configPath(PVViewer_ViewManager::GetPVConfigPath());
320 PVViewer_Core::ParaviewLoadConfigurations(configPath, true);
321 PVViewer_ViewManager::ConnectToExternalPVServer(aDesktop);
324 // Find created toolbars
325 QCoreApplication::processEvents();
327 // process PVViewer toolbars (might be added by PVViewer created BEFORE activating ParaVis)
328 QList<QToolBar*> pvToolbars = myGuiElements->getToolbars();
329 foreach(QToolBar* aBar, pvToolbars) {
330 if (!myToolbars.contains(aBar)) {
331 myToolbars[aBar] = true;
332 myToolbarBreaks[aBar] = false;
333 aBar->setVisible(false);
334 aBar->toggleViewAction()->setVisible(false);
338 // process other toolbars (possibly added by Paraview)
339 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
340 foreach(QToolBar* aBar, allToolbars) {
341 if (!foreignToolbars.contains(aBar) && !myToolbars.contains(aBar)) {
342 myToolbars[aBar] = true;
343 myToolbarBreaks[aBar] = false;
344 aBar->setVisible(false);
345 aBar->toggleViewAction()->setVisible(false);
351 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
352 bool isStop = aResourceMgr->booleanValue( PARAVIS_MODULE_NAME, "stop_trace", false );
355 // Start a timer to schedule asap:
357 myInitTimer = new QTimer(aDesktop);
358 QObject::connect(myInitTimer, SIGNAL(timeout()), this, SLOT(onInitTimer()) );
359 myInitTimer->setSingleShot(true);
360 myInitTimer->start(0);
363 this->VTKConnect = vtkEventQtSlotConnect::New();
365 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
367 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
369 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
371 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
372 this, SLOT(onStartProgress()));
373 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
374 this, SLOT(onEndProgress()));
378 connect( application(), SIGNAL( appClosed() ), this, SLOT( onStopTrace() ) );
382 * \brief Slot called when the progress bar starts.
384 void PVGUI_Module::onStartProgress()
386 // VSR 19/03/2015, issue 0023025
387 // next line is commented: it is bad idea to show wait cursor on ANY vtk event
388 // moreover, it does not work when running pvserver with --multi-client mode
389 //QApplication::setOverrideCursor(Qt::WaitCursor);
393 * \brief Slot called when the progress bar is done.
395 void PVGUI_Module::onEndProgress()
397 // VSR 19/03/2015, issue 0023025
398 // next line is commented: it is bad idea to show wait cursor on ANY vtk event
399 // moreover, it does not work when running pvserver with --multi-client mode
400 //QApplication::restoreOverrideCursor();
403 void PVGUI_Module::onDataRepresentationUpdated() {
404 LightApp_Study* activeStudy = dynamic_cast<LightApp_Study*>(application()->activeStudy());
405 if(!activeStudy) return;
407 activeStudy->Modified();
411 \brief Initialisation timer event - Starts up the Python trace
413 void PVGUI_Module::onInitTimer()
419 \brief Get list of embedded macros files
421 QStringList PVGUI_Module::getEmbeddedMacrosList()
423 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
425 QString aSourcePath = aRootDir + "/bin/salome/Macro";
430 QDir aSourceDir(aSourcePath);
431 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
432 QStringList aFullPathSourceFiles;
433 foreach (QString aMacrosName, aSourceFiles) {
434 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
436 return aFullPathSourceFiles;
440 \brief Update the list of embedded macros
442 void PVGUI_Module::updateMacros()
444 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
445 if(!aPythonManager) {
449 foreach (QString aStr, getEmbeddedMacrosList()) {
450 aPythonManager->addMacro(aStr);
456 \brief Get list of compliant dockable GUI elements
457 \param m map to be filled in ("type":"default_position")
459 void PVGUI_Module::windows( QMap<int, int>& m ) const
461 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
462 #ifndef DISABLE_PYCONSOLE
463 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
465 // ParaView diagnostic output redirected here
466 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
470 \brief Shows (toShow = true) or hides ParaView view window
472 void PVGUI_Module::showView( bool toShow )
474 // VSR: TODO: all below is not needed, if we use standard approach
475 // that consists in implementing viewManagers() function properly
476 // This should be done after we decide what to do with Log window.
477 LightApp_Application* anApp = getApp();
478 PVViewer_ViewManager* viewMgr =
479 dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), false ) );
481 viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop() );
482 anApp->addViewManager( viewMgr );
483 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
484 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
487 PVViewer_ViewWindow* pvWnd = dynamic_cast<PVViewer_ViewWindow*>( viewMgr->getActiveView() );
489 pvWnd = dynamic_cast<PVViewer_ViewWindow*>( viewMgr->createViewWindow() );
490 // this also connects to the pvserver and instantiates relevant PV behaviors
493 pvWnd->setVisible( toShow );
494 if ( toShow ) pvWnd->setFocus();
498 \brief Slot to show help for proxy.
500 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
502 pqHelpReaction::showProxyHelp(groupname, proxyname);
506 \brief Slot to show the waiting state.
508 void PVGUI_Module::onPreAccept()
510 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
511 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
515 \brief Slot to show the ready state.
517 void PVGUI_Module::onPostAccept()
519 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
520 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
524 \brief Slot to switch off wait cursor.
526 void PVGUI_Module::endWaitCursor()
528 QApplication::restoreOverrideCursor();
532 \brief Activate module.
533 \param study current study
534 \return \c true if activaion is done successfully or 0 to prevent
537 bool PVGUI_Module::activateModule( SUIT_Study* study )
539 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
541 storeCommonWindowsState();
543 bool isDone = LightApp_Module::activateModule( study );
544 if ( !isDone ) return false;
547 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
548 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
549 if ( myMacrosMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
550 if ( myCatalystMenuId != -1 ) menuMgr()->show(myCatalystMenuId);
552 // Update the various menus with the content pre-loaded in myGuiElements
553 // QMenu* srcMenu = menuMgr()->findMenu( mySourcesMenuId );
554 // myGuiElements->updateSourcesMenu(srcMenu);
555 // QMenu* filtMenu = menuMgr()->findMenu( myFiltersMenuId );
556 // myGuiElements->updateFiltersMenu(filtMenu);
557 // QMenu* macMenu = menuMgr()->findMenu( myMacrosMenuId );
558 // myGuiElements->updateMacrosMenu(macMenu);
560 setMenuShown( true );
561 setToolShown( true );
563 restoreDockWidgetsState();
565 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
567 QList<QAction*> anActns = aMenu->actions();
568 for (int i = 0; i < anActns.size(); ++i) {
569 QAction* a = anActns.at(i);
575 QList<QMenu*>::iterator it;
576 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
577 QAction* a = (*it)->menuAction();
582 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
584 // VSR 18/10/2018 - 0023170: Workaround to re-select current index after module activation
585 QItemSelectionModel* selection_model = myGuiElements->getPipelineBrowserWidget()->getSelectionModel();
586 QModelIndex idx = selection_model->currentIndex();
587 selection_model->clearCurrentIndex();
588 selection_model->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
595 \brief Deactivate module.
596 \param study current study
597 \return \c true if deactivaion is done successfully or 0 to prevent
598 deactivation on error
600 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
602 MESSAGE("PARAVIS deactivation ...")
604 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
606 QList<QAction*> anActns = aMenu->actions();
607 for (int i = 0; i < anActns.size(); ++i) {
608 QAction* a = anActns.at(i);
610 a->setVisible(false);
614 QList<QMenu*>::iterator it;
615 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
616 QAction* a = (*it)->menuAction();
618 a->setVisible(false);
621 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
622 foreach(QDockWidget* aView, aStreamingViews) {
623 if (!myDockWidgets.contains(aView))
624 myDockWidgets[aView] = aView->isVisible();
627 /*if (pqImplementation::helpWindow) {
628 pqImplementation::helpWindow->hide();
631 menuMgr()->hide(myRecentMenuId);
632 menuMgr()->hide(mySourcesMenuId);
633 menuMgr()->hide(myFiltersMenuId);
634 menuMgr()->hide(myMacrosMenuId);
635 menuMgr()->hide(myCatalystMenuId);
636 setMenuShown( false );
637 setToolShown( false );
639 saveDockWidgetsState();
641 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
644 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
645 qInstallMsgHandler(myOldMsgHandler);
647 qInstallMessageHandler(myOldMsgHandler);
649 restoreCommonWindowsState();
651 return LightApp_Module::deactivateModule( study );
656 \brief Called when application is closed.
658 Process finalize application functionality from ParaView in order to save server settings
659 and nullify application pointer if the application is being closed.
661 \param theApp application
663 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
665 PVViewer_Core::ParaviewCleanup();
666 CAM_Module::onApplicationClosed(theApp);
670 \brief Called when study is closed.
672 Removes data model from the \a study.
674 \param study study being closed
676 void PVGUI_Module::studyClosed(SUIT_Study* study)
678 showView(false); // VSR: this seems to be not needed (all views are automatically closed)
679 clearParaviewState();
683 LightApp_Module::studyClosed(study);
687 \brief Open file of format supported by ParaView
689 void PVGUI_Module::openFile( const char* theName )
693 pqLoadDataReaction::loadData( aFiles );
697 \brief Starts Python trace.
699 Start trace invoking the newly introduced C++ API (PV 4.2)
700 (inspired from pqTraceReaction::start())
702 void PVGUI_Module::startTrace()
704 vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().activeServer()->proxyManager();
706 vtkSmartPointer<vtkSMProxy> proxy;
707 proxy.TakeReference( pxm->NewProxy( "pythontracing", "PythonTraceOptions" ) );
709 vtkNew<vtkSMParaViewPipelineController> controller;
710 controller->InitializeProxy( proxy );
712 vtkSMTrace* trace = vtkSMTrace::StartTrace();
714 // Set manually the properties entered via the dialog box poping-up when requiring
715 // a trace start in PV4.2 (trace options)
716 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
717 int type = aResourceMgr->integerValue( PARAVIS_MODULE_NAME, "tracestate_type", 2 );
718 trace->SetPropertiesToTraceOnCreate( type );
719 trace->SetFullyTraceSupplementalProxies( false );
724 \brief Stops Python trace.
726 void PVGUI_Module::stopTrace()
728 vtkSMTrace::StopTrace();
732 \brief Execute a Python script.
734 void PVGUI_Module::executeScript( const char* script )
737 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
738 pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
740 pqPythonDialog* pyDiag = manager->pythonShellDialog();
742 pyDiag->runString(script);
749 // * Debug function printing out the given interpreter's execution context
751 //void printInterpContext(PyInterp_Interp * interp )
753 // // Extract __smtraceString from interpreter's context
754 // const PyObject* ctxt = interp->getExecutionContext();
756 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
757 // Py_ssize_t siz = PyList_GET_SIZE(lst);
758 // for (Py_ssize_t i = 0; i < siz; i++)
760 // PyObject * elem = PyList_GetItem(lst, i);
761 // if (PyString_Check(elem))
763 // std::cout << "At pos:" << i << ", " << Py_EncodeLocale(PyUnicode_AS_UNICODE(elem), NULL) << std::endl;
766 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
772 \brief Returns trace string
774 QString PVGUI_Module::getTraceString()
776 QString traceString = "";
778 static const QString replaceStr( "paraview.simple" );
779 std::stringstream nl;
780 nl << std::endl; // surely there is some Qt trick to do that in a portable way??
781 QString end_line( nl.str().c_str() );
783 vtkSMTrace* tracer = vtkSMTrace::GetActiveTracer();
785 traceString = tracer->GetCurrentTrace();
786 // 'import pvsimple' is necessary to fix the first call to DisableFirstRenderCamera in the paraview trace
787 // 'ShowParaviewView()' ensure there is an opened viewing window (otherwise SEGFAULT!)
788 traceString = "import pvsimple" + end_line +
789 "pvsimple.ShowParaviewView()" + end_line + traceString;
791 // Replace import "paraview.simple" by "pvsimple"
792 if ( !traceString.isEmpty() ) {
793 int aPos = traceString.indexOf( replaceStr );
794 while ( aPos != -1 ) {
795 traceString = traceString.replace( aPos, replaceStr.length(), "pvsimple" );
796 aPos = traceString.indexOf( replaceStr, aPos );
801 // Save camera position to, which is no longer output by the tracer ...
803 vtkPythonScopeGilEnsurer psge;
804 PyObject * mods(PySys_GetObject(const_cast<char*>("modules")));
805 PyObject * trace_mod(PyDict_GetItemString(mods, "paraview.smtrace")); // module was already (really) imported by vtkSMTrace
806 if (trace_mod && trace_mod != Py_None && PyModule_Check(trace_mod)) {
807 vtkSmartPyObject save_cam(PyObject_GetAttrString(trace_mod, const_cast<char*>("SaveCameras")));
808 vtkSmartPyObject camera_trace(PyObject_CallMethod(save_cam, const_cast<char*>("get_trace"), NULL));
809 // Convert to a single string
810 vtkSmartPyObject ret(PyUnicode_FromUnicode(Py_DecodeLocale(end_line.toStdString().c_str(), NULL), end_line.size()));
811 vtkSmartPyObject final_string(PyObject_CallMethod(ret, const_cast<char*>("join"),
812 const_cast<char*>("O"), (PyObject*)camera_trace));
813 if (PyUnicode_CheckExact(final_string))
815 QString camera_qs(Py_EncodeLocale(PyUnicode_AS_UNICODE(final_string.GetPointer()), NULL)); // deep copy
816 traceString = traceString + end_line + end_line + QString("#### saving camera placements for all active views")
817 + end_line + end_line + camera_qs + end_line;
826 \brief Saves trace string to disk file
828 void PVGUI_Module::saveTrace( const char* theName )
830 QFile file( theName );
831 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) {
832 MESSAGE( "Could not open file:" << theName );
835 QTextStream out( &file );
836 out << getTraceString();
841 \brief Saves ParaView state to a disk file
843 void PVGUI_Module::saveParaviewState( const QString& theFileName )
845 pqApplicationCore::instance()->saveState( theFileName.toStdString().c_str() );
849 \brief Delete all objects for Paraview Pipeline Browser
851 void PVGUI_Module::clearParaviewState()
853 QAction* deleteAllAction = action( DeleteAllId );
854 if ( deleteAllAction ) {
855 deleteAllAction->activate( QAction::Trigger );
860 \brief Restores ParaView state from a disk file
862 void PVGUI_Module::loadParaviewState( const QString& theFileName )
864 pqApplicationCore::instance()->loadState( theFileName.toStdString().c_str(), getActiveServer() );
868 \brief Returns current active ParaView server
870 pqServer* PVGUI_Module::getActiveServer()
872 return pqApplicationCore::instance()->getActiveServer();
877 \brief Creates PARAVIS preferences panel.
879 void PVGUI_Module::createPreferences()
881 QList<QVariant> aIndices;
882 QStringList aStrings;
884 // Paraview settings tab
885 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
887 setPreferenceProperty(aParaViewSettingsTab, "stretch", false );
888 int aPanel = addPreference( QString(), aParaViewSettingsTab,
889 LightApp_Preferences::UserDefined, PARAVIS_MODULE_NAME, "" );
891 setPreferenceProperty( aPanel, "content", (qint64)( new PVGUI_ParaViewSettingsPane( 0, getApp() ) ) );
893 // Paravis settings tab
894 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
896 addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab,
897 LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "no_ext_pv_server" );
899 int aSaveType = addPreference( tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
900 LightApp_Preferences::Selector,
901 PARAVIS_MODULE_NAME, "savestate_type" );
905 aIndices << 0 << 1 << 2;
906 aStrings << tr("PREF_SAVE_TYPE_0") << tr("PREF_SAVE_TYPE_1") << tr("PREF_SAVE_TYPE_2");
907 setPreferenceProperty( aSaveType, "strings", aStrings );
908 setPreferenceProperty( aSaveType, "indexes", aIndices );
910 // ... "Language" group <<start>>
911 int traceGroup = addPreference( tr( "PREF_GROUP_TRACE" ), aParaVisSettingsTab );
913 int stopTrace = addPreference( tr( "PREF_STOP_TRACE" ), traceGroup,
914 LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
915 setPreferenceProperty( stopTrace, "restart", true );
917 int aTraceType = addPreference( tr( "PREF_TRACE_TYPE_LBL" ), traceGroup,
918 LightApp_Preferences::Selector,
919 PARAVIS_MODULE_NAME, "tracestate_type" );
922 aIndices << 0 << 1 << 2;
923 aStrings << tr("PREF_TRACE_TYPE_0") << tr("PREF_TRACE_TYPE_1") << tr("PREF_TRACE_TYPE_2");
924 setPreferenceProperty( aTraceType, "strings", aStrings );
925 setPreferenceProperty( aTraceType, "indexes", aIndices );
926 setPreferenceProperty( aTraceType, "restart", true );
930 \brief. Show ParaView python trace.
932 void PVGUI_Module::onShowTrace()
934 if (!myTraceWindow) {
935 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
937 myTraceWindow->setText(getTraceString());
938 myTraceWindow->show();
939 myTraceWindow->raise();
940 myTraceWindow->activateWindow();
945 \brief. Re-initialize ParaView python trace.
947 void PVGUI_Module::onRestartTrace()
954 \brief. Close ParaView python trace.
956 void PVGUI_Module::onStopTrace()
961 \brief Called when view manager is added
963 void PVGUI_Module::onViewManagerAdded( SUIT_ViewManager* vm )
965 if ( PVViewer_ViewManager* pvvm = dynamic_cast<PVViewer_ViewManager*>( vm ) ) {
966 connect( pvvm, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
967 this, SLOT( onPVViewCreated( SUIT_ViewWindow* ) ) );
968 connect( pvvm, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
969 this, SLOT( onPVViewDelete( SUIT_ViewWindow* ) ) );
974 \brief Called when view manager is removed
976 void PVGUI_Module::onViewManagerRemoved( SUIT_ViewManager* vm )
978 if ( PVViewer_ViewManager* pvvm = dynamic_cast<PVViewer_ViewManager*>( vm ) )
979 disconnect( pvvm, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
980 this, SLOT( onPVViewCreated( SUIT_ViewWindow* ) ) );
984 \brief Show toolbars at \a vw PV view window creating when PARAVIS is active.
986 void PVGUI_Module::onPVViewCreated( SUIT_ViewWindow* vw )
988 myGuiElements->setToolBarVisible( true );
989 restoreDockWidgetsState();
993 \brief Save toolbars state at \a view view closing.
995 void PVGUI_Module::onPVViewDelete( SUIT_ViewWindow* view )
997 if ( dynamic_cast<PVViewer_ViewWindow*>( view ) )
998 saveDockWidgetsState( false );
1002 \fn CAM_Module* createModule();
1003 \brief Export module instance (factory function).
1004 \return new created instance of the module
1008 #define PVGUI_EXPORT __declspec(dllexport)
1010 #define PVGUI_EXPORT
1016 PVGUI_EXPORT CAM_Module* createModule() {
1017 return new PVGUI_Module();
1020 PVGUI_EXPORT char* getModuleVersion() {
1021 return (char*)PARAVIS_VERSION_STR;