]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
[MEDCalc]: replace mode now targets the current view only.
authorabn <adrien.bruneton@cea.fr>
Thu, 28 Jul 2016 08:00:08 +0000 (10:00 +0200)
committerabn <adrien.bruneton@cea.fr>
Thu, 28 Jul 2016 08:00:08 +0000 (10:00 +0200)
To be confirmed with Cedric!

idl/MEDPresentationManager.idl
src/MEDCalc/cmp/MEDDataManager_i.cxx
src/MEDCalc/cmp/MEDPresentation.cxx
src/MEDCalc/cmp/MEDPresentation.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.cxx
src/MEDCalc/cmp/MEDPresentationManager_i.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.txx
src/MEDCalc/cmp/MEDPresentationScalarMap.cxx
src/MEDCalc/cmp/MEDPresentationScalarMap.hxx
src/MEDCalc/gui/PresentationController.cxx

index 4007aa8d55ea8edb028d5e329d453737a89158f2..b5566fe5c92b9b05905c37d1cd6bdcdd20f0a7cb 100644 (file)
@@ -152,7 +152,7 @@ module MEDCALC
     // Low level ParaVis dump
     string getParavisDump(in long presId);
     
-    MEDPresentationViewMode getPresentationViewMode(in long presId);
+//    MEDPresentationViewMode getPresentationViewMode(in long presId);
   };
 };
 
index 7896465c86fecd5a798d6e5a20f287c59b7a191a..f3f5b325a3ba1f9b367d4828ca9658bee19909a6 100644 (file)
@@ -337,7 +337,7 @@ MEDCALC::FieldHandlerList * MEDDataManager_i::getFieldHandlerList() {
  * This returns a copy of the fieldHandler associated to the specified id.
  */
 MEDCALC::FieldHandler * MEDDataManager_i::getFieldHandler(CORBA::Long fieldHandlerId) {
-  LOG("getFieldHandler: START")
+//  LOG("getFieldHandler: START")
 
   FieldHandlerMapIterator fieldIt = _fieldHandlerMap.find(fieldHandlerId);
   if ( fieldIt != _fieldHandlerMap.end() ) {
index 61c631d689dd86cc1d131788d68af1b715e394a5..e4bd9c9ae8abbf9abd60cdaa1d03d025544429af 100644 (file)
@@ -38,14 +38,17 @@ const std::string MEDPresentation::PROP_SCALAR_BAR_RANGE = "scalarBarRange";
 
 MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
                                  const MEDCALC::MEDPresentationViewMode viewMode,
-                                 const MEDCALC::MEDPresentationColorMap colorMap)
+                                 const MEDCALC::MEDPresentationColorMap colorMap,
+                                 const MEDCALC::MEDPresentationScalarBarRange sbRange)
     : _fieldHandlerId(fieldHandlerId), _propertiesStr(),
       //_pipeline(0), _display(0)
       _selectedComponentIndex(-1),
       _viewMode(viewMode),
       _colorMap(colorMap),
-      _renderViewPyId(GeneratePythonId()),
-      _objId(_renderViewPyId), _dispId(_renderViewPyId), _lutId(_renderViewPyId),
+      _sbRange(sbRange),
+      _renderViewPyId(-1),  // will be set by getRenderViewCommand()
+      _objId(GeneratePythonId()),
+      _dispId(_objId), _lutId(_objId),
       _globalDict(0)
 {
   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
@@ -58,7 +61,8 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s
   _fieldType = getFieldTypeString((MEDCoupling::TypeOfField) fieldHandler->type);
 
   if (_fileName.substr(0, 7) != std::string("file://")) {
-    const char* msg = "Data source is not a file! Can not proceed.";
+    const char* msg = "MEDPresentation(): Data source is not a file! Can not proceed.";
+    STDLOG(msg);
     throw MEDPresentationException(msg);
   }
   _fileName = _fileName.substr(7, _fileName.size());
@@ -104,18 +108,25 @@ MEDPresentation::generatePipeline()
 
 void
 MEDPresentation::pushAndExecPyLine(const std::string & lin)
+{
+  execPyLine(lin);
+  _pythonCmds.push_back(lin);
+}
+
+void
+MEDPresentation::execPyLine(const std::string & lin)
 {
   PyLockWrapper lock;
-//  std::cerr << lin << std::endl;
+//  STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
   if(PyRun_SimpleString(lin.c_str()))
     {
       std::ostringstream oss;
-      oss << "MEDPresentation::pushAndExecPyLine(): following Python command failed!\n";
+      oss << "MEDPresentation::execPyLine(): following Python command failed!\n";
       oss << ">> " << lin;
       STDLOG(oss.str());
       throw KERNEL::createSalomeException(oss.str().c_str());
     }
-  _pythonCmds.push_back(lin);
+
 }
 
 void
@@ -132,6 +143,7 @@ MEDPresentation::getStringProperty(const std::string& propName) const
       return (*it).second;
   }
   else {
+      STDLOG("MEDPresentation::getStringProperty(): no property named " + propName);
       throw MEDPresentationException("MEDPresentation::getStringProperty(): no property named " + propName);
   }
 }
