SVGHMI: created detachable_elements.ysl2 svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 17 Mar 2020 09:29:04 +0100
branchsvghmi
changeset 2875 6a12e1084deb
parent 2874 b67af0b8dc72
child 2876 d2adbc273125
SVGHMI: created detachable_elements.ysl2
svghmi/detachable_elements.ysl2
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
svghmi/geometry.ysl2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/svghmi/detachable_elements.ysl2	Tue Mar 17 09:29:04 2020 +0100
@@ -0,0 +1,75 @@
+// detachable_elements.ysl2
+//
+// compute what elements are required by pages
+// and decide where to cut when removing/attaching 
+// pages elements on page switch
+
+// returns all directly or indirectly refered elements
+def "func:refered_elements" {
+    param "elems";
+    const "descend", "$elems/descendant-or-self::svg:*";
+    const "clones", "$descend[self::svg:use]";
+    const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
+    choose {
+        when "$originals"
+            result "$descend | func:refered_elements($originals)";
+        otherwise
+            result "$descend";
+    }
+}
+
+def "func:all_related_elements" {
+    param "page";
+    const "page_overlapping_geometry", "func:overlapping_geometry($page)";
+    const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]";
+    const "page_sub_elements", "func:refered_elements($page | $page_overlapping_elements)";
+    result "$page_sub_elements";
+}
+
+def "func:required_elements" {
+    param "pages"; 
+    choose{
+        when "$pages"{
+            result """func:all_related_elements($pages[1])
+                      | func:required_elements($pages[position()!=1])""";
+        }otherwise{
+            result "/..";
+        }
+    }
+}
+
+const "required_elements",
+    """//svg:defs/descendant-or-self::svg:*
+       | func:required_elements($hmi_pages)/ancestor-or-self::svg:*""";
+
+const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
+
+def "func:sumarized_elements" {
+    param "elements";
+    const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
+    const "filled_groups", """$short_list/parent::svg:*[
+        not(descendant::*[
+            not(self::svg:g) and
+            not(@id = $discardable_elements/@id) and
+            not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)
+        ])]""";
+    const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
+    result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
+}
+
+def "func:detachable_elements" {
+    param "pages";
+    choose{
+        when "$pages"{
+            result """func:sumarized_elements(func:all_related_elements($pages[1]))
+                      | func:detachable_elements($pages[position()!=1])""";
+        }otherwise{
+            result "/..";
+        }
+    }
+}
+
+// Avoid nested detachables
+const "_detachable_elements", "func:detachable_elements($hmi_pages)";
+const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]";
+
--- a/svghmi/gen_index_xhtml.xslt	Tue Mar 17 08:00:33 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Tue Mar 17 09:29:04 2020 +0100
@@ -37,23 +37,9 @@
     </noindex>
   </xsl:variable>
   <xsl:variable name="categories" select="exsl:node-set($_categories)"/>
-  <func:function name="func:refered_elements">
-    <xsl:param name="elems"/>
-    <xsl:variable name="descend" select="$elems/descendant-or-self::svg:*"/>
-    <xsl:variable name="clones" select="$descend[self::svg:use]"/>
-    <xsl:variable name="originals" select="//svg:*[concat('#',@id) = $clones/@xlink:href]"/>
-    <xsl:choose>
-      <xsl:when test="$originals">
-        <func:result select="$descend | func:refered_elements($originals)"/>
-      </xsl:when>
-      <xsl:otherwise>
-        <func:result select="$descend"/>
-      </xsl:otherwise>
-    </xsl:choose>
-  </func:function>
   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
   <xsl:template name="debug_geometry">
-    <xsl:text>GEOMETRY : ID, x, y, w, h
+    <xsl:text>ID, x, y, w, h
 </xsl:text>
     <xsl:for-each select="$geometry[@Id = $hmi_elements/@id]">
       <xsl:text> </xsl:text>
@@ -116,6 +102,20 @@
     <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
     <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or &#10;                          (not(@Id = $groups/@id) and (func:intersect($g, .) &gt; 0 ))]"/>
   </func:function>
+  <func:function name="func:refered_elements">
+    <xsl:param name="elems"/>
+    <xsl:variable name="descend" select="$elems/descendant-or-self::svg:*"/>
+    <xsl:variable name="clones" select="$descend[self::svg:use]"/>
+    <xsl:variable name="originals" select="//svg:*[concat('#',@id) = $clones/@xlink:href]"/>
+    <xsl:choose>
+      <xsl:when test="$originals">
+        <func:result select="$descend | func:refered_elements($originals)"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <func:result select="$descend"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </func:function>
   <func:function name="func:all_related_elements">
     <xsl:param name="page"/>
     <xsl:variable name="page_overlapping_geometry" select="func:overlapping_geometry($page)"/>
