Search in sources :

Example 11 with VNumberArray

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

the class WaveformView method showSelectedSample.

/**
 * Show the current sample of the current model item.
 */
private void showSelectedSample() {
    // Get selected sample (= one waveform)
    final PlotSamples samples = model_item.getSamples();
    final int idx = sample_index.getSelection();
    final PlotSample sample;
    samples.getLock().lock();
    try {
        sample_index.setMaximum(samples.size());
        sample = samples.get(idx);
    } finally {
        samples.getLock().unlock();
    }
    // Setting the value can be delayed while the plot is being updated
    final VType value = sample.getVType();
    Activator.getThreadPool().execute(() -> waveform.setValue(value));
    if (value == null)
        clearInfo();
    else {
        updateAnnotation(sample.getPosition(), sample.getValue());
        int size = value instanceof VNumberArray ? ((VNumberArray) value).getData().size() : 1;
        plot.getXAxis().setValueRange(0.0, (double) size);
        timestamp.setText(TimestampHelper.format(VTypeHelper.getTimestamp(value)));
        status.setText(NLS.bind(Messages.SeverityStatusFmt, VTypeHelper.getSeverity(value).toString(), VTypeHelper.getMessage(value)));
    }
    plot.requestUpdate();
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VType(org.diirt.vtype.VType) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 12 with VNumberArray

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

the class WidgetInfoDialog method createPVs.

private Tab createPVs(final Collection<NameStateValue> pvs) {
    // Use text field to allow users to copy the name, value to clipboard
    final TableColumn<NameStateValue, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(TextFieldTableCell.forTableColumn());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().name));
    final TableColumn<NameStateValue, String> state = new TableColumn<>(Messages.WidgetInfoDialog_State);
    state.setCellFactory(TextFieldTableCell.forTableColumn());
    state.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().state));
    final TableColumn<NameStateValue, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(TextFieldTableCell.forTableColumn());
    value.setCellValueFactory(param -> {
        String text;
        final VType vtype = param.getValue().value;
        if (vtype == null)
            text = Messages.WidgetInfoDialog_Disconnected;
        else {
            // so only show the basic type info
            if (vtype instanceof VNumberArray)
                text = vtype.toString();
            else
                text = VTypeUtil.getValueString(vtype, true);
            if (vtype instanceof Alarm) {
                final Alarm alarm = (Alarm) vtype;
                if (alarm.getAlarmSeverity() != AlarmSeverity.NONE)
                    text = text + " [" + alarm.getAlarmSeverity().toString() + ", " + alarm.getAlarmName() + "]";
            }
        }
        return new ReadOnlyStringWrapper(text);
    });
    final ObservableList<NameStateValue> pv_data = FXCollections.observableArrayList(pvs);
    pv_data.sort((a, b) -> a.name.compareTo(b.name));
    final TableView<NameStateValue> table = new TableView<>(pv_data);
    table.getColumns().add(name);
    table.getColumns().add(state);
    table.getColumns().add(value);
    table.setEditable(true);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return new Tab(Messages.WidgetInfoDialog_TabPVs, table);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VType(org.diirt.vtype.VType) Tab(javafx.scene.control.Tab) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) Alarm(org.diirt.vtype.Alarm) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 13 with VNumberArray

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

the class ValueUtil method getDoubleArray.

/**
 * Try to get a 'double' type array from a value.
 *  @param value Value of a PV
 *  @return Current value as double[].
 *          Will return single-element array for scalar value,
 *          including <code>{ Double.NaN }</code> in case the value type
 *          does not decode into a number.
 */
public static double[] getDoubleArray(final VType value) {
    if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final Object wrapped = CollectionNumbers.wrappedArray(list);
        if (wrapped instanceof double[])
            return (double[]) wrapped;
        final double[] result = new double[list.size()];
        for (int i = 0; i < result.length; i++) result[i] = list.getDouble(i);
        return result;
    }
    return new double[] { getDouble(value) };
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber)

Example 14 with VNumberArray

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

the class ValueUtil method getTable.

/**
 * Get a table from PV
 *
 *  <p>Ideally, the PV holds a {@link VTable},
 *  and the returned data is then the table's data.
 *
 *  <p>If the PV is a scalar, a table with a single cell is returned.
 *  <p>If the PV is an array, a table with one column is returned.
 *
 *  @param value Value of a PV
 *  @return List of rows, where each row contains either String or Number cells
 */
