Salome HOME
[MEDCalc] : better slices + more error handling when invalid params
[modules/med.git] / src / MEDCalc / gui / PresentationController.cxx
index d9ea2b2b9d508b151b6cf97b6bcfeab7f993ad9b..3b8e9e21948bf30037e5f25ae397e76f5138f393 100644 (file)
 #include "MEDPresentationScalarMap.hxx"
 #include "MEDPresentationContour.hxx"
 #include "MEDPresentationSlices.hxx"
+#include "MEDPresentationPointSprite.hxx"
+#include "MEDPresentationVectorField.hxx"
+#include "MEDPresentationDeflectionShape.hxx"
 
 #include "MEDWidgetHelperMeshView.hxx"
 #include "MEDWidgetHelperScalarMap.hxx"
 #include "MEDWidgetHelperContour.hxx"
 #include "MEDWidgetHelperSlices.hxx"
+#include "MEDWidgetHelperPointSprite.hxx"
+#include "MEDWidgetHelperVectorField.hxx"
+#include "MEDWidgetHelperDeflectionShape.hxx"
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
@@ -236,25 +242,25 @@ PresentationController::createActions()
 
   label   = tr("LAB_DELETE_PRESENTATION");
   tooltip = tr("TIP_DELETE_PRESENTATION");
-  icon    = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
+  icon    = tr("ICO_DELETE_PRESENTATION");
   actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
   //  _salomeModule->createTool(actionId, presentationToolbarId);
   //  _salomeModule->action(actionId)->setIconVisibleInMenu(true);
   _salomeModule->createMenu(actionId, presentationMenuId);
 
-  //
-  // Actions for popup menu only
-  //
   // Low level PARAVIS dump
   label = tr("LAB_PARAVIS_DUMP");
-  //icon  = tr("ICO_DATASOURCE_EXPAND_FIELD");
+  tooltip = tr("TIP_PARAVIS_DUMP");
   actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
-  _salomeModule->addActionInPopupMenu(actionId);
+  _salomeModule->createMenu(actionId, presentationMenuId);
 
+  //
+  // Actions for popup menu only
+  //
 
 }
 
-MEDCALC::MEDPresentationViewMode
+MEDCALC::ViewModeType
 PresentationController::getSelectedViewMode() const
 {
   if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
@@ -274,13 +280,13 @@ PresentationController::getSelectedViewMode() const
   return MEDCALC::VIEW_MODE_REPLACE;
 }
 
-MEDCALC::MEDPresentationColorMap
+MEDCALC::ColorMapType
 PresentationController::getSelectedColorMap() const
 {
   return _widgetPresentationParameters->getColorMap();
 }
 
-MEDCALC::MEDPresentationScalarBarRange
+MEDCALC::ScalarBarRangeType
 PresentationController::getSelectedScalarBarRange() const
 {
   return _widgetPresentationParameters->getScalarBarRange();
@@ -401,7 +407,7 @@ PresentationController::onDeletePresentation()
 QString
 PresentationController::getViewModePython() const
 {
-  MEDCALC::MEDPresentationViewMode viewMode = getSelectedViewMode();
+  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";
@@ -414,7 +420,7 @@ PresentationController::getViewModePython() const
 QString
 PresentationController::getColorMapPython() const
 {
-  MEDCALC::MEDPresentationColorMap colorMap = getSelectedColorMap();
+  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";
@@ -425,7 +431,7 @@ PresentationController::getColorMapPython() const
 QString
 PresentationController::getScalarBarRangePython() const
 {
-  MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange();
+  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";
@@ -436,7 +442,7 @@ PresentationController::getScalarBarRangePython() const
 QString
 PresentationController::getMeshModePython(const int mode) const
 {
-  MEDCALC::MEDPresentationMeshMode mod = static_cast<MEDCALC::MEDPresentationMeshMode>(mode);
+  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";
@@ -448,7 +454,7 @@ PresentationController::getMeshModePython(const int mode) const
 QString
 PresentationController::getSliceOrientationPython(const int orientation) const
 {
-  MEDCALC::MEDPresentationSliceOrientation orient = static_cast<MEDCALC::MEDPresentationSliceOrientation>(orientation);
+  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";
@@ -478,6 +484,10 @@ PresentationController::processPresentationEvent(const PresentationEvent* event)
   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 ) {
         commands += QString("presentation_id = medcalc.MakeMeshView(accessField(%1), viewMode=%2)").arg(fieldHandler->id).arg(viewMode);
         commands += QString("presentation_id");
@@ -489,29 +499,31 @@ PresentationController::processPresentationEvent(const PresentationEvent* event)
   }
   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);
+            .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), %2)").arg(fieldHandler->id).arg(viewMode);
-  //    commands += QString("presentation_id");
-  //  }
-    else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
+  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);
+            .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), %2)").arg(fieldHandler->id).arg(viewMode);
-  //    commands += QString("presentation_id");
-  //  }
-  //  else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
-  //    commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
-  //    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");
+  }
+
 
-  // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each
-  // dedicated widget helper class?
   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);
@@ -571,7 +583,7 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager
   std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
   if (it != _presHelperMap.end())
     return (*it).second;
-  MEDWidgetHelper * wh;
+  MEDWidgetHelper * wh = 0;
   if (type == MEDPresentationMeshView::TYPE_NAME)
     wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters);
   else if (type == MEDPresentationScalarMap::TYPE_NAME)
@@ -579,10 +591,17 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager
   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);
+    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
     {
-      STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
+      const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!";
+      STDLOG(msg);
     }
   _presHelperMap[presId] = wh;
   return wh;
@@ -606,7 +625,7 @@ PresentationController::onPresentationSelected(int presId, const QString& presTy
       _presManager->activateView(presId);
       // Update widgets parameters
       _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
-      _currentWidgetHelper->udpateWidget();
+      _currentWidgetHelper->updateWidget(true);
     }
 }
 
@@ -629,9 +648,9 @@ PresentationController::onParavisDump()
         continue;
 
       std::string dump(_presManager->getParavisDump(presId));
-      std::cerr << "#====== ParaVis dump =============== " << std::endl;
+      std::cerr << "#====== ParaVis dump (presentation "  << presId << ") =====" << std::endl;
       std::cerr << dump;
-      std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
+      std::cerr << "#====== End of ParaVis dump =============== " << std::endl;
 
       break; // stop at the first one
   }
@@ -663,7 +682,7 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre
       oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
 
 
-  //  MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
+  //  MEDCALC::ViewModeType viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
   //
   //  // Remove sibling presentations if view mode is set to REPLACE
   //  if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
@@ -730,11 +749,19 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
             STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
           // Presentation in module but not in manager anymore: to be deleted from OB:
           updateTreeViewForPresentationRemoval((*lstModule)[i]);
+          onPresentationSelected(-1, "", ""); // make sure param widget is hidden
           }
       }
   }
   else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
       updateTreeViewForPresentationRemoval(event->presentationId);
+      // Hide parameter widget if necessary:
+      onPresentationSelected(-1, "", "");
+  }
+  else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
+      // Update parameter widget if shown:
+      if(_currentWidgetHelper)
+        _currentWidgetHelper->updateWidget(false);
   }
 }