Skip to content

Commit

Permalink
Add CALC support to Rectangle Alarm (#39)
Browse files Browse the repository at this point in the history
Add CALC support to Rectangle Alarm
Fixes #38
  • Loading branch information
slominskir authored Apr 4, 2024
1 parent fdb746e commit 7f541c9
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
66 changes: 66 additions & 0 deletions examples/edl/wedm/tests/calc-alarm.edl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
4 0 1
beginScreenProperties
major 4
minor 0
release 1
x 0
y 0
w 400
h 400
font "helvetica-medium-r-18.0"
ctlFont "helvetica-medium-r-18.0"
btnFont "helvetica-medium-r-18.0"
fgColor index 8
bgColor index 2
textColor index 14
ctlFgColor1 index 14
ctlFgColor2 index 14
ctlBgColor1 index 51
ctlBgColor2 index 8
topShadowColor index 2
botShadowColor index 12
snapToGrid
endScreenProperties

# (Rectangle)
object activeRectangleClass
beginObjectProperties
major 4
minor 0
release 0
x 50
y 40
w 15
h 10
lineColor index 14
fill
fillColor index 113
fillAlarm
alarmPv "CALC\\\{max(A,B)\}(channel1.STAT,channel2.STAT)"
endObjectProperties

# (Text Monitor)
object activeXTextDspClass:noedit
beginObjectProperties
major 4
minor 7
release 0
x 180
y 40
w 300
h 22
controlPv "CALC\\\{max(A,B)\}(channel1.SEVR,channel2.SEVR)"
font "helvetica-medium-r-18.0"
fgColor index 14
bgColor index 51
topShadowColor index 2
botShadowColor index 12
useDisplayBg
autoHeight
limitsFromDb
nullColor index 14
useHexPrefix
newPos
objType "monitors"
endObjectProperties

38 changes: 30 additions & 8 deletions src/main/webapp/resources/js/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,32 @@ jlab.wedm.PvObserver = function (id, pvSet) {
return pvs;
};

jlab.wedm.PvObserver.prototype.handleCalcExpr = function(value) {
if (jlab.wedm.isCalcExpr(this.pvSet.colorPvExpr)) {
var pvs = this.toOrderedExpressionValues(this.pvSet.colorPvs);
jlab.wedm.PvObserver.prototype.handleColorCalcExpr = function(value) {

if(pvs == null) {
var expr = this.pvSet.colorPvExpr,
pvs = this.pvSet.colorPvs;

return this.handleCalcExpr(value, expr, pvs);
};

jlab.wedm.PvObserver.prototype.handleAlarmCalcExpr = function(value) {

var expr = this.pvSet.alarmPvExpr,
pvs = this.pvSet.alarmPvs;

return this.handleCalcExpr(value, expr, pvs);
};

jlab.wedm.PvObserver.prototype.handleCalcExpr = function(value, expr, pvs) {

if (jlab.wedm.isCalcExpr(expr)) {
var ordered = this.toOrderedExpressionValues(pvs);

if(ordered == null) {
return null; // We don't have complete set of variables yet!
}

value = jlab.wedm.evalCalcExpr(this.pvSet.colorPvExpr, pvs);
value = jlab.wedm.evalCalcExpr(expr, ordered);
}

return value;
Expand Down Expand Up @@ -649,9 +666,14 @@ jlab.wedm.createWidgets = function () {
if (alarmSensitive && indicatorPvs.length === 1 && !jlab.wedm.isLocalExpr(indicatorPvs[0])) {
basename = jlab.wedm.basename(indicatorPvs[0]);
alarmPvs.push(basename + ".SEVR");
} else if (alarmPvs.length === 1) {
basename = jlab.wedm.basename(alarmPvs[0]);
alarmPvs[0] = basename + ".SEVR";
}

// Force alarm PVs to always end with .SEVR
for(var i = 0; i < alarmPvs.length; i++) {
basename = jlab.wedm.basename(alarmPvs[i]);
var newname = basename + ".SEVR";
alarmPvExpr = alarmPvExpr.replace(alarmPvs[i], newname);
alarmPvs[i] = newname;
}

if (showUnits && ctrlPvs.length === 1 && !jlab.wedm.isLocalExpr(ctrlPvs[0]) && typeof $obj.find(".screen-text") !== 'undefined') {
Expand Down
10 changes: 8 additions & 2 deletions src/main/webapp/resources/widgets/activeRectangleClass/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jlab.wedm.ShapePvObserverInit = function () {
lineAlarm = $obj.attr("data-line-alarm") === "true",
invalid = false;

sevr = this.handleAlarmCalcExpr(sevr);

if(sevr == null) {
return; // Still waiting for more updates
}

$obj.attr("data-sevr", sevr);
$obj[0].classList.remove("waiting-for-state");

Expand Down Expand Up @@ -92,7 +98,7 @@ jlab.wedm.ShapePvObserverInit = function () {
if (lineRuleIndex !== undefined) {
stmt = jlab.wedm.colorRules[lineRuleIndex];

value = this.handleCalcExpr(value);
value = this.handleColorCalcExpr(value);

if(value == null) {
return; // Still waiting for more updates
Expand All @@ -106,7 +112,7 @@ jlab.wedm.ShapePvObserverInit = function () {
if (fillRuleIndex !== undefined) {
stmt = jlab.wedm.colorRules[fillRuleIndex];

value = this.handleCalcExpr(value);
value = this.handleColorCalcExpr(value);

if(value == null) {
return; // Still waiting for more updates
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/resources/widgets/activeXTextClass/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jlab.wedm.StaticTextPvObserverInit = function () {
if (typeof fgRuleIndex !== 'undefined') {
stmt = jlab.wedm.colorRules[fgRuleIndex];

value = this.handleCalcExpr(value);
value = this.handleColorCalcExpr(value);

if(value == null) {
return; // Still waiting for more updates
Expand All @@ -121,7 +121,7 @@ jlab.wedm.StaticTextPvObserverInit = function () {
if (typeof bgRuleIndex !== 'undefined') {
stmt = jlab.wedm.colorRules[bgRuleIndex];

value = this.handleCalcExpr(value);
value = this.handleColorCalcExpr(value);

if(value == null) {
return; // Still waiting for more updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jlab.wedm.ControlTextPvObserverInit = function () {
hexPrefix = $obj.attr("data-hex-prefix") === "true",
units = $obj.attr("data-units");

if (typeof enumVal !== 'undefined') {
if (typeof enumVal !== 'undefined' && this.pvSet.ctrlPvs.length === 1) {
value = enumVal;
} else { /*Not an enum*/
if (jlab.wedm.isCalcExpr(this.pvSet.ctrlPvExpr)) {
Expand Down

0 comments on commit 7f541c9

Please sign in to comment.