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 #include "SALOMEconfig.h"
33 #include CORBA_CLIENT_HEADER(VISU_Gen)
35 #include CORBA_SERVER_HEADER(SALOMEDS)
38 #include "PARAVIS_Gen_i.hh"
42 #include "PVGUI_ViewModel.h"
43 #include "PVGUI_ViewManager.h"
44 #include "PVGUI_ViewWindow.h"
45 #include "PVGUI_Tools.h"
46 #include "PVGUI_ParaViewSettingsPane.h"
47 #include "PVGUI_OutputWindowAdapter.h"
49 #include <SUIT_DataBrowser.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <SUIT_ExceptionHandler.h>
58 #include "SALOME_LifeCycleCORBA.hxx"
59 #include "SALOMEDS_SObject.hxx"
61 #include "LightApp_SelectionMgr.h"
62 #include "LightApp_NameDlg.h"
64 #include <SalomeApp_Application.h>
65 #include <SalomeApp_Study.h>
66 #include <SALOME_ListIO.hxx>
67 #include <SALOMEDS_Tool.hxx>
68 #include <PyInterp_Interp.h>
69 #include <PyInterp_Dispatcher.h>
70 #include <PyConsole_Console.h>
72 #include <QtxActionMenuMgr.h>
73 #include <QtxActionToolMgr.h>
76 #include <QApplication>
82 #include <QInputDialog>
86 #include <QStringList>
89 #include <QTextStream>
91 #include <QDockWidget>
92 #include <QHelpEngine>
94 #include <pqApplicationCore.h>
95 #include <pqPVApplicationCore.h>
96 #include <pqActiveView.h>
97 #include <pqObjectBuilder.h>
98 #include <pqOptions.h>
99 #include <pqRenderView.h>
100 #include <pqServer.h>
101 #include <pqUndoStack.h>
102 #include <pqVCRController.h>
103 #include <pqTabbedMultiViewWidget.h>
104 #include <pqPipelineSource.h>
105 #include <pqActiveObjects.h>
106 #include <vtkProcessModule.h>
107 #include <vtkSMSession.h>
108 #include <vtkPVSession.h>
109 #include <vtkPVProgressHandler.h>
110 #include <pqParaViewBehaviors.h>
111 #include <pqHelpReaction.h>
112 #include <vtkOutputWindow.h>
113 #include <pqPluginManager.h>
114 #include "pqInterfaceTracker.h"
115 #include <pqSettings.h>
116 #include <pqPythonDialog.h>
117 #include <pqPythonManager.h>
118 #include <pqPythonShell.h>
119 #include <pqLoadDataReaction.h>
120 #include <vtkEventQtSlotConnect.h>
121 #include <pqPythonScriptEditor.h>
122 #include <pqCollaborationBehavior.h>
123 #include <pqDataRepresentation.h>
124 #include <pqPipelineRepresentation.h>
125 #include <pqLookupTableManager.h>
126 #include <pqDisplayColorWidget.h>
127 #include <pqColorToolbar.h>
128 #include <pqScalarBarVisibilityReaction.h>
129 #include <pqStandardPropertyWidgetInterface.h>
130 #include <pqViewStreamingBehavior.h>
131 #include <pqServerResource.h>
132 #include <pqServerConnectReaction.h>
134 #include <PARAVIS_version.h>
136 #include <vtkPVConfig.h>
139 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
141 #include <pqAlwaysConnectedBehavior.h>
142 #include <pqApplicationCore.h>
143 #include <pqAutoLoadPluginXMLBehavior.h>
144 #include <pqCommandLineOptionsBehavior.h>
145 #include <pqCrashRecoveryBehavior.h>
146 #include <pqDataTimeStepBehavior.h>
147 #include <pqDefaultViewBehavior.h>
148 #include <pqDeleteBehavior.h>
149 #include <pqObjectPickingBehavior.h>
150 #include <pqPersistentMainWindowStateBehavior.h>
151 #include <pqPipelineContextMenuBehavior.h>
152 #include <pqPluginActionGroupBehavior.h>
153 #include <pqPluginDockWidgetsBehavior.h>
154 #include <pqPluginManager.h>
155 #include <pqPVNewSourceBehavior.h>
156 #include <pqSpreadSheetVisibilityBehavior.h>
157 #include <pqStandardViewModules.h>
158 #include <pqUndoRedoBehavior.h>
159 #include <pqViewFrameActionsBehavior.h>
160 #include <pqServerManagerObserver.h>
162 #include <vtkClientServerInterpreterInitializer.h>
165 //----------------------------------------------------------------------------
166 pqPVApplicationCore* PVGUI_Module::MyCoreApp = 0;
167 //PVGUI_OutputWindowAdapter* PVGUI_Module::pqImplementation::OutputWindowAdapter = 0;
168 //QPointer<pqHelpWindow> PVGUI_Module::pqImplementation::helpWindow = 0;
170 PVGUI_Module* ParavisModule = 0;
175 <h2>Building and installing PARAVIS</h2>
176 As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
177 installation directory.
178 Other variables needed for correct detection of ParaView location:
179 \li PVHOME - points at the ParaView installation directory tree
180 \li PVVERSION - number of ParaView version
182 It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
185 PARAVIS module can be launched using the following commands:
186 \li Full SALOME configuration
188 runSalome --modules="PARAVIS"
191 <h2>ParaView GUI integration</h2>
192 <h3>ParaView GUI integration overview</h3>
194 The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
195 between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
197 \li SALOME GUI executable and Qt event loop
198 \li SALOME GUI desktop
199 \li Dock windows areas
200 \li SALOME menu and toolbar managers
202 Major part of the integration is implemented in PVGUI_Module class.
204 <h3>ParaView client initalization</h3>
206 ParaView client initalization is performed when an instance of PVGUI_Module class has been created
207 and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
208 The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
211 <h3>Multi-view manager</h3>
213 SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
216 \li PVGUI_ViewManager - view manager class
217 \li PVGUI_Viewer - view model class
218 \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
220 Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
221 PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
222 when the module is deactivated (the user switches to another module or a study is closed).
223 A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
224 with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
225 \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
226 of %pqViewManager widget that would break %pqMainWindowCore class.
228 <h3>ParaView plugins</h3>
229 ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
230 As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
235 \brief Implementation
236 SALOME module wrapping ParaView GUI.
241 Fix for the issue 21730: [CEA 596] Slice of polyhedron in PARAVIS returns no cell.
242 Wrap vtkEDFCutter filter.
245 extern "C" void vtkEDFCutterCS_Initialize(vtkClientServerInterpreter*);
246 static void vtkEDFHelperInit();
248 void vtkEDFHelperInit(vtkClientServerInterpreter* interp){
249 vtkEDFCutterCS_Initialize(interp);
252 void vtkEDFHelperInit() {
253 vtkClientServerInterpreterInitializer::GetInitializer()->
254 RegisterCallback(&vtkEDFHelperInit);
259 ClientFindOrCreateParavisComponent(_PTR(Study) theStudyDocument)
261 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("PARAVIS");
263 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
264 aStudyBuilder->NewCommand();
265 int aLocked = theStudyDocument->GetProperties()->IsLocked();
266 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
267 aSComponent = aStudyBuilder->NewComponent("PARAVIS");
268 _PTR(GenericAttribute) anAttr =
269 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
270 _PTR(AttributeName) aName (anAttr);
272 CORBA::ORB_var anORB = PARAVIS::PARAVIS_Gen_i::GetORB();
273 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
274 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
275 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
276 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
277 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
278 if (!Comp->_is_nil()) {
279 aName->SetValue(Comp->componentusername());
282 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
283 _PTR(AttributePixMap) aPixmap (anAttr);
284 aPixmap->SetPixMap( "pqAppIcon16.png" );
286 // Create Attribute parameters for future using
287 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
290 PARAVIS::PARAVIS_Gen_var aPARAVIS = PARAVIS::PARAVIS_Gen_i::GetParavisGenImpl()->_this();
292 aStudyBuilder->DefineComponentInstance(aSComponent, aPARAVIS->GetIOR());
293 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
294 aStudyBuilder->CommitCommand();
300 Clean up function; used to stop ParaView progress events when
301 exception is caught by global exception handler.
303 void paravisCleanUp()
305 if ( pqApplicationCore::instance() ) {
306 pqServer* s = pqApplicationCore::instance()->getActiveServer();
307 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
312 \brief Constructor. Sets the default name for the module.
314 PVGUI_Module::PVGUI_Module()
315 : SalomeApp_Module( "PARAVIS" ),
316 // Implementation( 0 ),
317 mySelectionControlsTb( -1 ),
318 mySourcesMenuId( -1 ),
319 myFiltersMenuId( -1 ),
321 myToolbarsMenuId(-1),
328 Q_INIT_RESOURCE( PVGUI );
330 ParavisModule = this;
332 // Clear old copies of embedded macros files
333 QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
337 QDir aDestDir(aDestPath);
338 QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
339 foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
340 QString aMacrosName = QFileInfo(aMacrosPath).fileName();
341 if (aDestFiles.contains(aMacrosName)) {
342 aDestDir.remove(aMacrosName);
350 PVGUI_Module::~PVGUI_Module()
355 \brief Initialize module. Creates menus, prepares context menu, etc.
356 \param app SALOME GUI application instance
358 void PVGUI_Module::initialize( CAM_Application* app )
360 // [ABN]: patched in ParaView's sources.
361 // PVGUI_MatplotlibMathTextUtilities::Disable();
363 SalomeApp_Module::initialize( app );
365 // Create ParaViS actions
367 // Create ParaViS menus
370 // Uncomment to debug ParaView initialization
371 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
379 // Initialize ParaView client
382 // Create GUI elements (menus, toolbars, dock widgets)
383 //if ( !Implementation ){
384 SalomeApp_Application* anApp = getApp();
385 SUIT_Desktop* aDesktop = anApp->desktop();
387 // connect(aDesktop, SIGNAL()
389 // Remember current state of desktop toolbars
390 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
392 // Simulate ParaView client main window
393 //Implementation = new pqImplementation( aDesktop );
401 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
402 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
404 // new pqParaViewBehaviors(anApp->desktop(), this);
405 // Has to be replaced in order to exclude using of pqQtMessageHandlerBehaviour
406 // Start pqParaViewBehaviors
407 // Register ParaView interfaces.
408 //pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
409 pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
411 // * adds support for standard paraview views.
412 pgm->addInterface(new pqStandardViewModules(pgm));
413 //pgm->addInterface(new pqStandardSummaryPanelImplementation(pgm));
414 pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm));
416 // Load plugins distributed with application.
417 pqApplicationCore::instance()->loadDistributedPlugins();
419 // Define application behaviors.
420 //new pqQtMessageHandlerBehavior(this);
421 new pqDataTimeStepBehavior(this);
422 new pqViewFrameActionsBehavior(this);
423 new pqSpreadSheetVisibilityBehavior(this);
424 new pqPipelineContextMenuBehavior(this);
425 new pqObjectPickingBehavior(this); // NEW in 4.1
426 new pqDefaultViewBehavior(this);
427 new pqAlwaysConnectedBehavior(this);
428 new pqPVNewSourceBehavior(this);
429 new pqDeleteBehavior(this);
430 new pqUndoRedoBehavior(this);
431 new pqCrashRecoveryBehavior(this);
432 new pqAutoLoadPluginXMLBehavior(this);
433 new pqPluginDockWidgetsBehavior(aDesktop);
434 //new pqVerifyRequiredPluginBehavior(this);
435 new pqPluginActionGroupBehavior(aDesktop);
436 //new pqFixPathsInStateFilesBehavior(this);
437 new pqCommandLineOptionsBehavior(this);
438 new pqPersistentMainWindowStateBehavior(aDesktop);
439 new pqObjectPickingBehavior(aDesktop);
440 new pqCollaborationBehavior(this);
441 //new pqMultiServerBehavior(this);
442 new pqViewStreamingBehavior(this);
444 // Setup quick-launch shortcuts.
445 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
446 QObject::connect(ctrlSpace, SIGNAL(activated()),
447 pqApplicationCore::instance(), SLOT(quickLaunch()));
449 // Find Plugin Dock Widgets
450 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
451 QList<QDockWidget*>::iterator i;
452 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
453 if(!activeDocks.contains(*i)) {
454 myDockWidgets[*i] = false; // hidden by default
460 QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
461 QList<QMenu*>::iterator im;
462 for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
463 if(!activeMenus.contains(*im)) {
468 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
469 QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
470 if (!aPath.isNull()) {
471 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
472 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
473 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
474 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
477 // Force creation of engine
478 PARAVIS::GetParavisGen(this);
481 // Find created toolbars
482 QCoreApplication::processEvents();
484 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
485 foreach(QToolBar* aBar, allToolbars) {
486 if (!foreignToolbars.contains(aBar)) {
487 myToolbars[aBar] = true;
488 myToolbarBreaks[aBar] = false;
489 aBar->setVisible(false);
490 aBar->toggleViewAction()->setVisible(false);
497 // we need to start trace after connection is done
498 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(finishedAddingServer(pqServer*)),
499 this, SLOT(onFinishedAddingServer(pqServer*)));
501 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(dataRepresentationCreated(pqDataRepresentation*)),
502 this, SLOT(onDataRepresentationCreated(pqDataRepresentation*)));
505 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
506 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
507 // start a timer to schedule the trace start asap:
511 this->VTKConnect = vtkEventQtSlotConnect::New();
513 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
515 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
517 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
519 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
520 this, SLOT(onStartProgress()));
521 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
522 this, SLOT(onEndProgress()));
527 connect(&pqActiveObjects::instance(),
528 SIGNAL(representationChanged(pqRepresentation*)),
529 this, SLOT(onRepresentationChanged(pqRepresentation*)));
531 // Try to connect to the external PVServer
532 QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL");
533 const char * serverUrl = "cs://localhost";
534 if (!serverUrlEnv.isEmpty())
535 serverUrl = serverUrlEnv.toStdString().c_str();
536 std::cout << "** Trying to connect to the external PVServer '" << serverUrl << "' ..." << std::endl;
538 if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl)))
540 std::cerr << "** Could not connect to the requested server \""
541 << serverUrl << "\". Creating default builtin connection.\n" << std::endl;
544 std::cout << "** Connected!" << std::endl;
548 void PVGUI_Module::onStartProgress()
550 QApplication::setOverrideCursor(Qt::WaitCursor);
553 void PVGUI_Module::onEndProgress()
555 QApplication::restoreOverrideCursor();
558 void PVGUI_Module::onFinishedAddingServer(pqServer* /*server*/)
560 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
561 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
566 void PVGUI_Module::onDataRepresentationCreated(pqDataRepresentation* data) {
570 if(!data->getLookupTable())
573 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
577 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
578 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
581 lut_mgr->setScalarBarVisibility(data,visible);
584 connect(data, SIGNAL(dataUpdated()), this, SLOT(onDataRepresentationUpdated()));
587 void PVGUI_Module::onDataRepresentationUpdated() {
588 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
589 if(!activeStudy) return;
591 activeStudy->Modified();
594 void PVGUI_Module::onVariableChanged(pqVariableType t, const QString) {
596 pqDisplayColorWidget* colorWidget = qobject_cast<pqDisplayColorWidget*>(sender());
600 if( t == VARIABLE_TYPE_NONE )
603 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
608 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
613 /*//VTN: getRepresentation is protected
614 pqDataRepresentation* data = colorWidget->getRepresentation();
616 if( !data->getLookupTable() )
619 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
622 lut_mgr->setScalarBarVisibility(data,visible);
625 pqColorToolbar* colorTooBar = qobject_cast<pqColorToolbar*>(colorWidget->parent());
629 pqScalarBarVisibilityReaction* scalarBarVisibility = colorTooBar->findChild<pqScalarBarVisibilityReaction *>();
630 if(scalarBarVisibility) {
631 scalarBarVisibility->setScalarBarVisibility(visible);
635 void PVGUI_Module::execPythonCommand(const QString& cmd, bool inSalomeConsole)
637 if ( inSalomeConsole ) {
638 if ( PyInterp_Dispatcher::Get()->IsBusy() ) return;
639 SalomeApp_Application* app =
640 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
641 PyConsole_Console* pyConsole = app->pythonConsole();
643 pyConsole->exec(cmd);
647 pqPythonManager* manager = qobject_cast<pqPythonManager*>
648 ( pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
651 pqPythonDialog* pyDiag = manager->pythonShellDialog();
654 pqPythonShell* shell = pyDiag->shell();
656 shell->executeScript(cmd);
664 \brief Launches a tracing of current server
666 void PVGUI_Module::timerEvent(QTimerEvent* te )
669 if ( PyInterp_Dispatcher::Get()->IsBusy() )
671 // Reschedule for later
672 MESSAGE("interpreter busy -> rescheduling trace start.");
677 MESSAGE("about to start trace....");
678 execPythonCommand("from paraview import smtrace;smtrace.start_trace()", false);
679 MESSAGE("trace STARTED....");
681 killTimer( te->timerId() );
686 \brief Get list of embedded macros files
688 QStringList PVGUI_Module::getEmbeddedMacrosList()
690 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
692 QString aSourcePath = aRootDir + "/bin/salome/Macro";
697 QDir aSourceDir(aSourcePath);
698 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
699 QStringList aFullPathSourceFiles;
700 foreach (QString aMacrosName, aSourceFiles) {
701 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
703 return aFullPathSourceFiles;
706 void PVGUI_Module::updateMacros()
708 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
709 if(!aPythonManager) {
713 foreach (QString aStr, getEmbeddedMacrosList()) {
714 aPythonManager->addMacro(aStr);
720 \brief Get list of compliant dockable GUI elements
721 \param m map to be filled in ("type":"default_position")
723 void PVGUI_Module::windows( QMap<int, int>& m ) const
725 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
726 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
727 // ParaView diagnostic output redirected here
728 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
732 \brief Static method, performs initialization of ParaView session.
733 \return \c true if ParaView has been initialized successfully, otherwise false
735 bool PVGUI_Module::pvInit()
737 // if ( !pqImplementation::Core ){
739 // Obtain command-line arguments
742 QString aOptions = getenv("PARAVIS_OPTIONS");
743 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
744 argv = new char*[aOptList.size() + 1];
745 QStringList args = QApplication::arguments();
746 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
749 foreach (QString aStr, aOptList) {
750 argv[argc] = strdup( aStr.toLatin1().constData() );
753 MyCoreApp = new pqPVApplicationCore (argc, argv);
754 if (MyCoreApp->getOptions()->GetHelpSelected() ||
755 MyCoreApp->getOptions()->GetUnknownArgument() ||
756 MyCoreApp->getOptions()->GetErrorMessage() ||
757 MyCoreApp->getOptions()->GetTellVersion()) {
761 /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in
762 // Not sure why this is needed. Andy added this ages ago with comment saying
763 // needed for Mac apps. Need to check that it's indeed still required.
764 QDir dir(QApplication::applicationDirPath());
767 QApplication::addLibraryPath(dir.absolutePath());
768 // Load required application plugins.
769 QString plugin_string = "";
770 QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
771 pqBrandPluginsLoader loader;
772 if (loader.loadPlugins(plugin_list) == false) {
773 printf("Failed to load required plugins for this application\n");
777 // Load optional plugins.
779 plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
780 loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
782 // End of Initializer code
784 vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New());
786 new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET on creation
788 for (int i = 0; i < argc; i++)
797 \brief Shows (toShow = true) or hides ParaView view window
799 void PVGUI_Module::showView( bool toShow )
801 SalomeApp_Application* anApp = getApp();
802 PVGUI_ViewManager* viewMgr =
803 dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
805 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
806 anApp->addViewManager( viewMgr );
807 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
808 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
811 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
813 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
816 pvWnd->setShown( toShow );
817 if ( toShow ) pvWnd->setFocus();
821 \brief Slot to show help for proxy.
823 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
825 pqHelpReaction::showProxyHelp(groupname, proxyname);
830 \brief Slot to show the waiting state.
832 void PVGUI_Module::onPreAccept()
834 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
835 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
839 \brief Slot to show the ready state.
841 void PVGUI_Module::onPostAccept()
843 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
844 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
848 \brief Slot to switch off wait cursor.
850 void PVGUI_Module::endWaitCursor()
852 QApplication::restoreOverrideCursor();
856 \brief Returns the ParaView multi-view manager.
858 pqTabbedMultiViewWidget* PVGUI_Module::getMultiViewManager() const
860 return qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
864 static void ParavisMessageOutput(QtMsgType type, const char *msg)
869 vtkOutputWindow::GetInstance()->DisplayText(msg);
872 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
875 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
878 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
886 \brief Activate module.
887 \param study current study
888 \return \c true if activaion is done successfully or 0 to prevent
891 bool PVGUI_Module::activateModule( SUIT_Study* study )
893 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
895 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
897 storeCommonWindowsState();
899 bool isDone = SalomeApp_Module::activateModule( study );
900 if ( !isDone ) return false;
903 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
904 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
905 if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
906 if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
907 setMenuShown( true );
908 setToolShown( true );
910 restoreDockWidgetsState();
912 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
914 QList<QAction*> anActns = aMenu->actions();
915 for (int i = 0; i < anActns.size(); ++i) {
916 QAction* a = anActns.at(i);
922 QList<QMenu*>::iterator it;
923 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
924 QAction* a = (*it)->menuAction();
929 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
931 ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this));
938 \brief Deactivate module.
939 \param study current study
940 \return \c true if deactivaion is done successfully or 0 to prevent
941 deactivation on error
943 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
945 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
947 QList<QAction*> anActns = aMenu->actions();
948 for (int i = 0; i < anActns.size(); ++i) {
949 QAction* a = anActns.at(i);
951 a->setVisible(false);
955 QList<QMenu*>::iterator it;
956 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
957 QAction* a = (*it)->menuAction();
959 a->setVisible(false);
962 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
963 foreach(QDockWidget* aView, aStreamingViews) {
964 if (!myDockWidgets.contains(aView))
965 myDockWidgets[aView] = aView->isVisible();
968 /*if (pqImplementation::helpWindow) {
969 pqImplementation::helpWindow->hide();
973 menuMgr()->hide(myRecentMenuId);
974 menuMgr()->hide(mySourcesMenuId);
975 menuMgr()->hide(myFiltersMenuId);
976 menuMgr()->hide(myMacrosMenuId);
977 menuMgr()->hide(myToolbarsMenuId);
978 setMenuShown( false );
979 setToolShown( false );
982 saveDockWidgetsState();
984 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
987 qInstallMsgHandler(myOldMsgHandler);
989 restoreCommonWindowsState();
991 return SalomeApp_Module::deactivateModule( study );
996 \brief Called when application is closed.
998 Process finalize application functionality from ParaView in order to save server settings
999 and nullify application pointer if the application is being closed.
1001 \param theApp application
1003 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
1005 pqApplicationCore::instance()->settings()->sync();
1006 int aAppsNb = SUIT_Session::session()->applications().size();
1008 deleteTemporaryFiles();
1009 MyCoreApp->deleteLater();
1011 CAM_Module::onApplicationClosed(theApp);
1016 \brief Called when study is closed.
1018 Removes data model from the \a study.
1020 \param study study being closed
1022 void PVGUI_Module::studyClosed(SUIT_Study* study)
1024 clearParaviewState();
1026 SalomeApp_Module::studyClosed(study);
1030 \brief Called when study is opened.
1032 void PVGUI_Module::onModelOpened()
1034 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1039 _PTR(SComponent) paravisComp =
1040 studyDS->FindComponent(PARAVIS::GetParavisGen(this)->ComponentDataType());
1045 _PTR(ChildIterator) anIter(studyDS->NewChildIterator(paravisComp));
1046 for (; anIter->More(); anIter->Next()) {
1047 _PTR(SObject) aSObj = anIter->Value();
1048 _PTR(GenericAttribute) anAttr;
1049 if (!aSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1052 _PTR(AttributeLocalID) anID(anAttr);
1053 if (anID->Value() == PVSTATEID) {
1060 \brief Returns IOR of current engine
1062 QString PVGUI_Module::engineIOR() const
1064 CORBA::String_var anIOR = PARAVIS::GetParavisGen(this)->GetIOR();
1065 return QString(anIOR.in());
1070 \brief Open file of format supported by ParaView
1072 void PVGUI_Module::openFile(const char* theName)
1076 pqLoadDataReaction::loadData(aFiles);
1079 void PVGUI_Module::executeScript(const char *script)
1082 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
1083 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
1085 pqPythonDialog* pyDiag = manager->pythonShellDialog();
1087 pyDiag->runString(script);
1094 // * Debug function printing out the given interpreter's execution context
1096 //void printInterpContext(PyInterp_Interp * interp )
1098 // // Extract __smtraceString from interpreter's context
1099 // const PyObject* ctxt = interp->getExecutionContext();
1101 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
1102 // Py_ssize_t siz = PyList_GET_SIZE(lst);
1103 // for (Py_ssize_t i = 0; i < siz; i++)
1105 // PyObject * elem = PyList_GetItem(lst, i);
1106 // if (PyString_Check(elem))
1108 // std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
1111 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
1117 \brief Returns trace string
1119 static const QString MYReplaceStr("paraview.simple");
1120 static const QString MYReplaceImportStr("except: from pvsimple import *");
1121 QString PVGUI_Module::getTraceString()
1123 QString traceString;
1126 PyLockWrapper lck; // Acquire GIL
1128 const char * code = "from paraview import smtrace;"
1129 "__smtraceString = smtrace.get_trace_string()";
1130 PyRun_SimpleString(code);
1131 // Now get the value of __smtraceString
1132 PyObject* main_module = PyImport_AddModule((char*)"__main__");
1133 PyObject* global_dict = PyModule_GetDict(main_module);
1134 PyObject* string_object = PyDict_GetItemString(global_dict, "__smtraceString");
1135 char* string_ptr = string_object ? PyString_AsString(string_object) : 0;
1137 traceString = string_ptr;
1141 if ((!traceString.isNull()) && traceString.length() != 0) {
1142 int aPos = traceString.indexOf(MYReplaceStr);
1143 while (aPos != -1) {
1144 traceString = traceString.replace(aPos, MYReplaceStr.length(), "pvsimple");
1145 aPos = traceString.indexOf(MYReplaceStr, aPos);
1147 int aImportPos = traceString.indexOf(MYReplaceImportStr);
1148 if(aImportPos != -1)
1150 traceString = traceString.replace(aImportPos, MYReplaceImportStr.length(), "except:\n import pvsimple\n from pvsimple import *");
1158 \brief Saves trace string to disk file
1160 void PVGUI_Module::saveTrace(const char* theName)
1162 QFile file(theName);
1163 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1164 MESSAGE( "Could not open file:" << theName );
1167 QTextStream out(&file);
1168 out << getTraceString();
1173 \brief Saves ParaView state to a disk file
1175 void PVGUI_Module::saveParaviewState(const char* theFileName)
1177 pqApplicationCore::instance()->saveState(theFileName);
1181 \brief Delete all objects for Paraview Pipeline Browser
1183 void PVGUI_Module::clearParaviewState()
1185 QAction* deleteAllAction = action(DeleteAllId);
1186 if (deleteAllAction) {
1187 deleteAllAction->activate(QAction::Trigger);
1192 \brief Restores ParaView state from a disk file
1194 If toClear == true, the current ojects will be deleted
1196 void PVGUI_Module::loadParaviewState(const char* theFileName)
1198 pqApplicationCore::instance()->loadState(theFileName, getActiveServer());
1202 \brief Imports MED data from VISU module by data entry
1204 void PVGUI_Module::onImportFromVisu(QString theEntry)
1207 SUIT_OverrideCursor aWaitCursor;
1210 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1211 if(!activeStudy) return;
1213 // get SALOMEDS client study
1214 _PTR(Study) aStudy = activeStudy->studyDS();
1217 // find VISU component in a study
1218 _PTR(SComponent) aVisuComp = aStudy->FindComponent( "VISU" );
1219 if(!aVisuComp) return;
1221 // get SObject client by entry
1222 _PTR(SObject) aSObj = aStudy->FindObjectID(qPrintable(theEntry));
1225 // get CORBA SObject
1226 SALOMEDS_SObject* aSObject = _CAST(SObject, aSObj);
1227 if ( !aSObject ) return;
1230 SALOME_NamingService* aNamingService = SalomeApp_Application::namingService();
1231 SALOME_LifeCycleCORBA aLCC(aNamingService);
1233 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
1234 VISU::VISU_Gen_var aVISU = VISU::VISU_Gen::_narrow(aComponent);
1235 if(CORBA::is_nil(aVISU)) return;
1237 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1238 aStudyBuilder->LoadWith( aVisuComp, SalomeApp_Application::orb()->object_to_string(aVISU) );
1240 // get VISU result object
1241 CORBA::Object_var aResultObject = aSObject->GetObject();
1242 if (CORBA::is_nil(aResultObject)) return;
1243 VISU::Result_var aResult = VISU::Result::_narrow( aResultObject );
1244 if (CORBA::is_nil(aResult)) return;
1246 // export VISU result to the MED file
1247 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1248 std::string aFileName = aSObject->GetName();
1249 std::string aFilePath = aTmpDir + aFileName;
1251 if (aResult->ExportMED(aFilePath.c_str())) {
1252 openFile(aFilePath.c_str());
1253 myTemporaryFiles.append(QString(aFilePath.c_str()));
1256 MESSAGE("Visu module is not found.");
1261 \brief Deletes temporary files created during import operation from VISU
1263 void PVGUI_Module::deleteTemporaryFiles()
1265 foreach(QString aFile, myTemporaryFiles) {
1266 if (QFile::exists(aFile)) {
1267 QFile::remove(aFile);
1274 \brief Returns current active ParaView server
1276 pqServer* PVGUI_Module::getActiveServer()
1278 return pqApplicationCore::instance()->getActiveServer();
1283 \brief Creates PARAVIS preference pane
1285 void PVGUI_Module::createPreferences()
1287 // Paraview settings tab
1288 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
1289 int aPanel = addPreference(QString(), aParaViewSettingsTab, LightApp_Preferences::UserDefined, "PARAVIS", "");
1290 setPreferenceProperty(aPanel, "content", (qint64)(new PVGUI_ParaViewSettingsPane()));
1292 // Paravis settings tab
1293 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
1294 addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
1296 int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
1297 LightApp_Preferences::Selector,
1298 "PARAVIS", "savestate_type");
1299 QList<QVariant> aIndices;
1300 QStringList aStrings;
1302 aStrings<<tr("PREF_SAVE_TYPE_0");
1303 aStrings<<tr("PREF_SAVE_TYPE_1");
1304 aStrings<<tr("PREF_SAVE_TYPE_2");
1305 setPreferenceProperty(aSaveType, "strings", aStrings);
1306 setPreferenceProperty(aSaveType, "indexes", aIndices);
1308 //rnv: imp 21712: [CEA 581] Preference to display legend by default
1309 int aDispColoreLegend = addPreference( tr( "PREF_SHOW_COLOR_LEGEND" ), aParaVisSettingsTab,
1310 LightApp_Preferences::Bool, "PARAVIS", "show_color_legend");
1314 \brief Creates ParaViS context menu popup
1316 void PVGUI_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
1318 SalomeApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
1320 // Check if we are in Object Browser
1321 SUIT_DataBrowser* ob = getApp()->objectBrowser();
1322 bool isOBClient = (ob && theClient == ob->popupClientType());
1327 // Get list of selected objects
1328 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1329 SALOME_ListIO aListIO;
1330 aSelectionMgr->selectedObjects(aListIO);
1331 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1332 QString entry = QString(aListIO.First()->getEntry());
1335 SalomeApp_Study* activeStudy =
1336 dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
1341 // Get SALOMEDS client study
1342 _PTR(Study) studyDS = activeStudy->studyDS();
1347 QString paravisDataType(PARAVIS::GetParavisGen(this)->ComponentDataType());
1348 if(activeStudy && activeStudy->isComponent(entry) &&
1349 activeStudy->componentDataType(entry) == paravisDataType) {
1350 // ParaViS module object
1351 theMenu->addSeparator();
1352 theMenu->addAction(action(SaveStatePopupId));
1355 // Try to get state object
1356 _PTR(SObject) stateSObj =
1357 studyDS->FindObjectID(entry.toLatin1().constData());
1363 _PTR(GenericAttribute) anAttr;
1364 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1368 _PTR(AttributeLocalID) anID(anAttr);
1370 if (anID->Value() == PVSTATEID) {
1371 // Paraview state object
1372 theMenu->addSeparator();
1373 theMenu->addAction(action(AddStatePopupId));
1374 theMenu->addAction(action(CleanAndAddStatePopupId));
1375 theMenu->addSeparator();
1376 theMenu->addAction(action(ParaVisRenameId));
1377 theMenu->addAction(action(ParaVisDeleteId));
1384 \brief. Show ParaView python trace.
1386 void PVGUI_Module::onShowTrace()
1388 if (!myTraceWindow) {
1389 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
1391 myTraceWindow->setText(getTraceString());
1392 myTraceWindow->show();
1393 myTraceWindow->raise();
1394 myTraceWindow->activateWindow();
1399 \brief. Re-initialize ParaView python trace.
1401 void PVGUI_Module::onRestartTrace()
1403 QString script = "from paraview import smtrace\n";
1404 script += "smtrace.stop_trace()\n";
1405 script += "smtrace.start_trace()\n";
1406 execPythonCommand(script, false);
1410 \brief Show ParaView view.
1412 void PVGUI_Module::onNewParaViewWindow()
1418 \brief Save state under the module root object.
1420 void PVGUI_Module::onSaveMultiState()
1422 // Create state study object
1424 // Get SALOMEDS client study
1425 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1430 _PTR(SComponent) paravisComp =
1431 studyDS->FindComponent(PARAVIS::GetParavisGen(this)->ComponentDataType());
1436 // Unlock the study if it is locked
1437 bool isLocked = studyDS->GetProperties()->IsLocked();
1439 studyDS->GetProperties()->SetLocked(false);
1442 QString stateName = tr("SAVED_PARAVIEW_STATE_NAME") +
1443 QString::number(myStateCounter + 1);
1445 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1446 _PTR(SObject) newSObj = studyBuilder->NewObject(paravisComp);
1449 _PTR(GenericAttribute) anAttr;
1450 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeName");
1451 _PTR(AttributeName) nameAttr(anAttr);
1453 nameAttr->SetValue(stateName.toLatin1().constData());
1456 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeLocalID");
1457 _PTR(AttributeLocalID) localIdAttr(anAttr);
1459 localIdAttr->SetValue(PVSTATEID);
1462 QString stateEntry = QString::fromStdString(newSObj->GetID());
1464 // File name for state saving
1465 QString tmpDir = QString::fromStdString(SALOMEDS_Tool::GetTmpDir());
1466 QString fileName = QString("%1_paravisstate:%2").arg(tmpDir,
1469 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeString");
1470 _PTR(AttributeString) stringAttr(anAttr);
1472 stringAttr->SetValue(fileName.toLatin1().constData());
1474 // Lock the study back if necessary
1476 studyDS->GetProperties()->SetLocked(true);
1480 saveParaviewState(fileName.toLatin1().constData());
1481 myTemporaryFiles.append(fileName);
1483 // Increment the counter
1490 \brief Restore the selected state by merging with the current one.
1492 void PVGUI_Module::onAddState()
1494 loadSelectedState(false);
1498 \brief Clean the current state and restore the selected one.
1500 void PVGUI_Module::onCleanAddState()
1502 loadSelectedState(true);
1506 \brief Rename the selected object.
1508 void PVGUI_Module::onRename()
1510 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1511 SALOME_ListIO aListIO;
1512 aSelectionMgr->selectedObjects(aListIO);
1514 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1515 std::string entry = aListIO.First()->getEntry();
1517 // Get SALOMEDS client study
1518 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1523 // Unlock the study if it is locked
1524 bool isLocked = studyDS->GetProperties()->IsLocked();
1526 studyDS->GetProperties()->SetLocked(false);
1529 // Rename the selected state object
1530 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1535 _PTR(GenericAttribute) anAttr;
1536 if (stateSObj->FindAttribute(anAttr, "AttributeName")) {
1537 _PTR(AttributeName) nameAttr (anAttr);
1539 LightApp_NameDlg::getName(getApp()->desktop(), nameAttr->Value().c_str());
1540 if (!newName.isEmpty()) {
1541 nameAttr->SetValue(newName.toLatin1().constData());
1542 aListIO.First()->setName(newName.toLatin1().constData());
1546 // Lock the study back if necessary
1548 studyDS->GetProperties()->SetLocked(true);
1551 // Update object browser
1558 \brief Delete the selected objects.
1560 void PVGUI_Module::onDelete()
1562 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1563 SALOME_ListIO aListIO;
1564 aSelectionMgr->selectedObjects(aListIO);
1566 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1567 std::string entry = aListIO.First()->getEntry();
1569 // Get SALOMEDS client study
1570 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1575 // Unlock the study if it is locked
1576 bool isLocked = studyDS->GetProperties()->IsLocked();
1578 studyDS->GetProperties()->SetLocked(false);
1581 // Remove the selected state from the study
1582 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1583 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1584 studyBuilder->RemoveObject(stateSObj);
1586 // Lock the study back if necessary
1588 studyDS->GetProperties()->SetLocked(true);
1591 // Update object browser
1597 \brief Discover help project files from the resources.
1598 \return name of the help file.
1600 QString PVGUI_Module::getHelpFileName() {
1601 QString aPVHome(getenv("PVHOME"));
1602 if (aPVHome.isNull()) {
1603 qWarning("Wariable PVHOME is not defined");
1606 QChar aSep = QDir::separator();
1607 //PARAVIEW_VERSION from the vtkPVConfig.h file
1608 QString aFileName = aPVHome + aSep + "share" + aSep + "doc" + aSep + "paraview-"+ PARAVIEW_VERSION + aSep + "paraview.qch";
1614 \brief Load selected paraview state
1616 If toClear == true, the current state will be cleared
1618 void PVGUI_Module::loadSelectedState(bool toClear)
1622 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1623 SALOME_ListIO aListIO;
1624 aSelectionMgr->selectedObjects(aListIO);
1626 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1627 std::string entry = aListIO.First()->getEntry();
1629 // Get SALOMEDS client study
1630 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1636 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1637 _PTR(GenericAttribute) anAttr;
1638 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1641 _PTR(AttributeLocalID) anID(anAttr);
1642 if (!anID->Value() == PVSTATEID) {
1646 // Get state file name
1647 if (stateSObj->FindAttribute(anAttr, "AttributeString")) {
1648 _PTR(AttributeString) aStringAttr(anAttr);
1649 QString stringValue(aStringAttr->Value().c_str());
1651 if (QFile::exists(stringValue)) {
1652 fileName = stringValue;
1657 if (!fileName.isEmpty()) {
1659 clearParaviewState();
1662 loadParaviewState(fileName.toLatin1().constData());
1665 SUIT_MessageBox::critical(getApp()->desktop(),
1667 tr("ERR_STATE_CANNOT_BE_RESTORED"));
1671 void PVGUI_Module::onRepresentationChanged(pqRepresentation*) {
1674 //rnv: to fix the issue "21712: [CEA 581] Preference to display legend by default"
1675 // find the pqDisplayColorWidget instances and connect the variableChanged SIGNAL on the
1676 // onVariableChanged slot of this class. This connection needs to change visibility
1677 // of the "Colored Legend" after change the "Color By" array.
1678 QList<pqDisplayColorWidget*> aWidget = getApp()->desktop()->findChildren<pqDisplayColorWidget*>();
1680 for (int i = 0; i < aWidget.size() ; i++ ) {
1682 connect( aWidget[i], SIGNAL ( variableChanged ( pqVariableType, const QString ) ),
1683 this, SLOT(onVariableChanged( pqVariableType, const QString) ), Qt::UniqueConnection );
1690 \fn CAM_Module* createModule();
1691 \brief Export module instance (factory function).
1692 \return new created instance of the module
1696 #define PVGUI_EXPORT __declspec(dllexport)
1698 #define PVGUI_EXPORT
1704 PVGUI_EXPORT CAM_Module* createModule() {
1709 return new PVGUI_Module();
1712 PVGUI_EXPORT char* getModuleVersion() {
1713 return (char*)PARAVIS_VERSION_STR;