SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
--- a/svghmi/gen_index_xhtml.xslt Wed Mar 04 16:46:35 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Wed Mar 04 20:02:15 2020 +0100
@@ -423,6 +423,7 @@
</xsl:text>
<xsl:for-each select="$hmi_elements">
<xsl:variable name="widget" select="func:parselabel(@inkscape:label)/widget"/>
+ <xsl:variable name="eltid" select="@id"/>
<xsl:text> "</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>": {
@@ -453,7 +454,11 @@
<xsl:choose>
<xsl:when test="count($hmitree_match) = 0">
<xsl:message terminate="no">
- <xsl:text>No match for path "</xsl:text>
+ <xsl:text>Widget </xsl:text>
+ <xsl:value-of select="$widget/@type"/>
+ <xsl:text> id="</xsl:text>
+ <xsl:value-of select="$eltid"/>
+ <xsl:text>" : No match for path "</xsl:text>
<xsl:value-of select="$hmipath"/>
<xsl:text>" in HMI tree</xsl:text>
</xsl:message>
@@ -1295,12 +1300,21 @@
<xsl:call-template name="defs_by_labels">
<xsl:with-param name="hmi_element" select="$hmi_element"/>
<xsl:with-param name="labels">
- <xsl:text>value min max needle range</xsl:text>
+ <xsl:text>needle range</xsl:text>
</xsl:with-param>
</xsl:call-template>
+ <xsl:call-template name="defs_by_labels">
+ <xsl:with-param name="hmi_element" select="$hmi_element"/>
+ <xsl:with-param name="labels">
+ <xsl:text>value min max</xsl:text>
+ </xsl:with-param>
+ <xsl:with-param name="mandatory" select="'no'"/>
+ </xsl:call-template>
<xsl:text> dispatch: function(value) {
</xsl:text>
- <xsl:text> this.value_elt.textContent = String(value);
+ <xsl:text> if(this.value_elt)
+</xsl:text>
+ <xsl:text> this.value_elt.textContent = String(value);
</xsl:text>
<xsl:text> let [min,max,totallength] = this.range;
</xsl:text>
@@ -1318,7 +1332,11 @@
</xsl:text>
<xsl:text> init: function() {
</xsl:text>
- <xsl:text> this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
+ <xsl:text> let min = this.min_elt ? Number(this.min_elt.textContent) : 0;
+</xsl:text>
+ <xsl:text> let max = this.max_elt ? Number(this.max_elt.textContent) : 100;
+</xsl:text>
+ <xsl:text> this.range = [min, max, this.range_elt.getTotalLength()]
</xsl:text>
<xsl:text> this.origin = this.needle_elt.getPointAtLength(0);
</xsl:text>
--- a/svghmi/gen_index_xhtml.ysl2 Wed Mar 04 16:46:35 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Wed Mar 04 20:02:15 2020 +0100
@@ -535,6 +535,7 @@
| var hmi_widgets = {
foreach "$hmi_elements" {
const "widget", "func:parselabel(@inkscape:label)/widget";
+ const "eltid","@id";
| "«@id»": {
| type: "«$widget/@type»",
| args: [
@@ -547,7 +548,7 @@
const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]";
choose {
when "count($hmitree_match) = 0" {
- warning > No match for path "«$hmipath»" in HMI tree
+ warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«$hmipath»" in HMI tree
}
otherwise {
| «$hmitree_match/@index»`if "position()!=last()" > ,`
@@ -706,9 +707,11 @@
template "widget[@type='Meter']", mode="widget_defs" {
param "hmi_element";
| frequency: 10,
- labels("value min max needle range");
+ labels("needle range");
+ optional_labels("value min max");
| dispatch: function(value) {
- | this.value_elt.textContent = String(value);
+ | if(this.value_elt)
+ | this.value_elt.textContent = String(value);
| let [min,max,totallength] = this.range;
| let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
| let tip = this.range_elt.getPointAtLength(length);
@@ -717,7 +720,9 @@
| origin: undefined,
| range: undefined,
| init: function() {
- | this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
+ | let min = this.min_elt ? Number(this.min_elt.textContent) : 0;
+ | let max = this.max_elt ? Number(this.max_elt.textContent) : 100;
+ | this.range = [min, max, this.range_elt.getTotalLength()]
| this.origin = this.needle_elt.getPointAtLength(0);
| },
}