1 // Copyright (C) 2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PresentationController.hxx"
21 #include <MEDCalcConstants.hxx>
22 #include "MEDModule.hxx"
23 #include "Basics_Utils.hxx"
24 #include "QtxActionGroup.h"
25 #include "QtxActionToolMgr.h"
26 #include "MEDFactoryClient.hxx"
27 #include "MEDPresentationManager_i.hxx"
28 #include "XmedConsoleDriver.hxx"
30 #include "MEDWidgetHelperScalarMap.hxx"
31 #include "MEDPresentationScalarMap.hxx"
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_DataObject.h>
37 #include <SALOMEDS_SObject.hxx>
38 #include <SALOMEDS_Study.hxx>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <QMessageBox>
46 #include "MEDFactoryClient.hxx"
48 static const int OPTIONS_VIEW_MODE_ID = 943;
49 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
50 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
51 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
52 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
54 //! The only instance of the MEDPresentationManager
55 MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
57 PresentationController::PresentationController(MEDModule* salomeModule) :
58 _salomeModule(salomeModule),
60 _studyEditor(salomeModule->getStudyEditor()),
62 _currentWidgetHelper(0)
64 STDLOG("Creating a PresentationController");
66 _widgetPresentationParameters = new WidgetPresentationParameters();
68 QMainWindow* parent = salomeModule->getApp()->desktop();
69 _dockWidget = new QDockWidget(parent);
70 _dockWidget->setVisible(false);
71 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
72 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
73 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
74 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
75 _dockWidget->setWidget(_widgetPresentationParameters);
76 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
77 //_dockWidget->show();
79 // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
80 if ( ! _presManager ) {
81 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
84 // Connect to the click in the object browser
85 connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
86 this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
89 PresentationController::~PresentationController()
91 STDLOG("Deleting the resentationController");
92 // Clean allocated widget helpers:
93 for ( std::map<int, MEDWidgetHelper *>::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
98 * [ABN] Created this probably because I don't know the right way to deal with non existent
99 * attributes in an object from the study ...
102 PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name)
106 theInt = _studyEditor->getParameterInt(obj,name);
113 PresentationController::_getIconName(const std::string& name)
115 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
119 // Read value from preferences and suffix name to select icon theme
120 int theme = mgr->integerValue("MEDCalc", "icons");
122 return name + "_MODERN";
123 } else if (theme == 1) {
124 return name + "_CLASSIC";
126 return name + "_DEFAULT";
130 PresentationController::createActions()
132 STDLOG("Creating PresentationController actions");
135 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
136 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
137 ag->setText("View mode");
138 ag->setUsesDropDown(true);
139 QString label = tr("LAB_VIEW_MODE_REPLACE");
140 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
141 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
142 a->setCheckable(true);
146 label = tr("LAB_VIEW_MODE_OVERLAP");
147 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
148 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
149 a->setCheckable(true);
152 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
153 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
154 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
155 a->setCheckable(true);
158 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
159 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
160 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
161 a->setCheckable(true);
164 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
167 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
168 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
170 label = tr("LAB_PRESENTATION_SCALAR_MAP");
171 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
172 QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
174 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip);
175 _salomeModule->createTool(actionId, presentationToolbarId);
176 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
177 _salomeModule->createMenu(actionId, presentationMenuId);
179 label = tr("LAB_PRESENTATION_CONTOUR");
180 tooltip = tr("TIP_PRESENTATION_CONTOUR");
181 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
182 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
183 _salomeModule->createTool(actionId, presentationToolbarId);
184 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
185 _salomeModule->createMenu(actionId, presentationMenuId);
187 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
188 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
189 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
190 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
191 _salomeModule->createTool(actionId, presentationToolbarId);
192 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
193 _salomeModule->createMenu(actionId, presentationMenuId);
195 label = tr("LAB_PRESENTATION_SLICES");
196 tooltip = tr("TIP_PRESENTATION_SLICES");
197 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
198 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
199 _salomeModule->createTool(actionId, presentationToolbarId);
200 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
201 _salomeModule->createMenu(actionId, presentationMenuId);
203 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
204 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
205 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
206 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
207 _salomeModule->createTool(actionId, presentationToolbarId);
208 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
209 _salomeModule->createMenu(actionId, presentationMenuId);
211 label = tr("LAB_PRESENTATION_POINT_SPRITE");
212 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
213 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
214 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
215 _salomeModule->createTool(actionId, presentationToolbarId);
216 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
217 _salomeModule->createMenu(actionId, presentationMenuId);
220 _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
222 label = tr("LAB_DELETE_PRESENTATION");
223 tooltip = tr("TIP_DELETE_PRESENTATION");
224 icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
225 actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
226 // _salomeModule->createTool(actionId, presentationToolbarId);
227 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
228 _salomeModule->createMenu(actionId, presentationMenuId);
231 // Actions for popup menu only
233 // Low level PARAVIS dump
234 label = tr("LAB_PARAVIS_DUMP");
235 //icon = tr("ICO_DATASOURCE_EXPAND_FIELD");
236 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
237 _salomeModule->addActionInPopupMenu(actionId);
242 MEDCALC::MEDPresentationViewMode
243 PresentationController::getSelectedViewMode() const
245 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
246 return MEDCALC::VIEW_MODE_REPLACE;
248 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
249 return MEDCALC::VIEW_MODE_OVERLAP;
251 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
252 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
254 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
255 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
258 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
259 return MEDCALC::VIEW_MODE_REPLACE;
262 MEDCALC::MEDPresentationColorMap
263 PresentationController::getSelectedColorMap() const
265 return _widgetPresentationParameters->getColorMap();
268 MEDCALC::MEDPresentationScalarBarRange
269 PresentationController::getSelectedScalarBarRange() const
271 return _widgetPresentationParameters->getScalarBarRange();
275 PresentationController::visualize(PresentationEvent::EventType eventType)
277 // We need a _studyEditor updated on the active study
278 _studyEditor->updateActiveStudy();
280 // Get the selected objects in the study (SObject)
281 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
283 // For each object, emit a signal to the workspace to request a
284 // visualisation using the tui command (so that the user can see how
285 // to make a view of an object from the tui console).
286 for (int i=0; i<listOfSObject->size(); i++) {
287 SALOMEDS::SObject_var soField = listOfSObject->at(i);
288 int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
289 if (fieldId < 0) // is it a field serie ?
291 int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
292 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
293 // managed by the MED module, and we stop this function process.
294 if ( fieldSeriesId < 0)
296 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
297 if (fieldHandlerList->length() < 0)
299 // For a field series, get the first real field entry:
300 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
301 fieldId = fieldHandler.id;
304 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
305 if (! fieldHandler) {
306 QMessageBox::warning(_salomeModule->getApp()->desktop(),
307 tr("Operation not allowed"),
308 tr("No field is defined"));
312 PresentationEvent* event = new PresentationEvent();
313 event->eventtype = eventType;
314 event->fieldHandler = fieldHandler;
315 emit presentationSignal(event); // --> processPresentationEvent()
320 PresentationController::onVisualizeScalarMap()
322 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
326 PresentationController::onVisualizeContour()
328 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
332 PresentationController::onVisualizeVectorField()
334 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
338 PresentationController::onVisualizeSlices()
340 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
344 PresentationController::onVisualizeDeflectionShape()
346 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
350 PresentationController::onVisualizePointSprite()
352 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
356 PresentationController::onDeletePresentation()
358 // We need a _studyEditor updated on the active study
359 _studyEditor->updateActiveStudy();
361 // Get the selected objects in the study (SObject)
362 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
364 // For each object, emit a signal to the workspace to request pres deletion
365 for (int i=0; i<listOfSObject->size(); i++) {
366 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
367 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
368 // If fieldId equals -1, then it means that it is not a field
369 // managed by the MED module, and we stop this function process.
373 PresentationEvent* event = new PresentationEvent();
374 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
375 event->presentationId = presId;
376 emit presentationSignal(event); // --> processPresentationEvent()
381 PresentationController::getViewModePython() const
383 MEDCALC::MEDPresentationViewMode viewMode = getSelectedViewMode();
385 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
386 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
387 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
388 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
394 PresentationController::getColorMapPython() const
396 MEDCALC::MEDPresentationColorMap colorMap = getSelectedColorMap();
398 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
399 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
405 PresentationController::getScalarBarRangePython() const
407 MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange();
409 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
410 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
416 PresentationController::getPresTypeFromWidgetHelper(int presId) const
418 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
419 if (it != _presHelperMap.end())
420 return (*it).second->getPythonTag();
425 PresentationController::processPresentationEvent(const PresentationEvent* event) {
426 // --> Send commands to SALOME Python console
427 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
428 QString viewMode = getViewModePython();
429 //QString displayedComponent = ; // from PresentationController combobox
430 //QString scalarBarRange = ; // from PresentationController spinbox
431 QString colorMap = getColorMapPython();
432 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
433 QStringList commands;
434 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap);
435 commands += QString("presentation_id");
436 _consoleDriver->exec(commands);
438 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
439 // QString viewMode = getViewModePython();
440 // MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
441 // QStringList commands;
442 // commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
443 // commands += QString("presentation_id");
444 // _consoleDriver->exec(commands);
446 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
447 // QString viewMode = getViewModePython();
448 // MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
449 // QStringList commands;
450 // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
451 // commands += QString("presentation_id");
452 // _consoleDriver->exec(commands);
454 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
455 // QString viewMode = getViewModePython();
456 // MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
457 // QStringList commands;
458 // commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
459 // commands += QString("presentation_id");
460 // _consoleDriver->exec(commands);
462 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
463 // QString viewMode = getViewModePython();
464 // MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
465 // QStringList commands;
466 // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
467 // commands += QString("presentation_id");
468 // _consoleDriver->exec(commands);
470 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
471 // QString viewMode = getViewModePython();
472 // MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
473 // QStringList commands;
474 // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
475 // commands += QString("presentation_id");
476 // _consoleDriver->exec(commands);
479 // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each
480 // dedicated widget helper class?
481 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
482 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
483 QStringList commands;
484 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
485 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
486 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
487 _consoleDriver->exec(commands);
489 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
490 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
491 QStringList commands;
492 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
493 commands += QString("params.colorMap = %1").arg(getColorMapPython());
494 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
495 _consoleDriver->exec(commands);
497 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
498 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
499 QStringList commands;
500 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
501 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
502 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
503 _consoleDriver->exec(commands);
505 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
506 QStringList commands;
507 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
508 _consoleDriver->exec(commands);
511 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
516 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
517 int presId, const std::string& type, const std::string& name )
519 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
520 if (it != _presHelperMap.end())
522 MEDWidgetHelper * wh;
523 if (type == MEDPresentationScalarMap::TYPE_NAME)
524 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
527 // case PRES_CONTOUR:
529 // case PRES_DEFLECTION:
531 // case PRES_VECTOR_FIELD:
533 // case PRES_POINT_SPRITE:
535 // case PRES_POINT_SPRITE:
538 STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
541 _presHelperMap[presId] = wh;
546 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
550 if (_widgetPresentationParameters->isShown())
552 _widgetPresentationParameters->toggleWidget(false);
553 if(_currentWidgetHelper)
554 _currentWidgetHelper->releaseWidget();
559 // Activate corresponding ParaView render view
560 _presManager->activateView(presId);
561 // Update widgets parameters
562 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
563 _currentWidgetHelper->udpateWidget();
568 PresentationController::onParavisDump()
570 // We need a _studyEditor updated on the active study
571 _studyEditor->updateActiveStudy();
573 // Get the selected objects in the study (SObject)
574 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
576 // For the first object only, request the dump
577 for (int i=0; i<listOfSObject->size(); i++) {
578 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
579 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
580 // If fieldId equals -1, then it means that it is not a field
581 // managed by the MED module, and we stop this function process.
585 std::string dump(_presManager->getParavisDump(presId));
586 std::cerr << "#====== ParaVis dump =============== " << std::endl;
588 std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
590 break; // stop at the first one
595 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
597 if (presentationId < 0) {
598 std::cerr << "Unknown presentation\n";
602 std::string name(MEDFactoryClient::getPresentationManager()->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
603 std::string type = name;
604 std::string icon = std::string("ICO_") + type;
605 icon = _getIconName(icon);
606 std::string ico = tr(icon.c_str()).toStdString();
608 // Append presentation ID to the displayed name in the OB:
609 std::ostringstream oss;
610 name = tr(name.c_str()).toStdString();
611 oss << name << " (" << presentationId << ")";
613 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
614 _PTR(Study) studyDS = study->studyDS();
616 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId,
617 oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
620 MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
622 // Remove sibling presentations if view mode is set to REPLACE
623 if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
624 MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
625 CORBA::ULong size = presList->length();
627 std::stringstream sstm;
628 sstm << "Removing sibling presentation(s): ";
629 for (int i = 0; i < size; ++i)
630 sstm << (*presList)[i] << " ";
633 for (int i = 0; i < size; ++i) {
634 PresentationEvent* event = new PresentationEvent();
635 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
636 XmedDataObject* dataObject = new XmedDataObject();
637 dataObject->setPresentationId((*presList)[i]);
638 event->objectdata = dataObject;
639 emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
645 // update Object browser
646 _salomeModule->getApp()->updateObjectBrowser(true);
650 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
652 if (presentationId < 0) {
653 std::cerr << "Unknown presentation\n";
657 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
658 _PTR(Study) studyDS = study->studyDS();
660 _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
662 // update Object browser
663 _salomeModule->getApp()->updateObjectBrowser(true);
667 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
669 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
670 this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
672 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
673 this->updateTreeViewForPresentationRemoval(event->presentationId);
678 PresentationController::showDockWidgets(bool isVisible)
680 _dockWidget->setVisible(isVisible);