edouard@2873: // hmi_tree.ysl2 Edouard@2790: 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@2941: | var hmitree_types = [ edouard@2941: edouard@2941: foreach "$indexed_hmitree/*" edouard@2941: | /* «@index» «@hmipath» */ "«substring(local-name(), 5)»"`if "position()!=last()" > ,` edouard@2941: edouard@3097: | ]; edouard@2941: | 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@2882: // Parses: edouard@3097: // "HMI:WidgetType:param1:param2@path1,path1min,path1max@path2" Edouard@2882: // Edouard@2882: // Into: Edouard@2893: // widget type="WidgetType" id="blah456" { Edouard@2882: // arg value="param1"; Edouard@2882: // arg value="param2"; edouard@3097: // path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL"; Edouard@3060: // path value="/path1" index="348" type="HMI_INT"; Edouard@3060: // path value="path4" index="path4" type="HMI_LOCAL"; Edouard@2882: // } Edouard@2882: // edouard@2886: template "*", mode="parselabel" { edouard@2886: const "label","@inkscape:label"; edouard@3097: const "id","@id"; Edouard@2877: const "description", "substring-after($label,'HMI:')"; Edouard@2877: Edouard@2877: const "_args", "substring-before($description,'@')"; Edouard@2877: const "args" choose { Edouard@2877: when "$_args" value "$_args"; Edouard@2877: otherwise value "$description"; Edouard@2877: } Edouard@2877: Edouard@2877: const "_type", "substring-before($args,':')"; Edouard@2877: const "type" choose { Edouard@2877: when "$_type" value "$_type"; Edouard@2877: otherwise value "$args"; Edouard@2877: } Edouard@2877: edouard@2886: if "$type" widget { edouard@3097: attrib "id" > «$id» Edouard@2877: attrib "type" > «$type» Edouard@2877: foreach "str:split(substring-after($args, ':'), ':')" { Edouard@2877: arg { Edouard@2877: attrib "value" > «.» Edouard@2877: } Edouard@2877: } Edouard@2877: const "paths", "substring-after($description,'@')"; Edouard@2877: foreach "str:split($paths, '@')" { Edouard@2877: if "string-length(.) > 0" path { edouard@3097: const "pathminmax", "str:split(.,',')"; edouard@3097: const "path", "$pathminmax[1]"; edouard@3097: const "pathminmaxcount", "count($pathminmax)"; edouard@3097: attrib "value" > «$path» edouard@3017: choose { edouard@3097: when "$pathminmaxcount = 3" { edouard@3097: attrib "min" > «$pathminmax[2]» edouard@3097: attrib "max" > «$pathminmax[3]» edouard@3097: } edouard@3097: when "$pathminmaxcount = 2" { edouard@3097: error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax» edouard@3097: } edouard@3097: } edouard@3097: choose { edouard@3097: when "regexp:test($path,'^\.[a-zA-Z0-9_]+')" { edouard@3097: attrib "type" > PAGE_LOCAL edouard@3097: } edouard@3097: when "regexp:test($path,'^[a-zA-Z0-9_]+')" { edouard@3097: attrib "type" > HMI_LOCAL edouard@3017: } edouard@3017: otherwise { edouard@3097: const "item", "$indexed_hmitree/*[@hmipath = $path]"; edouard@3097: const "pathtype", "local-name($item)"; edouard@3097: if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" { edouard@3097: error > Widget id:«$id» label:«$label» path section «$pathminmax» use min and max on non mumeric value edouard@3097: } edouard@3097: if "count($item) = 1" { edouard@3097: attrib "index" > «$item/@index» edouard@3097: attrib "type" > «$pathtype» edouard@3017: } edouard@3017: } Edouard@2911: } Edouard@2877: } Edouard@2877: } Edouard@2877: } Edouard@2877: } Edouard@2877: edouard@2886: const "_parsed_widgets" apply "$hmi_elements", mode="parselabel"; 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: }