@SuppressWarnings("rawtypes")
public static List<List<Object>> getTable(final VType value) {
    final List<List<Object>> data = new ArrayList<>();
    if (value instanceof VTable) {
        final VTable table = (VTable) value;
        final int rows = table.getRowCount();
        final int cols = table.getColumnCount();
        // Extract 2D string matrix for data
        for (int r = 0; r < rows; ++r) {
            final List<Object> row = new ArrayList<>(cols);
            for (int c = 0; c < cols; ++c) {
                final Object col_data = table.getColumnData(c);
                if (col_data instanceof List)
                    row.add(Objects.toString(((List) col_data).get(r)));
                else if (col_data instanceof ListDouble)
                    row.add(((ListDouble) col_data).getDouble(r));
                else if (col_data instanceof ListNumber)
                    row.add(((ListNumber) col_data).getLong(r));
                else
                    row.add(Objects.toString(col_data));
            }
            data.add(row);
        }
    } else if (value instanceof VNumberArray) {
        final ListNumber numbers = ((VNumberArray) value).getData();
        final int num = numbers.size();
        for (int i = 0; i < num; ++i) data.add(Arrays.asList(numbers.getDouble(i)));
    } else if (value instanceof VNumber)
        data.add(Arrays.asList(((VNumber) value).getValue()));
    else
        data.add(Arrays.asList(Objects.toString(value)));
    return data;
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) VTable(org.diirt.vtype.VTable) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ListDouble(org.diirt.util.array.ListDouble) VNumber(org.diirt.vtype.VNumber)

Example 15 with VNumberArray

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

the class ArrayPVDispatcherTest method testArrayPVDispatcher.

/**
 * Test double-typed array PV
 */
@Test
public void testArrayPVDispatcher() throws Exception {
    // Array PV. It's elements are to be dispatched into separate PVs
    final RuntimePV array_pv = PVFactory.getPV("loc://an_array(1.0, 2.0, 3, 4)");
    // The per-element PVs that will be bound to the array
    final AtomicReference<List<RuntimePV>> element_pvs = new AtomicReference<>();
    final CountDownLatch got_element_pvs = new CountDownLatch(1);
    // Listener to the ArrayPVDispatcher
    final Listener dispatch_listener = new Listener() {

        @Override
        public void arrayChanged(final List<RuntimePV> pvs) {
            System.out.println("Per-element PVs: ");
            element_pvs.set(pvs);
            dump(pvs);
            got_element_pvs.countDown();
        }
    };
    final ArrayPVDispatcher dispatcher = new ArrayPVDispatcher(array_pv, "elementA247FE_", dispatch_listener);
    // Await initial set of per-element PVs
    got_element_pvs.await();
    assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(0).read()).doubleValue(), equalTo(1.0));
    assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(1).read()).doubleValue(), equalTo(2.0));
    assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(2).read()).doubleValue(), equalTo(3.0));
    assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(3).read()).doubleValue(), equalTo(4.0));
    // Change array -> Observe update of per-element PV
    System.out.println("Updating array");
    array_pv.write(new double[] { 1.0, 22.5, 3, 4 });
    dump(element_pvs.get());
    // On one hand, this changed only one array element.
    // On the other hand, it's a new array value with a new time stamp.
    // Unclear if the array dispatcher should detect this and only update
    // the per-element PVs that really have a new value, or all.
    // Currently it updates all, but the test is satisfied with just one update:
    assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(1).read()).doubleValue(), equalTo(22.5));
    // Change per-element PV -> Observe update of array
    System.out.println("Updating per-element PV for element [2]");
    element_pvs.get().get(2).write(30.7);
    // Test assumes a local array PV which immediately reflects the change.
    // A "real" PV can have a delay between writing a new value and receiving the update.
    final ListNumber array_value = ((VNumberArray) array_pv.read()).getData();
    System.out.println("Array: " + array_value);
    assertThat(array_value.getDouble(2), equalTo(30.7));
    // Close dispatcher
    dispatcher.close();
    // Close the array PV
    PVFactory.releasePV(array_pv);
}
Also used : ArrayPVDispatcher(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher) VNumberArray(org.diirt.vtype.VNumberArray) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) ListNumber(org.diirt.util.array.ListNumber) Listener(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher.Listener) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

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