Search in sources :

Example 16 with Display

use of org.diirt.vtype.Display in project org.csstudio.display.builder by kasemir.

the class FormulaItem method compute.

/**
 * Evaluate formula for each input sample
 *  <p>
 *  Iterates over the input samples in a manner of spreadsheet or
 *  staircase-interpolation: An input with a time stamp is valid
 *  until there's a sample with a greater time stamp.
 */
private void compute() {
    final List<PlotSample> result = new ArrayList<PlotSample>();
    final Display display = ValueFactory.displayNone();
    try {
        // Prevent changes to formula & inputs
        synchronized (this) {
            // 'Current' value for each input or null when no more
            // In computation loop, values is actually moved to the _next_
            // value
            final VType[] values = new VType[inputs.length];
            // 'Current' numeric min/val/max of values
            final double[] min = new double[inputs.length];
            final double[] val = new double[inputs.length];
            final double[] max = new double[inputs.length];
            // Determine first sample for each input
            boolean more_input = false;
            for (int i = 0; i < values.length; i++) {
                // Initially, none have any data
                min[i] = val[i] = max[i] = Double.NaN;
                // Is there an initial value for any input?
                values[i] = inputs[i].first();
                if (values[i] != null)
                    more_input = true;
            }
            // Compute result for each 'line in the spreadsheet'
            Instant time;
            while (more_input) {
                // Find oldest time stamp of all the inputs
                time = null;
                for (int i = 0; i < values.length; i++) {
                    if (values[i] == null)
                        continue;
                    final Instant sample_time = VTypeHelper.getTimestamp(values[i]);
                    if (time == null || sample_time.compareTo(time) < 0)
                        time = sample_time;
                }
                if (time == null) {
                    // No input left with any data
                    more_input = false;
                    break;
                }
                // 'time' now defines the current spreadsheet line.
                // Set min/max/val to sample from each input for that time.
                // This might move values[i] resp. the inputs' iterators
                // to the 'next' sample
                boolean have_min_max = true;
                for (int i = 0; i < values.length; i++) {
                    if (// No more data
                    values[i] == null) {
                        min[i] = val[i] = max[i] = Double.NaN;
                        have_min_max = false;
                    } else if (VTypeHelper.getTimestamp(values[i]).compareTo(time) <= 0) {
                        // Input is valid before-and-up-to 'time'
                        if (values[i] instanceof VStatistics) {
                            final VStatistics mmv = (VStatistics) values[i];
                            min[i] = mmv.getMin();
                            val[i] = mmv.getAverage();
                            max[i] = mmv.getMax();
                        } else {
                            min[i] = max[i] = Double.NaN;
                            val[i] = VTypeHelper.toDouble(values[i]);
                            // Use NaN for any non-number
                            if (Double.isInfinite(val[i]))
                                val[i] = Double.NaN;
                            have_min_max = false;
                        }
                        // Move to next input sample
                        values[i] = inputs[i].next();
                    } else {
                        // Just update the have_min_max flag
                        if (Double.isNaN(min[i]) || Double.isNaN(max[i]))
                            have_min_max = false;
                    }
                }
                // Set variables[] from val to get res_val
                for (int i = 0; i < values.length; i++) variables[i].setValue(val[i]);
                // Evaluate formula for these inputs
                final double res_val = formula.eval();
                final VType value;
                if (have_min_max) {
                    // Set variables[] from min
                    for (int i = 0; i < values.length; i++) variables[i].setValue(min[i]);
                    final double res_min = formula.eval();
                    // Set variables[] from max
                    for (int i = 0; i < values.length; i++) variables[i].setValue(max[i]);
                    final double res_max = formula.eval();
                    value = new ArchiveVStatistics(time, AlarmSeverity.NONE, Messages.Formula, display, res_val, res_min, res_max, 0.0, 1);
                } else {
                    // No min/max.
                    if (Double.isNaN(res_val))
                        value = new ArchiveVNumber(time, AlarmSeverity.INVALID, Messages.Formula, display, res_val);
                    else
                        value = new ArchiveVNumber(time, AlarmSeverity.NONE, ArchiveVType.STATUS_OK, display, res_val);
                }
                result.add(new PlotSample(Messages.Formula, value));
            }
        }
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error computing " + this, ex);
    }
    // Update PlotSamples
    samples.set(result);
}
Also used : ArchiveVNumber(org.csstudio.archive.vtype.ArchiveVNumber) Instant(java.time.Instant) ArchiveVStatistics(org.csstudio.archive.vtype.ArchiveVStatistics) ArrayList(java.util.ArrayList) VType(org.diirt.vtype.VType) ArchiveVType(org.csstudio.archive.vtype.ArchiveVType) VStatistics(org.diirt.vtype.VStatistics) ArchiveVStatistics(org.csstudio.archive.vtype.ArchiveVStatistics) Display(org.diirt.vtype.Display)

