Salome HOME
[MEDCalc] Remove sibling presentations in REPLACE view mode
authorCédric Aguerre <cedric.aguerre@edf.fr>
Mon, 18 Jul 2016 09:08:29 +0000 (11:08 +0200)
committerabn <adrien.bruneton@cea.fr>
Wed, 27 Jul 2016 09:45:24 +0000 (11:45 +0200)
15 files changed:
idl/MEDPresentationManager.idl
idl/MED_Gen.idl
src/MEDCalc/cmp/MED.cxx
src/MEDCalc/cmp/MED.hxx
src/MEDCalc/cmp/MEDPresentation.hxx
src/MEDCalc/cmp/MEDPresentationContour.hxx
src/MEDCalc/cmp/MEDPresentationDeflectionShape.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.cxx
src/MEDCalc/cmp/MEDPresentationManager_i.hxx
src/MEDCalc/cmp/MEDPresentationManager_i.txx
src/MEDCalc/cmp/MEDPresentationPointSprite.hxx
src/MEDCalc/cmp/MEDPresentationScalarMap.hxx
src/MEDCalc/cmp/MEDPresentationSlices.hxx
src/MEDCalc/cmp/MEDPresentationVectorField.hxx
src/MEDCalc/gui/PresentationController.cxx

index 86bc0b21f99399260891c2462eea05107f1d44d7..c3e100225381634171c8dcb7ca63d8ba505220bf 100644 (file)
@@ -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);
   };
 
 };
index 6dbae1d6a39b6765a9f79057ca8650852c73313b..21df0b93374d867cc8eee8fd69501dd57e7aa0c0 100644 (file)
@@ -34,6 +34,8 @@ module MED_ORB
     OP_ERROR                 //!< ERROR: other problems
   };
 
+  typedef sequence<long> 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);
+
   };
 };
 
index cb92d8e483d457aecaf6c6884957eed4bb93041a..99b6976c6a07e0c4f55d4395e7af546b4494aef1 100644 (file)
@@ -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,
index 73270a20861650b1c7e7838dcefdb804a6298b8c..ddd373a7696924a51e0c47d5c525203f565d937c 100644 (file)
@@ -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,
index d6458d2f671fa0df122161e2cf8d926327026c8c..d67971dbed4236e2d3c43efa12d569b161309871 100644 (file)
@@ -66,6 +66,8 @@ protected:
 
   static int GeneratePythonId();
 
+  virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
+
 private:
 
   std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
index e03b76b58ba4b061b8892d5bc6a54047d989be41..364965cd6000563a9748ba0d5b0dc99fcfc0f7e5 100644 (file)
@@ -32,6 +32,7 @@ public:
   virtual ~MEDPresentationContour() {}
 
   void updatePipeline(const MEDCALC::ContourParameters& params);
+  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
 protected:
   virtual void internalGeneratePipeline();
index f9bbbb2f24f7e7a9e255ff2fde8577ade249589d..f03240e087ff2cab0c09d56e7b70bb3fcf6b9e84 100644 (file)
@@ -32,6 +32,7 @@ public:
   virtual ~MEDPresentationDeflectionShape() {}
 
   void updatePipeline(const MEDCALC::DeflectionShapeParameters& params);
+  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
 protected:
   virtual void internalGeneratePipeline();
index 563979e1686ca94275cdea9f42ae200f5a38798e..920d0e060e2d92ddadbd893dafb224e0bd38eee9 100644 (file)
@@ -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 <iostream>
+#include <sstream>
 
 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;
+  }
 }
index 0b073ebd57acd65a61dc236fd7f691bc7e9fc237..4d455d20de4ac817d2b90d4b202b5886d37c67af 100644 (file)
@@ -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 :
 
index 4c66cfc719180ee00e429e0cb41b9bb7d9403de7..eb283bf152986e6e60abcb850c3e4dd16c52e227 100644 (file)
@@ -24,13 +24,6 @@ template<typename PresentationType, typename PresentationParameters>
 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 {
index 27530af82a8ddd35cb084735de45f91b855584dc..49b200b125a1d7c71c2436784f485f6b94f11738 100644 (file)
@@ -32,6 +32,7 @@ public:
   virtual ~MEDPresentationPointSprite() {}
 
   void updatePipeline(const MEDCALC::PointSpriteParameters& params);
+  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
 protected:
   virtual void internalGeneratePipeline();
index d3d1ae1cf5e3a566d92d884042bb954fd4c4e4da..2b35a3482b76b79c36441525f1e0d93cd7167641 100644 (file)
@@ -32,6 +32,7 @@ public:
   virtual ~MEDPresentationScalarMap() {}
 
   void updatePipeline(const MEDCALC::ScalarMapParameters& params);
+  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
 protected:
   virtual void internalGeneratePipeline();
index b7ee4184e66f989f61d4e6240cbf97f3bf2018b4..7166a92bdb5baafe88e6bbba1727257ce74ad308 100644 (file)
@@ -32,6 +32,7 @@ public:
   virtual ~MEDPresentationSlices() {}
 
   void updatePipeline(const MEDCALC::SlicesParameters& params);
+  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
 protected:
   virtual void internalGeneratePipeline();
index 7981f4264247690ca11f656c82ee3c7ee0e5f2b2..3da7403113c2ab6e15240c44b7b04a803acfa9c9 100644 (file)
@@ -32,6 +32,7 @@ public:
   virtual ~MEDPresentationVectorField() {}
 
   void updatePipeline(const MEDCALC::VectorFieldParameters& params);
+  MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
 
 protected:
   virtual void internalGeneratePipeline();
index 99ba86d646ba7439dbbb3709c97339eed6359eb3..1785436a6c16c255701b6e79554e1f1686373d9c 100644 (file)
@@ -24,6 +24,7 @@
 #include "QtxActionGroup.h"
 #include "QtxActionToolMgr.h"
 #include "MEDFactoryClient.hxx"
+#include "MEDPresentationManager_i.hxx"
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
@@ -36,6 +37,7 @@
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
 #include <QMessageBox>
+#include <sstream>
 
 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);
 }