# HG changeset patch # User Edouard Tisserant # Date 1570788194 -7200 # Node ID c5ba1e77f05499b354c005de95c047686fe27d65 # Parent c7a22ce8c1569a2a965d767ba2cdb68cd13c24e6 SVGHMI: added a widgets description object, accessed by id. Added frequency to widgets, as separate template to allow future customization. Excluded non svg elements (i.e inkscape Sets) with HMI: labels from widgets. diff -r c7a22ce8c156 -r c5ba1e77f054 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Thu Oct 10 10:03:47 2019 +0200 +++ b/svghmi/gen_index_xhtml.xslt Fri Oct 11 12:03:14 2019 +0200 @@ -3,7 +3,7 @@ - + @@ -179,27 +179,30 @@ - var hmi_index = { - - - - + var hmi_hash = [ + + ]; + + var hmi_widgets = { + + + + : { - name: " - + type: " + ", - hmipath: " - - " - - ids: [ - - - + frequency: + + , + + args: [ + + " - + " , @@ -207,6 +210,28 @@ + ], + + paths: [ + + + + + + + No match for HMI + + ; + + + + + + , + + + + ] } @@ -220,10 +245,54 @@ + var hmi_index = [ + + + + { /* + + + + */ + + type: " + + ", + + ids: [ + + + + hmi_widgets[" + + "] + + , + + + + + ] + + } + + , + + + + + ] + + + var page_desc = { + + + + " ": { @@ -234,11 +303,9 @@ widgets: [ - - - + " - + " , @@ -248,6 +315,30 @@ ] + subscriptions: [ + + + + + + + + + + , + + + + + + ] + + } + + , + + + } @@ -321,13 +412,11 @@ - - // subscription state as needed by widget now // expected {index:[widgets]}; - var subscribers = {}; + var subscribers = new Map(); @@ -337,24 +426,30 @@ let delta = []; - Object.keys(subscribers).forEach(index => { - - + for(let [index, widgets] in subscribers.entries()){ + + + + // periods are in ms let previous_period = subscriptions.get(index); - delete subscriptions[index]; - - - - let new_period = Math.min(...widgets.map(widget => widget.period)); - - - - if(previous_period != new_period) + + + let new_period = Math.min(...widgets.map(widget => 1000/widget.frequency)); + + + + if(previous_period != new_period) { + + subscriptions.set(index, new_period); delta.push({index: index, period: new_period}); + } + + + }) return result; @@ -373,8 +468,28 @@ + var current_page = default_page; + + + function switch_page(page_name) { + let new_desc = page_desc[page_name]; + + let old_desc = page_desc[page_name]; + + /* TODO hide / show widgets */ + + /* TODO move viewport */ + + + + /* Update subscribers */ + + /* Update subscriptions */ + + + }; @@ -456,4 +571,16 @@ + + 10 + + + 10 + + + 5 + + + 5 + diff -r c7a22ce8c156 -r c5ba1e77f054 svghmi/gen_index_xhtml.ysl2 --- a/svghmi/gen_index_xhtml.ysl2 Thu Oct 10 10:03:47 2019 +0200 +++ b/svghmi/gen_index_xhtml.ysl2 Fri Oct 11 12:03:14 2019 +0200 @@ -24,7 +24,7 @@ const "geometry", "ns:GetSVGGeometry()"; const "hmitree", "ns:GetHMITree()"; - const "hmi_elements", "//*[starts-with(@inkscape:label, 'HMI:')]"; + const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; const "hmi_geometry", "$geometry[@Id = $hmi_elements/@id]"; const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"; @@ -163,7 +163,8 @@ function "scripts" { - /* TODO : paste hmitree hash stored in hmi tree root node */ + /* paste hmitree hash stored in hmi tree root node */ + | var hmi_hash = [«$hmitree/@hash»]; /* TODO re-enable || @@ -183,45 +184,74 @@ || */ - /*TODO add : - - pages content - + with ref to elt ? - - widgets parameters - */ - - | var hmi_index = { + | var hmi_widgets = { + foreach "$hmi_elements" { + const "widget", "func:parselabel(@inkscape:label)/widget"; + | «@id»: { + | type: "«$widget/@type»", + | frequency: `apply "$widget", mode="refresh_frequency"`, + | args: [ + foreach "$widget/arg" + | "«@value»"`if "position()!=last()" > ,` + | ], + | paths: [ + foreach "$widget/path" { + const "hmipath","@value"; + const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]"; + if "count($hmitree_match) = 0" + error > No match for HMI «$hmipath»; + | «$hmitree_match/@index»`if "position()!=last()" > ,` + } + | ] + | }`if "position()!=last()" > ,` + } + | } + | + | var hmi_index = [ const "svg","/"; /* foreach loses document root */ foreach "$indexed_hmitree/*" { - | «@index»: { - | name: "«@name»", - | hmipath: "«@hmipath»" + | { /* «@index» «@hmipath» */ + | type: "«local-name()»", | ids: [ const "hmipath","@hmipath"; foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" { - | "«@id»"`if "position()!=last()" > ,` + | hmi_widgets["«@id»"]`if "position()!=last()" > ,` } | ] | }`if "position()!=last()" > ,` } - | } + | ] | | var page_desc = { foreach "$hmi_pages" { const "desc", "func:parselabel(@inkscape:label)/widget"; + const "page", "."; + const "p", "$hmi_geometry[@Id = $page/@id]"; + const "page_ids","""$hmi_geometry[@Id != $page/@id and + @x >= $p/@x and @y >= $p/@y and + @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id"""; + const "page_elements", "$hmi_elements[@id = $page_ids]"; | "«$desc/arg[1]/@value»": { | id: "«@id»", | widgets: [ - const "page", "."; - const "p", "$hmi_geometry[@Id = $page/@id]"; - foreach """$hmi_geometry[@Id != $page/@id and - @x >= $p/@x and @y >= $p/@y and - @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]""" { - | "«@Id»"`if "position()!=last()" > ,` + foreach "$page_ids" { + | "«.»"`if "position()!=last()" > ,` } | ] + | subscriptions: [ + foreach "$page_elements" { + const "hmipaths", "func:parselabel(@inkscape:label)/widget/path/@value"; + const "notlast", "position()!=last()"; + foreach "$hmipaths" { + const "hmipath","."; + | «$indexed_hmitree/*[@hmipath = $hmipath]/@index»`if "$notlast or position()!=last()" > ,` + } + } + | ] + | }`if "position()!=last()" > ,` } | } @@ -291,4 +321,9 @@ with "indent" value "concat($indent,'>')" }; } + + template "widget", mode="refresh_frequency" > 10 + template "widget[@type='Meter']", mode="refresh_frequency" > 10 + template "widget[@type='Display']", mode="refresh_frequency" > 5 + template "widget[@type='Input']", mode="refresh_frequency" > 5 }