beremiz

SVGHMI: ForEach knows its own widgets
svghmi
2020-03-23, Edouard Tisserant
27dd409fba1d
Parents 8927ae8326b2
Children d57a12b8f5db
SVGHMI: ForEach knows its own widgets
--- a/svghmi/gen_index_xhtml.xslt Fri Mar 20 10:46:15 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Mon Mar 23 10:16:38 2020 +0100
@@ -680,8 +680,29 @@
</xsl:otherwise>
</xsl:choose>
</func:function>
+ <xsl:template mode="widget_defs" match="widget[@type='Display']">
+ <xsl:param name="hmi_element"/>
+ <xsl:text> frequency: 5,
+</xsl:text>
+ <xsl:text> dispatch: function(value) {
+</xsl:text>
+ <xsl:choose>
+ <xsl:when test="$hmi_element[self::svg:text]">
+ <xsl:text> this.element.textContent = String(value);
+</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="no">
+ <xsl:text>Display widget as a group not implemented</xsl:text>
+ </xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> },
+</xsl:text>
+ </xsl:template>
<xsl:template mode="widget_defs" match="widget[@type='ForEach']">
<xsl:param name="hmi_element"/>
+ <xsl:variable name="widgets" select="func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]"/>
<xsl:text> frequency: 2,
</xsl:text>
<xsl:text> dispatch: function(value) {
@@ -710,6 +731,34 @@
</xsl:for-each>
<xsl:text> },
</xsl:text>
+ <xsl:text> widgets: [
+</xsl:text>
+ <xsl:variable name="labels_regex" select="concat('^',arg[1]/@value,':[0-9]+')"/>
+ <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label, $labels_regex)]">
+ <xsl:text> [ /* </xsl:text>
+ <xsl:value-of select="@inkscape:label"/>
+ <xsl:text> */
+</xsl:text>
+ <xsl:variable name="elt" select="."/>
+ <xsl:for-each select="func:refered_elements(.)[@id = $hmi_elements/@id][not(@id = $elt/@id)]">
+ <xsl:text> hmi_widgets["</xsl:text>
+ <xsl:value-of select="@id"/>
+ <xsl:text>"]</xsl:text>
+ <xsl:if test="position()!=last()">
+ <xsl:text>,</xsl:text>
+ </xsl:if>
+ <xsl:text>
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text> ]</xsl:text>
+ <xsl:if test="position()!=last()">
+ <xsl:text>,</xsl:text>
+ </xsl:if>
+ <xsl:text>
+</xsl:text>
+ </xsl:for-each>
+ <xsl:text> ],
+</xsl:text>
</xsl:template>
<xsl:template mode="widget_subscribe" match="widget[@type='ForEach']">
<xsl:text> sub: function(off){
@@ -725,26 +774,6 @@
<xsl:text> },
</xsl:text>
</xsl:template>
- <xsl:template mode="widget_defs" match="widget[@type='Display']">
- <xsl:param name="hmi_element"/>
- <xsl:text> frequency: 5,
-</xsl:text>
- <xsl:text> dispatch: function(value) {
-</xsl:text>
- <xsl:choose>
- <xsl:when test="$hmi_element[self::svg:text]">
- <xsl:text> this.element.textContent = String(value);
-</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="no">
- <xsl:text>Display widget as a group not implemented</xsl:text>
- </xsl:message>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:text> },
-</xsl:text>
- </xsl:template>
<xsl:template mode="widget_defs" match="widget[@type='Input']">
<xsl:param name="hmi_element"/>
<xsl:variable name="value_elt">
--- a/svghmi/widget_foreach.ysl2 Fri Mar 20 10:46:15 2020 +0100
+++ b/svghmi/widget_foreach.ysl2 Mon Mar 23 10:16:38 2020 +0100
@@ -1,6 +1,7 @@
template "widget[@type='ForEach']", mode="widget_defs" {
param "hmi_element";
+ const "widgets", "func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]";
| frequency: 2,
| dispatch: function(value) {
| // do something
@@ -14,15 +15,30 @@
| });
}
| },
+
+ | widgets: [
+ const "labels_regex","concat('^',arg[1]/@value,':[0-9]+')";
+ foreach "$hmi_element/*[regexp:test(@inkscape:label, $labels_regex)]" {
+ | [ /* «@inkscape:label» */
+ const "elt",".";
+ //foreach "$hmi_elements[ancestor::svg:*/@id = $_id]" {
+ foreach "func:refered_elements(.)[@id = $hmi_elements/@id][not(@id = $elt/@id)]" {
+ | hmi_widgets["«@id»"]`if "position()!=last()" > ,`
+ }
+ | ]`if "position()!=last()" > ,`
+ }
+ | ],
}
template "widget[@type='ForEach']", mode="widget_subscribe"{
// param "hmi_element";
| sub: function(off){
- | subscribe.call(this,off)
+ | subscribe.call(this,off);
+ /* TODO */
| },
| unsub: function(){
- | unsubscribe.call(this)
+ | unsubscribe.call(this);
+ /* TODO */
| },
}