@@ -150,6 +162,7 @@ MEDPresentation::getIntProperty(const std::string& propName) const
       return (*it).second;
   }
   else {
+      STDLOG("MEDPresentation::getIntProperty(): no property named " + propName);
       throw MEDPresentationException("MEDPresentation::getIntProperty(): no property named " + propName);
   }
 }
@@ -180,6 +193,13 @@ MEDPresentation::getIntProperty(const std::string& propName) const
      }
  }
 
+ void
+ MEDPresentation::internalGeneratePipeline()
+ {
+   PyLockWrapper lock;
+   pushAndExecPyLine( "import pvsimple as pvs;");
+ }
+
 
 PyObject*
 MEDPresentation::getPythonObjectFromMain(const char* python_var) const
@@ -212,12 +232,16 @@ std::string
 MEDPresentation::getRenderViewCommand() const
 {
   std::ostringstream oss, oss2;
+
   oss << "__view" << _renderViewPyId;
   std::string view(oss.str());
   oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl;
   if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
+      // this might potentially re-assign to an existing view variable, but this is OK, we
+      // normally reassign exaclty the same RenderView object.
       oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl;
   } else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) {
+      // same as above
       oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl;
       oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");" << std::endl;
       oss2 << "pvs.Render();" << std::endl;
@@ -269,6 +293,7 @@ MEDPresentation::getColorMapCommand() const
     oss << lut << ".ApplyPreset('Cool to Warm',True);";
     break;
   default:
+    STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!");
     throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
   }
   return oss.str();
@@ -287,6 +312,7 @@ MEDPresentation::getRescaleCommand() const
       oss << disp <<  ".RescaleTransferFunctionToDataRange(False);";
       break;
     default:
+      STDLOG("MEDPresentation::getRescaleCommand(): invalid range!");
       throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
   }
   return oss.str();
@@ -348,30 +374,37 @@ MEDPresentation::fillAvailableFieldComponents()
   }
   else {
       std::string msg("Unsupported spatial discretisation: " + _fieldType);
+      STDLOG(msg);
       throw KERNEL::createSalomeException(msg.c_str());
   }
 
   std::ostringstream oss;
   oss << "__nbCompo = " << obj << "." << typ << ".GetArray('" <<  _fieldName << "').GetNumberOfComponents();";
-  PyRun_SimpleString(oss.str().c_str());
+  execPyLine(oss.str());
   PyObject* p_obj = getPythonObjectFromMain("__nbCompo");
   long nbCompo;
   if (p_obj && PyInt_Check(p_obj))
     nbCompo = PyInt_AS_LONG(p_obj);
   else
