author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 03 Dec 2024 21:22:45 +0100 | |
changeset 4057 | cf42c3dbdd5c |
parent 3921 | 9bb17341aebb |
permissions | -rw-r--r-- |
3685
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
1 |
// widget_page.ysl2 |
3627
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
2 |
|
3685
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
3 |
widget_desc("Page") { |
3627
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 |
|
3685
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
9 |
- XXX reference path TODO |
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
10 |
|
3627
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
11 |
- name=value: setting variable with literal value. |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
12 |
- name=other_name: copy variable content into another |
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 |
|
3685
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
16 |
HMI:Page:notify=1@notify=/PLCVAR |
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
17 |
HMI:Page:ack=2:notify=1@ack=.local_var@notify=/PLCVAR |
3627
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 |
|
3685
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
21 |
shortdesc > Page |
3627
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 |
|
3685
570a738239f4
SVGHMI: Add arbitrary variable assignment when entering Pages
Edouard Tisserant
parents:
3627
diff
changeset
|
25 |
widget_defs("Page") { |
3627
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 |
| assignments: {}, |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
28 |
| dispatch: function(value, oldval, varnum) { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
29 |
const "widget", "."; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
30 |
foreach "path" { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
31 |
const "varid","generate-id()"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
32 |
const "varnum","position()-1"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
33 |
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
|
34 |
| if(varnum == «$varnum») this.assignments["«@assign»"] = value; |
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 |
| assign: function() { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
39 |
const "paths","path"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
40 |
foreach "arg[contains(@value,'=')]"{ |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
41 |
const "name","substring-before(@value,'=')"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
42 |
const "value","substring-after(@value,'=')"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
43 |
const "index" foreach "$paths" if "@assign = $name" value "position()-1"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
44 |
const "isVarName", "regexp:test($value,'^[a-zA-Z_][a-zA-Z0-9_]+$')"; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
45 |
choose { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
46 |
when "$isVarName"{ |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
47 |
| const «$value» = this.assignments["«$value»"]; |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
48 |
| if(«$value» != undefined) |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
49 |
| this.apply_hmi_value(«$index», «$value»); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
50 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
51 |
otherwise { |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
52 |
| this.apply_hmi_value(«$index», «$value»); |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
53 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
54 |
} |
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 |
} |
1b627c2c743c
SVGHMI: Add Assign widget, doing multiple assignments on click.
Edouard Tisserant
parents:
diff
changeset
|
58 |