SVGHMI compute default page svghmi
authorEdouard Tisserant
Thu, 10 Oct 2019 09:54:44 +0200
branchsvghmi
changeset 2795 c0cf62bb9aa7
parent 2794 c10069a02ed0
child 2796 c7a22ce8c156
SVGHMI compute default page
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Wed Oct 09 11:15:14 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Thu Oct 10 09:54:44 2019 +0200
@@ -6,6 +6,27 @@
   <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="default_page">
+    <xsl:choose>
+      <xsl:when test="count($hmi_pages) &gt; 1">
+        <xsl:variable name="Home_page" select="$hmi_pages[func:parselabel(@inkscape:label)/widget/arg[1]/@value = 'Home']"/>
+        <xsl:choose>
+          <xsl:when test="$Home_page">
+            <xsl:text>Home</xsl:text>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:message terminate="yes">No Home page defined!</xsl:message>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:when>
+      <xsl:when test="count($hmi_pages) = 0">
+        <xsl:message terminate="yes">No page defined!</xsl:message>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="func:parselabel($hmi_pages/@inkscape:label)/widget/arg[1]/@value"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
   <xsl:variable name="_categories">
     <noindex>
       <xsl:text>HMI_ROOT</xsl:text>
@@ -209,13 +230,13 @@
 </xsl:text>
       <xsl:text>        id: "</xsl:text>
       <xsl:value-of select="@id"/>
-      <xsl:text>"
+      <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:for-each select="$hmi_geometry[@Id != $page/@id and &#10;                       @x &gt;= $p/@x and @y &gt;= $p/@y and &#10;                       @w &lt;= $p/@w and @h &lt;= $p/@h]">
         <xsl:text>            "</xsl:text>
         <xsl:value-of select="@Id"/>
         <xsl:text>"</xsl:text>
@@ -230,6 +251,12 @@
     </xsl:for-each>
     <xsl:text>}
 </xsl:text>
+    <xsl:text>
+</xsl:text>
+    <xsl:text>var default_page = "</xsl:text>
+    <xsl:value-of select="$default_page"/>
+    <xsl:text>";
+</xsl:text>
     <xsl:text>// svghmi.js
 </xsl:text>
     <xsl:text>
--- a/svghmi/gen_index_xhtml.ysl2	Wed Oct 09 11:15:14 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2	Thu Oct 10 09:54:44 2019 +0200
@@ -29,6 +29,23 @@
 
     const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']";
 
+    const "default_page" choose {
+        when "count($hmi_pages) > 1" {
+            const "Home_page", 
+                "$hmi_pages[func:parselabel(@inkscape:label)/widget/arg[1]/@value = 'Home']";
+            choose {
+                when "$Home_page" > Home
+                otherwise {
+                    error "No Home page defined!";
+                }
+            }
+        }
+        when "count($hmi_pages) = 0" {
+            error "No page defined!";
+        }
+        otherwise > «func:parselabel($hmi_pages/@inkscape:label)/widget/arg[1]/@value»
+    }
+
     const "_categories" {
         noindex > HMI_ROOT
         noindex > HMI_LABEL
@@ -37,7 +54,6 @@
         noindex > HMI_CURRENT_PAGE
     }
     const "categories", "exsl:node-set($_categories)";
-    //const "indexed_hmitree", "$hmitree[not(local-name() = $categories/noindex/text())]";
     const "_indexed_hmitree" apply "$hmitree", mode="index";
     const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)";
 
@@ -196,7 +212,7 @@
         foreach "$hmi_pages" {
             const "desc", "func:parselabel(@inkscape:label)/widget";
             |     "«$desc/arg[1]/@value»": {
-            |         id: "«@id»"
+            |         id: "«@id»",
             |         widgets: [
             const "page", "."; 
             const "p", "$hmi_geometry[@Id = $page/@id]"; 
@@ -209,6 +225,9 @@
         }
         | }
 
+        |
+        | var default_page = "«$default_page»";
+
         include text svghmi.js
     }