author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Mon, 18 Nov 2024 22:42:11 +0100 | |
changeset 4041 | af7671a9945a |
parent 3922 | ffc8da83fdc2 |
permissions | -rw-r--r-- |
3627
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
1 |
// widget_assign.ysl2 |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
2 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
3 |
widget_desc("Assign") { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
4 |
longdesc |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
5 |
|| |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
6 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
7 |
Arguments are either: |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
8 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
9 |
- name=value: setting variable with literal value. |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
10 |
- name=other_name: copy variable content into another |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
11 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
12 |
"active"+"inactive" labeled elements can be provided to show feedback when pressed |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
13 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
14 |
Exemples: |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
15 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
16 |
HMI:Assign:notify=1@notify=/PLCVAR |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
17 |
HMI:Assign:ack=2:notify=1@ack=.local_var@notify=/PLCVAR |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
18 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
19 |
|| |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
20 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
21 |
shortdesc > Assign variables on click |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
22 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
23 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
24 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
25 |
widget_class("Assign") { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
26 |
|| |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
27 |
frequency = 2; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
28 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
29 |
onmouseup(evt) { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
30 |
svg_root.removeEventListener("pointerup", this.bound_onmouseup, true); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
31 |
if(this.enable_state) { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
32 |
this.activity_state = false |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
33 |
this.request_animate(); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
34 |
this.assign(); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
35 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
36 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
37 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
38 |
onmousedown(){ |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
39 |
if(this.enable_state) { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
40 |
svg_root.addEventListener("pointerup", this.bound_onmouseup, true); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
41 |
this.activity_state = true; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
42 |
this.request_animate(); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
43 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
44 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
45 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
46 |
|| |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
47 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
48 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
49 |
widget_defs("Assign") { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
50 |
optional_activable(); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
51 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
52 |
| init: function() { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
53 |
| this.bound_onmouseup = this.onmouseup.bind(this); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
54 |
| this.element.addEventListener("pointerdown", this.onmousedown.bind(this)); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
55 |
| }, |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
56 |
|
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
57 |
| assignments: {}, |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
58 |
| dispatch: function(value, oldval, varnum) { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
59 |
const "widget", "."; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
60 |
foreach "path" { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
61 |
const "varid","generate-id()"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
62 |
const "varnum","position()-1"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
63 |
if "@assign" foreach "$widget/path[@assign]" if "$varid = generate-id()" { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
64 |
| if(varnum == «$varnum») this.assignments["«@assign»"] = value; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
65 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
66 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
67 |
| }, |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
68 |
| assign: function() { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
69 |
const "paths","path"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
70 |
foreach "arg[contains(@value,'=')]"{ |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
71 |
const "name","substring-before(@value,'=')"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
72 |
const "value","substring-after(@value,'=')"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
73 |
const "index" foreach "$paths" if "@assign = $name" value "position()-1"; |
3922
ffc8da83fdc2
SVG: fix HMI:Assign widget to properly handle single-letter variable names.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3627
diff
changeset
|
74 |
const "isVarName", "regexp:test($value,'^[a-zA-Z_][a-zA-Z0-9_]*$')"; |
3627
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
75 |
choose { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
76 |
when "$isVarName"{ |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
77 |
| const «$value» = this.assignments["«$value»"]; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
78 |
| if(«$value» != undefined) |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
79 |
| this.apply_hmi_value(«$index», «$value»); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
80 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
81 |
otherwise { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
82 |
| this.apply_hmi_value(«$index», «$value»); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
83 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
84 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
85 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
86 |
| }, |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
87 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
88 |