Search in sources :

Example 1 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer 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 TextRenderer

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

the class DiscreteTimeSeries method addValueTime.

@SuppressWarnings("unchecked")
public void addValueTime(IValueTime pvt) {
    DataValue value = pvt.getValue();
    if (value == null)
        return;
    valueTimes.add(pvt);
    if (getValueIndex(value) == -1) {
        String text;
        if (textRenderer == null)
            text = value.toString();
        else
            text = textRenderer.getText(value, TextRenderer.HINT_FULL);
        ValueDescription vd = new ValueDescription((Comparable<Object>) value, text);
        int index = Collections.binarySearch(valueDescriptions, vd);
        valueDescriptions.add(-index - 1, vd);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) Paint(java.awt.Paint)

Example 3 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer in project ma-modules-public by infiniteautomation.

the class TextRendererFactory method createModel.

/**
 * @param vo
 * @return
 */
public static BaseTextRendererModel<?> createModel(DataPointVO vo) {
    TextRenderer renderer = vo.getTextRenderer();
    // For when a VO is created that has no renderer
    if (renderer == null)
        return new NoneTextRendererModel();
    if (renderer.getTypeName().equals(AnalogRenderer.getDefinition().getName())) {
        AnalogRenderer r = (AnalogRenderer) renderer;
        AnalogTextRendererModel model = new AnalogTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getFormat(), r.getSuffix());
        return model;
    } else if (renderer.getTypeName().equals(BinaryTextRenderer.getDefinition().getName())) {
        BinaryTextRendererModel model = new BinaryTextRendererModel();
        BinaryTextRenderer btr = (BinaryTextRenderer) renderer;
        model.setOneColour(btr.getOneColour());
        model.setOneLabel(btr.getOneLabel());
        model.setZeroColour(btr.getZeroColour());
        model.setZeroLabel(btr.getZeroLabel());
        return model;
    } else if (renderer.getTypeName().equals(MultistateRenderer.getDefinition().getName())) {
        MultistateRenderer r = (MultistateRenderer) renderer;
        MultistateTextRendererModel model = new MultistateTextRendererModel(r.getMultistateValues());
        return model;
    } else if (renderer.getTypeName().equals(NoneRenderer.getDefinition().getName())) {
        return new NoneTextRendererModel();
    }
    if (renderer.getTypeName().equals(PlainRenderer.getDefinition().getName())) {
        PlainRenderer r = (PlainRenderer) renderer;
        PlainTextRendererModel model = new PlainTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getSuffix());
        return model;
    } else if (renderer.getTypeName().equals(RangeRenderer.getDefinition().getName())) {
        RangeRenderer r = (RangeRenderer) renderer;
        RangeTextRendererModel model = new RangeTextRendererModel(r.isUseUnitAsSuffix(), UnitUtil.formatLocal(r.getUnit()), UnitUtil.formatLocal(r.getRenderedUnit()), r.getFormat(), r.getRangeValues());
        return model;
    } else if (renderer.getTypeName().equals(TimeRenderer.getDefinition().getName())) {
        TimeRenderer r = (TimeRenderer) renderer;
        TimeTextRendererModel model = new TimeTextRendererModel(r.getFormat(), r.getConversionExponent());
        return model;
    } else {
        throw new ShouldNeverHappenException("Unknown Text Renderer: " + renderer.getDef().getName());
    }
}
Also used : PlainRenderer(com.serotonin.m2m2.view.text.PlainRenderer) TimeRenderer(com.serotonin.m2m2.view.text.TimeRenderer) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer) MultistateRenderer(com.serotonin.m2m2.view.text.MultistateRenderer) RangeRenderer(com.serotonin.m2m2.view.text.RangeRenderer) AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) BinaryTextRenderer(com.serotonin.m2m2.view.text.BinaryTextRenderer) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 4 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer in project ma-modules-public by infiniteautomation.

the class ReportDao method reportInstanceDataNoSQL.

