Search in sources :

Example 6 with VNumberArray

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

the class EnumFromVNumberFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumber value = (VNumber) args.get(0);
    VNumberArray intervals = (VNumberArray) args.get(1);
    VStringArray labels = (VStringArray) args.get(2);
    int index = 0;
    while (index < intervals.getData().size() && value.getValue().doubleValue() >= intervals.getData().getDouble(index)) {
        index++;
    }
    return newVEnum(index, labels.getData(), value, latestValidTimeOrNowOf(args));
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VNumber(org.diirt.vtype.VNumber) VStringArray(org.diirt.vtype.VStringArray)

Example 7 with VNumberArray

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

the class TableRangeArrayFilterFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VTable table = (VTable) args.get(0);
    VString columnName = (VString) args.get(1);
    VNumberArray range = (VNumberArray) args.get(2);
    if (range.getData().size() != 2) {
        throw new IllegalArgumentException("Range array must be of 2 elements");
    }
    VTable result = VTableFactory.tableRangeFilter(table, columnName.getValue(), ValueFactory.newVDouble(range.getData().getDouble(0)), ValueFactory.newVDouble(range.getData().getDouble(1)));
    return result;
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable)

Example 8 with VNumberArray

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

the class PVUtil method getStringArray.

/**
 * Get string array from pv.
 *
 * @param pv
 *            The PV.
 * @return String array. For string array, it's the actual strings. For numeric arrays, the numbers are formatted as
 *         strings. For enum array, the labels are returned. For scalar PVs, an array with a single string is
 *         returned.
 */
public static final String[] getStringArray(IPV pv) {
    final VType value = checkPVValue(pv);
    if (value instanceof VStringArray) {
        final List<String> list = ((VStringArray) value).getData();
        return list.toArray(new String[list.size()]);
    } else if (value instanceof VDoubleArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Double.toString(list.getDouble(i));
        return text;
    } else if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Long.toString(list.getLong(i));
        return text;
    } else if (value instanceof VEnumArray) {
        final List<String> labels = ((VEnumArray) value).getLabels();
        final ListInt list = ((VEnumArray) value).getIndexes();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) {
            final int index = list.getInt(i);
            if (index >= 0 && index <= labels.size())
                text[i] = labels.get(index);
            else
                text[i] = "<" + index + ">";
        }
        return text;
    }
    return new String[] { getString(pv) };
}
Also used : VDoubleArray(org.diirt.vtype.VDoubleArray) VNumberArray(org.diirt.vtype.VNumberArray) VEnumArray(org.diirt.vtype.VEnumArray) ListNumber(org.diirt.util.array.ListNumber) ListInt(org.diirt.util.array.ListInt) VType(org.diirt.vtype.VType) List(java.util.List) VStringArray(org.diirt.vtype.VStringArray)

Example 9 with VNumberArray

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

the class TextInputEditpart method parseStringArray.

/**
 * If the text has spaces in the string and the PV is numeric array type, it will return an array of numeric values.
 *
 * @param text
 * @return
 * @throws ParseException
 */
