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 "MEDPresentationScalarMap.hxx"
31 #include "MEDPresentationContour.hxx"
33 #include "MEDWidgetHelperScalarMap.hxx"
34 #include "MEDWidgetHelperContour.hxx"
36 #include <SalomeApp_Application.h>
37 #include <SalomeApp_Study.h>
38 #include <SalomeApp_DataObject.h>
40 #include <SALOMEDS_SObject.hxx>
41 #include <SALOMEDS_Study.hxx>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <QMessageBox>
49 #include "MEDFactoryClient.hxx"
51 static const int OPTIONS_VIEW_MODE_ID = 943;
52 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
53 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
54 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
55 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
57 //! The only instance of the MEDPresentationManager
58 MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
60 PresentationController::PresentationController(MEDModule* salomeModule) :
61 _salomeModule(salomeModule),
63 _studyEditor(salomeModule->getStudyEditor()),
65 _currentWidgetHelper(0)
67 STDLOG("Creating a PresentationController");
69 _widgetPresentationParameters = new WidgetPresentationParameters();
71 QMainWindow* parent = salomeModule->getApp()->desktop();
72 _dockWidget = new QDockWidget(parent);
73 _dockWidget->setVisible(false);
74 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
75 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
76 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
77 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
78 _dockWidget->setWidget(_widgetPresentationParameters);
79 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
80 //_dockWidget->show();
82 // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
83 if ( ! _presManager ) {
84 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
87 // Connect to the click in the object browser
88 connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
89 this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
92 PresentationController::~PresentationController()
94 STDLOG("Deleting the resentationController");
95 // Clean allocated widget helpers:
96 for ( std::map<int, MEDWidgetHelper *>::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
101 * [ABN] Created this probably because I don't know the right way to deal with non existent
102 * attributes in an object from the study ...
105 PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name)
109 theInt = _studyEditor->getParameterInt(obj,name);
116 PresentationController::_getIconName(const std::string& name)
118 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
122 // Read value from preferences and suffix name to select icon theme
123 int theme = mgr->integerValue("MEDCalc", "icons");
125 return name + "_MODERN";
126 } else if (theme == 1) {
127 return name + "_CLASSIC";
129 return name + "_DEFAULT";
133 PresentationController::createActions()
135 STDLOG("Creating PresentationController actions");
138 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
139 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
140 ag->setText("View mode");
141 ag->setUsesDropDown(true);
142 QString label = tr("LAB_VIEW_MODE_REPLACE");
143 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
144 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
145 a->setCheckable(true);
149 label = tr("LAB_VIEW_MODE_OVERLAP");
150 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
151 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
152 a->setCheckable(true);
155 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
156 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
157 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
158 a->setCheckable(true);
161 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
162 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
163 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
164 a->setCheckable(true);
167 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
170 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
171 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
173 label = tr("LAB_PRESENTATION_SCALAR_MAP");
174 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
175 QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
177 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip);
178 _salomeModule->createTool(actionId, presentationToolbarId);
179 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
180 _salomeModule->createMenu(actionId, presentationMenuId);
182 label = tr("LAB_PRESENTATION_CONTOUR");
183 tooltip = tr("TIP_PRESENTATION_CONTOUR");
184 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
185 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
186 _salomeModule->createTool(actionId, presentationToolbarId);
187 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
188 _salomeModule->createMenu(actionId, presentationMenuId);
190 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
191 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
192 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
193 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
194 _salomeModule->createTool(actionId, presentationToolbarId);
195 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
196 _salomeModule->createMenu(actionId, presentationMenuId);
198 label = tr("LAB_PRESENTATION_SLICES");
199 tooltip = tr("TIP_PRESENTATION_SLICES");
200 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
201 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
202 _salomeModule->createTool(actionId, presentationToolbarId);
203 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
204 _salomeModule->createMenu(actionId, presentationMenuId);
206 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
207 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
208 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
209 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
210 _salomeModule->createTool(actionId, presentationToolbarId);
211 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
212 _salomeModule->createMenu(actionId, presentationMenuId);
214 label = tr("LAB_PRESENTATION_POINT_SPRITE");
215 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
216 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
217 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
218 _salomeModule->createTool(actionId, presentationToolbarId);
219 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
220 _salomeModule->createMenu(actionId, presentationMenuId);
223 _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
225 label = tr("LAB_DELETE_PRESENTATION");
226 tooltip = tr("TIP_DELETE_PRESENTATION");
227 icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
228 actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
229 // _salomeModule->createTool(actionId, presentationToolbarId);
230 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
231 _salomeModule->createMenu(actionId, presentationMenuId);
234 // Actions for popup menu only
236 // Low level PARAVIS dump
237 label = tr("LAB_PARAVIS_DUMP");
238 //icon = tr("ICO_DATASOURCE_EXPAND_FIELD");
239 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
240 _salomeModule->addActionInPopupMenu(actionId);
245 MEDCALC::MEDPresentationViewMode
246 PresentationController::getSelectedViewMode() const
248 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
249 return MEDCALC::VIEW_MODE_REPLACE;
251 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
252 return MEDCALC::VIEW_MODE_OVERLAP;
254 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
255 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
257 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
258 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
261 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
262 return MEDCALC::VIEW_MODE_REPLACE;
265 MEDCALC::MEDPresentationColorMap
266 PresentationController::getSelectedColorMap() const
268 return _widgetPresentationParameters->getColorMap();
271 MEDCALC::MEDPresentationScalarBarRange
272 PresentationController::getSelectedScalarBarRange() const
274 return _widgetPresentationParameters->getScalarBarRange();
278 PresentationController::visualize(PresentationEvent::EventType eventType)
280 // We need a _studyEditor updated on the active study
281 _studyEditor->updateActiveStudy();
283 // Get the selected objects in the study (SObject)
284 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
286 // For each object, emit a signal to the workspace to request a
287 // visualisation using the tui command (so that the user can see how
288 // to make a view of an object from the tui console).
289 for (int i=0; i<listOfSObject->size(); i++) {
290 SALOMEDS::SObject_var soField = listOfSObject->at(i);
291 int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
292 if (fieldId < 0) // is it a field serie ?
294 int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
295 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
296 // managed by the MED module, and we stop this function process.
297 if ( fieldSeriesId < 0)
299 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
300 if (fieldHandlerList->length() < 0)
302 // For a field series, get the first real field entry:
303 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
304 fieldId = fieldHandler.id;
307 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
308 if (! fieldHandler) {
309 QMessageBox::warning(_salomeModule->getApp()->desktop(),
310 tr("Operation not allowed"),
311 tr("No field is defined"));
315 PresentationEvent* event = new PresentationEvent();
316 event->eventtype = eventType;
317 event->fieldHandler = fieldHandler;
318 emit presentationSignal(event); // --> processPresentationEvent()
323 PresentationController::onVisualizeScalarMap()
325 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
329 PresentationController::onVisualizeContour()
331 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
335 PresentationController::onVisualizeVectorField()
337 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
341 PresentationController::onVisualizeSlices()
343 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
347 PresentationController::onVisualizeDeflectionShape()
349 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
353 PresentationController::onVisualizePointSprite()
355 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
359 PresentationController::onDeletePresentation()
361 // We need a _studyEditor updated on the active study
362 _studyEditor->updateActiveStudy();
364 // Get the selected objects in the study (SObject)
365 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
367 // For each object, emit a signal to the workspace to request pres deletion
368 for (int i=0; i<listOfSObject->size(); i++) {
369 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
370 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
371 // If fieldId equals -1, then it means that it is not a field
372 // managed by the MED module, and we stop this function process.
376 PresentationEvent* event = new PresentationEvent();
377 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
378 event->presentationId = presId;
379 emit presentationSignal(event); // --> processPresentationEvent()
384 PresentationController::getViewModePython() const
386 MEDCALC::MEDPresentationViewMode viewMode = getSelectedViewMode();
388 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
389 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
390 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
391 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
397 PresentationController::getColorMapPython() const
399 MEDCALC::MEDPresentationColorMap colorMap = getSelectedColorMap();
401 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
402 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
408 PresentationController::getScalarBarRangePython() const
410 MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange();
412 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
413 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
419 PresentationController::getPresTypeFromWidgetHelper(int presId) const
421 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
422 if (it != _presHelperMap.end())
423 return (*it).second->getPythonTag();
428 PresentationController::processPresentationEvent(const PresentationEvent* event) {
429 // --> Send commands to SALOME Python console
430 QString viewMode = getViewModePython();
431 QString colorMap = getColorMapPython();
432 QString scalarBarRange = getScalarBarRangePython();
433 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
434 QStringList commands;
435 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
436 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
437 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
438 commands += QString("presentation_id");
440 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
441 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
442 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
443 commands += QString("presentation_id");
445 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
446 // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
447 // commands += QString("presentation_id");
449 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
450 // commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
451 // commands += QString("presentation_id");
453 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
454 // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
455 // commands += QString("presentation_id");
457 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
458 // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
459 // commands += QString("presentation_id");
462 // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each
463 // dedicated widget helper class?
464 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
465 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
466 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
467 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
468 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
470 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
471 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
472 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
473 commands += QString("params.colorMap = %1").arg(getColorMapPython());
474 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
476 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
477 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
478 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
479 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
480 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
482 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
483 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
484 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
485 commands += QString("params.nbContours = %1").arg(event->anInteger);
486 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
488 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
489 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
492 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
494 _consoleDriver->exec(commands);
498 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
499 int presId, const std::string& type, const std::string& name )
501 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
502 if (it != _presHelperMap.end())
504 MEDWidgetHelper * wh;
505 if (type == MEDPresentationScalarMap::TYPE_NAME)
506 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
507 else if (type == MEDPresentationContour::TYPE_NAME)
508 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
511 // case PRES_CONTOUR:
513 // case PRES_DEFLECTION:
515 // case PRES_VECTOR_FIELD:
517 // case PRES_POINT_SPRITE:
519 // case PRES_POINT_SPRITE:
522 STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
525 _presHelperMap[presId] = wh;
530 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
534 if (_widgetPresentationParameters->isShown())
536 _widgetPresentationParameters->toggleWidget(false);
537 if(_currentWidgetHelper)
538 _currentWidgetHelper->releaseWidget();
543 // Activate corresponding ParaView render view
544 _presManager->activateView(presId);
545 // Update widgets parameters
546 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
547 _currentWidgetHelper->udpateWidget();
552 PresentationController::onParavisDump()
554 // We need a _studyEditor updated on the active study
555 _studyEditor->updateActiveStudy();
557 // Get the selected objects in the study (SObject)
558 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
560 // For the first object only, request the dump
561 for (int i=0; i<listOfSObject->size(); i++) {
562 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
563 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
564 // If fieldId equals -1, then it means that it is not a field
565 // managed by the MED module, and we stop this function process.
569 std::string dump(_presManager->getParavisDump(presId));
570 std::cerr << "#====== ParaVis dump =============== " << std::endl;
572 std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
574 break; // stop at the first one
579 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
581 if (presentationId < 0) {
582 std::cerr << "Unknown presentation\n";
586 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
587 std::string type = name;
588 std::string icon = std::string("ICO_") + type;
589 icon = _getIconName(icon);
590 std::string ico = tr(icon.c_str()).toStdString();
592 // Append presentation ID to the displayed name in the OB:
593 std::ostringstream oss;
594 name = tr(name.c_str()).toStdString();
595 oss << name << " (" << presentationId << ")";
597 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
598 _PTR(Study) studyDS = study->studyDS();
600 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId,
601 oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
604 // MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
606 // // Remove sibling presentations if view mode is set to REPLACE
607 // if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
608 // MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
609 // CORBA::ULong size = presList->length();
611 // std::stringstream sstm;
612 // sstm << "Removing sibling presentation(s): ";
613 // for (int i = 0; i < size; ++i)
614 // sstm << (*presList)[i] << " ";
615 // STDLOG(sstm.str());
617 // for (int i = 0; i < size; ++i) {
618 // PresentationEvent* event = new PresentationEvent();
619 // event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
620 // XmedDataObject* dataObject = new XmedDataObject();
621 // dataObject->setPresentationId((*presList)[i]);
622 // event->objectdata = dataObject;
623 // emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
629 // update Object browser
630 _salomeModule->getApp()->updateObjectBrowser(true);
634 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
636 if (presentationId < 0) {
637 std::cerr << "Unknown presentation\n";
641 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
642 _PTR(Study) studyDS = study->studyDS();
644 _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
646 // update Object browser
647 _salomeModule->getApp()->updateObjectBrowser(true);
651 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
653 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
654 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
655 // Deal with replace mode: presentations with invalid IDs have to be removed:
656 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
657 _PTR(Study) studyDS = study->studyDS();
659 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
660 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations(_CAST(Study, studyDS)->GetStudy());
661 // The IDs not in the intersection needs deletion:
662 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
663 for (unsigned i = 0; i < lstModule->length(); i++)
665 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
668 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
669 // Presentation in module but not in manager anymore: to be deleted from OB:
670 updateTreeViewForPresentationRemoval((*lstModule)[i]);
674 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
675 updateTreeViewForPresentationRemoval(event->presentationId);
680 PresentationController::showDockWidgets(bool isVisible)
682 _dockWidget->setVisible(isVisible);