From b4f7dcf77900b877394b030a9be980b760468a03 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Wed, 22 Jul 2015 15:33:37 +0200 Subject: [PATCH] datasource load from gui relies on tui --- idl/MEDDataManager.idl | 3 +- src/MEDOP/cmp/MEDDataManager_i.cxx | 26 ++++++++--- src/MEDOP/cmp/MEDDataManager_i.hxx | 3 +- src/MEDOP/cmp/MEDPresentationManager_i.cxx | 1 - src/MEDOP/cmp/test_medop_components.py | 46 +++++++++---------- src/MEDOP/doc/sphinx/fr/medop-develguide.rst | 16 +++---- src/MEDOP/doc/sphinx/medop-develguide.rst | 16 +++---- src/MEDOP/gui/DatasourceController.cxx | 26 +++++++---- src/MEDOP/gui/DatasourceController.hxx | 6 ++- src/MEDOP/gui/WorkspaceController.cxx | 6 +++ .../tui/medpresentation/medpresentation.py | 3 +- src/MEDOP/tui/xmedpy/fieldtools.py | 2 + .../xmedpy/tests/test_xmed_fieldOperations.py | 10 ++-- 13 files changed, 100 insertions(+), 64 deletions(-) diff --git a/idl/MEDDataManager.idl b/idl/MEDDataManager.idl index 26acc5a3e..a0fa2907e 100644 --- a/idl/MEDDataManager.idl +++ b/idl/MEDDataManager.idl @@ -116,7 +116,8 @@ module MEDOP //========================================================== // Datasource management //========================================================== - DatasourceHandler addDatasource(in string filepath); + DatasourceHandler loadDatasource(in string filepath); + DatasourceHandler getDatasourceHandler(in string filepath); //========================================================== // Mesh data management diff --git a/src/MEDOP/cmp/MEDDataManager_i.cxx b/src/MEDOP/cmp/MEDDataManager_i.cxx index 5db5c996e..a2af2f07d 100644 --- a/src/MEDOP/cmp/MEDDataManager_i.cxx +++ b/src/MEDOP/cmp/MEDDataManager_i.cxx @@ -77,7 +77,7 @@ std::string MEDDataManager_i::source_to_file(const char * source) * is a key to retrieve all informations concerning the data (meshes, * fields). */ -MEDOP::DatasourceHandler * MEDDataManager_i::addDatasource(const char *filepath) { +MEDOP::DatasourceHandler * MEDDataManager_i::loadDatasource(const char *filepath) { // We first check that this datasource is not already registered long sourceid = getDatasourceId(filepath); @@ -202,6 +202,20 @@ long MEDDataManager_i::getDatasourceId(const char *filepath) { return LONG_UNDEFINED; } +MEDOP::DatasourceHandler* +MEDDataManager_i::getDatasourceHandler(const char *filepath) +{ + std::string uri(file_to_source(filepath)); + DatasourceHandlerMapIterator it = _datasourceHandlerMap.begin(); + while ( it != _datasourceHandlerMap.end() ) { + if ( strcmp(it->second->uri,uri.c_str()) == 0 ) { + return it->second; + } + ++it; + } + return NULL; +} + MEDOP::MeshHandler * MEDDataManager_i::getMesh(CORBA::Long meshId) { if ( _meshHandlerMap.count(meshId) == 0 ) { @@ -293,7 +307,7 @@ MEDOP::FieldHandlerList * MEDDataManager_i::getFieldListInFieldseries(CORBA::Lon /*! * This returns the whole set of fields handlers for all datasource - * that have been loaded using addDatasource. + * that have been loaded using loadDatasource. */ MEDOP::FieldHandlerList * MEDDataManager_i::getFieldHandlerList() { MEDOP::FieldHandlerList_var fieldHandlerSeq = new MEDOP::FieldHandlerList(); @@ -562,15 +576,15 @@ MEDCouplingFieldDouble * MEDDataManager_i::getFieldDouble(const MEDOP::FieldHand // At this step, the mesh handler needs a meshid correctly // set. Normally, we should arrive at this step only in the case // where the field is loaded from a file ==> the meshid is defined - // (see the addDatasource function). + // (see the loadDatasource function). // // >>>> __GBO__ TO BE CHECKED AND SERIOUSLY TESTED. There at least // one case where we can arrive here with no previous call to - // addDataSource: for example the field handler list can be obtained - // from a call to addFieldsFromFile instead of addDataSource (see + // loadDataSource: for example the field handler list can be obtained + // from a call to addFieldsFromFile instead of loadDataSource (see // for exemple the getFieldRepresentation service of the // dataManager, that comes here and then calls getUMesh where we - // need a map initialized only in addDataSource) <<<< + // need a map initialized only in loadDataSource) <<<< long meshid = fieldHandler->meshid; // We first have to check if the associated mesh is already loaded diff --git a/src/MEDOP/cmp/MEDDataManager_i.hxx b/src/MEDOP/cmp/MEDDataManager_i.hxx index f950f5be9..43eb0fcf0 100644 --- a/src/MEDOP/cmp/MEDDataManager_i.hxx +++ b/src/MEDOP/cmp/MEDDataManager_i.hxx @@ -69,7 +69,8 @@ public: // // ----------------------------------------------------------- // Datasource management - MEDOP::DatasourceHandler * addDatasource(const char *filepath); + MEDOP::DatasourceHandler * loadDatasource(const char *filepath); + MEDOP::DatasourceHandler * getDatasourceHandler(const char *filepath); // ----------------------------------------------------------- // Mesh management diff --git a/src/MEDOP/cmp/MEDPresentationManager_i.cxx b/src/MEDOP/cmp/MEDPresentationManager_i.cxx index b37e616ad..4bcd056de 100644 --- a/src/MEDOP/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDOP/cmp/MEDPresentationManager_i.cxx @@ -41,6 +41,5 @@ MEDPresentationManager_i::~MEDPresentationManager_i() void MEDPresentationManager_i::MakeScalarMap(const MEDOP::ScalarMapParameters& params) { - std::cout << "View mode: " << params.viewMode << std::endl; std::cout << "MEDPresentationManager_i::MakeScalarMap: Not implemented yet\n"; } diff --git a/src/MEDOP/cmp/test_medop_components.py b/src/MEDOP/cmp/test_medop_components.py index be873629b..f332306d4 100644 --- a/src/MEDOP/cmp/test_medop_components.py +++ b/src/MEDOP/cmp/test_medop_components.py @@ -106,13 +106,13 @@ testFilePath = getFilePath(testFileName) # def TEST_getDataManager(): dataManager = factory.getDataManager() - if "addDatasource" not in dir(dataManager): + if "loadDatasource" not in dir(dataManager): return False return True -def TEST_addDatasource(): +def TEST_loadDatasource(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) if datasource.name != testFileName: print "ERR: datasource.name=%s (should be %s)"%(datasource.name,testFilePath) return False @@ -120,16 +120,16 @@ def TEST_addDatasource(): # We try to load the file twice. It should not load twice and # return the same datasource as previously registered (same id). sourceid_ref = datasource.id - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) if datasource.id != sourceid_ref: print "ERR: datasource.id=%s (should be %s)"%(datasource.id,sourceid_ref) return False - + return True def TEST_getFieldHandlerList(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() if fieldHandlerList is None or len(fieldHandlerList) == 0: return False @@ -137,7 +137,7 @@ def TEST_getFieldHandlerList(): def TEST_getFieldRepresentation(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() fieldHandler0 = fieldHandlerList[0] @@ -146,13 +146,13 @@ def TEST_getFieldRepresentation(): def TEST_updateFieldMetadata(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() fieldHandler0 = fieldHandlerList[0] fieldid = fieldHandler0.id newname = fieldHandler0.fieldname + " modified" - + dataManager.updateFieldMetadata(fieldid, newname, fieldHandler0.iteration, fieldHandler0.order, @@ -168,7 +168,7 @@ def TEST_updateFieldMetadata(): def TEST_saveFields(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() fieldHandler0 = fieldHandlerList[0] fieldIdList = [fieldHandler0.id] @@ -176,7 +176,7 @@ def TEST_saveFields(): print "fieldIdList = %s"%fieldIdList print "filepath = %s"%filepath - + dataManager.saveFields(filepath,fieldIdList) # We just control that the file exists. But we should reload the # contents to check the fields @@ -193,17 +193,17 @@ def TEST_saveFields(): # def TEST_MEDDataManager_getMeshList(): dataManager = factory.getDataManager() - datasourceHandler = dataManager.addDatasource(testFilePath) + datasourceHandler = dataManager.loadDatasource(testFilePath) meshHandlerList = dataManager.getMeshList(datasourceHandler.id) print meshHandlerList if len(meshHandlerList) == 0: return False return True - + def TEST_MEDDataManager_getMesh(): dataManager = factory.getDataManager() - datasourceHandler = dataManager.addDatasource(testFilePath) + datasourceHandler = dataManager.loadDatasource(testFilePath) meshHandlerList = dataManager.getMeshList(datasourceHandler.id) for mRef in meshHandlerList: meshId = mRef.id @@ -212,10 +212,10 @@ def TEST_MEDDataManager_getMesh(): if ( mRes.name != mRef.name ) or ( mRes.sourceid != mRef.sourceid): return False return True - + def TEST_MEDDataManager_getFieldseriesListOnMesh(): dataManager = factory.getDataManager() - datasourceHandler = dataManager.addDatasource(testFilePath) + datasourceHandler = dataManager.loadDatasource(testFilePath) meshHandlerList = dataManager.getMeshList(datasourceHandler.id) # We look for the fieldseries defined on the first mesh of the list @@ -232,7 +232,7 @@ def TEST_MEDDataManager_getFieldListInFieldseries(): testFilePath = os.path.join(RESDIR,testFileName) testFilePath = getFilePath("timeseries.med") - datasourceHandler = dataManager.addDatasource(testFilePath) + datasourceHandler = dataManager.loadDatasource(testFilePath) meshHandlerList = dataManager.getMeshList(datasourceHandler.id) # We look for the fieldseries defined on the first mesh of the list @@ -255,7 +255,7 @@ def TEST_MEDDataManager_getFieldListInFieldseries(): # def TEST_Calculator_basics(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() # Try to operate on the two first fields @@ -274,7 +274,7 @@ def TEST_Calculator_basics(): div = calculator.div(fieldHandler0, fieldHandler1) print div #power = calculator.pow(fieldHandler0, 2) - #print power + #print power linear = calculator.lin(fieldHandler0, 3,2) print linear @@ -282,7 +282,7 @@ def TEST_Calculator_basics(): def TEST_Calculator_applyFunc(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() fieldHandler = fieldHandlerList[0] @@ -307,7 +307,7 @@ def TEST_Calculator_applyFunc(): # def TEST_markAsPersistent(): dataManager = factory.getDataManager() - datasource = dataManager.addDatasource(testFilePath) + datasource = dataManager.loadDatasource(testFilePath) fieldHandlerList = dataManager.getFieldHandlerList() fieldHandler0 = fieldHandlerList[0] fieldHandler1 = fieldHandlerList[1] @@ -337,8 +337,8 @@ class MyTestSuite(unittest.TestCase): def test_getDataManager(self): self.assertTrue(TEST_getDataManager()) - def test_addDatasource(self): - self.assertTrue(TEST_addDatasource()) + def test_loadDatasource(self): + self.assertTrue(TEST_loadDatasource()) def test_getFieldHandlerList(self): self.assertTrue(TEST_getFieldHandlerList()) diff --git a/src/MEDOP/doc/sphinx/fr/medop-develguide.rst b/src/MEDOP/doc/sphinx/fr/medop-develguide.rst index 57f826e1c..444a0a9a6 100644 --- a/src/MEDOP/doc/sphinx/fr/medop-develguide.rst +++ b/src/MEDOP/doc/sphinx/fr/medop-develguide.rst @@ -65,14 +65,14 @@ lancés depuis une session shell SALOME. Dans un nouveau shell, taper:: L'exécution imprime un rapport détaillant le résultat pour chaque fonction de test:: - + test_Calculator_applyFunc (__main__.MyTestSuite) ... ok test_Calculator_basics (__main__.MyTestSuite) ... ok test_MEDDataManager_getFieldListInFieldseries (__main__.MyTestSuite) ... ok test_MEDDataManager_getFieldseriesListOnMesh (__main__.MyTestSuite) ... ok test_MEDDataManager_getMesh (__main__.MyTestSuite) ... ok test_MEDDataManager_getMeshList (__main__.MyTestSuite) ... ok - test_addDatasource (__main__.MyTestSuite) ... ok + test_loadDatasource (__main__.MyTestSuite) ... ok test_getDataManager (__main__.MyTestSuite) ... ok test_getFieldHandlerList (__main__.MyTestSuite) ... ok test_getFieldRepresentation (__main__.MyTestSuite) ... ok @@ -150,7 +150,7 @@ valeurs des champs et les maillages support sont chargés au besoin. Le chargement des métadonnées de description se fait par la méthode:: - addDatasource(const char \*filepath) + loadDatasource(const char \*filepath) @@ -164,16 +164,16 @@ Ecrire un service CORBA qui retourne une sequence de FieldHandler: MEDOP::FieldHandlerList * MyFunction(...) { vector fieldHandlerList; ... - + fieldHandlerList.push_back(fieldHandler); - + // Map the resulting list to a CORBA sequence for return: MEDOP::FieldHandlerList_var fieldHandlerSeq = new MEDOP::FieldHandlerList(); int nbFieldHandler = fieldHandlerList.size(); fieldHandlerSeq->length(nbFieldHandler); for (int i=0; i fieldHandlerList; ... - + fieldHandlerList.push_back(fieldHandler); - + // Map the resulting list to a CORBA sequence for return: MEDOP::FieldHandlerList_var fieldHandlerSeq = new MEDOP::FieldHandlerList(); int nbFieldHandler = fieldHandlerList.size(); fieldHandlerSeq->length(nbFieldHandler); for (int i=0; iaddDatasource(filename); +void +DatasourceController::addDatasource(const char* filename) +{ + DatasourceEvent* event = new DatasourceEvent(); + event->eventtype = DatasourceEvent::EVENT_ADD_DATASOURCE; + event->objectalias = filename; + emit datasourceSignal(event); +} +// call to this function is trigerred by workspace (itself from python console) +void +DatasourceController::updateTreeViewWithNewDatasource(const MEDOP::DatasourceHandler* datasourceHandler) +{ + if (!datasourceHandler) { + return; + } // We need a studyEditor updated on the active study _studyEditor->updateActiveStudy(); @@ -169,8 +180,6 @@ MEDOP::DatasourceHandler * DatasourceController::addDatasource(const char * file _studyEditor->setParameterBool(soFieldseries,OBJECT_IS_IN_WORKSPACE,false); } } - - return datasourceHandler; } @@ -554,10 +563,11 @@ void DatasourceController::OnInterpolateFieldInputValidated() { } void -DatasourceController::processWorkspaceEvent(const MEDOP::MedEvent * event) +DatasourceController::processWorkspaceEvent(const MEDOP::MedEvent* event) { if ( event->type == MEDOP::EVENT_ADD_DATASOURCE ) { - this->addDatasource(event->filename); + MEDOP::DatasourceHandler* datasourceHandler = MEDOPFactoryClient::getDataManager()->getDatasourceHandler(event->filename); + this->updateTreeViewWithNewDatasource(datasourceHandler); _salomeModule->updateObjBrowser(true); } } diff --git a/src/MEDOP/gui/DatasourceController.hxx b/src/MEDOP/gui/DatasourceController.hxx index 9ed1ee0da..63d3fc960 100644 --- a/src/MEDOP/gui/DatasourceController.hxx +++ b/src/MEDOP/gui/DatasourceController.hxx @@ -54,7 +54,8 @@ typedef struct { EVENT_IMPORT_OBJECT, // Simply import the object in the workspace EVENT_USE_OBJECT, // Import in the workspace AND define a proxy // variable in the tui console to use it - EVENT_VIEW_OBJECT_SCALAR_MAP + EVENT_VIEW_OBJECT_SCALAR_MAP, + EVENT_ADD_DATASOURCE // to forward action to workspace (and then to python console) }; int eventtype; XmedDataObject * objectdata; @@ -74,7 +75,6 @@ public: ~DatasourceController(); void createActions(); - MEDOP::DatasourceHandler * addDatasource(const char * filename); public slots: // Callback connected to dialog box validation signals @@ -96,6 +96,8 @@ protected slots: private: void visualize(DatasourceEvent::EventType); + void addDatasource(const char* filename); + void updateTreeViewWithNewDatasource(const MEDOP::DatasourceHandler*); private: StandardApp_Module * _salomeModule; diff --git a/src/MEDOP/gui/WorkspaceController.cxx b/src/MEDOP/gui/WorkspaceController.cxx index e5ef41345..6d28d336d 100644 --- a/src/MEDOP/gui/WorkspaceController.cxx +++ b/src/MEDOP/gui/WorkspaceController.cxx @@ -498,6 +498,12 @@ void WorkspaceController::processDatasourceEvent(const DatasourceEvent * event) commands += QString("MakeScalarMap(get(%1), %2)").arg(fieldHandler->id).arg(viewMode); _consoleDriver->exec(commands); } + else if ( event->eventtype == DatasourceEvent::EVENT_ADD_DATASOURCE ) { + QStringList commands; + commands += QString("from medpresentation import LoadDataSource"); + commands += QString("LoadDataSource('%1')").arg(event->objectalias); + _consoleDriver->exec(commands); + } else { STDLOG("The event "<eventtype<<" is not implemented yet"); } diff --git a/src/MEDOP/tui/medpresentation/medpresentation.py b/src/MEDOP/tui/medpresentation/medpresentation.py index 7e51ad0a0..1fb6d8618 100644 --- a/src/MEDOP/tui/medpresentation/medpresentation.py +++ b/src/MEDOP/tui/medpresentation/medpresentation.py @@ -24,6 +24,7 @@ import SALOME __manager = xmed.factory.getPresentationManager() def LoadDataSource(filename): + xmed.dataManager.loadDatasource(filename) from xmed.fieldproxy import notifyGui_addsource notifyGui_addsource(filename) # @@ -36,7 +37,7 @@ def MakeScalarMap(proxy, viewMode=MEDOP.VIEW_MODE_REPLACE): print "viewMode:", viewMode, " [", type(viewMode), "]" - params = MEDOP.ScalarMapParameters(proxy.id, viewMode); + params = MEDOP.ScalarMapParameters(proxy.id, viewMode) __manager.MakeScalarMap(params) # diff --git a/src/MEDOP/tui/xmedpy/fieldtools.py b/src/MEDOP/tui/xmedpy/fieldtools.py index 33beb8641..13effcd80 100644 --- a/src/MEDOP/tui/xmedpy/fieldtools.py +++ b/src/MEDOP/tui/xmedpy/fieldtools.py @@ -155,6 +155,8 @@ def load(medFileName=filepath): """ xmed.dataManager.addDatasource(filepath) print status(local=False,remote=True) + from xmed.fieldproxy import notifyGui_addsource + notifyGui_addsource(filename) def get(fieldHandlerId): """ diff --git a/src/MEDOP/tui/xmedpy/tests/test_xmed_fieldOperations.py b/src/MEDOP/tui/xmedpy/tests/test_xmed_fieldOperations.py index de911c7a8..4f7daab0f 100644 --- a/src/MEDOP/tui/xmedpy/tests/test_xmed_fieldOperations.py +++ b/src/MEDOP/tui/xmedpy/tests/test_xmed_fieldOperations.py @@ -38,7 +38,7 @@ xmed.setConsoleGlobals(globals()) # Load some test data in the MedDataManager filepath = properties.testFilePath -xmed.dataManager.addDatasource(filepath) +xmed.dataManager.loadDatasource(filepath) fieldHandlerList = xmed.dataManager.getFieldHandlerList() def setup(): @@ -63,11 +63,11 @@ def TEST_addition(): # The addition can be done using field handler directly addFieldHandler = xmed.calculator.add(fieldHandler0, fieldHandler1) print addFieldHandler - + # Or with a field proxy that ease the writing of operations fieldProxy0 = FieldProxy(fieldHandler0) fieldProxy1 = FieldProxy(fieldHandler1) - + res = fieldProxy0 + fieldProxy1 if res is None: return False @@ -128,7 +128,7 @@ def TEST_composition(): if res is None: return False return True - + def TEST_litteral_equation(): fieldProxy0 = FieldProxy(fieldHandlerList[0]) res = fieldProxy0.ope("abs(u)^2") @@ -225,7 +225,7 @@ def myusecases(): #TEST_unary_operations() #TEST_update_metadata() #TEST_composition() - + if __name__ == "__main__": #myusecases() myunittests() -- 2.30.2