35 <noindex> |
12 <noindex> |
36 <xsl:text>HMI_CURRENT_PAGE</xsl:text> |
13 <xsl:text>HMI_CURRENT_PAGE</xsl:text> |
37 </noindex> |
14 </noindex> |
38 </xsl:variable> |
15 </xsl:variable> |
39 <xsl:variable name="categories" select="exsl:node-set($_categories)"/> |
16 <xsl:variable name="categories" select="exsl:node-set($_categories)"/> |
40 <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/> |
|
41 <xsl:template name="debug_geometry"> |
|
42 <xsl:text>ID, x, y, w, h |
|
43 </xsl:text> |
|
44 <xsl:for-each select="$geometry[@Id = $hmi_elements/@id]"> |
|
45 <xsl:text> </xsl:text> |
|
46 <xsl:value-of select="@Id"/> |
|
47 <xsl:text> </xsl:text> |
|
48 <xsl:value-of select="@x"/> |
|
49 <xsl:text> </xsl:text> |
|
50 <xsl:value-of select="@y"/> |
|
51 <xsl:text> </xsl:text> |
|
52 <xsl:value-of select="@w"/> |
|
53 <xsl:text> </xsl:text> |
|
54 <xsl:value-of select="@h"/> |
|
55 <xsl:text> |
|
56 </xsl:text> |
|
57 </xsl:for-each> |
|
58 </xsl:template> |
|
59 <func:function name="func:intersect_1d"> |
|
60 <xsl:param name="a0"/> |
|
61 <xsl:param name="a1"/> |
|
62 <xsl:param name="b0"/> |
|
63 <xsl:param name="b1"/> |
|
64 <xsl:variable name="d0" select="$a0 >= $b0"/> |
|
65 <xsl:variable name="d1" select="$a1 >= $b1"/> |
|
66 <xsl:choose> |
|
67 <xsl:when test="not($d0) and $d1"> |
|
68 <func:result select="3"/> |
|
69 </xsl:when> |
|
70 <xsl:when test="$d0 and not($d1)"> |
|
71 <func:result select="2"/> |
|
72 </xsl:when> |
|
73 <xsl:when test="$d0 and $d1 and $a0 < $b1"> |
|
74 <func:result select="1"/> |
|
75 </xsl:when> |
|
76 <xsl:when test="not($d0) and not($d1) and $b0 < $a1"> |
|
77 <func:result select="1"/> |
|
78 </xsl:when> |
|
79 <xsl:otherwise> |
|
80 <func:result select="0"/> |
|
81 </xsl:otherwise> |
|
82 </xsl:choose> |
|
83 </func:function> |
|
84 <func:function name="func:intersect"> |
|
85 <xsl:param name="a"/> |
|
86 <xsl:param name="b"/> |
|
87 <xsl:variable name="x_intersect" select="func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)"/> |
|
88 <xsl:choose> |
|
89 <xsl:when test="$x_intersect != 0"> |
|
90 <xsl:variable name="y_intersect" select="func:intersect_1d($a/@y, $a/@y+$a/@h, $b/@y, $b/@y+$b/@h)"/> |
|
91 <func:result select="$x_intersect * $y_intersect"/> |
|
92 </xsl:when> |
|
93 <xsl:otherwise> |
|
94 <func:result select="0"/> |
|
95 </xsl:otherwise> |
|
96 </xsl:choose> |
|
97 </func:function> |
|
98 <func:function name="func:overlapping_geometry"> |
|
99 <xsl:param name="elt"/> |
|
100 <xsl:variable name="groups" select="/svg:svg | //svg:g"/> |
|
101 <xsl:variable name="g" select="$geometry[@Id = $elt/@id]"/> |
|
102 <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/> |
|
103 <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or (not(@Id = $groups/@id) and (func:intersect($g, .) > 0 ))]"/> |
|
104 </func:function> |
|
105 <func:function name="func:refered_elements"> |
|
106 <xsl:param name="elems"/> |
|
107 <xsl:variable name="descend" select="$elems/descendant-or-self::svg:*"/> |
|
108 <xsl:variable name="clones" select="$descend[self::svg:use]"/> |
|
109 <xsl:variable name="originals" select="//svg:*[concat('#',@id) = $clones/@xlink:href]"/> |
|
110 <xsl:choose> |
|
111 <xsl:when test="$originals"> |
|
112 <func:result select="$descend | func:refered_elements($originals)"/> |
|
113 </xsl:when> |
|
114 <xsl:otherwise> |
|
115 <func:result select="$descend"/> |
|
116 </xsl:otherwise> |
|
117 </xsl:choose> |
|
118 </func:function> |
|
119 <func:function name="func:all_related_elements"> |
|
120 <xsl:param name="page"/> |
|
121 <xsl:variable name="page_overlapping_geometry" select="func:overlapping_geometry($page)"/> |
|
122 <xsl:variable name="page_overlapping_elements" select="//svg:*[@id = $page_overlapping_geometry/@Id]"/> |
|
123 <xsl:variable name="page_sub_elements" select="func:refered_elements($page | $page_overlapping_elements)"/> |
|
124 <func:result select="$page_sub_elements"/> |
|
125 </func:function> |
|
126 <func:function name="func:required_elements"> |
|
127 <xsl:param name="pages"/> |
|
128 <xsl:choose> |
|
129 <xsl:when test="$pages"> |
|
130 <func:result select="func:all_related_elements($pages[1]) | func:required_elements($pages[position()!=1])"/> |
|
131 </xsl:when> |
|
132 <xsl:otherwise> |
|
133 <func:result select="/.."/> |
|
134 </xsl:otherwise> |
|
135 </xsl:choose> |
|
136 </func:function> |
|
137 <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:* | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/> |
|
138 <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/> |
|
139 <func:function name="func:sumarized_elements"> |
|
140 <xsl:param name="elements"/> |
|
141 <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/> |
|
142 <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[ not(descendant::*[ not(self::svg:g) and not(@id = $discardable_elements/@id) and not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id) ])]"/> |
|
143 <xsl:variable name="groups_to_add" select="$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"/> |
|
144 <func:result select="$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]"/> |
|
145 </func:function> |
|
146 <func:function name="func:detachable_elements"> |
|
147 <xsl:param name="pages"/> |
|
148 <xsl:choose> |
|
149 <xsl:when test="$pages"> |
|
150 <func:result select="func:sumarized_elements(func:all_related_elements($pages[1])) | func:detachable_elements($pages[position()!=1])"/> |
|
151 </xsl:when> |
|
152 <xsl:otherwise> |
|
153 <func:result select="/.."/> |
|
154 </xsl:otherwise> |
|
155 </xsl:choose> |
|
156 </func:function> |
|
157 <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages)"/> |
|
158 <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/> |
|
159 <xsl:template name="debug_detachables"> |
|
160 <xsl:for-each select="$detachable_elements"> |
|
161 <xsl:text> </xsl:text> |
|
162 <xsl:value-of select="@id"/> |
|
163 <xsl:text> |
|
164 </xsl:text> |
|
165 </xsl:for-each> |
|
166 </xsl:template> |
|
167 <xsl:variable name="hmitree" select="ns:GetHMITree()"/> |
|
168 <xsl:variable name="_indexed_hmitree"> |
17 <xsl:variable name="_indexed_hmitree"> |
169 <xsl:apply-templates mode="index" select="$hmitree"/> |
18 <xsl:apply-templates mode="index" select="$hmitree"/> |
170 </xsl:variable> |
19 </xsl:variable> |
171 <xsl:variable name="indexed_hmitree" select="exsl:node-set($_indexed_hmitree)"/> |
20 <xsl:variable name="indexed_hmitree" select="exsl:node-set($_indexed_hmitree)"/> |
172 <xsl:template mode="index" match="*"> |
21 <xsl:template mode="index" match="*"> |
220 <xsl:with-param name="index" select="$index + count(exsl:node-set($content)/*)"/> |
69 <xsl:with-param name="index" select="$index + count(exsl:node-set($content)/*)"/> |
221 <xsl:with-param name="parentpath"> |
70 <xsl:with-param name="parentpath"> |
222 <xsl:value-of select="$parentpath"/> |
71 <xsl:value-of select="$parentpath"/> |
223 </xsl:with-param> |
72 </xsl:with-param> |
224 </xsl:apply-templates> |
73 </xsl:apply-templates> |
225 </xsl:template> |
|
226 <xsl:template mode="testtree" match="*"> |
|
227 <xsl:param name="indent" select="''"/> |
|
228 <xsl:value-of select="$indent"/> |
|
229 <xsl:text> </xsl:text> |
|
230 <xsl:value-of select="local-name()"/> |
|
231 <xsl:text> </xsl:text> |
|
232 <xsl:for-each select="@*"> |
|
233 <xsl:value-of select="local-name()"/> |
|
234 <xsl:text>="</xsl:text> |
|
235 <xsl:value-of select="."/> |
|
236 <xsl:text>" </xsl:text> |
|
237 </xsl:for-each> |
|
238 <xsl:text> |
|
239 </xsl:text> |
|
240 <xsl:apply-templates mode="testtree" select="*"> |
|
241 <xsl:with-param name="indent"> |
|
242 <xsl:value-of select="concat($indent,'>')"/> |
|
243 </xsl:with-param> |
|
244 </xsl:apply-templates> |
|
245 </xsl:template> |
|
246 <xsl:template name="debug_hmitree"> |
|
247 <xsl:text>Raw HMI tree |
|
248 </xsl:text> |
|
249 <xsl:apply-templates mode="testtree" select="$hmitree"/> |
|
250 <xsl:text> |
|
251 </xsl:text> |
|
252 <xsl:text>Indexed HMI tree |
|
253 </xsl:text> |
|
254 <xsl:apply-templates mode="testtree" select="$indexed_hmitree"/> |
|
255 </xsl:template> |
|
256 <func:function name="func:is_descendant_path"> |
|
257 <xsl:param name="descend"/> |
|
258 <xsl:param name="ancest"/> |
|
259 <func:result select="string-length($ancest) > 0 and starts-with($descend,$ancest)"/> |
|
260 </func:function> |
|
261 <xsl:template mode="inline_svg" match="@* | node()"> |
|
262 <xsl:if test="not(@id = $discardable_elements/@id)"> |
|
263 <xsl:copy> |
|
264 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
265 </xsl:copy> |
|
266 </xsl:if> |
|
267 </xsl:template> |
|
268 <xsl:template mode="inline_svg" match="svg:svg/@width"/> |
|
269 <xsl:template mode="inline_svg" match="svg:svg/@height"/> |
|
270 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:svg"> |
|
271 <svg> |
|
272 <xsl:attribute name="preserveAspectRatio"> |
|
273 <xsl:text>none</xsl:text> |
|
274 </xsl:attribute> |
|
275 <xsl:attribute name="height"> |
|
276 <xsl:text>100vh</xsl:text> |
|
277 </xsl:attribute> |
|
278 <xsl:attribute name="width"> |
|
279 <xsl:text>100vw</xsl:text> |
|
280 </xsl:attribute> |
|
281 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
282 </svg> |
|
283 </xsl:template> |
|
284 <xsl:template mode="inline_svg" match="svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]"> |
|
285 <xsl:message terminate="yes"> |
|
286 <xsl:text>ViewBox settings other than X=0, Y=0 and Scale=1 are not supported</xsl:text> |
|
287 </xsl:message> |
|
288 </xsl:template> |
|
289 <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']"> |
|
290 <xsl:message terminate="yes"> |
|
291 <xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text> |
|
292 </xsl:message> |
|
293 </xsl:template> |
|
294 <xsl:variable name="to_unlink" select="$hmi_elements[not(@id = $hmi_pages)]//svg:use"/> |
|
295 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:use"> |
|
296 <xsl:choose> |
|
297 <xsl:when test="@id = $to_unlink/@id"> |
|
298 <xsl:call-template name="unlink_clone"/> |
|
299 </xsl:when> |
|
300 <xsl:otherwise> |
|
301 <xsl:copy> |
|
302 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
303 </xsl:copy> |
|
304 </xsl:otherwise> |
|
305 </xsl:choose> |
|
306 </xsl:template> |
|
307 <xsl:variable name="_excluded_use_attrs"> |
|
308 <name> |
|
309 <xsl:text>href</xsl:text> |
|
310 </name> |
|
311 <name> |
|
312 <xsl:text>width</xsl:text> |
|
313 </name> |
|
314 <name> |
|
315 <xsl:text>height</xsl:text> |
|
316 </name> |
|
317 <name> |
|
318 <xsl:text>x</xsl:text> |
|
319 </name> |
|
320 <name> |
|
321 <xsl:text>y</xsl:text> |
|
322 </name> |
|
323 </xsl:variable> |
|
324 <xsl:variable name="excluded_use_attrs" select="exsl:node-set($_excluded_use_attrs)"/> |
|
325 <xsl:template xmlns="http://www.w3.org/2000/svg" name="unlink_clone"> |
|
326 <g> |
|
327 <xsl:for-each select="@*[not(local-name() = $excluded_use_attrs/name)]"> |
|
328 <xsl:attribute name="{name()}"> |
|
329 <xsl:value-of select="."/> |
|
330 </xsl:attribute> |
|
331 </xsl:for-each> |
|
332 <xsl:variable name="targetid" select="substring-after(@xlink:href,'#')"/> |
|
333 <xsl:apply-templates mode="unlink_clone" select="//svg:*[@id = $targetid]"> |
|
334 <xsl:with-param name="seed" select="@id"/> |
|
335 </xsl:apply-templates> |
|
336 </g> |
|
337 </xsl:template> |
|
338 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="@id"> |
|
339 <xsl:param name="seed"/> |
|
340 <xsl:attribute name="id"> |
|
341 <xsl:value-of select="$seed"/> |
|
342 <xsl:text>_</xsl:text> |
|
343 <xsl:value-of select="."/> |
|
344 </xsl:attribute> |
|
345 </xsl:template> |
|
346 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="@*"> |
|
347 <xsl:copy/> |
|
348 </xsl:template> |
|
349 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="svg:*"> |
|
350 <xsl:param name="seed"/> |
|
351 <xsl:choose> |
|
352 <xsl:when test="@id = $hmi_elements/@id"> |
|
353 <use> |
|
354 <xsl:attribute name="xlink:href"> |
|
355 <xsl:value-of select="concat('#',@id)"/> |
|
356 </xsl:attribute> |
|
357 </use> |
|
358 </xsl:when> |
|
359 <xsl:otherwise> |
|
360 <xsl:copy> |
|
361 <xsl:apply-templates mode="unlink_clone" select="@* | node()"> |
|
362 <xsl:with-param name="seed" select="$seed"/> |
|
363 </xsl:apply-templates> |
|
364 </xsl:copy> |
|
365 </xsl:otherwise> |
|
366 </xsl:choose> |
|
367 </xsl:template> |
|
368 <xsl:variable name="result_svg"> |
|
369 <xsl:apply-templates mode="inline_svg" select="/"/> |
|
370 </xsl:variable> |
|
371 <xsl:variable name="result_svg_ns" select="exsl:node-set($result_svg)"/> |
|
372 <xsl:template match="/"> |
|
373 <xsl:comment> |
|
374 <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text> |
|
375 </xsl:comment> |
|
376 <xsl:comment> |
|
377 <xsl:text> |
|
378 </xsl:text> |
|
379 <xsl:text>debug_geometry: |
|
380 </xsl:text> |
|
381 <xsl:call-template name="debug_geometry"/> |
|
382 <xsl:text> |
|
383 </xsl:text> |
|
384 </xsl:comment> |
|
385 <xsl:comment> |
|
386 <xsl:text> |
|
387 </xsl:text> |
|
388 <xsl:text>debug_detachables: |
|
389 </xsl:text> |
|
390 <xsl:call-template name="debug_detachables"/> |
|
391 <xsl:text> |
|
392 </xsl:text> |
|
393 </xsl:comment> |
|
394 <xsl:comment> |
|
395 <xsl:text> |
|
396 </xsl:text> |
|
397 <xsl:text>debug_hmitree: |
|
398 </xsl:text> |
|
399 <xsl:call-template name="debug_hmitree"/> |
|
400 <xsl:text> |
|
401 </xsl:text> |
|
402 </xsl:comment> |
|
403 <xsl:comment> |
|
404 <xsl:text>Unlinked : |
|
405 </xsl:text> |
|
406 <xsl:for-each select="$to_unlink"> |
|
407 <xsl:value-of select="@id"/> |
|
408 <xsl:text> |
|
409 </xsl:text> |
|
410 </xsl:for-each> |
|
411 </xsl:comment> |
|
412 <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml"> |
|
413 <head/> |
|
414 <body style="margin:0;overflow:hidden;"> |
|
415 <xsl:copy-of select="$result_svg"/> |
|
416 <script> |
|
417 <xsl:call-template name="scripts"/> |
|
418 </script> |
|
419 </body> |
|
420 </html> |
|
421 </xsl:template> |
74 </xsl:template> |
422 <func:function name="func:parselabel"> |
75 <func:function name="func:parselabel"> |
423 <xsl:param name="label"/> |
76 <xsl:param name="label"/> |
424 <xsl:variable name="description" select="substring-after($label,'HMI:')"/> |
77 <xsl:variable name="description" select="substring-after($label,'HMI:')"/> |
425 <xsl:variable name="_args" select="substring-before($description,'@')"/> |
78 <xsl:variable name="_args" select="substring-before($description,'@')"/> |
477 </widget> |
130 </widget> |
478 </xsl:if> |
131 </xsl:if> |
479 </xsl:variable> |
132 </xsl:variable> |
480 <func:result select="exsl:node-set($ast)"/> |
133 <func:result select="exsl:node-set($ast)"/> |
481 </func:function> |
134 </func:function> |
|
135 <xsl:template mode="testtree" match="*"> |
|
136 <xsl:param name="indent" select="''"/> |
|
137 <xsl:value-of select="$indent"/> |
|
138 <xsl:text> </xsl:text> |
|
139 <xsl:value-of select="local-name()"/> |
|
140 <xsl:text> </xsl:text> |
|
141 <xsl:for-each select="@*"> |
|
142 <xsl:value-of select="local-name()"/> |
|
143 <xsl:text>="</xsl:text> |
|
144 <xsl:value-of select="."/> |
|
145 <xsl:text>" </xsl:text> |
|
146 </xsl:for-each> |
|
147 <xsl:text> |
|
148 </xsl:text> |
|
149 <xsl:apply-templates mode="testtree" select="*"> |
|
150 <xsl:with-param name="indent"> |
|
151 <xsl:value-of select="concat($indent,'>')"/> |
|
152 </xsl:with-param> |
|
153 </xsl:apply-templates> |
|
154 </xsl:template> |
|
155 <xsl:template name="debug_hmitree"> |
|
156 <xsl:text>Raw HMI tree |
|
157 </xsl:text> |
|
158 <xsl:apply-templates mode="testtree" select="$hmitree"/> |
|
159 <xsl:text> |
|
160 </xsl:text> |
|
161 <xsl:text>Indexed HMI tree |
|
162 </xsl:text> |
|
163 <xsl:apply-templates mode="testtree" select="$indexed_hmitree"/> |
|
164 </xsl:template> |
|
165 <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/> |
|
166 <xsl:template name="debug_geometry"> |
|
167 <xsl:text>ID, x, y, w, h |
|
168 </xsl:text> |
|
169 <xsl:for-each select="$geometry[@Id = $hmi_elements/@id]"> |
|
170 <xsl:text> </xsl:text> |
|
171 <xsl:value-of select="@Id"/> |
|
172 <xsl:text> </xsl:text> |
|
173 <xsl:value-of select="@x"/> |
|
174 <xsl:text> </xsl:text> |
|
175 <xsl:value-of select="@y"/> |
|
176 <xsl:text> </xsl:text> |
|
177 <xsl:value-of select="@w"/> |
|
178 <xsl:text> </xsl:text> |
|
179 <xsl:value-of select="@h"/> |
|
180 <xsl:text> |
|
181 </xsl:text> |
|
182 </xsl:for-each> |
|
183 </xsl:template> |
|
184 <func:function name="func:intersect_1d"> |
|
185 <xsl:param name="a0"/> |
|
186 <xsl:param name="a1"/> |
|
187 <xsl:param name="b0"/> |
|
188 <xsl:param name="b1"/> |
|
189 <xsl:variable name="d0" select="$a0 >= $b0"/> |
|
190 <xsl:variable name="d1" select="$a1 >= $b1"/> |
|
191 <xsl:choose> |
|
192 <xsl:when test="not($d0) and $d1"> |
|
193 <func:result select="3"/> |
|
194 </xsl:when> |
|
195 <xsl:when test="$d0 and not($d1)"> |
|
196 <func:result select="2"/> |
|
197 </xsl:when> |
|
198 <xsl:when test="$d0 and $d1 and $a0 < $b1"> |
|
199 <func:result select="1"/> |
|
200 </xsl:when> |
|
201 <xsl:when test="not($d0) and not($d1) and $b0 < $a1"> |
|
202 <func:result select="1"/> |
|
203 </xsl:when> |
|
204 <xsl:otherwise> |
|
205 <func:result select="0"/> |
|
206 </xsl:otherwise> |
|
207 </xsl:choose> |
|
208 </func:function> |
|
209 <func:function name="func:intersect"> |
|
210 <xsl:param name="a"/> |
|
211 <xsl:param name="b"/> |
|
212 <xsl:variable name="x_intersect" select="func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)"/> |
|
213 <xsl:choose> |
|
214 <xsl:when test="$x_intersect != 0"> |
|
215 <xsl:variable name="y_intersect" select="func:intersect_1d($a/@y, $a/@y+$a/@h, $b/@y, $b/@y+$b/@h)"/> |
|
216 <func:result select="$x_intersect * $y_intersect"/> |
|
217 </xsl:when> |
|
218 <xsl:otherwise> |
|
219 <func:result select="0"/> |
|
220 </xsl:otherwise> |
|
221 </xsl:choose> |
|
222 </func:function> |
|
223 <func:function name="func:overlapping_geometry"> |
|
224 <xsl:param name="elt"/> |
|
225 <xsl:variable name="groups" select="/svg:svg | //svg:g"/> |
|
226 <xsl:variable name="g" select="$geometry[@Id = $elt/@id]"/> |
|
227 <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/> |
|
228 <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or (not(@Id = $groups/@id) and (func:intersect($g, .) > 0 ))]"/> |
|
229 </func:function> |
|
230 <xsl:variable name="svg_root_id" select="/svg:svg/@id"/> |
|
231 <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/> |
|
232 <xsl:variable name="hmi_pages" select="$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"/> |
|
233 <xsl:variable name="default_page"> |
|
234 <xsl:choose> |
|
235 <xsl:when test="count($hmi_pages) > 1"> |
|
236 <xsl:variable name="Home_page" select="$hmi_pages[func:parselabel(@inkscape:label)/widget/arg[1]/@value = 'Home']"/> |
|
237 <xsl:choose> |
|
238 <xsl:when test="$Home_page"> |
|
239 <xsl:text>Home</xsl:text> |
|
240 </xsl:when> |
|
241 <xsl:otherwise> |
|
242 <xsl:message terminate="yes">No Home page defined!</xsl:message> |
|
243 </xsl:otherwise> |
|
244 </xsl:choose> |
|
245 </xsl:when> |
|
246 <xsl:when test="count($hmi_pages) = 0"> |
|
247 <xsl:message terminate="yes">No page defined!</xsl:message> |
|
248 </xsl:when> |
|
249 <xsl:otherwise> |
|
250 <xsl:value-of select="func:parselabel($hmi_pages/@inkscape:label)/widget/arg[1]/@value"/> |
|
251 </xsl:otherwise> |
|
252 </xsl:choose> |
|
253 </xsl:variable> |
|
254 <func:function name="func:refered_elements"> |
|
255 <xsl:param name="elems"/> |
|
256 <xsl:variable name="descend" select="$elems/descendant-or-self::svg:*"/> |
|
257 <xsl:variable name="clones" select="$descend[self::svg:use]"/> |
|
258 <xsl:variable name="originals" select="//svg:*[concat('#',@id) = $clones/@xlink:href]"/> |
|
259 <xsl:choose> |
|
260 <xsl:when test="$originals"> |
|
261 <func:result select="$descend | func:refered_elements($originals)"/> |
|
262 </xsl:when> |
|
263 <xsl:otherwise> |
|
264 <func:result select="$descend"/> |
|
265 </xsl:otherwise> |
|
266 </xsl:choose> |
|
267 </func:function> |
|
268 <func:function name="func:all_related_elements"> |
|
269 <xsl:param name="page"/> |
|
270 <xsl:variable name="page_overlapping_geometry" select="func:overlapping_geometry($page)"/> |
|
271 <xsl:variable name="page_overlapping_elements" select="//svg:*[@id = $page_overlapping_geometry/@Id]"/> |
|
272 <xsl:variable name="page_sub_elements" select="func:refered_elements($page | $page_overlapping_elements)"/> |
|
273 <func:result select="$page_sub_elements"/> |
|
274 </func:function> |
|
275 <func:function name="func:required_elements"> |
|
276 <xsl:param name="pages"/> |
|
277 <xsl:choose> |
|
278 <xsl:when test="$pages"> |
|
279 <func:result select="func:all_related_elements($pages[1]) | func:required_elements($pages[position()!=1])"/> |
|
280 </xsl:when> |
|
281 <xsl:otherwise> |
|
282 <func:result select="/.."/> |
|
283 </xsl:otherwise> |
|
284 </xsl:choose> |
|
285 </func:function> |
|
286 <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:* | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/> |
|
287 <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/> |
|
288 <func:function name="func:sumarized_elements"> |
|
289 <xsl:param name="elements"/> |
|
290 <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/> |
|
291 <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[ not(descendant::*[ not(self::svg:g) and not(@id = $discardable_elements/@id) and not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id) ])]"/> |
|
292 <xsl:variable name="groups_to_add" select="$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"/> |
|
293 <func:result select="$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]"/> |
|
294 </func:function> |
|
295 <func:function name="func:detachable_elements"> |
|
296 <xsl:param name="pages"/> |
|
297 <xsl:choose> |
|
298 <xsl:when test="$pages"> |
|
299 <func:result select="func:sumarized_elements(func:all_related_elements($pages[1])) | func:detachable_elements($pages[position()!=1])"/> |
|
300 </xsl:when> |
|
301 <xsl:otherwise> |
|
302 <func:result select="/.."/> |
|
303 </xsl:otherwise> |
|
304 </xsl:choose> |
|
305 </func:function> |
|
306 <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages)"/> |
|
307 <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/> |
|
308 <func:function name="func:is_descendant_path"> |
|
309 <xsl:param name="descend"/> |
|
310 <xsl:param name="ancest"/> |
|
311 <func:result select="string-length($ancest) > 0 and starts-with($descend,$ancest)"/> |
|
312 </func:function> |
|
313 <xsl:template mode="page_desc" match="svg:*"> |
|
314 <xsl:variable name="desc" select="func:parselabel(@inkscape:label)/widget"/> |
|
315 <xsl:variable name="page" select="."/> |
|
316 <xsl:variable name="p" select="$geometry[@Id = $page/@id]"/> |
|
317 <xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/> |
|
318 <xsl:variable name="all_page_widgets" select="$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]"/> |
|
319 <xsl:variable name="page_relative_widgets" select="$all_page_widgets[func:is_descendant_path(func:parselabel(@inkscape:label)/widget/path/@value, $desc/path/@value)]"/> |
|
320 <xsl:variable name="required_detachables" select="func:sumarized_elements($page_all_elements)/ ancestor-or-self::*[@id = $detachable_elements/@id]"/> |
|
321 <xsl:text> "</xsl:text> |
|
322 <xsl:value-of select="$desc/arg[1]/@value"/> |
|
323 <xsl:text>": { |
|
324 </xsl:text> |
|
325 <xsl:text> widget: hmi_widgets["</xsl:text> |
|
326 <xsl:value-of select="@id"/> |
|
327 <xsl:text>"], |
|
328 </xsl:text> |
|
329 <xsl:text> bbox: [</xsl:text> |
|
330 <xsl:value-of select="$p/@x"/> |
|
331 <xsl:text>, </xsl:text> |
|
332 <xsl:value-of select="$p/@y"/> |
|
333 <xsl:text>, </xsl:text> |
|
334 <xsl:value-of select="$p/@w"/> |
|
335 <xsl:text>, </xsl:text> |
|
336 <xsl:value-of select="$p/@h"/> |
|
337 <xsl:text>], |
|
338 </xsl:text> |
|
339 <xsl:if test="$desc/path/@value"> |
|
340 <xsl:if test="count($desc/path/@index)=0"> |
|
341 <xsl:message terminate="no"> |
|
342 <xsl:text>Page id="</xsl:text> |
|
343 <xsl:value-of select="$page/@id"/> |
|
344 <xsl:text>" : No match for path "</xsl:text> |
|
345 <xsl:value-of select="$desc/path/@value"/> |
|
346 <xsl:text>" in HMI tree</xsl:text> |
|
347 </xsl:message> |
|
348 </xsl:if> |
|
349 <xsl:text> page_index: </xsl:text> |
|
350 <xsl:value-of select="$desc/path/@index"/> |
|
351 <xsl:text>, |
|
352 </xsl:text> |
|
353 </xsl:if> |
|
354 <xsl:text> relative_widgets: [ |
|
355 </xsl:text> |
|
356 <xsl:for-each select="$page_relative_widgets"> |
|
357 <xsl:text> hmi_widgets["</xsl:text> |
|
358 <xsl:value-of select="@id"/> |
|
359 <xsl:text>"]</xsl:text> |
|
360 <xsl:if test="position()!=last()"> |
|
361 <xsl:text>,</xsl:text> |
|
362 </xsl:if> |
|
363 <xsl:text> |
|
364 </xsl:text> |
|
365 </xsl:for-each> |
|
366 <xsl:text> ], |
|
367 </xsl:text> |
|
368 <xsl:text> absolute_widgets: [ |
|
369 </xsl:text> |
|
370 <xsl:for-each select="$all_page_widgets[not(@id = $page_relative_widgets/@id)]"> |
|
371 <xsl:text> hmi_widgets["</xsl:text> |
|
372 <xsl:value-of select="@id"/> |
|
373 <xsl:text>"]</xsl:text> |
|
374 <xsl:if test="position()!=last()"> |
|
375 <xsl:text>,</xsl:text> |
|
376 </xsl:if> |
|
377 <xsl:text> |
|
378 </xsl:text> |
|
379 </xsl:for-each> |
|
380 <xsl:text> ], |
|
381 </xsl:text> |
|
382 <xsl:text> required_detachables: { |
|
383 </xsl:text> |
|
384 <xsl:for-each select="$required_detachables"> |
|
385 <xsl:text> "</xsl:text> |
|
386 <xsl:value-of select="@id"/> |
|
387 <xsl:text>": detachable_elements["</xsl:text> |
|
388 <xsl:value-of select="@id"/> |
|
389 <xsl:text>"]</xsl:text> |
|
390 <xsl:if test="position()!=last()"> |
|
391 <xsl:text>,</xsl:text> |
|
392 </xsl:if> |
|
393 <xsl:text> |
|
394 </xsl:text> |
|
395 </xsl:for-each> |
|
396 <xsl:text> } |
|
397 </xsl:text> |
|
398 <xsl:text> }</xsl:text> |
|
399 <xsl:if test="position()!=last()"> |
|
400 <xsl:text>,</xsl:text> |
|
401 </xsl:if> |
|
402 <xsl:text> |
|
403 </xsl:text> |
|
404 </xsl:template> |
|
405 <xsl:template name="debug_detachables"> |
|
406 <xsl:for-each select="$detachable_elements"> |
|
407 <xsl:text> </xsl:text> |
|
408 <xsl:value-of select="@id"/> |
|
409 <xsl:text> |
|
410 </xsl:text> |
|
411 </xsl:for-each> |
|
412 </xsl:template> |
|
413 <xsl:template mode="inline_svg" match="@* | node()"> |
|
414 <xsl:if test="not(@id = $discardable_elements/@id)"> |
|
415 <xsl:copy> |
|
416 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
417 </xsl:copy> |
|
418 </xsl:if> |
|
419 </xsl:template> |
|
420 <xsl:template mode="inline_svg" match="svg:svg/@width"/> |
|
421 <xsl:template mode="inline_svg" match="svg:svg/@height"/> |
|
422 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:svg"> |
|
423 <svg> |
|
424 <xsl:attribute name="preserveAspectRatio"> |
|
425 <xsl:text>none</xsl:text> |
|
426 </xsl:attribute> |
|
427 <xsl:attribute name="height"> |
|
428 <xsl:text>100vh</xsl:text> |
|
429 </xsl:attribute> |
|
430 <xsl:attribute name="width"> |
|
431 <xsl:text>100vw</xsl:text> |
|
432 </xsl:attribute> |
|
433 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
434 </svg> |
|
435 </xsl:template> |
|
436 <xsl:template mode="inline_svg" match="svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]"> |
|
437 <xsl:message terminate="yes"> |
|
438 <xsl:text>ViewBox settings other than X=0, Y=0 and Scale=1 are not supported</xsl:text> |
|
439 </xsl:message> |
|
440 </xsl:template> |
|
441 <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']"> |
|
442 <xsl:message terminate="yes"> |
|
443 <xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text> |
|
444 </xsl:message> |
|
445 </xsl:template> |
|
446 <xsl:variable name="to_unlink" select="$hmi_elements[not(@id = $hmi_pages)]//svg:use"/> |
|
447 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:use"> |
|
448 <xsl:choose> |
|
449 <xsl:when test="@id = $to_unlink/@id"> |
|
450 <xsl:call-template name="unlink_clone"/> |
|
451 </xsl:when> |
|
452 <xsl:otherwise> |
|
453 <xsl:copy> |
|
454 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
455 </xsl:copy> |
|
456 </xsl:otherwise> |
|
457 </xsl:choose> |
|
458 </xsl:template> |
|
459 <xsl:variable name="_excluded_use_attrs"> |
|
460 <name> |
|
461 <xsl:text>href</xsl:text> |
|
462 </name> |
|
463 <name> |
|
464 <xsl:text>width</xsl:text> |
|
465 </name> |
|
466 <name> |
|
467 <xsl:text>height</xsl:text> |
|
468 </name> |
|
469 <name> |
|
470 <xsl:text>x</xsl:text> |
|
471 </name> |
|
472 <name> |
|
473 <xsl:text>y</xsl:text> |
|
474 </name> |
|
475 </xsl:variable> |
|
476 <xsl:variable name="excluded_use_attrs" select="exsl:node-set($_excluded_use_attrs)"/> |
|
477 <xsl:template xmlns="http://www.w3.org/2000/svg" name="unlink_clone"> |
|
478 <g> |
|
479 <xsl:for-each select="@*[not(local-name() = $excluded_use_attrs/name)]"> |
|
480 <xsl:attribute name="{name()}"> |
|
481 <xsl:value-of select="."/> |
|
482 </xsl:attribute> |
|
483 </xsl:for-each> |
|
484 <xsl:variable name="targetid" select="substring-after(@xlink:href,'#')"/> |
|
485 <xsl:apply-templates mode="unlink_clone" select="//svg:*[@id = $targetid]"> |
|
486 <xsl:with-param name="seed" select="@id"/> |
|
487 </xsl:apply-templates> |
|
488 </g> |
|
489 </xsl:template> |
|
490 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="@id"> |
|
491 <xsl:param name="seed"/> |
|
492 <xsl:attribute name="id"> |
|
493 <xsl:value-of select="$seed"/> |
|
494 <xsl:text>_</xsl:text> |
|
495 <xsl:value-of select="."/> |
|
496 </xsl:attribute> |
|
497 </xsl:template> |
|
498 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="@*"> |
|
499 <xsl:copy/> |
|
500 </xsl:template> |
|
501 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="svg:*"> |
|
502 <xsl:param name="seed"/> |
|
503 <xsl:choose> |
|
504 <xsl:when test="@id = $hmi_elements/@id"> |
|
505 <use> |
|
506 <xsl:attribute name="xlink:href"> |
|
507 <xsl:value-of select="concat('#',@id)"/> |
|
508 </xsl:attribute> |
|
509 </use> |
|
510 </xsl:when> |
|
511 <xsl:otherwise> |
|
512 <xsl:copy> |
|
513 <xsl:apply-templates mode="unlink_clone" select="@* | node()"> |
|
514 <xsl:with-param name="seed" select="$seed"/> |
|
515 </xsl:apply-templates> |
|
516 </xsl:copy> |
|
517 </xsl:otherwise> |
|
518 </xsl:choose> |
|
519 </xsl:template> |
|
520 <xsl:variable name="result_svg"> |
|
521 <xsl:apply-templates mode="inline_svg" select="/"/> |
|
522 </xsl:variable> |
|
523 <xsl:variable name="result_svg_ns" select="exsl:node-set($result_svg)"/> |
|
524 <xsl:template match="/"> |
|
525 <xsl:comment> |
|
526 <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text> |
|
527 </xsl:comment> |
|
528 <xsl:comment> |
|
529 <xsl:text> |
|
530 </xsl:text> |
|
531 <xsl:text>debug_hmitree: |
|
532 </xsl:text> |
|
533 <xsl:call-template name="debug_hmitree"/> |
|
534 <xsl:text> |
|
535 </xsl:text> |
|
536 </xsl:comment> |
|
537 <xsl:comment> |
|
538 <xsl:text> |
|
539 </xsl:text> |
|
540 <xsl:text>debug_geometry: |
|
541 </xsl:text> |
|
542 <xsl:call-template name="debug_geometry"/> |
|
543 <xsl:text> |
|
544 </xsl:text> |
|
545 </xsl:comment> |
|
546 <xsl:comment> |
|
547 <xsl:text> |
|
548 </xsl:text> |
|
549 <xsl:text>debug_detachables: |
|
550 </xsl:text> |
|
551 <xsl:call-template name="debug_detachables"/> |
|
552 <xsl:text> |
|
553 </xsl:text> |
|
554 </xsl:comment> |
|
555 <xsl:comment> |
|
556 <xsl:text>Unlinked : |
|
557 </xsl:text> |
|
558 <xsl:for-each select="$to_unlink"> |
|
559 <xsl:value-of select="@id"/> |
|
560 <xsl:text> |
|
561 </xsl:text> |
|
562 </xsl:for-each> |
|
563 </xsl:comment> |
|
564 <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml"> |
|
565 <head/> |
|
566 <body style="margin:0;overflow:hidden;"> |
|
567 <xsl:copy-of select="$result_svg"/> |
|
568 <script> |
|
569 <xsl:call-template name="scripts"/> |
|
570 </script> |
|
571 </body> |
|
572 </html> |
|
573 </xsl:template> |
482 <xsl:template name="scripts"> |
574 <xsl:template name="scripts"> |
483 <xsl:text>//(function(){ |
575 <xsl:text>//(function(){ |
484 </xsl:text> |
576 </xsl:text> |
485 <xsl:text> |
577 <xsl:text> |
486 </xsl:text> |
578 </xsl:text> |
611 </xsl:text> |
703 </xsl:text> |
612 <xsl:text> |
704 <xsl:text> |
613 </xsl:text> |
705 </xsl:text> |
614 <xsl:text>var page_desc = { |
706 <xsl:text>var page_desc = { |
615 </xsl:text> |
707 </xsl:text> |
616 <xsl:for-each select="$hmi_pages"> |
708 <xsl:apply-templates mode="page_desc" select="$hmi_pages"/> |
617 <xsl:variable name="desc" select="func:parselabel(@inkscape:label)/widget"/> |
|
618 <xsl:variable name="page" select="."/> |
|
619 <xsl:variable name="p" select="$geometry[@Id = $page/@id]"/> |
|
620 <xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/> |
|
621 <xsl:variable name="all_page_widgets" select="$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]"/> |
|
622 <xsl:variable name="page_relative_widgets" select="$all_page_widgets[func:is_descendant_path(func:parselabel(@inkscape:label)/widget/path/@value, $desc/path/@value)]"/> |
|
623 <xsl:variable name="required_detachables" select="func:sumarized_elements($page_all_elements)/ ancestor-or-self::*[@id = $detachable_elements/@id]"/> |
|
624 <xsl:text> "</xsl:text> |
|
625 <xsl:value-of select="$desc/arg[1]/@value"/> |
|
626 <xsl:text>": { |
|
627 </xsl:text> |
|
628 <xsl:text> widget: hmi_widgets["</xsl:text> |
|
629 <xsl:value-of select="@id"/> |
|
630 <xsl:text>"], |
|
631 </xsl:text> |
|
632 <xsl:text> bbox: [</xsl:text> |
|
633 <xsl:value-of select="$p/@x"/> |
|
634 <xsl:text>, </xsl:text> |
|
635 <xsl:value-of select="$p/@y"/> |
|
636 <xsl:text>, </xsl:text> |
|
637 <xsl:value-of select="$p/@w"/> |
|
638 <xsl:text>, </xsl:text> |
|
639 <xsl:value-of select="$p/@h"/> |
|
640 <xsl:text>], |
|
641 </xsl:text> |
|
642 <xsl:if test="$desc/path/@value"> |
|
643 <xsl:if test="count($desc/path/@index)=0"> |
|
644 <xsl:message terminate="no"> |
|
645 <xsl:text>Page id="</xsl:text> |
|
646 <xsl:value-of select="$page/@id"/> |
|
647 <xsl:text>" : No match for path "</xsl:text> |
|
648 <xsl:value-of select="$desc/path/@value"/> |
|
649 <xsl:text>" in HMI tree</xsl:text> |
|
650 </xsl:message> |
|
651 </xsl:if> |
|
652 <xsl:text> page_index: </xsl:text> |
|
653 <xsl:value-of select="$desc/path/@index"/> |
|
654 <xsl:text>, |
|
655 </xsl:text> |
|
656 </xsl:if> |
|
657 <xsl:text> relative_widgets: [ |
|
658 </xsl:text> |
|
659 <xsl:for-each select="$page_relative_widgets"> |
|
660 <xsl:text> hmi_widgets["</xsl:text> |
|
661 <xsl:value-of select="@id"/> |
|
662 <xsl:text>"]</xsl:text> |
|
663 <xsl:if test="position()!=last()"> |
|
664 <xsl:text>,</xsl:text> |
|
665 </xsl:if> |
|
666 <xsl:text> |
|
667 </xsl:text> |
|
668 </xsl:for-each> |
|
669 <xsl:text> ], |
|
670 </xsl:text> |
|
671 <xsl:text> absolute_widgets: [ |
|
672 </xsl:text> |
|
673 <xsl:for-each select="$all_page_widgets[not(@id = $page_relative_widgets/@id)]"> |
|
674 <xsl:text> hmi_widgets["</xsl:text> |
|
675 <xsl:value-of select="@id"/> |
|
676 <xsl:text>"]</xsl:text> |
|
677 <xsl:if test="position()!=last()"> |
|
678 <xsl:text>,</xsl:text> |
|
679 </xsl:if> |
|
680 <xsl:text> |
|
681 </xsl:text> |
|
682 </xsl:for-each> |
|
683 <xsl:text> ], |
|
684 </xsl:text> |
|
685 <xsl:text> required_detachables: { |
|
686 </xsl:text> |
|
687 <xsl:for-each select="$required_detachables"> |
|
688 <xsl:text> "</xsl:text> |
|
689 <xsl:value-of select="@id"/> |
|
690 <xsl:text>": detachable_elements["</xsl:text> |
|
691 <xsl:value-of select="@id"/> |
|
692 <xsl:text>"]</xsl:text> |
|
693 <xsl:if test="position()!=last()"> |
|
694 <xsl:text>,</xsl:text> |
|
695 </xsl:if> |
|
696 <xsl:text> |
|
697 </xsl:text> |
|
698 </xsl:for-each> |
|
699 <xsl:text> } |
|
700 </xsl:text> |
|
701 <xsl:text> }</xsl:text> |
|
702 <xsl:if test="position()!=last()"> |
|
703 <xsl:text>,</xsl:text> |
|
704 </xsl:if> |
|
705 <xsl:text> |
|
706 </xsl:text> |
|
707 </xsl:for-each> |
|
708 <xsl:text>} |
709 <xsl:text>} |
709 </xsl:text> |
710 </xsl:text> |
710 <xsl:text> |
711 <xsl:text> |
711 </xsl:text> |
712 </xsl:text> |
712 <xsl:text>var default_page = "</xsl:text> |
713 <xsl:text>var default_page = "</xsl:text> |