# HG changeset patch # User Edouard Tisserant # Date 1570604675 -7200 # Node ID 2a97688c94c5839e1286dcc90d7def9c78dbc0fa # Parent 0c0d3895b0364f6a06393e52fe6cd18a69fbb949 SVGHMI: use func:function for parsing labels so that it can be used in predicates diff -r 0c0d3895b036 -r 2a97688c94c5 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Tue Oct 08 13:27:00 2019 +0200 +++ b/svghmi/gen_index_xhtml.xslt Wed Oct 09 09:04:35 2019 +0200 @@ -1,5 +1,5 @@ - + @@ -83,6 +83,9 @@ + + Made with SVGHMI. https://beremiz.org + @@ -104,191 +107,7 @@ - - var hmi_index = { - - - - - : { - - name: " - - ", - - hmipath: " - - " - - ids: [ - - - - " - - " - - , - - - - - ] - - } - - , - - - - - } - - - - var page_desc = { - - - - - - - - - - - - - } - - // svghmi.js - - - - (function(){ - - // Open WebSocket to relative "/ws" address - - var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws')); - - - - // Register message reception handler - - ws.onmessage = function (evt) { - - // TODO : dispatch and cache hmi tree updates - - - - var received_msg = evt.data; - - // TODO : check for hmitree hash header - - // if not matching, reload page - - alert("Message is received..."+received_msg); - - }; - - - - // Once connection established - - ws.onopen = function (evt) { - - // TODO : enable the HMI (was previously offline, or just starts) - - // show main page - - - - - - // TODO : prefix with hmitree hash header - - ws.send("test"); - - }; - - - - var pending_updates = {}; - - - - // subscription state, as it should be in hmi server - - // expected {index:period} - - const subscriptions = new Map(); - - - - - - // subscription state as needed by widget now - - // expected {index:[widgets]}; - - var subscribers = {}; - - - - // return the diff in between curently subscribed and subscription - - function update_subscriptions() { - - let delta = []; - - Object.keys(subscribers).forEach(index => { - - - - let previous_period = subscriptions.get(index); - - delete subscriptions[index]; - - - - let new_period = Math.min(...widgets.map(widget => widget.period)); - - - - if(previous_period != new_period) - - delta.push({index: index, period: new_period}); - - }) - - return result; - - } - - - - - - function update_value(index, value) { - - - - }; - - - - function switch_page(page_name) { - - - - }; - - - - })(); - - - + @@ -313,28 +132,211 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + var hmi_index = { + + + + + : { + + name: " + + ", + + hmipath: " + + " + + ids: [ + + + + " + + " + + , + + + + + ] + + } + + , + + + + + } + + + + var page_desc = { + + + + + + + + + } + + // svghmi.js + + + + (function(){ + + // Open WebSocket to relative "/ws" address + + var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws')); + + + + // Register message reception handler + + ws.onmessage = function (evt) { + + // TODO : dispatch and cache hmi tree updates + + + + var received_msg = evt.data; + + // TODO : check for hmitree hash header + + // if not matching, reload page + + alert("Message is received..."+received_msg); + + }; + + + + // Once connection established + + ws.onopen = function (evt) { + + // TODO : enable the HMI (was previously offline, or just starts) + + // show main page + + + + + + // TODO : prefix with hmitree hash header + + ws.send("test"); + + }; + + + + var pending_updates = {}; + + + + // subscription state, as it should be in hmi server + + // expected {index:period} + + const subscriptions = new Map(); + + + + + + // subscription state as needed by widget now + + // expected {index:[widgets]}; + + var subscribers = {}; + + + + // return the diff in between curently subscribed and subscription + + function update_subscriptions() { + + let delta = []; + + Object.keys(subscribers).forEach(index => { + + + + let previous_period = subscriptions.get(index); + + delete subscriptions[index]; + + + + let new_period = Math.min(...widgets.map(widget => widget.period)); + + + + if(previous_period != new_period) + + delta.push({index: index, period: new_period}); + + }) + + return result; + + } + + + + + + function update_value(index, value) { + + + + }; + + + + function switch_page(page_name) { + + + + }; + + + + })(); + diff -r 0c0d3895b036 -r 2a97688c94c5 svghmi/gen_index_xhtml.ysl2 --- a/svghmi/gen_index_xhtml.ysl2 Tue Oct 08 13:27:00 2019 +0200 +++ b/svghmi/gen_index_xhtml.ysl2 Wed Oct 09 09:04:35 2019 +0200 @@ -14,8 +14,8 @@ /* Our namespace to invoke python code */ xmlns:ns="beremiz" - extension-element-prefixes="ns" - exclude-result-prefixes="ns str regexp exsl" { + extension-element-prefixes="ns func" + exclude-result-prefixes="ns str regexp exsl func" { /* This retrieves geometry obtained through "inkscape -S" * already parsed by python and presented as a list of @@ -83,6 +83,7 @@ /* copy root node and add geometry as comment for a test */ template "/" { + comment > Made with SVGHMI. https://beremiz.org html xmlns="http://www.w3.org/1999/xhtml" { head; body style="margin:0;" { @@ -105,6 +106,40 @@ } } + func:function name="func:parselabel" { + param "label"; + const "description", "substring-after($label,'HMI:')"; + + const "_args", "substring-before($description,'@')"; + const "args" choose { + when "$_args" value "$_args"; + otherwise value "$description"; + } + + const "_type", "substring-before($args,':')"; + const "type" choose { + when "$_type" value "$_type"; + otherwise value "$args"; + } + + const "ast" if "$type" widget { + attrib "type" > «$type» + foreach "str:split($args, ':')" { + arg { + attrib "value" > «.» + } + } + const "paths", "substring-after($description,'@')"; + foreach "str:split($paths, '@')" { + path { + attrib "value" > «.» + } + } + } + + func:result select="exsl:node-set($ast)" + } + function "scripts" { /* TODO : paste hmitree hash stored in hmi tree root node */ @@ -154,10 +189,10 @@ | var page_desc = { // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI' - foreach "//*[starts-with(@inkscape:label,'HMI:')]" { + foreach "//*[func:parselabel(@inkscape:label)/widget/@type = 'Page']" { | «@inkscape:label» - const "ast" call "parse_label" with "label","@inkscape:label"; - apply "exsl:node-set($ast)", mode="testtree"; + const "ast", "func:parselabel(@inkscape:label)"; + apply "$ast", mode="testtree"; } | } @@ -176,37 +211,6 @@ path value="path2"; } */ - function "parse_label" { - param "label"; - const "description", "substring-after($label,'HMI:')"; - - const "_args", "substring-before($description,'@')"; - const "args" choose { - when "$_args" value "$_args"; - otherwise value "$description"; - } - - const "_type", "substring-before($args,':')"; - const "type" choose { - when "$_type" value "$_type"; - otherwise value "$args"; - } - - if "$type" widget { - attrib "type" > «$type» - foreach "str:split($args, ':')" { - arg { - attrib "value" > «.» - } - } - const "paths", "substring-after($description,'@')"; - foreach "str:split($paths, '@')" { - path { - attrib "value" > «.» - } - } - } - } template "*", mode="page_desc" { } diff -r 0c0d3895b036 -r 2a97688c94c5 yslt_noindent.yml2 --- a/yslt_noindent.yml2 Tue Oct 08 13:27:00 2019 +0200 +++ b/yslt_noindent.yml2 Wed Oct 09 09:04:35 2019 +0200 @@ -12,7 +12,8 @@ xmlns:exsl='http://exslt.org/common', xmlns:regexp="http://exslt.org/regular-expressions", xmlns:str="http://exslt.org/strings", - extension-element-prefixes='exsl regexp str' + xmlns:func="http://exslt.org/functions", + extension-element-prefixes='exsl regexp str func' ) alias stylesheet { output *output; content;