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"
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::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name)
119 SALOMEDS::GenericAttribute_var anAttr;
120 SALOMEDS::AttributeParameter_var aParam;
121 if ( obj->FindAttribute(anAttr,"AttributeParameter") ) {
122 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
123 if (aParam->IsSet(name, PT_INTEGER))
124 return aParam->GetInt(name);
130 PresentationController::_getIconName(const std::string& name)
132 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
136 // Read value from preferences and suffix name to select icon theme
137 int theme = mgr->integerValue("MEDCalc", "icons");
139 return name + "_MODERN";
140 } else if (theme == 1) {
141 return name + "_CLASSIC";
143 return name + "_DEFAULT";
147 PresentationController::createActions()
149 STDLOG("Creating PresentationController actions");
152 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
153 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
154 ag->setText("View mode");
155 ag->setUsesDropDown(true);
156 QString label = tr("LAB_VIEW_MODE_REPLACE");
157 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
158 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
159 a->setCheckable(true);
163 label = tr("LAB_VIEW_MODE_OVERLAP");
164 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
165 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
166 a->setCheckable(true);
169 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
170 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
171 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
172 a->setCheckable(true);
175 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
176 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
177 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
178 a->setCheckable(true);
181 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
184 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
185 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, -1, 10);
187 label = tr("LAB_PRESENTATION_MESH_VIEW");
188 tooltip = tr("TIP_PRESENTATION_MESH_VIEW");
189 QString icon = tr(_getIconName("ICO_PRESENTATION_MESH_VIEW").c_str());
191 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeMeshView()),icon,tooltip);
192 _salomeModule->createTool(actionId, presentationToolbarId);
193 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
194 _salomeModule->createMenu(actionId, presentationMenuId);
196 label = tr("LAB_PRESENTATION_SCALAR_MAP");
197 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
198 icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
199 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip);
200 _salomeModule->createTool(actionId, presentationToolbarId);
201 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
202 _salomeModule->createMenu(actionId, presentationMenuId);
204 label = tr("LAB_PRESENTATION_CONTOUR");
205 tooltip = tr("TIP_PRESENTATION_CONTOUR");
206 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
207 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
208 _salomeModule->createTool(actionId, presentationToolbarId);
209 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
210 _salomeModule->createMenu(actionId, presentationMenuId);
212 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
213 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
214 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
215 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
216 _salomeModule->createTool(actionId, presentationToolbarId);
217 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
218 _salomeModule->createMenu(actionId, presentationMenuId);
220 label = tr("LAB_PRESENTATION_SLICES");
221 tooltip = tr("TIP_PRESENTATION_SLICES");
222 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
223 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
224 _salomeModule->createTool(actionId, presentationToolbarId);
225 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
226 _salomeModule->createMenu(actionId, presentationMenuId);
228 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
229 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
230 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
231 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
232 _salomeModule->createTool(actionId, presentationToolbarId);
233 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
234 _salomeModule->createMenu(actionId, presentationMenuId);
236 label = tr("LAB_PRESENTATION_POINT_SPRITE");
237 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
238 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
239 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
240 _salomeModule->createTool(actionId, presentationToolbarId);
241 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
242 _salomeModule->createMenu(actionId, presentationMenuId);
245 _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
247 label = tr("LAB_DELETE_PRESENTATION");
248 tooltip = tr("TIP_DELETE_PRESENTATION");
249 icon = tr("ICO_DELETE_PRESENTATION");
250 actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
251 // _salomeModule->createTool(actionId, presentationToolbarId);
252 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
253 _salomeModule->createMenu(actionId, presentationMenuId);
255 // Low level PARAVIS dump
256 label = tr("LAB_PARAVIS_DUMP");
257 tooltip = tr("TIP_PARAVIS_DUMP");
258 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
259 _salomeModule->createMenu(actionId, presentationMenuId);
262 // Actions for popup menu only
267 MEDCALC::ViewModeType
268 PresentationController::getSelectedViewMode() const
270 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
271 return MEDCALC::VIEW_MODE_REPLACE;
273 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
274 return MEDCALC::VIEW_MODE_OVERLAP;
276 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
277 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
279 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
280 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
283 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
284 return MEDCALC::VIEW_MODE_REPLACE;
287 MEDCALC::ColorMapType
288 PresentationController::getSelectedColorMap() const
290 return _widgetPresentationParameters->getColorMap();
293 MEDCALC::ScalarBarRangeType
294 PresentationController::getSelectedScalarBarRange() const
296 return _widgetPresentationParameters->getScalarBarRange();
300 PresentationController::visualize(PresentationEvent::EventType eventType)
302 // Get the selected objects in the study (SObject)
303 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
305 // For each object, emit a signal to the workspace to request a
306 // visualisation using the tui command (so that the user can see how
307 // to make a view of an object from the tui console).
308 for (int i=0; i<listOfSObject->size(); i++) {
309 SALOMEDS::SObject_var soObj = listOfSObject->at(i);
310 std::string name(_studyEditor->getName(soObj));
311 if (soObj->_is_nil() || name == "MEDCalc")
314 int fieldId = getIntParamFromStudyEditor(soObj, FIELD_ID);
315 int meshId = getIntParamFromStudyEditor(soObj, MESH_ID);
316 MEDCALC::FieldHandler* fieldHandler = 0;
317 MEDCALC::MeshHandler* meshHandler = 0;
322 if (eventType != PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW)
324 meshHandler = MEDFactoryClient::getDataManager()->getMeshHandler(meshId);
328 if (fieldId < 0) // is it a field serie ?
330 int fieldSeriesId = getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
331 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
332 // managed by the MED module, and we stop this function process.
333 if ( fieldSeriesId < 0)
336 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
337 if (fieldHandlerList->length() < 0)
339 // For a field series, get the first real field entry:
340 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
341 fieldId = fieldHandler.id;
343 fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
346 if ((!fieldHandler) && (!meshHandler)) {
347 QMessageBox::warning(_salomeModule->getApp()->desktop(),
348 tr("Operation not allowed"),
349 tr("No field (or mesh) is defined"));
353 PresentationEvent* event = new PresentationEvent();
354 event->eventtype = eventType;
355 event->fieldHandler = fieldHandler;
356 event->meshHandler = meshHandler;
357 emit presentationSignal(event); // --> processPresentationEvent()
362 PresentationController::onVisualizeMeshView()
364 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW);
368 PresentationController::onVisualizeScalarMap()
370 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
374 PresentationController::onVisualizeContour()
376 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
380 PresentationController::onVisualizeVectorField()
382 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
386 PresentationController::onVisualizeSlices()
388 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
392 PresentationController::onVisualizeDeflectionShape()
394 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
398 PresentationController::onVisualizePointSprite()
400 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
404 PresentationController::onDeletePresentation()
406 // Get the selected objects in the study (SObject)
407 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
409 // For each object, emit a signal to the workspace to request pres deletion
410 for (int i=0; i<listOfSObject->size(); i++) {
411 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
412 std::string name(_studyEditor->getName(soPres));
413 if (soPres->_is_nil() || name == "MEDCalc")
415 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
416 // If fieldId equals -1, then it means that it is not a field
417 // managed by the MED module, and we stop this function process.
421 PresentationEvent* event = new PresentationEvent();
422 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
423 event->presentationId = presId;
424 emit presentationSignal(event); // --> processPresentationEvent()
429 PresentationController::getViewModePython() const
431 MEDCALC::ViewModeType viewMode = getSelectedViewMode();
433 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
434 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
435 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
436 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
442 PresentationController::getColorMapPython() const
444 MEDCALC::ColorMapType colorMap = getSelectedColorMap();
446 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
447 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
453 PresentationController::getScalarBarRangePython() const
455 MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange();
457 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
458 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
464 PresentationController::getMeshModePython(const int mode) const
466 MEDCALC::MeshModeType mod = static_cast<MEDCALC::MeshModeType>(mode);
468 case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
469 case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
470 case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
476 PresentationController::getSliceOrientationPython(const int orientation) const
478 MEDCALC::SliceOrientationType orient = static_cast<MEDCALC::SliceOrientationType>(orientation);
480 case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
481 case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
482 case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
483 case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
484 case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
485 case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
486 case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
492 PresentationController::getPresTypeFromWidgetHelper(int presId) const
494 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
495 if (it != _presHelperMap.end())
496 return (*it).second->getPythonTag();
501 PresentationController::processPresentationEvent(const PresentationEvent* event) {
502 // --> Send commands to SALOME Python console
503 QString viewMode = getViewModePython();
504 QString colorMap = getColorMapPython();
505 QString scalarBarRange = getScalarBarRangePython();
506 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
507 QStringList commands;
509 // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each
510 // dedicated widget helper class?
512 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
513 // Do we request mesh view from a field or from a mesh only?
514 int meshId = event->meshHandler ? event->meshHandler->id : event->fieldHandler->meshid;
515 commands += QString("presentation_id = medcalc.MakeMeshView(%1, viewMode=%2)").arg(meshId).arg(viewMode);
516 commands += QString("presentation_id");
518 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
519 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
520 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
521 commands += QString("presentation_id");
523 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
524 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
525 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
526 commands += QString("presentation_id");
528 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
529 commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
530 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
531 commands += QString("presentation_id");
533 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
534 commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
535 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
536 commands += QString("presentation_id");
538 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
539 commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
540 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
541 commands += QString("presentation_id");
543 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
544 commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
545 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
546 commands += QString("presentation_id");
550 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
551 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
552 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
553 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
554 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
556 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
557 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
558 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
559 commands += QString("params.colorMap = %1").arg(getColorMapPython());
560 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
562 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
563 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
564 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
565 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
566 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
568 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
569 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
570 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
571 commands += QString("params.nbContours = %1").arg(event->anInteger);
572 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
574 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
575 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
576 commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
577 commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
578 commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
580 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
581 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
582 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
583 commands += QString("params.nbSlices = %1").arg(event->anInteger);
584 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
586 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
587 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
588 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
589 commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
590 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
593 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
594 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
597 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
599 _consoleDriver->exec(commands);
603 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
604 int presId, const std::string& type, const std::string& name )
606 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
607 if (it != _presHelperMap.end())
609 MEDWidgetHelper * wh = 0;
610 if (type == MEDPresentationMeshView::TYPE_NAME)
611 wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
612 else if (type == MEDPresentationScalarMap::TYPE_NAME)
613 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
614 else if (type == MEDPresentationContour::TYPE_NAME)
615 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
616 else if (type == MEDPresentationSlices::TYPE_NAME)
617 wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
618 else if (type == MEDPresentationVectorField::TYPE_NAME)
619 wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
620 else if (type == MEDPresentationPointSprite::TYPE_NAME)
621 wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
622 else if (type == MEDPresentationDeflectionShape::TYPE_NAME)
623 wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters);
626 const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!";
630 _presHelperMap[presId] = wh;
635 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
639 if (_widgetPresentationParameters->isShown())
641 _widgetPresentationParameters->toggleWidget(false);
642 if(_currentWidgetHelper)
643 _currentWidgetHelper->releaseWidget();
648 if(_currentWidgetHelper)
649 _currentWidgetHelper->releaseWidget();
650 // Activate corresponding ParaView render view
651 _presManager->activateView(presId);
652 // Update widgets parameters
653 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
654 _currentWidgetHelper->updateWidget(true);
659 PresentationController::onParavisDump()
661 // Get the selected objects in the study (SObject)
662 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
664 // For the first object only, request the dump
665 for (int i=0; i<listOfSObject->size(); i++) {
666 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
667 std::string name(_studyEditor->getName(soPres));
668 if (soPres->_is_nil() || name == "MEDCalc")
670 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
671 // If fieldId equals -1, then it means that it is not a field
672 // managed by the MED module, and we stop this function process.
676 std::string dump(_presManager->getParavisDump(presId));
677 std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl;
679 std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
681 break; // stop at the first one
686 PresentationController::updateTreeViewWithNewPresentation(long dataId, long presentationId)
688 if (presentationId < 0) {
689 std::cerr << "Unknown presentation\n";
693 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
694 std::string type = name;
695 std::string icon = std::string("ICO_") + type;
696 icon = _getIconName(icon);
697 std::string ico = tr(icon.c_str()).toStdString();
699 // Append presentation ID to the displayed name in the OB:
700 std::ostringstream oss;
701 name = tr(name.c_str()).toStdString();
702 oss << name << " (" << presentationId << ")";
704 // Mesh views are always registered at the mesh level:
705 if (type == MEDPresentationMeshView::TYPE_NAME)
707 _salomeModule->engine()->registerPresentationMesh(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
710 _salomeModule->engine()->registerPresentationField(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
712 // update Object browser
713 _salomeModule->getApp()->updateObjectBrowser(true);
715 // auto-select new presentation
716 std::string entry = _salomeModule->engine()->getStudyPresentationEntry(presentationId);
717 SALOME_ListIO selectedObjects;
718 LightApp_Study* lightStudy = dynamic_cast<LightApp_Study*>( _salomeModule->application()->activeStudy() );
719 QString component = lightStudy->componentDataType( entry.c_str() );
720 selectedObjects.Append( new SALOME_InteractiveObject( (const char*)entry.c_str(),
721 (const char*)component.toLatin1(),
722 ""/*refobj->Name().c_str()*/ ) );
723 //QStringList selectedObjects;
724 //selectedObjects << QString(entry.c_str());
725 LightApp_SelectionMgr* aSelectionMgr = _salomeModule->getApp()->selectionMgr();
726 aSelectionMgr->setSelectedObjects(selectedObjects, false);
728 // emit onPresentationSelected
730 _salomeModule->itemClickGeneric(name, type, presId);
731 onPresentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name));
735 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
737 if (presentationId < 0) {
738 std::cerr << "Unknown presentation\n";
742 _salomeModule->engine()->unregisterPresentation(presentationId);
744 // update Object browser
745 _salomeModule->getApp()->updateObjectBrowser(true);
749 PresentationController::_dealWithReplaceMode()
751 // Deal with replace mode: presentations with invalid IDs have to be removed:
753 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
754 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations();
755 // The IDs not in the intersection needs deletion:
756 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
757 for (unsigned i = 0; i < lstModule->length(); i++) {
758 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
760 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
761 // Presentation in module but not in manager anymore: to be deleted from OB:
762 updateTreeViewForPresentationRemoval((*lstModule)[i]);
768 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
770 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
771 if (event->dataId == -1) {
772 // A file has been loaded, and we want to create a default presentation (MeshView) for it
773 QString viewMode = getViewModePython();
774 QStringList commands;
775 commands += QString("presentation_id = medcalc.MakeMeshView(medcalc.GetFirstMeshFromDataSource(source_id), viewMode=%1)").arg(viewMode);
776 commands += QString("presentation_id");
777 _consoleDriver->exec(commands);
780 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
781 _dealWithReplaceMode();
784 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
785 updateTreeViewForPresentationRemoval(event->presentationId);
786 // Hide parameter widget if necessary:
787 onPresentationSelected(-1, "", "");
789 else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
790 // Update parameter widget if shown:
791 if(_currentWidgetHelper)
792 _currentWidgetHelper->updateWidget(false);
797 PresentationController::showDockWidgets(bool isVisible)
799 _dockWidget->setVisible(isVisible);