Search in sources :

Example 11 with Display

use of org.diirt.vtype.Display in project yamcs-studio by yamcs.

the class AbstractMarkedWidgetEditPart method registerLoadLimitsListener.

/**
 */
private void registerLoadLimitsListener() {
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        final AbstractMarkedWidgetModel model = (AbstractMarkedWidgetModel) getModel();
        if (model.isLimitsFromPV()) {
            IPV pv = getPV(AbstractPVWidgetModel.PROP_PVNAME);
            if (pv != null) {
                if (pvLoadLimitsListener == null)
                    pvLoadLimitsListener = new IPVListener.Stub() {

                        @Override
                        public void valueChanged(IPV pv) {
                            VType value = pv.getValue();
                            if (value != null && VTypeHelper.getDisplayInfo(value) != null) {
                                Display new_meta = VTypeHelper.getDisplayInfo(value);
                                if (meta == null || !meta.equals(new_meta)) {
                                    meta = new_meta;
                                    Double upperLimit;
                                    Double lowerLimit;
                                    if (model.isControlWidget()) {
                                        // DRVH / DRVL
                                        upperLimit = meta.getUpperCtrlLimit();
                                        lowerLimit = meta.getLowerCtrlLimit();
                                    } else {
                                        // HOPR / LOPR
                                        upperLimit = meta.getUpperDisplayLimit();
                                        lowerLimit = meta.getLowerDisplayLimit();
                                    }
                                    if (!Double.isNaN(upperLimit)) {
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_MAX, upperLimit);
                                    }
                                    if (!Double.isNaN(lowerLimit)) {
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_MIN, lowerLimit);
                                    }
                                    if (Double.isNaN(meta.getUpperWarningLimit()))
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_HI, false);
                                    else {
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_HI, true);
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_HI_LEVEL, meta.getUpperWarningLimit());
                                    }
                                    if (Double.isNaN(meta.getUpperAlarmLimit()))
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_HIHI, false);
                                    else {
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_HIHI, true);
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_HIHI_LEVEL, meta.getUpperAlarmLimit());
                                    }
                                    if (Double.isNaN(meta.getLowerWarningLimit()))
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_LO, false);
                                    else {
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_LO, true);
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_LO_LEVEL, meta.getLowerWarningLimit());
                                    }
                                    if (Double.isNaN(meta.getLowerAlarmLimit()))
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_LOLO, false);
                                    else {
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_SHOW_LOLO, true);
                                        model.setPropertyValue(AbstractMarkedWidgetModel.PROP_LOLO_LEVEL, meta.getLowerAlarmLimit());
                                    }
                                }
                            }
                        }
                    };
                pv.addListener(pvLoadLimitsListener);
            }
        }
    }
}
Also used : VType(org.diirt.vtype.VType) AbstractMarkedWidgetModel(org.csstudio.opibuilder.widgets.model.AbstractMarkedWidgetModel) IPV(org.csstudio.simplepv.IPV) Display(org.diirt.vtype.Display)

Example 12 with Display

use of org.diirt.vtype.Display in project yamcs-studio by yamcs.

the class ThumbWheelEditPart method registerLoadLimitsListener.

/**
 */
private void registerLoadLimitsListener() {
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        final ThumbWheelModel model = getWidgetModel();
        if (model.isLimitsFromPV()) {
            IPV pv = getPV(AbstractPVWidgetModel.PROP_PVNAME);
            if (pv != null) {
                if (pvLoadLimitsListener == null)
                    pvLoadLimitsListener = new IPVListener.Stub() {

                        @Override
                        public void valueChanged(IPV pv) {
                            VType value = pv.getValue();
                            Display displayInfo = VTypeHelper.getDisplayInfo(value);
                            if (value != null && displayInfo != null) {
                                Display new_meta = displayInfo;
                                if (meta == null || !meta.equals(new_meta)) {
                                    meta = new_meta;
                                    model.setPropertyValue(ThumbWheelModel.PROP_MAX, meta.getUpperDisplayLimit());
                                    model.setPropertyValue(ThumbWheelModel.PROP_MIN, meta.getLowerDisplayLimit());
                                }
                            }
                        }
                    };
                pv.addListener(pvLoadLimitsListener);
            }
        }
    }
}
Also used : ThumbWheelModel(org.csstudio.opibuilder.widgets.model.ThumbWheelModel) VType(org.diirt.vtype.VType) IPV(org.csstudio.simplepv.IPV) Display(org.diirt.vtype.Display)

Example 13 with Display

use of org.diirt.vtype.Display in project yamcs-studio by yamcs.

the class ShowPVInfoAction method getPVInfo.

