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()),icon,tooltip);
184 _salomeModule->createTool(actionId, presentationToolbarId);
185 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
186 _salomeModule->createMenu(actionId, presentationMenuId);
188 label = tr("LAB_PRESENTATION_CONTOUR");
189 tooltip = tr("TIP_PRESENTATION_CONTOUR");
190 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
191 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
192 _salomeModule->createTool(actionId, presentationToolbarId);
193 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
194 _salomeModule->createMenu(actionId, presentationMenuId);
196 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
197 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
198 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
199 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
200 _salomeModule->createTool(actionId, presentationToolbarId);
201 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
202 _salomeModule->createMenu(actionId, presentationMenuId);
204 label = tr("LAB_PRESENTATION_SLICES");
205 tooltip = tr("TIP_PRESENTATION_SLICES");
206 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
207 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
208 _salomeModule->createTool(actionId, presentationToolbarId);
209 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
210 _salomeModule->createMenu(actionId, presentationMenuId);
212 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
213 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
214 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
215 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
216 _salomeModule->createTool(actionId, presentationToolbarId);
217 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
218 _salomeModule->createMenu(actionId, presentationMenuId);
220 label = tr("LAB_PRESENTATION_POINT_SPRITE");
221 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
222 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
223 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
224 _salomeModule->createTool(actionId, presentationToolbarId);
225 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
226 _salomeModule->createMenu(actionId, presentationMenuId);
229 _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
231 label = tr("LAB_DELETE_PRESENTATION");
232 tooltip = tr("TIP_DELETE_PRESENTATION");
233 icon = tr("ICO_DELETE_PRESENTATION");
234 actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
235 // _salomeModule->createTool(actionId, presentationToolbarId);
236 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
237 _salomeModule->createMenu(actionId, presentationMenuId);
239 // Low level PARAVIS dump
240 label = tr("LAB_PARAVIS_DUMP");
241 tooltip = tr("TIP_PARAVIS_DUMP");
242 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
243 _salomeModule->createMenu(actionId, presentationMenuId);
246 // Actions for popup menu only
251 MEDCALC::ViewModeType
252 PresentationController::getSelectedViewMode() const
254 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
255 return MEDCALC::VIEW_MODE_REPLACE;
257 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
258 return MEDCALC::VIEW_MODE_OVERLAP;
260 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
261 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
263 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
264 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
267 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
268 return MEDCALC::VIEW_MODE_REPLACE;
271 MEDCALC::ColorMapType
272 PresentationController::getSelectedColorMap() const
274 return _widgetPresentationParameters->getColorMap();
277 MEDCALC::ScalarBarRangeType
278 PresentationController::getSelectedScalarBarRange() const
280 return _widgetPresentationParameters->getScalarBarRange();
284 PresentationController::visualize(PresentationEvent::EventType eventType)
286 // Get the selected objects in the study (SObject)
287 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
289 // For each object, emit a signal to the workspace to request a
290 // visualisation using the tui command (so that the user can see how
291 // to make a view of an object from the tui console).
292 for (int i=0; i<(int)listOfSObject->size(); i++) {
293 SALOMEDS::SObject_var soObj = listOfSObject->at(i);
294 std::string name(_studyEditor->getName(soObj));
295 if (soObj->_is_nil() || name == "MEDCalc")
297 int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
298 int meshId = _salomeModule->getIntParamFromStudyEditor(soObj, MESH_ID);
299 MEDCALC::FieldHandler* fieldHandler = 0;
300 MEDCALC::MeshHandler* meshHandler = 0;
305 if (eventType != PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW)
307 meshHandler = MEDFactoryClient::getDataManager()->getMeshHandler(meshId);
311 if (fieldId < 0) // is it a field series?
313 int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
314 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
315 // managed by the MED module, and we stop this function process.
316 if ( fieldSeriesId < 0)
319 // get the current timestamp
320 double timestamp = _salomeModule->getCurrentAnimationTimestamp();
321 // get the field id a the current timestamp
322 fieldId = MEDFactoryClient::getDataManager()->getFieldIdAtTimestamp(fieldSeriesId, timestamp);
324 fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
327 if ((!fieldHandler) && (!meshHandler)) {
328 QMessageBox::warning(_salomeModule->getApp()->desktop(),
329 tr("Operation not allowed"),
330 tr("No field (or mesh) is defined"));
334 PresentationEvent* event = new PresentationEvent();
335 event->eventtype = eventType;
336 event->fieldHandler = fieldHandler;
337 event->meshHandler = meshHandler;
338 emit presentationSignal(event); // --> processPresentationEvent()
343 PresentationController::onVisualizeMeshView()
345 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW);
349 PresentationController::onVisualizeScalarMap()
351 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
355 PresentationController::onVisualizeContour()
357 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
361 PresentationController::onVisualizeVectorField()
363 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
367 PresentationController::onVisualizeSlices()
369 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
373 PresentationController::onVisualizeDeflectionShape()
375 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
379 PresentationController::onVisualizePointSprite()
381 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
385 PresentationController::onDeletePresentation()
387 // Get the selected objects in the study (SObject)
388 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
390 // For each object, emit a signal to the workspace to request pres deletion
391 for (int i=0; i<(int)listOfSObject->size(); i++) {
392 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
393 std::string name(_studyEditor->getName(soPres));
394 if (soPres->_is_nil() || name == "MEDCalc")
396 int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
397 // If fieldId equals -1, then it means that it is not a field
398 // managed by the MED module, and we stop this function process.
402 PresentationEvent* event = new PresentationEvent();
403 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
404 event->presentationId = presId;
405 emit presentationSignal(event); // --> processPresentationEvent()
410 PresentationController::getViewModePython() const
412 MEDCALC::ViewModeType viewMode = getSelectedViewMode();
414 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
415 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
416 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
417 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
423 PresentationController::getColorMapPython() const
425 MEDCALC::ColorMapType colorMap = getSelectedColorMap();
427 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
428 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
434 PresentationController::getScalarBarRangePython() const
436 MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange();
438 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
439 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
445 PresentationController::getMeshModePython(const int mode) const
447 MEDCALC::MeshModeType mod = static_cast<MEDCALC::MeshModeType>(mode);
449 case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
450 case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
451 case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
457 PresentationController::getSliceOrientationPython(const int orientation) const
459 MEDCALC::SliceOrientationType orient = static_cast<MEDCALC::SliceOrientationType>(orientation);
461 case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
462 case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
463 case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
464 case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
465 case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
466 case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
467 case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
473 PresentationController::getPresTypeFromWidgetHelper(int presId) const
475 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
476 if (it != _presHelperMap.end())
477 return (*it).second->getPythonTag();
482 PresentationController::processPresentationEvent(const PresentationEvent* event) {
483 // --> Send commands to SALOME Python console
484 QString viewMode = getViewModePython();
485 QString colorMap = getColorMapPython();
486 QString scalarBarRange = getScalarBarRangePython();
487 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
488 QStringList commands;
490 // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each
491 // dedicated widget helper class?
493 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
494 // Do we request mesh view from a field or from a mesh only?
495 int meshId = event->meshHandler ? event->meshHandler->id : event->fieldHandler->meshid;
496 commands += QString("presentation_id = medcalc.MakeMeshView(%1, viewMode=%2)").arg(meshId).arg(viewMode);
497 commands += QString("presentation_id");
499 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
500 commands += QString("presentation_id = medcalc.MakeScalarMap(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_CONTOUR ) {
505 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
506 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
507 commands += QString("presentation_id");
509 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
510 commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
511 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
512 commands += QString("presentation_id");
514 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
515 commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
516 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
517 commands += QString("presentation_id");
519 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
520 commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
521 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
522 commands += QString("presentation_id");
524 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
525 commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
526 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
527 commands += QString("presentation_id");
531 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
532 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
533 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
534 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
535 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
537 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
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.colorMap = %1").arg(getColorMapPython());
541 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
543 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
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.scalarBarRange = %1").arg(getScalarBarRangePython());
547 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
549 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
550 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
551 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
552 commands += QString("params.nbContours = %1").arg(event->anInteger);
553 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
555 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
556 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
557 commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
558 commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
559 commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
561 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
562 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
563 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
564 commands += QString("params.nbSlices = %1").arg(event->anInteger);
565 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
567 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
568 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
569 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
570 commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
571 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
574 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
575 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
578 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
580 _consoleDriver->exec(commands);
584 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr /*presManager*/, // todo: unused
585 int presId, const std::string& type, const std::string& name )
587 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
588 if (it != _presHelperMap.end())
590 MEDWidgetHelper * wh = 0;
591 if (type == MEDPresentationMeshView::TYPE_NAME)
592 wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
593 else if (type == MEDPresentationScalarMap::TYPE_NAME)
594 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
595 else if (type == MEDPresentationContour::TYPE_NAME)
596 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
597 else if (type == MEDPresentationSlices::TYPE_NAME)
598 wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
599 else if (type == MEDPresentationVectorField::TYPE_NAME)
600 wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
601 else if (type == MEDPresentationPointSprite::TYPE_NAME)
602 wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
603 else if (type == MEDPresentationDeflectionShape::TYPE_NAME)
604 wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters);
607 STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
610 _presHelperMap[presId] = wh;
615 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
619 if (_widgetPresentationParameters->isShown())
621 _widgetPresentationParameters->toggleWidget(false);
622 if(_currentWidgetHelper)
623 _currentWidgetHelper->releaseWidget();
628 if(_currentWidgetHelper)
629 _currentWidgetHelper->releaseWidget();
630 // Activate corresponding ParaView render view
631 _presManager->activateView(presId);
632 // Update widgets parameters
633 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
634 _currentWidgetHelper->updateWidget(true);
639 PresentationController::onParavisDump()
641 // Get the selected objects in the study (SObject)
642 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
644 // For the first object only, request the dump
645 for (int i=0; i<(int)listOfSObject->size(); i++) {
646 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
647 std::string name(_studyEditor->getName(soPres));
648 if (soPres->_is_nil() || name == "MEDCalc")
650 int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
651 // If fieldId equals -1, then it means that it is not a field
652 // managed by the MED module, and we stop this function process.
656 std::string dump(_presManager->getParavisDump(presId));
657 std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl;
659 std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
661 break; // stop at the first one
666 PresentationController::updateTreeViewWithNewPresentation(long dataId, long presentationId)
668 if (presentationId < 0) {
669 std::cerr << "Unknown presentation\n";
673 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
674 std::string type = name;
675 std::string icon = std::string("ICO_") + type;
676 icon = _getIconName(icon);
677 std::string ico = tr(icon.c_str()).toStdString();
679 // Append presentation ID to the displayed name in the OB:
680 std::ostringstream oss;
681 name = tr(name.c_str()).toStdString();
682 oss << name << " (" << presentationId << ")";
684 // Mesh views are always registered at the mesh level:
685 if (type == MEDPresentationMeshView::TYPE_NAME)
687 _salomeModule->engine()->registerPresentationMesh(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
690 _salomeModule->engine()->registerPresentationField(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
692 // update Object browser
693 _salomeModule->getApp()->updateObjectBrowser(true);
695 // auto-select new presentation
696 std::string entry = _salomeModule->engine()->getStudyPresentationEntry(presentationId);
697 SALOME_ListIO selectedObjects;
698 LightApp_Study* lightStudy = dynamic_cast<LightApp_Study*>( _salomeModule->application()->activeStudy() );
699 QString component = lightStudy->componentDataType( entry.c_str() );
700 selectedObjects.Append( new SALOME_InteractiveObject( (const char*)entry.c_str(),
701 (const char*)component.toLatin1(),
702 ""/*refobj->Name().c_str()*/ ) );
703 //QStringList selectedObjects;
704 //selectedObjects << QString(entry.c_str());
705 LightApp_SelectionMgr* aSelectionMgr = _salomeModule->getApp()->selectionMgr();
706 aSelectionMgr->setSelectedObjects(selectedObjects, false);
708 // emit onPresentationSelected
710 _salomeModule->itemClickGeneric(name, type, presId);
711 onPresentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name));
715 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
717 if (presentationId < 0) {
718 std::cerr << "Unknown presentation\n";
722 _salomeModule->engine()->unregisterPresentation(presentationId);
724 // update Object browser
725 _salomeModule->getApp()->updateObjectBrowser(true);
729 PresentationController::_dealWithReplaceMode()
731 // Deal with replace mode: presentations with invalid IDs have to be removed:
733 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
734 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations();
735 // The IDs not in the intersection needs deletion:
736 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
737 for (unsigned i = 0; i < lstModule->length(); i++) {
738 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
740 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
741 // Presentation in module but not in manager anymore: to be deleted from OB:
742 updateTreeViewForPresentationRemoval((*lstModule)[i]);
748 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
750 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
751 if (event->dataId == -1) {
752 // A file has been loaded, and we want to create a default presentation (MeshView) for it
753 QString viewMode = getViewModePython();
754 QStringList commands;
755 commands += QString("presentation_id = medcalc.MakeMeshView(medcalc.GetFirstMeshFromDataSource(source_id), viewMode=%1)").arg(viewMode);
756 commands += QString("presentation_id");
757 _consoleDriver->exec(commands);
760 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
761 _dealWithReplaceMode();
764 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
765 updateTreeViewForPresentationRemoval(event->presentationId);
766 // Hide parameter widget if necessary:
767 onPresentationSelected(-1, "", "");
769 else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
770 // Update parameter widget if shown:
771 if(_currentWidgetHelper)
772 _currentWidgetHelper->updateWidget(false);
777 PresentationController::showDockWidgets(bool isVisible)
779 _dockWidget->setVisible(isVisible);