//==========================================================
DatasourceHandler loadDatasource(in string filepath);
DatasourceHandler getDatasourceHandler(in string filepath);
+ DatasourceHandler getDatasourceHandlerFromID(in long sourceid);
//==========================================================
// Mesh data management
module MEDCALC
{
-
enum MEDPresentationViewMode {
VIEW_MODE_OVERLAP,
VIEW_MODE_REPLACE,
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);
+
};
};
${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
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
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})
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 ) {
// Datasource management
MEDCALC::DatasourceHandler * loadDatasource(const char *filepath);
MEDCALC::DatasourceHandler * getDatasourceHandler(const char *filepath);
+ MEDCALC::DatasourceHandler * getDatasourceHandlerFromID(CORBA::Long sourceId);
// -----------------------------------------------------------
// Mesh management
--- /dev/null
+// 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 <PyInterp_Utils.h>
+#include <iostream>
+
+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:" <<std::endl;
+ std::cout << "\tfileName: " << fileName << std::endl;
+ std::cout << "\tfiedName: " << fieldName << std::endl;
+ if (fileName.substr(0, 7) != std::string("file://"))
+ {
+ std::cerr << "\tData source is not a file! Can not proceed." << std::endl;
+ return;
+ }
+
+ fileName = fileName.substr(7, fileName.size());
+ std::cout << "\tfileName: " << fileName << std::endl;
+
+ { // PyLock protected section
+ PyLockWrapper lock;
+
+ PyRun_SimpleString("print 'hello world'");
+ std::string cmd = std::string(
+ "import pvsimple as pvs;"
+ "__obj1 = pvs.MEDReader(FileName='") + fileName + std::string("');"
+ "__disp1 = pvs.Show(__obj1);"
+ "pvs.ColorBy(__disp1, ('") + fieldType + std::string("', '") + fieldName + std::string("'));"
+ "pvs.GetActiveViewOrCreate('RenderView').ResetCamera()");
+
+ std::cerr << "Python command:" << std::endl;
+ std::cerr << cmd << std::endl;
+ PyRun_SimpleString(cmd.c_str());
+ // Retrieve Python object for internal storage:
+ PyObject * obj = getPythonObjectFromMain("__obj1");
+ PyObject * disp = getPythonObjectFromMain("__disp1");
+ pushInternal(obj, disp);
+ }
+
+}
--- /dev/null
+// 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)
+
+#ifndef SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
+#define SRC_MEDCALC_CMP_MEDPRESENTATION_HXX_
+
+#include <Python.h>
+#include "MEDCALC.hxx"
+
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(MEDDataManager)
+#include CORBA_SERVER_HEADER(MEDPresentationManager)
+
+#include <vector>
+#include <string>
+
+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_ */
#include "MEDPresentationManager_i.hxx"
#include "MEDFactoryClient.hxx"
+#include "MEDPresentation.hxx"
MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
*/
}
+TypeID MEDPresentationManager_i::GenerateID()
+{
+ static TypeID START_ID = -1;
+ START_ID++;
+ return START_ID;
+}
+
#include <iostream>
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<TypeID, MEDPresentation *>(newID, scalarMap) );
- MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldHandlerId);
+ scalarMap->generatePipeline();
+ return newID;
}
#include <vector>
+typedef ::CORBA::Long TypeID;
+
+class MEDPresentation;
+
class MEDCALC_EXPORT MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager,
public SALOME::GenericObj_i
{
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();
// 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<MEDPresentation*> _presentations;
+ std::map< TypeID, MEDPresentation * > _presentations;
};
print "viewMode:", viewMode, " [", type(viewMode), "]"
params = MEDCALC.ScalarMapParameters(proxy.id, viewMode)
- __manager.MakeScalarMap(params)
+ __manager.makeScalarMap(params)
#