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 <vtkOutputWindow.h>
91 #include <vtkEventQtSlotConnect.h>
93 #include <vtkSMProxy.h>
94 #include <vtkSmartPointer.h>
95 #include <vtkSMSession.h>
96 #include <vtkSMTrace.h>
97 #include <vtkSMSessionProxyManager.h>
98 #include <vtkSMParaViewPipelineController.h>
99 #include <vtkSmartPyObject.h>
101 #include <pqApplicationCore.h>
102 #include <pqPVApplicationCore.h>
103 #include <pqObjectBuilder.h>
104 #include <pqOptions.h>
105 #include <pqSettings.h>
106 #include <pqServer.h>
107 #include <pqUndoStack.h>
108 #include <pqTabbedMultiViewWidget.h>
109 #include <pqActiveObjects.h>
110 #include <pqHelpReaction.h>
111 #include <pqPluginManager.h>
112 #include <pqPythonDialog.h>
113 #include <pqPythonManager.h>
114 #include <pqLoadDataReaction.h>
115 #include <pqPythonScriptEditor.h>
116 #include <pqDataRepresentation.h>
117 #include <pqDisplayColorWidget.h>
118 #include <pqColorToolbar.h>
119 #include <pqScalarBarVisibilityReaction.h>
120 #include <pqServerResource.h>
121 #include <pqServerConnectReaction.h>
122 #include <pqPluginManager.h>
123 #include <pqVCRToolbar.h>
124 #include <pqAnimationScene.h>
125 #include <pqServerManagerModel.h>
126 #include <pqAnimationTimeToolbar.h>
128 //----------------------------------------------------------------------------
129 PVGUI_Module* ParavisModule = 0;
133 This is the doxygen documentation of the ParaVis module.
134 If you are looking for general information about the structure of the module, you should
135 take a look at the <a href="../index.html">Sphinx documentation</a> first.
137 The integration of ParaView into SALOME is split in two parts:
138 \li the PVViewer in the GUI module (folder *src/PVViewer*)
139 \li the ParaVis module itself (the pages you are currently browsing)
144 \brief Implementation
145 SALOME module wrapping ParaView GUI.
149 \brief Clean up function
151 Used to stop ParaView progress events when
152 exception is caught by global exception handler.
154 void paravisCleanUp()
156 if ( pqApplicationCore::instance() ) {
157 pqServer* s = pqApplicationCore::instance()->getActiveServer();
158 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
163 \brief Constructor. Sets the default name for the module.
165 PVGUI_Module::PVGUI_Module()
166 : LightApp_Module( PARAVIS_MODULE_NAME ),
167 mySourcesMenuId( -1 ),
168 myFiltersMenuId( -1 ),
169 #ifdef PVCATALYST_ENABLED
170 myCatalystMenuId(-1),
180 Q_INIT_RESOURCE( PVGUI );
182 ParavisModule = this;
184 // Clear old copies of embedded macros files
185 QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
189 QDir aDestDir(aDestPath);
190 QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
191 foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
192 QString aMacrosName = QFileInfo(aMacrosPath).fileName();
193 if (aDestFiles.contains(aMacrosName)) {
194 aDestDir.remove(aMacrosName);
202 PVGUI_Module::~PVGUI_Module()
209 \brief Retrieve the PVSERVER CORBA engine.
210 This uses the Python wrapper provided
211 by the PVViewer code in GUI (class PVViewer_EngineWrapper).
214 PVServer_ServiceWrapper* PVGUI_Module::GetEngine()
216 return PVServer_ServiceWrapper::GetInstance();
220 \brief Create data model.
221 \return module specific data model
223 CAM_DataModel* PVGUI_Module::createDataModel()
225 return new PVGUI_DataModel( this );
229 \brief Get the ParaView application singleton.
231 pqPVApplicationCore* PVGUI_Module::GetPVApplication()
233 return PVViewer_Core::GetPVApplication();
237 \brief Initialize module. Creates menus, prepares context menu, etc.
238 \param app SALOME GUI application instance
240 void PVGUI_Module::initialize( CAM_Application* app )
242 LightApp_Module::initialize( app );
244 // Uncomment to debug ParaView initialization
245 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
253 LightApp_Application* anApp = getApp();
254 SUIT_Desktop* aDesktop = anApp->desktop();
256 // Remember current state of desktop toolbars
257 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
259 // Initialize ParaView client and associated behaviors
260 // and connect to externally launched pvserver
261 PVViewer_Core::ParaviewInitApp(aDesktop, anApp->logWindow());
262 myGuiElements = PVViewer_GUIElements::GetInstance(aDesktop);
264 // [ABN]: careful with the order of the GUI element creation, the loading of the configuration
265 // and the connection to the server. This order is very sensitive if one wants to make
266 // sure all menus, etc ... are correctly populated.
267 // Reference points are: ParaViewMainWindow.cxx and branded_paraview_initializer.cxx.in
274 PVViewer_Core::ParaviewInitBehaviors(true, aDesktop);
276 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
277 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
279 // Setup quick-launch shortcuts.
280 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
281 QObject::connect(ctrlSpace, SIGNAL(activated()),
282 pqApplicationCore::instance(), SLOT(quickLaunch()));
284 // Find Plugin Dock Widgets
285 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
286 QList<QDockWidget*>::iterator i;
287 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
288 if(!activeDocks.contains(*i)) {
289 myDockWidgets[*i] = false; // hidden by default
295 // [ABN] TODO: fix this - triggers a SEGFAULT at deactivation() time.
296 // QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
297 // QList<QMenu*>::iterator im;
298 // for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
299 // if(!activeMenus.contains(*im)) {
300 // QString s = (*im)->title();
301 // std::cout << " MENU "<< s.toStdString() << std::endl;
302 // myMenus.append(*im);
306 // Connect after toolbar creation, etc ... as some activations of the toolbars is triggered
307 // by the ServerConnection event:
308 const QString configPath(PVViewer_ViewManager::GetPVConfigPath());
309 PVViewer_Core::ParaviewLoadConfigurations(configPath, true);
310 PVViewer_ViewManager::ConnectToExternalPVServer(aDesktop);
313 // Find created toolbars
314 QCoreApplication::processEvents();
316 // process PVViewer toolbars (might be added by PVViewer created BEFORE activating ParaVis)
317 QList<QToolBar*> pvToolbars = myGuiElements->getToolbars();
318 foreach(QToolBar* aBar, pvToolbars) {
319 if (!myToolbars.contains(aBar)) {
320 myToolbars[aBar] = true;
321 myToolbarBreaks[aBar] = false;
322 aBar->setVisible(false);
323 aBar->toggleViewAction()->setVisible(false);
327 // process other toolbars (possibly added by Paraview)
328 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
329 foreach(QToolBar* aBar, allToolbars) {
330 if (!foreignToolbars.contains(aBar) && !myToolbars.contains(aBar)) {
331 myToolbars[aBar] = true;
332 myToolbarBreaks[aBar] = false;
333 aBar->setVisible(false);
334 aBar->toggleViewAction()->setVisible(false);
340 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
341 bool isStop = aResourceMgr->booleanValue( PARAVIS_MODULE_NAME, "stop_trace", false );
344 // Start a timer to schedule asap:
346 myInitTimer = new QTimer(aDesktop);
347 QObject::connect(myInitTimer, SIGNAL(timeout()), this, SLOT(onInitTimer()) );
348 myInitTimer->setSingleShot(true);
349 myInitTimer->start(0);
352 this->VTKConnect = vtkEventQtSlotConnect::New();
354 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
356 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
358 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
360 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
361 this, SLOT(onStartProgress()));
362 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
363 this, SLOT(onEndProgress()));
367 connect( application(), SIGNAL( appClosed() ), this, SLOT( onStopTrace() ) );
371 * \brief Slot called when the progress bar starts.
373 void PVGUI_Module::onStartProgress()
375 // VSR 19/03/2015, issue 0023025
376 // next line is commented: it is bad idea to show wait cursor on ANY vtk event
377 // moreover, it does not work when running pvserver with --multi-client mode
378 //QApplication::setOverrideCursor(Qt::WaitCursor);
382 * \brief Slot called when the progress bar is done.
384 void PVGUI_Module::onEndProgress()
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::restoreOverrideCursor();
392 void PVGUI_Module::onDataRepresentationUpdated() {
393 LightApp_Study* activeStudy = dynamic_cast<LightApp_Study*>(application()->activeStudy());
394 if(!activeStudy) return;
396 activeStudy->Modified();
400 \brief Initialisation timer event - Starts up the Python trace
402 void PVGUI_Module::onInitTimer()
408 \brief Get list of embedded macros files
410 QStringList PVGUI_Module::getEmbeddedMacrosList()
412 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
414 QString aSourcePath = aRootDir + "/bin/salome/Macro";
419 QDir aSourceDir(aSourcePath);
420 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
421 QStringList aFullPathSourceFiles;
422 foreach (QString aMacrosName, aSourceFiles) {
423 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
425 return aFullPathSourceFiles;
429 \brief Update the list of embedded macros
431 void PVGUI_Module::updateMacros()
433 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
434 if(!aPythonManager) {
438 foreach (QString aStr, getEmbeddedMacrosList()) {
439 aPythonManager->addMacro(aStr);
445 \brief Get list of compliant dockable GUI elements
446 \param m map to be filled in ("type":"default_position")
448 void PVGUI_Module::windows( QMap<int, int>& m ) const
450 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
451 #ifndef DISABLE_PYCONSOLE
452 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
454 // ParaView diagnostic output redirected here
455 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
459 \brief Shows (toShow = true) or hides ParaView view window
461 void PVGUI_Module::showView( bool toShow )
463 // VSR: TODO: all below is not needed, if we use standard approach
464 // that consists in implementing viewManagers() function properly
465 // This should be done after we decide what to do with Log window.
466 LightApp_Application* anApp = getApp();
467 PVViewer_ViewManager* viewMgr =
468 dynamic_cast<PVViewer_ViewManager*>( anApp->getViewManager( PVViewer_Viewer::Type(), false ) );
470 viewMgr = new PVViewer_ViewManager( anApp->activeStudy(), anApp->desktop(), anApp->logWindow() );
471 anApp->addViewManager( viewMgr );
472 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
473 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
476 PVViewer_ViewWindow* pvWnd = dynamic_cast<PVViewer_ViewWindow*>( viewMgr->getActiveView() );
478 pvWnd = dynamic_cast<PVViewer_ViewWindow*>( viewMgr->createViewWindow() );
479 // this also connects to the pvserver and instantiates relevant PV behaviors
482 pvWnd->setVisible( toShow );
483 if ( toShow ) pvWnd->setFocus();
487 \brief Slot to show help for proxy.
489 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
491 pqHelpReaction::showProxyHelp(groupname, proxyname);
495 \brief Slot to show the waiting state.
497 void PVGUI_Module::onPreAccept()
499 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
500 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
504 \brief Slot to show the ready state.
506 void PVGUI_Module::onPostAccept()
508 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
509 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
513 \brief Slot to switch off wait cursor.
515 void PVGUI_Module::endWaitCursor()
517 QApplication::restoreOverrideCursor();
519 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
521 \brief Handler method for the output of messages.
523 static void ParavisMessageOutput(QtMsgType type, const char *msg)
528 vtkOutputWindow::GetInstance()->DisplayText(msg);
531 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
534 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
537 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
543 \brief Handler method for the output of messages.
545 static void ParavisMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
550 vtkOutputWindow::GetInstance()->DisplayText(msg.toLatin1().constData());
553 vtkOutputWindow::GetInstance()->DisplayErrorText(msg.toLatin1().constData());
556 vtkOutputWindow::GetInstance()->DisplayErrorText(msg.toLatin1().constData());
559 vtkOutputWindow::GetInstance()->DisplayErrorText(msg.toLatin1().constData());
565 \brief Activate module.
566 \param study current study
567 \return \c true if activaion is done successfully or 0 to prevent
570 bool PVGUI_Module::activateModule( SUIT_Study* study )
572 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
573 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
575 myOldMsgHandler = qInstallMessageHandler(ParavisMessageOutput);
577 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
579 storeCommonWindowsState();
581 bool isDone = LightApp_Module::activateModule( study );
582 if ( !isDone ) return false;
585 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
586 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
587 #ifdef PVCATALYST_ENABLED
588 if ( myCatalystMenuId != -1 ) menuMgr()->show(myCatalystMenuId);
590 if ( myMacrosMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
592 // Update the various menus with the content pre-loaded in myGuiElements
593 // QMenu* srcMenu = menuMgr()->findMenu( mySourcesMenuId );
594 // myGuiElements->updateSourcesMenu(srcMenu);
595 // QMenu* filtMenu = menuMgr()->findMenu( myFiltersMenuId );
596 // myGuiElements->updateFiltersMenu(filtMenu);
597 //#ifdef PVCATALYST_ENABLED
598 // QMenu* catalystMenu = menuMgr()->findMenu( myCatalystMenuId );
599 // myGuiElements->updateCatalystMenu(catalystMenu);
601 // QMenu* macMenu = menuMgr()->findMenu( myMacrosMenuId );
602 // myGuiElements->updateMacrosMenu(macMenu);
604 setMenuShown( true );
605 setToolShown( true );
607 restoreDockWidgetsState();
609 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
611 QList<QAction*> anActns = aMenu->actions();
612 for (int i = 0; i < anActns.size(); ++i) {
613 QAction* a = anActns.at(i);
619 QList<QMenu*>::iterator it;
620 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
621 QAction* a = (*it)->menuAction();
626 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
633 \brief Deactivate module.
634 \param study current study
635 \return \c true if deactivaion is done successfully or 0 to prevent
636 deactivation on error
638 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
640 MESSAGE("PARAVIS deactivation ...")
642 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
644 QList<QAction*> anActns = aMenu->actions();
645 for (int i = 0; i < anActns.size(); ++i) {
646 QAction* a = anActns.at(i);
648 a->setVisible(false);
652 QList<QMenu*>::iterator it;
653 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
654 QAction* a = (*it)->menuAction();
656 a->setVisible(false);
659 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
660 foreach(QDockWidget* aView, aStreamingViews) {
661 if (!myDockWidgets.contains(aView))
662 myDockWidgets[aView] = aView->isVisible();
665 /*if (pqImplementation::helpWindow) {
666 pqImplementation::helpWindow->hide();
669 menuMgr()->hide(myRecentMenuId);
670 menuMgr()->hide(mySourcesMenuId);
671 menuMgr()->hide(myFiltersMenuId);
672 #ifdef PVCATALYST_ENABLED
673 menuMgr()->hide(myCatalystMenuId);
675 menuMgr()->hide(myMacrosMenuId);
676 setMenuShown( false );
677 setToolShown( false );
679 saveDockWidgetsState();
681 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
684 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
685 qInstallMsgHandler(myOldMsgHandler);
687 qInstallMessageHandler(myOldMsgHandler);
689 restoreCommonWindowsState();
691 return LightApp_Module::deactivateModule( study );
696 \brief Called when application is closed.
698 Process finalize application functionality from ParaView in order to save server settings
699 and nullify application pointer if the application is being closed.
701 \param theApp application
703 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
705 PVViewer_Core::ParaviewCleanup();
706 CAM_Module::onApplicationClosed(theApp);
710 \brief Called when study is closed.
712 Removes data model from the \a study.
714 \param study study being closed
716 void PVGUI_Module::studyClosed(SUIT_Study* study)
718 showView(false); // VSR: this seems to be not needed (all views are automatically closed)
719 clearParaviewState();
723 LightApp_Module::studyClosed(study);
727 \brief Open file of format supported by ParaView
729 void PVGUI_Module::openFile( const char* theName )
733 pqLoadDataReaction::loadData( aFiles );
737 \brief Starts Python trace.
739 Start trace invoking the newly introduced C++ API (PV 4.2)
740 (inspired from pqTraceReaction::start())
742 void PVGUI_Module::startTrace()
744 vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().activeServer()->proxyManager();
746 vtkSmartPointer<vtkSMProxy> proxy;
747 proxy.TakeReference( pxm->NewProxy( "pythontracing", "PythonTraceOptions" ) );
749 vtkNew<vtkSMParaViewPipelineController> controller;
750 controller->InitializeProxy( proxy );
752 vtkSMTrace* trace = vtkSMTrace::StartTrace();
754 // Set manually the properties entered via the dialog box poping-up when requiring
755 // a trace start in PV4.2 (trace options)
756 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
757 int type = aResourceMgr->integerValue( PARAVIS_MODULE_NAME, "tracestate_type", 2 );
758 trace->SetPropertiesToTraceOnCreate( type );
759 trace->SetFullyTraceSupplementalProxies( false );
764 \brief Stops Python trace.
766 void PVGUI_Module::stopTrace()
768 vtkSMTrace::StopTrace();
772 \brief Execute a Python script.
774 void PVGUI_Module::executeScript( const char* script )
777 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
778 pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
780 pqPythonDialog* pyDiag = manager->pythonShellDialog();
782 pyDiag->runString(script);
789 // * Debug function printing out the given interpreter's execution context
791 //void printInterpContext(PyInterp_Interp * interp )
793 // // Extract __smtraceString from interpreter's context
794 // const PyObject* ctxt = interp->getExecutionContext();
796 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
797 // Py_ssize_t siz = PyList_GET_SIZE(lst);
798 // for (Py_ssize_t i = 0; i < siz; i++)
800 // PyObject * elem = PyList_GetItem(lst, i);
801 // if (PyString_Check(elem))
803 // std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
806 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
812 \brief Returns trace string
814 QString PVGUI_Module::getTraceString()
816 QString traceString = "";
818 static const QString replaceStr( "paraview.simple" );
819 std::stringstream nl;
820 nl << std::endl; // surely there is some Qt trick to do that in a portable way??
821 QString end_line( nl.str().c_str() );
823 vtkSMTrace* tracer = vtkSMTrace::GetActiveTracer();
825 traceString = tracer->GetCurrentTrace();
826 // 'import pvsimple' is necessary to fix the first call to DisableFirstRenderCamera in the paraview trace
827 // 'ShowParaviewView()' ensure there is an opened viewing window (otherwise SEGFAULT!)
828 traceString = "import pvsimple" + end_line +
829 "pvsimple.ShowParaviewView()" + end_line + traceString;
831 // Replace import "paraview.simple" by "pvsimple"
832 if ( !traceString.isEmpty() ) {
833 int aPos = traceString.indexOf( replaceStr );
834 while ( aPos != -1 ) {
835 traceString = traceString.replace( aPos, replaceStr.length(), "pvsimple" );
836 aPos = traceString.indexOf( replaceStr, aPos );
841 // Save camera position to, which is no longer output by the tracer ...
843 vtkPythonScopeGilEnsurer psge;
844 PyObject * mods(PySys_GetObject(const_cast<char*>("modules")));
845 PyObject * trace_mod(PyDict_GetItemString(mods, "paraview.smtrace")); // module was already (really) imported by vtkSMTrace
846 if (PyModule_Check(trace_mod)) {
847 vtkSmartPyObject save_cam(PyObject_GetAttrString(trace_mod, const_cast<char*>("SaveCameras")));
848 vtkSmartPyObject camera_trace(PyObject_CallMethod(save_cam, const_cast<char*>("get_trace"), NULL));
849 // Convert to a single string
850 vtkSmartPyObject ret(PyString_FromString(end_line.toStdString().c_str()));
851 vtkSmartPyObject final_string(PyObject_CallMethod(ret, const_cast<char*>("join"),
852 const_cast<char*>("O"), (PyObject*)camera_trace));
853 if (PyString_CheckExact(final_string))
855 QString camera_qs(PyString_AsString(final_string)); // deep copy
856 traceString = traceString + end_line + end_line + QString("#### saving camera placements for all active views")
857 + end_line + end_line + camera_qs + end_line;
866 \brief Saves trace string to disk file
868 void PVGUI_Module::saveTrace( const char* theName )
870 QFile file( theName );
871 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) {
872 MESSAGE( "Could not open file:" << theName );
875 QTextStream out( &file );
876 out << getTraceString();
881 \brief Saves ParaView state to a disk file
883 void PVGUI_Module::saveParaviewState( const QString& theFileName )
885 pqApplicationCore::instance()->saveState( theFileName.toStdString().c_str() );
889 \brief Delete all objects for Paraview Pipeline Browser
891 void PVGUI_Module::clearParaviewState()
893 QAction* deleteAllAction = action( DeleteAllId );
894 if ( deleteAllAction ) {
895 deleteAllAction->activate( QAction::Trigger );
900 \brief Restores ParaView state from a disk file
902 void PVGUI_Module::loadParaviewState( const QString& theFileName )
904 pqApplicationCore::instance()->loadState( theFileName.toStdString().c_str(), getActiveServer() );
908 \brief Returns current active ParaView server
910 pqServer* PVGUI_Module::getActiveServer()
912 return pqApplicationCore::instance()->getActiveServer();
917 \brief Creates PARAVIS preferences panel.
919 void PVGUI_Module::createPreferences()
921 QList<QVariant> aIndices;
922 QStringList aStrings;
924 // Paraview settings tab
925 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
927 setPreferenceProperty(aParaViewSettingsTab, "stretch", false );
928 int aPanel = addPreference( QString(), aParaViewSettingsTab,
929 LightApp_Preferences::UserDefined, PARAVIS_MODULE_NAME, "" );
931 setPreferenceProperty( aPanel, "content", (qint64)( new PVGUI_ParaViewSettingsPane( 0, getApp() ) ) );
933 // Paravis settings tab
934 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
936 addPreference( tr( "PREF_NO_EXT_PVSERVER" ), aParaVisSettingsTab,
937 LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "no_ext_pv_server" );
939 int aSaveType = addPreference( tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
940 LightApp_Preferences::Selector,
941 PARAVIS_MODULE_NAME, "savestate_type" );
945 aIndices << 0 << 1 << 2;
946 aStrings << tr("PREF_SAVE_TYPE_0") << tr("PREF_SAVE_TYPE_1") << tr("PREF_SAVE_TYPE_2");
947 setPreferenceProperty( aSaveType, "strings", aStrings );
948 setPreferenceProperty( aSaveType, "indexes", aIndices );
950 // ... "Language" group <<start>>
951 int traceGroup = addPreference( tr( "PREF_GROUP_TRACE" ), aParaVisSettingsTab );
953 int stopTrace = addPreference( tr( "PREF_STOP_TRACE" ), traceGroup,
954 LightApp_Preferences::Bool, PARAVIS_MODULE_NAME, "stop_trace" );
955 setPreferenceProperty( stopTrace, "restart", true );
957 int aTraceType = addPreference( tr( "PREF_TRACE_TYPE_LBL" ), traceGroup,
958 LightApp_Preferences::Selector,
959 PARAVIS_MODULE_NAME, "tracestate_type" );
962 aIndices << 0 << 1 << 2;
963 aStrings << tr("PREF_TRACE_TYPE_0") << tr("PREF_TRACE_TYPE_1") << tr("PREF_TRACE_TYPE_2");
964 setPreferenceProperty( aTraceType, "strings", aStrings );
965 setPreferenceProperty( aTraceType, "indexes", aIndices );
966 setPreferenceProperty( aTraceType, "restart", true );
970 \brief. Show ParaView python trace.
972 void PVGUI_Module::onShowTrace()
974 if (!myTraceWindow) {
975 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
977 myTraceWindow->setText(getTraceString());
978 myTraceWindow->show();
979 myTraceWindow->raise();
980 myTraceWindow->activateWindow();
985 \brief. Re-initialize ParaView python trace.
987 void PVGUI_Module::onRestartTrace()
994 \brief. Close ParaView python trace.
996 void PVGUI_Module::onStopTrace()
1001 \brief Called when view manager is added
1003 void PVGUI_Module::onViewManagerAdded( SUIT_ViewManager* vm )
1005 if ( PVViewer_ViewManager* pvvm = dynamic_cast<PVViewer_ViewManager*>( vm ) ) {
1006 connect( pvvm, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1007 this, SLOT( onPVViewCreated( SUIT_ViewWindow* ) ) );
1008 connect( pvvm, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
1009 this, SLOT( onPVViewDelete( SUIT_ViewWindow* ) ) );
1014 \brief Called when view manager is removed
1016 void PVGUI_Module::onViewManagerRemoved( SUIT_ViewManager* vm )
1018 if ( PVViewer_ViewManager* pvvm = dynamic_cast<PVViewer_ViewManager*>( vm ) )
1019 disconnect( pvvm, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
1020 this, SLOT( onPVViewCreated( SUIT_ViewWindow* ) ) );
1024 \brief Show toolbars at \a vw PV view window creating when PARAVIS is active.
1026 void PVGUI_Module::onPVViewCreated( SUIT_ViewWindow* vw )
1028 myGuiElements->setToolBarVisible( true );
1029 restoreDockWidgetsState();
1033 \brief Save toolbars state at \a view view closing.
1035 void PVGUI_Module::onPVViewDelete( SUIT_ViewWindow* view )
1037 if ( dynamic_cast<PVViewer_ViewWindow*>( view ) )
1038 saveDockWidgetsState( false );
1042 \fn CAM_Module* createModule();
1043 \brief Export module instance (factory function).
1044 \return new created instance of the module
1048 #define PVGUI_EXPORT __declspec(dllexport)
1050 #define PVGUI_EXPORT
1056 PVGUI_EXPORT CAM_Module* createModule() {
1057 return new PVGUI_Module();
1060 PVGUI_EXPORT char* getModuleVersion() {
1061 return (char*)PARAVIS_VERSION_STR;