SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class. svghmi
authorEdouard Tisserant
Thu, 26 Mar 2020 13:33:20 +0100
branchsvghmi
changeset 2901 3f5194bba67d
parent 2900 3ef217f525ff
child 2902 1fcb50af0335
SVGHMI: Jump widget now make errors if path given for relative jump doesn't match target page reference path class.
svghmi/detachable_pages.ysl2
svghmi/gen_index_xhtml.xslt
svghmi/widget_jump.ysl2
--- a/svghmi/detachable_pages.ysl2	Thu Mar 26 11:17:34 2020 +0100
+++ b/svghmi/detachable_pages.ysl2	Thu Mar 26 13:33:20 2020 +0100
@@ -102,9 +102,10 @@
 
     const "page_all_elements", "func:all_related_elements($page)";
 
-    const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id and not(@id=$in_forEach_widget_ids)]";
+    const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]";
+    const "page_managed_widgets","$all_page_widgets[not(@id=$in_forEach_widget_ids)]";
     const "page_relative_widgets",
-        "$all_page_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]";
+        "$page_managed_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]";
 
     // Take closest ancestor in detachable_elements
     // since nested detachable elements are filtered out
@@ -126,7 +127,7 @@
     }
     |     ],
     |     absolute_widgets: [
-    foreach "$all_page_widgets[not(@id = $page_relative_widgets/@id)]" {
+    foreach "$page_managed_widgets[not(@id = $page_relative_widgets/@id)]" {
     |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
     }
     |     ],
@@ -135,9 +136,14 @@
     |         "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
     }
     |     }
+    apply "$parsed_widgets/widget[@id = $all_page_widgets/@id]", mode="per_page_widget_template"{
+        with "page_desc", "$desc";
+    }
     |   }`if "position()!=last()" > ,`
 }
 
