# HG changeset patch # User Edouard Tisserant # Date 1584092173 -3600 # Node ID d9eb50c015d1c9e1ab9f10b2b9026d9902909775 # Parent 8d9757191f0533662fc59d99d403554298df9c66 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state. diff -r 8d9757191f05 -r d9eb50c015d1 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Thu Mar 12 13:16:18 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Fri Mar 13 10:36:13 2020 +0100 @@ -198,6 +198,11 @@ + + + + + @@ -399,11 +404,20 @@ - - - - - + + + + + + + + + + + + + + @@ -453,23 +467,21 @@ indexes: [ - - - + Widget id=" " : No match for path " - + " in HMI tree - + , @@ -551,7 +563,8 @@ - + + " @@ -571,11 +584,40 @@ ], - widgets: [ - - + + + + Page id=" + + " : No match for path " + + " in HMI tree + + + page_index: + + , + + + relative_widgets: [ + + hmi_widgets[" - + + "] + + , + + + + + ], + + absolute_widgets: [ + + + hmi_widgets[" + "] , @@ -1138,7 +1180,7 @@ - function switch_page(page_name) { + function switch_page(page_name, root_index) { if(current_subscribed_page != current_visible_page){ @@ -1164,6 +1206,16 @@ + function* chain(a,b){ + + yield* a; + + yield* b; + + }; + + + function switch_subscribed_page(page_name) { let old_desc = page_desc[current_subscribed_page]; @@ -1184,7 +1236,7 @@ if(old_desc){ - for(let widget of old_desc.widgets){ + for(let widget of chain(old_desc.absolute_widgets,old_desc.relative_widgets)){ /* remove subsribers */ @@ -1198,7 +1250,7 @@ } - for(let widget of new_desc.widgets){ + for(let widget of chain(new_desc.absolute_widgets,new_desc.relative_widgets)){ /* add widget's subsribers */ @@ -1276,7 +1328,7 @@ - for(let widget of new_desc.widgets){ + for(let widget of chain(new_desc.absolute_widgets,new_desc.relative_widgets)){ for(let index of widget.indexes){ @@ -1621,7 +1673,7 @@ on_click: function(evt) { - switch_page(this.args[0]); + switch_page(this.args[0], this.indexes[0]); }, diff -r 8d9757191f05 -r d9eb50c015d1 svghmi/gen_index_xhtml.ysl2 --- a/svghmi/gen_index_xhtml.ysl2 Thu Mar 12 13:16:18 2020 +0100 +++ b/svghmi/gen_index_xhtml.ysl2 Fri Mar 13 10:36:13 2020 +0100 @@ -305,6 +305,11 @@ } + def "func:is_descendant_path" { + param "ancest"; + param "descend"; + result "starts-with($descend,$ancest)"; + } //////////////// Inline SVG @@ -501,8 +506,12 @@ } const "paths", "substring-after($description,'@')"; foreach "str:split($paths, '@')" { - path { + if "string-length(.) > 0" path { attrib "value" > «.» + const "path", "."; + const "item", "$indexed_hmitree/*[@hmipath = $path]"; + if "count($item) = 1" + attrib "index" > «$item/@index» } } } @@ -548,14 +557,12 @@ | ], | indexes: [ foreach "$widget/path" { - const "hmipath","@value"; - const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]"; choose { - when "count($hmitree_match) = 0" { - warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«$hmipath»" in HMI tree + when "not(@index)" { + warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree } otherwise { - | «$hmitree_match/@index»`if "position()!=last()" > ,` + | «@index»`if "position()!=last()" > ,` } } } @@ -593,7 +600,10 @@ const "page_all_elements", "func:all_related_elements($page)"; - const "all_page_ids","$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id"; + 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($desc/path/@value, path/@value)]"; // Take closest ancestor in detachable_elements // since nested detachable elements are filtered out @@ -604,9 +614,19 @@ | "«$desc/arg[1]/@value»": { | widget: hmi_widgets["«@id»"], | bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»], - | widgets: [ - foreach "$all_page_ids" { - | hmi_widgets["«.»"]`if "position()!=last()" > ,` + if "$desc/path/@value" { + if "count($desc/path/@index)=0" + warning > Page id="«$page/@id»" : No match for path "«$desc/path/@value»" in HMI tree + | page_index: «$desc/path/@index», + } + | relative_widgets: [ + foreach "$page_relative_widgets" { + | hmi_widgets["«@id»"]`if "position()!=last()" > ,` + } + | ], + | absolute_widgets: [ + foreach "$all_page_widgets[not(@id = $page_relative_widgets/@id)]" { + | hmi_widgets["«@id»"]`if "position()!=last()" > ,` } | ], | required_detachables: { @@ -824,7 +844,7 @@ template "widget[@type='Jump']", mode="widget_defs" { param "hmi_element"; | on_click: function(evt) { - | switch_page(this.args[0]); + | switch_page(this.args[0], this.indexes[0]); | }, | init: function() { /* registering event this way doies not "click" through svg:use diff -r 8d9757191f05 -r d9eb50c015d1 svghmi/svghmi.js --- a/svghmi/svghmi.js Thu Mar 12 13:16:18 2020 +0100 +++ b/svghmi/svghmi.js Fri Mar 13 10:36:13 2020 +0100 @@ -257,7 +257,7 @@ } }; -function switch_page(page_name) { +function switch_page(page_name, root_index) { if(current_subscribed_page != current_visible_page){ /* page switch already going */ /* TODO LOG ERROR */ @@ -270,6 +270,11 @@ switch_subscribed_page(page_name); }; +function* chain(a,b){ + yield* a; + yield* b; +}; + function switch_subscribed_page(page_name) { let old_desc = page_desc[current_subscribed_page]; let new_desc = page_desc[page_name]; @@ -280,14 +285,14 @@ } if(old_desc){ - for(let widget of old_desc.widgets){ + for(let widget of chain(old_desc.absolute_widgets,old_desc.relative_widgets)){ /* remove subsribers */ for(let index of widget.indexes){ subscribers[index].delete(widget); } } } - for(let widget of new_desc.widgets){ + for(let widget of chain(new_desc.absolute_widgets,new_desc.relative_widgets)){ /* add widget's subsribers */ for(let index of widget.indexes){ subscribers[index].add(widget); @@ -326,7 +331,7 @@ } } - for(let widget of new_desc.widgets){ + for(let widget of chain(new_desc.absolute_widgets,new_desc.relative_widgets)){ for(let index of widget.indexes){ /* dispatch current cache in newly opened page widgets */ let cached_val = cache[index];