--- a/svghmi/gen_index_xhtml.xslt Thu Nov 04 12:02:08 2021 +0100
+++ b/svghmi/gen_index_xhtml.xslt Thu Nov 04 12:03:43 2021 +0100
@@ -3,6 +3,7 @@
<xsl:output cdata-section-elements="xhtml:script" method="xml"/>
<xsl:variable name="svg" select="/svg:svg"/>
<xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
+ <xsl:param name="instance_name"/> <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
<xsl:variable name="_categories">
@@ -39,12 +40,16 @@
+ <xsl:text>var current_page_var_index = </xsl:text> + <xsl:value-of select="$indexed_hmitree/*[@hmipath = concat('/CURRENT_PAGE_', $instance_name)]/@index"/> <xsl:text>var hmitree_types = [
<xsl:for-each select="$indexed_hmitree/*">
- <xsl:text> /* </xsl:text>
- <xsl:value-of select="@index"/>
- <xsl:text> */ "</xsl:text>
+ <xsl:text> "</xsl:text> <xsl:value-of select="substring(local-name(), 5)"/>
<xsl:if test="position()!=last()">
@@ -60,9 +65,7 @@
<xsl:text>var hmitree_paths = [
<xsl:for-each select="$indexed_hmitree/*">
- <xsl:text> /* </xsl:text>
- <xsl:value-of select="@index"/>
- <xsl:text> */ "</xsl:text>
+ <xsl:text> "</xsl:text> <xsl:value-of select="@hmipath"/>
<xsl:if test="position()!=last()">
@@ -75,6 +78,26 @@
+ <xsl:text>var hmitree_nodes = { + <xsl:for-each select="$indexed_hmitree/*[local-name() = 'HMI_NODE']"> + <xsl:text> "</xsl:text> + <xsl:value-of select="@hmipath"/> + <xsl:text>" : [</xsl:text> + <xsl:value-of select="@index"/> + <xsl:text>, "</xsl:text> + <xsl:value-of select="@class"/> + <xsl:text>"]</xsl:text> + <xsl:if test="position()!=last()"> @@ -656,6 +679,10 @@
<xsl:value-of select="$desc/path/@index"/>
+ <xsl:text> page_class: "</xsl:text> + <xsl:value-of select="$indexed_hmitree/*[@hmipath = $desc/path/@value]/@class"/> @@ -8045,17 +8072,17 @@
<xsl:text>// Open WebSocket to relative "/ws" address
+ <xsl:text>var has_watchdog = window.location.hash == "#watchdog"; <xsl:text> window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws')
- <xsl:text> + '?mode=' + (window.location.hash == "#watchdog"
- <xsl:text> ? "watchdog"
- <xsl:text> : "multiclient");
+ <xsl:text> + '?mode=' + (has_watchdog ? "watchdog" : "multiclient"); <xsl:text>var ws = new WebSocket(ws_url);
@@ -8375,23 +8402,45 @@
- <xsl:text>// artificially subscribe the watchdog widget to "/heartbeat" hmi variable
- <xsl:text>// Since dispatch directly calls change_hmi_value,
- <xsl:text>// PLC will periodically send variable at given frequency
- <xsl:text>subscribers(heartbeat_index).add({
- <xsl:text> /* type: "Watchdog", */
+ <xsl:text>if(has_watchdog){ + <xsl:text> // artificially subscribe the watchdog widget to "/heartbeat" hmi variable + <xsl:text> // Since dispatch directly calls change_hmi_value, + <xsl:text> // PLC will periodically send variable at given frequency + <xsl:text> subscribers(heartbeat_index).add({ + <xsl:text> /* type: "Watchdog", */ + <xsl:text> frequency: 1, + <xsl:text> indexes: [heartbeat_index], + <xsl:text> new_hmi_value: function(index, value, oldval) { + <xsl:text> apply_hmi_value(heartbeat_index, value+1); + <xsl:text>// subscribe to per instance current page hmi variable + <xsl:text>subscribers(current_page_var_index).add({ - <xsl:text> indexes: [heartbeat_index],
+ <xsl:text> indexes: [current_page_var_index], <xsl:text> new_hmi_value: function(index, value, oldval) {
- <xsl:text> apply_hmi_value(heartbeat_index, value+1);
+ <xsl:text> switch_page(value); @@ -8787,7 +8836,11 @@
<xsl:text> page_name = current_subscribed_page;
+ <xsl:text> else if(page_index == undefined){ + <xsl:text> [page_name, page_index] = page_name.split('@') @@ -8807,10 +8860,32 @@
- <xsl:text> if(page_index == undefined){
+ <xsl:text> if(page_index == undefined) <xsl:text> page_index = new_desc.page_index;
+ <xsl:text> else if(typeof(page_index) == "string") { + <xsl:text> let hmitree_node = hmitree_nodes[page_index]; + <xsl:text> if(hmitree_node !== undefined){ + <xsl:text> let [int_index, hmiclass] = hmitree_node; + <xsl:text> if(hmiclass == new_desc.page_class) + <xsl:text> page_index = int_index; + <xsl:text> page_index = new_desc.page_index; + <xsl:text> page_index = new_desc.page_index; @@ -8871,6 +8946,16 @@
+ <xsl:text> apply_hmi_value(current_page_var_index, + <xsl:text> page_index == undefined + <xsl:text> : page_name + "@" + hmitree_paths[page_index]);