Search in sources :

Example 26 with VType

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

the class FormatOptionHandlerTest method testStringArrayParsing.

@Test
public void testStringArrayParsing() throws Exception {
    final VType value = ValueFactory.newVStringArray(Arrays.asList("Flintstone, \"Al\" Fred", "Jane"), ValueFactory.alarmNone(), ValueFactory.timeNow());
    final String text = FormatOptionHandler.format(value, FormatOption.DEFAULT, 0, true);
    System.out.println(text);
    Object parsed = FormatOptionHandler.parse(value, text, FormatOption.DEFAULT);
    System.out.println(Arrays.toString((String[]) parsed));
    assertThat(parsed, equalTo(new String[] { "Flintstone, \"Al\" Fred", "Jane" }));
    parsed = FormatOptionHandler.parse(value, "[ \"Freddy\", \"Janet\" ] ", FormatOption.DEFAULT);
    assertThat(parsed, instanceOf(String[].class));
    assertThat(parsed, equalTo(new String[] { "Freddy", "Janet" }));
    parsed = FormatOptionHandler.parse(value, "[ Freddy, Janet ] ", FormatOption.DEFAULT);
    assertThat(parsed, equalTo(new String[] { "Freddy", "Janet" }));
    parsed = FormatOptionHandler.parse(value, "Freddy, Janet", FormatOption.DEFAULT);
    assertThat(parsed, equalTo(new String[] { "Freddy", "Janet" }));
    parsed = FormatOptionHandler.parse(value, " [ \"Flintstone, Fred\", Janet", FormatOption.DEFAULT);
    assertThat(parsed, equalTo(new String[] { "Flintstone, Fred", "Janet" }));
    parsed = FormatOptionHandler.parse(value, " \"Al \\\"Ed\\\" Stone\", Jane", FormatOption.DEFAULT);
    System.out.println(Arrays.toString((String[]) parsed));
    assertThat(parsed, equalTo(new String[] { "Al \"Ed\" Stone", "Jane" }));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Example 27 with VType

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

the class FormatOptionHandlerTest method testString.

@Test
public void testString() throws Exception {
    // Actual String
    VType value = ValueFactory.newVString("Test1", ValueFactory.alarmNone(), ValueFactory.timeNow());
    String text = FormatOptionHandler.format(value, FormatOption.DEFAULT, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("Test1"));
    text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("Test1"));
    text = FormatOptionHandler.format(value, FormatOption.EXPONENTIAL, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("Test1"));
    // Number interpreted as char
    value = ValueFactory.newVDouble(65.0, display);
    text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("A V"));
    // Number array interpreted as long string
    // UTF-8 for 'Hello'
    ListNumber data = new ArrayInt(72, 101, 108, 108, 111);
    value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
    System.out.println(value);
    text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("Hello"));
    data = new ArrayInt(/* Dollar */
    0x24, /* Euro */
    0xE2, 0x82, 0xAC);
    value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
    System.out.println(value);
    text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
    System.out.println(text);
    // For this to work, Eclipse IDE Preferences -> General -> Workspace -> Text file encoding
    // must be set to UTF-8, which is the default on Linux but not necessarily Windows
    assertThat(text, equalTo("$€"));
}
Also used : ListNumber(org.diirt.util.array.ListNumber) VType(org.diirt.vtype.VType) ArrayInt(org.diirt.util.array.ArrayInt) Test(org.junit.Test)

Example 28 with VType

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

the class FormatOptionHandlerTest method testDecimal.

@Test
public void testDecimal() throws Exception {
    VType number = ValueFactory.newVDouble(3.16, display);
    assertThat(fmt.format(3.16), equalTo("3.16"));
    String text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("3.160 V"));
    text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, false);
    System.out.println(text);
    assertThat(text, equalTo("3.160"));
    text = FormatOptionHandler.format(number, FormatOption.DECIMAL, 4, true);
    System.out.println(text);
    assertThat(text, equalTo("3.1600 V"));
    text = FormatOptionHandler.format(number, FormatOption.DECIMAL, 1, true);
    System.out.println(text);
    assertThat(text, equalTo("3.2 V"));
    // For running in debugger: Repeated use of precision 4 should use cached format
    text = FormatOptionHandler.format(number, FormatOption.DECIMAL, 4, true);
    System.out.println(text);
    assertThat(text, equalTo("3.1600 V"));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Example 29 with VType

use of org.diirt.vtype.VType 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 30 with VType

use of org.diirt.vtype.VType 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)

Aggregations

VType (org.diirt.vtype.VType)76 Test (org.junit.Test)17 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)10 IFigure (org.eclipse.draw2d.IFigure)10 IPV (org.csstudio.simplepv.IPV)9 VEnum (org.diirt.vtype.VEnum)8 ArrayList (java.util.ArrayList)7 Display (org.diirt.vtype.Display)7 ListNumber (org.diirt.util.array.ListNumber)6 VNumberArray (org.diirt.vtype.VNumberArray)6 VString (org.diirt.vtype.VString)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 Instant (java.time.Instant)5 List (java.util.List)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)5 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