From: Cédric Aguerre Date: Tue, 19 Apr 2016 14:29:13 +0000 (+0200) Subject: [MEDCalc] Presentation removal X-Git-Tag: V8_1_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b20f7e235416dfe68ef29bc5ea806a776a5bdd73;p=modules%2Fmed.git [MEDCalc] Presentation removal --- diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index 1181a6e16..73d8b9be7 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -34,6 +34,7 @@ module MEDCALC EVENT_CLEAN_WORKSPACE, EVENT_ADD_DATASOURCE, EVENT_ADD_PRESENTATION, + EVENT_REMOVE_PRESENTATION, EVENT_UNKNOWN }; diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index deb0f0a52..c797e4036 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -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); + }; }; diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl index 5df35be24..6dbae1d6a 100644 --- a/idl/MED_Gen.idl +++ b/idl/MED_Gen.idl @@ -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); }; }; diff --git a/src/MEDCalc/cmp/MED.cxx b/src/MEDCalc/cmp/MED.cxx index 8a69c612f..a69140721 100644 --- a/src/MEDCalc/cmp/MED.cxx +++ b/src/MEDCalc/cmp/MED.cxx @@ -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, diff --git a/src/MEDCalc/cmp/MED.hxx b/src/MEDCalc/cmp/MED.hxx index 373051b53..73270a208 100644 --- a/src/MEDCalc/cmp/MED.hxx +++ b/src/MEDCalc/cmp/MED.hxx @@ -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, diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 10fe56a44..aa5075387 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -24,7 +24,7 @@ #include "MEDCouplingRefCountObject.hxx" #include -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() { diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index e76750107..5be9e89cf 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -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 _pipeline; ///! Corresponding display object, if any: - std::vector< PyObject * > _display; + std::vector _display; ///! Presentation properties std::map _properties; diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index c5f7a8f0b..a2e3cfb09 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -166,3 +166,26 @@ MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentation { return _updatePresentation(presentationID, params); } + +CORBA::Boolean +MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID) +{ + std::map::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; +} diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 826ecc7bb..e7ec9677c 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -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 : diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.txx b/src/MEDCalc/cmp/MEDPresentationManager_i.txx index eb283bf15..4c66cfc71 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.txx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.txx @@ -24,6 +24,13 @@ 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/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index b727b6b4c..4356a1074 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -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(_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 diff --git a/src/MEDCalc/gui/PresentationController.hxx b/src/MEDCalc/gui/PresentationController.hxx index 53c0272ad..78d7ca36b 100644 --- a/src/MEDCalc/gui/PresentationController.hxx +++ b/src/MEDCalc/gui/PresentationController.hxx @@ -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: diff --git a/src/MEDCalc/gui/WorkspaceController.cxx b/src/MEDCalc/gui/WorkspaceController.cxx index b38d17ed1..b85ea1f9d 100644 --- a/src/MEDCalc/gui/WorkspaceController.cxx +++ b/src/MEDCalc/gui/WorkspaceController.cxx @@ -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 } } diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 17cb536f4..553704dd1 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -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 diff --git a/src/MEDCalc/tui/medevents.py b/src/MEDCalc/tui/medevents.py index 97def727c..3db24ca00 100644 --- a/src/MEDCalc/tui/medevents.py +++ b/src/MEDCalc/tui/medevents.py @@ -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) +# diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index eeac1b063..c48eebd48 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -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) +#