Example 17 with Display

use of org.diirt.vtype.Display in project org.csstudio.display.builder by kasemir.

the class ThermometerRepresentation method valueChanged.

private void valueChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final VType vtype = model_widget.runtimePropValue().getValue();
    final boolean limits_from_pv = model_widget.propLimitsFromPV().getValue();
    double min_val = model_widget.propMinimum().getValue();
    double max_val = model_widget.propMaximum().getValue();
    if (limits_from_pv) {
        // Try display range from PV
        final Display display_info = ValueUtil.displayOf(vtype);
        if (display_info != null) {
            min_val = display_info.getLowerDisplayLimit();
            max_val = display_info.getUpperDisplayLimit();
        }
    }
    // Fall back to 0..100 range
    if (min_val >= max_val) {
        min_val = 0.0;
        max_val = 100.0;
    }
    // Determine percentage of value within the min..max range
    final double value = VTypeUtil.getValueNumber(vtype).doubleValue();
    min = min_val;
    max = max_val;
    val = value;
    dirty_value.mark();
    toolkit.scheduleUpdate(this);
}
Also used : VType(org.diirt.vtype.VType) Display(org.diirt.vtype.Display)

Example 18 with Display

use of org.diirt.vtype.Display in project org.csstudio.display.builder by kasemir.

the class ThumbWheelRepresentation method updateLimits.

/**
 * Updates, if required, the limits and zones.
 *
 * @return {@code true} is something changed and and UI update is required.
 */
private boolean updateLimits() {
    boolean somethingChanged = false;
    // Model's values.
    double newMin = model_widget.propMinimum().getValue();
    double newMax = model_widget.propMaximum().getValue();
    // If invalid limits, fall back to 0..100 range.
    if (Double.isNaN(newMin) || Double.isNaN(newMax) || newMin > newMax) {
        newMin = 0.0;
        newMax = 100.0;
    }
    if (model_widget.propLimitsFromPV().getValue()) {
        // Try to get display range from PV.
        final Display display_info = ValueUtil.displayOf(model_widget.runtimePropValue().getValue());
        if (display_info != null) {
            double infoMin = display_info.getLowerCtrlLimit();
            double infoMax = display_info.getUpperCtrlLimit();
            if (!Double.isNaN(infoMin) && !Double.isNaN(infoMax) && infoMin < infoMax) {
                newMin = infoMin;
                newMax = infoMax;
            }
        }
    }
    if (Double.compare(min, newMin) != 0) {
        min = newMin;
        somethingChanged = true;
    }
    if (Double.compare(max, newMax) != 0) {
        max = newMax;
        somethingChanged = true;
    }
    return somethingChanged;
}
Also used : Display(org.diirt.vtype.Display)

Example 19 with Display

use of org.diirt.vtype.Display in project org.csstudio.display.builder by kasemir.

the class BaseGaugeRepresentation method updateLimits.

/**
 * Updates, if required, the limits and zones.
 *
 * @return {@code true} is something changed and and UI update is required.
 */
