1 // Copyright (C) 2011-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Authors: A Bruneton (CEA), C Aguerre (EdF)
21 #include "MEDFactoryClient.hxx"
22 #include "MEDPresentation.hxx"
23 #include "MEDPresentationException.hxx"
24 #include "MEDCouplingRefCountObject.hxx"
27 MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name)
28 : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties()
30 MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
31 MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
32 MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
33 MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
35 _fileName = dataSHandler->uri;
36 _fieldName = fieldHandler->fieldname;
37 _fieldType = getFieldTypeString((ParaMEDMEM::TypeOfField) fieldHandler->type);
39 if (_fileName.substr(0, 7) != std::string("file://")) {
40 const char* msg = "Data source is not a file! Can not proceed.";
41 throw MEDPresentationException(msg);
43 _fileName = _fileName.substr(7, _fileName.size());
45 setProperty("name", name);
48 void MEDPresentation::generatePipeline()
50 // Might be more complicated in the future:
52 this->internalGeneratePipeline();
55 void MEDPresentation::pushInternal(PyObject * obj, PyObject * disp)
57 _pipeline.push_back(obj);
58 _display.push_back(disp);
61 void MEDPresentation::setProperty(const std::string& propName, const std::string& propValue)
63 // LIMITED!!! For now switch the first display element to Wireframe
66 PyObject_CallMethod(_display[0], (char*)"SetRepresentationType", (char*)"(s)", "Wireframe");
69 _properties[propName] = propValue;
73 MEDPresentation::getProperty(const std::string& propName)
75 if (_properties.find(propName) != _properties.end()) {
76 return _properties[propName];
79 std::cerr << "getProperty(): no property named " << propName << std::endl;
84 PyObject * MEDPresentation::getPythonObjectFromMain(const char * python_var)
86 // TODO: improve to avoid getting dict at each call
88 // All the calls below returns *borrowed* references
89 PyObject* main_module = PyImport_AddModule((char*)"__main__");
90 PyObject* global_dict = PyModule_GetDict(main_module);
91 return PyDict_GetItemString(global_dict, python_var);
94 std::string MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType)
98 case MEDCoupling::ON_CELLS:
100 case MEDCoupling::ON_NODES:
103 std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?";