private String getPVInfo(IPV pv) {
    StringBuilder stateInfo = new StringBuilder();
    if (!pv.isStarted())
        stateInfo.append("Not started");
    else if (pv.isConnected()) {
        stateInfo.append("Connected");
        if (pv.isPaused())
            stateInfo.append(" Paused");
        else
            stateInfo.append(" Running");
    } else
        stateInfo.append("Connecting");
    StringBuilder sb = new StringBuilder();
    // $NON-NLS-2$
    sb.append("Name: " + pv.getName() + "\n");
    // $NON-NLS-2$
    sb.append("State: " + stateInfo + "\n");
    if (pv.getValue() != null) {
        // $NON-NLS-2$
        sb.append((pv.isConnected() ? "Value: " : "Last received value: ") + pv.getValue() + "\n");
        sb.append("Display Info: ");
        Display displayInfo = VTypeHelper.getDisplayInfo(pv.getValue());
        if (displayInfo != null) {
            sb.append("\nUnits: ");
            sb.append(displayInfo.getUnits());
            sb.append("\nPrecision: ");
            sb.append(displayInfo.getFormat().getMaximumFractionDigits());
            sb.append("\nControl_Low: ");
            sb.append(displayInfo.getLowerCtrlLimit());
            sb.append("\nControl_High :");
            sb.append(displayInfo.getUpperCtrlLimit());
            sb.append("\nDisplay_Low: ");
            sb.append(displayInfo.getLowerDisplayLimit());
            sb.append("\nDisplay_High :");
            sb.append(displayInfo.getUpperDisplayLimit());
            sb.append("\nAlarm_Low: ");
            sb.append(displayInfo.getLowerAlarmLimit());
            sb.append("\nWarning_Low: ");
            sb.append(displayInfo.getLowerWarningLimit());
            sb.append("\nWarning_High: ");
            sb.append(displayInfo.getUpperWarningLimit());
            sb.append("\nAlarm_High: ");
            sb.append(displayInfo.getUpperAlarmLimit());
        } else
            // $NON-NLS-1$
            sb.append("null");
    } else {
        sb.append("Value: null");
    }
    return sb.toString();
}
Also used : Display(org.diirt.vtype.Display)

Example 14 with Display

use of org.diirt.vtype.Display in project yamcs-studio by yamcs.

the class VTypeHelper method formatScalarNumber.

/**
 * @param formatEnum
 * @param pmValue
 *            The PVManager V Value. It must be a scalar with number value.
 * @param numValue
 *            the number value. not necessary if pmValue is given.
 * @param precision
 * @return
 */
private static String formatScalarNumber(FormatEnum formatEnum, Object pmValue, Number numValue, int precision) {
    if (pmValue != null)
        numValue = (Number) ((Scalar) pmValue).getValue();
    NumberFormat numberFormat;
    int displayPrecision = calculatePrecision(pmValue, precision);
    double highDispLimit = 0.0, lowDispLimit = 0.0;
    switch(formatEnum) {
        case DECIMAL:
        case DEFAULT:
        default:
            if (precision == UNSET_PRECISION) {
                if (pmValue instanceof Display && ((Display) pmValue).getFormat() != null) {
                    return ((Display) pmValue).getFormat().format(((Number) numValue).doubleValue());
                } else {
                    return formatScalarNumber(FormatEnum.COMPACT, numValue, displayPrecision);
                }
            } else {
                // consistent with the rest of CSS.
                if (Double.isNaN(numValue.doubleValue())) {
                    return Double.toString(Double.NaN);
                }
                // Also check for positive and negative infinity.
                if (Double.isInfinite(numValue.doubleValue())) {
                    return Double.toString(numValue.doubleValue());
                }
                numberFormat = getDecimalFormat(precision);
                return numberFormat.format(numValue.doubleValue());
            }
        case COMPACT:
            double dValue = numValue.doubleValue();
            if (((dValue > 0.0001) && (dValue < 10000)) || ((dValue < -0.0001) && (dValue > -10000)) || dValue == 0.0) {
                return formatScalarNumber(FormatEnum.DECIMAL, numValue, displayPrecision);
            } else {
                return formatScalarNumber(FormatEnum.EXP, numValue, displayPrecision);
            }
        case ENG:
            double value = numValue.doubleValue();
            if (value == 0) {
                return formatScalarNumber(FormatEnum.EXP, numValue, displayPrecision);
            }
            double log10 = Math.log10(Math.abs(value));
            int power = 3 * (int) Math.floor(log10 / 3);
            return String.format("%." + displayPrecision + "fE%d", value / Math.pow(10, power), power);
        case SEXA:
            if (pmValue instanceof Display) {
                highDispLimit = ((Display) pmValue).getUpperDisplayLimit();
                lowDispLimit = ((Display) pmValue).getLowerDisplayLimit();
            }
            return doubleToSexagesimal(numValue.doubleValue(), displayPrecision, highDispLimit, lowDispLimit);
        case SEXA_HMS:
            if (pmValue instanceof Display) {
                highDispLimit = ((Display) pmValue).getUpperDisplayLimit();
                lowDispLimit = ((Display) pmValue).getLowerDisplayLimit();
            }
            return doubleToSexagesimal(numValue.doubleValue() * 12.0 / Math.PI, displayPrecision, highDispLimit, lowDispLimit);
        case SEXA_DMS:
            if (pmValue instanceof Display) {
                highDispLimit = ((Display) pmValue).getUpperDisplayLimit();
                lowDispLimit = ((Display) pmValue).getLowerDisplayLimit();
            }
            return doubleToSexagesimal(numValue.doubleValue() * 180.0 / Math.PI, displayPrecision, highDispLimit, lowDispLimit);
        case EXP:
            // Exponential notation identified as 'negative' precision in cached
            numberFormat = getExponentialFormat(displayPrecision);
            return numberFormat.format(numValue.doubleValue());
        case HEX:
            return HEX_PREFIX + Integer.toHexString(numValue.intValue()).toUpperCase();
        case HEX64:
            return HEX_PREFIX + Long.toHexString(numValue.longValue());
        case STRING:
            return new String(new char[] { (char) numValue.intValue() });
    }
}
Also used : ListNumber(org.diirt.util.array.ListNumber) VNumber(org.diirt.vtype.VNumber) VString(org.diirt.vtype.VString) NumberFormat(java.text.NumberFormat) Display(org.diirt.vtype.Display)

Example 15 with Display

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

the class PVItem method updateUnits.

private void updateUnits(final VType value) {
    if (!(value instanceof Display))
        return;
    final Display display = (Display) value;
    setUnits(display.getUnits());
}
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