protected boolean updateLimits() {
    boolean somethingChanged = false;
    // Model's values.
    double newMin = model_widget.propMinimum().getValue();
    double newMax = model_widget.propMaximum().getValue();
    // If invalid limits, fall back to 0..100 range.
    if (Double.isNaN(newMin) || Double.isNaN(newMax) || newMin > newMax) {
        newMin = 0.0;
        newMax = 100.0;
    }
    double newLoLo = model_widget.propLevelLoLo().getValue();
    double newLow = model_widget.propLevelLow().getValue();
    double newHigh = model_widget.propLevelHigh().getValue();
    double newHiHi = model_widget.propLevelHiHi().getValue();
    if (model_widget.propLimitsFromPV().getValue()) {
        // Try to get display range from PV.
        final Display display_info = ValueUtil.displayOf(model_widget.runtimePropValue().getValue());
        if (display_info != null) {
            double infoMin = display_info.getLowerCtrlLimit();
            double infoMax = display_info.getUpperCtrlLimit();
            if (!Double.isNaN(infoMin) && !Double.isNaN(infoMax) && infoMin < infoMax) {
                newMin = infoMin;
                newMax = infoMax;
            }
            newLoLo = display_info.getLowerAlarmLimit();
            newLow = display_info.getLowerWarningLimit();
            newHigh = display_info.getUpperWarningLimit();
            newHiHi = display_info.getUpperAlarmLimit();
        }
    }
    if (!model_widget.propShowLoLo().getValue()) {
        newLoLo = Double.NaN;
    }
    if (!model_widget.propShowLow().getValue()) {
        newLow = Double.NaN;
    }
    if (!model_widget.propShowHigh().getValue()) {
        newHigh = Double.NaN;
    }
    if (!model_widget.propShowHiHi().getValue()) {
        newHiHi = Double.NaN;
    }
    if (Double.compare(min, newMin) != 0) {
        min = newMin;
        somethingChanged = true;
    }
    if (Double.compare(max, newMax) != 0) {
        max = newMax;
        somethingChanged = true;
    }
    if (Double.compare(lolo, newLoLo) != 0) {
        lolo = newLoLo;
        somethingChanged = true;
    }
    if (Double.compare(low, newLow) != 0) {
        low = newLow;
        somethingChanged = true;
    }
    if (Double.compare(high, newHigh) != 0) {
        high = newHigh;
        somethingChanged = true;
    }
    if (Double.compare(hihi, newHiHi) != 0) {
        hihi = newHiHi;
        somethingChanged = true;
    }
    return somethingChanged;
}
Also used : Display(org.diirt.vtype.Display)

Aggregations

Display (org.diirt.vtype.Display)19 VType (org.diirt.vtype.VType)7 IPV (org.csstudio.simplepv.IPV)4 VNumber (org.diirt.vtype.VNumber)3 ArrayList (java.util.ArrayList)2 ListDouble (org.diirt.util.array.ListDouble)2 NumberFormat (java.text.NumberFormat)1 Instant (java.time.Instant)1 ArchiveVNumber (org.csstudio.archive.vtype.ArchiveVNumber)1 ArchiveVStatistics (org.csstudio.archive.vtype.ArchiveVStatistics)1 ArchiveVType (org.csstudio.archive.vtype.ArchiveVType)1 AbstractMarkedWidgetModel (org.csstudio.opibuilder.widgets.model.AbstractMarkedWidgetModel)1 ScrollBarModel (org.csstudio.opibuilder.widgets.model.ScrollBarModel)1 ThumbWheelModel (org.csstudio.opibuilder.widgets.model.ThumbWheelModel)1 Statistics (org.diirt.util.Statistics)1 ListNumber (org.diirt.util.array.ListNumber)1 VStatistics (org.diirt.vtype.VStatistics)1 VString (org.diirt.vtype.VString)1 ValueFactory.newDisplay (org.diirt.vtype.ValueFactory.newDisplay)1