--- a/svghmi/analyse_widget.xslt Wed Nov 23 11:30:30 2022 +0100
+++ b/svghmi/analyse_widget.xslt Wed Nov 23 11:34:15 2022 +0100
@@ -854,6 +854,46 @@
<xsl:text>Value to display</xsl:text>
+ <xsl:template match="widget[@type='Page']" mode="widget_desc"> + <xsl:value-of select="@type"/> + <xsl:text>Arguments are either: + <xsl:text>- XXX reference path TODO + <xsl:text>- name=value: setting variable with literal value. + <xsl:text>- name=other_name: copy variable content into another + <xsl:text>"active"+"inactive" labeled elements can be provided to show feedback when pressed + <xsl:text>HMI:Page:notify=1@notify=/PLCVAR + <xsl:text>HMI:Page:ack=2:notify=1@ack=.local_var@notify=/PLCVAR + <xsl:text>Page </xsl:text> <xsl:template match="widget[@type='PathSlider']" mode="widget_desc">
<xsl:value-of select="@type"/>
--- a/svghmi/gen_index_xhtml.xslt Wed Nov 23 11:30:30 2022 +0100
+++ b/svghmi/gen_index_xhtml.xslt Wed Nov 23 11:34:15 2022 +0100
@@ -734,6 +734,21 @@
<xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages | $keypads)"/>
<xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
+ <declarations:page-class/> + <xsl:template match="declarations:page-class"> + <xsl:text>/* </xsl:text> + <xsl:value-of select="local-name()"/> + <xsl:text>class PageWidget extends Widget{} <declarations:detachable-elements/>
<xsl:template match="declarations:detachable-elements">
@@ -787,7 +802,15 @@
<xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/>
<xsl:variable name="all_page_widgets" select="$hmi_widgets[@id = $page_all_elements/@id and @id != $page/@id]"/>
<xsl:variable name="page_managed_widgets" select="$all_page_widgets[not(@id=$in_forEach_widget_ids)]"/>
- <xsl:variable name="page_relative_widgets" select="$page_managed_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]"/>
+ <xsl:variable name="page_root_path" select="$desc/path[not(@assign)]"/> + <xsl:if test="count($page_root_path)>1"> + <xsl:message terminate="yes"> + <xsl:text>Page id="</xsl:text> + <xsl:value-of select="$page/@id"/> + <xsl:text>" : only one root path can be declared</xsl:text> + <xsl:variable name="page_relative_widgets" select="$page_managed_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $page_root_path/@value)]"/> <xsl:variable name="sumarized_page" select="func:sumarized_elements($page_all_elements)"/>
<xsl:variable name="required_detachables" select="$sumarized_page/ ancestor-or-self::*[@id = $detachable_elements/@id]"/>
@@ -804,31 +827,35 @@
<xsl:value-of select="$p/@h"/>
- <xsl:if test="$desc/path/@value">
- <xsl:if test="count($desc/path/@index)=0">
+ <xsl:if test="count($page_root_path)=1"> + <xsl:if test="count($page_root_path/@index)=0"> <xsl:message terminate="no">
<xsl:text>Page id="</xsl:text>
<xsl:value-of select="$page/@id"/>
<xsl:text>" : No match for path "</xsl:text>
- <xsl:value-of select="$desc/path/@value"/>
+ <xsl:value-of select="$page_root_path/@value"/> <xsl:text>" in HMI tree</xsl:text>
<xsl:text> page_index: </xsl:text>
- <xsl:value-of select="$desc/path/@index"/>
+ <xsl:value-of select="$page_root_path/@index"/> <xsl:text> page_class: "</xsl:text>
- <xsl:value-of select="$indexed_hmitree/*[@hmipath = $desc/path/@value]/@class"/>
+ <xsl:value-of select="$indexed_hmitree/*[@hmipath = $page_root_path/@value]/@class"/> + <xsl:text> [hmi_widgets["</xsl:text> + <xsl:value-of select="$page/@id"/> <xsl:for-each select="$page_managed_widgets">
<xsl:variable name="widget_paths_relativeness">
<xsl:for-each select="func:widget(@id)/path">
- <xsl:value-of select="func:is_descendant_path(@value, $desc/path/@value)"/>
+ <xsl:value-of select="func:is_descendant_path(@value, $page_root_path/@value)"/> <xsl:if test="position()!=last()">
@@ -1440,7 +1467,7 @@
<xsl:if test="$widget/@enable_expr">
- <xsl:text> assignments: [],
+ <xsl:text> enable_assignments: [], <xsl:text> compute_enable: function(value, oldval, varnum) {
@@ -1456,13 +1483,13 @@
<xsl:if test="$varid = generate-id()">
<xsl:text> if(varnum == </xsl:text>
<xsl:value-of select="$varnum"/>
- <xsl:text>) this.assignments[</xsl:text>
+ <xsl:text>) this.enable_assignments[</xsl:text> <xsl:value-of select="position()-1"/>
<xsl:text> let </xsl:text>
<xsl:value-of select="@assign"/>
- <xsl:text> = this.assignments[</xsl:text>
+ <xsl:text> = this.enable_assignments[</xsl:text> <xsl:value-of select="position()-1"/>
@@ -2388,7 +2415,9 @@
<xsl:variable name="included_ids" select="$parsed_widgets/widget[not(@type = $excluded_types) and not(@id = $discardable_elements/@id)]/@id"/>
+ <xsl:variable name="page_ids" select="$parsed_widgets/widget[@type = 'Page']/@id"/> <xsl:variable name="hmi_widgets" select="$hmi_elements[@id = $included_ids]"/>
+ <xsl:variable name="page_widgets" select="$hmi_elements[@id = $page_ids]"/> <xsl:variable name="result_widgets" select="$result_svg_ns//*[@id = $hmi_widgets/@id]"/>
<declarations:hmi-elements/>
<xsl:template match="declarations:hmi-elements">
@@ -2402,7 +2431,7 @@
<xsl:text>var hmi_widgets = {
- <xsl:apply-templates mode="hmi_widgets" select="$hmi_widgets"/>
+ <xsl:apply-templates mode="hmi_widgets" select="$hmi_widgets | $page_widgets"/> @@ -6367,10 +6396,10 @@
<xsl:variable name="target_page_path">
- <xsl:value-of select="$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value"/>
+ <xsl:value-of select="$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[not(@assign)]/@value"/> - <xsl:value-of select="$page_desc/path[1]/@value"/>
+ <xsl:value-of select="$page_desc/path[not(@assign)]/@value"/> @@ -7195,6 +7224,128 @@
+ <xsl:template match="widget[@type='Page']" mode="widget_desc"> + <xsl:value-of select="@type"/> + <xsl:text>Arguments are either: + <xsl:text>- XXX reference path TODO + <xsl:text>- name=value: setting variable with literal value. + <xsl:text>- name=other_name: copy variable content into another + <xsl:text>"active"+"inactive" labeled elements can be provided to show feedback when pressed + <xsl:text>HMI:Page:notify=1@notify=/PLCVAR + <xsl:text>HMI:Page:ack=2:notify=1@ack=.local_var@notify=/PLCVAR + <xsl:text>Page </xsl:text> + <xsl:template match="widget[@type='Page']" mode="widget_defs"> + <xsl:param name="hmi_element"/> + <xsl:variable name="disability"> + <xsl:call-template name="defs_by_labels"> + <xsl:with-param name="hmi_element" select="$hmi_element"/> + <xsl:with-param name="labels"> + <xsl:text>/disabled</xsl:text> + <xsl:with-param name="mandatory" select="'no'"/> + <xsl:value-of select="$disability"/> + <xsl:variable name="has_disability" select="string-length($disability)>0"/> + <xsl:text> assignments: {}, + <xsl:text> dispatch: function(value, oldval, varnum) { + <xsl:variable name="widget" select="."/> + <xsl:for-each select="path"> + <xsl:variable name="varid" select="generate-id()"/> + <xsl:variable name="varnum" select="position()-1"/> + <xsl:if test="@assign"> + <xsl:for-each select="$widget/path[@assign]"> + <xsl:if test="$varid = generate-id()"> + <xsl:text> if(varnum == </xsl:text> + <xsl:value-of select="$varnum"/> + <xsl:text>) this.assignments["</xsl:text> + <xsl:value-of select="@assign"/> + <xsl:text> assign: function() { + <xsl:variable name="paths" select="path"/> + <xsl:for-each select="arg[contains(@value,'=')]"> + <xsl:variable name="name" select="substring-before(@value,'=')"/> + <xsl:variable name="value" select="substring-after(@value,'=')"/> + <xsl:variable name="index"> + <xsl:for-each select="$paths"> + <xsl:if test="@assign = $name"> + <xsl:value-of select="position()-1"/> + <xsl:variable name="isVarName" select="regexp:test($value,'^[a-zA-Z_][a-zA-Z0-9_]+$')"/> + <xsl:when test="$isVarName"> + <xsl:text> const </xsl:text> + <xsl:value-of select="$value"/> + <xsl:text> = this.assignments["</xsl:text> + <xsl:value-of select="$value"/> + <xsl:text> if(</xsl:text> + <xsl:value-of select="$value"/> + <xsl:text> != undefined) + <xsl:text> this.apply_hmi_value(</xsl:text> + <xsl:value-of select="$index"/> + <xsl:text>, </xsl:text> + <xsl:value-of select="$value"/> + <xsl:text> this.apply_hmi_value(</xsl:text> + <xsl:value-of select="$index"/> + <xsl:text>, </xsl:text> + <xsl:value-of select="$value"/> <xsl:template match="widget[@type='PathSlider']" mode="widget_desc">
<xsl:value-of select="@type"/>
@@ -12322,6 +12473,12 @@
+ <xsl:text> // when entering a page, assignments are evaluated + <xsl:text> new_desc.widgets[0][0].assign();