1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2014 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
22 // Author : Julia DOROVSKIKH
24 #include <Standard_math.hxx> // E.A. must be included before Python.h to fix compilation on windows
26 #undef HAVE_FINITE // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
28 #include <vtkPython.h> // Python first
29 #include "PVGUI_Module.h"
31 #ifdef PARAVIS_WITH_FULL_CORBA
32 # include "PARAVIS_Gen_i.hh"
35 //#include "PV_Tools.h"
37 #include "PVGUI_ViewModel.h"
38 #include "PVGUI_ViewManager.h"
39 #include "PVGUI_ViewWindow.h"
40 #include "PVGUI_Tools.h"
41 #include "PVGUI_ParaViewSettingsPane.h"
42 #include "PVGUI_OutputWindowAdapter.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>
53 #include "SALOME_LifeCycleCORBA.hxx"
54 #include "SALOMEDS_SObject.hxx"
56 #include "LightApp_SelectionMgr.h"
57 #include "LightApp_NameDlg.h"
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_Study.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOMEDS_Tool.hxx>
63 #include <PyInterp_Interp.h>
64 #include <PyInterp_Dispatcher.h>
65 #include <PyConsole_Console.h>
66 #include <PyConsole_Interp.h>
70 #include <QtxActionMenuMgr.h>
71 #include <QtxActionToolMgr.h>
74 #include <QApplication>
80 #include <QInputDialog>
84 #include <QStringList>
87 #include <QTextStream>
89 #include <QDockWidget>
90 #include <QHelpEngine>
92 #include <pqApplicationCore.h>
93 #include <pqPVApplicationCore.h>
94 #include <pqActiveView.h>
95 #include <pqObjectBuilder.h>
96 #include <pqOptions.h>
97 #include <pqRenderView.h>
99 #include <pqUndoStack.h>
100 #include <pqVCRController.h>
101 #include <pqTabbedMultiViewWidget.h>
102 #include <pqPipelineSource.h>
103 #include <pqActiveObjects.h>
104 #include <vtkProcessModule.h>
105 #include <vtkSMSession.h>
106 #include <vtkPVSession.h>
107 #include <vtkPVProgressHandler.h>
108 #include <pqParaViewBehaviors.h>
109 #include <pqHelpReaction.h>
110 #include <vtkOutputWindow.h>
111 #include <pqPluginManager.h>
112 #include "pqInterfaceTracker.h"
113 #include <pqSettings.h>
114 #include <pqPythonDialog.h>
115 #include <pqPythonManager.h>
116 #include <pqPythonShell.h>
117 #include <pqLoadDataReaction.h>
118 #include <vtkEventQtSlotConnect.h>
119 #include <pqPythonScriptEditor.h>
120 #include <pqCollaborationBehavior.h>
121 #include <pqDataRepresentation.h>
122 #include <pqPipelineRepresentation.h>
123 #include <pqLookupTableManager.h>
124 #include <pqDisplayColorWidget.h>
125 #include <pqColorToolbar.h>
126 #include <pqScalarBarVisibilityReaction.h>
127 #include <pqStandardPropertyWidgetInterface.h>
128 #include <pqViewStreamingBehavior.h>
129 #include <pqServerResource.h>
130 #include <pqServerConnectReaction.h>
131 #include <pqServerDisconnectReaction.h>
133 #include <PARAVIS_version.h>
135 #include <vtkPVConfig.h>
138 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
140 #include <pqAlwaysConnectedBehavior.h>
141 #include <pqApplicationCore.h>
142 #include <pqAutoLoadPluginXMLBehavior.h>
143 #include <pqCommandLineOptionsBehavior.h>
144 #include <pqCrashRecoveryBehavior.h>
145 #include <pqDataTimeStepBehavior.h>
146 #include <pqDefaultViewBehavior.h>
147 #include <pqDeleteBehavior.h>
148 #include <pqObjectPickingBehavior.h>
149 #include <pqPersistentMainWindowStateBehavior.h>
150 #include <pqPipelineContextMenuBehavior.h>
151 #include <pqPluginActionGroupBehavior.h>
152 #include <pqPluginDockWidgetsBehavior.h>
153 #include <pqPluginManager.h>
154 #include <pqPVNewSourceBehavior.h>
155 #include <pqSpreadSheetVisibilityBehavior.h>
156 #include <pqStandardViewModules.h>
157 #include <pqUndoRedoBehavior.h>
158 #include <pqViewFrameActionsBehavior.h>
159 #include <pqServerManagerObserver.h>
161 #include <vtkClientServerInterpreterInitializer.h>
164 //----------------------------------------------------------------------------
165 pqPVApplicationCore* PVGUI_Module::MyCoreApp = 0;
167 PVGUI_Module* ParavisModule = 0;
169 PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::myEngine;
174 <h2>Building and installing PARAVIS</h2>
175 As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
176 installation directory.
177 Other variables needed for correct detection of ParaView location:
178 \li PVHOME - points at the ParaView installation directory tree
179 \li PVVERSION - number of ParaView version
181 It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
184 PARAVIS module can be launched using the following commands:
185 \li Full SALOME configuration
187 runSalome --modules="PARAVIS"
190 <h2>ParaView GUI integration</h2>
191 <h3>ParaView GUI integration overview</h3>
193 The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
194 between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
196 \li SALOME GUI executable and Qt event loop
197 \li SALOME GUI desktop
198 \li Dock windows areas
199 \li SALOME menu and toolbar managers
201 Major part of the integration is implemented in PVGUI_Module class.
203 <h3>ParaView client initalization</h3>
205 ParaView client initalization is performed when an instance of PVGUI_Module class has been created
206 and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
207 The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
210 <h3>Multi-view manager</h3>
212 SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
215 \li PVGUI_ViewManager - view manager class
216 \li PVGUI_Viewer - view model class
217 \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
219 Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
220 PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
221 when the module is deactivated (the user switches to another module or a study is closed).
222 A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
223 with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
224 \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
225 of %pqViewManager widget that would break %pqMainWindowCore class.
227 <h3>ParaView plugins</h3>
228 ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
229 As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
234 \brief Implementation
235 SALOME module wrapping ParaView GUI.
240 Fix for the issue 21730: [CEA 596] Slice of polyhedron in PARAVIS returns no cell.
241 Wrap vtkEDFCutter filter.
244 extern "C" void vtkEDFCutterCS_Initialize(vtkClientServerInterpreter*);
245 static void vtkEDFHelperInit();
247 void vtkEDFHelperInit(vtkClientServerInterpreter* interp){
248 vtkEDFCutterCS_Initialize(interp);
251 void vtkEDFHelperInit() {
252 vtkClientServerInterpreterInitializer::GetInitializer()->
253 RegisterCallback(&vtkEDFHelperInit);
258 ClientFindOrCreateParavisComponent(_PTR(Study) theStudyDocument)
260 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("PARAVIS");
262 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
263 aStudyBuilder->NewCommand();
264 int aLocked = theStudyDocument->GetProperties()->IsLocked();
265 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
266 aSComponent = aStudyBuilder->NewComponent("PARAVIS");
267 _PTR(GenericAttribute) anAttr =
268 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
269 _PTR(AttributeName) aName (anAttr);
271 //CORBA::ORB_var anORB = PARAVIS::PARAVIS_Gen_i::GetORB();
273 CORBA::ORB_var anORB = CORBA::ORB_init(dnu, 0); // suppose ORB was already initialized
274 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
275 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
276 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
277 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
278 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
279 if (!Comp->_is_nil()) {
280 aName->SetValue(Comp->componentusername());
283 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
284 _PTR(AttributePixMap) aPixmap (anAttr);
285 aPixmap->SetPixMap( "pqAppIcon16.png" );
287 // Create Attribute parameters for future using
288 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
290 aStudyBuilder->DefineComponentInstance(aSComponent, PVGUI_Module::GetEngine()->GetIOR());
291 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
292 aStudyBuilder->CommitCommand();
298 Clean up function; used to stop ParaView progress events when
299 exception is caught by global exception handler.
301 void paravisCleanUp()
303 if ( pqApplicationCore::instance() ) {
304 pqServer* s = pqApplicationCore::instance()->getActiveServer();
305 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
310 \brief Constructor. Sets the default name for the module.
312 PVGUI_Module::PVGUI_Module()
313 : SalomeApp_Module( "PARAVIS" ),
314 mySelectionControlsTb( -1 ),
315 mySourcesMenuId( -1 ),
316 myFiltersMenuId( -1 ),
318 myToolbarsMenuId(-1),
327 Q_INIT_RESOURCE( PVGUI );
329 ParavisModule = this;
331 // Clear old copies of embedded macros files
332 QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
336 QDir aDestDir(aDestPath);
337 QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
338 foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
339 QString aMacrosName = QFileInfo(aMacrosPath).fileName();
340 if (aDestFiles.contains(aMacrosName)) {
341 aDestDir.remove(aMacrosName);
349 PVGUI_Module::~PVGUI_Module()
351 if (myPushTraceTimer)
352 delete myPushTraceTimer;
355 // Disconnect from server
356 pqServer* server = pqActiveObjects::instance().activeServer();
357 if (server && server->isRemote())
359 MESSAGE("~PVGUI_Module(): Disconnecting from remote server ...");
360 pqServerDisconnectReaction::disconnectFromServer();
364 PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::GetEngine()
366 // initialize PARAVIS module engine (load, if necessary)
367 if ( CORBA::is_nil( myEngine ) ) {
368 Engines::EngineComponent_var comp =
369 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" );
370 myEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp );
376 \brief Initialize module. Creates menus, prepares context menu, etc.
377 \param app SALOME GUI application instance
379 void PVGUI_Module::initialize( CAM_Application* app )
381 SalomeApp_Module::initialize( app );
383 // Create ParaViS actions
385 // Create ParaViS menus
388 // Uncomment to debug ParaView initialization
389 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
397 // Initialize ParaView client
400 // Create GUI elements (menus, toolbars, dock widgets)
401 SalomeApp_Application* anApp = getApp();
402 SUIT_Desktop* aDesktop = anApp->desktop();
404 // Remember current state of desktop toolbars
405 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
413 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
414 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
416 // new pqParaViewBehaviors(anApp->desktop(), this);
417 // Has to be replaced in order to exclude using of pqQtMessageHandlerBehaviour
418 // Start pqParaViewBehaviors
419 // Register ParaView interfaces.
420 //pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
421 pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
423 // * adds support for standard paraview views.
424 pgm->addInterface(new pqStandardViewModules(pgm));
425 pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm));
427 // Load plugins distributed with application.
428 pqApplicationCore::instance()->loadDistributedPlugins();
430 // Define application behaviors.
431 //new pqQtMessageHandlerBehavior(this);
432 new pqDataTimeStepBehavior(this);
433 new pqViewFrameActionsBehavior(this);
434 new pqSpreadSheetVisibilityBehavior(this);
435 new pqPipelineContextMenuBehavior(this);
436 new pqObjectPickingBehavior(this); // NEW in 4.1
437 new pqDefaultViewBehavior(this);
438 new pqAlwaysConnectedBehavior(this);
439 new pqPVNewSourceBehavior(this);
440 new pqDeleteBehavior(this);
441 new pqUndoRedoBehavior(this);
442 new pqCrashRecoveryBehavior(this);
443 new pqAutoLoadPluginXMLBehavior(this);
444 new pqPluginDockWidgetsBehavior(aDesktop);
445 //new pqVerifyRequiredPluginBehavior(this);
446 new pqPluginActionGroupBehavior(aDesktop);
447 //new pqFixPathsInStateFilesBehavior(this);
448 new pqCommandLineOptionsBehavior(this);
449 new pqPersistentMainWindowStateBehavior(aDesktop);
450 new pqObjectPickingBehavior(aDesktop);
451 new pqCollaborationBehavior(this);
452 //new pqMultiServerBehavior(this);
453 new pqViewStreamingBehavior(this);
455 // Setup quick-launch shortcuts.
456 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
457 QObject::connect(ctrlSpace, SIGNAL(activated()),
458 pqApplicationCore::instance(), SLOT(quickLaunch()));
460 // Find Plugin Dock Widgets
461 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
462 QList<QDockWidget*>::iterator i;
463 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
464 if(!activeDocks.contains(*i)) {
465 myDockWidgets[*i] = false; // hidden by default
471 QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
472 QList<QMenu*>::iterator im;
473 for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
474 if(!activeMenus.contains(*im)) {
479 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
480 QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
481 if (!aPath.isNull()) {
482 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
483 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
484 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
485 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
488 // Force creation of the PARAVIS engine
492 // Find created toolbars
493 QCoreApplication::processEvents();
495 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
496 foreach(QToolBar* aBar, allToolbars) {
497 if (!foreignToolbars.contains(aBar)) {
498 myToolbars[aBar] = true;
499 myToolbarBreaks[aBar] = false;
500 aBar->setVisible(false);
501 aBar->toggleViewAction()->setVisible(false);
507 // we need to start trace after connection is done
508 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(finishedAddingServer(pqServer*)),
509 this, SLOT(onFinishedAddingServer(pqServer*)));
511 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(dataRepresentationCreated(pqDataRepresentation*)),
512 this, SLOT(onDataRepresentationCreated(pqDataRepresentation*)));
514 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
515 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
518 // Start a timer to schedule asap:
519 // - the connection to the server
521 myInitTimer = new QTimer(aDesktop);
522 QObject::connect(myInitTimer, SIGNAL(timeout()), this, SLOT(onInitTimer()) );
523 myInitTimer->setSingleShot(true);
524 myInitTimer->start(0);
526 // Another timer to regularly push the trace onto the engine:
527 myPushTraceTimer = new QTimer(aDesktop);
528 QObject::connect(myPushTraceTimer, SIGNAL(timeout()), this, SLOT(onPushTraceTimer()) );
529 myPushTraceTimer->setSingleShot(false);
530 myPushTraceTimer->start(500);
533 this->VTKConnect = vtkEventQtSlotConnect::New();
535 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
537 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
539 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
541 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
542 this, SLOT(onStartProgress()));
543 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
544 this, SLOT(onEndProgress()));
549 connect(&pqActiveObjects::instance(),
550 SIGNAL(representationChanged(pqRepresentation*)),
551 this, SLOT(onRepresentationChanged(pqRepresentation*)));
554 bool PVGUI_Module::connectToExternalPVServer()
556 pqServer* server = pqActiveObjects::instance().activeServer();
557 if (server && server->isRemote())
559 // Already connected to an external server, do nothing
560 MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect.");
564 std::stringstream msg;
566 // Try to connect to the external PVServer - gives priority to an externally specified URL:
567 QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL");
568 std::string serverUrl;
569 if (!serverUrlEnv.isEmpty())
570 serverUrl = serverUrlEnv.toStdString();
573 // Get the URL from the engine (possibly starting the pvserver)
574 CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port
575 serverUrl = (char *)url;
578 msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ...";
581 if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str())))
583 std::stringstream msg2;
584 msg2 << "Error while connecting to the requested pvserver '" << serverUrl;
585 msg2 << "'. Might use default built-in connection instead!" << std::endl;
586 qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below)
587 SUIT_MessageBox::warning( getApp()->desktop(),
588 QString("Error connecting to PVServer"), QString(msg2.str().c_str()));
592 MESSAGE("connectToExternalPVServer(): Connected!");
596 void PVGUI_Module::onStartProgress()
598 QApplication::setOverrideCursor(Qt::WaitCursor);
601 void PVGUI_Module::onEndProgress()
603 QApplication::restoreOverrideCursor();
606 void PVGUI_Module::onFinishedAddingServer(pqServer* /*server*/)
608 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
609 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
614 void PVGUI_Module::onDataRepresentationCreated(pqDataRepresentation* data) {
618 if(!data->getLookupTable())
621 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
625 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
626 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
629 lut_mgr->setScalarBarVisibility(data,visible);
632 connect(data, SIGNAL(dataUpdated()), this, SLOT(onDataRepresentationUpdated()));
635 void PVGUI_Module::onDataRepresentationUpdated() {
636 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
637 if(!activeStudy) return;
639 activeStudy->Modified();
642 void PVGUI_Module::onVariableChanged(pqVariableType t, const QString) {
644 pqDisplayColorWidget* colorWidget = qobject_cast<pqDisplayColorWidget*>(sender());
648 if( t == VARIABLE_TYPE_NONE )
651 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
656 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
661 /*//VTN: getRepresentation is protected
662 pqDataRepresentation* data = colorWidget->getRepresentation();
664 if( !data->getLookupTable() )
667 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
670 lut_mgr->setScalarBarVisibility(data,visible);
673 pqColorToolbar* colorTooBar = qobject_cast<pqColorToolbar*>(colorWidget->parent());
677 pqScalarBarVisibilityReaction* scalarBarVisibility = colorTooBar->findChild<pqScalarBarVisibilityReaction *>();
678 if(scalarBarVisibility) {
679 scalarBarVisibility->setScalarBarVisibility(visible);
683 void PVGUI_Module::execPythonCommand(const QString& cmd, bool inSalomeConsole)
685 if ( inSalomeConsole ) {
686 if ( PyInterp_Dispatcher::Get()->IsBusy() ) return;
687 SalomeApp_Application* app =
688 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
689 PyConsole_Console* pyConsole = app->pythonConsole();
691 pyConsole->exec(cmd);
695 SalomeApp_Application* app =
696 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
697 PyConsole_Interp* pyInterp = app->pythonConsole()->getInterp();
699 pyInterp->run(cmd.toStdString().c_str());
700 // pqPythonManager* manager = qobject_cast<pqPythonManager*>
701 // ( pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
704 // pqPythonDialog* pyDiag = manager->pythonShellDialog();
707 // pqPythonShell* shell = pyDiag->shell();
709 // shell->executeScript(cmd);
717 \brief Initialisation timer event - fired only once, after the GUI loop is ready.
718 See creation in initialize().
720 void PVGUI_Module::onInitTimer()
722 #ifndef PARAVIS_WITH_FULL_CORBA
723 connectToExternalPVServer();
727 // if ( PyInterp_Dispatcher::Get()->IsBusy() )
729 // // Reschedule for later
730 // MESSAGE("interpreter busy -> rescheduling trace start.");
735 MESSAGE("timerEvent(): About to start trace....");
736 execPythonCommand("from paraview import smtrace;smtrace.start_trace()", false);
737 MESSAGE("timerEvent(): Trace STARTED....");
741 MESSAGE("initialize(): Initializing PARAVIS's Python context ...");
742 execPythonCommand("import paraview.servermanager as sm; sm.fromGUI=True", false);
743 MESSAGE("initialize(): Initialized.");
747 \brief Get list of embedded macros files
749 QStringList PVGUI_Module::getEmbeddedMacrosList()
751 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
753 QString aSourcePath = aRootDir + "/bin/salome/Macro";
758 QDir aSourceDir(aSourcePath);
759 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
760 QStringList aFullPathSourceFiles;
761 foreach (QString aMacrosName, aSourceFiles) {
762 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
764 return aFullPathSourceFiles;
767 void PVGUI_Module::updateMacros()
769 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
770 if(!aPythonManager) {
774 foreach (QString aStr, getEmbeddedMacrosList()) {
775 aPythonManager->addMacro(aStr);
781 \brief Get list of compliant dockable GUI elements
782 \param m map to be filled in ("type":"default_position")
784 void PVGUI_Module::windows( QMap<int, int>& m ) const
786 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
787 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
788 // ParaView diagnostic output redirected here
789 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
793 \brief Static method, performs initialization of ParaView session.
794 \return \c true if ParaView has been initialized successfully, otherwise false
796 bool PVGUI_Module::pvInit()
798 // if ( !pqImplementation::Core ){
800 // Obtain command-line arguments
803 QString aOptions = getenv("PARAVIS_OPTIONS");
804 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
805 argv = new char*[aOptList.size() + 1];
806 QStringList args = QApplication::arguments();
807 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
810 foreach (QString aStr, aOptList) {
811 argv[argc] = strdup( aStr.toLatin1().constData() );
814 MyCoreApp = new pqPVApplicationCore (argc, argv);
815 if (MyCoreApp->getOptions()->GetHelpSelected() ||
816 MyCoreApp->getOptions()->GetUnknownArgument() ||
817 MyCoreApp->getOptions()->GetErrorMessage() ||
818 MyCoreApp->getOptions()->GetTellVersion()) {
822 /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in
823 // Not sure why this is needed. Andy added this ages ago with comment saying
824 // needed for Mac apps. Need to check that it's indeed still required.
825 QDir dir(QApplication::applicationDirPath());
828 QApplication::addLibraryPath(dir.absolutePath());
829 // Load required application plugins.
830 QString plugin_string = "";
831 QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
832 pqBrandPluginsLoader loader;
833 if (loader.loadPlugins(plugin_list) == false) {
834 printf("Failed to load required plugins for this application\n");
838 // Load optional plugins.
840 plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
841 loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
843 // End of Initializer code
845 vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New());
847 new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET on creation
849 for (int i = 0; i < argc; i++)
858 \brief Shows (toShow = true) or hides ParaView view window
860 void PVGUI_Module::showView( bool toShow )
862 SalomeApp_Application* anApp = getApp();
863 PVGUI_ViewManager* viewMgr =
864 dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
866 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
867 anApp->addViewManager( viewMgr );
868 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
869 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
872 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
874 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
877 pvWnd->setShown( toShow );
878 if ( toShow ) pvWnd->setFocus();
882 \brief Slot to show help for proxy.
884 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
886 pqHelpReaction::showProxyHelp(groupname, proxyname);
891 \brief Slot to show the waiting state.
893 void PVGUI_Module::onPreAccept()
895 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
896 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
900 \brief Slot to show the ready state.
902 void PVGUI_Module::onPostAccept()
904 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
905 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
909 \brief Slot to switch off wait cursor.
911 void PVGUI_Module::endWaitCursor()
913 QApplication::restoreOverrideCursor();
917 \brief Returns the ParaView multi-view manager.
919 pqTabbedMultiViewWidget* PVGUI_Module::getMultiViewManager() const
921 return qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
925 static void ParavisMessageOutput(QtMsgType type, const char *msg)
930 vtkOutputWindow::GetInstance()->DisplayText(msg);
933 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
936 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
939 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
947 \brief Activate module.
948 \param study current study
949 \return \c true if activaion is done successfully or 0 to prevent
952 bool PVGUI_Module::activateModule( SUIT_Study* study )
954 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
956 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
958 storeCommonWindowsState();
960 bool isDone = SalomeApp_Module::activateModule( study );
961 if ( !isDone ) return false;
964 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
965 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
966 if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
967 if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
968 setMenuShown( true );
969 setToolShown( true );
971 restoreDockWidgetsState();
973 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
975 QList<QAction*> anActns = aMenu->actions();
976 for (int i = 0; i < anActns.size(); ++i) {
977 QAction* a = anActns.at(i);
983 QList<QMenu*>::iterator it;
984 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
985 QAction* a = (*it)->menuAction();
990 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
992 ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this));
999 \brief Deactivate module.
1000 \param study current study
1001 \return \c true if deactivaion is done successfully or 0 to prevent
1002 deactivation on error
1004 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
1006 MESSAGE("PARAVIS deactivation ...")
1008 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
1010 QList<QAction*> anActns = aMenu->actions();
1011 for (int i = 0; i < anActns.size(); ++i) {
1012 QAction* a = anActns.at(i);
1014 a->setVisible(false);
1018 QList<QMenu*>::iterator it;
1019 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
1020 QAction* a = (*it)->menuAction();
1022 a->setVisible(false);
1025 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
1026 foreach(QDockWidget* aView, aStreamingViews) {
1027 if (!myDockWidgets.contains(aView))
1028 myDockWidgets[aView] = aView->isVisible();
1031 /*if (pqImplementation::helpWindow) {
1032 pqImplementation::helpWindow->hide();
1036 menuMgr()->hide(myRecentMenuId);
1037 menuMgr()->hide(mySourcesMenuId);
1038 menuMgr()->hide(myFiltersMenuId);
1039 menuMgr()->hide(myMacrosMenuId);
1040 menuMgr()->hide(myToolbarsMenuId);
1041 setMenuShown( false );
1042 setToolShown( false );
1044 saveDockWidgetsState();
1046 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
1048 if (myOldMsgHandler)
1049 qInstallMsgHandler(myOldMsgHandler);
1051 restoreCommonWindowsState();
1053 return SalomeApp_Module::deactivateModule( study );
1058 \brief Called when application is closed.
1060 Process finalize application functionality from ParaView in order to save server settings
1061 and nullify application pointer if the application is being closed.
1063 \param theApp application
1065 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
1067 pqApplicationCore::instance()->settings()->sync();
1068 int aAppsNb = SUIT_Session::session()->applications().size();
1070 deleteTemporaryFiles();
1071 MyCoreApp->deleteLater();
1073 CAM_Module::onApplicationClosed(theApp);
1078 \brief Deletes temporary files created during import operation from VISU
1080 void PVGUI_Module::deleteTemporaryFiles()
1082 foreach(QString aFile, myTemporaryFiles) {
1083 if (QFile::exists(aFile)) {
1084 QFile::remove(aFile);
1091 \brief Called when study is closed.
1093 Removes data model from the \a study.
1095 \param study study being closed
1097 void PVGUI_Module::studyClosed(SUIT_Study* study)
1099 clearParaviewState();
1101 SalomeApp_Module::studyClosed(study);
1105 \brief Called when study is opened.
1107 void PVGUI_Module::onModelOpened()
1109 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1114 _PTR(SComponent) paravisComp =
1115 studyDS->FindComponent(GetEngine()->ComponentDataType());
1120 _PTR(ChildIterator) anIter(studyDS->NewChildIterator(paravisComp));
1121 for (; anIter->More(); anIter->Next()) {
1122 _PTR(SObject) aSObj = anIter->Value();
1123 _PTR(GenericAttribute) anAttr;
1124 if (!aSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1127 _PTR(AttributeLocalID) anID(anAttr);
1128 if (anID->Value() == PVSTATEID) {
1135 \brief Returns IOR of current engine
1137 QString PVGUI_Module::engineIOR() const
1139 CORBA::String_var anIOR = GetEngine()->GetIOR();
1140 return QString(anIOR.in());
1145 \brief Open file of format supported by ParaView
1147 void PVGUI_Module::openFile(const char* theName)
1151 pqLoadDataReaction::loadData(aFiles);
1154 void PVGUI_Module::executeScript(const char *script)
1157 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
1158 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
1160 pqPythonDialog* pyDiag = manager->pythonShellDialog();
1162 pyDiag->runString(script);
1169 // * Debug function printing out the given interpreter's execution context
1171 //void printInterpContext(PyInterp_Interp * interp )
1173 // // Extract __smtraceString from interpreter's context
1174 // const PyObject* ctxt = interp->getExecutionContext();
1176 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
1177 // Py_ssize_t siz = PyList_GET_SIZE(lst);
1178 // for (Py_ssize_t i = 0; i < siz; i++)
1180 // PyObject * elem = PyList_GetItem(lst, i);
1181 // if (PyString_Check(elem))
1183 // std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
1186 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
1192 \brief Returns trace string
1194 static const QString MYReplaceStr("paraview.simple");
1195 static const QString MYReplaceImportStr("except: from pvsimple import *");
1196 QString PVGUI_Module::getTraceString()
1198 QString traceString;
1201 PyLockWrapper lck; // Acquire GIL
1203 const char * code = "from paraview import smtrace;"
1204 "__smtraceString = smtrace.get_trace_string()";
1205 PyRun_SimpleString(code);
1206 // Now get the value of __smtraceString
1207 PyObject* main_module = PyImport_AddModule((char*)"__main__");
1208 PyObject* global_dict = PyModule_GetDict(main_module);
1209 PyObject* string_object = PyDict_GetItemString(global_dict, "__smtraceString");
1210 char* string_ptr = string_object ? PyString_AsString(string_object) : 0;
1212 traceString = string_ptr;
1216 if ((!traceString.isNull()) && traceString.length() != 0) {
1217 int aPos = traceString.indexOf(MYReplaceStr);
1218 while (aPos != -1) {
1219 traceString = traceString.replace(aPos, MYReplaceStr.length(), "pvsimple");
1220 aPos = traceString.indexOf(MYReplaceStr, aPos);
1222 int aImportPos = traceString.indexOf(MYReplaceImportStr);
1223 if(aImportPos != -1)
1225 traceString = traceString.replace(aImportPos, MYReplaceImportStr.length(), "except:\n import pvsimple\n from pvsimple import *");
1233 \brief Saves trace string to disk file
1235 void PVGUI_Module::saveTrace(const char* theName)
1237 QFile file(theName);
1238 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1239 MESSAGE( "Could not open file:" << theName );
1242 QTextStream out(&file);
1243 out << getTraceString();
1248 \brief Saves ParaView state to a disk file
1250 void PVGUI_Module::saveParaviewState(const char* theFileName)
1252 pqApplicationCore::instance()->saveState(theFileName);
1256 \brief Delete all objects for Paraview Pipeline Browser
1258 void PVGUI_Module::clearParaviewState()
1260 QAction* deleteAllAction = action(DeleteAllId);
1261 if (deleteAllAction) {
1262 deleteAllAction->activate(QAction::Trigger);
1267 \brief Restores ParaView state from a disk file
1269 If toClear == true, the current ojects will be deleted
1271 void PVGUI_Module::loadParaviewState(const char* theFileName)
1273 pqApplicationCore::instance()->loadState(theFileName, getActiveServer());
1277 \brief Returns current active ParaView server
1279 pqServer* PVGUI_Module::getActiveServer()
1281 return pqApplicationCore::instance()->getActiveServer();
1286 \brief Creates PARAVIS preference pane
1288 void PVGUI_Module::createPreferences()
1290 // Paraview settings tab
1291 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
1292 int aPanel = addPreference(QString(), aParaViewSettingsTab, LightApp_Preferences::UserDefined, "PARAVIS", "");
1293 setPreferenceProperty(aPanel, "content", (qint64)(new PVGUI_ParaViewSettingsPane()));
1295 // Paravis settings tab
1296 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
1297 addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
1299 int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
1300 LightApp_Preferences::Selector,
1301 "PARAVIS", "savestate_type");
1302 QList<QVariant> aIndices;
1303 QStringList aStrings;
1305 aStrings<<tr("PREF_SAVE_TYPE_0");
1306 aStrings<<tr("PREF_SAVE_TYPE_1");
1307 aStrings<<tr("PREF_SAVE_TYPE_2");
1308 setPreferenceProperty(aSaveType, "strings", aStrings);
1309 setPreferenceProperty(aSaveType, "indexes", aIndices);
1311 //rnv: imp 21712: [CEA 581] Preference to display legend by default
1312 int aDispColoreLegend = addPreference( tr( "PREF_SHOW_COLOR_LEGEND" ), aParaVisSettingsTab,
1313 LightApp_Preferences::Bool, "PARAVIS", "show_color_legend");
1317 \brief Creates ParaViS context menu popup
1319 void PVGUI_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
1321 SalomeApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
1323 // Check if we are in Object Browser
1324 SUIT_DataBrowser* ob = getApp()->objectBrowser();
1325 bool isOBClient = (ob && theClient == ob->popupClientType());
1330 // Get list of selected objects
1331 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1332 SALOME_ListIO aListIO;
1333 aSelectionMgr->selectedObjects(aListIO);
1334 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1335 QString entry = QString(aListIO.First()->getEntry());
1338 SalomeApp_Study* activeStudy =
1339 dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
1344 // Get SALOMEDS client study
1345 _PTR(Study) studyDS = activeStudy->studyDS();
1350 QString paravisDataType(GetEngine()->ComponentDataType());
1351 if(activeStudy && activeStudy->isComponent(entry) &&
1352 activeStudy->componentDataType(entry) == paravisDataType) {
1353 // ParaViS module object
1354 theMenu->addSeparator();
1355 theMenu->addAction(action(SaveStatePopupId));
1358 // Try to get state object
1359 _PTR(SObject) stateSObj =
1360 studyDS->FindObjectID(entry.toLatin1().constData());
1366 _PTR(GenericAttribute) anAttr;
1367 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1371 _PTR(AttributeLocalID) anID(anAttr);
1373 if (anID->Value() == PVSTATEID) {
1374 // Paraview state object
1375 theMenu->addSeparator();
1376 theMenu->addAction(action(AddStatePopupId));
1377 theMenu->addAction(action(CleanAndAddStatePopupId));
1378 theMenu->addSeparator();
1379 theMenu->addAction(action(ParaVisRenameId));
1380 theMenu->addAction(action(ParaVisDeleteId));
1387 \brief. Show ParaView python trace.
1389 void PVGUI_Module::onShowTrace()
1391 if (!myTraceWindow) {
1392 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
1394 myTraceWindow->setText(getTraceString());
1395 myTraceWindow->show();
1396 myTraceWindow->raise();
1397 myTraceWindow->activateWindow();
1402 \brief. Re-initialize ParaView python trace.
1404 void PVGUI_Module::onRestartTrace()
1406 QString script = "from paraview import smtrace\n";
1407 script += "smtrace.stop_trace()\n";
1408 script += "smtrace.start_trace()\n";
1409 execPythonCommand(script, false);
1413 \brief Show ParaView view.
1415 void PVGUI_Module::onNewParaViewWindow()
1421 \brief Save state under the module root object.
1423 void PVGUI_Module::onSaveMultiState()
1425 // Create state study object
1427 // Get SALOMEDS client study
1428 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1433 _PTR(SComponent) paravisComp =
1434 studyDS->FindComponent(GetEngine()->ComponentDataType());
1439 // Unlock the study if it is locked
1440 bool isLocked = studyDS->GetProperties()->IsLocked();
1442 studyDS->GetProperties()->SetLocked(false);
1445 QString stateName = tr("SAVED_PARAVIEW_STATE_NAME") +
1446 QString::number(myStateCounter + 1);
1448 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1449 _PTR(SObject) newSObj = studyBuilder->NewObject(paravisComp);
1452 _PTR(GenericAttribute) anAttr;
1453 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeName");
1454 _PTR(AttributeName) nameAttr(anAttr);
1456 nameAttr->SetValue(stateName.toLatin1().constData());
1459 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeLocalID");
1460 _PTR(AttributeLocalID) localIdAttr(anAttr);
1462 localIdAttr->SetValue(PVSTATEID);
1465 QString stateEntry = QString::fromStdString(newSObj->GetID());
1467 // File name for state saving
1468 QString tmpDir = QString::fromStdString(SALOMEDS_Tool::GetTmpDir());
1469 QString fileName = QString("%1_paravisstate:%2").arg(tmpDir, stateEntry);
1471 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeString");
1472 _PTR(AttributeString) stringAttr(anAttr);
1474 stringAttr->SetValue(fileName.toLatin1().constData());
1476 // Lock the study back if necessary
1478 studyDS->GetProperties()->SetLocked(true);
1482 saveParaviewState(fileName.toLatin1().constData());
1483 myTemporaryFiles.append(fileName);
1485 // Increment the counter
1492 \brief Restore the selected state by merging with the current one.
1494 void PVGUI_Module::onAddState()
1496 loadSelectedState(false);
1500 \brief Clean the current state and restore the selected one.
1502 void PVGUI_Module::onCleanAddState()
1504 loadSelectedState(true);
1508 \brief Rename the selected object.
1510 void PVGUI_Module::onRename()
1512 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1513 SALOME_ListIO aListIO;
1514 aSelectionMgr->selectedObjects(aListIO);
1516 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1517 std::string entry = aListIO.First()->getEntry();
1519 // Get SALOMEDS client study
1520 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1525 // Unlock the study if it is locked
1526 bool isLocked = studyDS->GetProperties()->IsLocked();
1528 studyDS->GetProperties()->SetLocked(false);
1531 // Rename the selected state object
1532 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1537 _PTR(GenericAttribute) anAttr;
1538 if (stateSObj->FindAttribute(anAttr, "AttributeName")) {
1539 _PTR(AttributeName) nameAttr (anAttr);
1541 LightApp_NameDlg::getName(getApp()->desktop(), nameAttr->Value().c_str());
1542 if (!newName.isEmpty()) {
1543 nameAttr->SetValue(newName.toLatin1().constData());
1544 aListIO.First()->setName(newName.toLatin1().constData());
1548 // Lock the study back if necessary
1550 studyDS->GetProperties()->SetLocked(true);
1553 // Update object browser
1560 \brief Delete the selected objects.
1562 void PVGUI_Module::onDelete()
1564 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1565 SALOME_ListIO aListIO;
1566 aSelectionMgr->selectedObjects(aListIO);
1568 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1569 std::string entry = aListIO.First()->getEntry();
1571 // Get SALOMEDS client study
1572 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1577 // Unlock the study if it is locked
1578 bool isLocked = studyDS->GetProperties()->IsLocked();
1580 studyDS->GetProperties()->SetLocked(false);
1583 // Remove the selected state from the study
1584 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1585 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1586 studyBuilder->RemoveObject(stateSObj);
1588 // Lock the study back if necessary
1590 studyDS->GetProperties()->SetLocked(true);
1593 // Update object browser
1598 void PVGUI_Module::onPushTraceTimer()
1600 // MESSAGE("onPushTraceTimer(): Pushing trace to engine...");
1601 GetEngine()->PutPythonTraceStringToEngine(getTraceString().toStdString().c_str());
1605 \brief Discover help project files from the resources.
1606 \return name of the help file.
1608 QString PVGUI_Module::getHelpFileName() {
1609 QString aPVHome(getenv("PVHOME"));
1610 if (aPVHome.isNull()) {
1611 qWarning("Wariable PVHOME is not defined");
1614 QChar aSep = QDir::separator();
1615 //PARAVIEW_VERSION from the vtkPVConfig.h file
1616 QString aFileName = aPVHome + aSep + "share" + aSep + "doc" + aSep + "paraview-"+ PARAVIEW_VERSION + aSep + "paraview.qch";
1622 \brief Load selected paraview state
1624 If toClear == true, the current state will be cleared
1626 void PVGUI_Module::loadSelectedState(bool toClear)
1630 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1631 SALOME_ListIO aListIO;
1632 aSelectionMgr->selectedObjects(aListIO);
1634 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1635 std::string entry = aListIO.First()->getEntry();
1637 // Get SALOMEDS client study
1638 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1644 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1645 _PTR(GenericAttribute) anAttr;
1646 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1649 _PTR(AttributeLocalID) anID(anAttr);
1650 if (!anID->Value() == PVSTATEID) {
1654 // Get state file name
1655 if (stateSObj->FindAttribute(anAttr, "AttributeString")) {
1656 _PTR(AttributeString) aStringAttr(anAttr);
1657 QString stringValue(aStringAttr->Value().c_str());
1659 if (QFile::exists(stringValue)) {
1660 fileName = stringValue;
1665 if (!fileName.isEmpty()) {
1667 clearParaviewState();
1670 loadParaviewState(fileName.toLatin1().constData());
1673 SUIT_MessageBox::critical(getApp()->desktop(),
1675 tr("ERR_STATE_CANNOT_BE_RESTORED"));
1679 void PVGUI_Module::onRepresentationChanged(pqRepresentation*) {
1682 //rnv: to fix the issue "21712: [CEA 581] Preference to display legend by default"
1683 // find the pqDisplayColorWidget instances and connect the variableChanged SIGNAL on the
1684 // onVariableChanged slot of this class. This connection needs to change visibility
1685 // of the "Colored Legend" after change the "Color By" array.
1686 QList<pqDisplayColorWidget*> aWidget = getApp()->desktop()->findChildren<pqDisplayColorWidget*>();
1688 for (int i = 0; i < aWidget.size() ; i++ ) {
1690 connect( aWidget[i], SIGNAL ( variableChanged ( pqVariableType, const QString ) ),
1691 this, SLOT(onVariableChanged( pqVariableType, const QString) ), Qt::UniqueConnection );
1698 \fn CAM_Module* createModule();
1699 \brief Export module instance (factory function).
1700 \return new created instance of the module
1704 #define PVGUI_EXPORT __declspec(dllexport)
1706 #define PVGUI_EXPORT
1712 PVGUI_EXPORT CAM_Module* createModule() {
1717 return new PVGUI_Module();
1720 PVGUI_EXPORT char* getModuleVersion() {
1721 return (char*)PARAVIS_VERSION_STR;