-    throw KERNEL::createSalomeException("Unexpected Python error");
+    {
+      STDLOG("Unexpected Python error");
+      throw KERNEL::createSalomeException("Unexpected Python error");
+    }
   setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, nbCompo);
   for (long i = 0; i<nbCompo; i++)
     {
       std::ostringstream oss2;
       oss2 << "__compo = " << obj << "." << typ << ".GetArray('" <<  _fieldName << "').GetComponentName(" << i << ");";
-      PyRun_SimpleString(oss2.str().c_str());
+      execPyLine(oss2.str());
       PyObject* p_obj = getPythonObjectFromMain("__compo");
       std::string compo;
       if (p_obj && PyString_Check(p_obj))
         compo = std::string(PyString_AsString(p_obj));  // pointing to internal Python memory, so make a copy!!
       else
-        throw KERNEL::createSalomeException("Unexpected Python error");
+        {
+          STDLOG("Unexpected Python error");
+          throw KERNEL::createSalomeException("Unexpected Python error");
+        }
       std::ostringstream oss_p;
       oss_p << MEDPresentation::PROP_COMPONENT << i;
       setStringProperty(oss_p.str(), compo);
index 4307e356fcd1b51214bd4013234cbca0b35bee4a..511abb44252e16cccca2baff78049ea0d06614da 100644 (file)
@@ -63,13 +63,17 @@ public:
 
   std::string paravisDump() const;
 
+  long getPyViewID() const { return _renderViewPyId; }
+  void setPyViewID(long id) { _renderViewPyId = id; }
+
 protected:
   typedef std::pair<int, PyObject *> PyObjectId;
   static int GeneratePythonId();
 
   MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
                   const MEDCALC::MEDPresentationViewMode viewMode,
-                  const MEDCALC::MEDPresentationColorMap colorMap);
+                  const MEDCALC::MEDPresentationColorMap colorMap,
+                  const MEDCALC::MEDPresentationScalarBarRange sbRange);
   std::string getRenderViewCommand() const;
   std::string getResetCameraCommand() const;
 
@@ -77,18 +81,17 @@ protected:
   std::string getColorMapCommand() const;
   std::string getRescaleCommand() const;
 
-  virtual void internalGeneratePipeline() = 0;
+  virtual void internalGeneratePipeline();
   PyObject* getPythonObjectFromMain(const char* var) const;
 //  void pushPyObjects(PyObjectId obj, PyObjectId disp);
+  void execPyLine(const std::string & lin);
   void pushAndExecPyLine(const std::string & lin);
 
   MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
-  long getPyViewID() const { return _renderViewPyId; }
 
   void fillAvailableFieldComponents();
 
-  // TODO: follow the pattern of the others methods: template!
-  virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
+//  virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
 
   template<typename PresentationType, typename PresentationParameters>
   void updateComponent(const std::string& newCompo);
index f2608c1251f1fe3f082d8ec115221499af1c10d6..b50697813801a71ce3e4500ae68343fc6b8a0047 100644 (file)
@@ -43,7 +43,9 @@ MEDPresentationManager_i::getInstance() {
   return _instance;
 }
 
-MEDPresentationManager_i::MEDPresentationManager_i()
+MEDPresentationManager_i::MEDPresentationManager_i() :
+    _presentations(),
+    _activeViewPythonId(-1)
 {
 }
 
@@ -214,10 +216,7 @@ MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentatio
     delete presentation;
   _presentations.erase(presentationID);
 
-  std::stringstream sstm;
-  sstm << "Presentation " << presentationID << " has been removed.\n";
-  STDLOG(sstm.str());
-
+  STDLOG("Presentation " << presentationID << " has been removed.");
   return true;
 }
 
@@ -232,21 +231,33 @@ MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID)
   MEDPresentation* presentation = (*citr).second;
 
   presentation->activateView();
+  _activeViewPythonId = presentation->getPyViewID();
   return true;
 }
 
-MEDCALC::MEDPresentationViewMode
-MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
+CORBA::Long
+MEDPresentationManager_i::getActiveViewPythonId()
 {
-  MEDPresentation* pres = _getPresentation(presentationID);
-  if (pres) {
-    return pres->getViewMode();
-  } else {
-    std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
-    return MEDCALC::VIEW_MODE_DEFAULT;
-  }
+  //TODO: should be more elaborate to re-identify the active ParaView view when another
+  //mechanism than MED module has activated another view.
+  // Idea: 1/ call Python to current active view
+  //       2/ compare with all id(__viewX) from currently existing presentations
+  return _activeViewPythonId;
 }
 
