author | Edouard Tisserant |
Wed, 18 Mar 2020 12:06:50 +0100 | |
branch | svghmi |
changeset 2885 | f398896b7ebf |
parent 2884 | 50b9832c51fc |
child 2886 | 6c82fad8be65 |
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}; |
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
|
6 |
}; |
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 |
|
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
|
8 |
in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template { |
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
|
9 |
with "hmi_element", "$hmi_element"; |
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
|
10 |
with "labels"{text *ptr}; |
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
|
11 |
with "mandatory","'no'"; |
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
|
12 |
}; |
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
|
13 |
|
2881 | 14 |
template "svg:*", mode="hmi_elements" { |
15 |
const "widget", "func:parselabel(@inkscape:label)/widget"; |
|
16 |
const "eltid","@id"; |
|
17 |
| "«@id»": { |
|
18 |
| type: "«$widget/@type»", |
|
19 |
| args: [ |
|
20 |
foreach "$widget/arg" |
|
21 |
| "«@value»"`if "position()!=last()" > ,` |
|
22 |
| ], |
|
23 |
| indexes: [ |
|
24 |
foreach "$widget/path" { |
|
25 |
choose { |
|
26 |
when "not(@index)" { |
|
27 |
warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree |
|
28 |
} |
|
29 |
otherwise { |
|
30 |
| «@index»`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
|
31 |
} |
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
32 |
} |
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
33 |
} |
2881 | 34 |
| ], |
35 |
| element: id("«@id»"), |
|
36 |
apply "$widget", mode="widget_defs" with "hmi_element","."; |
|
37 |
| }`if "position()!=last()" > ,` |
|
38 |
} |
|
2810
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
39 |
|
2793
2a97688c94c5
SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents:
2792
diff
changeset
|
40 |
|
2881 | 41 |
function "defs_by_labels" { |
42 |
param "labels","''"; |
|
43 |
param "mandatory","'yes'"; |
|
44 |
param "hmi_element"; |
|
45 |
const "widget_type","@type"; |
|
46 |
foreach "str:split($labels)" { |
|
47 |
const "name","."; |
|
48 |
const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"; |
|
49 |
choose { |
|
50 |
when "not($elt_id)" { |
|
51 |
if "$mandatory='yes'" { |
|
52 |
// TODO FIXME error > «$widget_type» widget must have a «$name» element |
|
53 |
warning > «$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
|
54 |
} |
2881 | 55 |
// 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
|
56 |
} |
2881 | 57 |
otherwise { |
58 |
| «$name»_elt: id("«$elt_id»"), |
|
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
|
59 |
} |
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
|
60 |
} |
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
|
61 |
} |
2881 | 62 |
} |
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
|
63 |
|
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
|
64 |
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
|
65 |
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
|
66 |
// 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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
} |
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
|
73 |
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
|
74 |
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
|
75 |
} |
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
|
76 |
} |
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
|
77 |
} |
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
|
78 |