SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 22 Jul 2020 13:56:43 +0200
branchsvghmi
changeset 2997 2f298089e32e
parent 2996 14635b09d329
child 2998 e8f707d99dc3
SVGHMI: JsonTable now picks items from HMI:List, and update texts, all according to Json data. Still miss scrolling.
svghmi/gen_index_xhtml.xslt
svghmi/widget_jsontable.ysl2
svghmi/widget_list.ysl2
svghmi/widgets_common.ysl2
tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/svghmi/gen_index_xhtml.xslt	Fri Jul 17 12:21:45 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Wed Jul 22 13:56:43 2020 +0200
@@ -1033,7 +1033,7 @@
     <xsl:text>}
 </xsl:text>
   </xsl:template>
-  <xsl:variable name="excluded_types" select="str:split('Page Lang List')"/>
+  <xsl:variable name="excluded_types" select="str:split('Page Lang')"/>
   <xsl:variable name="excluded_ids" select="$parsed_widgets/widget[not(@type = $excluded_types)]/@id"/>
   <preamble:hmi-elements/>
   <xsl:template match="preamble:hmi-elements">
@@ -2220,7 +2220,7 @@
 </xsl:text>
   </xsl:template>
   <xsl:template mode="json_table_elt_render" match="svg:*">
-    <xsl:message terminate="no">
+    <xsl:message terminate="yes">
       <xsl:text>JsonTable Widget can't contain element of type </xsl:text>
       <xsl:value-of select="local-name()"/>
       <xsl:text>.</xsl:text>
@@ -2228,7 +2228,16 @@
   </xsl:template>
   <xsl:template mode="json_table_elt_render" match="svg:use">
     <xsl:param name="value_expr"/>
