1 // Copyright (C) 2016-2020 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"
34 #include "MEDPresentationPointSprite.hxx"
35 #include "MEDPresentationVectorField.hxx"
36 #include "MEDPresentationDeflectionShape.hxx"
38 #include "MEDWidgetHelperMeshView.hxx"
39 #include "MEDWidgetHelperScalarMap.hxx"
40 #include "MEDWidgetHelperContour.hxx"
41 #include "MEDWidgetHelperSlices.hxx"
42 #include "MEDWidgetHelperPointSprite.hxx"
43 #include "MEDWidgetHelperVectorField.hxx"
44 #include "MEDWidgetHelperDeflectionShape.hxx"
46 #include <SalomeApp_Application.h>
47 #include <SalomeApp_Study.h>
48 #include <SalomeApp_DataObject.h>
50 #include <SALOME_ListIO.hxx>
51 #include <LightApp_SelectionMgr.h>
53 #include <SALOMEDS_SObject.hxx>
54 #include <SALOMEDS_Study.hxx>
56 #include <SUIT_Desktop.h>
57 #include <SUIT_Session.h>
58 #include <SUIT_ResourceMgr.h>
59 #include <QMessageBox>
62 #include "MEDFactoryClient.hxx"
64 static const int OPTIONS_VIEW_MODE_ID = 943;
65 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
66 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
67 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
68 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
70 //! The only instance of the MEDPresentationManager
71 MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
73 PresentationController::PresentationController(MEDModule* salomeModule) :
74 _salomeModule(salomeModule),
76 _studyEditor(salomeModule->getStudyEditor()),
78 _currentWidgetHelper(0)
80 STDLOG("Creating a PresentationController");
82 _widgetPresentationParameters = new WidgetPresentationParameters();
84 QMainWindow* parent = salomeModule->getApp()->desktop();
85 _dockWidget = new QDockWidget(parent);
86 _dockWidget->setVisible(false);
87 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
88 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
89 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
90 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
91 _dockWidget->setWidget(_widgetPresentationParameters);
92 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
93 //_dockWidget->show();
95 // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
96 if ( ! _presManager ) {
97 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
100 // Connect to the click in the object browser
101 connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
102 this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
105 PresentationController::~PresentationController()
107 STDLOG("Deleting the resentationController");
108 // Clean allocated widget helpers:
109 for ( std::map<int, MEDWidgetHelper *>::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
110 delete((*it).second);
114 PresentationController::_getIconName(const std::string& name)
116 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
120 // Read value from preferences and suffix name to select icon theme
121 int theme = mgr->integerValue("MEDCalc", "icons");
123 return name + "_MODERN";
124 } else if (theme == 1) {
125 return name + "_CLASSIC";
127 return name + "_DEFAULT";
131 PresentationController::createActions()
133 STDLOG("Creating PresentationController actions");
136 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
137 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
138 ag->setText("View mode");
139 ag->setUsesDropDown(true);
140 QString label = tr("LAB_VIEW_MODE_REPLACE");
141 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
142 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
143 a->setCheckable(true);
147 label = tr("LAB_VIEW_MODE_OVERLAP");
148 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
149 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
150 a->setCheckable(true);
153 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
154 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
155 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
156 a->setCheckable(true);
159 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
160 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
161 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
162 a->setCheckable(true);
165 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
168 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
169 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, -1, 10);
171 label = tr("LAB_PRESENTATION_MESH_VIEW");
172 tooltip = tr("TIP_PRESENTATION_MESH_VIEW");
173 QString icon = tr(_getIconName("ICO_PRESENTATION_MESH_VIEW").c_str());
175 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeMeshView()),icon,tooltip);
176 _salomeModule->createTool(actionId, presentationToolbarId);
177 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
178 _salomeModule->createMenu(actionId, presentationMenuId);
180 label = tr("LAB_PRESENTATION_SCALAR_MAP");
181 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
182 icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
183 actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeScalarMap()),
184 icon, tooltip, FIELDSOp::OpScalarMap);
185 _salomeModule->createTool(actionId, presentationToolbarId);
186 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
187 _salomeModule->createMenu(actionId, presentationMenuId);
189 label = tr("LAB_PRESENTATION_CONTOUR");
190 tooltip = tr("TIP_PRESENTATION_CONTOUR");
191 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
192 actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeContour()),
193 icon, tooltip, FIELDSOp::OpContour);
194 _salomeModule->createTool(actionId, presentationToolbarId);
195 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
196 _salomeModule->createMenu(actionId, presentationMenuId);
198 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
199 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
200 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
201 actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeVectorField()),
202 icon, tooltip, FIELDSOp::OpVectorFields);
203 _salomeModule->createTool(actionId, presentationToolbarId);
204 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
205 _salomeModule->createMenu(actionId, presentationMenuId);
207 label = tr("LAB_PRESENTATION_SLICES");
208 tooltip = tr("TIP_PRESENTATION_SLICES");
209 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
210 actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeSlices()),
211 icon, tooltip, FIELDSOp::OpSlices);
212 _salomeModule->createTool(actionId, presentationToolbarId);
213 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
214 _salomeModule->createMenu(actionId, presentationMenuId);
216 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
217 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
218 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
219 actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizeDeflectionShape()),
220 icon, tooltip, FIELDSOp::OpDeflectionShape);
221 _salomeModule->createTool(actionId, presentationToolbarId);
222 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
223 _salomeModule->createMenu(actionId, presentationMenuId);
225 label = tr("LAB_PRESENTATION_POINT_SPRITE");
226 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
227 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
228 actionId = _salomeModule->createStandardAction(label, this, SLOT(onVisualizePointSprite()),
229 icon, tooltip, FIELDSOp::OpPointSprite);
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("ICO_DELETE_PRESENTATION");
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);
245 // Low level PARAVIS dump
246 label = tr("LAB_PARAVIS_DUMP");
247 tooltip = tr("TIP_PARAVIS_DUMP");
248 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
249 _salomeModule->createMenu(actionId, presentationMenuId);
252 // Actions for popup menu only
257 MEDCALC::ViewModeType
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::ColorMapType
278 PresentationController::getSelectedColorMap() const
280 return _widgetPresentationParameters->getColorMap();
283 MEDCALC::ScalarBarRangeType
284 PresentationController::getSelectedScalarBarRange() const
286 return _widgetPresentationParameters->getScalarBarRange();
290 PresentationController::visualize(PresentationEvent::EventType eventType)
292 // Get the selected objects in the study (SObject)
293 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
295 // For each object, emit a signal to the workspace to request a
296 // visualisation using the tui command (so that the user can see how
297 // to make a view of an object from the tui console).
298 for (int i=0; i<(int)listOfSObject->size(); i++) {
299 SALOMEDS::SObject_var soObj = listOfSObject->at(i);
300 std::string name(_studyEditor->getName(soObj));
301 if (soObj->_is_nil() || name == "MEDCalc")
303 int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
304 int meshId = _salomeModule->getIntParamFromStudyEditor(soObj, MESH_ID);
305 MEDCALC::FieldHandler* fieldHandler = 0;
306 MEDCALC::MeshHandler* meshHandler = 0;
311 if (eventType != PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW)
313 meshHandler = MEDFactoryClient::getDataManager()->getMeshHandler(meshId);
317 if (fieldId < 0) // is it a field series?
319 int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
320 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
321 // managed by the MED module, and we stop this function process.
322 if ( fieldSeriesId < 0)
325 // get the current timestamp
326 double timestamp = _salomeModule->getCurrentAnimationTimestamp();
327 // get the field id a the current timestamp
328 fieldId = MEDFactoryClient::getDataManager()->getFieldIdAtTimestamp(fieldSeriesId, timestamp);
330 fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
333 if ((!fieldHandler) && (!meshHandler)) {
334 QMessageBox::warning(_salomeModule->getApp()->desktop(),
335 tr("Operation not allowed"),
336 tr("No field (or mesh) is defined"));
340 PresentationEvent* event = new PresentationEvent();
341 event->eventtype = eventType;
342 event->fieldHandler = fieldHandler;
343 event->meshHandler = meshHandler;
344 emit presentationSignal(event); // --> processPresentationEvent()
349 PresentationController::onVisualizeMeshView()
351 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW);
355 PresentationController::onVisualizeScalarMap()
357 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
361 PresentationController::onVisualizeContour()
363 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
367 PresentationController::onVisualizeVectorField()
369 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
373 PresentationController::onVisualizeSlices()
375 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
379 PresentationController::onVisualizeDeflectionShape()
381 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
385 PresentationController::onVisualizePointSprite()
387 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
391 PresentationController::onDeletePresentation()
393 // Get the selected objects in the study (SObject)
394 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
396 // For each object, emit a signal to the workspace to request pres deletion
397 for (int i=0; i<(int)listOfSObject->size(); i++) {
398 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
399 std::string name(_studyEditor->getName(soPres));
400 if (soPres->_is_nil() || name == "MEDCalc")
402 int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
403 // If fieldId equals -1, then it means that it is not a field
404 // managed by the MED module, and we stop this function process.
408 PresentationEvent* event = new PresentationEvent();
409 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
410 event->presentationId = presId;
411 emit presentationSignal(event); // --> processPresentationEvent()
416 PresentationController::getViewModePython() const
418 MEDCALC::ViewModeType viewMode = getSelectedViewMode();
420 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
421 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
422 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
423 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
429 PresentationController::getColorMapPython() const
431 MEDCALC::ColorMapType colorMap = getSelectedColorMap();
433 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
434 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
440 PresentationController::getScalarBarRangePython() const
442 MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange();
444 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
445 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
451 PresentationController::getMeshModePython(const int mode) const
453 MEDCALC::MeshModeType mod = static_cast<MEDCALC::MeshModeType>(mode);
455 case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
456 case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
457 case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
463 PresentationController::getSliceOrientationPython(const int orientation) const
465 MEDCALC::SliceOrientationType orient = static_cast<MEDCALC::SliceOrientationType>(orientation);
467 case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
468 case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
469 case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
470 case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
471 case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
472 case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
473 case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
479 PresentationController::getPresTypeFromWidgetHelper(int presId) const
481 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
482 if (it != _presHelperMap.end())
483 return (*it).second->getPythonTag();
488 PresentationController::processPresentationEvent(const PresentationEvent* event) {
489 // --> Send commands to SALOME Python console
490 QString viewMode = getViewModePython();
491 QString colorMap = getColorMapPython();
492 QString scalarBarRange = getScalarBarRangePython();
493 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
494 QStringList commands;
496 // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each
497 // dedicated widget helper class?
499 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
500 // Do we request mesh view from a field or from a mesh only?
501 int meshId = event->meshHandler ? event->meshHandler->id : event->fieldHandler->meshid;
502 commands += QString("presentation_id = medcalc.MakeMeshView(%1, viewMode=%2)").arg(meshId).arg(viewMode);
503 commands += QString("presentation_id");
505 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
506 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
507 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
508 commands += QString("presentation_id");
510 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
511 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
512 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
513 commands += QString("presentation_id");
515 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
516 commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
517 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
518 commands += QString("presentation_id");
520 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
521 commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
522 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
523 commands += QString("presentation_id");
525 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
526 commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
527 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
528 commands += QString("presentation_id");
530 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
531 commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
532 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
533 commands += QString("presentation_id");
537 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
538 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
539 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
540 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
541 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
543 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
544 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
545 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
546 commands += QString("params.colorMap = %1").arg(getColorMapPython());
547 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
549 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
550 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
551 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
552 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
553 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
555 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
556 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
557 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
558 commands += QString("params.nbContours = %1").arg(event->anInteger);
559 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
561 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
562 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
563 commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
564 commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
565 commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
567 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
568 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
569 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
570 commands += QString("params.nbSlices = %1").arg(event->anInteger);
571 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
573 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
574 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
575 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
576 commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
577 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
580 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
581 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
584 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
586 _consoleDriver->exec(commands);
590 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr /*presManager*/, // todo: unused
591 int presId, const std::string& type, const std::string& name )
593 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
594 if (it != _presHelperMap.end())
596 MEDWidgetHelper * wh = 0;
597 if (type == MEDPresentationMeshView::TYPE_NAME)
598 wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
599 else if (type == MEDPresentationScalarMap::TYPE_NAME)
600 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
601 else if (type == MEDPresentationContour::TYPE_NAME)
602 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
603 else if (type == MEDPresentationSlices::TYPE_NAME)
604 wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
605 else if (type == MEDPresentationVectorField::TYPE_NAME)
606 wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
607 else if (type == MEDPresentationPointSprite::TYPE_NAME)
608 wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
609 else if (type == MEDPresentationDeflectionShape::TYPE_NAME)
610 wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters);
613 STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
616 _presHelperMap[presId] = wh;
621 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
625 if (_widgetPresentationParameters->isShown())
627 _widgetPresentationParameters->toggleWidget(false);
628 if(_currentWidgetHelper)
629 _currentWidgetHelper->releaseWidget();
634 if(_currentWidgetHelper)
635 _currentWidgetHelper->releaseWidget();
636 // Activate corresponding ParaView render view
637 _presManager->activateView(presId);
638 // Update widgets parameters
639 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
640 _currentWidgetHelper->updateWidget(true);
645 PresentationController::onParavisDump()
647 // Get the selected objects in the study (SObject)
648 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
650 // For the first object only, request the dump
651 for (int i=0; i<(int)listOfSObject->size(); i++) {
652 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
653 std::string name(_studyEditor->getName(soPres));
654 if (soPres->_is_nil() || name == "MEDCalc")
656 int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
657 // If fieldId equals -1, then it means that it is not a field
658 // managed by the MED module, and we stop this function process.
662 std::string dump(_presManager->getParavisDump(presId));
663 std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl;
665 std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
667 break; // stop at the first one
672 PresentationController::updateTreeViewWithNewPresentation(long dataId, long presentationId)
674 if (presentationId < 0) {
675 std::cerr << "Unknown presentation\n";
679 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
680 std::string type = name;
681 std::string icon = std::string("ICO_") + type;
682 icon = _getIconName(icon);
683 std::string ico = tr(icon.c_str()).toStdString();
685 // Append presentation ID to the displayed name in the OB:
686 std::ostringstream oss;
687 name = tr(name.c_str()).toStdString();
688 oss << name << " (" << presentationId << ")";
690 // Mesh views are always registered at the mesh level:
691 if (type == MEDPresentationMeshView::TYPE_NAME)
693 _salomeModule->engine()->registerPresentationMesh(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
696 _salomeModule->engine()->registerPresentationField(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
698 // update Object browser
699 _salomeModule->getApp()->updateObjectBrowser(true);
701 // auto-select new presentation
702 std::string entry = _salomeModule->engine()->getStudyPresentationEntry(presentationId);
703 SALOME_ListIO selectedObjects;
704 LightApp_Study* lightStudy = dynamic_cast<LightApp_Study*>( _salomeModule->application()->activeStudy() );
705 QString component = lightStudy->componentDataType( entry.c_str() );
706 selectedObjects.Append( new SALOME_InteractiveObject( (const char*)entry.c_str(),
707 (const char*)component.toLatin1(),
708 ""/*refobj->Name().c_str()*/ ) );
709 //QStringList selectedObjects;
710 //selectedObjects << QString(entry.c_str());
711 LightApp_SelectionMgr* aSelectionMgr = _salomeModule->getApp()->selectionMgr();
712 aSelectionMgr->setSelectedObjects(selectedObjects, false);
714 // emit onPresentationSelected
716 _salomeModule->itemClickGeneric(name, type, presId);
717 onPresentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name));
721 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
723 if (presentationId < 0) {
724 std::cerr << "Unknown presentation\n";
728 _salomeModule->engine()->unregisterPresentation(presentationId);
730 // update Object browser
731 _salomeModule->getApp()->updateObjectBrowser(true);
735 PresentationController::_dealWithReplaceMode()
737 // Deal with replace mode: presentations with invalid IDs have to be removed:
739 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
740 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations();
741 // The IDs not in the intersection needs deletion:
742 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
743 for (unsigned i = 0; i < lstModule->length(); i++) {
744 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
746 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
747 // Presentation in module but not in manager anymore: to be deleted from OB:
748 updateTreeViewForPresentationRemoval((*lstModule)[i]);
754 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
756 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
757 if (event->dataId == -1) {
758 // A file has been loaded, and we want to create a default presentation (MeshView) for it
759 QString viewMode = getViewModePython();
760 QStringList commands;
761 commands += QString("presentation_id = medcalc.MakeMeshView(medcalc.GetFirstMeshFromDataSource(source_id), viewMode=%1)").arg(viewMode);
762 commands += QString("presentation_id");
763 _consoleDriver->exec(commands);
766 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
767 _dealWithReplaceMode();
770 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
771 updateTreeViewForPresentationRemoval(event->presentationId);
772 // Hide parameter widget if necessary:
773 onPresentationSelected(-1, "", "");
775 else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
776 // Update parameter widget if shown:
777 if(_currentWidgetHelper)
778 _currentWidgetHelper->updateWidget(false);
783 PresentationController::showDockWidgets(bool isVisible)
785 _dockWidget->setVisible(isVisible);