+PresentationController::onDeletePresentation()
+{
+ // We need a _studyEditor updated on the active study
+ _studyEditor->updateActiveStudy();
+
+ // Get the selected objects in the study (SObject)
+ SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
+
+ // For each object, emit a signal to the workspace to request pres deletion
+ for (int i=0; i<listOfSObject->size(); i++) {
+ SALOMEDS::SObject_var soPres = listOfSObject->at(i);
+ std::string name(_studyEditor->getName(soPres));
+ if (soPres->_is_nil() || name == "MEDCalc")
+ return;
+ int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
+ // If fieldId equals -1, then it means that it is not a field
+ // managed by the MED module, and we stop this function process.
+ if ( presId < 0 )
+ continue;
+
+ PresentationEvent* event = new PresentationEvent();
+ event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
+ event->presentationId = presId;
+ emit presentationSignal(event); // --> processPresentationEvent()
+ }
+}
+
+QString
+PresentationController::getViewModePython() const
+{
+ MEDCALC::ViewModeType viewMode = getSelectedViewMode();
+ switch(viewMode) {
+ case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
+ case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
+ case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
+ case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
+ }
+ return QString();
+}
+
+QString
+PresentationController::getColorMapPython() const
+{
+ MEDCALC::ColorMapType colorMap = getSelectedColorMap();
+ switch(colorMap) {
+ case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
+ case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
+ }
+ return QString();
+}
+
+QString
+PresentationController::getScalarBarRangePython() const
+{
+ MEDCALC::ScalarBarRangeType colorMap = getSelectedScalarBarRange();
+ switch(colorMap) {
+ case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
+ case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
+ }
+ return QString();
+}
+
+QString
+PresentationController::getMeshModePython(const int mode) const
+{
+ MEDCALC::MeshModeType mod = static_cast<MEDCALC::MeshModeType>(mode);
+ switch(mod) {
+ case MEDCALC::MESH_MODE_WIREFRAME: return "MEDCALC.MESH_MODE_WIREFRAME";
+ case MEDCALC::MESH_MODE_SURFACE: return "MEDCALC.MESH_MODE_SURFACE";
+ case MEDCALC::MESH_MODE_SURFACE_EDGES: return "MEDCALC.MESH_MODE_SURFACE_EDGES";
+ }
+ return QString();
+}
+
+QString
+PresentationController::getSliceOrientationPython(const int orientation) const
+{
+ MEDCALC::SliceOrientationType orient = static_cast<MEDCALC::SliceOrientationType>(orientation);
+ switch(orient) {
+ case MEDCALC::SLICE_NORMAL_TO_X: return "MEDCALC.SLICE_NORMAL_TO_X";
+ case MEDCALC::SLICE_NORMAL_TO_Y: return "MEDCALC.SLICE_NORMAL_TO_Y";
+ case MEDCALC::SLICE_NORMAL_TO_Z: return "MEDCALC.SLICE_NORMAL_TO_Z";
+ case MEDCALC::SLICE_NORMAL_TO_XY: return "MEDCALC.SLICE_NORMAL_TO_XY";
+ case MEDCALC::SLICE_NORMAL_TO_XZ: return "MEDCALC.SLICE_NORMAL_TO_XZ";
+ case MEDCALC::SLICE_NORMAL_TO_YZ: return "MEDCALC.SLICE_NORMAL_TO_YZ";
+ case MEDCALC::SLICE_NORMAL_TO_XYZ: return "MEDCALC.SLICE_NORMAL_TO_XYZ";
+ }
+ return QString();
+}
+
+std::string
+PresentationController::getPresTypeFromWidgetHelper(int presId) const
+{
+ std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
+ if (it != _presHelperMap.end())
+ return (*it).second->getPythonTag();
+ return "UNKNOWN";
+}
+
+void
+PresentationController::processPresentationEvent(const PresentationEvent* event) {
+ // --> Send commands to SALOME Python console
+ QString viewMode = getViewModePython();
+ QString colorMap = getColorMapPython();
+ QString scalarBarRange = getScalarBarRangePython();
+ MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
+ QStringList commands;
+
+ // [ABN] using event mechanism for all this is awkward? TODO: direct implementation in each
+ // dedicated widget helper class?
+
+ if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_MESH_VIEW ) {
+ // Do we request mesh view from a field or from a mesh only?
+ int meshId = event->meshHandler ? event->meshHandler->id : event->fieldHandler->meshid;
+ commands += QString("presentation_id = medcalc.MakeMeshView(%1, viewMode=%2)").arg(meshId).arg(viewMode);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
+ commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
+ commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
+ commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
+ commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
+ commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
+ commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+
+
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
+ commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ commands += QString("params.colorMap = %1").arg(getColorMapPython());
+ commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
+ commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_CONTOUR ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
+ commands += QString("params.nbContours = %1").arg(event->anInteger);
+ commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_MESH_MODE ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.GetMeshViewParameters(%2)").arg(event->presentationId);
+ commands += QString("params.mode = %1").arg(getMeshModePython(event->anInteger));
+ commands += QString("medcalc.UpdateMeshView(%1, params)").arg(event->presentationId);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_NB_SLICES ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
+ commands += QString("params.nbSlices = %1").arg(event->anInteger);
+ commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.GetSlicesParameters(%2)").arg(event->presentationId);
+ commands += QString("params.orientation = %1").arg(getSliceOrientationPython(event->anInteger));
+ commands += QString("medcalc.UpdateSlices(%1, params)").arg(event->presentationId);
+ }
+
+ else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
+ commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
+ }
+ else {
+ STDLOG("The event "<<event->eventtype<<" is not implemented yet");
+ }
+ _consoleDriver->exec(commands);
+}
+
+MEDWidgetHelper *
+PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
+ int presId, const std::string& type, const std::string& name )
+{
+ std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
+ if (it != _presHelperMap.end())
+ return (*it).second;
+ MEDWidgetHelper * wh = 0;
+ if (type == MEDPresentationMeshView::TYPE_NAME)
+ wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationScalarMap::TYPE_NAME)
+ wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationContour::TYPE_NAME)
+ wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationSlices::TYPE_NAME)
+ wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationVectorField::TYPE_NAME)
+ wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationPointSprite::TYPE_NAME)
+ wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationDeflectionShape::TYPE_NAME)
+ wh = new MEDWidgetHelperDeflectionShape(this, _presManager, presId, name, _widgetPresentationParameters);
+ else
+ {
+ const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!";
+ STDLOG(msg);
+ return wh;
+ }
+ _presHelperMap[presId] = wh;
+ return wh;
+}
+
+void
+PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
+{
+ if (presId == -1)
+ {
+ if (_widgetPresentationParameters->isShown())
+ {
+ _widgetPresentationParameters->toggleWidget(false);
+ if(_currentWidgetHelper)
+ _currentWidgetHelper->releaseWidget();
+ }
+ }
+ else
+ {
+ if(_currentWidgetHelper)
+ _currentWidgetHelper->releaseWidget();
+ // Activate corresponding ParaView render view
+ _presManager->activateView(presId);
+ // Update widgets parameters
+ _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
+ _currentWidgetHelper->updateWidget(true);
+ }
+}
+
+void
+PresentationController::onParavisDump()
+{
+ // We need a _studyEditor updated on the active study
+ _studyEditor->updateActiveStudy();
+
+ // Get the selected objects in the study (SObject)
+ SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
+
+ // For the first object only, request the dump
+ for (int i=0; i<listOfSObject->size(); i++) {
+ SALOMEDS::SObject_var soPres = listOfSObject->at(i);
+ std::string name(_studyEditor->getName(soPres));
+ if (soPres->_is_nil() || name == "MEDCalc")
+ return;
+ int presId = _salomeModule->getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
+ // If fieldId equals -1, then it means that it is not a field
+ // managed by the MED module, and we stop this function process.
+ if ( presId < 0 )
+ continue;
+
+ std::string dump(_presManager->getParavisDump(presId));
+ std::cerr << "#====== ParaVis dump (presentation " << presId << ") =====" << std::endl;
+ std::cerr << dump;
+ std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
+
+ break; // stop at the first one
+ }
+}
+
+void
+PresentationController::updateTreeViewWithNewPresentation(long dataId, long presentationId)