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 "MEDPresentationMeshView.hxx"
31 #include "MEDPresentationScalarMap.hxx"
32 #include "MEDPresentationContour.hxx"
33 #include "MEDPresentationSlices.hxx"
35 #include "MEDWidgetHelperMeshView.hxx"
36 #include "MEDWidgetHelperScalarMap.hxx"
37 #include "MEDWidgetHelperContour.hxx"
38 #include "MEDWidgetHelperSlices.hxx"
40 #include <SalomeApp_Application.h>
41 #include <SalomeApp_Study.h>
42 #include <SalomeApp_DataObject.h>
44 #include <SALOMEDS_SObject.hxx>
45 #include <SALOMEDS_Study.hxx>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <QMessageBox>
53 #include "MEDFactoryClient.hxx"
55 static const int OPTIONS_VIEW_MODE_ID = 943;
56 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
57 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
58 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
59 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
61 //! The only instance of the MEDPresentationManager
62 MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
64 PresentationController::PresentationController(MEDModule* salomeModule) :
65 _salomeModule(salomeModule),
67 _studyEditor(salomeModule->getStudyEditor()),
69 _currentWidgetHelper(0)
71 STDLOG("Creating a PresentationController");
73 _widgetPresentationParameters = new WidgetPresentationParameters();
75 QMainWindow* parent = salomeModule->getApp()->desktop();
76 _dockWidget = new QDockWidget(parent);
77 _dockWidget->setVisible(false);
78 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
79 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
80 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
81 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
82 _dockWidget->setWidget(_widgetPresentationParameters);
83 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
84 //_dockWidget->show();
86 // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
87 if ( ! _presManager ) {
88 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
91 // Connect to the click in the object browser
92 connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
93 this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
96 PresentationController::~PresentationController()
98 STDLOG("Deleting the resentationController");
99 // Clean allocated widget helpers:
100 for ( std::map<int, MEDWidgetHelper *>::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
101 delete((*it).second);
105 * [ABN] Created this probably because I don't know the right way to deal with non existent
106 * attributes in an object from the study ...
109 PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name)
113 theInt = _studyEditor->getParameterInt(obj,name);
120 PresentationController::_getIconName(const std::string& name)
122 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
126 // Read value from preferences and suffix name to select icon theme
127 int theme = mgr->integerValue("MEDCalc", "icons");
129 return name + "_MODERN";
130 } else if (theme == 1) {
131 return name + "_CLASSIC";
133 return name + "_DEFAULT";
137 PresentationController::createActions()
139 STDLOG("Creating PresentationController actions");
142 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
143 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
144 ag->setText("View mode");
145 ag->setUsesDropDown(true);
146 QString label = tr("LAB_VIEW_MODE_REPLACE");
147 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
148 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
149 a->setCheckable(true);
153 label = tr("LAB_VIEW_MODE_OVERLAP");
154 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
155 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
156 a->setCheckable(true);
159 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
160 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
161 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
162 a->setCheckable(true);
165 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
166 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
167 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
168 a->setCheckable(true);
171 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
174 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
175 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
177 label = tr("LAB_PRESENTATION_MESH_VIEW");
178 tooltip = tr("TIP_PRESENTATION_MESH_VIEW");
179 QString icon = tr(_getIconName("ICO_PRESENTATION_MESH_VIEW").c_str());
181 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeMeshView()),icon,tooltip);
182 _salomeModule->createTool(actionId, presentationToolbarId);
183 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
184 _salomeModule->createMenu(actionId, presentationMenuId);
186 label = tr("LAB_PRESENTATION_SCALAR_MAP");
187 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
188 icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
189 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip);
190 _salomeModule->createTool(actionId, presentationToolbarId);
191 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
192 _salomeModule->createMenu(actionId, presentationMenuId);
194 label = tr("LAB_PRESENTATION_CONTOUR");
195 tooltip = tr("TIP_PRESENTATION_CONTOUR");
196 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
197 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
198 _salomeModule->createTool(actionId, presentationToolbarId);
199 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
200 _salomeModule->createMenu(actionId, presentationMenuId);
202 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
203 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
204 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
205 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
206 _salomeModule->createTool(actionId, presentationToolbarId);
207 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
208 _salomeModule->createMenu(actionId, presentationMenuId);
210 label = tr("LAB_PRESENTATION_SLICES");
211 tooltip = tr("TIP_PRESENTATION_SLICES");
212 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
213 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
214 _salomeModule->createTool(actionId, presentationToolbarId);
215 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
216 _salomeModule->createMenu(actionId, presentationMenuId);
218 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
219 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
220 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
221 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
222 _salomeModule->createTool(actionId, presentationToolbarId);
223 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
224 _salomeModule->createMenu(actionId, presentationMenuId);
226 label = tr("LAB_PRESENTATION_POINT_SPRITE");
227 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
228 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
229 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
230 _salomeModule->createTool(actionId, presentationToolbarId);
231 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
232 _salomeModule->createMenu(actionId, presentationMenuId);
235 _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
237 label = tr("LAB_DELETE_PRESENTATION");
238 tooltip = tr("TIP_DELETE_PRESENTATION");
239 icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
240 actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
241 // _salomeModule->createTool(actionId, presentationToolbarId);
242 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
243 _salomeModule->createMenu(actionId, presentationMenuId);
246 // Actions for popup menu only
248 // Low level PARAVIS dump
249 label = tr("LAB_PARAVIS_DUMP");
250 //icon = tr("ICO_DATASOURCE_EXPAND_FIELD");
251 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
252 _salomeModule->addActionInPopupMenu(actionId);
257 MEDCALC::MEDPresentationViewMode
258 PresentationController::getSelectedViewMode() const
260 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
261 return MEDCALC::VIEW_MODE_REPLACE;
263 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
264 return MEDCALC::VIEW_MODE_OVERLAP;
266 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
267 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
269 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
270 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
273 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
274 return MEDCALC::VIEW_MODE_REPLACE;
277 MEDCALC::MEDPresentationColorMap
278 PresentationController::getSelectedColorMap() const
280 return _widgetPresentationParameters->getColorMap();
283 MEDCALC::MEDPresentationScalarBarRange
284 PresentationController::getSelectedScalarBarRange() const
286 return _widgetPresentationParameters->getScalarBarRange();
290 PresentationController::visualize(PresentationEvent::EventType eventType)
292 // We need a _studyEditor updated on the active study
293 _studyEditor->updateActiveStudy();
295 // Get the selected objects in the study (SObject)
296 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
298 // For each object, emit a signal to the workspace to request a
299 // visualisation using the tui command (so that the user can see how
300 // to make a view of an object from the tui console).
301 for (int i=0; i<listOfSObject->size(); i++) {
302 SALOMEDS::SObject_var soField = listOfSObject->at(i);
303 int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
304 if (fieldId < 0) // is it a field serie ?
306 int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
307 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
308 // managed by the MED module, and we stop this function process.
309 if ( fieldSeriesId < 0)
311 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
312 if (fieldHandlerList->length() < 0)
314 // For a field series, get the first real field entry:
315 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
316 fieldId = fieldHandler.id;
319 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
320 if (! fieldHandler) {
321 QMessageBox::warning(_salomeModule->getApp()->desktop(),
322 tr("Operation not allowed"),
323 tr("No field is defined"));
327 PresentationEvent* event = new PresentationEvent();
328 event->eventtype = eventType;
329 event->fieldHandler = fieldHandler;
330 emit presentationSignal(event); // --> processPresentationEvent()
335 PresentationController::onVisualizeMeshView()
337 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW);
341 PresentationController::onVisualizeScalarMap()
343 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
347 PresentationController::onVisualizeContour()
349 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
353 PresentationController::onVisualizeVectorField()
355 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
359 PresentationController::onVisualizeSlices()
361 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
365 PresentationController::onVisualizeDeflectionShape()
367 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
371 PresentationController::onVisualizePointSprite()
373 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
377 PresentationController::onDeletePresentation()
379 // We need a _studyEditor updated on the active study
380 _studyEditor->updateActiveStudy();
382 // Get the selected objects in the study (SObject)
383 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
385 // For each object, emit a signal to the workspace to request pres deletion
386 for (int i=0; i<listOfSObject->size(); i++) {
387 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
388 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
389 // If fieldId equals -1, then it means that it is not a field
390 // managed by the MED module, and we stop this function process.
394 PresentationEvent* event = new PresentationEvent();
395 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
396 event->presentationId = presId;
397 emit presentationSignal(event); // --> processPresentationEvent()
402 PresentationController::getViewModePython() const
404 MEDCALC::MEDPresentationViewMode viewMode = getSelectedViewMode();
406 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
407 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
408 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
409 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
415 PresentationController::getColorMapPython() const
417 MEDCALC::MEDPresentationColorMap colorMap = getSelectedColorMap();
419 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
420 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
426 PresentationController::getScalarBarRangePython() const
428 MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange();
430 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
431 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
437 PresentationController::getMeshModePython(const int mode) const
439 MEDCALC::MEDPresentationMeshMode mod = static_cast<MEDCALC::MEDPresentationMeshMode>(mode);
441 case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
442 case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
443 case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
449 PresentationController::getSliceOrientationPython(const int orientation) const
451 MEDCALC::MEDPresentationSliceOrientation orient = static_cast<MEDCALC::MEDPresentationSliceOrientation>(orientation);
453 case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
454 case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
455 case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
456 case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
457 case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
458 case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
459 case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
465 PresentationController::getPresTypeFromWidgetHelper(int presId) const
467 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
468 if (it != _presHelperMap.end())
469 return (*it).second->getPythonTag();
474 PresentationController::processPresentationEvent(const PresentationEvent* event) {
475 // --> Send commands to SALOME Python console
476 QString viewMode = getViewModePython();
477 QString colorMap = getColorMapPython();
478 QString scalarBarRange = getScalarBarRangePython();
479 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
480 QStringList commands;
481 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
482 commands += QString("presentation_id = medcalc.MakeMeshView(accessField(%1), viewMode=%2)").arg(fieldHandler->id).arg(viewMode);
483 commands += QString("presentation_id");
485 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
486 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
487 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
488 commands += QString("presentation_id");
490 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
491 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
492 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
493 commands += QString("presentation_id");
495 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
496 // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
497 // commands += QString("presentation_id");
499 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
500 commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
501 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
502 commands += QString("presentation_id");
504 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
505 // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
506 // commands += QString("presentation_id");
508 // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
509 // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
510 // commands += QString("presentation_id");
513 // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each
514 // dedicated widget helper class?
515 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
516 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
517 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
518 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
519 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
521 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
522 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
523 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
524 commands += QString("params.colorMap = %1").arg(getColorMapPython());
525 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
527 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
528 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
529 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
530 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
531 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
533 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
534 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
535 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
536 commands += QString("params.nbContours = %1").arg(event->anInteger);
537 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
539 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
540 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
541 commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
542 commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
543 commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
545 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
546 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
547 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
548 commands += QString("params.nbSlices = %1").arg(event->anInteger);
549 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
551 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
552 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
553 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
554 commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
555 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
558 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
559 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
562 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
564 _consoleDriver->exec(commands);
568 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
569 int presId, const std::string& type, const std::string& name )
571 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
572 if (it != _presHelperMap.end())
574 MEDWidgetHelper * wh;
575 if (type == MEDPresentationMeshView::TYPE_NAME)
576 wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
577 else if (type == MEDPresentationScalarMap::TYPE_NAME)
578 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
579 else if (type == MEDPresentationContour::TYPE_NAME)
580 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
581 else if (type == MEDPresentationSlices::TYPE_NAME)
582 wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
585 STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
587 _presHelperMap[presId] = wh;
592 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
596 if (_widgetPresentationParameters->isShown())
598 _widgetPresentationParameters->toggleWidget(false);
599 if(_currentWidgetHelper)
600 _currentWidgetHelper->releaseWidget();
605 // Activate corresponding ParaView render view
606 _presManager->activateView(presId);
607 // Update widgets parameters
608 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
609 _currentWidgetHelper->udpateWidget();
614 PresentationController::onParavisDump()
616 // We need a _studyEditor updated on the active study
617 _studyEditor->updateActiveStudy();
619 // Get the selected objects in the study (SObject)
620 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
622 // For the first object only, request the dump
623 for (int i=0; i<listOfSObject->size(); i++) {
624 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
625 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
626 // If fieldId equals -1, then it means that it is not a field
627 // managed by the MED module, and we stop this function process.
631 std::string dump(_presManager->getParavisDump(presId));
632 std::cerr << "#====== ParaVis dump =============== " << std::endl;
634 std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
636 break; // stop at the first one
641 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
643 if (presentationId < 0) {
644 std::cerr << "Unknown presentation\n";
648 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
649 std::string type = name;
650 std::string icon = std::string("ICO_") + type;
651 icon = _getIconName(icon);
652 std::string ico = tr(icon.c_str()).toStdString();
654 // Append presentation ID to the displayed name in the OB:
655 std::ostringstream oss;
656 name = tr(name.c_str()).toStdString();
657 oss << name << " (" << presentationId << ")";
659 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
660 _PTR(Study) studyDS = study->studyDS();
662 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId,
663 oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
666 // MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
668 // // Remove sibling presentations if view mode is set to REPLACE
669 // if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
670 // MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
671 // CORBA::ULong size = presList->length();
673 // std::stringstream sstm;
674 // sstm << "Removing sibling presentation(s): ";
675 // for (int i = 0; i < size; ++i)
676 // sstm << (*presList)[i] << " ";
677 // STDLOG(sstm.str());
679 // for (int i = 0; i < size; ++i) {
680 // PresentationEvent* event = new PresentationEvent();
681 // event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
682 // XmedDataObject* dataObject = new XmedDataObject();
683 // dataObject->setPresentationId((*presList)[i]);
684 // event->objectdata = dataObject;
685 // emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
691 // update Object browser
692 _salomeModule->getApp()->updateObjectBrowser(true);
696 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
698 if (presentationId < 0) {
699 std::cerr << "Unknown presentation\n";
703 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
704 _PTR(Study) studyDS = study->studyDS();
706 _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
708 // update Object browser
709 _salomeModule->getApp()->updateObjectBrowser(true);
713 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
715 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
716 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
717 // Deal with replace mode: presentations with invalid IDs have to be removed:
718 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
719 _PTR(Study) studyDS = study->studyDS();
721 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
722 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations(_CAST(Study, studyDS)->GetStudy());
723 // The IDs not in the intersection needs deletion:
724 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
725 for (unsigned i = 0; i < lstModule->length(); i++)
727 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
730 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
731 // Presentation in module but not in manager anymore: to be deleted from OB:
732 updateTreeViewForPresentationRemoval((*lstModule)[i]);
736 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
737 updateTreeViewForPresentationRemoval(event->presentationId);
742 PresentationController::showDockWidgets(bool isVisible)
744 _dockWidget->setVisible(isVisible);