SVGHMI: Update Widget Display templates to generate Class based declaration.
--- a/svghmi/gen_index_xhtml.xslt Wed Jul 22 13:56:43 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Mon Aug 03 12:08:25 2020 +0200
@@ -1331,25 +1331,29 @@
<xsl:text>},
</xsl:text>
</xsl:template>
+ <xsl:template mode="widget_class" match="widget[@type='Display']">
+ <xsl:text>class DisplayWidget extends Widget{
+</xsl:text>
+ <xsl:text> frequency = 5;
+</xsl:text>
+ <xsl:text> dispatch(value) {
+</xsl:text>
+ <xsl:text> this.element.textContent = String(value);
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <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:if test="$hmi_element[not(self::svg:text)]">
+ <xsl:message terminate="yes">
+ <xsl:text>Display Widget id="</xsl:text>
+ <xsl:value-of select="$hmi_element/@id"/>
+ <xsl:text>" is not a svg::text element</xsl:text>
+ </xsl:message>
+ </xsl:if>
</xsl:template>
<xsl:template mode="widget_defs" match="widget[@type='DropDown']">
<xsl:param name="hmi_element"/>
--- a/svghmi/widget_display.ysl2 Wed Jul 22 13:56:43 2020 +0200
+++ b/svghmi/widget_display.ysl2 Mon Aug 03 12:08:25 2020 +0200
@@ -1,19 +1,18 @@
// widget_display.ysl2
+template "widget[@type='Display']", mode="widget_class"
+ ||
+ class DisplayWidget extends Widget{
+ frequency = 5;
+ dispatch(value) {
+ this.element.textContent = String(value);
+ }
+ }
+ ||
+
template "widget[@type='Display']", mode="widget_defs" {
param "hmi_element";
- | frequency: 5,
- | dispatch: function(value) {
- choose {
- when "$hmi_element[self::svg:text]"{
- // TODO : care about <tspan> ?
- | this.element.textContent = String(value);
- }
- otherwise {
- warning > Display widget as a group not implemented
- }
- }
- | },
-
+ if "$hmi_element[not(self::svg:text)]"
+ error > Display Widget id="«$hmi_element/@id»" is not a svg::text element
}