|
1 // hmi_tree.ysl2 |
|
2 |
|
3 |
|
4 // HMI Tree computed from VARIABLES.CSV in svghmi.py |
|
5 const "hmitree", "ns:GetHMITree()"; |
|
6 |
|
7 const "_categories" { |
|
8 noindex > HMI_PLC_STATUS |
|
9 noindex > HMI_CURRENT_PAGE |
|
10 } |
|
11 const "categories", "exsl:node-set($_categories)"; |
|
12 |
|
13 // HMI Tree Index |
|
14 const "_indexed_hmitree" apply "$hmitree", mode="index"; |
|
15 const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)"; |
|
16 |
|
17 emit "preamble:hmi-tree" { |
|
18 | var hmi_hash = [«$hmitree/@hash»]; |
|
19 | |
|
20 | var heartbeat_index = «$indexed_hmitree/*[@hmipath = '/HEARTBEAT']/@index»; |
|
21 | |
|
22 | var hmitree_types = [ |
|
23 |
|
24 foreach "$indexed_hmitree/*" |
|
25 | /* «@index» */ "«substring(local-name(), 5)»"`if "position()!=last()" > ,` |
|
26 |
|
27 | ]; |
|
28 | |
|
29 | var hmitree_paths = [ |
|
30 |
|
31 foreach "$indexed_hmitree/*" |
|
32 | /* «@index» */ "«@hmipath»"`if "position()!=last()" > ,` |
|
33 |
|
34 | ]; |
|
35 | |
|
36 } |
|
37 |
|
38 template "*", mode="index" { |
|
39 param "index", "0"; |
|
40 param "parentpath", "''"; |
|
41 const "content" { |
|
42 const "path" |
|
43 choose { |
|
44 when "count(ancestor::*)=0" > / |
|
45 when "count(ancestor::*)=1" > /«@name» |
|
46 otherwise > «$parentpath»/«@name» |
|
47 } |
|
48 choose { |
|
49 when "not(local-name() = $categories/noindex)" { |
|
50 xsl:copy { |
|
51 attrib "index" > «$index» |
|
52 attrib "hmipath" > «$path» |
|
53 foreach "@*" xsl:copy; |
|
54 } |
|
55 apply "*[1]", mode="index"{ |
|
56 with "index", "$index + 1"; |
|
57 with "parentpath" > «$path» |
|
58 } |
|
59 } |
|
60 otherwise { |
|
61 apply "*[1]", mode="index"{ |
|
62 with "index", "$index"; |
|
63 with "parentpath" > «$path» |
|
64 } |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 copy "$content"; |
|
70 apply "following-sibling::*[1]", mode="index" { |
|
71 with "index", "$index + count(exsl:node-set($content)/*)"; |
|
72 with "parentpath" > «$parentpath» |
|
73 } |
|
74 } |
|
75 |
|
76 include parse_labels.ysl2 |
|
77 |
|
78 const "_parsed_widgets" { |
|
79 widget type="VarInitPersistent" { |
|
80 arg value="0"; |
|
81 path value="lang"; |
|
82 } |
|
83 apply "$hmi_elements", mode="parselabel"; |
|
84 } |
|
85 |
|
86 const "parsed_widgets","exsl:node-set($_parsed_widgets)"; |
|
87 |
|
88 def "func:widget" { |
|
89 param "id"; |
|
90 result "$parsed_widgets/widget[@id = $id]"; |
|
91 } |
|
92 |
|
93 def "func:is_descendant_path" { |
|
94 param "descend"; |
|
95 param "ancest"; |
|
96 // TODO : use HMI tree to answer more accurately |
|
97 result "string-length($ancest) > 0 and starts-with($descend,$ancest)"; |
|
98 } |
|
99 |
|
100 def "func:same_class_paths" { |
|
101 param "a"; |
|
102 param "b"; |
|
103 const "class_a", "$indexed_hmitree/*[@hmipath = $a]/@class"; |
|
104 const "class_b", "$indexed_hmitree/*[@hmipath = $b]/@class"; |
|
105 result "$class_a and $class_b and $class_a = $class_b"; |
|
106 } |
|
107 |
|
108 // Debug data |
|
109 template "*", mode="testtree"{ |
|
110 param "indent", "''"; |
|
111 > «$indent» «local-name()» |
|
112 foreach "@*" > «local-name()»="«.»" |
|
113 > \n |
|
114 apply "*", mode="testtree" { |
|
115 with "indent" value "concat($indent,'>')" |
|
116 }; |
|
117 } |
|
118 |
|
119 emit "debug:hmi-tree" { |
|
120 | Raw HMI tree |
|
121 apply "$hmitree", mode="testtree"; |
|
122 | |
|
123 | Indexed HMI tree |
|
124 apply "$indexed_hmitree", mode="testtree"; |
|
125 | |
|
126 | Parsed Widgets |
|
127 copy "_parsed_widgets"; |
|
128 apply "$parsed_widgets", mode="testtree"; |
|
129 } |