author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Sun, 19 Apr 2020 10:48:34 +0200 | |
branch | svghmi |
changeset 2940 | 034b6ce4f885 |
parent 2937 | 9226a830fbc3 |
child 2941 | ef13a4007538 |
permissions | -rw-r--r-- |
2884
50b9832c51fc
SVGHMI: update Makefile to pick all changes to any dependency
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
1 |
// widgets_common.ysl2 |
50b9832c51fc
SVGHMI: update Makefile to pick all changes to any dependency
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2883
diff
changeset
|
2 |
|
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
3 |
in xsl decl labels(*ptr, name="defs_by_labels") alias call-template { |
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
4 |
with "hmi_element", "$hmi_element"; |
2810
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
5 |
with "labels"{text *ptr}; |
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
6 |
content; |
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
7 |
}; |
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
8 |
|
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
9 |
decl optional_labels(*ptr) alias - { |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
10 |
/* TODO add some per label xslt variable to check if exist */ |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
11 |
labels(*ptr){ |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
12 |
with "mandatory","'no'"; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
13 |
content; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
14 |
} |
2836
ce6cecdb7320
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents:
2834
diff
changeset
|
15 |
}; |
ce6cecdb7320
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents:
2834
diff
changeset
|
16 |
|
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
17 |
decl activable_labels(*ptr) alias - { |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
18 |
optional_labels(*ptr) { |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
19 |
with "subelements","'active inactive'"; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
20 |
content; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2920
diff
changeset
|
21 |
} |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
22 |
}; |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
23 |
|
2881 | 24 |
template "svg:*", mode="hmi_elements" { |
2886
6c82fad8be65
SVGHMI: Simplification and optimization. func:parselabel becomes a template.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2884
diff
changeset
|
25 |
const "widget", "func:widget(@id)"; |
2881 | 26 |
const "eltid","@id"; |
27 |
| "«@id»": { |
|
28 |
| type: "«$widget/@type»", |
|
29 |
| args: [ |
|
2889
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
30 |
foreach "$widget/arg" |
2881 | 31 |
| "«@value»"`if "position()!=last()" > ,` |
32 |
| ], |
|
2889
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
33 |
| offset: 0, |
2881 | 34 |
| indexes: [ |
35 |
foreach "$widget/path" { |
|
36 |
choose { |
|
37 |
when "not(@index)" { |
|
38 |
warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree |
|
39 |
} |
|
40 |
otherwise { |
|
2893
d57a12b8f5db
SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents:
2890
diff
changeset
|
41 |
| «@index» /* «@value» */ `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
|
42 |
} |
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
43 |
} |
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
44 |
} |
2881 | 45 |
| ], |
46 |
| element: id("«@id»"), |
|
47 |
apply "$widget", mode="widget_defs" with "hmi_element","."; |
|
2889
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
48 |
apply "$widget", mode="widget_subscribe" with "hmi_element","."; |
2881 | 49 |
| }`if "position()!=last()" > ,` |
50 |
} |
|
2810
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
51 |
|
2889
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
52 |
// default : normal subscribing |
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
53 |
template "widget", mode="widget_subscribe" { |
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
54 |
| sub: subscribe, |
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
55 |
| unsub: unsubscribe, |
2897
bf8a39cc65e4
SVGHMI: Generalize applying cache to widgets, be it from page or ForEach widgets. Now ForEach widget buttons work as expected.
Edouard Tisserant
parents:
2893
diff
changeset
|
56 |
| apply_cache: widget_apply_cache, |
2889
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
57 |
} |
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
58 |
// page aren't subscribers |
4eeed820fd3a
SVGHMI: reworked widget (un)subscription now a method of widgect object, allowing special subscription methods
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2886
diff
changeset
|
59 |
template "widget[@type='Page']", mode="widget_subscribe"; |
2793
2a97688c94c5
SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents:
2792
diff
changeset
|
60 |
|
2881 | 61 |
function "defs_by_labels" { |
62 |
param "labels","''"; |
|
63 |
param "mandatory","'yes'"; |
|
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
64 |
param "subelements","/.."; |
2881 | 65 |
param "hmi_element"; |
66 |
const "widget_type","@type"; |
|
67 |
foreach "str:split($labels)" { |
|
68 |
const "name","."; |
|
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
69 |
const "elt","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]"; |
2881 | 70 |
choose { |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
71 |
when "not($elt/@id)" { |
2881 | 72 |
if "$mandatory='yes'" { |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
73 |
error > «$widget_type» widget must have a «$name» element |
2834
6ac6a9dff594
SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents:
2833
diff
changeset
|
74 |
} |
2881 | 75 |
// otherwise produce nothing |
2797
c5ba1e77f054
SVGHMI: added a widgets description object, accessed by id. Added frequency to widgets, as separate template to allow future customization. Excluded non svg elements (i.e inkscape Sets) with HMI: labels from widgets.
Edouard Tisserant
parents:
2796
diff
changeset
|
76 |
} |
2881 | 77 |
otherwise { |
2920
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
78 |
| «$name»_elt: id("«$elt/@id»"), |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
79 |
if "$subelements" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
80 |
| «$name»_sub: { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
81 |
foreach "str:split($subelements)" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
82 |
const "subname","."; |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
83 |
const "subelt","$elt/*[@inkscape:label=$subname][1]"; |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
84 |
choose { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
85 |
when "not($subelt/@id)" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
86 |
if "$mandatory='yes'" { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
87 |
error > «$widget_type» widget must have a «$name»/«$subname» element |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
88 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
89 |
| /* missing «$name»/«$subname» element */ |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
90 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
91 |
otherwise { |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
92 |
| "«$subname»": id("«$subelt/@id»")`if "position()!=last()" > ,` |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
93 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
94 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
95 |
} |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
96 |
| }, |
3ee337c8c769
SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2897
diff
changeset
|
97 |
} |
2836
ce6cecdb7320
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents:
2834
diff
changeset
|
98 |
} |
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
99 |
} |
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
100 |
} |
2881 | 101 |
} |
2808
dc78ffa5253d
SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents:
2807
diff
changeset
|
102 |
|
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:
2881
diff
changeset
|
103 |
def "func:escape_quotes" { |
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:
2881
diff
changeset
|
104 |
param "txt"; |
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:
2881
diff
changeset
|
105 |
// have to use a python string to enter escaped quote |
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:
2881
diff
changeset
|
106 |
const "frst", !"substring-before($txt,'\"')"!; |
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:
2881
diff
changeset
|
107 |
const "frstln", "string-length($frst)"; |
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:
2881
diff
changeset
|
108 |
choose { |
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:
2881
diff
changeset
|
109 |
when "$frstln > 0 and string-length($txt) > $frstln" { |
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:
2881
diff
changeset
|
110 |
result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!; |
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:
2881
diff
changeset
|
111 |
} |
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:
2881
diff
changeset
|
112 |
otherwise { |
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:
2881
diff
changeset
|
113 |
result "$txt"; |
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:
2881
diff
changeset
|
114 |
} |
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:
2881
diff
changeset
|
115 |
} |
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:
2881
diff
changeset
|
116 |
} |
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:
2881
diff
changeset
|
117 |