author | Edouard Tisserant |
Thu, 20 Aug 2020 14:12:49 +0200 | |
branch | svghmi |
changeset 3032 | 2f6dfb99d094 |
parent 2969 | 88988edb2e93 |
child 3220 | ec365ef396b1 |
permissions | -rw-r--r-- |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
1 |
// widget_switch.ysl2 |
2779
75c6a31caca6
SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents:
2763
diff
changeset
|
2 |
|
2962
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
3 |
template "widget[@type='Switch']", mode="widget_class" |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
4 |
|| |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
5 |
class SwitchWidget extends Widget{ |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
6 |
frequency = 5; |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
7 |
dispatch(value) { |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
8 |
for(let choice of this.choices){ |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
9 |
if(value != choice.value){ |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
10 |
choice.elt.setAttribute("style", "display:none"); |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
11 |
} else { |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
12 |
choice.elt.setAttribute("style", choice.style); |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
13 |
} |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
14 |
} |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
15 |
} |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
16 |
} |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
17 |
|| |
02ea529fd08c
SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2907
diff
changeset
|
18 |
|
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
19 |
template "widget[@type='Switch']", mode="widget_defs" { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
20 |
param "hmi_element"; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
21 |
| choices: [ |
2907
1695122a5e16
SVGHMI: HMI:Switch now accepts boolean values 'true' and 'false'
Edouard Tisserant
parents:
2883
diff
changeset
|
22 |
const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; |
2969
88988edb2e93
SVGHMI: Switch widget was picking sub-elements from original SVG, not the result SVG ehwe clones are unlinked, thus making problems with svg:use based widgets.
Edouard Tisserant
parents:
2962
diff
changeset
|
23 |
foreach "$result_svg_ns//*[@id = $hmi_element/@id]//*[regexp:test(@inkscape:label,$regex)]" { |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
24 |
const "literal", "regexp:match(@inkscape:label,$regex)[2]"; |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
25 |
| { |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
26 |
| elt:id("«@id»"), |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
27 |
| style:"«@style»", |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
28 |
| value:«$literal» |
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
29 |
| }`if "position()!=last()" > ,` |
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
30 |
} |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
31 |
| ], |
2753
9a7e12e96399
SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
diff
changeset
|
32 |
} |