--- a/svghmi/gen_index_xhtml.xslt Fri May 08 16:47:52 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Fri May 08 16:51:43 2020 +0200
@@ -1,6 +1,6 @@
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 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" xmlns:debug="debug" xmlns:preamble="preamble" xmlns:declarations="declarations" xmlns:definitions="definitions" xmlns:epilogue="epilogue" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions">
- <xsl:output cdata-section-elements="xhtml:script" method="xml"/>
+<xsl:stylesheet xmlns:ns="beremiz" xmlns:definitions="definitions" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:func="http://exslt.org/functions" xmlns:epilogue="epilogue" xmlns:preamble="preamble" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:svg="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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:declarations="declarations" xmlns:debug="debug" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0"> + <xsl:output method="xml" cdata-section-elements="xhtml:script"/> <xsl:variable name="svg" select="/svg:svg"/>
<xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
<xsl:variable name="hmitree" select="ns:GetHMITree()"/>
@@ -19,6 +19,14 @@
<xsl:variable name="indexed_hmitree" select="exsl:node-set($_indexed_hmitree)"/>
<xsl:template match="preamble:hmi-tree">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var hmi_hash = [</xsl:text>
<xsl:value-of select="$hmitree/@hash"/>
@@ -51,6 +59,8 @@
<xsl:template mode="index" match="*">
<xsl:param name="index" select="0"/>
@@ -215,6 +225,14 @@
<xsl:template match="debug:hmi-tree">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:apply-templates mode="testtree" select="$hmitree"/>
@@ -229,10 +247,20 @@
<xsl:copy-of select="_parsed_widgets"/>
<xsl:apply-templates mode="testtree" select="$parsed_widgets"/>
<xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
<xsl:template match="debug:geometry">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:for-each select="$geometry">
@@ -249,6 +277,8 @@
<func:function name="func:intersect_1d">
@@ -322,10 +352,20 @@
<xsl:template match="preamble:default-page">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var default_page = "</xsl:text>
<xsl:value-of select="$default_page"/>
<xsl:variable name="keypads_descs" select="$parsed_widgets/widget[@type = 'Keypad']"/>
<xsl:variable name="keypads" select="$hmi_elements[@id = $keypads_descs/@id]"/>
@@ -387,6 +427,14 @@
<xsl:template match="declarations:detachable-elements">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var detachable_elements = {
<xsl:for-each select="$detachable_elements">
@@ -405,6 +453,8 @@
<xsl:variable name="forEach_widgets_ids" select="$parsed_widgets/widget[@type = 'ForEach']/@id"/>
<xsl:variable name="forEach_widgets" select="$hmi_elements[@id = $forEach_widgets_ids]"/>
@@ -531,17 +581,35 @@
<xsl:template match="declarations:page-desc">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var page_desc = {
<xsl:apply-templates mode="page_desc" select="$hmi_pages"/>
<xsl:template mode="per_page_widget_template" match="*"/>
<debug:detachable-pages/>
<xsl:template match="debug:detachable-pages">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:for-each select="$detachable_elements">
@@ -558,6 +626,8 @@
<xsl:template mode="inline_svg" match="@* | node()">
<xsl:if test="not(@id = $discardable_elements/@id)">
@@ -672,17 +742,35 @@
<xsl:variable name="result_svg_ns" select="exsl:node-set($result_svg)"/>
<xsl:template match="preamble:inline-svg">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>let id = document.getElementById.bind(document);
<xsl:text>var svg_root = id("</xsl:text>
<xsl:value-of select="$svg/@id"/>
<xsl:template match="debug:clone-unlinking">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:for-each select="$to_unlink">
@@ -690,17 +778,17 @@
<xsl:template mode="hmi_elements" match="svg:*">
<xsl:variable name="widget" select="func:widget(@id)"/>
<xsl:variable name="eltid" select="@id"/>
<xsl:value-of select="@id"/>
- <xsl:text> type: "</xsl:text>
+ <xsl:text>": new </xsl:text> <xsl:value-of select="$widget/@type"/>
@@ -759,20 +847,99 @@
<xsl:apply-templates mode="widget_subscribe" select="$widget">
<xsl:with-param name="hmi_element" select="."/>
- <xsl:text> }</xsl:text>
+ <xsl:text> })</xsl:text> <xsl:if test="position()!=last()">
+ <func:function name="func:unique_types"> + <xsl:param name="elts_with_type"/> + <xsl:when test="count($elts_with_type) > 1"> + <xsl:variable name="prior_results" select="func:unique_types($elts_with_type[position()!=last()])"/> + <xsl:when test="$elts_with_type[last()][@type = $prior_results/@type]"> + <func:result select="$prior_results"/> + <func:result select="$prior_results | $elts_with_type[last()]"/> + <func:result select="$elts_with_type"/> + <preamble:widget-base-class/> + <xsl:template match="preamble:widget-base-class"> + <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> + <xsl:text>class Widget { + <xsl:text> constructor(members){ + <xsl:text> Object.keys(members).forEach(prop => this[prop]=members[prop]); + <preamble:hmi-classes/> + <xsl:template match="preamble:hmi-classes"> + <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> + <xsl:variable name="used_widget_types" select="func:unique_types($parsed_widgets/widget)"/> + <xsl:apply-templates mode="widget_class" select="$used_widget_types"/> + <xsl:template mode="widget_class" match="widget"> + <xsl:text>class </xsl:text> + <xsl:value-of select="@type"/> + <xsl:text>Widget extends Widget{ + <xsl:text> /* empty class, as </xsl:text> + <xsl:value-of select="@type"/> + <xsl:text> widget didn't provide any */ <xsl:template match="preamble:hmi-elements">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var hmi_widgets = {
<xsl:apply-templates mode="hmi_elements" select="$hmi_elements"/>
<xsl:template mode="widget_subscribe" match="widget">
<xsl:text> sub: subscribe,
@@ -1671,6 +1838,14 @@
<xsl:template match="definitions:foreach">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>function foreach_unsubscribe(){
<xsl:text> for(let item of this.items){
@@ -1777,6 +1952,8 @@
<xsl:template mode="widget_defs" match="widget[@type='Input']">
<xsl:param name="hmi_element"/>
@@ -2083,6 +2260,14 @@
<xsl:template match="declarations:jump">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var jumps_need_update = false;
<xsl:text>var jump_history = [[default_page, undefined]];
@@ -2099,11 +2284,21 @@
<xsl:template match="declarations:keypad">
+ <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> <xsl:text>var keypads = {
<xsl:for-each select="$keypads_descs">
@@ -2124,6 +2319,8 @@
<xsl:template mode="widget_defs" match="widget[@type='Keypad']">
<xsl:param name="hmi_element"/>
@@ -2453,15 +2650,10 @@
<xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
- <xsl:for-each select="document('')/*/debug:*">
- <xsl:value-of select="local-name()"/>
- <xsl:apply-templates select="."/>
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <xsl:apply-templates select="document('')/*/debug:*"/> + <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml"> <body style="margin:0;overflow:hidden;">
<xsl:copy-of select="$result_svg"/>
--- a/svghmi/widgets_common.ysl2 Fri May 08 16:47:52 2020 +0200
+++ b/svghmi/widgets_common.ysl2 Fri May 08 16:51:43 2020 +0200
@@ -24,8 +24,7 @@
template "svg:*", mode="hmi_elements" {
const "widget", "func:widget(@id)";
- | type: "«$widget/@type»",
+ | "«@id»": new «$widget/@type»Widget ({ | "«@value»"`if "position()!=last()" > ,`
@@ -46,7 +45,8 @@
apply "$widget", mode="widget_defs" with "hmi_element",".";
apply "$widget", mode="widget_subscribe" with "hmi_element",".";
- | }`if "position()!=last()" > ,`
+ | })`if "position()!=last()" > ,` def "func:unique_types" {
@@ -69,17 +69,35 @@
+emit "preamble:widget-base-class" { + Object.keys(members).forEach(prop => this[prop]=members[prop]); emit "preamble:hmi-classes" {
const "used_widget_types", "func:unique_types($parsed_widgets/widget)";
apply "$used_widget_types", mode="widget_class";
+template "widget", mode="widget_class" +class «@type»Widget extends Widget{ + /* empty class, as «@type» widget didn't provide any */ emit "preamble:hmi-elements" {
apply "$hmi_elements", mode="hmi_elements";
// default : normal subscribing
template "widget", mode="widget_subscribe" {