public void reportInstanceDataNoSQL(int instanceId, final ExportDataStreamHandler handler) {
    // Retrieve point information.
    List<ExportPointInfo> pointInfos = query(REPORT_INSTANCE_POINT_SELECT + "where reportInstanceId=?", new Object[] { instanceId }, new RowMapper<ExportPointInfo>() {

        @Override
        public ExportPointInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            int i = 0;
            ExportPointInfo rp = new ExportPointInfo();
            rp.setReportPointId(rs.getInt(++i));
            rp.setDeviceName(rs.getString(++i));
            rp.setPointName(rs.getString(++i));
            rp.setXid(rs.getString(++i));
            rp.setDataType(rs.getInt(++i));
            String startValue = rs.getString(++i);
            if (startValue != null)
                rp.setStartValue(DataValue.stringToValue(startValue, rp.getDataType()));
            rp.setTextRenderer((TextRenderer) SerializationHelper.readObjectInContext(rs.getBlob(++i).getBinaryStream()));
            rp.setColour(rs.getString(++i));
            rp.setWeight(rs.getFloat(++i));
            rp.setConsolidatedChart(charToBool(rs.getString(++i)));
            rp.setPlotType(rs.getInt(++i));
            return rp;
        }
    });
    final ExportDataValue edv = new ExportDataValue();
    for (final ExportPointInfo point : pointInfos) {
        if (point.getDataType() == DataTypes.IMAGE) {
            DataPointVO vo = DataPointDao.instance.getByXid(point.getXid());
            if (vo != null)
                point.setDataPointId(vo.getId());
            else
                point.setDataPointId(-1);
        }
        handler.startPoint(point);
        edv.setReportPointId(point.getReportPointId());
        final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
        final String pointStore = instanceId + "_" + point.getReportPointId();
        dao.getData(pointStore, 0, Long.MAX_VALUE, -1, false, new NoSQLQueryCallback() {

            @Override
            public void entry(String storeName, long timestamp, ITime entry) {
                PointValueTime pvt = (PointValueTime) entry;
                edv.setValue(pvt.getValue());
                edv.setTime(pvt.getTime());
                if (pvt instanceof AnnotatedPointValueTime)
                    edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
                handler.pointData(edv);
            }
        });
    }
    handler.done();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLException(java.sql.SQLException) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) NoSQLQueryCallback(com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback) NoSQLDao(com.serotonin.m2m2.db.dao.nosql.NoSQLDao) ResultSet(java.sql.ResultSet) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) ITime(com.serotonin.m2m2.view.stats.ITime) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Example 5 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer in project ma-modules-public by infiniteautomation.

the class ReportDao method reportInstanceDataSQL.

public void reportInstanceDataSQL(int instanceId, final ExportDataStreamHandler handler) {
    // Retrieve point information.
    List<ExportPointInfo> pointInfos = query(REPORT_INSTANCE_POINT_SELECT + "where reportInstanceId=?", new Object[] { instanceId }, new RowMapper<ExportPointInfo>() {

        @Override
        public ExportPointInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
            int i = 0;
            ExportPointInfo rp = new ExportPointInfo();
            rp.setReportPointId(rs.getInt(++i));
            rp.setDeviceName(rs.getString(++i));
            rp.setPointName(rs.getString(++i));
            rp.setXid(rs.getString(++i));
            rp.setDataType(rs.getInt(++i));
            String startValue = rs.getString(++i);
            if (startValue != null)
                rp.setStartValue(DataValue.stringToValue(startValue, rp.getDataType()));
            rp.setTextRenderer((TextRenderer) SerializationHelper.readObjectInContext(rs.getBlob(++i).getBinaryStream()));
            rp.setColour(rs.getString(++i));
            rp.setWeight(rs.getFloat(++i));
            rp.setConsolidatedChart(charToBool(rs.getString(++i)));
            rp.setPlotType(rs.getInt(++i));
            return rp;
        }
    });
    final ExportDataValue edv = new ExportDataValue();
    for (final ExportPointInfo point : pointInfos) {
        if (point.getDataType() == DataTypes.IMAGE) {
            DataPointVO vo = DataPointDao.instance.getByXid(point.getXid());
            if (vo != null)
                point.setDataPointId(vo.getId());
            else
                point.setDataPointId(-1);
        }
        handler.startPoint(point);
        edv.setReportPointId(point.getReportPointId());
        final int dataType = point.getDataType();
        ejt.query(REPORT_INSTANCE_DATA_SELECT + "where rd.reportInstancePointId=? order by rd.ts", new Object[] { point.getReportPointId() }, new RowCallbackHandler() {

            @Override
            public void processRow(ResultSet rs) throws SQLException {
                switch(dataType) {
                    case (DataTypes.NUMERIC):
                        edv.setValue(new NumericValue(rs.getDouble(1)));
                        break;
                    case (DataTypes.BINARY):
                        edv.setValue(new BinaryValue(rs.getDouble(1) == 1));
                        break;
                    case (DataTypes.MULTISTATE):
                        edv.setValue(new MultistateValue(rs.getInt(1)));
                        break;
                    case (DataTypes.ALPHANUMERIC):
                        edv.setValue(new AlphanumericValue(rs.getString(2)));
                        if (rs.wasNull())
                            edv.setValue(new AlphanumericValue(rs.getString(3)));
                        break;
                    case (DataTypes.IMAGE):
                        edv.setValue(new ImageValue(Integer.parseInt(rs.getString(2)), rs.getInt(1)));
                        break;
                    default:
                        edv.setValue(null);
                }
                edv.setTime(rs.getLong(4));
                edv.setAnnotation(BaseDao.readTranslatableMessage(rs, 5));
                handler.pointData(edv);
            }
        });
    }
    handler.done();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) SQLException(java.sql.SQLException) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) TextRenderer(com.serotonin.m2m2.view.text.TextRenderer)

Aggregations

TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 AnalogRenderer (com.serotonin.m2m2.view.text.AnalogRenderer)2 ConvertingRenderer (com.serotonin.m2m2.view.text.ConvertingRenderer)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)2 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 JsonException (com.serotonin.json.JsonException)1 NoSQLDao (com.serotonin.m2m2.db.dao.nosql.NoSQLDao)1 NoSQLQueryCallback (com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)1 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1