--- 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 @@
-<xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns" extension-element-prefixes="ns" version="1.0">
+<xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns str regexp exsl" extension-element-prefixes="ns" version="1.0"> <xsl:output method="xml" cdata-section-elements="script"/>
<xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
<xsl:variable name="hmitree" select="ns:GetHMITree()"/>
@@ -99,161 +99,244 @@
<xsl:apply-templates mode="identity_svg" select="@* | node()"/>
- <xsl:text>var subscriptions = {
- <xsl:variable name="svg" select="/"/>
- <xsl:for-each select="$indexed_hmitree/*">
- <xsl:value-of select="@index"/>
- <xsl:text> name: "</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text> hmipath: "</xsl:text>
- <xsl:value-of select="@hmipath"/>
- <xsl:variable name="hmipath" select="@hmipath"/>
- <xsl:for-each select="$svg//*[substring-after(@inkscape:label,'@') = $hmipath]">
- <xsl:text> "</xsl:text>
- <xsl:value-of select="@id"/>
- <xsl:if test="position()!=last()">
- <xsl:if test="position()!=last()">
- <xsl:text> // Open WebSocket to relative "/ws" address
- <xsl:text> var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws'));
- <xsl:text> // Register message reception handler
- <xsl:text> ws.onmessage = function (evt) {
- <xsl:text> // TODO : dispatch and cache hmi tree updates
- <xsl:text> var received_msg = evt.data;
- <xsl:text> // TODO : check for hmitree hash header
- <xsl:text> // if not matching, reload page
- <xsl:text> alert("Message is received..."+received_msg);
- <xsl:text> // Once connection established
- <xsl:text> ws.onopen = function (evt) {
- <xsl:text> // TODO : enable the HMI (was previously offline, or just starts)
- <xsl:text> // show main page
- <xsl:text> // TODO : prefix with hmitree hash header
- <xsl:text> ws.send("test");
- <xsl:text> var pending_updates = {};
- <xsl:text> // subscription state, as it should be in hmi server
- <xsl:text> // expected {index:period}
- <xsl:text> var subscriptions = {};
- <xsl:text> // subscription state as needed by widget now
- <xsl:text> // expected {index:[widgets]};
- <xsl:text> var subscribers = {};
- <xsl:text> // return the diff in between curently subscribed and subscription
- <xsl:text> function update_subscriptions() {
- <xsl:text> let result = [];
- <xsl:text> Object.keys(subscribers).forEach(index => {
- <xsl:text> let previous_period = subscriptions[index];
- <xsl:text> let new_period = Math.min(...widgets.map(widget => widget.period));
- <xsl:text> if(previous_period != new_period)
- <xsl:text> result.push({index: index, period: new_period});
- <xsl:text> function update_value(index, value) {
+ <xsl:call-template name="scripts"/> + <xsl:template name="scripts"> + <xsl:text>var hmi_index = { + <xsl:variable name="svg" select="/"/> + <xsl:for-each select="$indexed_hmitree/*"> + <xsl:value-of select="@index"/> + <xsl:text> name: "</xsl:text> + <xsl:value-of select="@name"/> + <xsl:text> hmipath: "</xsl:text> + <xsl:value-of select="@hmipath"/> + <xsl:variable name="hmipath" select="@hmipath"/> + <xsl:for-each select="$svg//*[substring-after(@inkscape:label,'@') = $hmipath]"> + <xsl:text> "</xsl:text> + <xsl:value-of select="@id"/> + <xsl:if test="position()!=last()"> + <xsl:if test="position()!=last()"> + <xsl:text>var page_desc = { + <xsl:for-each select="//*[starts-with(@inkscape:label,'HMI:')]"> + <xsl:value-of select="@inkscape:label"/> + <xsl:variable name="ast"> + <xsl:call-template name="parse_label"> + <xsl:with-param name="label" select="@inkscape:label"/> + <xsl:apply-templates mode="testtree" select="exsl:node-set($ast)"/> + <xsl:text> // Open WebSocket to relative "/ws" address + <xsl:text> var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws')); + <xsl:text> // Register message reception handler + <xsl:text> ws.onmessage = function (evt) { + <xsl:text> // TODO : dispatch and cache hmi tree updates + <xsl:text> var received_msg = evt.data; + <xsl:text> // TODO : check for hmitree hash header + <xsl:text> // if not matching, reload page + <xsl:text> alert("Message is received..."+received_msg); + <xsl:text> // Once connection established + <xsl:text> ws.onopen = function (evt) { + <xsl:text> // TODO : enable the HMI (was previously offline, or just starts) + <xsl:text> // show main page + <xsl:text> // TODO : prefix with hmitree hash header + <xsl:text> ws.send("test"); + <xsl:text> var pending_updates = {}; + <xsl:text> // subscription state, as it should be in hmi server + <xsl:text> // expected {index:period} + <xsl:text> const subscriptions = new Map(); + <xsl:text> // subscription state as needed by widget now + <xsl:text> // expected {index:[widgets]}; + <xsl:text> var subscribers = {}; + <xsl:text> // return the diff in between curently subscribed and subscription + <xsl:text> function update_subscriptions() { + <xsl:text> let delta = []; + <xsl:text> Object.keys(subscribers).forEach(index => { + <xsl:text> let previous_period = subscriptions.get(index); + <xsl:text> delete subscriptions[index]; + <xsl:text> let new_period = Math.min(...widgets.map(widget => widget.period)); + <xsl:text> if(previous_period != new_period) + <xsl:text> delta.push({index: index, period: new_period}); + <xsl:text> return result; + <xsl:text> function update_value(index, value) { + <xsl:text> function switch_page(page_name) { + <xsl:template name="parse_label"> + <xsl:param name="label"/> + <xsl:variable name="description" select="substring-after($label,'HMI:')"/> + <xsl:variable name="_args" select="substring-before($description,'@')"/> + <xsl:variable name="args"> + <xsl:when test="$_args"> + <xsl:value-of select="$_args"/> + <xsl:value-of select="$description"/> + <xsl:variable name="_type" select="substring-before($args,':')"/> + <xsl:variable name="type"> + <xsl:when test="$_type"> + <xsl:value-of select="$_type"/> + <xsl:value-of select="$args"/> + <xsl:attribute name="type"> + <xsl:value-of select="$type"/> + <xsl:for-each select="str:split($args, ':')"> + <xsl:attribute name="value"> + <xsl:value-of select="."/> + <xsl:variable name="paths" select="substring-after($description,'@')"/> + <xsl:for-each select="str:split($paths, '@')"> + <xsl:attribute name="value"> + <xsl:value-of select="."/> + <xsl:template mode="page_desc" match="*"/> <xsl:template mode="code_from_descs" match="*">
--- 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");
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 */
- 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 * <bbox x="0" y="0" w="42" h="42">
const "geometry", "ns:GetSVGGeometry()";
@@ -82,70 +82,133 @@
/* copy root node and add geometry as comment for a test */
- html xmlns="http://www.w3.org/1999/xhtml" {
- body style="margin:0;" {
- apply "$geometry", mode="testgeo";
- apply "$hmitree", mode="testtree";
- apply "$indexed_hmitree", mode="testtree";
- apply "@* | node()", mode="identity_svg";
- /* TODO : paste hmitree hash stored in hmi tree root node */
+ html xmlns="http://www.w3.org/1999/xhtml" { + body style="margin:0;" { + apply "$geometry", mode="testgeo"; + apply "$hmitree", mode="testtree"; + apply "$indexed_hmitree", mode="testtree"; + apply "@* | node()", mode="identity_svg"; + /* TODO : paste hmitree hash stored in hmi tree root node */ + function evaluate_js_from_descriptions() { + const "midmark" > \n«$mark» + apply """//*[contains(child::svg:desc, $midmark) or \ + starts-with(child::svg:desc, $mark)]""",2 + mode="code_from_descs";
- function evaluate_js_from_descriptions() {
- const "midmark" > \n«$mark»
- apply """//*[contains(child::svg:desc, $midmark) or \
- starts-with(child::svg:desc, $mark)]""",2
- mode="code_from_descs";
+ const "svg","/"; /* foreach loses document root */ + foreach "$indexed_hmitree/*" { + | hmipath: "«@hmipath»" + const "hmipath","@hmipath"; + foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" { + | "«@id»"`if "position()!=last()" > ,` + | }`if "position()!=last()" > ,` + // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI' + foreach "//*[starts-with(@inkscape:label,'HMI:')]" { + const "ast" call "parse_label" with "label","@inkscape:label"; + apply "exsl:node-set($ast)", mode="testtree"; + "HMI:WidgetType:param1:param2@path1@path2"
+ widget type="WidgetType" { + function "parse_label" { + const "description", "substring-after($label,'HMI:')"; - | var subscriptions = {
+ const "_args", "substring-before($description,'@')"; + when "$_args" value "$_args"; + otherwise value "$description"; - const "svg","/"; /* foreach loses document root */
- foreach "$indexed_hmitree/*" {
- | hmipath: "«@hmipath»"
- const "hmipath","@hmipath";
- foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" {
- | "«@id»"`if "position()!=last()" > ,`
- | }`if "position()!=last()" > ,`
+ const "_type", "substring-before($args,':')"; + when "$_type" value "$_type"; + otherwise value "$args";
+ attrib "type" > «$type» + foreach "str:split($args, ':')" { + const "paths", "substring-after($description,'@')"; + foreach "str:split($paths, '@')" {
+ template "*", mode="page_desc" { template "*", mode="code_from_descs" {