Skip to content

Commit

Permalink
MEDM converter: Fix patching of bool expression
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed May 21, 2024
1 parent 3a9dee2 commit adb13c7
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ else if (dynAttr.get_vis().equals("if zero"))
widgetModel);
else if (dynAttr.get_vis().equals("calc"))
{
// Make widget visible, then add rule to make invisible
WidgetProperty<Boolean> visible = widgetModel.getProperty(CommonWidgetProperties.propVisible);
visible.setValue(true);
// Make widget visible
final WidgetProperty<Boolean> visible = widgetModel.getProperty(CommonWidgetProperties.propVisible);
visible.setValue(true); // true is already the default, but just in case ...

visible = visible.clone();
visible.setValue(false);
// Add rule to hide
final WidgetProperty<Boolean> hide = visible.clone();
hide.setValue(false);

final List<ScriptPV> pvs = new ArrayList<>();
for (String pv : List.of(dynAttr.get_chan(), dynAttr.get_chanb(), dynAttr.get_chanc(), dynAttr.get_chand()))
Expand All @@ -166,7 +167,7 @@ else if (dynAttr.get_vis().equals("calc"))
final RuleInfo rule = new RuleInfo("vis_calc",
CommonWidgetProperties.propVisible.getName(),
false,
List.of(new RuleInfo.ExprInfoValue<>("!("+ newExpr + ")", visible)),
List.of(new RuleInfo.ExprInfoValue<>("!("+ newExpr + ")", hide)),
pvs);

widgetModel.propRules().setValue(List.of(rule));
Expand Down Expand Up @@ -255,17 +256,22 @@ private void addSimpleVisibilityRule(final String name,
* @return
*/
private String translateExpression(String adlExpr) {
// Variable names
String opiExpr = adlExpr.replace("A", "pv0")
.replace("B", "pv1")
.replace("C", "pv2")
.replace("D", "pv3")
.replace("=", "==")
.replace("#", "!=");

// The above can result in "pv0====7" or "pv1 !== 8"
// when exiting "==" or "!=" gets replaced.
// Patch that back into a plain "==" resp. "!="
opiExpr = opiExpr.replaceAll("==+", "==");
.replace("D", "pv3");

// MEDM allows both "#" and "!=", while jython would consider "#.." a comment
opiExpr = opiExpr.replace("#", "!=");

// Replace any sequence of "=" with "=="
opiExpr = opiExpr.replaceAll("=+", "==");

// The above can result in "pv1 !== 8"
// when exiting "!=" got replaced with "!==".
// Patch that back into "!="
opiExpr = opiExpr.replaceAll("!=+", "!=");

return opiExpr;
}
Expand Down

0 comments on commit adb13c7

Please sign in to comment.