+// Copyright (C) 2016 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
+//
+
#include "MEDPresentationScalarMap.hxx"
+#include "PyInterp_Utils.h"
+
+#include <sstream>
void
MEDPresentationScalarMap::internalGeneratePipeline()
{
- //MEDPresentation::TypeID fieldHandlerId = params.fieldHandlerId;
- //MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
-
- // :TODO: consider viewMode
-
- /*
- MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
- MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
+ PyLockWrapper lock;
- std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
- std::cout << "\tviewMode: " << viewMode << std::endl;
+ int disp_id(GeneratePythonId());
+ int obj_id(disp_id);
+ std::ostringstream oss_o, oss_d, oss, oss_v;
+ oss_o << "__obj" << obj_id; std::string obj(oss_o.str());
+ oss_d << "__disp" << disp_id; std::string disp(oss_d.str());
- MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
- MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
- std::cout << "\tfileName: " << dataSHandler->uri << std::endl;
- std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
- */
+ pushAndExecPyLine( "import pvsimple as pvs;");
+ pushAndExecPyLine( getRenderViewCommand(_params.viewMode) ); // define __viewXXX
- PyGILState_STATE _gil_state = PyGILState_Ensure();
+ oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str());
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__disp1 = pvs.Show(__obj1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("pvs.GetActiveViewOrCreate('RenderView').ResetCamera();");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+ oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << disp << " = pvs.Show(" << obj << ", " << view << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << disp << ".SetScalarBarVisibility(" << view << ", True);";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << disp << ".RescaleTransferFunctionToDataRangeOverTime();";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "__lut = pvs.GetColorTransferFunction('" << _fieldName << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "__lut.ApplyPreset('" << getColorMapCommand(_params.colorMap) << "',True);";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ pushAndExecPyLine(getResetCameraCommand());
+ pushAndExecPyLine("pvs.Render();");
- //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);
+ PyObject* p_obj = getPythonObjectFromMain(obj.c_str());
+ PyObject* p_disp = getPythonObjectFromMain(disp.c_str());
+ pushPyObjects(std::make_pair(obj_id, p_obj), std::make_pair(disp_id, p_disp));
+}
- PyGILState_Release(_gil_state);
+void
+MEDPresentationScalarMap::updatePipeline(const MEDCALC::ScalarMapParameters& params)
+{
+ // :TODO:
}