SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 20 Mar 2020 10:00:59 +0100
branchsvghmi
changeset 2890 ae8063127e95
parent 2889 4eeed820fd3a
child 2891 8927ae8326b2
SVGHMI: make root HMI tree node a HMI_NODE, droped HMI_ROOT node type
svghmi/gen_index_xhtml.xslt
svghmi/hmi_tree.ysl2
svghmi/svghmi.js
svghmi/svghmi.py
svghmi/widgets_common.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Thu Mar 19 19:23:56 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Fri Mar 20 10:00:59 2020 +0100
@@ -5,9 +5,6 @@
   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
   <xsl:variable name="_categories">
     <noindex>
-      <xsl:text>HMI_ROOT</xsl:text>
-    </noindex>
-    <noindex>
       <xsl:text>HMI_PLC_STATUS</xsl:text>
     </noindex>
     <noindex>
@@ -25,8 +22,12 @@
     <xsl:variable name="content">
       <xsl:variable name="path">
         <xsl:choose>
-          <xsl:when test="local-name() = 'HMI_ROOT'">
-            <xsl:value-of select="$parentpath"/>
+          <xsl:when test="count(ancestor::*)=0">
+            <xsl:text>/</xsl:text>
+          </xsl:when>
+          <xsl:when test="count(ancestor::*)=1">
+            <xsl:text>/</xsl:text>
+            <xsl:value-of select="@name"/>
           </xsl:when>
           <xsl:otherwise>
             <xsl:value-of select="$parentpath"/>
@@ -597,8 +598,11 @@
           </xsl:message>
         </xsl:when>
         <xsl:otherwise>
-          <xsl:text>            </xsl:text>
+          <xsl:text>        </xsl:text>
           <xsl:value-of select="@index"/>
+          <xsl:text> /*</xsl:text>
+          <xsl:value-of select="$widget/path"/>
+          <xsl:text>*/ </xsl:text>
           <xsl:if test="position()!=last()">
             <xsl:text>,</xsl:text>
           </xsl:if>
@@ -676,6 +680,51 @@
       </xsl:otherwise>
     </xsl:choose>
   </func:function>