@@ -127,19 +127,19 @@
     <xsl:param name="pages"/>
     <xsl:choose>
       <xsl:when test="$pages">
-        <func:result select="func:all_related_elements($pages[1])&#10;                          | func:required_elements($pages[position()!=1])"/>
+        <func:result select="func:all_related_elements($pages[1])&#10;                      | func:required_elements($pages[position()!=1])"/>
       </xsl:when>
       <xsl:otherwise>
         <func:result select="/.."/>
       </xsl:otherwise>
     </xsl:choose>
   </func:function>
-  <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:*&#10;           | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/>
+  <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:*&#10;       | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/>
   <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/>
   <func:function name="func:sumarized_elements">
     <xsl:param name="elements"/>
     <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/>
-    <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[&#10;            not(descendant::*[&#10;                not(self::svg:g) and&#10;                not(@id = $discardable_elements/@id) and&#10;                not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)&#10;            ])]"/>
+    <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[&#10;        not(descendant::*[&#10;            not(self::svg:g) and&#10;            not(@id = $discardable_elements/@id) and&#10;            not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)&#10;        ])]"/>
     <xsl:variable name="groups_to_add" select="$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"/>
     <func:result select="$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]"/>
   </func:function>
@@ -147,7 +147,7 @@
     <xsl:param name="pages"/>
     <xsl:choose>
       <xsl:when test="$pages">
-        <func:result select="func:sumarized_elements(func:all_related_elements($pages[1]))&#10;                          | func:detachable_elements($pages[position()!=1])"/>
+        <func:result select="func:sumarized_elements(func:all_related_elements($pages[1]))&#10;                      | func:detachable_elements($pages[position()!=1])"/>
       </xsl:when>
       <xsl:otherwise>
         <func:result select="/.."/>
--- a/svghmi/gen_index_xhtml.ysl2	Tue Mar 17 08:00:33 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2	Tue Mar 17 09:29:04 2020 +0100
@@ -65,79 +65,9 @@
     }
     const "categories", "exsl:node-set($_categories)";
 
-
-    // returns all directly or indirectly refered elements
-    def "func:refered_elements" {
-        param "elems";
-        const "descend", "$elems/descendant-or-self::svg:*";
-        const "clones", "$descend[self::svg:use]";
-        const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
-        choose {
-            when "$originals"
-                result "$descend | func:refered_elements($originals)";
-            otherwise
-                result "$descend";
-        }
-    }
-
     include geometry.ysl2
 
-
-    def "func:all_related_elements" {
-        param "page";
-        const "page_overlapping_geometry", "func:overlapping_geometry($page)";
-        const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]";
-        const "page_sub_elements", "func:refered_elements($page | $page_overlapping_elements)";
-        result "$page_sub_elements";
-    }
-
-    def "func:required_elements" {
-        param "pages"; 
-        choose{
-            when "$pages"{
-                result """func:all_related_elements($pages[1])
-                          | func:required_elements($pages[position()!=1])""";
-            }otherwise{
-                result "/..";
-            }
-        }
-    }
-
-    const "required_elements",
-        """//svg:defs/descendant-or-self::svg:*
-           | func:required_elements($hmi_pages)/ancestor-or-self::svg:*""";
-
-    const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
-
-    def "func:sumarized_elements" {
-        param "elements";
-        const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
-        const "filled_groups", """$short_list/parent::svg:*[
-            not(descendant::*[
-                not(self::svg:g) and
-                not(@id = $discardable_elements/@id) and
-                not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)
-            ])]""";
-        const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
-        result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
-    }
-
-    def "func:detachable_elements" {
-        param "pages";
-        choose{
-            when "$pages"{
-                result """func:sumarized_elements(func:all_related_elements($pages[1]))
-                          | func:detachable_elements($pages[position()!=1])""";
-            }otherwise{
-                result "/..";
-            }
-        }
-    }
-
-    // Avoid nested detachables
-    const "_detachable_elements", "func:detachable_elements($hmi_pages)";
-    const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]";
-
+    include detachable_elements.ysl2
 
     include hmi_tree.ysl2
 
--- a/svghmi/geometry.ysl2	Tue Mar 17 08:00:33 2020 +0100
+++ b/svghmi/geometry.ysl2	Tue Mar 17 09:29:04 2020 +0100
@@ -9,7 +9,7 @@
 
 // Debug data
 function "debug_geometry" {
-    | GEOMETRY : ID, x, y, w, h
+    | ID, x, y, w, h
     foreach "$geometry[@Id = $hmi_elements/@id]"
         |  «@Id» «@x» «@y» «@w» «@h»
 }