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"));
}
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"));
}
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])"));
}
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());
}
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();
}
}
Aggregations