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 <pqStandardViewFrameActionsImplementation.h>
131 #include <pqViewStreamingBehavior.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 <pqObjectPickingBehavior.h>
148 #include <pqPersistentMainWindowStateBehavior.h>
149 #include <pqPipelineContextMenuBehavior.h>
150 #include <pqPluginActionGroupBehavior.h>
151 #include <pqPluginDockWidgetsBehavior.h>
152 #include <pqPluginManager.h>
153 #include <pqSpreadSheetVisibilityBehavior.h>
154 #include <pqUndoRedoBehavior.h>
155 #include <pqServerManagerObserver.h>
156 #include <pqVerifyRequiredPluginBehavior.h>
157 #include <pqFixPathsInStateFilesBehavior.h>
158 #include <pqPluginSettingsBehavior.h>
159 #include <pqPropertiesPanel.h>
161 #include <pqApplyBehavior.h>
163 #include <vtkClientServerInterpreterInitializer.h>
167 #include <vtkSMTrace.h>
168 #include <vtkSMSessionProxyManager.h>
169 #include <vtkSMParaViewPipelineController.h>
171 //----------------------------------------------------------------------------
172 pqPVApplicationCore* PVGUI_Module::MyCoreApp = 0;
173 //PVGUI_OutputWindowAdapter* PVGUI_Module::pqImplementation::OutputWindowAdapter = 0;
174 //QPointer<pqHelpWindow> PVGUI_Module::pqImplementation::helpWindow = 0;
176 PVGUI_Module* ParavisModule = 0;
181 <h2>Building and installing PARAVIS</h2>
182 As any other SALOME module, PARAVIS requires PARAVIS_ROOT_DIR environment variable to be set to PARAVIS
183 installation directory.
184 Other variables needed for correct detection of ParaView location:
185 \li PVHOME - points at the ParaView installation directory tree
186 \li PVVERSION - number of ParaView version
188 It also requires common SALOME environment including GUI_ROOT_DIR and other prerequsites.
191 PARAVIS module can be launched using the following commands:
192 \li Full SALOME configuration
194 runSalome --modules="PARAVIS"
197 <h2>ParaView GUI integration</h2>
198 <h3>ParaView GUI integration overview</h3>
200 The main idea is to reuse ParaView GUI internal logic as much as possible, providing a layer
201 between it and SALOME GUI that hides the following SALOME GUI implementation details from ParaView:
203 \li SALOME GUI executable and Qt event loop
204 \li SALOME GUI desktop
205 \li Dock windows areas
206 \li SALOME menu and toolbar managers
208 Major part of the integration is implemented in PVGUI_Module class.
210 <h3>ParaView client initalization</h3>
212 ParaView client initalization is performed when an instance of PVGUI_Module class has been created
213 and \link PVGUI_Module::initialize() PVGUI_Module::initialize()\endlink method is called by SALOME GUI.
214 The actual client start-up is done in \link PVGUI_Module::pvInit() PVGUI_Module::pvInit()\endlink method.
217 <h3>Multi-view manager</h3>
219 SALOME GUI requires that each kind of view be implemnted with help of (at least) three classes. For ParaView multi-view manager
222 \li PVGUI_ViewManager - view manager class
223 \li PVGUI_Viewer - view model class
224 \li PVGUI_ViewWindow - view window class that acts as a parent for %pqViewManager
226 Single instances of PVGUI_ViewManager and PVGUI_ViewWindow classes are created by \link PVGUI_Module::showView()
227 PVGUI_Module::showView()\endlink method upon the first PARAVIS module activation. The same method hides the multi-view manager
228 when the module is deactivated (the user switches to another module or a study is closed).
229 A special trick is used to make PVGUI_ViewWindow the parent of %pqViewManager widget. It is created initally by %pqMainWindowCore
230 with the desktop as a parent, so when it is shown PVGUI_ViewWindow instance is passed to its setParent() method. In
231 \link PVGUI_ViewWindow::~PVGUI_ViewWindow() PVGUI_ViewWindow::~PVGUI_ViewWindow()\endlink the parent is nullified to avoid deletion
232 of %pqViewManager widget that would break %pqMainWindowCore class.
234 <h3>ParaView plugins</h3>
235 ParaView server and client plugins are managed by %pqMainWindowCore slots that has full access to PARAVIS menus and toolbars.
236 As a result they appears automatically in PARAVIS menus and toolbars if loaded successfully.
241 \brief Implementation
242 SALOME module wrapping ParaView GUI.
246 ClientFindOrCreateParavisComponent(_PTR(Study) theStudyDocument)
248 _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("PARAVIS");
250 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
251 aStudyBuilder->NewCommand();
252 int aLocked = theStudyDocument->GetProperties()->IsLocked();
253 if (aLocked) theStudyDocument->GetProperties()->SetLocked(false);
254 aSComponent = aStudyBuilder->NewComponent("PARAVIS");
255 _PTR(GenericAttribute) anAttr =
256 aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName");
257 _PTR(AttributeName) aName (anAttr);
259 CORBA::ORB_var anORB = PARAVIS::PARAVIS_Gen_i::GetORB();
260 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
261 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
262 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
263 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
264 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
265 if (!Comp->_is_nil()) {
266 aName->SetValue(Comp->componentusername());
269 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
270 _PTR(AttributePixMap) aPixmap (anAttr);
271 aPixmap->SetPixMap( "pqAppIcon16.png" );
273 // Create Attribute parameters for future using
274 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
277 PARAVIS::PARAVIS_Gen_var aPARAVIS = PARAVIS::PARAVIS_Gen_i::GetParavisGenImpl()->_this();
279 aStudyBuilder->DefineComponentInstance(aSComponent, aPARAVIS->GetIOR());
280 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
281 aStudyBuilder->CommitCommand();
287 Clean up function; used to stop ParaView progress events when
288 exception is caught by global exception handler.
290 void paravisCleanUp()
292 if ( pqApplicationCore::instance() ) {
293 pqServer* s = pqApplicationCore::instance()->getActiveServer();
294 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
299 \brief Constructor. Sets the default name for the module.
301 PVGUI_Module::PVGUI_Module()
302 : SalomeApp_Module( "PARAVIS" ),
303 // Implementation( 0 ),
304 mySelectionControlsTb( -1 ),
305 mySourcesMenuId( -1 ),
306 myFiltersMenuId( -1 ),
308 myToolbarsMenuId(-1),
315 Q_INIT_RESOURCE( PVGUI );
317 ParavisModule = this;
319 // Clear old copies of embedded macros files
320 QString aDestPath = QString( "%1/.config/%2/Macros" ).arg( QDir::homePath() ).arg( QApplication::applicationName() );
324 QDir aDestDir(aDestPath);
325 QStringList aDestFiles = aDestDir.entryList(aFilter, QDir::Files);
326 foreach (QString aMacrosPath, getEmbeddedMacrosList()) {
327 QString aMacrosName = QFileInfo(aMacrosPath).fileName();
328 if (aDestFiles.contains(aMacrosName)) {
329 aDestDir.remove(aMacrosName);
337 PVGUI_Module::~PVGUI_Module()
342 \brief Initialize module. Creates menus, prepares context menu, etc.
343 \param app SALOME GUI application instance
345 void PVGUI_Module::initialize( CAM_Application* app )
347 // [ABN]: patched in ParaView's sources.
348 // PVGUI_MatplotlibMathTextUtilities::Disable();
350 SalomeApp_Module::initialize( app );
352 // Create ParaViS actions
354 // Create ParaViS menus
357 // Uncomment to debug ParaView initialization
358 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
366 // Initialize ParaView client
369 // Create GUI elements (menus, toolbars, dock widgets)
370 //if ( !Implementation ){
371 SalomeApp_Application* anApp = getApp();
372 SUIT_Desktop* aDesktop = anApp->desktop();
374 // connect(aDesktop, SIGNAL()
376 // Remember current state of desktop toolbars
377 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
379 // Simulate ParaView client main window
380 //Implementation = new pqImplementation( aDesktop );
388 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
389 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
391 // new pqParaViewBehaviors(anApp->desktop(), this);
392 // Has to be replaced in order to exclude using of pqQtMessageHandlerBehaviour
393 // Start pqParaViewBehaviors
394 // Register ParaView interfaces.
395 //pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
396 pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
398 // Register standard types of property widgets.
399 pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm));
400 // Register standard types of view-frame actions.
401 pgm->addInterface(new pqStandardViewFrameActionsImplementation(pgm));
403 // Load plugins distributed with application.
404 pqApplicationCore::instance()->loadDistributedPlugins();
406 // Define application behaviors.
407 //new pqQtMessageHandlerBehavior(this);
408 new pqDataTimeStepBehavior(this);
409 new pqSpreadSheetVisibilityBehavior(this);
410 new pqPipelineContextMenuBehavior(this);
411 new pqObjectPickingBehavior(this);
412 new pqDefaultViewBehavior(this);
413 new pqUndoRedoBehavior(this);
414 new pqAlwaysConnectedBehavior(this);
415 new pqCrashRecoveryBehavior(this);
416 new pqAutoLoadPluginXMLBehavior(this);
417 new pqPluginDockWidgetsBehavior(aDesktop);
418 new pqVerifyRequiredPluginBehavior(this);
419 new pqPluginActionGroupBehavior(aDesktop);
420 new pqFixPathsInStateFilesBehavior(this);
421 new pqCommandLineOptionsBehavior(this);
422 new pqPersistentMainWindowStateBehavior(aDesktop);
423 new pqCollaborationBehavior(this);
424 new pqViewStreamingBehavior(this);
425 new pqPluginSettingsBehavior(this);
427 pqApplyBehavior* applyBehavior = new pqApplyBehavior(this);
428 foreach (pqPropertiesPanel* ppanel, aDesktop->findChildren<pqPropertiesPanel*>())
430 applyBehavior->registerPanel(ppanel);
434 // Setup quick-launch shortcuts.
435 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
436 QObject::connect(ctrlSpace, SIGNAL(activated()),
437 pqApplicationCore::instance(), SLOT(quickLaunch()));
439 // Find Plugin Dock Widgets
440 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
441 QList<QDockWidget*>::iterator i;
442 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
443 if(!activeDocks.contains(*i)) {
444 myDockWidgets[*i] = false; // hidden by default
450 // [ABN] TODO: fix this - triggers a SEGFAULT at deactivation() time.
451 // QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
452 // QList<QMenu*>::iterator im;
453 // for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
454 // if(!activeMenus.contains(*im)) {
455 // QString s = (*im)->title();
456 // std::cout << " MENU "<< s.toStdString() << std::endl;
457 // myMenus.append(*im);
461 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
462 QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
463 if (!aPath.isNull()) {
464 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
465 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
466 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
467 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
470 // Force creation of engine
471 PARAVIS::GetParavisGen(this);
474 // Find created toolbars
475 QCoreApplication::processEvents();
477 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
478 foreach(QToolBar* aBar, allToolbars) {
479 if (!foreignToolbars.contains(aBar)) {
480 myToolbars[aBar] = true;
481 myToolbarBreaks[aBar] = false;
482 aBar->setVisible(false);
483 aBar->toggleViewAction()->setVisible(false);
490 // we need to start trace after connection is done
491 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(finishedAddingServer(pqServer*)),
492 this, SLOT(onFinishedAddingServer(pqServer*)));
494 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(dataRepresentationCreated(pqDataRepresentation*)),
495 this, SLOT(onDataRepresentationCreated(pqDataRepresentation*)));
498 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
499 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
500 // start a timer to schedule the trace start asap:
504 this->VTKConnect = vtkEventQtSlotConnect::New();
506 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
508 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
510 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
512 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
513 this, SLOT(onStartProgress()));
514 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
515 this, SLOT(onEndProgress()));
520 connect(&pqActiveObjects::instance(),
521 SIGNAL(representationChanged(pqRepresentation*)),
522 this, SLOT(onRepresentationChanged(pqRepresentation*)));
525 void PVGUI_Module::onStartProgress()
527 QApplication::setOverrideCursor(Qt::WaitCursor);
530 void PVGUI_Module::onEndProgress()
532 QApplication::restoreOverrideCursor();
535 void PVGUI_Module::onFinishedAddingServer(pqServer* /*server*/)
537 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
538 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
543 void PVGUI_Module::onDataRepresentationCreated(pqDataRepresentation* data) {
547 // if(!data->getLookupTable())
550 // SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
554 // bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
555 // pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
558 // lut_mgr->setScalarBarVisibility(data,visible);
561 // connect(data, SIGNAL(dataUpdated()), this, SLOT(onDataRepresentationUpdated()));
564 void PVGUI_Module::onDataRepresentationUpdated() {
565 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
566 if(!activeStudy) return;
568 activeStudy->Modified();
571 void PVGUI_Module::onVariableChanged(pqVariableType t, const QString) {
573 pqDisplayColorWidget* colorWidget = qobject_cast<pqDisplayColorWidget*>(sender());
577 if( t == VARIABLE_TYPE_NONE )
580 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
585 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
590 /*//VTN: getRepresentation is protected
591 pqDataRepresentation* data = colorWidget->getRepresentation();
593 if( !data->getLookupTable() )
596 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
599 lut_mgr->setScalarBarVisibility(data,visible);
602 pqColorToolbar* colorTooBar = qobject_cast<pqColorToolbar*>(colorWidget->parent());
606 pqScalarBarVisibilityReaction* scalarBarVisibility = colorTooBar->findChild<pqScalarBarVisibilityReaction *>();
607 if(scalarBarVisibility) {
608 scalarBarVisibility->setScalarBarVisibility(visible);
613 \brief Launches a tracing of current server
615 void PVGUI_Module::timerEvent(QTimerEvent* te )
618 // if ( PyInterp_Dispatcher::Get()->IsBusy() )
620 // // Reschedule for later
621 // MESSAGE("interpreter busy -> rescheduling trace start.");
626 MESSAGE("about to start trace....");
628 MESSAGE("trace STARTED....");
630 killTimer( te->timerId() );
635 \brief Get list of embedded macros files
637 QStringList PVGUI_Module::getEmbeddedMacrosList()
639 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
641 QString aSourcePath = aRootDir + "/bin/salome/Macro";
646 QDir aSourceDir(aSourcePath);
647 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
648 QStringList aFullPathSourceFiles;
649 foreach (QString aMacrosName, aSourceFiles) {
650 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
652 return aFullPathSourceFiles;
655 void PVGUI_Module::updateMacros()
657 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
658 if(!aPythonManager) {
662 foreach (QString aStr, getEmbeddedMacrosList()) {
663 aPythonManager->addMacro(aStr);
669 \brief Get list of compliant dockable GUI elements
670 \param m map to be filled in ("type":"default_position")
672 void PVGUI_Module::windows( QMap<int, int>& m ) const
674 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
675 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
676 // ParaView diagnostic output redirected here
677 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
681 \brief Static method, performs initialization of ParaView session.
682 \return \c true if ParaView has been initialized successfully, otherwise false
684 bool PVGUI_Module::pvInit()
686 // if ( !pqImplementation::Core ){
688 // Obtain command-line arguments
691 QString aOptions = getenv("PARAVIS_OPTIONS");
692 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
693 argv = new char*[aOptList.size() + 1];
694 QStringList args = QApplication::arguments();
695 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
698 foreach (QString aStr, aOptList) {
699 argv[argc] = strdup( aStr.toLatin1().constData() );
702 MyCoreApp = new pqPVApplicationCore (argc, argv);
703 if (MyCoreApp->getOptions()->GetHelpSelected() ||
704 MyCoreApp->getOptions()->GetUnknownArgument() ||
705 MyCoreApp->getOptions()->GetErrorMessage() ||
706 MyCoreApp->getOptions()->GetTellVersion()) {
710 /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in
711 // Not sure why this is needed. Andy added this ages ago with comment saying
712 // needed for Mac apps. Need to check that it's indeed still required.
713 QDir dir(QApplication::applicationDirPath());
716 QApplication::addLibraryPath(dir.absolutePath());
717 // Load required application plugins.
718 QString plugin_string = "";
719 QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
720 pqBrandPluginsLoader loader;
721 if (loader.loadPlugins(plugin_list) == false) {
722 printf("Failed to load required plugins for this application\n");
726 // Load optional plugins.
728 plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
729 loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
731 // End of Initializer code
733 MyCoreApp->settings();
735 vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New());
737 new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET on creation
739 for (int i = 0; i < argc; i++)
748 \brief Shows (toShow = true) or hides ParaView view window
750 void PVGUI_Module::showView( bool toShow )
752 SalomeApp_Application* anApp = getApp();
753 PVGUI_ViewManager* viewMgr =
754 dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
756 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
757 anApp->addViewManager( viewMgr );
758 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
759 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
762 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
764 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
767 pvWnd->setShown( toShow );
768 if ( toShow ) pvWnd->setFocus();
772 \brief Slot to show help for proxy.
774 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
776 pqHelpReaction::showProxyHelp(groupname, proxyname);
781 \brief Slot to show the waiting state.
783 void PVGUI_Module::onPreAccept()
785 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
786 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
790 \brief Slot to show the ready state.
792 void PVGUI_Module::onPostAccept()
794 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
795 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
799 \brief Slot to switch off wait cursor.
801 void PVGUI_Module::endWaitCursor()
803 QApplication::restoreOverrideCursor();
807 \brief Returns the ParaView multi-view manager.
809 pqTabbedMultiViewWidget* PVGUI_Module::getMultiViewManager() const
811 return qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
815 static void ParavisMessageOutput(QtMsgType type, const char *msg)
820 vtkOutputWindow::GetInstance()->DisplayText(msg);
823 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
826 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
829 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
837 \brief Activate module.
838 \param study current study
839 \return \c true if activaion is done successfully or 0 to prevent
842 bool PVGUI_Module::activateModule( SUIT_Study* study )
844 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
846 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
848 storeCommonWindowsState();
850 bool isDone = SalomeApp_Module::activateModule( study );
851 if ( !isDone ) return false;
854 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
855 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
856 if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
857 if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
858 setMenuShown( true );
859 setToolShown( true );
861 restoreDockWidgetsState();
863 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
865 QList<QAction*> anActns = aMenu->actions();
866 for (int i = 0; i < anActns.size(); ++i) {
867 QAction* a = anActns.at(i);
873 QList<QMenu*>::iterator it;
874 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
875 QAction* a = (*it)->menuAction();
880 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
882 ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this));
889 \brief Deactivate module.
890 \param study current study
891 \return \c true if deactivaion is done successfully or 0 to prevent
892 deactivation on error
894 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
896 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
898 QList<QAction*> anActns = aMenu->actions();
899 for (int i = 0; i < anActns.size(); ++i) {
900 QAction* a = anActns.at(i);
902 a->setVisible(false);
906 QList<QMenu*>::iterator it;
907 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
908 QAction* a = (*it)->menuAction();
910 a->setVisible(false);
913 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
914 foreach(QDockWidget* aView, aStreamingViews) {
915 if (!myDockWidgets.contains(aView))
916 myDockWidgets[aView] = aView->isVisible();
919 /*if (pqImplementation::helpWindow) {
920 pqImplementation::helpWindow->hide();
924 menuMgr()->hide(myRecentMenuId);
925 menuMgr()->hide(mySourcesMenuId);
926 menuMgr()->hide(myFiltersMenuId);
927 menuMgr()->hide(myMacrosMenuId);
928 menuMgr()->hide(myToolbarsMenuId);
929 setMenuShown( false );
930 setToolShown( false );
933 saveDockWidgetsState();
935 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
938 qInstallMsgHandler(myOldMsgHandler);
940 restoreCommonWindowsState();
942 return SalomeApp_Module::deactivateModule( study );
947 \brief Called when application is closed.
949 Process finalize application functionality from ParaView in order to save server settings
950 and nullify application pointer if the application is being closed.
952 \param theApp application
954 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
956 pqApplicationCore::instance()->settings()->sync();
957 int aAppsNb = SUIT_Session::session()->applications().size();
959 deleteTemporaryFiles();
960 MyCoreApp->deleteLater();
962 CAM_Module::onApplicationClosed(theApp);
967 \brief Called when study is closed.
969 Removes data model from the \a study.
971 \param study study being closed
973 void PVGUI_Module::studyClosed(SUIT_Study* study)
975 clearParaviewState();
977 SalomeApp_Module::studyClosed(study);
981 \brief Called when study is opened.
983 void PVGUI_Module::onModelOpened()
985 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
990 _PTR(SComponent) paravisComp =
991 studyDS->FindComponent(PARAVIS::GetParavisGen(this)->ComponentDataType());
996 _PTR(ChildIterator) anIter(studyDS->NewChildIterator(paravisComp));
997 for (; anIter->More(); anIter->Next()) {
998 _PTR(SObject) aSObj = anIter->Value();
999 _PTR(GenericAttribute) anAttr;
1000 if (!aSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1003 _PTR(AttributeLocalID) anID(anAttr);
1004 if (anID->Value() == PVSTATEID) {
1011 \brief Returns IOR of current engine
1013 QString PVGUI_Module::engineIOR() const
1015 CORBA::String_var anIOR = PARAVIS::GetParavisGen(this)->GetIOR();
1016 return QString(anIOR.in());
1021 \brief Open file of format supported by ParaView
1023 void PVGUI_Module::openFile(const char* theName)
1027 pqLoadDataReaction::loadData(aFiles);
1031 * Start trace invoking the newly introduced C++ API (PV 4.2)
1032 * (inspired from pqTraceReaction::start())
1034 void PVGUI_Module::startTrace()
1036 vtkSMSessionProxyManager* pxm = pqActiveObjects::instance().activeServer()->proxyManager();
1038 vtkSmartPointer<vtkSMProxy> proxy;
1039 proxy.TakeReference(pxm->NewProxy("pythontracing", "PythonTraceOptions"));
1042 vtkNew<vtkSMParaViewPipelineController> controller;
1043 controller->InitializeProxy(proxy);
1045 vtkSMTrace* trace = vtkSMTrace::StartTrace();
1048 // Set manually the properties entered via the dialog box poping-up when requiring
1049 // a trace start in PV4.2 (trace options)
1050 trace->SetPropertiesToTraceOnCreate(vtkSMTrace::RECORD_USER_MODIFIED_PROPERTIES);
1051 trace->SetFullyTraceSupplementalProxies(false);
1055 void PVGUI_Module::stopTrace()
1057 vtkSMTrace::StopTrace();
1060 void PVGUI_Module::executeScript(const char *script)
1063 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
1064 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
1066 pqPythonDialog* pyDiag = manager->pythonShellDialog();
1068 pyDiag->runString(script);
1075 // * Debug function printing out the given interpreter's execution context
1077 //void printInterpContext(PyInterp_Interp * interp )
1079 // // Extract __smtraceString from interpreter's context
1080 // const PyObject* ctxt = interp->getExecutionContext();
1082 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
1083 // Py_ssize_t siz = PyList_GET_SIZE(lst);
1084 // for (Py_ssize_t i = 0; i < siz; i++)
1086 // PyObject * elem = PyList_GetItem(lst, i);
1087 // if (PyString_Check(elem))
1089 // std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
1092 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
1098 \brief Returns trace string
1100 static const QString MYReplaceStr("paraview.simple");
1101 static const QString MYReplaceImportStr("except: from pvsimple import *");
1102 QString PVGUI_Module::getTraceString()
1104 vtkSMTrace *tracer = vtkSMTrace::GetActiveTracer();
1105 if (!tracer) // trace is not started
1108 QString traceString(tracer->GetCurrentTrace());
1110 // Replace import "paraview.simple" by "pvsimple"
1111 if ((!traceString.isNull()) && traceString.length() != 0) {
1112 int aPos = traceString.indexOf(MYReplaceStr);
1113 while (aPos != -1) {
1114 traceString = traceString.replace(aPos, MYReplaceStr.length(), "pvsimple");
1115 aPos = traceString.indexOf(MYReplaceStr, aPos);
1117 int aImportPos = traceString.indexOf(MYReplaceImportStr);
1118 if(aImportPos != -1)
1120 traceString = traceString.replace(aImportPos, MYReplaceImportStr.length(), "except:\n import pvsimple\n from pvsimple import *");
1128 \brief Saves trace string to disk file
1130 void PVGUI_Module::saveTrace(const char* theName)
1132 QFile file(theName);
1133 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1134 MESSAGE( "Could not open file:" << theName );
1137 QTextStream out(&file);
1138 out << getTraceString();
1143 \brief Saves ParaView state to a disk file
1145 void PVGUI_Module::saveParaviewState(const char* theFileName)
1147 pqApplicationCore::instance()->saveState(theFileName);
1151 \brief Delete all objects for Paraview Pipeline Browser
1153 void PVGUI_Module::clearParaviewState()
1155 QAction* deleteAllAction = action(DeleteAllId);
1156 if (deleteAllAction) {
1157 deleteAllAction->activate(QAction::Trigger);
1162 \brief Restores ParaView state from a disk file
1164 If toClear == true, the current ojects will be deleted
1166 void PVGUI_Module::loadParaviewState(const char* theFileName)
1168 pqApplicationCore::instance()->loadState(theFileName, getActiveServer());
1172 \brief Imports MED data from VISU module by data entry
1174 void PVGUI_Module::onImportFromVisu(QString theEntry)
1177 SUIT_OverrideCursor aWaitCursor;
1180 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1181 if(!activeStudy) return;
1183 // get SALOMEDS client study
1184 _PTR(Study) aStudy = activeStudy->studyDS();
1187 // find VISU component in a study
1188 _PTR(SComponent) aVisuComp = aStudy->FindComponent( "VISU" );
1189 if(!aVisuComp) return;
1191 // get SObject client by entry
1192 _PTR(SObject) aSObj = aStudy->FindObjectID(qPrintable(theEntry));
1195 // get CORBA SObject
1196 SALOMEDS_SObject* aSObject = _CAST(SObject, aSObj);
1197 if ( !aSObject ) return;
1200 SALOME_NamingService* aNamingService = SalomeApp_Application::namingService();
1201 SALOME_LifeCycleCORBA aLCC(aNamingService);
1203 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","VISU");
1204 VISU::VISU_Gen_var aVISU = VISU::VISU_Gen::_narrow(aComponent);
1205 if(CORBA::is_nil(aVISU)) return;
1207 _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
1208 aStudyBuilder->LoadWith( aVisuComp, SalomeApp_Application::orb()->object_to_string(aVISU) );
1210 // get VISU result object
1211 CORBA::Object_var aResultObject = aSObject->GetObject();
1212 if (CORBA::is_nil(aResultObject)) return;
1213 VISU::Result_var aResult = VISU::Result::_narrow( aResultObject );
1214 if (CORBA::is_nil(aResult)) return;
1216 // export VISU result to the MED file
1217 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
1218 std::string aFileName = aSObject->GetName();
1219 std::string aFilePath = aTmpDir + aFileName;
1221 if (aResult->ExportMED(aFilePath.c_str())) {
1222 openFile(aFilePath.c_str());
1223 myTemporaryFiles.append(QString(aFilePath.c_str()));
1226 MESSAGE("Visu module is not found.");
1231 \brief Deletes temporary files created during import operation from VISU
1233 void PVGUI_Module::deleteTemporaryFiles()
1235 foreach(QString aFile, myTemporaryFiles) {
1236 if (QFile::exists(aFile)) {
1237 QFile::remove(aFile);
1244 \brief Returns current active ParaView server
1246 pqServer* PVGUI_Module::getActiveServer()
1248 return pqApplicationCore::instance()->getActiveServer();
1253 \brief Creates PARAVIS preference pane
1255 void PVGUI_Module::createPreferences()
1257 // Paraview settings tab
1258 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
1259 int aPanel = addPreference(QString(), aParaViewSettingsTab, LightApp_Preferences::UserDefined, "PARAVIS", "");
1260 setPreferenceProperty(aPanel, "content", (qint64)(new PVGUI_ParaViewSettingsPane()));
1262 // Paravis settings tab
1263 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
1264 addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
1266 int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
1267 LightApp_Preferences::Selector,
1268 "PARAVIS", "savestate_type");
1269 QList<QVariant> aIndices;
1270 QStringList aStrings;
1272 aStrings<<tr("PREF_SAVE_TYPE_0");
1273 aStrings<<tr("PREF_SAVE_TYPE_1");
1274 aStrings<<tr("PREF_SAVE_TYPE_2");
1275 setPreferenceProperty(aSaveType, "strings", aStrings);
1276 setPreferenceProperty(aSaveType, "indexes", aIndices);
1278 //rnv: imp 21712: [CEA 581] Preference to display legend by default
1279 // [ABN]: now fixed in ParaView.
1280 // int aDispColoreLegend = addPreference( tr( "PREF_SHOW_COLOR_LEGEND" ), aParaVisSettingsTab,
1281 // LightApp_Preferences::Bool, "PARAVIS", "show_color_legend");
1285 \brief Creates ParaViS context menu popup
1287 void PVGUI_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
1289 SalomeApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
1291 // Check if we are in Object Browser
1292 SUIT_DataBrowser* ob = getApp()->objectBrowser();
1293 bool isOBClient = (ob && theClient == ob->popupClientType());
1298 // Get list of selected objects
1299 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1300 SALOME_ListIO aListIO;
1301 aSelectionMgr->selectedObjects(aListIO);
1302 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1303 QString entry = QString(aListIO.First()->getEntry());
1306 SalomeApp_Study* activeStudy =
1307 dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
1312 // Get SALOMEDS client study
1313 _PTR(Study) studyDS = activeStudy->studyDS();
1318 QString paravisDataType(PARAVIS::GetParavisGen(this)->ComponentDataType());
1319 if(activeStudy && activeStudy->isComponent(entry) &&
1320 activeStudy->componentDataType(entry) == paravisDataType) {
1321 // ParaViS module object
1322 theMenu->addSeparator();
1323 theMenu->addAction(action(SaveStatePopupId));
1326 // Try to get state object
1327 _PTR(SObject) stateSObj =
1328 studyDS->FindObjectID(entry.toLatin1().constData());
1334 _PTR(GenericAttribute) anAttr;
1335 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1339 _PTR(AttributeLocalID) anID(anAttr);
1341 if (anID->Value() == PVSTATEID) {
1342 // Paraview state object
1343 theMenu->addSeparator();
1344 theMenu->addAction(action(AddStatePopupId));
1345 theMenu->addAction(action(CleanAndAddStatePopupId));
1346 theMenu->addSeparator();
1347 theMenu->addAction(action(ParaVisRenameId));
1348 theMenu->addAction(action(ParaVisDeleteId));
1355 \brief. Show ParaView python trace.
1357 void PVGUI_Module::onShowTrace()
1359 if (!myTraceWindow) {
1360 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
1362 myTraceWindow->setText(getTraceString());
1363 myTraceWindow->show();
1364 myTraceWindow->raise();
1365 myTraceWindow->activateWindow();
1370 \brief. Re-initialize ParaView python trace.
1372 void PVGUI_Module::onRestartTrace()
1379 \brief Show ParaView view.
1381 void PVGUI_Module::onNewParaViewWindow()
1387 \brief Save state under the module root object.
1389 void PVGUI_Module::onSaveMultiState()
1391 // Create state study object
1393 // Get SALOMEDS client study
1394 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1399 _PTR(SComponent) paravisComp =
1400 studyDS->FindComponent(PARAVIS::GetParavisGen(this)->ComponentDataType());
1405 // Unlock the study if it is locked
1406 bool isLocked = studyDS->GetProperties()->IsLocked();
1408 studyDS->GetProperties()->SetLocked(false);
1411 QString stateName = tr("SAVED_PARAVIEW_STATE_NAME") +
1412 QString::number(myStateCounter + 1);
1414 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1415 _PTR(SObject) newSObj = studyBuilder->NewObject(paravisComp);
1418 _PTR(GenericAttribute) anAttr;
1419 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeName");
1420 _PTR(AttributeName) nameAttr(anAttr);
1422 nameAttr->SetValue(stateName.toLatin1().constData());
1425 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeLocalID");
1426 _PTR(AttributeLocalID) localIdAttr(anAttr);
1428 localIdAttr->SetValue(PVSTATEID);
1431 QString stateEntry = QString::fromStdString(newSObj->GetID());
1433 // File name for state saving
1434 QString tmpDir = QString::fromStdString(SALOMEDS_Tool::GetTmpDir());
1435 QString fileName = QString("%1_paravisstate:%2").arg(tmpDir,
1438 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeString");
1439 _PTR(AttributeString) stringAttr(anAttr);
1441 stringAttr->SetValue(fileName.toLatin1().constData());
1443 // Lock the study back if necessary
1445 studyDS->GetProperties()->SetLocked(true);
1449 saveParaviewState(fileName.toLatin1().constData());
1450 myTemporaryFiles.append(fileName);
1452 // Increment the counter
1459 \brief Restore the selected state by merging with the current one.
1461 void PVGUI_Module::onAddState()
1463 loadSelectedState(false);
1467 \brief Clean the current state and restore the selected one.
1469 void PVGUI_Module::onCleanAddState()
1471 loadSelectedState(true);
1475 \brief Rename the selected object.
1477 void PVGUI_Module::onRename()
1479 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1480 SALOME_ListIO aListIO;
1481 aSelectionMgr->selectedObjects(aListIO);
1483 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1484 std::string entry = aListIO.First()->getEntry();
1486 // Get SALOMEDS client study
1487 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1492 // Unlock the study if it is locked
1493 bool isLocked = studyDS->GetProperties()->IsLocked();
1495 studyDS->GetProperties()->SetLocked(false);
1498 // Rename the selected state object
1499 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1504 _PTR(GenericAttribute) anAttr;
1505 if (stateSObj->FindAttribute(anAttr, "AttributeName")) {
1506 _PTR(AttributeName) nameAttr (anAttr);
1508 LightApp_NameDlg::getName(getApp()->desktop(), nameAttr->Value().c_str());
1509 if (!newName.isEmpty()) {
1510 nameAttr->SetValue(newName.toLatin1().constData());
1511 aListIO.First()->setName(newName.toLatin1().constData());
1515 // Lock the study back if necessary
1517 studyDS->GetProperties()->SetLocked(true);
1520 // Update object browser
1527 \brief Delete the selected objects.
1529 void PVGUI_Module::onDelete()
1531 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1532 SALOME_ListIO aListIO;
1533 aSelectionMgr->selectedObjects(aListIO);
1535 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1536 std::string entry = aListIO.First()->getEntry();
1538 // Get SALOMEDS client study
1539 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1544 // Unlock the study if it is locked
1545 bool isLocked = studyDS->GetProperties()->IsLocked();
1547 studyDS->GetProperties()->SetLocked(false);
1550 // Remove the selected state from the study
1551 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1552 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1553 studyBuilder->RemoveObject(stateSObj);
1555 // Lock the study back if necessary
1557 studyDS->GetProperties()->SetLocked(true);
1560 // Update object browser
1566 \brief Discover help project files from the resources.
1567 \return name of the help file.
1569 QString PVGUI_Module::getHelpFileName() {
1570 QString aPVHome(getenv("PVHOME"));
1571 if (aPVHome.isNull()) {
1572 qWarning("Wariable PVHOME is not defined");
1575 QChar aSep = QDir::separator();
1576 //PARAVIEW_VERSION from the vtkPVConfig.h file
1577 QString aFileName = aPVHome + aSep + "share" + aSep + "doc" + aSep + "paraview-"+ PARAVIEW_VERSION + aSep + "paraview.qch";
1583 \brief Load selected paraview state
1585 If toClear == true, the current state will be cleared
1587 void PVGUI_Module::loadSelectedState(bool toClear)
1591 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1592 SALOME_ListIO aListIO;
1593 aSelectionMgr->selectedObjects(aListIO);
1595 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1596 std::string entry = aListIO.First()->getEntry();
1598 // Get SALOMEDS client study
1599 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1605 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1606 _PTR(GenericAttribute) anAttr;
1607 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1610 _PTR(AttributeLocalID) anID(anAttr);
1611 if (!anID->Value() == PVSTATEID) {
1615 // Get state file name
1616 if (stateSObj->FindAttribute(anAttr, "AttributeString")) {
1617 _PTR(AttributeString) aStringAttr(anAttr);
1618 QString stringValue(aStringAttr->Value().c_str());
1620 if (QFile::exists(stringValue)) {
1621 fileName = stringValue;
1626 if (!fileName.isEmpty()) {
1628 clearParaviewState();
1631 loadParaviewState(fileName.toLatin1().constData());
1634 SUIT_MessageBox::critical(getApp()->desktop(),
1636 tr("ERR_STATE_CANNOT_BE_RESTORED"));
1640 void PVGUI_Module::onRepresentationChanged(pqRepresentation*) {
1643 //rnv: to fix the issue "21712: [CEA 581] Preference to display legend by default"
1644 // find the pqDisplayColorWidget instances and connect the variableChanged SIGNAL on the
1645 // onVariableChanged slot of this class. This connection needs to change visibility
1646 // of the "Colored Legend" after change the "Color By" array.
1647 QList<pqDisplayColorWidget*> aWidget = getApp()->desktop()->findChildren<pqDisplayColorWidget*>();
1649 for (int i = 0; i < aWidget.size() ; i++ ) {
1651 connect( aWidget[i], SIGNAL ( variableChanged ( pqVariableType, const QString ) ),
1652 this, SLOT(onVariableChanged( pqVariableType, const QString) ), Qt::UniqueConnection );
1659 \fn CAM_Module* createModule();
1660 \brief Export module instance (factory function).
1661 \return new created instance of the module
1665 #define PVGUI_EXPORT __declspec(dllexport)
1667 #define PVGUI_EXPORT
1673 PVGUI_EXPORT CAM_Module* createModule() {
1675 // vtkEDFHelperInit();
1678 return new PVGUI_Module();
1681 PVGUI_EXPORT char* getModuleVersion() {
1682 return (char*)PARAVIS_VERSION_STR;