SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in) svghmi
authorEdouard Tisserant
Wed, 09 Oct 2019 11:15:14 +0200
branchsvghmi
changeset 2794 c10069a02ed0
parent 2793 2a97688c94c5
child 2795 c0cf62bb9aa7
SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Wed Oct 09 09:04:35 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Wed Oct 09 11:15:14 2019 +0200
@@ -3,6 +3,9 @@
   <xsl:output method="xml" cdata-section-elements="script"/>
   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
+  <xsl:variable name="hmi_elements" select="//*[starts-with(@inkscape:label, 'HMI:')]"/>
+  <xsl:variable name="hmi_geometry" select="$geometry[@Id = $hmi_elements/@id]"/>
+  <xsl:variable name="hmi_pages" select="$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']"/>
   <xsl:variable name="_categories">
     <noindex>
       <xsl:text>HMI_ROOT</xsl:text>
@@ -78,10 +81,6 @@
       <xsl:apply-templates mode="identity_svg" select="@* | node()"/>
     </xsl:copy>
   </xsl:template>
-  <xsl:variable name="mark">
-    <xsl:text>=HMI=
-</xsl:text>
-  </xsl:variable>
   <xsl:template match="/">
     <xsl:comment>
       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
@@ -91,7 +90,7 @@
       <body style="margin:0;">
         <xsl:copy>
           <xsl:comment>
-            <xsl:apply-templates mode="testgeo" select="$geometry"/>
+            <xsl:apply-templates mode="testgeo" select="$hmi_geometry"/>
           </xsl:comment>
           <xsl:comment>
             <xsl:apply-templates mode="testtree" select="$hmitree"/>
@@ -138,7 +137,7 @@
           <xsl:attribute name="type">
             <xsl:value-of select="$type"/>
           </xsl:attribute>
-          <xsl:for-each select="str:split($args, ':')">
+          <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
             <arg>
               <xsl:attribute name="value">
                 <xsl:value-of select="."/>
@@ -202,12 +201,32 @@
 </xsl:text>
     <xsl:text>var page_desc = {
 </xsl:text>
-    <xsl:for-each select="//*[func:parselabel(@inkscape:label)/widget/@type = 'Page']">
-      <xsl:value-of select="@inkscape:label"/>
-      <xsl:text>
-</xsl:text>
-      <xsl:variable name="ast" select="func:parselabel(@inkscape:label)"/>
-      <xsl:apply-templates mode="testtree" select="$ast"/>
+    <xsl:for-each select="$hmi_pages">
+      <xsl:variable name="desc" select="func:parselabel(@inkscape:label)/widget"/>
+      <xsl:text>    "</xsl:text>
+      <xsl:value-of select="$desc/arg[1]/@value"/>
+      <xsl:text>": {
+</xsl:text>
+      <xsl:text>        id: "</xsl:text>
+      <xsl:value-of select="@id"/>
+      <xsl:text>"
+</xsl:text>
+      <xsl:text>        widgets: [
+</xsl:text>
+      <xsl:variable name="page" select="."/>
+      <xsl:variable name="p" select="$hmi_geometry[@Id = $page/@id]"/>
+      <xsl:for-each select="$hmi_geometry[@Id != $page/@id and &#10;                       @x &gt;= $p/@x and @y &gt;= $p/@y and @w &lt;= $p/@w and @h &lt;= $p/@h]">
+        <xsl:text>            "</xsl:text>
+        <xsl:value-of select="@Id"/>
+        <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:for-each>
     <xsl:text>}
 </xsl:text>
--- a/svghmi/gen_index_xhtml.ysl2	Wed Oct 09 09:04:35 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2	Wed Oct 09 11:15:14 2019 +0200
@@ -24,6 +24,11 @@
     const "geometry", "ns:GetSVGGeometry()";
     const "hmitree", "ns:GetHMITree()";
 
+    const "hmi_elements", "//*[starts-with(@inkscape:label, 'HMI:')]";
+    const "hmi_geometry", "$geometry[@Id = $hmi_elements/@id]";
+
+    const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']";
+
     const "_categories" {
         noindex > HMI_ROOT
         noindex > HMI_LABEL
@@ -36,7 +41,7 @@
     const "_indexed_hmitree" apply "$hmitree", mode="index";
     const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)";
 
-    template "*", mode="index"{
+    template "*", mode="index" {
         param "index", "0";
         param "parentpath", "''";
         const "content" {
@@ -79,7 +84,7 @@
       xsl:copy apply "@* | node()", mode="identity_svg";
     }
 
-    const "mark" > =HMI=\n
+    /*const "mark" > =HMI=\n*/
 
     /* copy root node and add geometry as comment for a test */
     template "/" { 
@@ -89,7 +94,7 @@
             body style="margin:0;" {
                 xsl:copy {
                     comment {
-                        apply "$geometry", mode="testgeo";
+                        apply "$hmi_geometry", mode="testgeo";
                     }
                     comment {
                         apply "$hmitree", mode="testtree";
@@ -124,7 +129,7 @@
 
         const "ast" if "$type" widget {
             attrib "type" > «$type»
-            foreach "str:split($args, ':')" {
+            foreach "str:split(substring-after($args, ':'), ':')" {
                 arg {
                     attrib "value" > «.»
                 }
@@ -188,11 +193,19 @@
         |
         | var page_desc = {
 
-        // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI'
-        foreach "//*[func:parselabel(@inkscape:label)/widget/@type = 'Page']" {
-            | «@inkscape:label»
-            const "ast", "func:parselabel(@inkscape:label)";
-            apply "$ast", mode="testtree";
+        foreach "$hmi_pages" {
+            const "desc", "func:parselabel(@inkscape:label)/widget";
+            |     "«$desc/arg[1]/@value»": {
+            |         id: "«@id»"
+            |         widgets: [
+            const "page", "."; 
+            const "p", "$hmi_geometry[@Id = $page/@id]"; 
+            foreach """$hmi_geometry[@Id != $page/@id and 
+                       @x >= $p/@x and @y >= $p/@y and 
+                       @w <= $p/@w and @h <= $p/@h]""" {
+                |             "«@Id»"`if "position()!=last()" > ,`
+            }
+            |         ]
         }
         | }