beremiz

SVGHMI: added widget_common.ysl2
svghmi
2020-03-17, Edouard Tisserant
3bb49f93d48c
Parents 9da4ac0c9add
Children ac08a5d15c15
SVGHMI: added widget_common.ysl2
--- a/svghmi/gen_index_xhtml.xslt Tue Mar 17 13:43:19 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Tue Mar 17 14:01:37 2020 +0100
@@ -527,6 +527,103 @@
</xsl:text>
</xsl:for-each>
</xsl:template>
+ <xsl:template mode="hmi_elements" match="svg:*">
+ <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>": {
+</xsl:text>
+ <xsl:text> type: "</xsl:text>
+ <xsl:value-of select="$widget/@type"/>
+ <xsl:text>",
+</xsl:text>
+ <xsl:text> args: [
+</xsl:text>
+ <xsl:for-each select="$widget/arg">
+ <xsl:text> "</xsl:text>
+ <xsl:value-of select="@value"/>
+ <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:text> indexes: [
+</xsl:text>
+ <xsl:for-each select="$widget/path">
+ <xsl:choose>
+ <xsl:when test="not(@index)">
+ <xsl:message terminate="no">
+ <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="@value"/>
+ <xsl:text>" in HMI tree</xsl:text>
+ </xsl:message>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@index"/>
+ <xsl:if test="position()!=last()">
+ <xsl:text>,</xsl:text>
+ </xsl:if>
+ <xsl:text>
+</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:text> ],
+</xsl:text>
+ <xsl:text> element: id("</xsl:text>
+ <xsl:value-of select="@id"/>
+ <xsl:text>"),
+</xsl:text>
+ <xsl:apply-templates mode="widget_defs" select="$widget">
+ <xsl:with-param name="hmi_element" select="."/>
+ </xsl:apply-templates>
+ <xsl:text> }</xsl:text>
+ <xsl:if test="position()!=last()">
+ <xsl:text>,</xsl:text>
+ </xsl:if>
+ <xsl:text>
+</xsl:text>
+ </xsl:template>
+ <xsl:template name="defs_by_labels">
+ <xsl:param name="labels" select="''"/>
+ <xsl:param name="mandatory" select="'yes'"/>
+ <xsl:param name="hmi_element"/>
+ <xsl:variable name="widget_type" select="@type"/>
+ <xsl:for-each select="str:split($labels)">
+ <xsl:variable name="name" select="."/>
+ <xsl:variable name="elt_id" select="$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"/>
+ <xsl:choose>
+ <xsl:when test="not($elt_id)">
+ <xsl:if test="$mandatory='yes'">
+ <xsl:message terminate="no">
+ <xsl:value-of select="$widget_type"/>
+ <xsl:text> widget must have a </xsl:text>
+ <xsl:value-of select="$name"/>
+ <xsl:text> element</xsl:text>
+ </xsl:message>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$name"/>
+ <xsl:text>_elt: id("</xsl:text>
+ <xsl:value-of select="$elt_id"/>
+ <xsl:text>"),
+</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:template>
<xsl:template match="/">
<xsl:comment>
<xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
@@ -592,73 +689,7 @@
</xsl:text>
<xsl:text>var hmi_widgets = {
</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>": {
-</xsl:text>
- <xsl:text> type: "</xsl:text>
- <xsl:value-of select="$widget/@type"/>
- <xsl:text>",
-</xsl:text>
- <xsl:text> args: [
-</xsl:text>
- <xsl:for-each select="$widget/arg">
- <xsl:text> "</xsl:text>
- <xsl:value-of select="@value"/>
- <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:text> indexes: [
-</xsl:text>
- <xsl:for-each select="$widget/path">
- <xsl:choose>
- <xsl:when test="not(@index)">
- <xsl:message terminate="no">
- <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="@value"/>
- <xsl:text>" in HMI tree</xsl:text>
- </xsl:message>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text> </xsl:text>
- <xsl:value-of select="@index"/>
- <xsl:if test="position()!=last()">
- <xsl:text>,</xsl:text>
- </xsl:if>
- <xsl:text>
-</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:text> ],
-</xsl:text>
- <xsl:text> element: id("</xsl:text>
- <xsl:value-of select="@id"/>
- <xsl:text>"),
-</xsl:text>
- <xsl:apply-templates mode="widget_defs" select="$widget">
- <xsl:with-param name="hmi_element" select="."/>
- </xsl:apply-templates>
- <xsl:text> }</xsl:text>
- <xsl:if test="position()!=last()">
- <xsl:text>,</xsl:text>
- </xsl:if>
- <xsl:text>
-</xsl:text>
- </xsl:for-each>
+ <xsl:apply-templates mode="hmi_elements" select="$hmi_elements"/>
<xsl:text>}
</xsl:text>
<xsl:text>
@@ -1507,36 +1538,6 @@
<xsl:text>//})();
</xsl:text>
</xsl:template>
- <xsl:template name="defs_by_labels">
- <xsl:param name="labels" select="''"/>
- <xsl:param name="mandatory" select="'yes'"/>
- <xsl:param name="hmi_element"/>
- <xsl:variable name="widget_type" select="@type"/>
- <xsl:for-each select="str:split($labels)">
- <xsl:variable name="name" select="."/>
- <xsl:variable name="elt_id" select="$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"/>
- <xsl:choose>
- <xsl:when test="not($elt_id)">
- <xsl:if test="$mandatory='yes'">
- <xsl:message terminate="no">
- <xsl:value-of select="$widget_type"/>
- <xsl:text> widget must have a </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text> element</xsl:text>
- </xsl:message>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text> </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text>_elt: id("</xsl:text>
- <xsl:value-of select="$elt_id"/>
- <xsl:text>"),
-</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- </xsl:template>
<xsl:template mode="widget_defs" match="widget[@type='Display']">
<xsl:param name="hmi_element"/>
<xsl:text> frequency: 5,
--- a/svghmi/gen_index_xhtml.ysl2 Tue Mar 17 13:43:19 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Tue Mar 17 14:01:37 2020 +0100
@@ -60,6 +60,8 @@
include inline_svg.ysl2
+ include widget_common.ysl2
+
template "/" {
comment > Made with SVGHMI. https://beremiz.org
@@ -120,31 +122,7 @@
*/
| var hmi_widgets = {
- foreach "$hmi_elements" {
- const "widget", "func:parselabel(@inkscape:label)/widget";
- const "eltid","@id";
- | "«@id»": {
- | type: "«$widget/@type»",
- | args: [
- foreach "$widget/arg"
- | "«@value»"`if "position()!=last()" > ,`
- | ],
- | indexes: [
- foreach "$widget/path" {
- choose {
- when "not(@index)" {
- warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
- }
- otherwise {
- | «@index»`if "position()!=last()" > ,`
- }
- }
- }
- | ],
- | element: id("«@id»"),
- apply "$widget", mode="widget_defs" with "hmi_element",".";
- | }`if "position()!=last()" > ,`
- }
+ apply "$hmi_elements", mode="hmi_elements";
| }
|
| var heartbeat_index = «$indexed_hmitree/*[@hmipath = '/HEARTBEAT']/@index»;
@@ -207,31 +185,6 @@
// }
-
- function "defs_by_labels" {
- param "labels","''";
- param "mandatory","'yes'";
- param "hmi_element";
- const "widget_type","@type";
- foreach "str:split($labels)" {
- const "name",".";
- const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@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: id("«$elt_id»"),
- }
- }
- }
- }
-
-
template "widget[@type='Display']", mode="widget_defs" {
param "hmi_element";
| frequency: 5,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/svghmi/widget_common.ysl2 Tue Mar 17 14:01:37 2020 +0100
@@ -0,0 +1,61 @@
+in xsl decl labels(*ptr, name="defs_by_labels") alias call-template {
+ with "hmi_element", "$hmi_element";
+ 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'";
+};
+
+template "svg:*", mode="hmi_elements" {
+ const "widget", "func:parselabel(@inkscape:label)/widget";
+ const "eltid","@id";
+ | "«@id»": {
+ | type: "«$widget/@type»",
+ | args: [
+ foreach "$widget/arg"
+ | "«@value»"`if "position()!=last()" > ,`
+ | ],
+ | indexes: [
+ foreach "$widget/path" {
+ choose {
+ when "not(@index)" {
+ warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
+ }
+ otherwise {
+ | «@index»`if "position()!=last()" > ,`
+ }
+ }
+ }
+ | ],
+ | element: id("«@id»"),
+ apply "$widget", mode="widget_defs" with "hmi_element",".";
+ | }`if "position()!=last()" > ,`
+}
+
+
+function "defs_by_labels" {
+ param "labels","''";
+ param "mandatory","'yes'";
+ param "hmi_element";
+ const "widget_type","@type";
+ foreach "str:split($labels)" {
+ const "name",".";
+ const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@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: id("«$elt_id»"),
+ }
+ }
+ }
+}
+