14 with "mandatory","'no'"; |
14 with "mandatory","'no'"; |
15 }; |
15 }; |
16 |
16 |
17 in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template; |
17 in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template; |
18 in xsl decl svgfunc(name, xmlns="http://www.w3.org/2000/svg") alias template; |
18 in xsl decl svgfunc(name, xmlns="http://www.w3.org/2000/svg") alias template; |
|
19 |
|
20 !debug_output_calls = [] |
19 |
21 |
20 istylesheet |
22 istylesheet |
21 /* From Inkscape */ |
23 /* From Inkscape */ |
22 xmlns:dc="http://purl.org/dc/elements/1.1/" |
24 xmlns:dc="http://purl.org/dc/elements/1.1/" |
23 xmlns:cc="http://creativecommons.org/ns#" |
25 xmlns:cc="http://creativecommons.org/ns#" |
31 /* Our namespace to invoke python code */ |
33 /* Our namespace to invoke python code */ |
32 xmlns:ns="beremiz" |
34 xmlns:ns="beremiz" |
33 extension-element-prefixes="ns func exsl regexp str dyn" |
35 extension-element-prefixes="ns func exsl regexp str dyn" |
34 exclude-result-prefixes="ns str regexp exsl func dyn" { |
36 exclude-result-prefixes="ns str regexp exsl func dyn" { |
35 |
37 |
36 /* This retrieves geometry obtained through "inkscape -S" |
|
37 * already parsed by python and presented as a list of |
|
38 * <bbox x="0" y="0" w="42" h="42"> |
|
39 */ |
|
40 const "geometry", "ns:GetSVGGeometry()"; |
|
41 const "hmitree", "ns:GetHMITree()"; |
|
42 |
38 |
43 const "svg_root_id", "/svg:svg/@id"; |
39 const "svg_root_id", "/svg:svg/@id"; |
44 const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; |
40 const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; |
45 const "hmi_geometry", "$geometry[@Id = $hmi_elements/@id]"; |
|
46 |
41 |
47 const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"; |
42 const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"; |
48 |
43 |
49 const "default_page" choose { |
44 const "default_page" choose { |
50 when "count($hmi_pages) > 1" { |
45 when "count($hmi_pages) > 1" { |
83 otherwise |
78 otherwise |
84 result "$descend"; |
79 result "$descend"; |
85 } |
80 } |
86 } |
81 } |
87 |
82 |
88 include bbox_intersect.ysl2 |
83 include geometry.ysl2 |
89 |
84 |
90 // return overlapping geometry for a given element |
|
91 // all intersercting element are returned |
|
92 // except groups, that must be contained to be counted in |
|
93 def "func:overlapping_geometry" { |
|
94 param "elt"; |
|
95 const "groups", "/svg:svg | //svg:g"; |
|
96 const "g", "$geometry[@Id = $elt/@id]"; |
|
97 const "candidates", "$geometry[@Id != $elt/@id]"; |
|
98 result """$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or |
|
99 (not(@Id = $groups/@id) and (func:intersect($g, .) > 0 ))]"""; |
|
100 } |
|
101 |
85 |
102 def "func:all_related_elements" { |
86 def "func:all_related_elements" { |
103 param "page"; |
87 param "page"; |
104 const "page_overlapping_geometry", "func:overlapping_geometry($page)"; |
88 const "page_overlapping_geometry", "func:overlapping_geometry($page)"; |
105 const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]"; |
89 const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]"; |
153 // Avoid nested detachables |
137 // Avoid nested detachables |
154 const "_detachable_elements", "func:detachable_elements($hmi_pages)"; |
138 const "_detachable_elements", "func:detachable_elements($hmi_pages)"; |
155 const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"; |
139 const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"; |
156 |
140 |
157 |
141 |
158 //////////////// HMI Tree Index |
142 include hmi_tree.ysl2 |
159 |
|
160 const "_indexed_hmitree" apply "$hmitree", mode="index"; |
|
161 const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)"; |
|
162 |
|
163 template "*", mode="index" { |
|
164 param "index", "0"; |
|
165 param "parentpath", "''"; |
|
166 const "content" { |
|
167 const "path" |
|
168 choose { |
|
169 when "local-name() = 'HMI_ROOT'" > «$parentpath» |
|
170 otherwise > «$parentpath»/«@name» |
|
171 } |
|
172 choose { |
|
173 when "not(local-name() = $categories/noindex)" { |
|
174 xsl:copy { |
|
175 attrib "index" > «$index» |
|
176 attrib "hmipath" > «$path» |
|
177 foreach "@*" xsl:copy; |
|
178 } |
|
179 apply "*[1]", mode="index"{ |
|
180 with "index", "$index + 1"; |
|
181 with "parentpath" > «$path» |
|
182 } |
|
183 } |
|
184 otherwise { |
|
185 apply "*[1]", mode="index"{ |
|
186 with "index", "$index"; |
|
187 with "parentpath" > «$path» |
|
188 } |
|
189 } |
|
190 } |
|
191 } |
|
192 |
|
193 copy "$content"; |
|
194 apply "following-sibling::*[1]", mode="index" { |
|
195 with "index", "$index + count(exsl:node-set($content)/*)"; |
|
196 with "parentpath" > «$parentpath» |
|
197 } |
|
198 } |
|
199 |
143 |
200 |
144 |
201 def "func:is_descendant_path" { |
145 def "func:is_descendant_path" { |
202 param "descend"; |
146 param "descend"; |
203 param "ancest"; |
147 param "ancest"; |
314 /*const "mark" > =HMI=\n*/ |
258 /*const "mark" > =HMI=\n*/ |
315 |
259 |
316 const "result_svg" apply "/", mode="inline_svg"; |
260 const "result_svg" apply "/", mode="inline_svg"; |
317 const "result_svg_ns", "exsl:node-set($result_svg)"; |
261 const "result_svg_ns", "exsl:node-set($result_svg)"; |
318 |
262 |
319 /* copy root node and add geometry as comment for a test */ |
|
320 template "/" { |
263 template "/" { |
321 comment > Made with SVGHMI. https://beremiz.org |
264 comment > Made with SVGHMI. https://beremiz.org |
322 /* DEBUG DATA */ |
265 |
323 comment { |
266 // use python to call all debug output from included definitions |
324 apply "$hmi_geometry", mode="testgeo"; |
267 // '&bug' is a workaround for old pyPEG that choke on empty python results |
325 } |
268 !"&bug "+"\n".join(["comment {|\n| %s:\n call \"%s\";\n| \n}"%(n,n) for n in debug_output_calls])! |
|
269 |
|
270 // TODO |
326 comment { |
271 comment { |
327 apply "$hmitree", mode="testtree"; |
272 apply "$hmitree", mode="testtree"; |
328 } |
273 } |
329 comment { |
274 comment { |
330 apply "$indexed_hmitree", mode="testtree"; |
275 apply "$indexed_hmitree", mode="testtree"; |
568 // || |
513 // || |
569 // } |
514 // } |
570 |
515 |
571 |
516 |
572 /**/ |
517 /**/ |
573 template "bbox", mode="testgeo"{ |
|
574 | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h» |
|
575 } |
|
576 |
|
577 template "*", mode="testtree"{ |
518 template "*", mode="testtree"{ |
578 param "indent", "''"; |
519 param "indent", "''"; |
579 > «$indent» «local-name()» |
520 > «$indent» «local-name()» |
580 foreach "@*" > «local-name()»="«.»" |
521 foreach "@*" > «local-name()»="«.»" |
581 > \n |
522 > \n |