]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
[MEDCalc]: replace mode - OB object deletion was not always working.
authorabn <adrien.bruneton@cea.fr>
Fri, 29 Jul 2016 07:54:04 +0000 (09:54 +0200)
committerabn <adrien.bruneton@cea.fr>
Fri, 29 Jul 2016 07:54:04 +0000 (09:54 +0200)
idl/MEDPresentationManager.idl
idl/MED_Gen.idl
src/MEDCalc/cmp/MED.cxx
src/MEDCalc/cmp/MED.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.cxx
src/MEDCalc/cmp/MEDPresentationManager_i.hxx
src/MEDCalc/gui/PresentationController.cxx

index b5566fe5c92b9b05905c37d1cd6bdcdd20f0a7cb..a62aaa241646623d4e735a2423410dff45dbe172 100644 (file)
@@ -119,6 +119,8 @@ module MEDCALC
 //    MEDPresentationColorMap colorMap;
 //  };
 
+  typedef sequence<long> PresentationsList;
+
   /* Functions */
 
   interface MEDPresentationManager : SALOME::GenericObj
@@ -153,6 +155,8 @@ module MEDCALC
     string getParavisDump(in long presId);
     
 //    MEDPresentationViewMode getPresentationViewMode(in long presId);
+    
+    PresentationsList getAllPresentations();
   };
 };
 
index 94bd24136828607352a30b5cb664da9ddbbb3c83..beefb0e19ebb03141e1a444879c08b10fe9d4863 100644 (file)
@@ -59,6 +59,9 @@ module MED_ORB
                                               in long presentationId)
       raises (SALOME::SALOME_Exception);
 
+    // Get all presentations in study:
+    PresentationsList getStudyPresentations(in SALOMEDS::Study study)
+      raises (SALOME::SALOME_Exception);
   };
 };
 
index 1d0ff2fe4350509a9122722395233878a660a1da..4b0ce7df08c5c8226bca8b6ae680a8c1b5a23dc2 100644 (file)
@@ -240,6 +240,38 @@ MED::unregisterPresentation(SALOMEDS::Study_ptr study,
   return MED_ORB::OP_OK;
 }
 
+MED_ORB::PresentationsList*
+MED::getStudyPresentations(SALOMEDS::Study_ptr study)
+{
+  // set exception handler to catch unexpected CORBA exceptions
+  Unexpect aCatch(SALOME_SalomeException);
+
+  MED_ORB::PresentationsList* presList = new MED_ORB::PresentationsList;
+
+  SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
+  SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
+
+  SALOMEDS::GenericAttribute_var anAttribute;
+  SALOMEDS::SComponent_var father = study->FindComponent("MED");
+  SALOMEDS::ChildIterator_var it = study->NewChildIterator(father);
+  for (it->InitEx(true); it->More(); it->Next())
+    {
+      SALOMEDS::SObject_var child(it->Value());
+      if (child->FindAttribute(anAttribute, "AttributeParameter"))
+        {
+          SALOMEDS::AttributeParameter_var attrParam = SALOMEDS::AttributeParameter::_narrow(anAttribute);
+          if (!attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN) || !attrParam->GetBool(IS_PRESENTATION) || !attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
+            continue;
+
+          CORBA::ULong size = presList->length();
+          presList->length(size+1);
+          (*presList)[size] = attrParam->GetInt(PRESENTATION_ID);
+        }
+    }
+  return presList;
+}
+
+
 MED_ORB::PresentationsList*
 MED::getSiblingPresentations(SALOMEDS::Study_ptr study, CORBA::Long presentationId)
 {
index c4b432234b5d840c32dec2b22c30fd6988b13451..57a3cc381385511efa38b67ee2eacca74f70b418 100644 (file)
@@ -69,6 +69,9 @@ public:
   MED_ORB::PresentationsList* getSiblingPresentations(SALOMEDS::Study_ptr study,
                                                       CORBA::Long presentationId);
 
+  // Get all presentations registered in the study
+  MED_ORB::PresentationsList* getStudyPresentations(SALOMEDS::Study_ptr study);
+
   /*! Dump the study as a Python file */
   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
                                        CORBA::Boolean isPublished,
index b50697813801a71ce3e4500ae68343fc6b8a0047..8fc47d514e86d9bdba045ffcecb2bbd6186e7de5 100644 (file)
@@ -269,3 +269,14 @@ MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
     throw KERNEL::createSalomeException("getParavisDump(): presentation not found!!");
 }
 
+MEDCALC::PresentationsList*
+MEDPresentationManager_i::getAllPresentations()
+{
+  MEDCALC::PresentationsList* presList = new MEDCALC::PresentationsList;
+  presList->length(_presentations.size());
+  std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
+  int i;
+  for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i)
+    (*presList)[i] = it->first;
+  return presList;
+}
index 095843ce89e156b614ada77c1cd7e23890c702f8..82fabe186084493f29768ac68e0c4200e4d1e0ae 100644 (file)
@@ -66,6 +66,7 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   MEDCALC_EXPORT CORBA::Long getActiveViewPythonId();
 //  MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID);
   MEDCALC_EXPORT char* getParavisDump(MEDPresentation::TypeID presentationID);
+  MEDCALC_EXPORT MEDCALC::PresentationsList* getAllPresentations();
 
  private:
   MEDPresentationManager_i();
index 032127d5535edb0b29d4806700a14054db3fbcd3..a845c48f8c3d6ae2e213e467d47db05ba52f2717 100644 (file)
@@ -669,25 +669,22 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
   if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
     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)
+    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
+    _PTR(Study) studyDS = study->studyDS();
+
+    MEDCALC::PresentationsList * lstManager = _presManager->getAllPresentations();
+    MED_ORB::PresentationsList * lstModule = _salomeModule->engine()->getStudyPresentations(_CAST(Study, studyDS)->GetStudy());
+    // The IDs not in the intersection needs deletion:
+    CORBA::Long * last = lstManager->get_buffer() + lstManager->length();
+    for (unsigned i = 0; i < lstModule->length(); i++)
       {
-        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);
+        CORBA::Long * ptr = std::find(lstManager->get_buffer(), last, (*lstModule)[i]);
+        if (ptr == last)
+          {
+            STDLOG("Removing pres " << (*lstModule)[i] << " from OB.");
+          // Presentation in module but not in manager anymore: to be deleted from OB:
+          updateTreeViewForPresentationRemoval((*lstModule)[i]);
+          }
       }
   }
   else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {