From: abn Date: Fri, 31 Jul 2015 13:57:59 +0000 (+0200) Subject: First scalar map implementation. No GUI (tree browser) update. X-Git-Tag: V8_0_0a1~5^2~35 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5e69906f174ec4dff3a944729f9c4abf8abd3998;p=modules%2Fmed.git First scalar map implementation. No GUI (tree browser) update. --- diff --git a/idl/MEDDataManager.idl b/idl/MEDDataManager.idl index 06d9e4d2e..c18c0740e 100644 --- a/idl/MEDDataManager.idl +++ b/idl/MEDDataManager.idl @@ -118,6 +118,7 @@ module MEDCALC //========================================================== DatasourceHandler loadDatasource(in string filepath); DatasourceHandler getDatasourceHandler(in string filepath); + DatasourceHandler getDatasourceHandlerFromID(in long sourceid); //========================================================== // Mesh data management diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index cab47d064..83a05392e 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -25,7 +25,6 @@ module MEDCALC { - enum MEDPresentationViewMode { VIEW_MODE_OVERLAP, VIEW_MODE_REPLACE, @@ -41,8 +40,9 @@ module MEDCALC interface MEDPresentationManager : SALOME::GenericObj { - void MakeScalarMap(in ScalarMapParameters params); - + long makeScalarMap(in ScalarMapParameters params); + void setPresentationProperty(in long presId, in string propName, in string propValue); + }; }; diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 57ed9e3e3..1c54b6c75 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES( ${MEDFILE_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS} ${PTHREAD_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_BINARY_DIR}/idl ${PROJECT_SOURCE_DIR}/src/MEDCoupling @@ -38,27 +39,20 @@ SET(MEDFactoryEngine_SOURCES MEDCalculator_i.cxx MEDPresentationManager_i.cxx MEDFactory_i.cxx + MEDPresentation.cxx ) SET(COMMON_LIBS - medloader + ${PLATFORM_LIBRARIES} SalomeIDLMED - ${KERNEL_TOOLSDS} - ${KERNEL_SalomeHDFPersist} - ${KERNEL_SalomeContainer} - ${KERNEL_SalomeCommunication} - ${KERNEL_SalomeKernelHelpers} - ${KERNEL_SalomeLifeCycleCORBA} - ${KERNEL_SALOMELocalTrace} - ${KERNEL_SALOMEBasics} + ${KERNEL_TOOLSDS} ${KERNEL_SalomeHDFPersist} ${KERNEL_SalomeContainer} ${KERNEL_SalomeCommunication} + ${KERNEL_SalomeKernelHelpers} ${KERNEL_SalomeLifeCycleCORBA} ${KERNEL_SALOMELocalTrace} ${KERNEL_SALOMEBasics} ${KERNEL_SalomeGenericObj} - medcoupling - medcouplingremapper - interpkernel + medloader medcoupling medcouplingremapper interpkernel ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${OMNIORB_LIBRARIES} - ${PLATFORM_LIBRARIES} + ${PYTHON_LIBRARIES} ) # This undefines the macros MIN and MAX which are specified in the windows headers @@ -68,7 +62,7 @@ ENDIF(WIN32) ADD_LIBRARY(MEDFactoryEngine SHARED ${MEDFactoryEngine_SOURCES}) SET_TARGET_PROPERTIES(MEDFactoryEngine PROPERTIES COMPILE_FLAGS "${COMMON_FLAGS}") -TARGET_LINK_LIBRARIES(MEDFactoryEngine SalomeIDLMED ${COMMON_LIBS}) +TARGET_LINK_LIBRARIES(MEDFactoryEngine ${COMMON_LIBS}) INSTALL(TARGETS MEDFactoryEngine DESTINATION ${SALOME_INSTALL_LIBS}) diff --git a/src/MEDCalc/cmp/MEDDataManager_i.cxx b/src/MEDCalc/cmp/MEDDataManager_i.cxx index ce81c29d9..3f9f46055 100644 --- a/src/MEDCalc/cmp/MEDDataManager_i.cxx +++ b/src/MEDCalc/cmp/MEDDataManager_i.cxx @@ -216,6 +216,16 @@ MEDDataManager_i::getDatasourceHandler(const char *filepath) return NULL; } +MEDCALC::DatasourceHandler* +MEDDataManager_i::getDatasourceHandlerFromID(CORBA::Long sourceid) +{ + DatasourceHandlerMapIterator it = _datasourceHandlerMap.find(sourceid); + if (it != _datasourceHandlerMap.end()) + { + return it->second; + } + return NULL; +} MEDCALC::MeshHandler * MEDDataManager_i::getMesh(CORBA::Long meshId) { if ( _meshHandlerMap.count(meshId) == 0 ) { diff --git a/src/MEDCalc/cmp/MEDDataManager_i.hxx b/src/MEDCalc/cmp/MEDDataManager_i.hxx index bb20a0944..5192fedb8 100644 --- a/src/MEDCalc/cmp/MEDDataManager_i.hxx +++ b/src/MEDCalc/cmp/MEDDataManager_i.hxx @@ -71,6 +71,7 @@ public: // Datasource management MEDCALC::DatasourceHandler * loadDatasource(const char *filepath); MEDCALC::DatasourceHandler * getDatasourceHandler(const char *filepath); + MEDCALC::DatasourceHandler * getDatasourceHandlerFromID(CORBA::Long sourceId); // ----------------------------------------------------------- // Mesh management diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx new file mode 100644 index 000000000..3c1956cb5 --- /dev/null +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -0,0 +1,117 @@ +// Copyright (C) 2011-2015 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Authors: A Bruneton (CEA), C Aguerre (EdF) + +#include "MEDFactoryClient.hxx" +#include "MEDPresentation.hxx" +#include "MEDCouplingRefCountObject.hxx" +#include +#include + +void MEDPresentation::generatePipeline() +{ + // Might be more complicated in the future: + + this->internalGeneratePipeline(); +} + +void MEDPresentation::pushInternal(PyObject * obj, PyObject * disp) +{ + _pipeline.push_back(obj); + _display.push_back(disp); +} + +void MEDPresentation::setProperty(const char * propName, const char * propValue) +{ + // LIMITED!!! For now switch the first display element to Wireframe + + PyLockWrapper lock; + PyObject_CallMethod(_display[0], (char*)"SetRepresentationType", (char*)"(s)", "Wireframe"); +} + +PyObject * MEDPresentation::getPythonObjectFromMain(const char * python_var) +{ + // TODO: improve to avoid getting dict at each call + + // All the calls below returns *borrowed* references + PyObject* main_module = PyImport_AddModule((char*)"__main__"); + PyObject* global_dict = PyModule_GetDict(main_module); + return PyDict_GetItemString(global_dict, python_var); +} + +std::string MEDPresentation::getFieldTypeString() +{ + ParaMEDMEM::TypeOfField typ = (ParaMEDMEM::TypeOfField)_fieldHandler->type; + switch(typ) + { + case ParaMEDMEM::ON_CELLS: + return "CELLS"; + case ParaMEDMEM::ON_NODES: + return "NODES"; + default: + std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?"; + return ""; + } +} + + +void MEDPresentationScalarMap::internalGeneratePipeline() +{ + MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager()); + + MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(_fieldHandler->meshid); + MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid); + + std::string fileName(dataSHandler->uri); + std::string fieldName(_fieldHandler->fieldname); + std::string fieldType = getFieldTypeString(); + + std::cout << "Generating pipeline for SCALAR MAP:" < +#include "MEDCALC.hxx" + +#include +#include CORBA_SERVER_HEADER(MEDDataManager) +#include CORBA_SERVER_HEADER(MEDPresentationManager) + +#include +#include + +class MEDCALC_EXPORT MEDPresentation +{ +public: + friend class MEDPresentationManager_i; + + MEDPresentation(MEDCALC::FieldHandler* fieldHdl): + _fieldHandler(fieldHdl), _pipeline(0), _display(0) + {} + virtual ~MEDPresentation() {} + + void setProperty(const char * propName, const char * propValue); + std::string getFieldTypeString(); + +protected: + + void generatePipeline(); + virtual void internalGeneratePipeline() = 0; + PyObject * getPythonObjectFromMain(const char * var); + void pushInternal(PyObject * obj, PyObject * disp = NULL); + +protected: + + ///! field reference - borrowed. + MEDCALC::FieldHandler* _fieldHandler; + + ///! Pipeline elements + std::vector< PyObject * > _pipeline; + + ///! Corresponding display object, if any: + std::vector< PyObject * > _display; +}; + +class MEDCALC_EXPORT MEDPresentationScalarMap : public MEDPresentation +{ +public: + MEDPresentationScalarMap(MEDCALC::FieldHandler* fieldHdl, bool wireframe) : + MEDPresentation(fieldHdl), + _isWireframe(wireframe) + {} + virtual ~MEDPresentationScalarMap() {} + +protected: + virtual void internalGeneratePipeline(); + +private: + bool _isWireframe; +}; + +#endif /* SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_ */ diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index eb0be04fd..47cca67da 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -19,6 +19,7 @@ #include "MEDPresentationManager_i.hxx" #include "MEDFactoryClient.hxx" +#include "MEDPresentation.hxx" MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL; @@ -45,19 +46,52 @@ MEDPresentationManager_i::~MEDPresentationManager_i() */ } +TypeID MEDPresentationManager_i::GenerateID() +{ + static TypeID START_ID = -1; + START_ID++; + return START_ID; +} + #include void -MEDPresentationManager_i::MakeScalarMap(const MEDCALC::ScalarMapParameters& params) +MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue) +{ + if (_presentations.find(presentationID) != _presentations.end()) + { + MEDPresentation * pres(_presentations[presentationID]); + pres->setProperty(propName, propValue); + } + else + { + std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl; + } +} + +TypeID +MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params) { - std::cout << "MEDPresentationManager_i::MakeScalarMap: Not implemented yet\n"; + MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager()); - std::size_t fieldHandlerId = params.fieldHandlerId; + TypeID fieldHandlerId = params.fieldHandlerId; MEDCALC::MEDPresentationViewMode viewMode = params.viewMode; + MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId); + MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid); + MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid); + std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl; std::cout << "\tviewMode: " << viewMode << std::endl; + std::cout << "\tfileName: " << dataSHandler->uri << std::endl; + std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl; + + // Create a new presentation instance + TypeID newID = MEDPresentationManager_i::GenerateID(); + MEDPresentationScalarMap * scalarMap = new MEDPresentationScalarMap(fieldHandler, true); // on stack or on heap?? stack for now + _presentations.insert( std::pair(newID, scalarMap) ); - MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldHandlerId); + scalarMap->generatePipeline(); + return newID; } diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 4d81c28e3..fca4267ea 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -30,6 +30,10 @@ #include +typedef ::CORBA::Long TypeID; + +class MEDPresentation; + class MEDCALC_EXPORT MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, public SALOME::GenericObj_i { @@ -37,10 +41,10 @@ class MEDCALC_EXPORT MEDPresentationManager_i: public POA_MEDCALC::MEDPresentati static MEDPresentationManager_i* getInstance(); - void MakeScalarMap(const MEDCALC::ScalarMapParameters&); + TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&); + void setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue); private: - MEDPresentationManager_i(); virtual ~MEDPresentationManager_i(); @@ -49,9 +53,10 @@ class MEDCALC_EXPORT MEDPresentationManager_i: public POA_MEDCALC::MEDPresentati // The MEDPresentationManager is a singleton, whose instance can be obtained // using the getInstance static method. static MEDPresentationManager_i * _instance; + static TypeID GenerateID(); // Owns a list of MEDPresentation objects - //std::vector _presentations; + std::map< TypeID, MEDPresentation * > _presentations; }; diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index 5e4945ca3..c0a158e9d 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -31,7 +31,7 @@ def MakeScalarMap(proxy, viewMode=MEDCALC.VIEW_MODE_REPLACE): print "viewMode:", viewMode, " [", type(viewMode), "]" params = MEDCALC.ScalarMapParameters(proxy.id, viewMode) - __manager.MakeScalarMap(params) + __manager.makeScalarMap(params) #