From 7599fb91bba597349668f8439bad0116702ecbf5 Mon Sep 17 00:00:00 2001 From: abn Date: Fri, 29 Jul 2016 09:54:04 +0200 Subject: [PATCH] [MEDCalc]: replace mode - OB object deletion was not always working. --- idl/MEDPresentationManager.idl | 4 +++ idl/MED_Gen.idl | 3 ++ src/MEDCalc/cmp/MED.cxx | 32 +++++++++++++++++++ src/MEDCalc/cmp/MED.hxx | 3 ++ src/MEDCalc/cmp/MEDPresentationManager_i.cxx | 11 +++++++ src/MEDCalc/cmp/MEDPresentationManager_i.hxx | 1 + src/MEDCalc/gui/PresentationController.cxx | 33 +++++++++----------- 7 files changed, 69 insertions(+), 18 deletions(-) diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index b5566fe5c..a62aaa241 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -119,6 +119,8 @@ module MEDCALC // MEDPresentationColorMap colorMap; // }; + typedef sequence PresentationsList; + /* Functions */ interface MEDPresentationManager : SALOME::GenericObj @@ -153,6 +155,8 @@ module MEDCALC string getParavisDump(in long presId); // MEDPresentationViewMode getPresentationViewMode(in long presId); + + PresentationsList getAllPresentations(); }; }; diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl index 94bd24136..beefb0e19 100644 --- a/idl/MED_Gen.idl +++ b/idl/MED_Gen.idl @@ -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); }; }; diff --git a/src/MEDCalc/cmp/MED.cxx b/src/MEDCalc/cmp/MED.cxx index 1d0ff2fe4..4b0ce7df0 100644 --- a/src/MEDCalc/cmp/MED.cxx +++ b/src/MEDCalc/cmp/MED.cxx @@ -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) { diff --git a/src/MEDCalc/cmp/MED.hxx b/src/MEDCalc/cmp/MED.hxx index c4b432234..57a3cc381 100644 --- a/src/MEDCalc/cmp/MED.hxx +++ b/src/MEDCalc/cmp/MED.hxx @@ -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, diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index b50697813..8fc47d514 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -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::const_iterator it; + int i; + for (i = 0, it = _presentations.begin(); it != _presentations.end(); ++it, ++i) + (*presList)[i] = it->first; + return presList; +} diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 095843ce8..82fabe186 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -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(); diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index 032127d55..a845c48f8 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -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::iterator it; - std::vector to_del; - for (it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it) + SalomeApp_Study* study = dynamic_cast(_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::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 ) { -- 2.30.2