1 include yslt_noindent.yml2 |
1 include yslt_noindent.yml2 |
2 |
2 |
3 // overrides yslt's output function to set CDATA |
3 // overrides yslt's output function to set CDATA |
4 decl output(method, cdata-section-elements="xhtml:script"); |
4 decl output(method, cdata-section-elements="xhtml:script"); |
|
5 |
|
6 in xsl decl labels(*ptr, name="defs_by_labels") alias call-template { |
|
7 with "hmi_element", "$hmi_element"; |
|
8 with "labels"{test *ptr}; |
|
9 }; |
5 |
10 |
6 istylesheet |
11 istylesheet |
7 /* From Inkscape */ |
12 /* From Inkscape */ |
8 xmlns:dc="http://purl.org/dc/elements/1.1/" |
13 xmlns:dc="http://purl.org/dc/elements/1.1/" |
9 xmlns:cc="http://creativecommons.org/ns#" |
14 xmlns:cc="http://creativecommons.org/ns#" |
23 * <bbox x="0" y="0" w="42" h="42"> |
28 * <bbox x="0" y="0" w="42" h="42"> |
24 */ |
29 */ |
25 const "geometry", "ns:GetSVGGeometry()"; |
30 const "geometry", "ns:GetSVGGeometry()"; |
26 const "hmitree", "ns:GetHMITree()"; |
31 const "hmitree", "ns:GetHMITree()"; |
27 |
32 |
|
33 const "svg_root_id", "/svg:svg/@id"; |
28 const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; |
34 const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; |
29 const "hmi_geometry", "$geometry[@Id = $hmi_elements/@id]"; |
35 const "hmi_geometry", "$geometry[@Id = $hmi_elements/@id]"; |
30 |
36 |
31 const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"; |
37 const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"; |
32 |
38 |
94 |
100 |
95 /* Identity template : |
101 /* Identity template : |
96 * - copy every attributes |
102 * - copy every attributes |
97 * - copy every sub-elements |
103 * - copy every sub-elements |
98 */ |
104 */ |
99 template "@* | node()", mode="identity_svg" { |
105 template "@* | node()", mode="inline_svg" { |
100 /* use real xsl:copy instead copy-of alias from yslt.yml2 */ |
106 /* use real xsl:copy instead copy-of alias from yslt.yml2 */ |
101 xsl:copy apply "@* | node()", mode="identity_svg"; |
107 xsl:copy apply "@* | node()", mode="inline_svg"; |
|
108 } |
|
109 |
|
110 /* replaces inkscape's height and width hints. forces fit */ |
|
111 template "svg:svg/@width", mode="inline_svg"; |
|
112 template "svg:svg/@height", mode="inline_svg"; |
|
113 template "svg:svg", mode="inline_svg" xsl:copy { |
|
114 attrib "preserveAspectRatio" > none |
|
115 attrib "height" > 100vh |
|
116 attrib "width" > 100vw |
|
117 apply "@* | node()", mode="inline_svg"; |
102 } |
118 } |
103 |
119 |
104 /*const "mark" > =HMI=\n*/ |
120 /*const "mark" > =HMI=\n*/ |
105 |
121 |
106 /* copy root node and add geometry as comment for a test */ |
122 /* copy root node and add geometry as comment for a test */ |
107 template "/" { |
123 template "/" { |
108 comment > Made with SVGHMI. https://beremiz.org |
124 comment > Made with SVGHMI. https://beremiz.org |
|
125 /* DEBUG DATA |
|
126 comment { |
|
127 apply "$hmi_geometry", mode="testgeo"; |
|
128 } |
|
129 comment { |
|
130 apply "$hmitree", mode="testtree"; |
|
131 } |
|
132 comment { |
|
133 apply "$indexed_hmitree", mode="testtree"; |
|
134 } |
|
135 */ |
109 html xmlns="http://www.w3.org/1999/xhtml" { |
136 html xmlns="http://www.w3.org/1999/xhtml" { |
110 head; |
137 head; |
111 body style="margin:0;" { |
138 body style="margin:0;overflow:hidden;" { |
112 xsl:copy { |
139 apply "svg:svg", mode="inline_svg"; |
113 comment { |
|
114 apply "$hmi_geometry", mode="testgeo"; |
|
115 } |
|
116 comment { |
|
117 apply "$hmitree", mode="testtree"; |
|
118 } |
|
119 comment { |
|
120 apply "$indexed_hmitree", mode="testtree"; |
|
121 } |
|
122 apply "@* | node()", mode="identity_svg"; |
|
123 } |
|
124 script{ |
140 script{ |
125 call "scripts"; |
141 call "scripts"; |
126 } |
142 } |
127 } |
143 } |
128 } |
144 } |
228 @x >= $p/@x and @y >= $p/@y and |
244 @x >= $p/@x and @y >= $p/@y and |
229 @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id"""; |
245 @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id"""; |
230 const "page_elements", "$hmi_elements[@id = $page_ids]"; |
246 const "page_elements", "$hmi_elements[@id = $page_ids]"; |
231 | "«$desc/arg[1]/@value»": { |
247 | "«$desc/arg[1]/@value»": { |
232 | id: "«@id»", |
248 | id: "«@id»", |
|
249 | bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»], |
233 | widgets: [ |
250 | widgets: [ |
234 foreach "$page_ids" { |
251 foreach "$page_ids" { |
235 | hmi_widgets.«.»`if "position()!=last()" > ,` |
252 | hmi_widgets.«.»`if "position()!=last()" > ,` |
236 } |
253 } |
237 | ] |
254 | ] |
305 apply "*", mode="testtree" { |
322 apply "*", mode="testtree" { |
306 with "indent" value "concat($indent,'>')" |
323 with "indent" value "concat($indent,'>')" |
307 }; |
324 }; |
308 } |
325 } |
309 |
326 |
|
327 |
|
328 function "defs_by_labels" { |
|
329 param "labels","''"; |
|
330 param "mandatory","'yes'"; |
|
331 param "hmi_element"; |
|
332 foreach "str:split($labels)" { |
|
333 const "name","."; |
|
334 const "elt_id","$hmi_element//*[@inkscape:label=$name][1]/@id"; |
|
335 if "$mandatory='yes' and not($elt_id)" error > Meter widget must have a «$name» element |
|
336 | «$name»_elt: document.getElementById("«$elt_id»"), |
|
337 } |
|
338 } |
|
339 |
|
340 |
310 template "widget[@type='Display']", mode="widget_defs" { |
341 template "widget[@type='Display']", mode="widget_defs" { |
311 param "hmi_element"; |
342 param "hmi_element"; |
312 | frequency: 5, |
343 | frequency: 5, |
313 | dispatch: function(value) { |
344 | dispatch: function(value) { |
314 choose { |
345 choose { |
324 |
355 |
325 } |
356 } |
326 template "widget[@type='Meter']", mode="widget_defs" { |
357 template "widget[@type='Meter']", mode="widget_defs" { |
327 param "hmi_element"; |
358 param "hmi_element"; |
328 | frequency: 10, |
359 | frequency: 10, |
329 foreach "str:split('value min max needle range')" { |
360 labels("value min max needle range"); |
330 const "name","."; |
|
331 const "elt_id","$hmi_element//*[@inkscape:label=$name][1]/@id"; |
|
332 if "not($elt_id)" error > Meter widget must have a «$name» element |
|
333 | «$name»_elt: document.getElementById("«$elt_id»"), |
|
334 } |
|
335 | dispatch: function(value) { |
361 | dispatch: function(value) { |
336 | this.value_elt.textContent = String(value); |
362 | this.value_elt.textContent = String(value); |
337 | let [min,max,totallength] = this.range; |
363 | let [min,max,totallength] = this.range; |
338 | let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); |
364 | let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); |
339 | let tip = this.range_elt.getPointAtLength(length); |
365 | let tip = this.range_elt.getPointAtLength(length); |
348 } |
374 } |
349 |
375 |
350 template "widget[@type='Input']", mode="widget_defs" { |
376 template "widget[@type='Input']", mode="widget_defs" { |
351 param "hmi_element"; |
377 param "hmi_element"; |
352 | frequency: 5, |
378 | frequency: 5, |
353 const "value_elt_id","$hmi_element//*[self::svg:text][@inkscape:label='value'][1]/@id"; |
379 labels("value"); |
354 if "not($value_elt_id)" error > Input widget must have a text element |
|
355 | value_elt: document.getElementById("«$value_elt_id»"), |
|
356 | dispatch: function(value) { |
380 | dispatch: function(value) { |
357 | this.value_elt.textContent = String(value); |
381 | this.value_elt.textContent = String(value); |
358 | }, |
382 | }, |
359 const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id"; |
383 const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id"; |
360 | init: function() { |
384 | init: function() { |
376 } |
400 } |
377 template "widget[@type='Toggle']", mode="widget_defs" { |
401 template "widget[@type='Toggle']", mode="widget_defs" { |
378 | frequency: 5, |
402 | frequency: 5, |
379 } |
403 } |
380 template "widget[@type='Change']", mode="widget_defs" { |
404 template "widget[@type='Change']", mode="widget_defs" { |
381 // HMI:Change:-10@/PUMP/VALUE |
|
382 // HMI:Change:+1@/PUMP/VALUE |
|
383 // HMI:Change:=42@/PUMP/VALUE |
|
384 | frequency: 5, |
405 | frequency: 5, |
385 } |
406 } |
386 // | frequency: 10`apply ".", mode="refresh_frequency"`, |
407 template "widget[@type='Jump']", mode="widget_defs" { |
387 // template "widget", mode="refresh_frequency" > 10 |
408 | init: function() { |
388 /* |
409 | this.element.addEventListener( |
389 template "widget[@type='Meter']", mode="refresh_frequency" > 10 |
410 | "click", |
390 template "widget[@type='Display']", mode="refresh_frequency" > 5 |
411 | evt => switch_page(this.args[0])); |
391 template "widget[@type='Input']", mode="refresh_frequency" > 5 |
412 | }, |
392 */ |
413 } |
393 } |
414 } |