private Object parseStringArray(final String text) throws ParseException {
    // $NON-NLS-1$
    String[] texts = text.split(" +");
    VType pvValue = getPVValue(AbstractPVWidgetModel.PROP_PVNAME);
    if (pvValue instanceof VNumberArray) {
        double[] result = new double[texts.length];
        for (int i = 0; i < texts.length; i++) {
            Object o = parseString(texts[i]);
            if (o instanceof Number)
                result[i] = ((Number) o).doubleValue();
            else
                throw new ParseException(texts[i] + " cannot be parsed as a number!", i);
        }
        return result;
    }
    return parseString(text);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VType(org.diirt.vtype.VType) ParseException(java.text.ParseException)

Example 10 with VNumberArray

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

the class IntensityGraphEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    innerUpdateGraphAreaSizeProperty();
    registerAxisPropertyChangeHandler();
    registerROIPropertyChangeHandlers();
    registerROIAmountChangeHandler();
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (newValue == null)
                return false;
            VType value = (VType) newValue;
            if (value instanceof VNumberArray) {
                setValue(((VNumberArray) value).getData());
                return false;
            }
            ((IntensityGraphFigure) figure).setDataArray(VTypeHelper.getDoubleArray(value));
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVVALUE, handler);
    getWidgetModel().getProperty(IntensityGraphModel.PROP_MIN).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            ((IntensityGraphFigure) figure).setMin((Double) evt.getNewValue());
            figure.repaint();
            innerUpdateGraphAreaSizeProperty();
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_MAX).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            ((IntensityGraphFigure) figure).setMax((Double) evt.getNewValue());
            figure.repaint();
            innerUpdateGraphAreaSizeProperty();
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_STYLE).removeAllPropertyChangeListeners();
    getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_STYLE).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            figure.setBorder(BorderFactory.createBorder(BorderStyle.values()[(Integer) evt.getNewValue()], getWidgetModel().getBorderWidth(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
            innerUpdateGraphAreaSizeProperty();
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_WIDTH).removeAllPropertyChangeListeners();
    getWidgetModel().getProperty(IntensityGraphModel.PROP_BORDER_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            figure.setBorder(BorderFactory.createBorder(getWidgetModel().getBorderStyle(), (Integer) evt.getNewValue(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
            innerUpdateGraphAreaSizeProperty();
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setDataWidth((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_DATA_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setDataHeight((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_DATA_HEIGHT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setColorMap((ColorMap) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_COLOR_MAP, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setCropLeft((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_LEFT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setCropRight((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_RIGHT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setCropTop((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_TOP, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) figure).setCropBottom((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_CROP_BOTTOM, handler);
    getWidgetModel().getProperty(IntensityGraphModel.PROP_SHOW_RAMP).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            ((IntensityGraphFigure) getFigure()).setShowRamp((Boolean) evt.getNewValue());
            Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
            innerTrig = true;
            getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_GRAPH_AREA_WIDTH, getWidgetModel().getWidth() - d.width);
            innerTrig = false;
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!innerTrig) {
                // if it is not triggered from inner
                innerTrig = true;
                Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
                getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_GRAPH_AREA_WIDTH, ((Integer) evt.getNewValue()) - d.width);
                // reset innerTrig to false after each inner triggering
                innerTrig = false;
            } else
                // if it is triggered from inner, do nothing
                innerTrig = false;
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_GRAPH_AREA_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!innerTrig) {
                innerTrig = true;
                Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
                getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_WIDTH, ((Integer) evt.getNewValue()) + d.width);
                // reset innerTrig to false after each inner triggering
                innerTrig = false;
            } else
                innerTrig = false;
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_HEIGHT).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!innerTrig) {
                innerTrig = true;
                Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
                getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_GRAPH_AREA_HEIGHT, ((Integer) evt.getNewValue()) - d.height);
                // reset innerTrig to false after each inner triggering
                innerTrig = false;
            } else
                innerTrig = false;
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_GRAPH_AREA_HEIGHT).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (!innerTrig) {
                innerTrig = true;
                Dimension d = ((IntensityGraphFigure) getFigure()).getGraphAreaInsets();
                getWidgetModel().setPropertyValue(IntensityGraphModel.PROP_HEIGHT, ((Integer) evt.getNewValue()) + d.height);
                // reset innerTrig to false after each inner triggering
                innerTrig = false;
            } else
                innerTrig = false;
        }
    });
    getWidgetModel().getProperty(IntensityGraphModel.PROP_RGB_MODE).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            updatePropSheet();
            ((IntensityGraphFigure) getFigure()).setInRGBMode((Boolean) (evt.getNewValue()));
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) getFigure()).setColorDepth(getWidgetModel().getColorDepth());
            return false;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_COLOR_DEPTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) getFigure()).setSingleLineProfiling((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_SINGLE_LINE_PROFILING, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((IntensityGraphFigure) getFigure()).setROIColor(((OPIColor) newValue).getSWTColor());
            return false;
        }
    };
    setPropertyChangeHandler(IntensityGraphModel.PROP_ROI_COLOR, handler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap) PredefinedColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap) Dimension(org.eclipse.draw2d.geometry.Dimension) ArrayDouble(org.diirt.util.array.ArrayDouble) VNumberArray(org.diirt.vtype.VNumberArray) IntensityGraphFigure(org.csstudio.swt.widgets.figures.IntensityGraphFigure) VType(org.diirt.vtype.VType) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) OPIColor(org.csstudio.opibuilder.util.OPIColor) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

VNumberArray (org.diirt.vtype.VNumberArray)30 ListNumber (org.diirt.util.array.ListNumber)13 VNumber (org.diirt.vtype.VNumber)10 VString (org.diirt.vtype.VString)6 ValueFactory.newVNumberArray (org.diirt.vtype.ValueFactory.newVNumberArray)6 VEnumArray (org.diirt.vtype.VEnumArray)5 VType (org.diirt.vtype.VType)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ArrayDouble (org.diirt.util.array.ArrayDouble)4 ListInt (org.diirt.util.array.ListInt)4 VStringArray (org.diirt.vtype.VStringArray)4 VEnum (org.diirt.vtype.VEnum)3 VTable (org.diirt.vtype.VTable)3 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ListDouble (org.diirt.util.array.ListDouble)2 ArrayDimensionDisplay (org.diirt.vtype.ArrayDimensionDisplay)2 VBoolean (org.diirt.vtype.VBoolean)2 VDoubleArray (org.diirt.vtype.VDoubleArray)2