Search in sources :

Example 1 with ConvertingRenderer

use of com.serotonin.m2m2.view.text.ConvertingRenderer in project ma-core-public by infiniteautomation.

the class BaseDwr method setPointImpl.

protected void setPointImpl(DataPointVO point, String valueStr, SetPointSource source) {
    if (point == null)
        return;
    if (valueStr == null)
        Common.runtimeManager.relinquish(point.getId());
    else {
        // Convert the string value into an object.
        DataValue value = DataValue.stringToValue(valueStr, point.getPointLocator().getDataTypeId());
        // do reverse conversion of renderer
        TextRenderer tr = point.getTextRenderer();
        if (point.getPointLocator().getDataTypeId() == DataTypes.NUMERIC && tr instanceof ConvertingRenderer) {
            ConvertingRenderer cr = (ConvertingRenderer) tr;
            UnitConverter converter = cr.getRenderedUnit().getConverterTo(cr.getUnit());
            double convertedValue = converter.convert(value.getDoubleValue());
            value = new NumericValue(convertedValue);
        }
        Common.runtimeManager.setDataPointValue(point.getId(), value, source);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) UnitConverter(javax.measure.converter.UnitConverter) ConvertingRenderer(com.serotonin.m2m2.view.text.ConvertingRenderer) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 2 with ConvertingRenderer

use of com.serotonin.m2m2.view.text.ConvertingRenderer in project ma-core-public by infiniteautomation.

the class DataPointVO method setUnitsOnTextRenderer.

private void setUnitsOnTextRenderer() {
    if (textRenderer instanceof ConvertingRenderer) {
        ConvertingRenderer cr = (ConvertingRenderer) textRenderer;
        cr.setUnit(unit);
        if (useRenderedUnit) {
            cr.setRenderedUnit(renderedUnit);
        } else {
            cr.setRenderedUnit(unit);
        }
    }
}
Also used : ConvertingRenderer(com.serotonin.m2m2.view.text.ConvertingRenderer)

Aggregations

ConvertingRenderer (com.serotonin.m2m2.view.text.ConvertingRenderer)2 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)1 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)1 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)1 UnitConverter (javax.measure.converter.UnitConverter)1