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::_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<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")
298 int fieldId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_ID);
299 int meshId = _salomeModule->getIntParamFromStudyEditor(soObj, MESH_ID);
300 MEDCALC::FieldHandler* fieldHandler = 0;
301 MEDCALC::MeshHandler* meshHandler = 0;
306 if (eventType != PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW)
308 meshHandler = MEDFactoryClient::getDataManager()->getMeshHandler(meshId);
312 if (fieldId < 0) // is it a field series?
314 int fieldSeriesId = _salomeModule->getIntParamFromStudyEditor(soObj, FIELD_SERIES_ID);
315 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
316 // managed by the MED module, and we stop this function process.
317 if ( fieldSeriesId < 0)
320 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
321 if (fieldHandlerList->length() < 0)
323 // For a field series, get the first real field entry:
324 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
325 fieldId = fieldHandler.id;
327 fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
330 if ((!fieldHandler) && (!meshHandler)) {
331 QMessageBox::warning(_salomeModule->getApp()->desktop(),
332 tr("Operation not allowed"),
333 tr("No field (or mesh) is defined"));
337 PresentationEvent* event = new PresentationEvent();
338 event->eventtype = eventType;
339 event->fieldHandler = fieldHandler;
340 event->meshHandler = meshHandler;
341 emit presentationSignal(event); // --> processPresentationEvent()
346 PresentationController::onVisualizeMeshView()
348 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW);
352 PresentationController::onVisualizeScalarMap()
354 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
358 PresentationController::onVisualizeContour()
360 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
364 PresentationController::onVisualizeVectorField()
366 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
370 PresentationController::onVisualizeSlices()
372 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
376 PresentationController::onVisualizeDeflectionShape()
378 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
382 PresentationController::onVisualizePointSprite()
384 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
388 PresentationController::onDeletePresentation()
390 // Get the selected objects in the study (SObject)
391 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
393 // For each object, emit a signal to the workspace to request pres deletion
394 for (int i=0; i<listOfSObject->size(); i++) {
395 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
396 std::string name(_studyEditor->getName(soPres));
397 if (soPres->_is_nil() || name == "MEDCalc")
399 int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
400 // If fieldId equals -1, then it means that it is not a field
401 // managed by the MED module, and we stop this function process.
405 PresentationEvent* event = new PresentationEvent();
406 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
407 event->presentationId = presId;
408 emit presentationSignal(event); // --> processPresentationEvent()
413 PresentationController::getViewModePython() const
415 MEDCALC::ViewModeType viewMode = getSelectedViewMode();
417 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
418 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
419 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
420 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
426 PresentationController::getColorMapPython() const
428 MEDCALC::ColorMapType colorMap = getSelectedColorMap();
430 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
431 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
437 PresentationController::getScalarBarRangePython() const
439 MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange();
441 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
442 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
448 PresentationController::getMeshModePython(const int mode) const
450 MEDCALC::MeshModeType mod = static_cast<MEDCALC::MeshModeType>(mode);
452 case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
453 case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
454 case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
460 PresentationController::getSliceOrientationPython(const int orientation) const
462 MEDCALC::SliceOrientationType orient = static_cast<MEDCALC::SliceOrientationType>(orientation);
464 case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
465 case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
466 case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
467 case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
468 case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
469 case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
470 case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
476 PresentationController::getPresTypeFromWidgetHelper(int presId) const
478 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
479 if (it != _presHelperMap.end())
480 return (*it).second->getPythonTag();
485 PresentationController::processPresentationEvent(const PresentationEvent* event) {
486 // --> Send commands to SALOME Python console
487 QString viewMode = getViewModePython();
488 QString colorMap = getColorMapPython();
489 QString scalarBarRange = getScalarBarRangePython();
490 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
491 QStringList commands;
493 // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each
494 // dedicated widget helper class?
496 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
497 // Do we request mesh view from a field or from a mesh only?
498 int meshId = event->meshHandler ? event->meshHandler->id : event->fieldHandler->meshid;
499 commands += QString("presentation_id = medcalc.MakeMeshView(%1, viewMode=%2)").arg(meshId).arg(viewMode);
500 commands += QString("presentation_id");
502 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
503 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
504 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
505 commands += QString("presentation_id");
507 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
508 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
509 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
510 commands += QString("presentation_id");
512 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
513 commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
514 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
515 commands += QString("presentation_id");
517 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
518 commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
519 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
520 commands += QString("presentation_id");
522 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
523 commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
524 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
525 commands += QString("presentation_id");
527 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
528 commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
529 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
530 commands += QString("presentation_id");
534 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
535 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
536 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
537 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
538 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
540 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
541 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
542 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
543 commands += QString("params.colorMap = %1").arg(getColorMapPython());
544 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
546 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
547 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
548 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
549 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
550 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
552 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
553 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
554 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
555 commands += QString("params.nbContours = %1").arg(event->anInteger);
556 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
558 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
559 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
560 commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
561 commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
562 commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
564 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
565 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
566 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
567 commands += QString("params.nbSlices = %1").arg(event->anInteger);
568 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
570 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
571 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
572 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
573 commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
574 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
577 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
578 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
581 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
583 _consoleDriver->exec(commands);
587 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
588 int presId, const std::string& type, const std::string& name )
590 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
591 if (it != _presHelperMap.end())
593 MEDWidgetHelper * wh = 0;
594 if (type == MEDPresentationMeshView::TYPE_NAME)
595 wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
596 else if (type == MEDPresentationScalarMap::TYPE_NAME)
597 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
598 else if (type == MEDPresentationContour::TYPE_NAME)
599 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
600 else if (type == MEDPresentationSlices::TYPE_NAME)
601 wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
602 else if (type == MEDPresentationVectorField::TYPE_NAME)
603 wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
604 else if (type == MEDPresentationPointSprite::TYPE_NAME)
605 wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
606 else if (type == MEDPresentationDeflectionShape::TYPE_NAME)
607 wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters);
610 const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!";
614 _presHelperMap[presId] = wh;
619 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
623 if (_widgetPresentationParameters->isShown())
625 _widgetPresentationParameters->toggleWidget(false);
626 if(_currentWidgetHelper)
627 _currentWidgetHelper->releaseWidget();
632 if(_currentWidgetHelper)
633 _currentWidgetHelper->releaseWidget();
634 // Activate corresponding ParaView render view
635 _presManager->activateView(presId);
636 // Update widgets parameters
637 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
638 _currentWidgetHelper->updateWidget(true);
643 PresentationController::onParavisDump()
645 // Get the selected objects in the study (SObject)
646 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
648 // For the first object only, request the dump
649 for (int i=0; i<listOfSObject->size(); i++) {
650 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
651 std::string name(_studyEditor->getName(soPres));
652 if (soPres->_is_nil() || name == "MEDCalc")
654 int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
655 // If fieldId equals -1, then it means that it is not a field
656 // managed by the MED module, and we stop this function process.
660 std::string dump(_presManager->getParavisDump(presId));
661 std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl;
663 std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
665 break; // stop at the first one
670 PresentationController::updateTreeViewWithNewPresentation(long dataId, long presentationId)
672 if (presentationId < 0) {
673 std::cerr << "Unknown presentation\n";
677 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
678 std::string type = name;
679 std::string icon = std::string("ICO_") + type;
680 icon = _getIconName(icon);
681 std::string ico = tr(icon.c_str()).toStdString();
683 // Append presentation ID to the displayed name in the OB:
684 std::ostringstream oss;
685 name = tr(name.c_str()).toStdString();
686 oss << name << " (" << presentationId << ")";
688 // Mesh views are always registered at the mesh level:
689 if (type == MEDPresentationMeshView::TYPE_NAME)
691 _salomeModule->engine()->registerPresentationMesh(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
694 _salomeModule->engine()->registerPresentationField(dataId, oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
696 // update Object browser
697 _salomeModule->getApp()->updateObjectBrowser(true);
699 // auto-select new presentation
700 std::string entry = _salomeModule->engine()->getStudyPresentationEntry(presentationId);
701 SALOME_ListIO selectedObjects;
702 LightApp_Study* lightStudy = dynamic_cast<LightApp_Study*>( _salomeModule->application()->activeStudy() );
703 QString component = lightStudy->componentDataType( entry.c_str() );
704 selectedObjects.Append( new SALOME_InteractiveObject( (const char*)entry.c_str(),
705 (const char*)component.toLatin1(),
706 ""/*refobj->Name().c_str()*/ ) );
707 //QStringList selectedObjects;
708 //selectedObjects << QString(entry.c_str());
709 LightApp_SelectionMgr* aSelectionMgr = _salomeModule->getApp()->selectionMgr();
710 aSelectionMgr->setSelectedObjects(selectedObjects, false);
712 // emit onPresentationSelected
714 _salomeModule->itemClickGeneric(name, type, presId);
715 onPresentationSelected(presId, QString::fromStdString(type), QString::fromStdString(name));
719 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
721 if (presentationId < 0) {
722 std::cerr << "Unknown presentation\n";
726 _salomeModule->engine()->unregisterPresentation(presentationId);
728 // update Object browser
729 _salomeModule->getApp()->updateObjectBrowser(true);
733 PresentationController::_dealWithReplaceMode()
735 // Deal with replace mode: presentations with invalid IDs have to be removed:
737 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
738 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations();
739 // The IDs not in the intersection needs deletion:
740 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
741 for (unsigned i = 0; i < lstModule->length(); i++) {
742 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
744 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
745 // Presentation in module but not in manager anymore: to be deleted from OB:
746 updateTreeViewForPresentationRemoval((*lstModule)[i]);
752 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
754 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
755 if (event->dataId == -1) {
756 // A file has been loaded, and we want to create a default presentation (MeshView) for it
757 QString viewMode = getViewModePython();
758 QStringList commands;
759 commands += QString("presentation_id = medcalc.MakeMeshView(medcalc.GetFirstMeshFromDataSource(source_id), viewMode=%1)").arg(viewMode);
760 commands += QString("presentation_id");
761 _consoleDriver->exec(commands);
764 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
765 _dealWithReplaceMode();
768 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
769 updateTreeViewForPresentationRemoval(event->presentationId);
770 // Hide parameter widget if necessary:
771 onPresentationSelected(-1, "", "");
773 else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
774 // Update parameter widget if shown:
775 if(_currentWidgetHelper)
776 _currentWidgetHelper->updateWidget(false);
781 PresentationController::showDockWidgets(bool isVisible)
783 _dockWidget->setVisible(isVisible);