Search in sources :

Example 1 with ScriptPV

use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.

the class ExampleModels method createModel.

/**
 * @return {@link DisplayModel}
 */
public static DisplayModel createModel() {
    final DisplayModel model = new DisplayModel();
    model.setPropertyValue(CommonWidgetProperties.propWidth, 1400);
    model.setPropertyValue(CommonWidgetProperties.propHeight, 20 * 50);
    for (int i = 0; i < 200; ++i) {
        final int x = 0 + (i / 20) * 132;
        final int y = 0 + (i % 20) * 50;
        final GroupWidget group = new GroupWidget();
        group.setPropertyValue(CommonWidgetProperties.propName, "Group " + i);
        group.setPropertyValue(CommonWidgetProperties.propX, x);
        group.setPropertyValue(CommonWidgetProperties.propY, y);
        group.setPropertyValue(CommonWidgetProperties.propWidth, 125);
        group.setPropertyValue(CommonWidgetProperties.propHeight, 53);
        final LabelWidget label = new LabelWidget();
        label.setPropertyValue(CommonWidgetProperties.propName, "Label " + i);
        label.setPropertyValue(CommonWidgetProperties.propX, 0);
        label.setPropertyValue(CommonWidgetProperties.propY, 4);
        label.setPropertyValue(CommonWidgetProperties.propWidth, 15);
        label.setPropertyValue(CommonWidgetProperties.propHeight, 15);
        label.setPropertyValue(CommonWidgetProperties.propText, Integer.toString(i));
        group.runtimeChildren().addChild(label);
        // For SWT implementation, rect. is not 'transparent',
        // so needs to be behind text
        final RectangleWidget rect = new RectangleWidget();
        rect.setPropertyValue(CommonWidgetProperties.propName, "Rect " + i);
        rect.setPropertyValue(CommonWidgetProperties.propX, 10);
        rect.setPropertyValue(CommonWidgetProperties.propY, 0);
        rect.setPropertyValue(CommonWidgetProperties.propWidth, 80);
        rect.setPropertyValue(CommonWidgetProperties.propHeight, 19);
        rect.setPropertyValue(CommonWidgetProperties.propScripts, Arrays.asList(new ScriptInfo("../org.csstudio.display.builder.runtime.test/examples/fudge_width.py", true, new ScriptPV("noise"))));
        group.runtimeChildren().addChild(rect);
        final TextUpdateWidget text = new TextUpdateWidget();
        text.setPropertyValue(CommonWidgetProperties.propName, "Text " + i);
        text.setPropertyValue(CommonWidgetProperties.propX, 30);
        text.setPropertyValue(CommonWidgetProperties.propY, 4);
        text.setPropertyValue(CommonWidgetProperties.propWidth, 45);
        text.setPropertyValue(CommonWidgetProperties.propHeight, 15);
        text.setPropertyValue(CommonWidgetProperties.propPVName, "ramp");
        group.runtimeChildren().addChild(text);
        model.runtimeChildren().addChild(group);
    }
    return model;
}
Also used : RectangleWidget(org.csstudio.display.builder.model.widgets.RectangleWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget)

Example 2 with ScriptPV

use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.

the class JFXScriptsDialogDemo method start.

@Override
public void start(final Stage stage) {
    final List<ScriptInfo> scripts = new ArrayList<>();
    scripts.add(new ScriptInfo("/tmp/demo1.py", true, new ScriptPV("pv1")));
    scripts.add(new ScriptInfo("/tmp/demo2.py", false, new ScriptPV("pv1"), new ScriptPV("pv2", false)));
    final ScriptsDialog dialog = new ScriptsDialog(new Widget("demo"), scripts);
    final Optional<List<ScriptInfo>> result = dialog.showAndWait();
    if (result.isPresent()) {
        for (ScriptInfo info : result.get()) System.out.println(info + ", embedded text: " + info.getText());
    } else
        System.out.println("Cancelled");
}
Also used : ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) ArrayList(java.util.ArrayList) Widget(org.csstudio.display.builder.model.Widget) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) List(java.util.List) ArrayList(java.util.ArrayList) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV)

Example 3 with ScriptPV

use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.

the class RulesTest method testValueAsExpression.

/**
 * Rules that uses the value of a PV within an expression
 */
@Test
public void testValueAsExpression() throws Exception {
    final Widget widget = new ImageWidget();
    final RuleInfo rule = new RuleInfo("WidthFromPV", "data_width", true, Arrays.asList(new RuleInfo.ExprInfoString("true", "pv0")), Arrays.asList(new ScriptPV("XSize")));
    System.out.println(rule);
    final String script = RuleToScript.generatePy(widget, rule);
    System.out.println(script);
    // Script must read the PV
    assertThat(script, containsString("PVUtil.get"));
}
Also used : ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) Test(org.junit.Test)

Example 4 with ScriptPV

use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.

the class RulesTest method testColorRule.

/**
 * Rule that uses color
 */
@Test
public void testColorRule() throws Exception {
    final LabelWidget widget = new LabelWidget();
    final WidgetProperty<WidgetColor> color = widget.propForegroundColor().clone();
    color.setValue(new WidgetColor(1, 2, 3));
    final RuleInfo rule = new RuleInfo("Color", "foreground_color", false, Arrays.asList(new RuleInfo.ExprInfoValue<WidgetColor>("pv0 > 10", color)), Arrays.asList(new ScriptPV("Whatever")));
    System.out.println(rule);
    final String script = RuleToScript.generatePy(widget, rule);
    System.out.println(script);
    // Script must create variables for colors
    assertThat(script, containsString("colorVal"));
}
Also used : LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) WidgetColor(org.csstudio.display.builder.model.properties.WidgetColor) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) Test(org.junit.Test)

Example 5 with ScriptPV

use of org.csstudio.display.builder.model.properties.ScriptPV in project org.csstudio.display.builder by kasemir.

the class RulesTest method testValueForCondition.

/**
 * Rule that checks pv0>10 and picks a certain value for that
 */
@Test
public void testValueForCondition() throws Exception {
    final ImageWidget widget = new ImageWidget();
    final WidgetProperty<Integer> width = widget.propDataWidth().clone();
    width.setValue(47);
    final RuleInfo rule = new RuleInfo("WidthBasedOnPV", "data_width", false, Arrays.asList(new RuleInfo.ExprInfoValue<Integer>("pv0>10", width)), Arrays.asList(new ScriptPV("XSize")));
    System.out.println(rule);
    final String script = RuleToScript.generatePy(widget, rule);
    System.out.println(script);
    // Script must read the PV
    assertThat(script, containsString("pv0 = PVUtil.getDouble(pvs[0])"));
}
Also used : ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) Test(org.junit.Test)

Aggregations

ScriptPV (org.csstudio.display.builder.model.properties.ScriptPV)5 RuleInfo (org.csstudio.display.builder.model.rules.RuleInfo)3 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Test (org.junit.Test)3 Widget (org.csstudio.display.builder.model.Widget)2 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)2 ImageWidget (org.csstudio.display.builder.model.widgets.plots.ImageWidget)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 WidgetColor (org.csstudio.display.builder.model.properties.WidgetColor)1 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)1 RectangleWidget (org.csstudio.display.builder.model.widgets.RectangleWidget)1 TextUpdateWidget (org.csstudio.display.builder.model.widgets.TextUpdateWidget)1 ScriptsDialog (org.csstudio.display.builder.representation.javafx.ScriptsDialog)1