Search in sources :

Example 1 with RuleInfo

use of org.csstudio.display.builder.model.rules.RuleInfo 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 2 with RuleInfo

use of org.csstudio.display.builder.model.rules.RuleInfo 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 3 with RuleInfo

use of org.csstudio.display.builder.model.rules.RuleInfo 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)

Example 4 with RuleInfo

use of org.csstudio.display.builder.model.rules.RuleInfo in project org.csstudio.display.builder by kasemir.

the class RulesDialogDemo method start.

/**
 * JavaFX Start
 */
@Override
public void start(final Stage stage) {
    final AutocompleteMenu menu = new AutocompleteMenu();
    final UndoableActionManager undo = new UndoableActionManager(10);
    final Widget widget = new LabelWidget();
    final List<RuleInfo> rules = widget.propRules().getValue();
    final RulesDialog dialog = new RulesDialog(undo, rules, widget, menu);
    System.out.println(dialog.showAndWait());
}
Also used : UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo)

Example 5 with RuleInfo

use of org.csstudio.display.builder.model.rules.RuleInfo in project org.csstudio.display.builder by kasemir.

the class RulesWidgetProperty method writeToXML.

@Override
public void writeToXML(final ModelWriter model_writer, final XMLStreamWriter writer) throws Exception {
    logger.log(Level.FINE, "Write " + value.size() + " rules to XML");
    for (final RuleInfo info : value) {
        // <rule name="name" prop_id="prop" out_exp="true">
        writer.writeStartElement(XMLTags.RULE);
        writer.writeAttribute(XMLTags.NAME, info.getName());
        writer.writeAttribute("prop_id", info.getPropID());
        writer.writeAttribute("out_exp", String.valueOf(info.getPropAsExprFlag()));
        for (final ExpressionInfo<?> expr : info.getExpressions()) {
            // <exp bool_exp="foo==1">
            writer.writeStartElement("exp");
            writer.writeAttribute("bool_exp", expr.getBoolExp());
            if (info.getPropAsExprFlag()) {
                // <expression>
                writer.writeStartElement("expression");
                if (!(expr.getPropVal() instanceof String)) {
                    logger.log(Level.SEVERE, "Mismatch of rules output expression flag with expression value type, expected String, got ", expr.getPropVal().getClass());
                    writer.writeCharacters("ERROR");
                }
                // some string of the value or expression
                writer.writeCharacters((String) expr.getPropVal());
            } else {
                // <value>
                writer.writeStartElement("value");
                if (!(expr.getPropVal() instanceof WidgetProperty<?>)) {
                    logger.log(Level.SEVERE, "Mismatch of rules output expression flag with expression value type, expected Widget Property, got ", expr.getPropVal().getClass());
                    writer.writeCharacters("ERROR");
                }
                // write the property
                ((WidgetProperty<?>) expr.getPropVal()).writeToXML(model_writer, writer);
            }
            // </value> or </expression>
            writer.writeEndElement();
            // </exp>
            writer.writeEndElement();
        }
        for (final ScriptPV pv : info.getPVs()) {
            // <pv trig="true">
            writer.writeStartElement(XMLTags.PV_NAME);
            if (!pv.isTrigger())
                writer.writeAttribute(XMLTags.TRIGGER, Boolean.FALSE.toString());
            // some string of the pv name
            writer.writeCharacters(pv.getName());
            // </pv>
            writer.writeEndElement();
        }
        // </rule>
        writer.writeEndElement();
    }
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo)

Aggregations

RuleInfo (org.csstudio.display.builder.model.rules.RuleInfo)7 ScriptPV (org.csstudio.display.builder.model.properties.ScriptPV)3 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Widget (org.csstudio.display.builder.model.Widget)2 ExprInfoString (org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString)2 ImageWidget (org.csstudio.display.builder.model.widgets.plots.ImageWidget)2 HashMap (java.util.HashMap)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 MacroValueProvider (org.csstudio.display.builder.model.macros.MacroValueProvider)1 ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)1 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)1 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)1 WidgetColor (org.csstudio.display.builder.model.properties.WidgetColor)1 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)1 ExpressionInfo (org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo)1 AutocompleteMenu (org.csstudio.display.builder.representation.javafx.AutocompleteMenu)1