Search in sources :

Example 46 with VType

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

the class ToStringFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    VType value = (VType) args.get(0);
    Alarm alarm = ValueUtil.alarmOf(value);
    if (alarm == null) {
        alarm = ValueFactory.alarmNone();
    }
    Time time = ValueUtil.timeOf(value);
    if (time == null) {
        time = ValueFactory.timeNow();
    }
    return ValueFactory.newVString(ValueUtil.getDefaultValueFormat().format(value), alarm, time);
}
Also used : VType(org.diirt.vtype.VType) Alarm(org.diirt.vtype.Alarm) Time(org.diirt.vtype.Time)

Example 47 with VType

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

the class TableRangeFilterFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VTable table = (VTable) args.get(0);
    VString columnName = (VString) args.get(1);
    VType min = (VType) args.get(2);
    VType max = (VType) args.get(3);
    if (columnName == null || columnName.getValue() == null || table == null || min == null || max == null) {
        return null;
    }
    VTable result = VTableFactory.tableRangeFilter(table, columnName.getValue(), min, max);
    return result;
}
Also used : VType(org.diirt.vtype.VType) VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable)

Example 48 with VType

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

the class ImageWidgetRuntime method bindROI.

/**
 * Bind an ROI PV to an ROI value
 *  @param name_prop Property for the PV name
 *  @param value_prop Property for the value
 */
private void bindROI(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
    final String pv_name = name_prop.getValue();
    if (pv_name.isEmpty())
        return;
    logger.log(Level.FINER, "Connecting {0} to ROI PV {1}", new Object[] { widget, pv_name });
    try {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        roi_pvs.add(pv);
        // Write value changes to the PV
        final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
            try {
                if (value == VTypeUtil.getValueNumber(pv.read()).doubleValue())
                    return;
                // System.out.println("Writing " + value_prop + " to PV " + pv_name);
                pv.write(value);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error writing ROI value to PV " + pv_name, ex);
            }
        };
        value_prop.addPropertyListener(prop_listener);
        roi_prop_listeners.put(value_prop, prop_listener);
        // Write PV updates to the value
        final RuntimePVListener pv_listener = new RuntimePVListener() {

            @Override
            public void valueChanged(final RuntimePV pv, final VType value) {
                final double number = VTypeUtil.getValueNumber(value).doubleValue();
                if (number == value_prop.getValue())
                    return;
                // System.out.println("Writing from PV " + pv_name + " to " + value_prop);
                value_prop.setValue(number);
            }
        };
        pv.addListener(pv_listener);
        roi_pv_listeners.put(pv, pv_listener);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error connecting ROI PV " + pv_name, ex);
    }
}
Also used : VTypeUtil(org.csstudio.display.builder.model.util.VTypeUtil) ROIWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WidgetRuntime(org.csstudio.display.builder.runtime.WidgetRuntime) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) PVFactory(org.csstudio.display.builder.runtime.pv.PVFactory) PVUtil(org.csstudio.display.builder.runtime.script.PVUtil) RuntimePlugin.logger(org.csstudio.display.builder.runtime.RuntimePlugin.logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) List(java.util.List) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) Map(java.util.Map) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 49 with VType

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

the class XYPlotWidgetRuntime method bindMarker.

private void bindMarker(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
    final String pv_name = name_prop.getValue();
    if (pv_name.isEmpty())
        return;
    logger.log(Level.FINER, "Connecting {0} to Marker PV {1}", new Object[] { widget, pv_name });
    try {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        marker_pvs.add(pv);
        // Write value changes to the PV
        final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
            // Ignore if PV already has same value to break update loops
            double pv_value = VTypeUtil.getValueNumber(pv.read()).doubleValue();
            if (value == pv_value)
                return;
            try {
                // System.out.println("Writing " + value_prop + " to PV " + pv_name);
                pv.write(value);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error writing marker value to PV " + pv_name, ex);
                // Restore property to the unchanged value of the PV
                value_prop.setValue(pv_value);
            }
        };
        value_prop.addPropertyListener(prop_listener);
        marker_prop_listeners.put(value_prop, prop_listener);
        // Write PV updates to the value
        final RuntimePVListener pv_listener = new RuntimePVListener() {

            @Override
            public void valueChanged(final RuntimePV pv, final VType value) {
                final double number = VTypeUtil.getValueNumber(value).doubleValue();
                if (number == value_prop.getValue())
                    return;
                // System.out.println("Writing " + number + " from PV " + pv_name + " to " + value_prop);
                value_prop.setValue(number);
            }
        };
        pv.addListener(pv_listener);
        marker_pv_listeners.put(pv, pv_listener);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error connecting Marker PV " + pv_name, ex);
    }
}
Also used : VTypeUtil(org.csstudio.display.builder.model.util.VTypeUtil) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WidgetRuntime(org.csstudio.display.builder.runtime.WidgetRuntime) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) PVFactory(org.csstudio.display.builder.runtime.pv.PVFactory) RuntimePlugin.logger(org.csstudio.display.builder.runtime.RuntimePlugin.logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) PVNameToValueBinding(org.csstudio.display.builder.runtime.PVNameToValueBinding) List(java.util.List) XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) Map(java.util.Map) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) TraceWidgetProperty(org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) MarkerProperty(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget.MarkerProperty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 50 with VType

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

the class VTypePV method addListener.

@Override
public void addListener(final RuntimePVListener listener) {
    // If there is a known value, perform initial update
    final VType value = pv.read();
    if (value != null)
        listener.valueChanged(this, value);
    listeners.add(listener);
}
Also used : VType(org.diirt.vtype.VType)

Aggregations

VType (org.diirt.vtype.VType)69 Test (org.junit.Test)17 IPV (org.csstudio.simplepv.IPV)8 ArrayList (java.util.ArrayList)7 Display (org.diirt.vtype.Display)7 VEnum (org.diirt.vtype.VEnum)7 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)6 ListNumber (org.diirt.util.array.ListNumber)6 IFigure (org.eclipse.draw2d.IFigure)6 Instant (java.time.Instant)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)5 VNumberArray (org.diirt.vtype.VNumberArray)5 VString (org.diirt.vtype.VString)5 List (java.util.List)4 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ValueIterator (org.csstudio.archive.reader.ValueIterator)3 ArchiveVNumber (org.csstudio.archive.vtype.ArchiveVNumber)3 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)3