edouard@2873: // hmi_tree.ysl2 Edouard@2790: Edouard@3381: // Location identifies uniquely SVGHMI instance Edouard@3381: param "instance_name"; Edouard@2843: edouard@2873: // HMI Tree computed from VARIABLES.CSV in svghmi.py edouard@2873: const "hmitree", "ns:GetHMITree()"; Edouard@2853: Edouard@2877: const "_categories" { Edouard@2877: noindex > HMI_PLC_STATUS Edouard@2877: noindex > HMI_CURRENT_PAGE Edouard@2877: } Edouard@2877: const "categories", "exsl:node-set($_categories)"; Edouard@2867: edouard@2873: // HMI Tree Index edouard@2873: const "_indexed_hmitree" apply "$hmitree", mode="index"; edouard@2873: const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)"; Edouard@2843: edouard@2941: emit "preamble:hmi-tree" { edouard@2941: | var hmi_hash = [«$hmitree/@hash»]; edouard@2941: | edouard@2941: | var heartbeat_index = «$indexed_hmitree/*[@hmipath = '/HEARTBEAT']/@index»; edouard@2941: | Edouard@3381: | var current_page_var_index = «$indexed_hmitree/*[@hmipath = concat('/CURRENT_PAGE_', $instance_name)]/@index»; Edouard@3381: | edouard@2941: | var hmitree_types = [ edouard@2941: edouard@2941: foreach "$indexed_hmitree/*" Edouard@3381: | "«substring(local-name(), 5)»"`if "position()!=last()" > ,` Edouard@3205: Edouard@3205: | ]; Edouard@3205: | Edouard@3205: | var hmitree_paths = [ Edouard@3205: Edouard@3205: foreach "$indexed_hmitree/*" Edouard@3381: | "«@hmipath»"`if "position()!=last()" > ,` edouard@2941: edouard@3097: | ]; edouard@2941: | Edouard@3381: | var hmitree_nodes = { Edouard@3381: Edouard@3381: foreach "$indexed_hmitree/*[local-name() = 'HMI_NODE']" Edouard@3381: | "«@hmipath»" : [«@index», "«@class»"]`if "position()!=last()" > ,` Edouard@3381: | }; Edouard@3381: | edouard@2941: } edouard@2941: edouard@2873: template "*", mode="index" { edouard@2873: param "index", "0"; edouard@2873: param "parentpath", "''"; edouard@2873: const "content" { edouard@2873: const "path" edouard@2873: choose { edouard@2890: when "count(ancestor::*)=0" > / edouard@2890: when "count(ancestor::*)=1" > /«@name» edouard@2873: otherwise > «$parentpath»/«@name» edouard@2873: } edouard@2873: choose { edouard@2873: when "not(local-name() = $categories/noindex)" { edouard@2873: xsl:copy { edouard@2873: attrib "index" > «$index» edouard@2873: attrib "hmipath" > «$path» edouard@2873: foreach "@*" xsl:copy; Edouard@2791: } edouard@2873: apply "*[1]", mode="index"{ edouard@2873: with "index", "$index + 1"; edouard@2873: with "parentpath" > «$path» Edouard@2854: } Edouard@2854: } Edouard@2854: otherwise { edouard@2873: apply "*[1]", mode="index"{ edouard@2873: with "index", "$index"; edouard@2873: with "parentpath" > «$path» Edouard@2854: } Edouard@2854: } Edouard@2854: } Edouard@2854: } Edouard@2842: edouard@2873: copy "$content"; edouard@2873: apply "following-sibling::*[1]", mode="index" { edouard@2873: with "index", "$index + count(exsl:node-set($content)/*)"; edouard@2873: with "parentpath" > «$parentpath» Edouard@2808: } Edouard@2753: } edouard@2874: edouard@3221: include parse_labels.ysl2 Edouard@2877: edouard@3129: const "_parsed_widgets" { edouard@3129: widget type="VarInitPersistent" { edouard@3129: arg value="0"; edouard@3129: path value="lang"; edouard@3129: } edouard@3129: apply "$hmi_elements", mode="parselabel"; edouard@3129: } edouard@3129: edouard@2886: const "parsed_widgets","exsl:node-set($_parsed_widgets)"; edouard@2886: edouard@2886: def "func:widget" { edouard@2886: param "id"; edouard@2886: result "$parsed_widgets/widget[@id = $id]"; Edouard@2885: } Edouard@2885: edouard@2894: def "func:is_descendant_path" { edouard@2894: param "descend"; edouard@2894: param "ancest"; edouard@2894: // TODO : use HMI tree to answer more accurately edouard@2894: result "string-length($ancest) > 0 and starts-with($descend,$ancest)"; edouard@2894: } edouard@2894: Edouard@2900: def "func:same_class_paths" { Edouard@2900: param "a"; Edouard@2900: param "b"; Edouard@2900: const "class_a", "$indexed_hmitree/*[@hmipath = $a]/@class"; Edouard@2900: const "class_b", "$indexed_hmitree/*[@hmipath = $b]/@class"; Edouard@2900: result "$class_a and $class_b and $class_a = $class_b"; Edouard@2900: } edouard@2894: edouard@2874: // Debug data edouard@2874: template "*", mode="testtree"{ edouard@2874: param "indent", "''"; edouard@2874: > «$indent» «local-name()» edouard@2874: foreach "@*" > «local-name()»="«.»" edouard@2874: > \n edouard@2874: apply "*", mode="testtree" { edouard@2874: with "indent" value "concat($indent,'>')" edouard@2874: }; edouard@2874: } edouard@2941: edouard@2940: emit "debug:hmi-tree" { edouard@2874: | Raw HMI tree edouard@2874: apply "$hmitree", mode="testtree"; edouard@2874: | edouard@2874: | Indexed HMI tree edouard@2874: apply "$indexed_hmitree", mode="testtree"; edouard@2886: | edouard@2886: | Parsed Widgets edouard@2886: copy "_parsed_widgets"; edouard@2886: apply "$parsed_widgets", mode="testtree"; edouard@2874: }