+template "*", mode="per_page_widget_template";
+
 function "debug_detachables" {
     | DETACHABLES:
     foreach "$detachable_elements"{
--- a/svghmi/gen_index_xhtml.xslt	Thu Mar 26 11:17:34 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Thu Mar 26 13:33:20 2020 +0100
@@ -147,6 +147,13 @@
     <xsl:param name="ancest"/>
     <func:result select="string-length($ancest) &gt; 0 and starts-with($descend,$ancest)"/>
   </func:function>
+  <func:function name="func:same_class_paths">
+    <xsl:param name="a"/>
+    <xsl:param name="b"/>
+    <xsl:variable name="class_a" select="$indexed_hmitree/*[@hmipath = $a]/@class"/>
+    <xsl:variable name="class_b" select="$indexed_hmitree/*[@hmipath = $b]/@class"/>
+    <func:result select="$class_a and $class_b and $class_a = $class_b"/>
+  </func:function>
   <xsl:template mode="testtree" match="*">
     <xsl:param name="indent" select="''"/>
     <xsl:value-of select="$indent"/>
@@ -332,8 +339,9 @@
     <xsl:variable name="page" select="."/>
     <xsl:variable name="p" select="$geometry[@Id = $page/@id]"/>
     <xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/>
-    <xsl:variable name="all_page_widgets" select="$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id and not(@id=$in_forEach_widget_ids)]"/>
-    <xsl:variable name="page_relative_widgets" select="$all_page_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]"/>
+    <xsl:variable name="all_page_widgets" select="$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]"/>
+    <xsl:variable name="page_managed_widgets" select="$all_page_widgets[not(@id=$in_forEach_widget_ids)]"/>
+    <xsl:variable name="page_relative_widgets" select="$page_managed_widgets[func:is_descendant_path(func:widget(@id)/path/@value, $desc/path/@value)]"/>
     <xsl:variable name="required_detachables" select="func:sumarized_elements($page_all_elements)/&#10;           ancestor-or-self::*[@id = $detachable_elements/@id]"/>
     <xsl:text>  "</xsl:text>
     <xsl:value-of select="$desc/arg[1]/@value"/>
@@ -384,7 +392,7 @@
 </xsl:text>
     <xsl:text>    absolute_widgets: [
 </xsl:text>
-    <xsl:for-each select="$all_page_widgets[not(@id = $page_relative_widgets/@id)]">
+    <xsl:for-each select="$page_managed_widgets[not(@id = $page_relative_widgets/@id)]">
       <xsl:text>        hmi_widgets["</xsl:text>
       <xsl:value-of select="@id"/>
       <xsl:text>"]</xsl:text>
@@ -412,6 +420,9 @@
     </xsl:for-each>
     <xsl:text>    }
 </xsl:text>
+    <xsl:apply-templates mode="per_page_widget_template" select="$parsed_widgets/widget[@id = $all_page_widgets/@id]">
+      <xsl:with-param name="page_desc" select="$desc"/>
+    </xsl:apply-templates>
     <xsl:text>  }</xsl:text>
     <xsl:if test="position()!=last()">
       <xsl:text>,</xsl:text>
@@ -419,6 +430,7 @@
     <xsl:text>
 </xsl:text>
   </xsl:template>
+  <xsl:template mode="per_page_widget_template" match="*"/>
   <xsl:template name="debug_detachables">
     <xsl:text>DETACHABLES:
 </xsl:text>
@@ -891,6 +903,44 @@
     <xsl:text>    },
 </xsl:text>
   </xsl:template>
+  <xsl:template mode="per_page_widget_template" match="widget[@type='Jump']">
+    <xsl:param name="page_desc"/>
+    <xsl:if test="path">
+      <xsl:variable name="target_page_name">
+        <xsl:choose>
+          <xsl:when test="arg">
+            <xsl:value-of select="arg[1]/@value"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$page_desc/arg[1]/@value"/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:variable name="target_page_path">
+        <xsl:choose>
+          <xsl:when test="arg">
+            <xsl:value-of select="$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value"/>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:value-of select="$page_desc/path[1]/@value"/>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:if test="not(func:same_class_paths($target_page_path, path[1]/@value))">
+        <xsl:message terminate="yes">
+          <xsl:text>Jump id="</xsl:text>
+          <xsl:value-of select="@id"/>
+          <xsl:text>" to page "</xsl:text>
+          <xsl:value-of select="$target_page_name"/>
+          <xsl:text>" with incompatible path "</xsl:text>
+          <xsl:value-of select="path[1]/@value"/>
+          <xsl:text> (must be same class as "</xsl:text>
+          <xsl:value-of select="$target_page_path"/>
+          <xsl:text>")</xsl:text>
+        </xsl:message>
+      </xsl:if>
+    </xsl:if>
+  </xsl:template>
   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
     <xsl:param name="hmi_element"/>
     <xsl:text>    frequency: 10,
--- a/svghmi/widget_jump.ysl2	Thu Mar 26 11:17:34 2020 +0100
+++ b/svghmi/widget_jump.ysl2	Thu Mar 26 13:33:20 2020 +0100
@@ -3,22 +3,12 @@
 template "widget[@type='Jump']", mode="widget_defs" {
     param "hmi_element";
 
-    /* check that given path is compatible with page's reference path */
-    if "count(arg) > 0 and count(path) > 0" {
-        const "target_page_name", "arg[1]/@value";
-        const "target_page_desc", "$hmi_pages_descs[arg[1]/@value = $target_page_name]";
-        const "target_page_path", "$target_page_desc/path[1]/@value";
-        if "not(func:same_class_paths($target_page_path, path[1]/@value))"
-            warning > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value»"
-    }
-    /* TODO check that path is also matching in case of implicit local jump (no page name given) */
-
     |     on_click: function(evt) {
     |         const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
     |         switch_page(this.args[0], index);
     |     },
     |     init: function() {
-    /* registering event this way doies not "click" through svg:use 
+    /* registering event this way does not "click" through svg:use 
     |     this.element.onclick = evt => switch_page(this.args[0]);
     event must be registered by adding attribute to element instead
     TODO : generalize mouse event handling by global event capture + getElementsAtPoint()
@@ -26,3 +16,22 @@
     |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
     |     },
 }
+
+template "widget[@type='Jump']", mode="per_page_widget_template"{
+    param "page_desc";
+    /* check that given path is compatible with page's reference path */
+    if "path" {
+        /* when no page name provided, check for same page */
+        const "target_page_name" choose {
+            when "arg" value "arg[1]/@value";
+            otherwise value "$page_desc/arg[1]/@value";
+        }
+        const "target_page_path" choose {
+            when "arg" value "$hmi_pages_descs[arg[1]/@value = $target_page_name]/path[1]/@value";
+            otherwise value "$page_desc/path[1]/@value";
+        }
+
+        if "not(func:same_class_paths($target_page_path, path[1]/@value))"
+            error > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value» (must be same class as "«$target_page_path»")
+    }
+}