Salome HOME
update MEDCalc APIs
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationScalarMap.cxx
1 #include "MEDPresentationScalarMap.hxx"
2 #include "MEDFactoryClient.hxx"
3
4 #include <iostream>
5
6 void
7 MEDPresentationScalarMap::internalGeneratePipeline()
8 {
9   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
10
11   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(_fieldHandler->meshid);
12   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
13
14   std::string fileName(dataSHandler->uri);
15   std::string fieldName(_fieldHandler->fieldname);
16   std::string fieldType = getFieldTypeString();
17
18   std::cout << "Generating pipeline for SCALAR MAP:" <<std::endl;
19   std::cout << "\tfileName: " <<  fileName << std::endl;
20   std::cout << "\tfiedName: " << fieldName << std::endl;
21   if (fileName.substr(0, 7) != std::string("file://"))
22     {
23       std::cerr << "\tData source is not a file! Can not proceed." << std::endl;
24       return;
25     }
26
27   fileName = fileName.substr(7, fileName.size());
28   std::cout << "\tfileName: " <<  fileName << std::endl;
29
30   PyGILState_STATE _gil_state = PyGILState_Ensure();
31
32   std::string cmd = std::string("import pvsimple as pvs;");
33   cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + fileName + std::string("');");
34   cmd += std::string("__disp1 = pvs.Show(__obj1);");
35   cmd += std::string("pvs.ColorBy(__disp1, ('") + fieldType + std::string("', '") + fieldName + std::string("'));");
36   cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
37   cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
38
39   //std::cerr << "Python command:" << std::endl;
40   //std::cerr << cmd << std::endl;
41   PyRun_SimpleString(cmd.c_str());
42   // Retrieve Python object for internal storage:
43   PyObject * obj = getPythonObjectFromMain("__obj1");
44   PyObject * disp = getPythonObjectFromMain("__disp1");
45   pushInternal(obj, disp);
46
47   PyGILState_Release(_gil_state);
48 }