# HG changeset patch
# User Edouard Tisserant
# Date 1581583415 -3600
# Node ID ce6cecdb7320a844e3d4ad9b46580c91909169eb
# Parent bc666f020ab34e2435e5a437d25c2845482ba436
SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
diff -r bc666f020ab3 -r ce6cecdb7320 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Thu Feb 13 09:41:43 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Thu Feb 13 09:43:35 2020 +0100
@@ -386,6 +386,10 @@
}*/
+ } catch(err) {
+
+ console.log(err);
+
}
}
@@ -434,9 +438,7 @@
} catch(err) {
- console.log("Widget initialization error : "+err.message);
-
-
+ console.log(err);
}
@@ -929,19 +931,25 @@
-
-
-
- widget must have a
+
+
+
+
+
+ widget must have a
+
+ element
+
+
+
+
- element
-
-
-
- _elt: document.getElementById("
-
- "),
-
+ _elt: document.getElementById("
+
+ "),
+
+
+
@@ -1016,18 +1024,26 @@
- frequency: 5,
-
-
-
-
- value
-
-
+
+
+
+
+ value
+
+
+
+
+
+
+ frequency: 5,
+
+
dispatch: function(value) {
- this.value_elt.textContent = String(value);
-
+
+ this.value_elt.textContent = String(value);
+
+
},
diff -r bc666f020ab3 -r ce6cecdb7320 svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.ysl2 Thu Feb 13 09:41:43 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Thu Feb 13 09:43:35 2020 +0100
@@ -8,6 +8,12 @@
with "labels"{text *ptr};
};
+in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template {
+ with "hmi_element", "$hmi_element";
+ with "labels"{text *ptr};
+ with "mandatory","'no'";
+};
+
istylesheet
/* From Inkscape */
xmlns:dc="http://purl.org/dc/elements/1.1/"
@@ -337,9 +343,18 @@
foreach "str:split($labels)" {
const "name",".";
const "elt_id","$hmi_element//*[@inkscape:label=$name][1]/@id";
- if "$mandatory='yes' and not($elt_id)"
- warning > «$widget_type» widget must have a «$name» element
- | «$name»_elt: document.getElementById("«$elt_id»"),
+ choose {
+ when "not($elt_id)" {
+ if "$mandatory='yes'" {
+ // TODO FIXME error > «$widget_type» widget must have a «$name» element
+ warning > «$widget_type» widget must have a «$name» element
+ }
+ // otherwise produce nothing
+ }
+ otherwise {
+ | «$name»_elt: document.getElementById("«$elt_id»"),
+ }
+ }
}
}
@@ -397,9 +412,14 @@
template "widget[@type='Input']", mode="widget_defs" {
param "hmi_element";
- | frequency: 5,
- labels("value");
+ const "value_elt" {
+ optional_labels("value");
+ }
+ value "$value_elt";
+ if "$value_elt"
+ | frequency: 5,
| dispatch: function(value) {
+ if "$value_elt"
| this.value_elt.textContent = String(value);
| },
const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id";
diff -r bc666f020ab3 -r ce6cecdb7320 svghmi/svghmi.js
--- a/svghmi/svghmi.js Thu Feb 13 09:41:43 2020 +0100
+++ b/svghmi/svghmi.js Thu Feb 13 09:43:35 2020 +0100
@@ -14,6 +14,8 @@
/*else {
throw new Error("Dunno how to dispatch to widget at index = " + index);
}*/
+ } catch(err) {
+ console.log(err);
}
}
@@ -38,8 +40,7 @@
try {
init.call(widget);
} catch(err) {
- console.log("Widget initialization error : "+err.message);
-
+ console.log(err);
}
}
});