1 // Copyright (C) 2011-2015 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 "MEDCouplingRefCountObject.hxx"
24 #include <PyInterp_Utils.h>
27 void MEDPresentation::generatePipeline()
29 // Might be more complicated in the future:
31 this->internalGeneratePipeline();
34 void MEDPresentation::pushInternal(PyObject * obj, PyObject * disp)
36 _pipeline.push_back(obj);
37 _display.push_back(disp);
40 void MEDPresentation::setProperty(const char * propName, const char * propValue)
42 // LIMITED!!! For now switch the first display element to Wireframe
45 PyObject_CallMethod(_display[0], (char*)"SetRepresentationType", (char*)"(s)", "Wireframe");
48 PyObject * MEDPresentation::getPythonObjectFromMain(const char * python_var)
50 // TODO: improve to avoid getting dict at each call
52 // All the calls below returns *borrowed* references
53 PyObject* main_module = PyImport_AddModule((char*)"__main__");
54 PyObject* global_dict = PyModule_GetDict(main_module);
55 return PyDict_GetItemString(global_dict, python_var);
58 std::string MEDPresentation::getFieldTypeString()
60 ParaMEDMEM::TypeOfField typ = (ParaMEDMEM::TypeOfField)_fieldHandler->type;
63 case ParaMEDMEM::ON_CELLS:
65 case ParaMEDMEM::ON_NODES:
68 std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?";
74 void MEDPresentationScalarMap::internalGeneratePipeline()
76 MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
78 MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(_fieldHandler->meshid);
79 MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
81 std::string fileName(dataSHandler->uri);
82 std::string fieldName(_fieldHandler->fieldname);
83 std::string fieldType = getFieldTypeString();
85 std::cout << "Generating pipeline for SCALAR MAP:" <<std::endl;
86 std::cout << "\tfileName: " << fileName << std::endl;
87 std::cout << "\tfiedName: " << fieldName << std::endl;
88 if (fileName.substr(0, 7) != std::string("file://"))
90 std::cerr << "\tData source is not a file! Can not proceed." << std::endl;
94 fileName = fileName.substr(7, fileName.size());
95 std::cout << "\tfileName: " << fileName << std::endl;
97 { // PyLock protected section
100 PyRun_SimpleString("print 'hello world'");
101 std::string cmd = std::string(
102 "import pvsimple as pvs;"
103 "__obj1 = pvs.MEDReader(FileName='") + fileName + std::string("');"
104 "__disp1 = pvs.Show(__obj1);"
105 "pvs.ColorBy(__disp1, ('") + fieldType + std::string("', '") + fieldName + std::string("'));"
106 "pvs.GetActiveViewOrCreate('RenderView').ResetCamera()");
108 std::cerr << "Python command:" << std::endl;
109 std::cerr << cmd << std::endl;
110 PyRun_SimpleString(cmd.c_str());
111 // Retrieve Python object for internal storage:
112 PyObject * obj = getPythonObjectFromMain("__obj1");
113 PyObject * disp = getPythonObjectFromMain("__disp1");
114 pushInternal(obj, disp);