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"
43 #include "PVGUI_Behaviors.h"
45 #include <SUIT_DataBrowser.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_ExceptionHandler.h>
54 #include "SALOME_LifeCycleCORBA.hxx"
55 #include "SALOMEDS_SObject.hxx"
57 #include "LightApp_SelectionMgr.h"
58 #include "LightApp_NameDlg.h"
60 #include <SalomeApp_Application.h>
61 #include <SalomeApp_Study.h>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOMEDS_Tool.hxx>
64 #include <PyInterp_Interp.h>
65 #include <PyInterp_Dispatcher.h>
66 #include <PyConsole_Console.h>
67 #include <PyConsole_Interp.h>
71 #include <QtxActionMenuMgr.h>
72 #include <QtxActionToolMgr.h>
75 #include <QApplication>
81 #include <QInputDialog>
85 #include <QStringList>
88 #include <QTextStream>
90 #include <QDockWidget>
91 #include <QHelpEngine>
93 #include <pqApplicationCore.h>
94 #include <pqPVApplicationCore.h>
95 #include <pqActiveView.h>
96 #include <pqObjectBuilder.h>
97 #include <pqOptions.h>
98 #include <pqRenderView.h>
100 #include <pqUndoStack.h>
101 #include <pqVCRController.h>
102 #include <pqTabbedMultiViewWidget.h>
103 #include <pqPipelineSource.h>
104 #include <pqActiveObjects.h>
105 #include <vtkProcessModule.h>
106 #include <vtkSMSession.h>
107 #include <vtkPVSession.h>
108 #include <vtkPVProgressHandler.h>
109 #include <pqParaViewBehaviors.h>
110 #include <pqHelpReaction.h>
111 #include <vtkOutputWindow.h>
112 #include <pqPluginManager.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 <pqDataRepresentation.h>
121 #include <pqPipelineRepresentation.h>
122 #include <pqLookupTableManager.h>
123 #include <pqDisplayColorWidget.h>
124 #include <pqColorToolbar.h>
125 #include <pqScalarBarVisibilityReaction.h>
127 #include <pqServerResource.h>
128 #include <pqServerConnectReaction.h>
129 #include <pqServerDisconnectReaction.h>
131 #include <pqApplicationCore.h>
132 #include <pqServerManagerObserver.h>
133 #include <vtkClientServerInterpreterInitializer.h>
134 #include <vtkPVConfig.h>
136 #include <PARAVIS_version.h>
138 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
140 //----------------------------------------------------------------------------
141 pqPVApplicationCore* PVGUI_Module::MyCoreApp = 0;
143 PVGUI_Module* ParavisModule = 0;
145 PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::myEngine;
150 <h2>Building and installing PARAVIS</h2>
151 As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
152 installation directory.
153 Other variables needed for correct detection of ParaView location:
154 \li PVHOME - points at the ParaView installation directory tree
155 \li PVVERSION - number of ParaView version
157 It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
160 PARAVIS module can be launched using the following commands:
161 \li Full SALOME configuration
163 runSalome --modules="PARAVIS"
166 <h2>ParaView GUI integration</h2>
167 <h3>ParaView GUI integration overview</h3>
169 The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
170 between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
172 \li SALOME GUI executable and Qt event loop
173 \li SALOME GUI desktop
174 \li Dock windows areas
175 \li SALOME menu and toolbar managers
177 Major part of the integration is implemented in PVGUI_Module class.
179 <h3>ParaView client initalization</h3>
181 ParaView client initalization is performed when an instance of PVGUI_Module class has been created
182 and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
183 The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
186 <h3>Multi-view manager</h3>
188 SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
191 \li PVGUI_ViewManager - view manager class
192 \li PVGUI_Viewer - view model class
193 \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
195 Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
196 PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
197 when the module is deactivated (the user switches to another module or a study is closed).
198 A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
199 with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
200 \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
201 of %pqViewManager widget that would break %pqMainWindowCore class.
203 <h3>ParaView plugins</h3>
204 ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
205 As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
210 \brief Implementation
211 SALOME module wrapping ParaView GUI.
216 Fix for the issue 21730: [CEA 596] Slice of polyhedron in PARAVIS returns no cell.
217 Wrap vtkEDFCutter filter.
220 extern "C" void vtkEDFCutterCS_Initialize(vtkClientServerInterpreter*);
221 static void vtkEDFHelperInit();
223 void vtkEDFHelperInit(vtkClientServerInterpreter* interp){
224 vtkEDFCutterCS_Initialize(interp);
227 void vtkEDFHelperInit() {
228 vtkClientServerInterpreterInitializer::GetInitializer()->
229 RegisterCallback(&vtkEDFHelperInit);
234 ClientFindOrCreateParavisComponent(_PTR(Study) theStudyDocument)
236 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("PARAVIS");
238 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
239 aStudyBuilder->NewCommand();
240 int aLocked = theStudyDocument->GetProperties()->IsLocked();
241 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
242 aSComponent = aStudyBuilder->NewComponent("PARAVIS");
243 _PTR(GenericAttribute) anAttr =
244 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
245 _PTR(AttributeName) aName (anAttr);
247 //CORBA::ORB_var anORB = PARAVIS::PARAVIS_Gen_i::GetORB();
249 CORBA::ORB_var anORB = CORBA::ORB_init(dnu, 0); // suppose ORB was already initialized
250 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
251 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
252 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
253 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
254 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
255 if (!Comp->_is_nil()) {
256 aName->SetValue(Comp->componentusername());
259 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
260 _PTR(AttributePixMap) aPixmap (anAttr);
261 aPixmap->SetPixMap( "pqAppIcon16.png" );
263 // Create Attribute parameters for future using
264 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
266 aStudyBuilder->DefineComponentInstance(aSComponent, PVGUI_Module::GetEngine()->GetIOR());
267 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
268 aStudyBuilder->CommitCommand();
274 Clean up function; used to stop ParaView progress events when
275 exception is caught by global exception handler.
277 void paravisCleanUp()
279 if ( pqApplicationCore::instance() ) {
280 pqServer* s = pqApplicationCore::instance()->getActiveServer();
281 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
286 \brief Constructor. Sets the default name for the module.
288 PVGUI_Module::PVGUI_Module()
289 : SalomeApp_Module( "PARAVIS" ),
290 mySelectionControlsTb( -1 ),
291 mySourcesMenuId( -1 ),
292 myFiltersMenuId( -1 ),
294 myToolbarsMenuId(-1),
303 Q_INIT_RESOURCE( PVGUI );
305 ParavisModule = this;
307 // Clear old copies of embedded macros files
308 QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
312 QDir aDestDir(aDestPath);
313 QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
314 foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
315 QString aMacrosName = QFileInfo(aMacrosPath).fileName();
316 if (aDestFiles.contains(aMacrosName)) {
317 aDestDir.remove(aMacrosName);
325 PVGUI_Module::~PVGUI_Module()
327 if (myPushTraceTimer)
328 delete myPushTraceTimer;
331 // Disconnect from server
332 pqServer* server = pqActiveObjects::instance().activeServer();
333 if (server && server->isRemote())
335 MESSAGE("~PVGUI_Module(): Disconnecting from remote server ...");
336 pqServerDisconnectReaction::disconnectFromServer();
340 PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::GetEngine()
342 // initialize PARAVIS module engine (load, if necessary)
343 if ( CORBA::is_nil( myEngine ) ) {
344 Engines::EngineComponent_var comp =
345 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" );
346 myEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp );
352 \brief Initialize module. Creates menus, prepares context menu, etc.
353 \param app SALOME GUI application instance
355 void PVGUI_Module::initialize( CAM_Application* app )
357 SalomeApp_Module::initialize( app );
359 // Create ParaViS actions
361 // Create ParaViS menus
364 // Uncomment to debug ParaView initialization
365 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
373 // Initialize ParaView client
376 // Create GUI elements (menus, toolbars, dock widgets)
377 SalomeApp_Application* anApp = getApp();
378 SUIT_Desktop* aDesktop = anApp->desktop();
380 // Remember current state of desktop toolbars
381 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
389 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
390 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
392 PVGUI_Behaviors * behav = new PVGUI_Behaviors(this);
393 behav->instanciateAllBehaviors(aDesktop);
395 // Setup quick-launch shortcuts.
396 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
397 QObject::connect(ctrlSpace, SIGNAL(activated()),
398 pqApplicationCore::instance(), SLOT(quickLaunch()));
400 // Find Plugin Dock Widgets
401 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
402 QList<QDockWidget*>::iterator i;
403 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
404 if(!activeDocks.contains(*i)) {
405 myDockWidgets[*i] = false; // hidden by default
411 QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
412 QList<QMenu*>::iterator im;
413 for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
414 if(!activeMenus.contains(*im)) {
419 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
420 QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
421 if (!aPath.isNull()) {
422 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
423 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
424 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
425 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
428 // Force creation of the PARAVIS engine
432 // Find created toolbars
433 QCoreApplication::processEvents();
435 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
436 foreach(QToolBar* aBar, allToolbars) {
437 if (!foreignToolbars.contains(aBar)) {
438 myToolbars[aBar] = true;
439 myToolbarBreaks[aBar] = false;
440 aBar->setVisible(false);
441 aBar->toggleViewAction()->setVisible(false);
447 // we need to start trace after connection is done
448 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(finishedAddingServer(pqServer*)),
449 this, SLOT(onFinishedAddingServer(pqServer*)));
451 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(dataRepresentationCreated(pqDataRepresentation*)),
452 this, SLOT(onDataRepresentationCreated(pqDataRepresentation*)));
454 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
455 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
458 // Start a timer to schedule asap:
459 // - the connection to the server
461 myInitTimer = new QTimer(aDesktop);
462 QObject::connect(myInitTimer, SIGNAL(timeout()), this, SLOT(onInitTimer()) );
463 myInitTimer->setSingleShot(true);
464 myInitTimer->start(0);
466 // Another timer to regularly push the trace onto the engine:
467 myPushTraceTimer = new QTimer(aDesktop);
468 QObject::connect(myPushTraceTimer, SIGNAL(timeout()), this, SLOT(onPushTraceTimer()) );
469 myPushTraceTimer->setSingleShot(false);
470 myPushTraceTimer->start(500);
473 this->VTKConnect = vtkEventQtSlotConnect::New();
475 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
477 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
479 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
481 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
482 this, SLOT(onStartProgress()));
483 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
484 this, SLOT(onEndProgress()));
489 connect(&pqActiveObjects::instance(),
490 SIGNAL(representationChanged(pqRepresentation*)),
491 this, SLOT(onRepresentationChanged(pqRepresentation*)));
494 bool PVGUI_Module::connectToExternalPVServer()
496 pqServer* server = pqActiveObjects::instance().activeServer();
497 if (server && server->isRemote())
499 // Already connected to an external server, do nothing
500 MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect.");
504 std::stringstream msg;
506 // Try to connect to the external PVServer - gives priority to an externally specified URL:
507 QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL");
508 std::string serverUrl;
509 if (!serverUrlEnv.isEmpty())
510 serverUrl = serverUrlEnv.toStdString();
513 // Get the URL from the engine (possibly starting the pvserver)
514 CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port
515 serverUrl = (char *)url;
518 msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ...";
521 if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str())))
523 std::stringstream msg2;
524 msg2 << "Error while connecting to the requested pvserver '" << serverUrl;
525 msg2 << "'. Might use default built-in connection instead!" << std::endl;
526 qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below)
527 SUIT_MessageBox::warning( getApp()->desktop(),
528 QString("Error connecting to PVServer"), QString(msg2.str().c_str()));
532 MESSAGE("connectToExternalPVServer(): Connected!");
536 void PVGUI_Module::onStartProgress()
538 QApplication::setOverrideCursor(Qt::WaitCursor);
541 void PVGUI_Module::onEndProgress()
543 QApplication::restoreOverrideCursor();
546 void PVGUI_Module::onFinishedAddingServer(pqServer* /*server*/)
548 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
549 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
554 void PVGUI_Module::onDataRepresentationCreated(pqDataRepresentation* data) {
558 if(!data->getLookupTable())
561 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
565 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
566 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
569 lut_mgr->setScalarBarVisibility(data,visible);
572 connect(data, SIGNAL(dataUpdated()), this, SLOT(onDataRepresentationUpdated()));
575 void PVGUI_Module::onDataRepresentationUpdated() {
576 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
577 if(!activeStudy) return;
579 activeStudy->Modified();
582 void PVGUI_Module::onVariableChanged(pqVariableType t, const QString) {
584 pqDisplayColorWidget* colorWidget = qobject_cast<pqDisplayColorWidget*>(sender());
588 if( t == VARIABLE_TYPE_NONE )
591 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
596 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
601 /*//VTN: getRepresentation is protected
602 pqDataRepresentation* data = colorWidget->getRepresentation();
604 if( !data->getLookupTable() )
607 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
610 lut_mgr->setScalarBarVisibility(data,visible);
613 pqColorToolbar* colorTooBar = qobject_cast<pqColorToolbar*>(colorWidget->parent());
617 pqScalarBarVisibilityReaction* scalarBarVisibility = colorTooBar->findChild<pqScalarBarVisibilityReaction *>();
618 if(scalarBarVisibility) {
619 scalarBarVisibility->setScalarBarVisibility(visible);
623 void PVGUI_Module::execPythonCommand(const QString& cmd, bool inSalomeConsole)
625 if ( inSalomeConsole ) {
626 if ( PyInterp_Dispatcher::Get()->IsBusy() ) return;
627 SalomeApp_Application* app =
628 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
629 PyConsole_Console* pyConsole = app->pythonConsole();
631 pyConsole->exec(cmd);
635 SalomeApp_Application* app =
636 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
637 PyConsole_Interp* pyInterp = app->pythonConsole()->getInterp();
639 pyInterp->run(cmd.toStdString().c_str());
640 // pqPythonManager* manager = qobject_cast<pqPythonManager*>
641 // ( pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
644 // pqPythonDialog* pyDiag = manager->pythonShellDialog();
647 // pqPythonShell* shell = pyDiag->shell();
649 // shell->executeScript(cmd);
657 \brief Initialisation timer event - fired only once, after the GUI loop is ready.
658 See creation in initialize().
660 void PVGUI_Module::onInitTimer()
662 #ifndef PARAVIS_WITH_FULL_CORBA
663 connectToExternalPVServer();
667 // if ( PyInterp_Dispatcher::Get()->IsBusy() )
669 // // Reschedule for later
670 // MESSAGE("interpreter busy -> rescheduling trace start.");
675 MESSAGE("timerEvent(): About to start trace....");
676 execPythonCommand("from paraview import smtrace;smtrace.start_trace()", false);
677 MESSAGE("timerEvent(): Trace STARTED....");
681 MESSAGE("initialize(): Initializing PARAVIS's Python context ...");
682 execPythonCommand("import paraview.servermanager as sm; sm.fromGUI=True", false);
683 MESSAGE("initialize(): Initialized.");
687 \brief Get list of embedded macros files
689 QStringList PVGUI_Module::getEmbeddedMacrosList()
691 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
693 QString aSourcePath = aRootDir + "/bin/salome/Macro";
698 QDir aSourceDir(aSourcePath);
699 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
700 QStringList aFullPathSourceFiles;
701 foreach (QString aMacrosName, aSourceFiles) {
702 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
704 return aFullPathSourceFiles;
707 void PVGUI_Module::updateMacros()
709 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
710 if(!aPythonManager) {
714 foreach (QString aStr, getEmbeddedMacrosList()) {
715 aPythonManager->addMacro(aStr);
721 \brief Get list of compliant dockable GUI elements
722 \param m map to be filled in ("type":"default_position")
724 void PVGUI_Module::windows( QMap<int, int>& m ) const
726 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
727 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
728 // ParaView diagnostic output redirected here
729 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
733 \brief Static method, performs initialization of ParaView session.
734 \return \c true if ParaView has been initialized successfully, otherwise false
736 bool PVGUI_Module::pvInit()
738 // if ( !pqImplementation::Core ){
740 // Obtain command-line arguments
743 QString aOptions = getenv("PARAVIS_OPTIONS");
744 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
745 argv = new char*[aOptList.size() + 1];
746 QStringList args = QApplication::arguments();
747 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
750 foreach (QString aStr, aOptList) {
751 argv[argc] = strdup( aStr.toLatin1().constData() );
754 MyCoreApp = new pqPVApplicationCore (argc, argv);
755 if (MyCoreApp->getOptions()->GetHelpSelected() ||
756 MyCoreApp->getOptions()->GetUnknownArgument() ||
757 MyCoreApp->getOptions()->GetErrorMessage() ||
758 MyCoreApp->getOptions()->GetTellVersion()) {
762 /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in
763 // Not sure why this is needed. Andy added this ages ago with comment saying
764 // needed for Mac apps. Need to check that it's indeed still required.
765 QDir dir(QApplication::applicationDirPath());
768 QApplication::addLibraryPath(dir.absolutePath());
769 // Load required application plugins.
770 QString plugin_string = "";
771 QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
772 pqBrandPluginsLoader loader;
773 if (loader.loadPlugins(plugin_list) == false) {
774 printf("Failed to load required plugins for this application\n");
778 // Load optional plugins.
780 plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
781 loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
783 // End of Initializer code
785 vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New());
787 new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET on creation
789 for (int i = 0; i < argc; i++)
798 \brief Shows (toShow = true) or hides ParaView view window
800 void PVGUI_Module::showView( bool toShow )
802 SalomeApp_Application* anApp = getApp();
803 PVGUI_ViewManager* viewMgr =
804 dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
806 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
807 anApp->addViewManager( viewMgr );
808 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
809 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
812 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
814 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
817 pvWnd->setShown( toShow );
818 if ( toShow ) pvWnd->setFocus();
822 \brief Slot to show help for proxy.
824 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
826 pqHelpReaction::showProxyHelp(groupname, proxyname);
831 \brief Slot to show the waiting state.
833 void PVGUI_Module::onPreAccept()
835 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
836 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
840 \brief Slot to show the ready state.
842 void PVGUI_Module::onPostAccept()
844 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
845 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
849 \brief Slot to switch off wait cursor.
851 void PVGUI_Module::endWaitCursor()
853 QApplication::restoreOverrideCursor();
857 \brief Returns the ParaView multi-view manager.
859 pqTabbedMultiViewWidget* PVGUI_Module::getMultiViewManager() const
861 return qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
865 static void ParavisMessageOutput(QtMsgType type, const char *msg)
870 vtkOutputWindow::GetInstance()->DisplayText(msg);
873 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
876 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
879 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
887 \brief Activate module.
888 \param study current study
889 \return \c true if activaion is done successfully or 0 to prevent
892 bool PVGUI_Module::activateModule( SUIT_Study* study )
894 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
896 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
898 storeCommonWindowsState();
900 bool isDone = SalomeApp_Module::activateModule( study );
901 if ( !isDone ) return false;
904 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
905 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
906 if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
907 if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
908 setMenuShown( true );
909 setToolShown( true );
911 restoreDockWidgetsState();
913 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
915 QList<QAction*> anActns = aMenu->actions();
916 for (int i = 0; i < anActns.size(); ++i) {
917 QAction* a = anActns.at(i);
923 QList<QMenu*>::iterator it;
924 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
925 QAction* a = (*it)->menuAction();
930 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
932 ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this));
939 \brief Deactivate module.
940 \param study current study
941 \return \c true if deactivaion is done successfully or 0 to prevent
942 deactivation on error
944 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
946 MESSAGE("PARAVIS deactivation ...")
948 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
950 QList<QAction*> anActns = aMenu->actions();
951 for (int i = 0; i < anActns.size(); ++i) {
952 QAction* a = anActns.at(i);
954 a->setVisible(false);
958 QList<QMenu*>::iterator it;
959 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
960 QAction* a = (*it)->menuAction();
962 a->setVisible(false);
965 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
966 foreach(QDockWidget* aView, aStreamingViews) {
967 if (!myDockWidgets.contains(aView))
968 myDockWidgets[aView] = aView->isVisible();
971 /*if (pqImplementation::helpWindow) {
972 pqImplementation::helpWindow->hide();
976 menuMgr()->hide(myRecentMenuId);
977 menuMgr()->hide(mySourcesMenuId);
978 menuMgr()->hide(myFiltersMenuId);
979 menuMgr()->hide(myMacrosMenuId);
980 menuMgr()->hide(myToolbarsMenuId);
981 setMenuShown( false );
982 setToolShown( false );
984 saveDockWidgetsState();
986 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
989 qInstallMsgHandler(myOldMsgHandler);
991 restoreCommonWindowsState();
993 return SalomeApp_Module::deactivateModule( study );
998 \brief Called when application is closed.
1000 Process finalize application functionality from ParaView in order to save server settings
1001 and nullify application pointer if the application is being closed.
1003 \param theApp application
1005 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
1007 pqApplicationCore::instance()->settings()->sync();
1008 int aAppsNb = SUIT_Session::session()->applications().size();
1010 deleteTemporaryFiles();
1011 MyCoreApp->deleteLater();
1013 CAM_Module::onApplicationClosed(theApp);
1018 \brief Deletes temporary files created during import operation from VISU
1020 void PVGUI_Module::deleteTemporaryFiles()
1022 foreach(QString aFile, myTemporaryFiles) {
1023 if (QFile::exists(aFile)) {
1024 QFile::remove(aFile);
1031 \brief Called when study is closed.
1033 Removes data model from the \a study.
1035 \param study study being closed
1037 void PVGUI_Module::studyClosed(SUIT_Study* study)
1039 clearParaviewState();
1041 SalomeApp_Module::studyClosed(study);
1045 \brief Called when study is opened.
1047 void PVGUI_Module::onModelOpened()
1049 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1054 _PTR(SComponent) paravisComp =
1055 studyDS->FindComponent(GetEngine()->ComponentDataType());
1060 _PTR(ChildIterator) anIter(studyDS->NewChildIterator(paravisComp));
1061 for (; anIter->More(); anIter->Next()) {
1062 _PTR(SObject) aSObj = anIter->Value();
1063 _PTR(GenericAttribute) anAttr;
1064 if (!aSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1067 _PTR(AttributeLocalID) anID(anAttr);
1068 if (anID->Value() == PVSTATEID) {
1075 \brief Returns IOR of current engine
1077 QString PVGUI_Module::engineIOR() const
1079 CORBA::String_var anIOR = GetEngine()->GetIOR();
1080 return QString(anIOR.in());
1085 \brief Open file of format supported by ParaView
1087 void PVGUI_Module::openFile(const char* theName)
1091 pqLoadDataReaction::loadData(aFiles);
1094 void PVGUI_Module::executeScript(const char *script)
1097 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
1098 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
1100 pqPythonDialog* pyDiag = manager->pythonShellDialog();
1102 pyDiag->runString(script);
1109 // * Debug function printing out the given interpreter's execution context
1111 //void printInterpContext(PyInterp_Interp * interp )
1113 // // Extract __smtraceString from interpreter's context
1114 // const PyObject* ctxt = interp->getExecutionContext();
1116 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
1117 // Py_ssize_t siz = PyList_GET_SIZE(lst);
1118 // for (Py_ssize_t i = 0; i < siz; i++)
1120 // PyObject * elem = PyList_GetItem(lst, i);
1121 // if (PyString_Check(elem))
1123 // std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
1126 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
1132 \brief Returns trace string
1134 static const QString MYReplaceStr("paraview.simple");
1135 static const QString MYReplaceImportStr("except: from pvsimple import *");
1136 QString PVGUI_Module::getTraceString()
1138 QString traceString;
1141 PyLockWrapper lck; // Acquire GIL
1143 const char * code = "from paraview import smtrace;"
1144 "__smtraceString = smtrace.get_trace_string()";
1145 PyRun_SimpleString(code);
1146 // Now get the value of __smtraceString
1147 PyObject* main_module = PyImport_AddModule((char*)"__main__");
1148 PyObject* global_dict = PyModule_GetDict(main_module);
1149 PyObject* string_object = PyDict_GetItemString(global_dict, "__smtraceString");
1150 char* string_ptr = string_object ? PyString_AsString(string_object) : 0;
1152 traceString = string_ptr;
1156 if ((!traceString.isNull()) && traceString.length() != 0) {
1157 int aPos = traceString.indexOf(MYReplaceStr);
1158 while (aPos != -1) {
1159 traceString = traceString.replace(aPos, MYReplaceStr.length(), "pvsimple");
1160 aPos = traceString.indexOf(MYReplaceStr, aPos);
1162 int aImportPos = traceString.indexOf(MYReplaceImportStr);
1163 if(aImportPos != -1)
1165 traceString = traceString.replace(aImportPos, MYReplaceImportStr.length(), "except:\n import pvsimple\n from pvsimple import *");
1173 \brief Saves trace string to disk file
1175 void PVGUI_Module::saveTrace(const char* theName)
1177 QFile file(theName);
1178 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1179 MESSAGE( "Could not open file:" << theName );
1182 QTextStream out(&file);
1183 out << getTraceString();
1188 \brief Saves ParaView state to a disk file
1190 void PVGUI_Module::saveParaviewState(const char* theFileName)
1192 pqApplicationCore::instance()->saveState(theFileName);
1196 \brief Delete all objects for Paraview Pipeline Browser
1198 void PVGUI_Module::clearParaviewState()
1200 QAction* deleteAllAction = action(DeleteAllId);
1201 if (deleteAllAction) {
1202 deleteAllAction->activate(QAction::Trigger);
1207 \brief Restores ParaView state from a disk file
1209 If toClear == true, the current ojects will be deleted
1211 void PVGUI_Module::loadParaviewState(const char* theFileName)
1213 pqApplicationCore::instance()->loadState(theFileName, getActiveServer());
1217 \brief Returns current active ParaView server
1219 pqServer* PVGUI_Module::getActiveServer()
1221 return pqApplicationCore::instance()->getActiveServer();
1226 \brief Creates PARAVIS preference pane
1228 void PVGUI_Module::createPreferences()
1230 // Paraview settings tab
1231 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
1232 int aPanel = addPreference(QString(), aParaViewSettingsTab, LightApp_Preferences::UserDefined, "PARAVIS", "");
1233 setPreferenceProperty(aPanel, "content", (qint64)(new PVGUI_ParaViewSettingsPane()));
1235 // Paravis settings tab
1236 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
1237 addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
1239 int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
1240 LightApp_Preferences::Selector,
1241 "PARAVIS", "savestate_type");
1242 QList<QVariant> aIndices;
1243 QStringList aStrings;
1245 aStrings<<tr("PREF_SAVE_TYPE_0");
1246 aStrings<<tr("PREF_SAVE_TYPE_1");
1247 aStrings<<tr("PREF_SAVE_TYPE_2");
1248 setPreferenceProperty(aSaveType, "strings", aStrings);
1249 setPreferenceProperty(aSaveType, "indexes", aIndices);
1251 //rnv: imp 21712: [CEA 581] Preference to display legend by default
1252 int aDispColoreLegend = addPreference( tr( "PREF_SHOW_COLOR_LEGEND" ), aParaVisSettingsTab,
1253 LightApp_Preferences::Bool, "PARAVIS", "show_color_legend");
1257 \brief Creates ParaViS context menu popup
1259 void PVGUI_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
1261 SalomeApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
1263 // Check if we are in Object Browser
1264 SUIT_DataBrowser* ob = getApp()->objectBrowser();
1265 bool isOBClient = (ob && theClient == ob->popupClientType());
1270 // Get list of selected objects
1271 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1272 SALOME_ListIO aListIO;
1273 aSelectionMgr->selectedObjects(aListIO);
1274 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1275 QString entry = QString(aListIO.First()->getEntry());
1278 SalomeApp_Study* activeStudy =
1279 dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
1284 // Get SALOMEDS client study
1285 _PTR(Study) studyDS = activeStudy->studyDS();
1290 QString paravisDataType(GetEngine()->ComponentDataType());
1291 if(activeStudy && activeStudy->isComponent(entry) &&
1292 activeStudy->componentDataType(entry) == paravisDataType) {
1293 // ParaViS module object
1294 theMenu->addSeparator();
1295 theMenu->addAction(action(SaveStatePopupId));
1298 // Try to get state object
1299 _PTR(SObject) stateSObj =
1300 studyDS->FindObjectID(entry.toLatin1().constData());
1306 _PTR(GenericAttribute) anAttr;
1307 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1311 _PTR(AttributeLocalID) anID(anAttr);
1313 if (anID->Value() == PVSTATEID) {
1314 // Paraview state object
1315 theMenu->addSeparator();
1316 theMenu->addAction(action(AddStatePopupId));
1317 theMenu->addAction(action(CleanAndAddStatePopupId));
1318 theMenu->addSeparator();
1319 theMenu->addAction(action(ParaVisRenameId));
1320 theMenu->addAction(action(ParaVisDeleteId));
1327 \brief. Show ParaView python trace.
1329 void PVGUI_Module::onShowTrace()
1331 if (!myTraceWindow) {
1332 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
1334 myTraceWindow->setText(getTraceString());
1335 myTraceWindow->show();
1336 myTraceWindow->raise();
1337 myTraceWindow->activateWindow();
1342 \brief. Re-initialize ParaView python trace.
1344 void PVGUI_Module::onRestartTrace()
1346 QString script = "from paraview import smtrace\n";
1347 script += "smtrace.stop_trace()\n";
1348 script += "smtrace.start_trace()\n";
1349 execPythonCommand(script, false);
1353 \brief Show ParaView view.
1355 void PVGUI_Module::onNewParaViewWindow()
1361 \brief Save state under the module root object.
1363 void PVGUI_Module::onSaveMultiState()
1365 // Create state study object
1367 // Get SALOMEDS client study
1368 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1373 _PTR(SComponent) paravisComp =
1374 studyDS->FindComponent(GetEngine()->ComponentDataType());
1379 // Unlock the study if it is locked
1380 bool isLocked = studyDS->GetProperties()->IsLocked();
1382 studyDS->GetProperties()->SetLocked(false);
1385 QString stateName = tr("SAVED_PARAVIEW_STATE_NAME") +
1386 QString::number(myStateCounter + 1);
1388 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1389 _PTR(SObject) newSObj = studyBuilder->NewObject(paravisComp);
1392 _PTR(GenericAttribute) anAttr;
1393 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeName");
1394 _PTR(AttributeName) nameAttr(anAttr);
1396 nameAttr->SetValue(stateName.toLatin1().constData());
1399 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeLocalID");
1400 _PTR(AttributeLocalID) localIdAttr(anAttr);
1402 localIdAttr->SetValue(PVSTATEID);
1405 QString stateEntry = QString::fromStdString(newSObj->GetID());
1407 // File name for state saving
1408 QString tmpDir = QString::fromStdString(SALOMEDS_Tool::GetTmpDir());
1409 QString fileName = QString("%1_paravisstate:%2").arg(tmpDir, stateEntry);
1411 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeString");
1412 _PTR(AttributeString) stringAttr(anAttr);
1414 stringAttr->SetValue(fileName.toLatin1().constData());
1416 // Lock the study back if necessary
1418 studyDS->GetProperties()->SetLocked(true);
1422 saveParaviewState(fileName.toLatin1().constData());
1423 myTemporaryFiles.append(fileName);
1425 // Increment the counter
1432 \brief Restore the selected state by merging with the current one.
1434 void PVGUI_Module::onAddState()
1436 loadSelectedState(false);
1440 \brief Clean the current state and restore the selected one.
1442 void PVGUI_Module::onCleanAddState()
1444 loadSelectedState(true);
1448 \brief Rename the selected object.
1450 void PVGUI_Module::onRename()
1452 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1453 SALOME_ListIO aListIO;
1454 aSelectionMgr->selectedObjects(aListIO);
1456 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1457 std::string entry = aListIO.First()->getEntry();
1459 // Get SALOMEDS client study
1460 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1465 // Unlock the study if it is locked
1466 bool isLocked = studyDS->GetProperties()->IsLocked();
1468 studyDS->GetProperties()->SetLocked(false);
1471 // Rename the selected state object
1472 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1477 _PTR(GenericAttribute) anAttr;
1478 if (stateSObj->FindAttribute(anAttr, "AttributeName")) {
1479 _PTR(AttributeName) nameAttr (anAttr);
1481 LightApp_NameDlg::getName(getApp()->desktop(), nameAttr->Value().c_str());
1482 if (!newName.isEmpty()) {
1483 nameAttr->SetValue(newName.toLatin1().constData());
1484 aListIO.First()->setName(newName.toLatin1().constData());
1488 // Lock the study back if necessary
1490 studyDS->GetProperties()->SetLocked(true);
1493 // Update object browser
1500 \brief Delete the selected objects.
1502 void PVGUI_Module::onDelete()
1504 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1505 SALOME_ListIO aListIO;
1506 aSelectionMgr->selectedObjects(aListIO);
1508 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1509 std::string entry = aListIO.First()->getEntry();
1511 // Get SALOMEDS client study
1512 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1517 // Unlock the study if it is locked
1518 bool isLocked = studyDS->GetProperties()->IsLocked();
1520 studyDS->GetProperties()->SetLocked(false);
1523 // Remove the selected state from the study
1524 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1525 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1526 studyBuilder->RemoveObject(stateSObj);
1528 // Lock the study back if necessary
1530 studyDS->GetProperties()->SetLocked(true);
1533 // Update object browser
1538 void PVGUI_Module::onPushTraceTimer()
1540 // MESSAGE("onPushTraceTimer(): Pushing trace to engine...");
1541 GetEngine()->PutPythonTraceStringToEngine(getTraceString().toStdString().c_str());
1545 \brief Discover help project files from the resources.
1546 \return name of the help file.
1548 QString PVGUI_Module::getHelpFileName() {
1549 QString aPVHome(getenv("PVHOME"));
1550 if (aPVHome.isNull()) {
1551 qWarning("Wariable PVHOME is not defined");
1554 QChar aSep = QDir::separator();
1555 //PARAVIEW_VERSION from the vtkPVConfig.h file
1556 QString aFileName = aPVHome + aSep + "share" + aSep + "doc" + aSep + "paraview-"+ PARAVIEW_VERSION + aSep + "paraview.qch";
1562 \brief Load selected paraview state
1564 If toClear == true, the current state will be cleared
1566 void PVGUI_Module::loadSelectedState(bool toClear)
1570 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1571 SALOME_ListIO aListIO;
1572 aSelectionMgr->selectedObjects(aListIO);
1574 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1575 std::string entry = aListIO.First()->getEntry();
1577 // Get SALOMEDS client study
1578 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1584 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1585 _PTR(GenericAttribute) anAttr;
1586 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1589 _PTR(AttributeLocalID) anID(anAttr);
1590 if (!anID->Value() == PVSTATEID) {
1594 // Get state file name
1595 if (stateSObj->FindAttribute(anAttr, "AttributeString")) {
1596 _PTR(AttributeString) aStringAttr(anAttr);
1597 QString stringValue(aStringAttr->Value().c_str());
1599 if (QFile::exists(stringValue)) {
1600 fileName = stringValue;
1605 if (!fileName.isEmpty()) {
1607 clearParaviewState();
1610 loadParaviewState(fileName.toLatin1().constData());
1613 SUIT_MessageBox::critical(getApp()->desktop(),
1615 tr("ERR_STATE_CANNOT_BE_RESTORED"));
1619 void PVGUI_Module::onRepresentationChanged(pqRepresentation*) {
1622 //rnv: to fix the issue "21712: [CEA 581] Preference to display legend by default"
1623 // find the pqDisplayColorWidget instances and connect the variableChanged SIGNAL on the
1624 // onVariableChanged slot of this class. This connection needs to change visibility
1625 // of the "Colored Legend" after change the "Color By" array.
1626 QList<pqDisplayColorWidget*> aWidget = getApp()->desktop()->findChildren<pqDisplayColorWidget*>();
1628 for (int i = 0; i < aWidget.size() ; i++ ) {
1630 connect( aWidget[i], SIGNAL ( variableChanged ( pqVariableType, const QString ) ),
1631 this, SLOT(onVariableChanged( pqVariableType, const QString) ), Qt::UniqueConnection );
1638 \fn CAM_Module* createModule();
1639 \brief Export module instance (factory function).
1640 \return new created instance of the module
1644 #define PVGUI_EXPORT __declspec(dllexport)
1646 #define PVGUI_EXPORT
1652 PVGUI_EXPORT CAM_Module* createModule() {
1657 return new PVGUI_Module();
1660 PVGUI_EXPORT char* getModuleVersion() {
1661 return (char*)PARAVIS_VERSION_STR;