+  <xsl:template mode="widget_defs" match="widget[@type='ForEach']">
+    <xsl:param name="hmi_element"/>
+    <xsl:text>    frequency: 2,
+</xsl:text>
+    <xsl:text>    dispatch: function(value) {
+</xsl:text>
+    <xsl:text>                    // do something
+</xsl:text>
+    <xsl:text>    },
+</xsl:text>
+    <xsl:text>    init: function() {
+</xsl:text>
+    <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
+      <xsl:text>        id("</xsl:text>
+      <xsl:value-of select="@id"/>
+      <xsl:text>").addEventListener(
+</xsl:text>
+      <xsl:text>            "click", 
+</xsl:text>
+      <xsl:text>            evt =&gt; {let new_val = "</xsl:text>
+      <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
+      <xsl:text>");
+</xsl:text>
+      <xsl:text>                    // do something with new_val
+</xsl:text>
+      <xsl:text>                   });
+</xsl:text>
+    </xsl:for-each>
+    <xsl:text>    },
+</xsl:text>
+  </xsl:template>
+  <xsl:template mode="widget_subscribe" match="widget[@type='ForEach']">
+    <xsl:text>    sub: function(off){
+</xsl:text>
+    <xsl:text>        subscribe.call(this,off)
+</xsl:text>
+    <xsl:text>    },
+</xsl:text>
+    <xsl:text>    unsub: function(){
+</xsl:text>
+    <xsl:text>        unsubscribe.call(this)
+</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,
@@ -1134,6 +1183,8 @@
 </xsl:text>
     <xsl:text>    BOOL: (dv,offset) =&gt; [dv.getInt8(offset, true), 1],
 </xsl:text>
+    <xsl:text>    NODE: (dv,offset) =&gt; [dv.getInt8(offset, true), 1],
+</xsl:text>
     <xsl:text>    STRING: (dv, offset) =&gt; {
 </xsl:text>
     <xsl:text>        size = dv.getInt8(offset);
@@ -1316,6 +1367,8 @@
 </xsl:text>
     <xsl:text>    BOOL: (truth) =&gt; new Int16Array([truth]),
 </xsl:text>
+    <xsl:text>    NODE: (truth) =&gt; new Int16Array([truth]),
+</xsl:text>
     <xsl:text>    STRING: (str) =&gt; {
 </xsl:text>
     <xsl:text>        // beremiz default string max size is 128
--- a/svghmi/hmi_tree.ysl2	Thu Mar 19 19:23:56 2020 +0100
+++ b/svghmi/hmi_tree.ysl2	Fri Mar 20 10:00:59 2020 +0100
@@ -5,7 +5,6 @@
 const "hmitree", "ns:GetHMITree()";
 
 const "_categories" {
-    noindex > HMI_ROOT
     noindex > HMI_PLC_STATUS
     noindex > HMI_CURRENT_PAGE
 }
@@ -21,7 +20,8 @@
     const "content" {
         const "path"
             choose {
-                when "local-name() = 'HMI_ROOT'" > «$parentpath»
+                when "count(ancestor::*)=0" > /
+                when "count(ancestor::*)=1" > /«@name»
                 otherwise > «$parentpath»/«@name»
             }
         choose {
--- a/svghmi/svghmi.js	Thu Mar 19 19:23:56 2020 +0100
+++ b/svghmi/svghmi.js	Fri Mar 20 10:00:59 2020 +0100
@@ -57,6 +57,7 @@
 const dvgetters = {
     INT: (dv,offset) => [dv.getInt16(offset, true), 2],
     BOOL: (dv,offset) => [dv.getInt8(offset, true), 1],
+    NODE: (dv,offset) => [dv.getInt8(offset, true), 1],
     STRING: (dv, offset) => {
         size = dv.getInt8(offset);
         return [
@@ -148,6 +149,7 @@
 const typedarray_types = {
     INT: (number) => new Int16Array([number]),
     BOOL: (truth) => new Int16Array([truth]),
+    NODE: (truth) => new Int16Array([truth]),
     STRING: (str) => {
         // beremiz default string max size is 128
         str = str.slice(0,128);
--- a/svghmi/svghmi.py	Thu Mar 19 19:23:56 2020 +0100
+++ b/svghmi/svghmi.py	Fri Mar 20 10:00:59 2020 +0100
@@ -55,7 +55,7 @@
             self.vartype = vartype
             self.cpath = cpath
 
-        if nodetype in ["HMI_NODE", "HMI_ROOT"]:
+        if nodetype in ["HMI_NODE"]:
             self.children = []
 
     def pprint(self, indent = 0):
@@ -136,7 +136,8 @@
 
 on_hmitree_update = None
 
-SPECIAL_NODES = [("heartbeat", "HMI_INT")]
+SPECIAL_NODES = [("HMI_ROOT", "HMI_NODE"),
+                 ("heartbeat", "HMI_INT")]
                  # ("current_page", "HMI_STRING")])
 
 class SVGHMILibrary(POULibrary):
@@ -183,7 +184,18 @@
         # Filter known HMI types
         hmi_types_instances = [v for v in varlist if v["derived"] in HMI_TYPES]
 
-        hmi_tree_root = HMITreeNode(None, "/", "HMI_ROOT")
+        hmi_tree_root = None
+
+        # take first HMI_NODE (placed as special node), make it root
+        for i,v in enumerate(hmi_types_instances):
+            path = v["IEC_path"].split(".")
+            derived = v["derived"]
+            if derived == "HMI_NODE" and ['CONFIG', 'HEARTBEAT'] :
+                hmi_tree_root = HMITreeNode(path, "", derived, v["type"], v["vartype"], v["C_path"])
+                hmi_types_instances.pop(i)
+                break
+
+        assert(hmi_tree_root is not None)
 
         # deduce HMI tree from PLC HMI_* instances
         for v in hmi_types_instances:
@@ -444,12 +456,6 @@
         return res
 
     def CTNGenerate_C(self, buildpath, locations):
-        """
-        Return C code generated by iec2c compiler
-        when _generate_softPLC have been called
-        @param locations: ignored
-        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
-        """
 
         location_str = "_".join(map(str, self.GetCurrentLocation()))
         view_name = self.BaseParams.getName()
--- a/svghmi/widgets_common.ysl2	Thu Mar 19 19:23:56 2020 +0100
+++ b/svghmi/widgets_common.ysl2	Fri Mar 20 10:00:59 2020 +0100
@@ -28,7 +28,7 @@
                 warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
             }
             otherwise {
-    |             «@index»`if "position()!=last()" > ,`
+    |         «@index» /*«$widget/path»*/ `if "position()!=last()" > ,`
             }
         }
     }