# HG changeset patch # User Edouard Tisserant # Date 1584606667 -3600 # Node ID 6c82fad8be65e75fc71240a2b144286a39da6ae1 # Parent f398896b7ebf13fb06d5af5513299cda5eead3ac SVGHMI: Simplification and optimization. func:parselabel becomes a template. All labels are parsed into a global variable containing resulting widget description as a node-set. func:widget(id) was added for random access to widget description. diff -r f398896b7ebf -r 6c82fad8be65 svghmi/detachable_pages.ysl2 --- a/svghmi/detachable_pages.ysl2 Wed Mar 18 12:06:50 2020 +0100 +++ b/svghmi/detachable_pages.ysl2 Thu Mar 19 09:31:07 2020 +0100 @@ -4,12 +4,13 @@ // and decide where to cut when removing/attaching // pages elements on page switch -const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"; +const "hmi_pages_ids", "$parsed_widgets/widget[@type = 'Page']/@id"; +const "hmi_pages", "$hmi_elements[@id = $hmi_pages_ids]"; const "default_page" choose { when "count($hmi_pages) > 1" { const "Home_page", - "$hmi_pages[func:parselabel(@inkscape:label)/widget/arg[1]/@value = 'Home']"; + "$hmi_pages[func:widget(@id)/arg[1]/@value = 'Home']"; choose { when "$Home_page" > Home otherwise { @@ -20,7 +21,7 @@ when "count($hmi_pages) = 0" { error "No page defined!"; } - otherwise > «func:parselabel($hmi_pages/@inkscape:label)/widget/arg[1]/@value» + otherwise > «func:widget($hmi_pages/@id)/arg[1]/@value» } // returns all directly or indirectly refered elements @@ -100,16 +101,16 @@ template "svg:*", mode="page_desc" { - const "desc", "func:parselabel(@inkscape:label)/widget"; + const "desc", "func:widget(@id)"; const "page", "."; const "p", "$geometry[@Id = $page/@id]"; const "page_all_elements", "func:all_related_elements($page)"; - const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id][not(func:parselabels(ancestor::svg:*)/widget/@type = 'ForEach')]"; + const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]"; const "page_relative_widgets", - "$all_page_widgets[func:is_descendant_path(func:parselabel(@inkscape:label)/widget/path/@value, $desc/path/@value)]"; + "$all_page_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]"; // Take closest ancestor in detachable_elements // since nested detachable elements are filtered out diff -r f398896b7ebf -r 6c82fad8be65 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed Mar 18 12:06:50 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Thu Mar 19 09:31:07 2020 +0100 @@ -73,8 +73,8 @@ - - + + @@ -98,51 +98,48 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -173,6 +170,12 @@ Indexed HMI tree + + + Parsed Widgets + + + @@ -239,11 +242,12 @@ - + + - + Home @@ -257,7 +261,7 @@ No page defined! - + @@ -321,12 +325,12 @@ - + - - + + " @@ -539,7 +543,7 @@ - + " diff -r f398896b7ebf -r 6c82fad8be65 svghmi/hmi_tree.ysl2 --- a/svghmi/hmi_tree.ysl2 Wed Mar 18 12:06:50 2020 +0100 +++ b/svghmi/hmi_tree.ysl2 Thu Mar 19 09:31:07 2020 +0100 @@ -63,8 +63,8 @@ // path value="path2"; // } // -def "func:parselabel" { - param "label"; +template "*", mode="parselabel" { + const "label","@inkscape:label"; const "description", "substring-after($label,'HMI:')"; const "_args", "substring-before($description,'@')"; @@ -79,7 +79,8 @@ otherwise value "$args"; } - const "ast" if "$type" widget { + if "$type" widget { + attrib "id" > «@id» attrib "type" > «$type» foreach "str:split(substring-after($args, ':'), ':')" { arg { @@ -97,22 +98,17 @@ } } } - - result "exsl:node-set($ast)"; } -def "func:parselabels" { - param "nodes"; - choose{ - when "$nodes"{ - result """func:parselabel($nodes[1]/@inkscape:label) - | func:parselabels($nodes[position()!=1])"""; - }otherwise{ - result "/.."; - } - } +const "_parsed_widgets" apply "$hmi_elements", mode="parselabel"; +const "parsed_widgets","exsl:node-set($_parsed_widgets)"; + +def "func:widget" { + param "id"; + result "$parsed_widgets/widget[@id = $id]"; } + // Debug data template "*", mode="testtree"{ param "indent", "''"; @@ -129,5 +125,9 @@ | | Indexed HMI tree apply "$indexed_hmitree", mode="testtree"; + | + | Parsed Widgets + copy "_parsed_widgets"; + apply "$parsed_widgets", mode="testtree"; } !debug_output_calls.append("debug_hmitree") diff -r f398896b7ebf -r 6c82fad8be65 svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Wed Mar 18 12:06:50 2020 +0100 +++ b/svghmi/widgets_common.ysl2 Thu Mar 19 09:31:07 2020 +0100 @@ -12,7 +12,7 @@ }; template "svg:*", mode="hmi_elements" { - const "widget", "func:parselabel(@inkscape:label)/widget"; + const "widget", "func:widget(@id)"; const "eltid","@id"; | "«@id»": { | type: "«$widget/@type»",