-    <xsl:text>    console.log("</xsl:text>
+    <xsl:variable name="targetid" select="substring-after(@xlink:href,'#')"/>
+    <xsl:variable name="from_list" select="$hmi_lists[(@id | */@id) = $targetid]"/>
+    <xsl:if test="count($from_list) = 0">
+      <xsl:message terminate="yes">
+        <xsl:text>Clones (svg:use) in JsonTable Widget must point to a valid HMI:List widget or HMI:List item. Reference "</xsl:text>
+        <xsl:value-of select="@xlink:href"/>
+        <xsl:text>" is not valid.</xsl:text>
+      </xsl:message>
+    </xsl:if>
+    <xsl:text>        console.log("</xsl:text>
     <xsl:value-of select="@id"/>
     <xsl:text>", "</xsl:text>
     <xsl:value-of select="$value_expr"/>
@@ -2236,10 +2245,20 @@
     <xsl:value-of select="$value_expr"/>
     <xsl:text>);
 </xsl:text>
+    <xsl:text>        id("</xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text>").setAttribute("xlink:href", 
+</xsl:text>
+    <xsl:text>            "#"+hmi_widgets["</xsl:text>
+    <xsl:value-of select="$from_list/@id"/>
+    <xsl:text>"].items[</xsl:text>
+    <xsl:value-of select="$value_expr"/>
+    <xsl:text>]);
+</xsl:text>
   </xsl:template>
   <xsl:template mode="json_table_elt_render" match="svg:text">
     <xsl:param name="value_expr"/>
-    <xsl:text>    console.log("</xsl:text>
+    <xsl:text>        console.log("</xsl:text>
     <xsl:value-of select="@id"/>
     <xsl:text>", "</xsl:text>
     <xsl:value-of select="$value_expr"/>
@@ -2247,6 +2266,12 @@
     <xsl:value-of select="$value_expr"/>
     <xsl:text>);
 </xsl:text>
+    <xsl:text>        id("</xsl:text>
+    <xsl:value-of select="@id"/>
+    <xsl:text>").textContent = String(</xsl:text>
+    <xsl:value-of select="$value_expr"/>
+    <xsl:text>);
+</xsl:text>
   </xsl:template>
   <xsl:template mode="json_table_render" match="svg:*">
     <xsl:param name="objname"/>
@@ -2259,7 +2284,7 @@
   </xsl:template>
   <xsl:template mode="json_table_render" match="svg:g">
     <xsl:param name="objname"/>
-    <xsl:text>let obj_</xsl:text>
+    <xsl:text>        let obj_</xsl:text>
     <xsl:value-of select="@id"/>
     <xsl:text> = </xsl:text>
     <xsl:value-of select="$objname"/>
@@ -2289,14 +2314,14 @@
       <xsl:with-param name="mandatory" select="'no'"/>
     </xsl:call-template>
     <xsl:variable name="data_elt" select="$result_svg_ns//*[@id = $hmi_element/@id]/*[@inkscape:label = 'data']"/>
-    <xsl:text>spread_json_data: function(jdata) {
-</xsl:text>
-    <xsl:text>    console.log(jdata);
+    <xsl:text>    spread_json_data: function(jdata) {
+</xsl:text>
+    <xsl:text>        console.log(jdata);
 </xsl:text>
     <xsl:apply-templates mode="json_table_render" select="$data_elt/*">
       <xsl:with-param name="objname" select="'jdata'"/>
     </xsl:apply-templates>
-    <xsl:text>}
+    <xsl:text>    }
 </xsl:text>
   </xsl:template>
   <xsl:template name="jump_widget_activity">
@@ -2765,6 +2790,21 @@
     <xsl:text>    },
 </xsl:text>
   </xsl:template>
+  <xsl:template mode="widget_defs" match="widget[@type='List']">
+    <xsl:param name="hmi_element"/>
+    <xsl:text>    items: {
+</xsl:text>
+    <xsl:for-each select="$hmi_element/*[@inkscape:label]">
+      <xsl:text>        </xsl:text>
+      <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
+      <xsl:text>: "</xsl:text>
+      <xsl:value-of select="@id"/>
+      <xsl:text>",
+</xsl:text>
+    </xsl:for-each>
+    <xsl:text>    },
+</xsl:text>
+  </xsl:template>
   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
     <xsl:param name="hmi_element"/>
     <xsl:text>    frequency: 10,
--- a/svghmi/widget_jsontable.ysl2	Fri Jul 17 12:21:45 2020 +0200
+++ b/svghmi/widget_jsontable.ysl2	Wed Jul 22 13:56:43 2020 +0200
@@ -34,17 +34,26 @@
     ||
 
 template "svg:*", mode="json_table_elt_render" {
-    warning > JsonTable Widget can't contain element of type «local-name()».
+    error > JsonTable Widget can't contain element of type «local-name()».
 }
 
 template "svg:use", mode="json_table_elt_render" {
     param "value_expr";
-    |     console.log("«@id»", "«$value_expr»", «$value_expr»);
+    // cloned element must be part of a HMI:List
+    const "targetid", "substring-after(@xlink:href,'#')";
+    const "from_list", "$hmi_lists[(@id | */@id) = $targetid]";
+
+    if "count($from_list) = 0"
+        error > Clones (svg:use) in JsonTable Widget must point to a valid HMI:List widget or HMI:List item. Reference "«@xlink:href»" is not valid.
+
+    |         id("«@id»").setAttribute("xlink:href", 
+    // obtain new target id from HMI:List widget
+    |             "#"+hmi_widgets["«$from_list/@id»"].items[«$value_expr»]);
 }
 
 template "svg:text", mode="json_table_elt_render" {
     param "value_expr";
-    |     console.log("«@id»", "«$value_expr»", «$value_expr»);
+    |         id("«@id»").textContent = String(«$value_expr»);
 }
 
 template "svg:*", mode="json_table_render" {
@@ -54,7 +63,7 @@
 
 template "svg:g", mode="json_table_render" {
     param "objname";
-    | let obj_«@id» = «$objname»«@inkscape:label»;
+    |         let obj_«@id» = «$objname»«@inkscape:label»;
     apply "*[@inkscape:label]", mode="json_table_render" 
         with "objname" > obj_«@id»
 }
@@ -64,8 +73,7 @@
     labels("data");
     optional_labels("forward backward cursor");
     const "data_elt", "$result_svg_ns//*[@id = $hmi_element/@id]/*[@inkscape:label = 'data']";
-    | spread_json_data: function(jdata) {
-    |     console.log(jdata);
+    |     spread_json_data: function(jdata) {
     apply "$data_elt/*", mode="json_table_render" with "objname","'jdata'";
-    | }
+    |     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/svghmi/widget_list.ysl2	Wed Jul 22 13:56:43 2020 +0200
@@ -0,0 +1,10 @@
+// widget_list.ysl2
+
+template "widget[@type='List']", mode="widget_defs" {
+    param "hmi_element";
+    |     items: {
+    foreach "$hmi_element/*[@inkscape:label]" {
+    |         «func:escape_quotes(@inkscape:label)»: "«@id»",
+    }
+    |     },
+}
--- a/svghmi/widgets_common.ysl2	Fri Jul 17 12:21:45 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Wed Jul 22 13:56:43 2020 +0200
@@ -121,7 +121,7 @@
 }
 ||
 
-const "excluded_types", "str:split('Page Lang List')";
+const "excluded_types", "str:split('Page Lang')";
 const "excluded_ids","$parsed_widgets/widget[not(@type = $excluded_types)]/@id";
 
 emit "preamble:hmi-elements" {
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg	Fri Jul 17 12:21:45 2020 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg	Wed Jul 22 13:56:43 2020 +0200
@@ -138,17 +138,17 @@
      inkscape:pageopacity="0"
      inkscape:pageshadow="2"
      inkscape:document-units="px"
-     inkscape:current-layer="g1384"
+     inkscape:current-layer="g1332"
      showgrid="false"
      units="px"
-     inkscape:zoom="2"
-     inkscape:cx="841.23474"
-     inkscape:cy="298.33077"
-     inkscape:window-width="2807"
-     inkscape:window-height="1582"
+     inkscape:zoom="1"
+     inkscape:cx="521.07002"
+     inkscape:cy="767.67088"
+     inkscape:window-width="3840"
+     inkscape:window-height="2096"
      inkscape:window-x="0"
      inkscape:window-y="27"
-     inkscape:window-maximized="0"
+     inkscape:window-maximized="1"
      showguides="true"
      inkscape:guide-bbox="true" />
   <rect
@@ -2890,13 +2890,13 @@
         <use
            x="0"
            y="0"
-           xlink:href="#path1316"
-           inkscape:transform-center-x="0.14620371"
-           inkscape:transform-center-y="2.9995242"
+           xlink:href="#use1297"
+           inkscape:transform-center-x="0.11123312"
+           inkscape:transform-center-y="2.2824109"
            id="use1378"
            width="100%"
            height="100%"
-           transform="translate(-198.17662,280.01428)"
+           transform="matrix(0.7609336,0,0,0.7609336,199.15217,164.3798)"
            inkscape:label=".sides" />
         <text
            xml:space="preserve"
@@ -2940,8 +2940,8 @@
     </g>
   </g>
   <g
-     id="g1324"
-     inkscape:label="HMI:List:polygons">
+     id="g1332"
+     inkscape:label="polygons">
     <path
        inkscape:transform-center-y="2.9995242"
        inkscape:transform-center-x="0.14620371"
@@ -3052,6 +3052,78 @@
        inkscape:label="eight" />
   </g>
   <g
+     inkscape:label="HMI:List:polygons"
+     id="g1311">
+    <use
+       x="0"
+       y="0"
+       xlink:href="#path1298"
+       inkscape:transform-center-x="0.14620371"
+       inkscape:transform-center-y="2.9995242"
+       id="use1293"
+       width="100%"
+       height="100%"
+       transform="translate(150.23297,80)"
+       style="display:inline"
+       inkscape:label="3" />
+    <use
+       x="0"
+       y="0"
+       xlink:href="#path1308"
+       inkscape:transform-center-x="0.14620371"
+       inkscape:transform-center-y="2.9995242"
+       id="use1295"
+       width="100%"
+       height="100%"
+       transform="translate(93.515259,80)"
+       inkscape:label="4" />
+    <use
+       x="0"
+       y="0"
+       xlink:href="#path1310"
+       inkscape:transform-center-x="0.14620371"
+       inkscape:transform-center-y="2.9995242"
+       id="use1297"
+       width="100%"
+       height="100%"
+       transform="translate(33.666488,80)"
+       inkscape:label="5" />
+    <use
+       x="0"
+       y="0"
+       xlink:href="#path1312"
+       inkscape:transform-center-x="0.14620371"
+       inkscape:transform-center-y="2.9995242"
+       id="use1299"
+       width="100%"
+       height="100%"
+       transform="translate(-26.484802,80)"
+       inkscape:label="6" />
+    <use
+       x="0"
+       y="0"
+       xlink:href="#path1314"
+       inkscape:transform-center-x="0.14620371"
+       inkscape:transform-center-y="2.9995242"
+       id="use1301"
+       width="100%"
+       height="100%"
+       transform="translate(-85.692787,80)"
+       inkscape:label="7" />
+    <use
+       x="0"
+       y="0"
+       xlink:href="#path1316"
+       inkscape:transform-center-x="0.14620371"
+       inkscape:transform-center-y="2.9995242"
+       id="use1303"
+       width="100%"
+       height="100%"
+       transform="translate(-146.48474,80)"
+       style="display:inline"
+       inkscape:label="8" />
+  </g>
+  <g
      transform="matrix(3.3549332,0,0,3.14525,-181.87457,3116.0198)"
      style="fill-rule:evenodd;stroke-width:0.47631353"
      id="g1490"