+
+//MEDCALC::MEDPresentationViewMode
+//MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
+//{
+//  MEDPresentation* pres = _getPresentation(presentationID);
+//  if (pres) {
+//    return pres->getViewMode();
+//  } else {
+//    std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
+//    return MEDCALC::VIEW_MODE_DEFAULT;
+//  }
+//}
+
 char*
 MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
 {
index 5092867292c7aa87af13f7e729930e103d0c4b3a..095843ce89e156b614ada77c1cd7e23890c702f8 100644 (file)
@@ -63,7 +63,8 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
 
   MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID);
   MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID);
-  MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID);
+  MEDCALC_EXPORT CORBA::Long getActiveViewPythonId();
+//  MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID);
   MEDCALC_EXPORT char* getParavisDump(MEDPresentation::TypeID presentationID);
 
  private:
@@ -95,6 +96,7 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   // Owns a list of MEDPresentation objects
   std::map<MEDPresentation::TypeID, MEDPresentation*> _presentations;
 
+  long _activeViewPythonId;
 };
 
 #include "MEDPresentationManager_i.txx"
index 80f5e84f89b44204109c97efaa6f712129dde2e7..3ae7c49860861dfa5d541d02c9d40b5853227448 100644 (file)
 #ifndef _MED_PRESENTATION_MANAGER_I_TXX_
 #define _MED_PRESENTATION_MANAGER_I_TXX_
 
+#include <Basics_Utils.hxx>
+
 template<typename PresentationType, typename PresentationParameters>
 MEDPresentation::TypeID
 MEDPresentationManager_i::_makePresentation(const PresentationParameters params, const MEDCALC::MEDPresentationViewMode viewMode)
 {
+  int activeViewId = getActiveViewPythonId();
+
   // Replace = Remove then add
-  if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
-    MEDPresentation::TypeID currentPresentationId = _getActivePresentationId();
-    if (currentPresentationId > -1)
-      removePresentation(currentPresentationId);
+  if (viewMode == MEDCALC::VIEW_MODE_REPLACE)
+    {
+      // Remove all presentations from this view:
+      std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
+      std::vector<int> to_del;
+      for (it = _presentations.begin(); it != _presentations.end(); ++it)
+        {
+          int viewId2 = (*it).second->getPyViewID();
+          if (viewId2 == activeViewId)
+            to_del.push_back((*it).first);
+        }
+      for (std::vector<int>::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2)
+        removePresentation(*it2);
   }
 
   // Create a new presentation instance
   PresentationType* presentation = NULL;
+  MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
+  STDLOG("Generated presentation ID: " << newID);
   try {
     presentation = new PresentationType(params, viewMode);  // on stack or on heap?? heap for now
+    // In replace or overlap mode we force the display in the active view:
+    if(activeViewId != -1 && (viewMode == MEDCALC::VIEW_MODE_REPLACE || viewMode == MEDCALC::VIEW_MODE_OVERLAP))
+      presentation->setPyViewID(activeViewId);
+    else
+      presentation->setPyViewID(newID);  // ensures a new ID for the view
   }
   catch (const std::exception& e) {
     std::cerr << e.what() << std::endl;
+    STDLOG("Error: " << e.what());
     return -1;
   }
 
-  MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
   _presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
   presentation->generatePipeline();
+  // Make the view holding the newly created presentation the active one:
+  activateView(newID);
   return newID;
 }
 
index 03c46af005b313dafaca29225a4fadd91be98ec0..9c0181b3e73db6c57e46624af4222d1c4d8e7c10 100644 (file)
@@ -31,25 +31,25 @@ const std::string MEDPresentationScalarMap::TYPE_NAME = "MEDPresentationScalarMa
 
 MEDPresentationScalarMap::MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params,
                                                    const MEDCALC::MEDPresentationViewMode viewMode) :
