X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCalc%2Fcmp%2FMEDPresentationDeflectionShape.cxx;h=b3a81b05c7bab2363944703deb7950749e526b48;hb=fdd9edc45ff7e3cb06adf2ccfc2c6f214786aa98;hp=e56aa9f4bde1cd9a2c5cab70dc2b64e7839766bf;hpb=5a68b347e3e1538f91e78144c39efd763c909b3e;p=modules%2Fmed.git diff --git a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx index e56aa9f4b..b3a81b05c 100644 --- a/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx +++ b/src/MEDCalc/cmp/MEDPresentationDeflectionShape.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2016 CEA/DEN, EDF R&D +// Copyright (C) 2016-2020 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 @@ -17,39 +17,100 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include "MEDPyLockWrapper.hxx" + #include "MEDPresentationDeflectionShape.hxx" +#include "MEDPresentationException.hxx" + +#include +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationDeflectionShape::TYPE_NAME = "MEDPresentationDeflectionShape"; + +MEDPresentationDeflectionShape::MEDPresentationDeflectionShape(const MEDCALC::DeflectionShapeParameters& params, + const MEDCALC::ViewModeType viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params) +{ +} + +void +MEDPresentationDeflectionShape::initFieldMeshInfos() +{ + MEDPresentation::initFieldMeshInfos(); + _colorByType = "POINTS"; +} + +void +MEDPresentationDeflectionShape::autoScale() +{ + std::ostringstream oss; + oss << "import medcalc;"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".ScaleFactor = 3.0*medcalc.ComputeCellAverageSize(" << _srcObjVar << ")/(" << _rangeVar + << "[1]-" << _rangeVar << "[0]);"; + pushAndExecPyLine(oss.str()); oss.str(""); +} void MEDPresentationDeflectionShape::internalGeneratePipeline() { - PyGILState_STATE _gil_state = PyGILState_Ensure(); - - std::string cmd = std::string("import pvsimple as pvs;"); - cmd += getRenderViewCommand(_params.viewMode); // define __view1 - - cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');"); - cmd += std::string("__warpByVector1 = pvs.WarpByVector(Input=__obj1);"); - cmd += std::string("__disp1 = pvs.Show(__warpByVector1, __view1);"); - cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));"); - cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);"); - cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();"); - cmd += std::string("pvs.Render();"); - - cmd += getResetCameraCommand(); - - //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("__warpByVector1"); - PyObject* disp = getPythonObjectFromMain("__disp1"); - pushInternal(obj, disp); - - PyGILState_Release(_gil_state); + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + createSource(); + setTimestamp(); + + // Populate internal array of available components: + fillAvailableFieldComponents(); + int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); + if (nbCompo <= 1) + { + const char * msg = "Deflection shape presentation does not work for scalar field!"; // this message will appear in GUI too + STDLOG(msg); + throw KERNEL::createSalomeException(msg); + } + + setOrCreateRenderView(); // needs to be after the exception above otherwise previous elements in the view will be hidden. + + // Warp needs point data: + applyCellToPointIfNeeded(); + + std::ostringstream oss; + oss << _objVar << " = pvs.WarpByVector(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + + showObject(); // to be done first so that the scale factor computation properly works + + std::string fieldName = nbCompo <= 2 ? _fieldName + "_Vector" : _fieldName; + oss << _objVar << ".Vectors = ['POINTS', '" << fieldName << "'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + + colorBy(); // see initFieldInfo() - necessarily POINTS + showScalarBar(); + selectColorMap(); + rescaleTransferFunction(); + + autoScale(); // to be called after transfer function so we have the range + + resetCameraAndRender(); } void MEDPresentationDeflectionShape::updatePipeline(const MEDCALC::DeflectionShapeParameters& params) { - // :TODO: + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (params.scalarBarRange != _params.scalarBarRange) + { + updateScalarBarRange(params.scalarBarRange); + autoScale(); + pushAndExecPyLine("pvs.Render();"); + } + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); }