1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : PVGUI_Module.cxx
22 // Author : Julia DOROVSKIKH
24 #include <Standard_math.hxx> // E.A. must be included before Python.h to fix compilation on windows
26 #undef HAVE_FINITE // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
28 #include <vtkPython.h> // Python first
29 #include "PVGUI_Module.h"
31 #ifdef PARAVIS_WITH_FULL_CORBA
32 # include "PARAVIS_Gen_i.hh"
35 //#include "PV_Tools.h"
37 #include "PVGUI_ViewModel.h"
38 #include "PVGUI_ViewManager.h"
39 #include "PVGUI_ViewWindow.h"
40 #include "PVGUI_Tools.h"
41 #include "PVGUI_ParaViewSettingsPane.h"
42 #include "PVGUI_OutputWindowAdapter.h"
44 #include <SUIT_DataBrowser.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_OverrideCursor.h>
50 #include <SUIT_ExceptionHandler.h>
53 #include "SALOME_LifeCycleCORBA.hxx"
54 #include "SALOMEDS_SObject.hxx"
56 #include "LightApp_SelectionMgr.h"
57 #include "LightApp_NameDlg.h"
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_Study.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOMEDS_Tool.hxx>
63 #include <PyInterp_Interp.h>
64 #include <PyInterp_Dispatcher.h>
65 #include <PyConsole_Console.h>
69 #include <QtxActionMenuMgr.h>
70 #include <QtxActionToolMgr.h>
73 #include <QApplication>
79 #include <QInputDialog>
83 #include <QStringList>
86 #include <QTextStream>
88 #include <QDockWidget>
89 #include <QHelpEngine>
91 #include <pqApplicationCore.h>
92 #include <pqPVApplicationCore.h>
93 #include <pqActiveView.h>
94 #include <pqObjectBuilder.h>
95 #include <pqOptions.h>
96 #include <pqRenderView.h>
98 #include <pqUndoStack.h>
99 #include <pqVCRController.h>
100 #include <pqTabbedMultiViewWidget.h>
101 #include <pqPipelineSource.h>
102 #include <pqActiveObjects.h>
103 #include <vtkProcessModule.h>
104 #include <vtkSMSession.h>
105 #include <vtkPVSession.h>
106 #include <vtkPVProgressHandler.h>
107 #include <pqParaViewBehaviors.h>
108 #include <pqHelpReaction.h>
109 #include <vtkOutputWindow.h>
110 #include <pqPluginManager.h>
111 #include "pqInterfaceTracker.h"
112 #include <pqSettings.h>
113 #include <pqPythonDialog.h>
114 #include <pqPythonManager.h>
115 #include <pqPythonShell.h>
116 #include <pqLoadDataReaction.h>
117 #include <vtkEventQtSlotConnect.h>
118 #include <pqPythonScriptEditor.h>
119 #include <pqCollaborationBehavior.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>
126 #include <pqStandardPropertyWidgetInterface.h>
127 #include <pqViewStreamingBehavior.h>
128 #include <pqServerResource.h>
129 #include <pqServerConnectReaction.h>
130 #include <pqServerDisconnectReaction.h>
132 #include <PARAVIS_version.h>
134 #include <vtkPVConfig.h>
137 #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
139 #include <pqAlwaysConnectedBehavior.h>
140 #include <pqApplicationCore.h>
141 #include <pqAutoLoadPluginXMLBehavior.h>
142 #include <pqCommandLineOptionsBehavior.h>
143 #include <pqCrashRecoveryBehavior.h>
144 #include <pqDataTimeStepBehavior.h>
145 #include <pqDefaultViewBehavior.h>
146 #include <pqDeleteBehavior.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 <pqPVNewSourceBehavior.h>
154 #include <pqSpreadSheetVisibilityBehavior.h>
155 #include <pqStandardViewModules.h>
156 #include <pqUndoRedoBehavior.h>
157 #include <pqViewFrameActionsBehavior.h>
158 #include <pqServerManagerObserver.h>
160 #include <vtkClientServerInterpreterInitializer.h>
163 //----------------------------------------------------------------------------
164 pqPVApplicationCore* PVGUI_Module::MyCoreApp = 0;
165 //PVGUI_OutputWindowAdapter* PVGUI_Module::pqImplementation::OutputWindowAdapter = 0;
166 //QPointer<pqHelpWindow> PVGUI_Module::pqImplementation::helpWindow = 0;
168 PVGUI_Module* ParavisModule = 0;
170 PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::myEngine;
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();
274 CORBA::ORB_var anORB = CORBA::ORB_init(dnu, 0); // suppose ORB was already initialized
275 SALOME_NamingService *NamingService = new SALOME_NamingService( anORB );
276 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
277 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
278 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
279 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "PARAVIS" );
280 if (!Comp->_is_nil()) {
281 aName->SetValue(Comp->componentusername());
284 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap");
285 _PTR(AttributePixMap) aPixmap (anAttr);
286 aPixmap->SetPixMap( "pqAppIcon16.png" );
288 // Create Attribute parameters for future using
289 anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeParameter");
291 aStudyBuilder->DefineComponentInstance(aSComponent, PVGUI_Module::GetEngine()->GetIOR());
292 if (aLocked) theStudyDocument->GetProperties()->SetLocked(true);
293 aStudyBuilder->CommitCommand();
299 Clean up function; used to stop ParaView progress events when
300 exception is caught by global exception handler.
302 void paravisCleanUp()
304 if ( pqApplicationCore::instance() ) {
305 pqServer* s = pqApplicationCore::instance()->getActiveServer();
306 if ( s ) s->session()->GetProgressHandler()->CleanupPendingProgress();
311 \brief Constructor. Sets the default name for the module.
313 PVGUI_Module::PVGUI_Module()
314 : SalomeApp_Module( "PARAVIS" ),
315 // Implementation( 0 ),
316 mySelectionControlsTb( -1 ),
317 mySourcesMenuId( -1 ),
318 myFiltersMenuId( -1 ),
320 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()
352 if (myPushTraceTimer)
353 delete myPushTraceTimer;
354 //MyCoreApp->prepareForQuit();
355 // even if it is static:
360 PARAVIS_ORB::PARAVIS_Gen_var PVGUI_Module::GetEngine()
362 // initialize PARAVIS module engine (load, if necessary)
363 if ( CORBA::is_nil( myEngine ) ) {
364 Engines::EngineComponent_var comp =
365 SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" );
366 myEngine = PARAVIS_ORB::PARAVIS_Gen::_narrow( comp );
372 \brief Initialize module. Creates menus, prepares context menu, etc.
373 \param app SALOME GUI application instance
375 void PVGUI_Module::initialize( CAM_Application* app )
377 // [ABN]: patched in ParaView's sources.
378 // PVGUI_MatplotlibMathTextUtilities::Disable();
380 SalomeApp_Module::initialize( app );
382 // Create ParaViS actions
384 // Create ParaViS menus
387 // Uncomment to debug ParaView initialization
388 // "aa" used instead of "i" as GDB doesn't like "i" variables :)
396 // Initialize ParaView client
399 // Create GUI elements (menus, toolbars, dock widgets)
400 SalomeApp_Application* anApp = getApp();
401 SUIT_Desktop* aDesktop = anApp->desktop();
403 // Remember current state of desktop toolbars
404 QList<QToolBar*> foreignToolbars = aDesktop->findChildren<QToolBar*>();
406 // Simulate ParaView client main window
407 //Implementation = new pqImplementation( aDesktop );
415 QList<QDockWidget*> activeDocks = aDesktop->findChildren<QDockWidget*>();
416 QList<QMenu*> activeMenus = aDesktop->findChildren<QMenu*>();
418 // new pqParaViewBehaviors(anApp->desktop(), this);
419 // Has to be replaced in order to exclude using of pqQtMessageHandlerBehaviour
420 // Start pqParaViewBehaviors
421 // Register ParaView interfaces.
422 //pqPluginManager* pgm = pqApplicationCore::instance()->getPluginManager();
423 pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
425 // * adds support for standard paraview views.
426 pgm->addInterface(new pqStandardViewModules(pgm));
427 //pgm->addInterface(new pqStandardSummaryPanelImplementation(pgm));
428 pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm));
430 // Load plugins distributed with application.
431 pqApplicationCore::instance()->loadDistributedPlugins();
433 // Define application behaviors.
434 //new pqQtMessageHandlerBehavior(this);
435 new pqDataTimeStepBehavior(this);
436 new pqViewFrameActionsBehavior(this);
437 new pqSpreadSheetVisibilityBehavior(this);
438 new pqPipelineContextMenuBehavior(this);
439 new pqObjectPickingBehavior(this); // NEW in 4.1
440 new pqDefaultViewBehavior(this);
441 new pqAlwaysConnectedBehavior(this);
442 new pqPVNewSourceBehavior(this);
443 new pqDeleteBehavior(this);
444 new pqUndoRedoBehavior(this);
445 new pqCrashRecoveryBehavior(this);
446 new pqAutoLoadPluginXMLBehavior(this);
447 new pqPluginDockWidgetsBehavior(aDesktop);
448 //new pqVerifyRequiredPluginBehavior(this);
449 new pqPluginActionGroupBehavior(aDesktop);
450 //new pqFixPathsInStateFilesBehavior(this);
451 new pqCommandLineOptionsBehavior(this);
452 new pqPersistentMainWindowStateBehavior(aDesktop);
453 new pqObjectPickingBehavior(aDesktop);
454 new pqCollaborationBehavior(this);
455 //new pqMultiServerBehavior(this);
456 new pqViewStreamingBehavior(this);
458 // Setup quick-launch shortcuts.
459 QShortcut *ctrlSpace = new QShortcut(Qt::CTRL + Qt::Key_Space, aDesktop);
460 QObject::connect(ctrlSpace, SIGNAL(activated()),
461 pqApplicationCore::instance(), SLOT(quickLaunch()));
463 // Find Plugin Dock Widgets
464 QList<QDockWidget*> currentDocks = aDesktop->findChildren<QDockWidget*>();
465 QList<QDockWidget*>::iterator i;
466 for (i = currentDocks.begin(); i != currentDocks.end(); ++i) {
467 if(!activeDocks.contains(*i)) {
468 myDockWidgets[*i] = false; // hidden by default
474 QList<QMenu*> currentMenus = aDesktop->findChildren<QMenu*>();
475 QList<QMenu*>::iterator im;
476 for (im = currentMenus.begin(); im != currentMenus.end(); ++im) {
477 if(!activeMenus.contains(*im)) {
482 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
483 QString aPath = resMgr->stringValue("resources", "PARAVIS", QString());
484 if (!aPath.isNull()) {
485 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewFilters.xml");
486 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewReaders.xml");
487 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewSources.xml");
488 MyCoreApp->loadConfiguration(aPath + QDir::separator() + "ParaViewWriters.xml");
491 // Force creation of the PARAVIS engine
495 // Find created toolbars
496 QCoreApplication::processEvents();
498 QList<QToolBar*> allToolbars = aDesktop->findChildren<QToolBar*>();
499 foreach(QToolBar* aBar, allToolbars) {
500 if (!foreignToolbars.contains(aBar)) {
501 myToolbars[aBar] = true;
502 myToolbarBreaks[aBar] = false;
503 aBar->setVisible(false);
504 aBar->toggleViewAction()->setVisible(false);
510 // we need to start trace after connection is done
511 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(finishedAddingServer(pqServer*)),
512 this, SLOT(onFinishedAddingServer(pqServer*)));
514 connect(pqApplicationCore::instance()->getObjectBuilder(), SIGNAL(dataRepresentationCreated(pqDataRepresentation*)),
515 this, SLOT(onDataRepresentationCreated(pqDataRepresentation*)));
517 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
518 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
519 // start a timer to schedule the trace start asap:
523 myPushTraceTimer = new QTimer(aDesktop);
524 QObject::connect(myPushTraceTimer, SIGNAL(timeout()), this, SLOT(onPushTraceTimer()) );
525 myPushTraceTimer->setSingleShot(false);
526 myPushTraceTimer->start(500);
529 this->VTKConnect = vtkEventQtSlotConnect::New();
531 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
533 vtkPVSession* pvs = dynamic_cast<vtkPVSession*>(pm->GetSession());
535 vtkPVProgressHandler* ph = pvs->GetProgressHandler();
537 this->VTKConnect->Connect(ph, vtkCommand::StartEvent,
538 this, SLOT(onStartProgress()));
539 this->VTKConnect->Connect(ph, vtkCommand::EndEvent,
540 this, SLOT(onEndProgress()));
545 connect(&pqActiveObjects::instance(),
546 SIGNAL(representationChanged(pqRepresentation*)),
547 this, SLOT(onRepresentationChanged(pqRepresentation*)));
549 #ifndef PARAVIS_WITH_FULL_CORBA
550 connectToExternalPVServer();
554 bool PVGUI_Module::connectToExternalPVServer()
556 pqServer* server = pqActiveObjects::instance().activeServer();
557 if (server && server->isRemote())
559 // Already connected to an external server, do nothing
560 MESSAGE("connectToExternalPVServer(): Already connected to an external PVServer, won't reconnect.");
564 std::stringstream msg;
566 // Try to connect to the external PVServer - gives priority to an externally specified URL:
567 QString serverUrlEnv = getenv("PARAVIS_PVSERVER_URL");
568 std::string serverUrl;
569 if (!serverUrlEnv.isEmpty())
570 serverUrl = serverUrlEnv.toStdString();
573 // Get the URL from the engine (possibly starting the pvserver)
574 CORBA::String_var url = GetEngine()->FindOrStartPVServer(0); // take the first free port
575 serverUrl = (char *)url;
578 msg << "connectToExternalPVServer(): Trying to connect to the external PVServer '" << serverUrl << "' ...";
581 if (!pqServerConnectReaction::connectToServer(pqServerResource(serverUrl.c_str())))
583 std::stringstream msg2;
584 msg2 << "Error while connecting to the requested pvserver '" << serverUrl;
585 msg2 << "'. Might use default built-in connection instead!" << std::endl;
586 qWarning(msg2.str().c_str()); // will go to the ParaView console (see ParavisMessageOutput below)
587 SUIT_MessageBox::warning( getApp()->desktop(),
588 QString("Error connecting to PVServer"), QString(msg2.str().c_str()));
592 MESSAGE("connectToExternalPVServer(): Connected!");
596 void PVGUI_Module::onStartProgress()
598 QApplication::setOverrideCursor(Qt::WaitCursor);
601 void PVGUI_Module::onEndProgress()
603 QApplication::restoreOverrideCursor();
606 void PVGUI_Module::onFinishedAddingServer(pqServer* /*server*/)
608 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
609 bool isStop = aResourceMgr->booleanValue( "PARAVIS", "stop_trace", false );
614 void PVGUI_Module::onDataRepresentationCreated(pqDataRepresentation* data) {
618 if(!data->getLookupTable())
621 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
625 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
626 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
629 lut_mgr->setScalarBarVisibility(data,visible);
632 connect(data, SIGNAL(dataUpdated()), this, SLOT(onDataRepresentationUpdated()));
635 void PVGUI_Module::onDataRepresentationUpdated() {
636 SalomeApp_Study* activeStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
637 if(!activeStudy) return;
639 activeStudy->Modified();
642 void PVGUI_Module::onVariableChanged(pqVariableType t, const QString) {
644 pqDisplayColorWidget* colorWidget = qobject_cast<pqDisplayColorWidget*>(sender());
648 if( t == VARIABLE_TYPE_NONE )
651 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
656 bool visible = aResourceMgr->booleanValue( "PARAVIS", "show_color_legend", false );
661 /*//VTN: getRepresentation is protected
662 pqDataRepresentation* data = colorWidget->getRepresentation();
664 if( !data->getLookupTable() )
667 pqLookupTableManager* lut_mgr = pqApplicationCore::instance()->getLookupTableManager();
670 lut_mgr->setScalarBarVisibility(data,visible);
673 pqColorToolbar* colorTooBar = qobject_cast<pqColorToolbar*>(colorWidget->parent());
677 pqScalarBarVisibilityReaction* scalarBarVisibility = colorTooBar->findChild<pqScalarBarVisibilityReaction *>();
678 if(scalarBarVisibility) {
679 scalarBarVisibility->setScalarBarVisibility(visible);
683 void PVGUI_Module::execPythonCommand(const QString& cmd, bool inSalomeConsole)
685 if ( inSalomeConsole ) {
686 if ( PyInterp_Dispatcher::Get()->IsBusy() ) return;
687 SalomeApp_Application* app =
688 dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
689 PyConsole_Console* pyConsole = app->pythonConsole();
691 pyConsole->exec(cmd);
695 pqPythonManager* manager = qobject_cast<pqPythonManager*>
696 ( pqApplicationCore::instance()->manager( "PYTHON_MANAGER" ) );
699 pqPythonDialog* pyDiag = manager->pythonShellDialog();
702 pqPythonShell* shell = pyDiag->shell();
704 shell->executeScript(cmd);
712 \brief Launches a tracing of current server
714 void PVGUI_Module::timerEvent(QTimerEvent* te )
716 // connectToExternalPVServer();
719 if ( PyInterp_Dispatcher::Get()->IsBusy() )
721 // Reschedule for later
722 MESSAGE("interpreter busy -> rescheduling trace start.");
727 MESSAGE("about to start trace....");
728 execPythonCommand("from paraview import smtrace;smtrace.start_trace()", false);
729 MESSAGE("trace STARTED....");
731 killTimer( te->timerId() );
736 \brief Get list of embedded macros files
738 QStringList PVGUI_Module::getEmbeddedMacrosList()
740 QString aRootDir = getenv("PARAVIS_ROOT_DIR");
742 QString aSourcePath = aRootDir + "/bin/salome/Macro";
747 QDir aSourceDir(aSourcePath);
748 QStringList aSourceFiles = aSourceDir.entryList(aFilter, QDir::Files);
749 QStringList aFullPathSourceFiles;
750 foreach (QString aMacrosName, aSourceFiles) {
751 aFullPathSourceFiles << aSourceDir.absoluteFilePath(aMacrosName);
753 return aFullPathSourceFiles;
756 void PVGUI_Module::updateMacros()
758 pqPythonManager* aPythonManager = pqPVApplicationCore::instance()->pythonManager();
759 if(!aPythonManager) {
763 foreach (QString aStr, getEmbeddedMacrosList()) {
764 aPythonManager->addMacro(aStr);
770 \brief Get list of compliant dockable GUI elements
771 \param m map to be filled in ("type":"default_position")
773 void PVGUI_Module::windows( QMap<int, int>& m ) const
775 m.insert( LightApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
776 m.insert( LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
777 // ParaView diagnostic output redirected here
778 m.insert( LightApp_Application::WT_LogWindow, Qt::BottomDockWidgetArea );
782 \brief Static method, performs initialization of ParaView session.
783 \return \c true if ParaView has been initialized successfully, otherwise false
785 bool PVGUI_Module::pvInit()
787 // if ( !pqImplementation::Core ){
789 // Obtain command-line arguments
792 QString aOptions = getenv("PARAVIS_OPTIONS");
793 QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts);
794 argv = new char*[aOptList.size() + 1];
795 QStringList args = QApplication::arguments();
796 argv[0] = (args.size() > 0)? strdup(args[0].toLatin1().constData()) : strdup("paravis");
799 foreach (QString aStr, aOptList) {
800 argv[argc] = strdup( aStr.toLatin1().constData() );
803 MyCoreApp = new pqPVApplicationCore (argc, argv);
804 if (MyCoreApp->getOptions()->GetHelpSelected() ||
805 MyCoreApp->getOptions()->GetUnknownArgument() ||
806 MyCoreApp->getOptions()->GetErrorMessage() ||
807 MyCoreApp->getOptions()->GetTellVersion()) {
811 /* VTN: Looks like trash. For porting see branded_paraview_initializer.cxx.in
812 // Not sure why this is needed. Andy added this ages ago with comment saying
813 // needed for Mac apps. Need to check that it's indeed still required.
814 QDir dir(QApplication::applicationDirPath());
817 QApplication::addLibraryPath(dir.absolutePath());
818 // Load required application plugins.
819 QString plugin_string = "";
820 QStringList plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
821 pqBrandPluginsLoader loader;
822 if (loader.loadPlugins(plugin_list) == false) {
823 printf("Failed to load required plugins for this application\n");
827 // Load optional plugins.
829 plugin_list = plugin_string.split(';',QString::SkipEmptyParts);
830 loader.loadPlugins(plugin_list, true); //quietly skip not-found plugins.
832 // End of Initializer code
834 vtkOutputWindow::SetInstance(PVGUI_OutputWindowAdapter::New());
836 new pqTabbedMultiViewWidget(); // it registers as "MULTIVIEW_WIDGET on creation
838 for (int i = 0; i < argc; i++)
847 \brief Shows (toShow = true) or hides ParaView view window
849 void PVGUI_Module::showView( bool toShow )
851 SalomeApp_Application* anApp = getApp();
852 PVGUI_ViewManager* viewMgr =
853 dynamic_cast<PVGUI_ViewManager*>( anApp->getViewManager( PVGUI_Viewer::Type(), false ) );
855 viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
856 anApp->addViewManager( viewMgr );
857 connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
858 anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
861 PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->getActiveView() );
863 pvWnd = dynamic_cast<PVGUI_ViewWindow*>( viewMgr->createViewWindow() );
866 pvWnd->setShown( toShow );
867 if ( toShow ) pvWnd->setFocus();
871 \brief Slot to show help for proxy.
873 void PVGUI_Module::showHelpForProxy( const QString& groupname, const QString& proxyname )
875 pqHelpReaction::showProxyHelp(groupname, proxyname);
880 \brief Slot to show the waiting state.
882 void PVGUI_Module::onPreAccept()
884 getApp()->desktop()->statusBar()->showMessage(tr("STB_PREACCEPT"));
885 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
889 \brief Slot to show the ready state.
891 void PVGUI_Module::onPostAccept()
893 getApp()->desktop()->statusBar()->showMessage(tr("STB_POSTACCEPT"), 2000);
894 QTimer::singleShot(0, this, SLOT(endWaitCursor()));
898 \brief Slot to switch off wait cursor.
900 void PVGUI_Module::endWaitCursor()
902 QApplication::restoreOverrideCursor();
906 \brief Returns the ParaView multi-view manager.
908 pqTabbedMultiViewWidget* PVGUI_Module::getMultiViewManager() const
910 return qobject_cast<pqTabbedMultiViewWidget*>(pqApplicationCore::instance()->manager("MULTIVIEW_WIDGET"));
914 static void ParavisMessageOutput(QtMsgType type, const char *msg)
919 vtkOutputWindow::GetInstance()->DisplayText(msg);
922 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
925 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
928 vtkOutputWindow::GetInstance()->DisplayErrorText(msg);
936 \brief Activate module.
937 \param study current study
938 \return \c true if activaion is done successfully or 0 to prevent
941 bool PVGUI_Module::activateModule( SUIT_Study* study )
943 myOldMsgHandler = qInstallMsgHandler(ParavisMessageOutput);
945 SUIT_ExceptionHandler::addCleanUpRoutine( paravisCleanUp );
947 storeCommonWindowsState();
949 bool isDone = SalomeApp_Module::activateModule( study );
950 if ( !isDone ) return false;
953 if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId);
954 if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId);
955 if ( myFiltersMenuId != -1 ) menuMgr()->show(myMacrosMenuId);
956 if ( myFiltersMenuId != -1 ) menuMgr()->show(myToolbarsMenuId);
957 setMenuShown( true );
958 setToolShown( true );
960 restoreDockWidgetsState();
962 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
964 QList<QAction*> anActns = aMenu->actions();
965 for (int i = 0; i < anActns.size(); ++i) {
966 QAction* a = anActns.at(i);
972 QList<QMenu*>::iterator it;
973 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
974 QAction* a = (*it)->menuAction();
979 if ( myRecentMenuId != -1 ) menuMgr()->show(myRecentMenuId);
981 ClientFindOrCreateParavisComponent(PARAVIS::GetCStudy(this));
988 \brief Deactivate module.
989 \param study current study
990 \return \c true if deactivaion is done successfully or 0 to prevent
991 deactivation on error
993 bool PVGUI_Module::deactivateModule( SUIT_Study* study )
996 MESSAGE("Stopping Python trace ...")
997 execPythonCommand("from paraview import smtrace;smtrace.stop_trace()", false);
999 QMenu* aMenu = menuMgr()->findMenu( myRecentMenuId );
1001 QList<QAction*> anActns = aMenu->actions();
1002 for (int i = 0; i < anActns.size(); ++i) {
1003 QAction* a = anActns.at(i);
1005 a->setVisible(false);
1009 QList<QMenu*>::iterator it;
1010 for (it = myMenus.begin(); it != myMenus.end(); ++it) {
1011 QAction* a = (*it)->menuAction();
1013 a->setVisible(false);
1016 QList<QDockWidget*> aStreamingViews = application()->desktop()->findChildren<QDockWidget*>("pqStreamingControls");
1017 foreach(QDockWidget* aView, aStreamingViews) {
1018 if (!myDockWidgets.contains(aView))
1019 myDockWidgets[aView] = aView->isVisible();
1022 /*if (pqImplementation::helpWindow) {
1023 pqImplementation::helpWindow->hide();
1027 menuMgr()->hide(myRecentMenuId);
1028 menuMgr()->hide(mySourcesMenuId);
1029 menuMgr()->hide(myFiltersMenuId);
1030 menuMgr()->hide(myMacrosMenuId);
1031 menuMgr()->hide(myToolbarsMenuId);
1032 setMenuShown( false );
1033 setToolShown( false );
1035 saveDockWidgetsState();
1037 SUIT_ExceptionHandler::removeCleanUpRoutine( paravisCleanUp );
1039 if (myOldMsgHandler)
1040 qInstallMsgHandler(myOldMsgHandler);
1042 restoreCommonWindowsState();
1044 return SalomeApp_Module::deactivateModule( study );
1049 \brief Called when application is closed.
1051 Process finalize application functionality from ParaView in order to save server settings
1052 and nullify application pointer if the application is being closed.
1054 \param theApp application
1056 void PVGUI_Module::onApplicationClosed( SUIT_Application* theApp )
1058 pqApplicationCore::instance()->settings()->sync();
1059 int aAppsNb = SUIT_Session::session()->applications().size();
1061 deleteTemporaryFiles();
1062 MyCoreApp->deleteLater();
1064 CAM_Module::onApplicationClosed(theApp);
1069 \brief Called when study is closed.
1071 Removes data model from the \a study.
1073 \param study study being closed
1075 void PVGUI_Module::studyClosed(SUIT_Study* study)
1077 clearParaviewState();
1079 SalomeApp_Module::studyClosed(study);
1083 \brief Called when study is opened.
1085 void PVGUI_Module::onModelOpened()
1087 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1092 _PTR(SComponent) paravisComp =
1093 studyDS->FindComponent(GetEngine()->ComponentDataType());
1098 _PTR(ChildIterator) anIter(studyDS->NewChildIterator(paravisComp));
1099 for (; anIter->More(); anIter->Next()) {
1100 _PTR(SObject) aSObj = anIter->Value();
1101 _PTR(GenericAttribute) anAttr;
1102 if (!aSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1105 _PTR(AttributeLocalID) anID(anAttr);
1106 if (anID->Value() == PVSTATEID) {
1113 \brief Returns IOR of current engine
1115 QString PVGUI_Module::engineIOR() const
1117 CORBA::String_var anIOR = GetEngine()->GetIOR();
1118 return QString(anIOR.in());
1123 \brief Open file of format supported by ParaView
1125 void PVGUI_Module::openFile(const char* theName)
1129 pqLoadDataReaction::loadData(aFiles);
1132 void PVGUI_Module::executeScript(const char *script)
1135 pqPythonManager* manager = qobject_cast<pqPythonManager*>(
1136 pqApplicationCore::instance()->manager("PYTHON_MANAGER"));
1138 pqPythonDialog* pyDiag = manager->pythonShellDialog();
1140 pyDiag->runString(script);
1147 // * Debug function printing out the given interpreter's execution context
1149 //void printInterpContext(PyInterp_Interp * interp )
1151 // // Extract __smtraceString from interpreter's context
1152 // const PyObject* ctxt = interp->getExecutionContext();
1154 // PyObject* lst = PyDict_Keys((PyObject *)ctxt);
1155 // Py_ssize_t siz = PyList_GET_SIZE(lst);
1156 // for (Py_ssize_t i = 0; i < siz; i++)
1158 // PyObject * elem = PyList_GetItem(lst, i);
1159 // if (PyString_Check(elem))
1161 // std::cout << "At pos:" << i << ", " << PyString_AsString(elem) << std::endl;
1164 // std::cout << "At pos:" << i << ", not a string!" << std::endl;
1170 \brief Returns trace string
1172 static const QString MYReplaceStr("paraview.simple");
1173 static const QString MYReplaceImportStr("except: from pvsimple import *");
1174 QString PVGUI_Module::getTraceString()
1176 QString traceString;
1179 PyLockWrapper lck; // Acquire GIL
1181 const char * code = "from paraview import smtrace;"
1182 "__smtraceString = smtrace.get_trace_string()";
1183 PyRun_SimpleString(code);
1184 // Now get the value of __smtraceString
1185 PyObject* main_module = PyImport_AddModule((char*)"__main__");
1186 PyObject* global_dict = PyModule_GetDict(main_module);
1187 PyObject* string_object = PyDict_GetItemString(global_dict, "__smtraceString");
1188 char* string_ptr = string_object ? PyString_AsString(string_object) : 0;
1190 traceString = string_ptr;
1194 if ((!traceString.isNull()) && traceString.length() != 0) {
1195 int aPos = traceString.indexOf(MYReplaceStr);
1196 while (aPos != -1) {
1197 traceString = traceString.replace(aPos, MYReplaceStr.length(), "pvsimple");
1198 aPos = traceString.indexOf(MYReplaceStr, aPos);
1200 int aImportPos = traceString.indexOf(MYReplaceImportStr);
1201 if(aImportPos != -1)
1203 traceString = traceString.replace(aImportPos, MYReplaceImportStr.length(), "except:\n import pvsimple\n from pvsimple import *");
1211 \brief Saves trace string to disk file
1213 void PVGUI_Module::saveTrace(const char* theName)
1215 QFile file(theName);
1216 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1217 MESSAGE( "Could not open file:" << theName );
1220 QTextStream out(&file);
1221 out << getTraceString();
1226 \brief Saves ParaView state to a disk file
1228 void PVGUI_Module::saveParaviewState(const char* theFileName)
1230 pqApplicationCore::instance()->saveState(theFileName);
1234 \brief Delete all objects for Paraview Pipeline Browser
1236 void PVGUI_Module::clearParaviewState()
1238 QAction* deleteAllAction = action(DeleteAllId);
1239 if (deleteAllAction) {
1240 deleteAllAction->activate(QAction::Trigger);
1245 \brief Restores ParaView state from a disk file
1247 If toClear == true, the current ojects will be deleted
1249 void PVGUI_Module::loadParaviewState(const char* theFileName)
1251 pqApplicationCore::instance()->loadState(theFileName, getActiveServer());
1255 \brief Deletes temporary files created during import operation from VISU
1257 void PVGUI_Module::deleteTemporaryFiles()
1259 foreach(QString aFile, myTemporaryFiles) {
1260 if (QFile::exists(aFile)) {
1261 QFile::remove(aFile);
1268 \brief Returns current active ParaView server
1270 pqServer* PVGUI_Module::getActiveServer()
1272 return pqApplicationCore::instance()->getActiveServer();
1277 \brief Creates PARAVIS preference pane
1279 void PVGUI_Module::createPreferences()
1281 // Paraview settings tab
1282 int aParaViewSettingsTab = addPreference( tr( "TIT_PVIEWSETTINGS" ) );
1283 int aPanel = addPreference(QString(), aParaViewSettingsTab, LightApp_Preferences::UserDefined, "PARAVIS", "");
1284 setPreferenceProperty(aPanel, "content", (qint64)(new PVGUI_ParaViewSettingsPane()));
1286 // Paravis settings tab
1287 int aParaVisSettingsTab = addPreference( tr( "TIT_PVISSETTINGS" ) );
1288 addPreference( tr( "PREF_STOP_TRACE" ), aParaVisSettingsTab, LightApp_Preferences::Bool, "PARAVIS", "stop_trace");
1290 int aSaveType = addPreference(tr( "PREF_SAVE_TYPE_LBL" ), aParaVisSettingsTab,
1291 LightApp_Preferences::Selector,
1292 "PARAVIS", "savestate_type");
1293 QList<QVariant> aIndices;
1294 QStringList aStrings;
1296 aStrings<<tr("PREF_SAVE_TYPE_0");
1297 aStrings<<tr("PREF_SAVE_TYPE_1");
1298 aStrings<<tr("PREF_SAVE_TYPE_2");
1299 setPreferenceProperty(aSaveType, "strings", aStrings);
1300 setPreferenceProperty(aSaveType, "indexes", aIndices);
1302 //rnv: imp 21712: [CEA 581] Preference to display legend by default
1303 int aDispColoreLegend = addPreference( tr( "PREF_SHOW_COLOR_LEGEND" ), aParaVisSettingsTab,
1304 LightApp_Preferences::Bool, "PARAVIS", "show_color_legend");
1308 \brief Creates ParaViS context menu popup
1310 void PVGUI_Module::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
1312 SalomeApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
1314 // Check if we are in Object Browser
1315 SUIT_DataBrowser* ob = getApp()->objectBrowser();
1316 bool isOBClient = (ob && theClient == ob->popupClientType());
1321 // Get list of selected objects
1322 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1323 SALOME_ListIO aListIO;
1324 aSelectionMgr->selectedObjects(aListIO);
1325 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1326 QString entry = QString(aListIO.First()->getEntry());
1329 SalomeApp_Study* activeStudy =
1330 dynamic_cast<SalomeApp_Study*>(getApp()->activeStudy());
1335 // Get SALOMEDS client study
1336 _PTR(Study) studyDS = activeStudy->studyDS();
1341 QString paravisDataType(GetEngine()->ComponentDataType());
1342 if(activeStudy && activeStudy->isComponent(entry) &&
1343 activeStudy->componentDataType(entry) == paravisDataType) {
1344 // ParaViS module object
1345 theMenu->addSeparator();
1346 theMenu->addAction(action(SaveStatePopupId));
1349 // Try to get state object
1350 _PTR(SObject) stateSObj =
1351 studyDS->FindObjectID(entry.toLatin1().constData());
1357 _PTR(GenericAttribute) anAttr;
1358 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1362 _PTR(AttributeLocalID) anID(anAttr);
1364 if (anID->Value() == PVSTATEID) {
1365 // Paraview state object
1366 theMenu->addSeparator();
1367 theMenu->addAction(action(AddStatePopupId));
1368 theMenu->addAction(action(CleanAndAddStatePopupId));
1369 theMenu->addSeparator();
1370 theMenu->addAction(action(ParaVisRenameId));
1371 theMenu->addAction(action(ParaVisDeleteId));
1378 \brief. Show ParaView python trace.
1380 void PVGUI_Module::onShowTrace()
1382 if (!myTraceWindow) {
1383 myTraceWindow = new pqPythonScriptEditor(getApp()->desktop());
1385 myTraceWindow->setText(getTraceString());
1386 myTraceWindow->show();
1387 myTraceWindow->raise();
1388 myTraceWindow->activateWindow();
1393 \brief. Re-initialize ParaView python trace.
1395 void PVGUI_Module::onRestartTrace()
1397 QString script = "from paraview import smtrace\n";
1398 script += "smtrace.stop_trace()\n";
1399 script += "smtrace.start_trace()\n";
1400 execPythonCommand(script, false);
1404 \brief Show ParaView view.
1406 void PVGUI_Module::onNewParaViewWindow()
1412 \brief Save state under the module root object.
1414 void PVGUI_Module::onSaveMultiState()
1416 // Create state study object
1418 // Get SALOMEDS client study
1419 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1424 _PTR(SComponent) paravisComp =
1425 studyDS->FindComponent(GetEngine()->ComponentDataType());
1430 // Unlock the study if it is locked
1431 bool isLocked = studyDS->GetProperties()->IsLocked();
1433 studyDS->GetProperties()->SetLocked(false);
1436 QString stateName = tr("SAVED_PARAVIEW_STATE_NAME") +
1437 QString::number(myStateCounter + 1);
1439 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1440 _PTR(SObject) newSObj = studyBuilder->NewObject(paravisComp);
1443 _PTR(GenericAttribute) anAttr;
1444 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeName");
1445 _PTR(AttributeName) nameAttr(anAttr);
1447 nameAttr->SetValue(stateName.toLatin1().constData());
1450 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeLocalID");
1451 _PTR(AttributeLocalID) localIdAttr(anAttr);
1453 localIdAttr->SetValue(PVSTATEID);
1456 QString stateEntry = QString::fromStdString(newSObj->GetID());
1458 // File name for state saving
1459 QString tmpDir = QString::fromStdString(SALOMEDS_Tool::GetTmpDir());
1460 QString fileName = QString("%1_paravisstate:%2").arg(tmpDir, stateEntry);
1462 anAttr = studyBuilder->FindOrCreateAttribute(newSObj, "AttributeString");
1463 _PTR(AttributeString) stringAttr(anAttr);
1465 stringAttr->SetValue(fileName.toLatin1().constData());
1467 // Lock the study back if necessary
1469 studyDS->GetProperties()->SetLocked(true);
1473 saveParaviewState(fileName.toLatin1().constData());
1474 myTemporaryFiles.append(fileName);
1476 // Increment the counter
1483 \brief Restore the selected state by merging with the current one.
1485 void PVGUI_Module::onAddState()
1487 loadSelectedState(false);
1491 \brief Clean the current state and restore the selected one.
1493 void PVGUI_Module::onCleanAddState()
1495 loadSelectedState(true);
1499 \brief Rename the selected object.
1501 void PVGUI_Module::onRename()
1503 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1504 SALOME_ListIO aListIO;
1505 aSelectionMgr->selectedObjects(aListIO);
1507 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1508 std::string entry = aListIO.First()->getEntry();
1510 // Get SALOMEDS client study
1511 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1516 // Unlock the study if it is locked
1517 bool isLocked = studyDS->GetProperties()->IsLocked();
1519 studyDS->GetProperties()->SetLocked(false);
1522 // Rename the selected state object
1523 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1528 _PTR(GenericAttribute) anAttr;
1529 if (stateSObj->FindAttribute(anAttr, "AttributeName")) {
1530 _PTR(AttributeName) nameAttr (anAttr);
1532 LightApp_NameDlg::getName(getApp()->desktop(), nameAttr->Value().c_str());
1533 if (!newName.isEmpty()) {
1534 nameAttr->SetValue(newName.toLatin1().constData());
1535 aListIO.First()->setName(newName.toLatin1().constData());
1539 // Lock the study back if necessary
1541 studyDS->GetProperties()->SetLocked(true);
1544 // Update object browser
1551 \brief Delete the selected objects.
1553 void PVGUI_Module::onDelete()
1555 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1556 SALOME_ListIO aListIO;
1557 aSelectionMgr->selectedObjects(aListIO);
1559 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1560 std::string entry = aListIO.First()->getEntry();
1562 // Get SALOMEDS client study
1563 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1568 // Unlock the study if it is locked
1569 bool isLocked = studyDS->GetProperties()->IsLocked();
1571 studyDS->GetProperties()->SetLocked(false);
1574 // Remove the selected state from the study
1575 _PTR(StudyBuilder) studyBuilder = studyDS->NewBuilder();
1576 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1577 studyBuilder->RemoveObject(stateSObj);
1579 // Lock the study back if necessary
1581 studyDS->GetProperties()->SetLocked(true);
1584 // Update object browser
1589 void PVGUI_Module::onPushTraceTimer()
1591 //MESSAGE("Pushing trace ...");
1592 GetEngine()->PutPythonTraceStringToEngine(getTraceString().toStdString().c_str());
1596 \brief Discover help project files from the resources.
1597 \return name of the help file.
1599 QString PVGUI_Module::getHelpFileName() {
1600 QString aPVHome(getenv("PVHOME"));
1601 if (aPVHome.isNull()) {
1602 qWarning("Wariable PVHOME is not defined");
1605 QChar aSep = QDir::separator();
1606 //PARAVIEW_VERSION from the vtkPVConfig.h file
1607 QString aFileName = aPVHome + aSep + "share" + aSep + "doc" + aSep + "paraview-"+ PARAVIEW_VERSION + aSep + "paraview.qch";
1613 \brief Load selected paraview state
1615 If toClear == true, the current state will be cleared
1617 void PVGUI_Module::loadSelectedState(bool toClear)
1621 LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
1622 SALOME_ListIO aListIO;
1623 aSelectionMgr->selectedObjects(aListIO);
1625 if (aListIO.Extent() == 1 && aListIO.First()->hasEntry()) {
1626 std::string entry = aListIO.First()->getEntry();
1628 // Get SALOMEDS client study
1629 _PTR(Study) studyDS = PARAVIS::GetCStudy(this);
1635 _PTR(SObject) stateSObj = studyDS->FindObjectID(entry);
1636 _PTR(GenericAttribute) anAttr;
1637 if (!stateSObj->FindAttribute(anAttr, "AttributeLocalID")) {
1640 _PTR(AttributeLocalID) anID(anAttr);
1641 if (!anID->Value() == PVSTATEID) {
1645 // Get state file name
1646 if (stateSObj->FindAttribute(anAttr, "AttributeString")) {
1647 _PTR(AttributeString) aStringAttr(anAttr);
1648 QString stringValue(aStringAttr->Value().c_str());
1650 if (QFile::exists(stringValue)) {
1651 fileName = stringValue;
1656 if (!fileName.isEmpty()) {
1658 clearParaviewState();
1661 loadParaviewState(fileName.toLatin1().constData());
1664 SUIT_MessageBox::critical(getApp()->desktop(),
1666 tr("ERR_STATE_CANNOT_BE_RESTORED"));
1670 void PVGUI_Module::onRepresentationChanged(pqRepresentation*) {
1673 //rnv: to fix the issue "21712: [CEA 581] Preference to display legend by default"
1674 // find the pqDisplayColorWidget instances and connect the variableChanged SIGNAL on the
1675 // onVariableChanged slot of this class. This connection needs to change visibility
1676 // of the "Colored Legend" after change the "Color By" array.
1677 QList<pqDisplayColorWidget*> aWidget = getApp()->desktop()->findChildren<pqDisplayColorWidget*>();
1679 for (int i = 0; i < aWidget.size() ; i++ ) {
1681 connect( aWidget[i], SIGNAL ( variableChanged ( pqVariableType, const QString ) ),
1682 this, SLOT(onVariableChanged( pqVariableType, const QString) ), Qt::UniqueConnection );
1689 \fn CAM_Module* createModule();
1690 \brief Export module instance (factory function).
1691 \return new created instance of the module
1695 #define PVGUI_EXPORT __declspec(dllexport)
1697 #define PVGUI_EXPORT
1703 PVGUI_EXPORT CAM_Module* createModule() {
1708 return new PVGUI_Module();
1711 PVGUI_EXPORT char* getModuleVersion() {
1712 return (char*)PARAVIS_VERSION_STR;