-    MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap), _params(params)
+    MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
 {
 }
 
 void
 MEDPresentationScalarMap::internalGeneratePipeline()
 {
+  MEDPresentation::internalGeneratePipeline();
+
   PyLockWrapper lock;
 
   std::ostringstream oss_o, oss_d,oss_l, oss, oss_v;
   oss_o << "__obj" << _objId;      std::string obj(oss_o.str());
   oss_d << "__disp" << _dispId;    std::string disp(oss_d.str());
   oss_l << "__lut" << _lutId;    std::string lut(oss_l.str());
-
-  pushAndExecPyLine( "import pvsimple as pvs;");
-  pushAndExecPyLine( getRenderViewCommand() ); // define __viewXXX
-
   oss_v << "__view" << _renderViewPyId;    std::string view(oss_v.str());
 
+  pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
+
   oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
   pushAndExecPyLine(oss.str()); oss.str("");
 
index 71c5521d44b66277a3203dc5501ed2afdd8f0661..d396d24f31a695c210d74b7fb995e0190e76416f 100644 (file)
@@ -33,11 +33,12 @@ public:
   virtual ~MEDPresentationScalarMap() {}
 
   void updatePipeline(const MEDCALC::ScalarMapParameters& params);
-  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
   void getParameters(MEDCALC::ScalarMapParameters & params) const { params = _params; } ;
   void setParameters(const MEDCALC::ScalarMapParameters & params) { _params = params; } ;
 
+//  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
+
 protected:
   virtual void internalGeneratePipeline();
 
index 0f7735122318255464186783596aa7aa841089cb..032127d5535edb0b29d4806700a14054db3fbcd3 100644 (file)
@@ -599,7 +599,7 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre
     return;
   }
 
-  std::string name(MEDFactoryClient::getPresentationManager()->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
+  std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
   std::string type = name;
   std::string icon = std::string("ICO_") + type;
   icon = _getIconName(icon);
@@ -617,30 +617,30 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre
       oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
 
 
-  MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
-
-  // Remove sibling presentations if view mode is set to REPLACE
-  if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
-    MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
-    CORBA::ULong size = presList->length();
-
-    std::stringstream sstm;
-    sstm << "Removing sibling presentation(s): ";
-    for (int i = 0; i < size; ++i)
-      sstm << (*presList)[i] << "  ";
-    STDLOG(sstm.str());
-
-    for (int i = 0; i < size; ++i) {
-      PresentationEvent* event = new PresentationEvent();
-      event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
-      XmedDataObject* dataObject = new XmedDataObject();
-      dataObject->setPresentationId((*presList)[i]);
-      event->objectdata = dataObject;
-      emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
-    }
-
-    delete presList;
-  }
+//  MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
+//
+//  // Remove sibling presentations if view mode is set to REPLACE
+//  if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
+//    MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
+//    CORBA::ULong size = presList->length();
+//
+//    std::stringstream sstm;
+//    sstm << "Removing sibling presentation(s): ";
+//    for (int i = 0; i < size; ++i)
+//      sstm << (*presList)[i] << "  ";
+//    STDLOG(sstm.str());
+//
+//    for (int i = 0; i < size; ++i) {
+//      PresentationEvent* event = new PresentationEvent();
+//      event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
+//      XmedDataObject* dataObject = new XmedDataObject();
+//      dataObject->setPresentationId((*presList)[i]);
+//      event->objectdata = dataObject;
+//      emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
+//    }
+//
+//    delete presList;
+//  }
 
   // update Object browser
   _salomeModule->getApp()->updateObjectBrowser(true);
@@ -667,10 +667,31 @@ void
 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
 {
   if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
-    this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
+    updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
+    // Deal with replace mode: presentations with invalid IDs have to be removed:
+    std::map<int, MEDWidgetHelper *>::iterator it;
+    std::vector<int> to_del;
+    for (it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
+      {
+        try {
+            // TODO: not the best way to test for presentation existence at the engine level?
+            _presManager->getPresentationStringProperty((*it).first, MEDPresentation::PROP_NAME.c_str());
+        }
+        catch(...){
+           to_del.push_back((*it).first);
+           delete((*it).second);
+           (*it).second = 0;
+        }
+      }
+    std::vector<int>::const_iterator it2;
+    for (it2 = to_del.begin(); it2 != to_del.end(); ++it2)
+      {
+        updateTreeViewForPresentationRemoval(*it2);
+        _presHelperMap.erase(*it2);
+      }
   }
   else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
-    this->updateTreeViewForPresentationRemoval(event->presentationId);
+    updateTreeViewForPresentationRemoval(event->presentationId);
   }
 }