author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Thu, 04 Feb 2021 21:20:01 +0100 | |
branch | svghmi |
changeset 3125 | 1fb0c07bd97b |
parent 3018 | 22b969b409b0 |
child 3232 | 7bdb766c2a4d |
permissions | -rw-r--r-- |
3014
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
1 |
// widget_multistate.ysl2 |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
2 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
3 |
template "widget[@type='MultiState']", mode="widget_class" |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
4 |
|| |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
5 |
class MultiStateWidget extends Widget{ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
6 |
frequency = 5; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
7 |
state = 0; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
8 |
dispatch(value) { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
9 |
this.state = value; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
10 |
for(let choice of this.choices){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
11 |
if(this.state != choice.value){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
12 |
choice.elt.setAttribute("style", "display:none"); |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
13 |
} else { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
14 |
choice.elt.setAttribute("style", choice.style); |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
15 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
16 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
17 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
18 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
19 |
on_click(evt) { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
20 |
//get current selected value |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
21 |
let next_ind; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
22 |
for(next_ind=0; next_ind<this.choices.length; next_ind++){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
23 |
if(this.state == this.choices[next_ind].value){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
24 |
next_ind = next_ind + 1; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
25 |
break; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
26 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
27 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
28 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
29 |
//get next selected value |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
30 |
if(this.choices.length > next_ind){ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
31 |
this.state = this.choices[next_ind].value; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
32 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
33 |
else{ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
34 |
this.state = this.choices[0].value; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
35 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
36 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
37 |
//post value to plc |
3018 | 38 |
this.apply_hmi_value(0, this.state); |
3014
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
39 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
40 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
41 |
init() { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
42 |
this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
43 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
44 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
45 |
|| |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
46 |
|
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
47 |
template "widget[@type='MultiState']", mode="widget_defs" { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
48 |
param "hmi_element"; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
49 |
| choices: [ |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
50 |
const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
51 |
foreach "$result_svg_ns//*[@id = $hmi_element/@id]//*[regexp:test(@inkscape:label,$regex)]" { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
52 |
const "literal", "regexp:match(@inkscape:label,$regex)[2]"; |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
53 |
| { |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
54 |
| elt:id("«@id»"), |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
55 |
| style:"«@style»", |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
56 |
| value:«$literal» |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
57 |
| }`if "position()!=last()" > ,` |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
58 |
} |
1a3fd83d9136
Create new multistate widget which extand class widget
usveticic
parents:
diff
changeset
|
59 |
| ], |
3018 | 60 |
} |