From 03b5d91784ca6723833b6b897e97a1cb5d2da2a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 18 Jul 2016 11:08:29 +0200 Subject: [PATCH] [MEDCalc] Remove sibling presentations in REPLACE view mode --- idl/MEDPresentationManager.idl | 4 +- idl/MED_Gen.idl | 7 +++ src/MEDCalc/cmp/MED.cxx | 48 +++++++++++++++++++ src/MEDCalc/cmp/MED.hxx | 4 ++ src/MEDCalc/cmp/MEDPresentation.hxx | 2 + src/MEDCalc/cmp/MEDPresentationContour.hxx | 1 + .../cmp/MEDPresentationDeflectionShape.hxx | 1 + src/MEDCalc/cmp/MEDPresentationManager_i.cxx | 21 ++++++-- src/MEDCalc/cmp/MEDPresentationManager_i.hxx | 23 ++++----- src/MEDCalc/cmp/MEDPresentationManager_i.txx | 7 --- .../cmp/MEDPresentationPointSprite.hxx | 1 + src/MEDCalc/cmp/MEDPresentationScalarMap.hxx | 1 + src/MEDCalc/cmp/MEDPresentationSlices.hxx | 1 + .../cmp/MEDPresentationVectorField.hxx | 1 + src/MEDCalc/gui/PresentationController.cxx | 28 +++++++++++ 15 files changed, 126 insertions(+), 24 deletions(-) diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index 86bc0b21f..c3e100225 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -140,9 +140,11 @@ module MEDCALC void updatePointSprite(in long presId, in PointSpriteParameters params); boolean removePresentation(in long presId); - + // Helper functions to keep GUI sync boolean activateView(in long presentationId); + + MEDPresentationViewMode getPresentationViewMode(in long presId); }; }; diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl index 6dbae1d6a..21df0b933 100644 --- a/idl/MED_Gen.idl +++ b/idl/MED_Gen.idl @@ -34,6 +34,8 @@ module MED_ORB OP_ERROR //!< ERROR: other problems }; + typedef sequence PresentationsList; + interface MED_Gen : Engines::EngineComponent { @@ -51,6 +53,11 @@ module MED_ORB status unregisterPresentation(in SALOMEDS::Study study, in long presentationId) raises (SALOME::SALOME_Exception); + + PresentationsList getSiblingPresentations(in SALOMEDS::Study study, + in long presentationId) + raises (SALOME::SALOME_Exception); + }; }; diff --git a/src/MEDCalc/cmp/MED.cxx b/src/MEDCalc/cmp/MED.cxx index cb92d8e48..99b6976c6 100644 --- a/src/MEDCalc/cmp/MED.cxx +++ b/src/MEDCalc/cmp/MED.cxx @@ -230,6 +230,54 @@ MED::unregisterPresentation(SALOMEDS::Study_ptr study, return MED_ORB::OP_OK; } +MED_ORB::PresentationsList* +MED::getSiblingPresentations(SALOMEDS::Study_ptr study, CORBA::Long presentationId) +{ + // 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; + + if (presentationId == attrParam->GetInt(PRESENTATION_ID)) { + // get siblings + SALOMEDS::ChildIterator_var siblItr = study->NewChildIterator(child->GetFather()); + for (siblItr->InitEx(true); siblItr->More(); siblItr->Next()) { + SALOMEDS::SObject_var sibl(siblItr->Value()); + + if (sibl->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; + + if (attrParam->GetInt(PRESENTATION_ID) != presentationId) { + CORBA::ULong size = presList->length(); + presList->length(size+1); + (*presList)[size] = attrParam->GetInt(PRESENTATION_ID); + } + } + } + return presList; + } + } + } + + return presList; +} + Engines::TMPFile* MED::DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, diff --git a/src/MEDCalc/cmp/MED.hxx b/src/MEDCalc/cmp/MED.hxx index 73270a208..ddd373a76 100644 --- a/src/MEDCalc/cmp/MED.hxx +++ b/src/MEDCalc/cmp/MED.hxx @@ -64,6 +64,10 @@ public: MED_ORB::status unregisterPresentation(SALOMEDS::Study_ptr study, CORBA::Long presentationId); + // Caller owns the returned list, and is responsible for the list deletion. + MED_ORB::PresentationsList* getSiblingPresentations(SALOMEDS::Study_ptr study, + CORBA::Long presentationId); + /*! Dump the study as a Python file */ virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index d6458d2f6..d67971dbe 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -66,6 +66,8 @@ protected: static int GeneratePythonId(); + virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0; + private: std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const; diff --git a/src/MEDCalc/cmp/MEDPresentationContour.hxx b/src/MEDCalc/cmp/MEDPresentationContour.hxx index e03b76b58..364965cd6 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.hxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationContour() {} void updatePipeline(const MEDCALC::ContourParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx index f9bbbb2f2..f03240e08 100644 --- a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx +++ b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationDeflectionShape() {} void updatePipeline(const MEDCALC::DeflectionShapeParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index 563979e16..920d0e060 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -19,6 +19,7 @@ #include "MEDPresentationManager_i.hxx" #include "MEDFactoryClient.hxx" +#include "Basics_Utils.hxx" // presentations #include "MEDPresentationScalarMap.hxx" @@ -29,6 +30,7 @@ #include "MEDPresentationPointSprite.hxx" #include +#include MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL; @@ -179,6 +181,11 @@ MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentatio if (presentation) delete presentation; _presentations.erase(presentationID); + + std::stringstream sstm; + sstm << "Presentation " << presentationID << " has been removed.\n"; + STDLOG(sstm.str()); + return true; } @@ -196,10 +203,14 @@ MEDPresentationManager_i::activateView(MEDPresentation::TypeID presentationID) return true; } -MEDPresentation::TypeID -MEDPresentationManager_i::_getActivePresentationId() const +MEDCALC::MEDPresentationViewMode +MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID) { - // :TODO: - - return -1; + MEDPresentation* pres = _getPresentation(presentationID); + if (pres) { + return pres->getViewMode(); + } else { + std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl; + return MEDCALC::VIEW_MODE_DEFAULT; + } } diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 0b073ebd5..4d455d20d 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -46,19 +46,21 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&); MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&); - MEDCALC_EXPORT void setPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue); - MEDCALC_EXPORT char* getPresentationProperty(MEDPresentation::TypeID presentationID, const char* propName); + MEDCALC_EXPORT void setPresentationProperty(MEDPresentation::TypeID, const char* propName, const char* propValue); + MEDCALC_EXPORT char* getPresentationProperty(MEDPresentation::TypeID, const char* propName); - MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters&); - MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters&); - MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters&); - MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters&); - MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters&); - MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters&); + MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&); + MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&); + MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&); + MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&); + MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&); + MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); - MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID); - MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID); + + MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID); private: MEDPresentationManager_i(); @@ -75,7 +77,6 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, void _updatePresentation(MEDPresentation::TypeID presentationID, PresentationParameters params); MEDPresentation* _getPresentation(MEDPresentation::TypeID) const; - MEDPresentation::TypeID _getActivePresentationId() const; private : diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.txx b/src/MEDCalc/cmp/MEDPresentationManager_i.txx index 4c66cfc71..eb283bf15 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.txx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.txx @@ -24,13 +24,6 @@ template MEDPresentation::TypeID MEDPresentationManager_i::_makePresentation(PresentationParameters params) { - // Replace = Remove then add - if (params.viewMode == MEDCALC::VIEW_MODE_REPLACE) { - MEDPresentation::TypeID currentPresentationId = _getActivePresentationId(); - if (currentPresentationId > -1) - removePresentation(currentPresentationId); - } - // Create a new presentation instance PresentationType* presentation = NULL; try { diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx index 27530af82..49b200b12 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationPointSprite() {} void updatePipeline(const MEDCALC::PointSpriteParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx index d3d1ae1cf..2b35a3482 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationScalarMap() {} void updatePipeline(const MEDCALC::ScalarMapParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.hxx b/src/MEDCalc/cmp/MEDPresentationSlices.hxx index b7ee4184e..7166a92bd 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.hxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationSlices() {} void updatePipeline(const MEDCALC::SlicesParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx index 7981f4264..3da740311 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx @@ -32,6 +32,7 @@ public: virtual ~MEDPresentationVectorField() {} void updatePipeline(const MEDCALC::VectorFieldParameters& params); + MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; } protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index 99ba86d64..1785436a6 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -24,6 +24,7 @@ #include "QtxActionGroup.h" #include "QtxActionToolMgr.h" #include "MEDFactoryClient.hxx" +#include "MEDPresentationManager_i.hxx" #include #include @@ -36,6 +37,7 @@ #include #include #include +#include static const int OPTIONS_VIEW_MODE_ID = 943; static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944; @@ -351,6 +353,32 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.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; + } + // update Object browser _salomeModule->getApp()->updateObjectBrowser(true); } -- 2.39.2