From: Cédric Aguerre Date: Tue, 4 Aug 2015 16:50:15 +0000 (+0200) Subject: GUI callback: add MEDPresentation X-Git-Tag: V8_0_0a1~5^2~34 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b0fe5c2648fb54af30904c04a25bd7a16b2976a;p=modules%2Fmed.git GUI callback: add MEDPresentation --- diff --git a/idl/MEDEventListener.idl b/idl/MEDEventListener.idl index fd6fc6d33..5d4df9211 100644 --- a/idl/MEDEventListener.idl +++ b/idl/MEDEventListener.idl @@ -33,12 +33,13 @@ module MEDCALC EVENT_UPDATE_FIELD, EVENT_CLEAN_WORKSPACE, EVENT_ADD_DATASOURCE, + EVENT_ADD_PRESENTATION, EVENT_UNKNOWN }; struct MedEvent { MedEventType type; - long fieldid; + long dataId; string filename; }; diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index 83a05392e..2d744bbce 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -42,7 +42,8 @@ module MEDCALC long makeScalarMap(in ScalarMapParameters params); void setPresentationProperty(in long presId, in string propName, in string propValue); - + string getPresentationProperty(in long presId, in string propName); + }; }; diff --git a/src/MEDCalc/cmp/MEDFactoryClient.cxx b/src/MEDCalc/cmp/MEDFactoryClient.cxx index d417e5936..2066cead9 100644 --- a/src/MEDCalc/cmp/MEDFactoryClient.cxx +++ b/src/MEDCalc/cmp/MEDFactoryClient.cxx @@ -58,4 +58,16 @@ namespace MEDFactoryClient { } return calculator; } + + /*! + * This returns a singleton (static) instance of the MED presentation manager. + */ + MEDCALC::MEDPresentationManager_ptr getPresentationManager() { + static MEDCALC::MEDPresentationManager_ptr presentationManager; + if(CORBA::is_nil(presentationManager)){ + presentationManager = getFactory()->getPresentationManager(); + } + return presentationManager; + } + } diff --git a/src/MEDCalc/cmp/MEDFactoryClient.hxx b/src/MEDCalc/cmp/MEDFactoryClient.hxx index 054f869be..84c97eef3 100644 --- a/src/MEDCalc/cmp/MEDFactoryClient.hxx +++ b/src/MEDCalc/cmp/MEDFactoryClient.hxx @@ -39,6 +39,7 @@ namespace MEDFactoryClient { MEDCALC_EXPORT MEDCALC::MEDFactory_ptr getFactory(); MEDCALC_EXPORT MEDCALC::MEDDataManager_ptr getDataManager(); MEDCALC_EXPORT MEDCALC::MEDCalculator_ptr getCalculator(); + MEDCALC_EXPORT MEDCALC::MEDPresentationManager_ptr getPresentationManager(); } #endif // _MEDFACTORY_CLIENT_HXX_ diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 3c1956cb5..7c129c23c 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -37,12 +37,27 @@ void MEDPresentation::pushInternal(PyObject * obj, PyObject * disp) _display.push_back(disp); } -void MEDPresentation::setProperty(const char * propName, const char * propValue) +void MEDPresentation::setProperty(const std::string& propName, const std::string& propValue) { // LIMITED!!! For now switch the first display element to Wireframe - + /* PyLockWrapper lock; PyObject_CallMethod(_display[0], (char*)"SetRepresentationType", (char*)"(s)", "Wireframe"); + */ + + _properties[propName] = propValue; +} + +const std::string +MEDPresentation::getProperty(const std::string& propName) +{ + if (_properties.find(propName) != _properties.end()) { + return _properties[propName]; + } + else { + std::cerr << "getProperty(): no property named " << propName << std::endl; + return std::string(); + } } PyObject * MEDPresentation::getPythonObjectFromMain(const char * python_var) diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index d7754fd7d..ef1bdf791 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -29,23 +29,27 @@ #include CORBA_SERVER_HEADER(MEDPresentationManager) #include +#include #include class MEDCALC_EXPORT MEDPresentation { -public: friend class MEDPresentationManager_i; - MEDPresentation(MEDCALC::FieldHandler* fieldHdl): - _fieldHandler(fieldHdl), _pipeline(0), _display(0) - {} +public: + virtual ~MEDPresentation() {} - void setProperty(const char * propName, const char * propValue); + void setProperty(const std::string& propName, const std::string& propValue); + const std::string getProperty(const std::string& propName); std::string getFieldTypeString(); protected: + MEDPresentation(MEDCALC::FieldHandler* fieldHdl): + _fieldHandler(fieldHdl), _pipeline(0), _display(0), _properties() + {} + void generatePipeline(); virtual void internalGeneratePipeline() = 0; PyObject * getPythonObjectFromMain(const char * var); @@ -61,6 +65,9 @@ protected: ///! Corresponding display object, if any: std::vector< PyObject * > _display; + + ///! Presentation properties + std::map _properties; }; class MEDCALC_EXPORT MEDPresentationScalarMap : public MEDPresentation diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index 47cca67da..a268f47f8 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -56,7 +56,7 @@ TypeID MEDPresentationManager_i::GenerateID() #include void -MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue) +MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue) { if (_presentations.find(presentationID) != _presentations.end()) { @@ -69,6 +69,19 @@ MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const c } } +char* +MEDPresentationManager_i::getPresentationProperty(TypeID presentationID, const char* propName) +{ + if (_presentations.find(presentationID) != _presentations.end()) { + MEDPresentation* pres = _presentations[presentationID]; + return (char*) pres->getProperty(propName).c_str(); + } + else { + std::cerr << "getPresentationProperty(): presentation not found!!" << std::endl; + return (char*) ""; + } +} + TypeID MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params) { diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index fca4267ea..1263f8874 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -29,6 +29,7 @@ #include "MEDCALC.hxx" #include +#include typedef ::CORBA::Long TypeID; @@ -42,7 +43,8 @@ class MEDCALC_EXPORT MEDPresentationManager_i: public POA_MEDCALC::MEDPresentati static MEDPresentationManager_i* getInstance(); TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&); - void setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue); + void setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue); + char* getPresentationProperty(TypeID presentationID, const char* propName); private: MEDPresentationManager_i(); diff --git a/src/MEDCalc/gui/DatasourceController.cxx b/src/MEDCalc/gui/DatasourceController.cxx index 0cde0a66b..4d7bc8b8e 100644 --- a/src/MEDCalc/gui/DatasourceController.cxx +++ b/src/MEDCalc/gui/DatasourceController.cxx @@ -179,10 +179,25 @@ DatasourceController::updateTreeViewWithNewDatasource(const MEDCALC::DatasourceH _studyEditor->setIcon(soFieldseries,tr("ICO_DATASOURCE_FIELD").toStdString().c_str()); _studyEditor->setParameterInt(soFieldseries,OBJECT_ID,fieldseriesHandler.id); _studyEditor->setParameterBool(soFieldseries,OBJECT_IS_IN_WORKSPACE,false); + //std::cout << "soFieldseries.GetIOR(): " << soFieldseries._retn()->GetIOR() << std::endl; + //std::cout << _studyEditor->findObject(soFieldseries._retn()->GetIOR())->GetIOR() << std::endl; + std::cout << "soFieldseries.GetName(): " << soFieldseries._retn()->GetName() << std::endl; + } } } +void +DatasourceController::updateTreeViewWithNewPresentation(long presentationId) +{ + if (presentationId < 0) { + return; + } + + std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name"); + +} + void DatasourceController::OnAddDatasource() { // Dialog to get the filename where the input data are read from @@ -568,4 +583,8 @@ DatasourceController::processWorkspaceEvent(const MEDCALC::MedEvent* event) this->updateTreeViewWithNewDatasource(datasourceHandler); _salomeModule->updateObjBrowser(true); } + else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) { + this->updateTreeViewWithNewPresentation(event->dataId); + _salomeModule->updateObjBrowser(true); + } } diff --git a/src/MEDCalc/gui/DatasourceController.hxx b/src/MEDCalc/gui/DatasourceController.hxx index a1f0b6fdf..09ecdc140 100644 --- a/src/MEDCalc/gui/DatasourceController.hxx +++ b/src/MEDCalc/gui/DatasourceController.hxx @@ -27,6 +27,7 @@ #include CORBA_CLIENT_HEADER(MEDDataManager) #include #include +#include #include @@ -57,7 +58,8 @@ typedef struct { EVENT_VIEW_OBJECT_SCALAR_MAP, // these ones forward actions to workspace (and then to python console) EVENT_ADD_DATASOURCE, - EVENT_ADD_IMAGE_AS_DATASOURCE + EVENT_ADD_IMAGE_AS_DATASOURCE, + EVENT_ADD_PRESENTATION }; int eventtype; XmedDataObject * objectdata; @@ -100,6 +102,7 @@ private: void visualize(DatasourceEvent::EventType); void addDatasource(const char* filename); void updateTreeViewWithNewDatasource(const MEDCALC::DatasourceHandler*); + void updateTreeViewWithNewPresentation(long presentationId); private: StandardApp_Module * _salomeModule; diff --git a/src/MEDCalc/gui/MEDEventListener_i.cxx b/src/MEDCalc/gui/MEDEventListener_i.cxx index ae9291e04..a95d6d365 100644 --- a/src/MEDCalc/gui/MEDEventListener_i.cxx +++ b/src/MEDCalc/gui/MEDEventListener_i.cxx @@ -47,7 +47,7 @@ MEDEventListener_i::~MEDEventListener_i() } void MEDEventListener_i::processMedEvent(const MEDCALC::MedEvent & event) { - LOG("Start processing event for field id="<fieldid); + STDLOG("dataId :"<dataId); XmedDataModel * dataModel = (XmedDataModel *)this->getDataModel(); if ( dataModel == NULL ) { @@ -267,7 +267,7 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { else if ( event->type == MEDCALC::EVENT_PUT_IN_WORKSPACE ) { STDLOG("add new field"); MEDCALC::FieldHandler * fieldHandler = - MEDFactoryClient::getDataManager()->getFieldHandler(event->fieldid); + MEDFactoryClient::getDataManager()->getFieldHandler(event->dataId); XmedDataObject * dataObject = (XmedDataObject *)dataModel->newDataObject(); dataObject->setFieldHandler(*fieldHandler); @@ -278,7 +278,7 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { std::map::iterator itr = dataModel->begin(); for ( ; itr != dataModel->end(); ++itr) { XmedDataObject* obj = dynamic_cast(itr->second); - if (obj->getFieldHandler()->id == event->fieldid) { + if (obj->getFieldHandler()->id == event->dataId) { std::string itemNameId = obj->getNameId(); this->getDataTreeModel()->removeData(obj); dataModel->removeDataObject(itemNameId); @@ -299,6 +299,9 @@ void WorkspaceController::processMedEvent(const MEDCALC::MedEvent * event) { else if ( event->type == MEDCALC::EVENT_ADD_DATASOURCE ) { emit workspaceSignal(event); // forward to DatasourceController } + else if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) { + emit workspaceSignal(event); // forward to DatasourceController + } } diff --git a/src/MEDCalc/tui/medevents.py b/src/MEDCalc/tui/medevents.py index d5e0f212c..2feb1645d 100644 --- a/src/MEDCalc/tui/medevents.py +++ b/src/MEDCalc/tui/medevents.py @@ -83,8 +83,8 @@ connectEventListener() # that they could be used in another context than the FieldProxy instances import MEDCALC -def __notifyGui(type, fieldId=-1, filename=""): - medEvent = MEDCALC.MedEvent(type, fieldId, filename) +def __notifyGui(eventType, dataId=-1, filename=""): + medEvent = MEDCALC.MedEvent(eventType, dataId, filename) if not eventListenerIsRunning(): return # Notify the GUI of the update event @@ -112,3 +112,6 @@ def notifyGui_cleanWorkspace(): def notifyGui_addDatasource(filename): __notifyGui(MEDCALC.EVENT_ADD_DATASOURCE, -1, filename) # +def notifyGui_addPresentation(presentation_id): + __notifyGui(MEDCALC.EVENT_ADD_PRESENTATION, presentation_id) +# diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index c0a158e9d..fad2d9680 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -19,6 +19,7 @@ import medcalc import MEDCALC +from medcalc.medevents import notifyGui_addPresentation __manager = medcalc.medcorba.factory.getPresentationManager() @@ -31,8 +32,8 @@ def MakeScalarMap(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE): print "viewMode:", viewMode, " [", type(viewMode), "]" params = MEDCALC.ScalarMapParameters(proxy.id, viewMode) - __manager.makeScalarMap(params) - + presentation_id = __manager.makeScalarMap(params) + notifyGui_addPresentation(presentation_id) # def MakeIsoSurface():