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 <SALOMEDS_SObject.hxx>
51 #include <SALOMEDS_Study.hxx>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <QMessageBox>
59 #include "MEDFactoryClient.hxx"
61 static const int OPTIONS_VIEW_MODE_ID = 943;
62 static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
63 static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
64 static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
65 static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
67 //! The only instance of the MEDPresentationManager
68 MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
70 PresentationController::PresentationController(MEDModule* salomeModule) :
71 _salomeModule(salomeModule),
73 _studyEditor(salomeModule->getStudyEditor()),
75 _currentWidgetHelper(0)
77 STDLOG("Creating a PresentationController");
79 _widgetPresentationParameters = new WidgetPresentationParameters();
81 QMainWindow* parent = salomeModule->getApp()->desktop();
82 _dockWidget = new QDockWidget(parent);
83 _dockWidget->setVisible(false);
84 _dockWidget->setWindowTitle(tr("TITLE_PRESENTATION_PARAMETERS"));
85 _dockWidget->setObjectName(tr("TITLE_PRESENTATION_PARAMETERS"));
86 _dockWidget->setFeatures(QDockWidget::AllDockWidgetFeatures);
87 _dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
88 _dockWidget->setWidget(_widgetPresentationParameters);
89 parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
90 //_dockWidget->show();
92 // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
93 if ( ! _presManager ) {
94 _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
97 // Connect to the click in the object browser
98 connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
99 this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
102 PresentationController::~PresentationController()
104 STDLOG("Deleting the resentationController");
105 // Clean allocated widget helpers:
106 for ( std::map<int, MEDWidgetHelper *>::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
107 delete((*it).second);
111 * [ABN] Created this probably because I don't know the right way to deal with non existent
112 * attributes in an object from the study ...
115 PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name)
119 theInt = _studyEditor->getParameterInt(obj,name);
126 PresentationController::_getIconName(const std::string& name)
128 SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
132 // Read value from preferences and suffix name to select icon theme
133 int theme = mgr->integerValue("MEDCalc", "icons");
135 return name + "_MODERN";
136 } else if (theme == 1) {
137 return name + "_CLASSIC";
139 return name + "_DEFAULT";
143 PresentationController::createActions()
145 STDLOG("Creating PresentationController actions");
148 int viewModeToolbarId = _salomeModule->createTool("View Mode", "ViewModeToolbar");
149 QtxActionGroup* ag = _salomeModule->createActionGroup(OPTIONS_VIEW_MODE_ID, true);
150 ag->setText("View mode");
151 ag->setUsesDropDown(true);
152 QString label = tr("LAB_VIEW_MODE_REPLACE");
153 QString tooltip = tr("TIP_VIEW_MODE_REPLACE");
154 QAction* a = _salomeModule->createAction(OPTIONS_VIEW_MODE_REPLACE_ID,label,QIcon(),label,tooltip,0);
155 a->setCheckable(true);
159 label = tr("LAB_VIEW_MODE_OVERLAP");
160 tooltip = tr("TIP_VIEW_MODE_OVERLAP");
161 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_OVERLAP_ID,label,QIcon(),label,tooltip,0);
162 a->setCheckable(true);
165 label = tr("LAB_VIEW_MODE_NEW_LAYOUT");
166 tooltip = tr("TIP_VIEW_MODE_NEW_LAYOUT");
167 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID,label,QIcon(),label,tooltip,0);
168 a->setCheckable(true);
171 label = tr("LAB_VIEW_MODE_SPLIT_VIEW");
172 tooltip = tr("TIP_VIEW_MODE_SPLIT_VIEW");
173 a = _salomeModule->createAction(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID,label,QIcon(),label,tooltip,0);
174 a->setCheckable(true);
177 _salomeModule->createTool(OPTIONS_VIEW_MODE_ID, viewModeToolbarId);
180 int presentationToolbarId = _salomeModule->createTool("Presentations", "PresentationToolbar");
181 int presentationMenuId = _salomeModule->createMenu(tr("MENU_PRESENTATIONS"), -1, 1);
183 label = tr("LAB_PRESENTATION_MESH_VIEW");
184 tooltip = tr("TIP_PRESENTATION_MESH_VIEW");
185 QString icon = tr(_getIconName("ICO_PRESENTATION_MESH_VIEW").c_str());
187 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeMeshView()),icon,tooltip);
188 _salomeModule->createTool(actionId, presentationToolbarId);
189 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
190 _salomeModule->createMenu(actionId, presentationMenuId);
192 label = tr("LAB_PRESENTATION_SCALAR_MAP");
193 tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
194 icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
195 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip);
196 _salomeModule->createTool(actionId, presentationToolbarId);
197 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
198 _salomeModule->createMenu(actionId, presentationMenuId);
200 label = tr("LAB_PRESENTATION_CONTOUR");
201 tooltip = tr("TIP_PRESENTATION_CONTOUR");
202 icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
203 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
204 _salomeModule->createTool(actionId, presentationToolbarId);
205 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
206 _salomeModule->createMenu(actionId, presentationMenuId);
208 label = tr("LAB_PRESENTATION_VECTOR_FIELD");
209 tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
210 icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
211 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
212 _salomeModule->createTool(actionId, presentationToolbarId);
213 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
214 _salomeModule->createMenu(actionId, presentationMenuId);
216 label = tr("LAB_PRESENTATION_SLICES");
217 tooltip = tr("TIP_PRESENTATION_SLICES");
218 icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
219 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
220 _salomeModule->createTool(actionId, presentationToolbarId);
221 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
222 _salomeModule->createMenu(actionId, presentationMenuId);
224 label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
225 tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
226 icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
227 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
228 _salomeModule->createTool(actionId, presentationToolbarId);
229 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
230 _salomeModule->createMenu(actionId, presentationMenuId);
232 label = tr("LAB_PRESENTATION_POINT_SPRITE");
233 tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
234 icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
235 actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
236 _salomeModule->createTool(actionId, presentationToolbarId);
237 _salomeModule->action(actionId)->setIconVisibleInMenu(true);
238 _salomeModule->createMenu(actionId, presentationMenuId);
241 _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
243 label = tr("LAB_DELETE_PRESENTATION");
244 tooltip = tr("TIP_DELETE_PRESENTATION");
245 icon = tr("ICO_DELETE_PRESENTATION");
246 actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
247 // _salomeModule->createTool(actionId, presentationToolbarId);
248 // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
249 _salomeModule->createMenu(actionId, presentationMenuId);
251 // Low level PARAVIS dump
252 label = tr("LAB_PARAVIS_DUMP");
253 tooltip = tr("TIP_PARAVIS_DUMP");
254 actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
255 _salomeModule->createMenu(actionId, presentationMenuId);
258 // Actions for popup menu only
263 MEDCALC::ViewModeType
264 PresentationController::getSelectedViewMode() const
266 if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
267 return MEDCALC::VIEW_MODE_REPLACE;
269 else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
270 return MEDCALC::VIEW_MODE_OVERLAP;
272 else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
273 return MEDCALC::VIEW_MODE_NEW_LAYOUT;
275 else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
276 return MEDCALC::VIEW_MODE_SPLIT_VIEW;
279 STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
280 return MEDCALC::VIEW_MODE_REPLACE;
283 MEDCALC::ColorMapType
284 PresentationController::getSelectedColorMap() const
286 return _widgetPresentationParameters->getColorMap();
289 MEDCALC::ScalarBarRangeType
290 PresentationController::getSelectedScalarBarRange() const
292 return _widgetPresentationParameters->getScalarBarRange();
296 PresentationController::visualize(PresentationEvent::EventType eventType)
298 // We need a _studyEditor updated on the active study
299 _studyEditor->updateActiveStudy();
301 // Get the selected objects in the study (SObject)
302 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
304 // For each object, emit a signal to the workspace to request a
305 // visualisation using the tui command (so that the user can see how
306 // to make a view of an object from the tui console).
307 for (int i=0; i<listOfSObject->size(); i++) {
308 SALOMEDS::SObject_var soField = listOfSObject->at(i);
309 int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
310 if (fieldId < 0) // is it a field serie ?
312 int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
313 // If fieldId and fieldSeriesId equals -1, then it means that it is not a field
314 // managed by the MED module, and we stop this function process.
315 if ( fieldSeriesId < 0)
317 MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
318 if (fieldHandlerList->length() < 0)
320 // For a field series, get the first real field entry:
321 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
322 fieldId = fieldHandler.id;
325 MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
326 if (! fieldHandler) {
327 QMessageBox::warning(_salomeModule->getApp()->desktop(),
328 tr("Operation not allowed"),
329 tr("No field is defined"));
333 PresentationEvent* event = new PresentationEvent();
334 event->eventtype = eventType;
335 event->fieldHandler = fieldHandler;
336 emit presentationSignal(event); // --> processPresentationEvent()
341 PresentationController::onVisualizeMeshView()
343 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW);
347 PresentationController::onVisualizeScalarMap()
349 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
353 PresentationController::onVisualizeContour()
355 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
359 PresentationController::onVisualizeVectorField()
361 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
365 PresentationController::onVisualizeSlices()
367 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
371 PresentationController::onVisualizeDeflectionShape()
373 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
377 PresentationController::onVisualizePointSprite()
379 this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
383 PresentationController::onDeletePresentation()
385 // We need a _studyEditor updated on the active study
386 _studyEditor->updateActiveStudy();
388 // Get the selected objects in the study (SObject)
389 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
391 // For each object, emit a signal to the workspace to request pres deletion
392 for (int i=0; i<listOfSObject->size(); i++) {
393 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
394 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
395 // If fieldId equals -1, then it means that it is not a field
396 // managed by the MED module, and we stop this function process.
400 PresentationEvent* event = new PresentationEvent();
401 event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
402 event->presentationId = presId;
403 emit presentationSignal(event); // --> processPresentationEvent()
408 PresentationController::getViewModePython() const
410 MEDCALC::ViewModeType viewMode = getSelectedViewMode();
412 case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
413 case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
414 case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
415 case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
421 PresentationController::getColorMapPython() const
423 MEDCALC::ColorMapType colorMap = getSelectedColorMap();
425 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
426 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
432 PresentationController::getScalarBarRangePython() const
434 MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange();
436 case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
437 case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
443 PresentationController::getMeshModePython(const int mode) const
445 MEDCALC::MeshModeType mod = static_cast<MEDCALC::MeshModeType>(mode);
447 case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
448 case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
449 case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
455 PresentationController::getSliceOrientationPython(const int orientation) const
457 MEDCALC::SliceOrientationType orient = static_cast<MEDCALC::SliceOrientationType>(orientation);
459 case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
460 case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
461 case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
462 case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
463 case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
464 case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
465 case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
471 PresentationController::getPresTypeFromWidgetHelper(int presId) const
473 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
474 if (it != _presHelperMap.end())
475 return (*it).second->getPythonTag();
480 PresentationController::processPresentationEvent(const PresentationEvent* event) {
481 // --> Send commands to SALOME Python console
482 QString viewMode = getViewModePython();
483 QString colorMap = getColorMapPython();
484 QString scalarBarRange = getScalarBarRangePython();
485 MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
486 QStringList commands;
488 // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each
489 // dedicated widget helper class?
491 if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
492 commands += QString("presentation_id = medcalc.MakeMeshView(accessField(%1), viewMode=%2)").arg(fieldHandler->id).arg(viewMode);
493 commands += QString("presentation_id");
495 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
496 commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
497 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
498 commands += QString("presentation_id");
500 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
501 commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
502 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
503 commands += QString("presentation_id");
505 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
506 commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
507 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
508 commands += QString("presentation_id");
510 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
511 commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
512 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
513 commands += QString("presentation_id");
515 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
516 commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
517 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
518 commands += QString("presentation_id");
520 else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
521 commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
522 .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
523 commands += QString("presentation_id");
527 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
528 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
529 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
530 commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
531 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
533 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
534 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
535 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
536 commands += QString("params.colorMap = %1").arg(getColorMapPython());
537 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
539 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
540 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
541 commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
542 commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
543 commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
545 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
546 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
547 commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
548 commands += QString("params.nbContours = %1").arg(event->anInteger);
549 commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
551 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
552 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
553 commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
554 commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
555 commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
557 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
558 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
559 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
560 commands += QString("params.nbSlices = %1").arg(event->anInteger);
561 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
563 else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
564 std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
565 commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
566 commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
567 commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
570 else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
571 commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
574 STDLOG("The event "<<event->eventtype<<" is not implemented yet");
576 _consoleDriver->exec(commands);
580 PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
581 int presId, const std::string& type, const std::string& name )
583 std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
584 if (it != _presHelperMap.end())
586 MEDWidgetHelper * wh = 0;
587 if (type == MEDPresentationMeshView::TYPE_NAME)
588 wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
589 else if (type == MEDPresentationScalarMap::TYPE_NAME)
590 wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
591 else if (type == MEDPresentationContour::TYPE_NAME)
592 wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
593 else if (type == MEDPresentationSlices::TYPE_NAME)
594 wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
595 else if (type == MEDPresentationVectorField::TYPE_NAME)
596 wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
597 else if (type == MEDPresentationPointSprite::TYPE_NAME)
598 wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
599 else if (type == MEDPresentationDeflectionShape::TYPE_NAME)
600 wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters);
603 const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!";
606 _presHelperMap[presId] = wh;
611 PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
615 if (_widgetPresentationParameters->isShown())
617 _widgetPresentationParameters->toggleWidget(false);
618 if(_currentWidgetHelper)
619 _currentWidgetHelper->releaseWidget();
624 // Activate corresponding ParaView render view
625 _presManager->activateView(presId);
626 // Update widgets parameters
627 _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
628 _currentWidgetHelper->updateWidget(true);
633 PresentationController::onParavisDump()
635 // We need a _studyEditor updated on the active study
636 _studyEditor->updateActiveStudy();
638 // Get the selected objects in the study (SObject)
639 SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
641 // For the first object only, request the dump
642 for (int i=0; i<listOfSObject->size(); i++) {
643 SALOMEDS::SObject_var soPres = listOfSObject->at(i);
644 int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
645 // If fieldId equals -1, then it means that it is not a field
646 // managed by the MED module, and we stop this function process.
650 std::string dump(_presManager->getParavisDump(presId));
651 std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl;
653 std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
655 break; // stop at the first one
660 PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
662 if (presentationId < 0) {
663 std::cerr << "Unknown presentation\n";
667 std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
668 std::string type = name;
669 std::string icon = std::string("ICO_") + type;
670 icon = _getIconName(icon);
671 std::string ico = tr(icon.c_str()).toStdString();
673 // Append presentation ID to the displayed name in the OB:
674 std::ostringstream oss;
675 name = tr(name.c_str()).toStdString();
676 oss << name << " (" << presentationId << ")";
678 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
679 _PTR(Study) studyDS = study->studyDS();
681 _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId,
682 oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
685 // MEDCALC::ViewModeType viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
687 // // Remove sibling presentations if view mode is set to REPLACE
688 // if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
689 // MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
690 // CORBA::ULong size = presList->length();
692 // std::stringstream sstm;
693 // sstm << "Removing sibling presentation(s): ";
694 // for (int i = 0; i < size; ++i)
695 // sstm << (*presList)[i] << " ";
696 // STDLOG(sstm.str());
698 // for (int i = 0; i < size; ++i) {
699 // PresentationEvent* event = new PresentationEvent();
700 // event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
701 // XmedDataObject* dataObject = new XmedDataObject();
702 // dataObject->setPresentationId((*presList)[i]);
703 // event->objectdata = dataObject;
704 // emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
710 // update Object browser
711 _salomeModule->getApp()->updateObjectBrowser(true);
715 PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
717 if (presentationId < 0) {
718 std::cerr << "Unknown presentation\n";
722 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
723 _PTR(Study) studyDS = study->studyDS();
725 _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
727 // update Object browser
728 _salomeModule->getApp()->updateObjectBrowser(true);
732 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
734 if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
735 updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
736 // Deal with replace mode: presentations with invalid IDs have to be removed:
737 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
738 _PTR(Study) studyDS = study->studyDS();
740 MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
741 MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations(_CAST(Study, studyDS)->GetStudy());
742 // The IDs not in the intersection needs deletion:
743 CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
744 for (unsigned i = 0; i < lstModule->length(); i++)
746 CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
749 STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
750 // Presentation in module but not in manager anymore: to be deleted from OB:
751 updateTreeViewForPresentationRemoval((*lstModule)[i]);
752 onPresentationSelected(-1, "", ""); // make sure param widget is hidden
756 else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
757 updateTreeViewForPresentationRemoval(event->presentationId);
759 else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
760 // Update parameter widget if shown:
761 if(_currentWidgetHelper)
762 _currentWidgetHelper->updateWidget(false);
767 PresentationController::showDockWidgets(bool isVisible)
769 _dockWidget->setVisible(isVisible);