Salome HOME
[MEDCalc] Presentation removal
authorCédric Aguerre <cedric.aguerre@edf.fr>
Tue, 19 Apr 2016 14:29:13 +0000 (16:29 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Tue, 19 Apr 2016 16:09:46 +0000 (18:09 +0200)
16 files changed:
idl/MEDEventListener.idl
idl/MEDPresentationManager.idl
idl/MED_Gen.idl
src/MEDCalc/cmp/MED.cxx
src/MEDCalc/cmp/MED.hxx
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/gui/PresentationController.cxx
src/MEDCalc/gui/PresentationController.hxx
src/MEDCalc/gui/WorkspaceController.cxx
src/MEDCalc/tui/__init__.py
src/MEDCalc/tui/medevents.py
src/MEDCalc/tui/medpresentation.py

index 1181a6e1697dfd083c3cd9e4a86bc5f00ba6dd9d..73d8b9be7f9de15d61b565ef6a9de6472ace50c3 100644 (file)
@@ -34,6 +34,7 @@ module MEDCALC
     EVENT_CLEAN_WORKSPACE,
     EVENT_ADD_DATASOURCE,
     EVENT_ADD_PRESENTATION,
+    EVENT_REMOVE_PRESENTATION,
     EVENT_UNKNOWN
   };
 
index deb0f0a522978bdf1c72bc1a6eedfe925261aacb..c797e4036b2bfdf0c0fc27e824662328fc99f96f 100644 (file)
@@ -139,6 +139,8 @@ module MEDCALC
     void updateDeflectionShape(in long presId, in DeflectionShapeParameters params);
     void updatePointSprite(in long presId, in PointSpriteParameters params);
 
+    boolean removePresentation(in long presId);
+
   };
 
 };
index 5df35be243cb5c841d6dedb614e22a6378528029..6dbae1d6a39b6765a9f79057ca8650852c73313b 100644 (file)
@@ -47,6 +47,10 @@ module MED_ORB
                                 in string label,
                                 in long presentationId)
       raises (SALOME::SALOME_Exception);
+
+    status unregisterPresentation(in SALOMEDS::Study study,
+                                  in long presentationId)
+      raises (SALOME::SALOME_Exception);
   };
 };
 
index 8a69c612f4997c57bb33a9f3af5f6ea6e9b9fc76..a69140721ab571b18b315d08676c583f5848c91d 100644 (file)
@@ -205,6 +205,40 @@ MED::registerPresentation(SALOMEDS::Study_ptr study,
   return result;
 }
 
+MED_ORB::status
+MED::unregisterPresentation(SALOMEDS::Study_ptr study,
+                            CORBA::Long presentationId)
+{
+  // set exception handler to catch unexpected CORBA exceptions
+  Unexpect aCatch(SALOME_SalomeException);
+
+  // set result status to error initially
+  MED_ORB::status result = MED_ORB::OP_ERROR;
+
+  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)) {
+        // remove object from study
+        studyBuilder->RemoveObjectWithChildren(child);
+        // remove object from use case tree
+        useCaseBuilder->Remove(child);
+      }
+    }
+  }
+}
+
 Engines::TMPFile*
 MED::DumpPython(CORBA::Object_ptr theStudy,
                 CORBA::Boolean isPublished,
index 373051b53e062f8ca5857b619b7143d461180aaf..73270a20861650b1c7e7838dcefdb804a6298b8c 100644 (file)
@@ -61,6 +61,9 @@ public:
                                        const char* label,
                                        CORBA::Long presentationId);
 
+  MED_ORB::status unregisterPresentation(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 10fe56a4425702578fde7b64baed85992840e088..aa5075387ef6cbbe09c863b4e52aed794a9d44af 100644 (file)
@@ -24,7 +24,7 @@
 #include "MEDCouplingRefCountObject.hxx"
 #include <iostream>
 
-MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name)
+MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name)
     : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties()
 {
   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
@@ -45,6 +45,12 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::st
   setProperty("name", name);
 }
 
+MEDPresentation::~MEDPresentation()
+{
+  std::cout << "###TODO#### ~MEDPresentation: clear pipeline\n";
+  std::cout << "###TODO#### ~MEDPresentation: clear display\n";
+}
+
 void
 MEDPresentation::generatePipeline()
 {
index e7675010724e3f85a836134352eee1a22e60becf..5be9e89cf373b96b3ddcabfa0f561dd54cb56bd8 100644 (file)
@@ -41,21 +41,21 @@ public:
 
   typedef ::CORBA::Long TypeID;
 
-  virtual ~MEDPresentation() {}
+  virtual ~MEDPresentation();
 
   void setProperty(const std::string& propName, const std::string& propValue);
   const std::string getProperty(const std::string& propName) const;
 
 protected:
 
-  MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name);
+  MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name);
   std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const;
   std::string getResetCameraCommand() const;
   std::string getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const;
 
   virtual void internalGeneratePipeline() = 0;
-  PyObject * getPythonObjectFromMain(const char * var) const;
-  void pushInternal(PyObject * obj, PyObject * disp = NULL);
+  PyObject* getPythonObjectFromMain(const char* var) const;
+  void pushInternal(PyObject* obj, PyObject* disp = NULL);
 
   MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
 
@@ -80,10 +80,10 @@ private:
   MEDPresentation::TypeID _fieldHandlerId;
 
   ///! Pipeline elements
-  std::vector< PyObject * > _pipeline;
+  std::vector<PyObject*> _pipeline;
 
   ///! Corresponding display object, if any:
-  std::vector< PyObject * > _display;
+  std::vector<PyObject*> _display;
 
   ///! Presentation properties <key,value>
   std::map<std::string, std::string> _properties;
index c5f7a8f0baf064a02b25bbd5430edce40cc61383..a2e3cfb0925649157def5f5f9dc42e781cf19f27 100644 (file)
@@ -166,3 +166,26 @@ MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentation
 {
   return _updatePresentation<MEDPresentationPointSprite>(presentationID, params);
 }
+
+CORBA::Boolean
+MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID)
+{
+  std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator citr = _presentations.find(presentationID);
+  if (citr == _presentations.end()) {
+    std::cerr << "removePresentation(): presentation not found!!" << std::endl;
+    return false;
+  }
+  MEDPresentation* presentation = (*citr).second;
+  if (presentation)
+    delete presentation;
+  _presentations.erase(presentationID);
+  return true;
+}
+
+MEDPresentation::TypeID
+MEDPresentationManager_i::_getActivePresentationId() const
+{
+  // :TODO:
+
+  return -1;
+}
index 826ecc7bbd706083f045270760f1b13d0896abad..e7ec9677cf22ed0ca7dec49f018e5c4b684d2d7c 100644 (file)
@@ -56,6 +56,8 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
   MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID presentationID, const MEDCALC::DeflectionShapeParameters&);
   MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters&);
 
+  MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID presentationID);
+
  private:
   MEDPresentationManager_i();
   virtual ~MEDPresentationManager_i();
@@ -71,6 +73,7 @@ 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 eb283bf152986e6e60abcb850c3e4dd16c52e227..4c66cfc719180ee00e429e0cb41b9bb7d9403de7 100644 (file)
@@ -24,6 +24,13 @@ 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 b727b6b4c722f69b27ef4079403aefcd5decb358..4356a10745f5d548f60f4c916b58719d918d2d42 100644 (file)
@@ -298,12 +298,32 @@ PresentationController::updateTreeViewWithNewPresentation(long fieldId, long pre
   _salomeModule->getApp()->updateObjectBrowser(true);
 }
 
+void
+PresentationController::updateTreeViewForPresentationRemoval(long presentationId)
+{
+  if (presentationId < 0) {
+    std::cerr << "Unknown presentation\n";
+    return;
+  }
+
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
+  _PTR(Study) studyDS = study->studyDS();
+
+  _salomeModule->engine()->unregisterPresentation(_CAST(Study, studyDS)->GetStudy(), presentationId);
+
+  // update Object browser
+  _salomeModule->getApp()->updateObjectBrowser(true);
+}
+
 void
 PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
 {
   if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
     this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
   }
+  else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
+    this->updateTreeViewForPresentationRemoval(event->presentationId);
+  }
 }
 
 void
index 53c0272ad01f59a81344c81baef20745fce1a21c..78d7ca36b9ba71b85653037da8b553605f82e92c 100644 (file)
@@ -77,6 +77,7 @@ protected slots:
 private:
   void visualize(PresentationEvent::EventType);
   void updateTreeViewWithNewPresentation(long, long);
+  void updateTreeViewForPresentationRemoval(long);
   std::string _getIconName(const std::string&);
 
 private:
index b38d17ed1ed0bb350c22c1b39b9c4b1867f7e138..b85ea1f9d5a564dd2a6e1bad5c05d91b9953414c 100644 (file)
@@ -306,7 +306,10 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent* event) {
     emit workspaceSignal(event); // forward to DatasourceController
   }
   else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
-    emit workspaceSignal(event); // forward to DatasourceController
+    emit workspaceSignal(event); // forward to PresentationController
+  }
+  else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
+    emit workspaceSignal(event); // forward to PresentationController
   }
 
 }
index 17cb536f4d7228bb86e6889d5a64e4c938967864..553704dd10b911ae9fd52a6526c97bb034e70f8f 100644 (file)
@@ -45,6 +45,7 @@ from medpresentation import MakeVectorField
 from medpresentation import MakeSlices
 from medpresentation import MakeDeflectionShape
 from medpresentation import MakePointSprite
+from medpresentation import RemovePresentation
 
 # Console commands
 import medconsole
index 97def727cf8eeb15a9ac498e51c1d882959e1e14..3db24ca009fb85fbf2fbe90ff14dab61790ba8bf 100644 (file)
@@ -115,3 +115,6 @@ def notifyGui_addDatasource(handlerId, filename):
 def notifyGui_addPresentation(fieldId, presId):
   __notifyGui(MEDCALC.EVENT_ADD_PRESENTATION, dataId=fieldId, presentationId=presId)
 #
+def notifyGui_removePresentation(presId):
+  __notifyGui(MEDCALC.EVENT_REMOVE_PRESENTATION, presentationId=presId)
+#
index eeac1b0636163540bceda1e9670ff1b11a9869b1..c48eebd485bf085a12eb97b33bfc3c4d388afe1c 100644 (file)
@@ -19,7 +19,7 @@
 
 import medcalc
 import MEDCALC
-from medcalc.medevents import notifyGui_addPresentation
+from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation
 
 __manager = medcalc.medcorba.factory.getPresentationManager()
 
@@ -93,3 +93,9 @@ def MakePointSprite(proxy,
   notifyGui_addPresentation(proxy.id, presentation_id)
   return presentation_id
 #
+
+def RemovePresentation(presentation_id):
+  ok = __manager.removePresentation(presentation_id)
+  if ok:
+    notifyGui_removePresentation(presentation_id)
+#