# HG changeset patch # User Edouard Tisserant # Date 1570534020 -7200 # Node ID 0c0d3895b0364f6a06393e52fe6cd18a69fbb949 # Parent d022523cb621068498caa1af9445096fa20d0d9e SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels diff -r d022523cb621 -r 0c0d3895b036 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Oct 07 12:02:45 2019 +0200 +++ b/svghmi/gen_index_xhtml.xslt Tue Oct 08 13:27:00 2019 +0200 @@ -1,5 +1,5 @@ - + @@ -99,161 +99,244 @@ + + 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 d022523cb621 -r 0c0d3895b036 svghmi/gen_index_xhtml.ysl2 --- a/svghmi/gen_index_xhtml.ysl2 Mon Oct 07 12:02:45 2019 +0200 +++ b/svghmi/gen_index_xhtml.ysl2 Tue Oct 08 13:27:00 2019 +0200 @@ -2,7 +2,8 @@ // overrides yslt's output function to set CDATA decl output(method, cdata-section-elements="script"); -istylesheet + +istylesheet /* From Inkscape */ xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" @@ -10,15 +11,14 @@ xmlns:svg="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - xmlns:xhtml="http://www.w3.org/1999/xhtml" /* Our namespace to invoke python code */ xmlns:ns="beremiz" - extension-element-prefixes="ns" - exclude-result-prefixes="ns" { - - /* This retrieves geometry obtained through "inkscape -S" - * already parsed by python and presented as a list of + extension-element-prefixes="ns" + exclude-result-prefixes="ns str regexp exsl" { + + /* This retrieves geometry obtained through "inkscape -S" + * already parsed by python and presented as a list of * */ const "geometry", "ns:GetSVGGeometry()"; @@ -82,70 +82,133 @@ const "mark" > =HMI=\n /* copy root node and add geometry as comment for a test */ - template "/" - html xmlns="http://www.w3.org/1999/xhtml" { - head; - body style="margin:0;" { - xsl:copy { - comment { - apply "$geometry", mode="testgeo"; - } - comment { - apply "$hmitree", mode="testtree"; - } - comment { - apply "$indexed_hmitree", mode="testtree"; - } - apply "@* | node()", mode="identity_svg"; - } - script{ - /* TODO : paste hmitree hash stored in hmi tree root node */ - - /* TODO re-enable - || - function evaluate_js_from_descriptions() { - var Page; - var Input; - var Display; - var res = []; - || - const "midmark" > \n«$mark» - apply """//*[contains(child::svg:desc, $midmark) or \ - starts-with(child::svg:desc, $mark)]""",2 - mode="code_from_descs"; - || - return res; - } - || - */ - - /*TODO add : - - pages content - + with ref to elt ? - - widgets parameters - */ - - | var subscriptions = { - - const "svg","/"; /* foreach loses document root */ - foreach "$indexed_hmitree/*" { - | «@index»: { - | name: "«@name»", - | hmipath: "«@hmipath»" - | ids: [ - const "hmipath","@hmipath"; - foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" { - | "«@id»"`if "position()!=last()" > ,` - } - | ] - | }`if "position()!=last()" > ,` - } - - | } - - include text svghmi.js - } - } + template "/" { + html xmlns="http://www.w3.org/1999/xhtml" { + head; + body style="margin:0;" { + xsl:copy { + comment { + apply "$geometry", mode="testgeo"; + } + comment { + apply "$hmitree", mode="testtree"; + } + comment { + apply "$indexed_hmitree", mode="testtree"; + } + apply "@* | node()", mode="identity_svg"; + } + script{ + call "scripts"; + } + } + } + } + + function "scripts" + { + /* TODO : paste hmitree hash stored in hmi tree root node */ + + /* TODO re-enable + || + function evaluate_js_from_descriptions() { + var Page; + var Input; + var Display; + var res = []; + || + const "midmark" > \n«$mark» + apply """//*[contains(child::svg:desc, $midmark) or \ + starts-with(child::svg:desc, $mark)]""",2 + mode="code_from_descs"; + || + return res; + } + || + */ + + /*TODO add : + - pages content + + with ref to elt ? + - widgets parameters + */ + + | var hmi_index = { + + const "svg","/"; /* foreach loses document root */ + foreach "$indexed_hmitree/*" { + | «@index»: { + | name: "«@name»", + | hmipath: "«@hmipath»" + | ids: [ + const "hmipath","@hmipath"; + foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" { + | "«@id»"`if "position()!=last()" > ,` + } + | ] + | }`if "position()!=last()" > ,` + } + + | } + | + | var page_desc = { + + // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI' + foreach "//*[starts-with(@inkscape:label,'HMI:')]" { + | «@inkscape:label» + const "ast" call "parse_label" with "label","@inkscape:label"; + apply "exsl:node-set($ast)", mode="testtree"; + } + | } + + include text svghmi.js + } + + /* + Parses: + "HMI:WidgetType:param1:param2@path1@path2" + + Into: + widget type="WidgetType" { + arg value="param1"; + arg value="param2"; + path value="path1"; + 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" { } template "*", mode="code_from_descs" {