SVGHMI: now compute discardable elements first so that we can do better grouping of required elements when sumarizing. svghmi
authorEdouard Tisserant
Fri, 28 Feb 2020 22:54:07 +0100
branchsvghmi
changeset 2846 7b1db17287b6
parent 2845 61548f7d1bef
child 2847 dffade5c83d3
SVGHMI: now compute discardable elements first so that we can do better grouping of required elements when sumarizing.
svghmi/gen_index_xhtml.xslt
svghmi/gen_index_xhtml.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Fri Feb 28 17:52:35 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Fri Feb 28 22:54:07 2020 +0100
@@ -100,18 +100,12 @@
       </xsl:otherwise>
     </xsl:choose>
   </func:function>
+  <xsl:variable name="groups" select="/svg:svg | //svg:g"/>
   <func:function name="func:overlapping_geometry">
     <xsl:param name="elt"/>
     <xsl:variable name="g" select="$geometry[@Id = $elt/@id]"/>
     <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
-    <func:result select="$candidates[func:intersect($g, .) = 9]"/>
-  </func:function>
-  <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:*[not(descendant::*[not(self::svg:g)][not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)])]"/>
-    <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: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:all_related_elements">
     <xsl:param name="page"/>
@@ -120,6 +114,26 @@
     <xsl:variable name="page_sub_elements" select="func:refered_elements($page | $page_overlapping_elements)"/>
     <func:result select="$page_sub_elements"/>
   </func:function>
+  <func:function name="func:required_elements">
+    <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])"/>
+      </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="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="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>
   <func:function name="func:detachable_elements">
     <xsl:param name="pages"/>
     <xsl:choose>
@@ -132,9 +146,6 @@
     </xsl:choose>
   </func:function>
   <xsl:variable name="detachable_elements" select="func:detachable_elements($hmi_pages)"/>
-  <xsl:variable name="essential_elements" select="$detachable_elements | /svg:svg/svg:defs"/>
-  <xsl:variable name="required_elements" select="$essential_elements//svg:* | $essential_elements/ancestor-or-self::svg:*"/>
-  <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/>
   <xsl:template mode="index" match="*">
     <xsl:param name="index" select="0"/>
     <xsl:param name="parentpath" select="''"/>
@@ -184,9 +195,11 @@
     </xsl:apply-templates>
   </xsl:template>
   <xsl:template mode="inline_svg" match="@* | node()">
-    <xsl:copy>
-      <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
-    </xsl:copy>
+    <xsl:if test="not(@id = $discardable_elements/@id)">
+      <xsl:copy>
+        <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
+      </xsl:copy>
+    </xsl:if>
   </xsl:template>
   <xsl:template mode="inline_svg" match="svg:svg/@width"/>
   <xsl:template mode="inline_svg" match="svg:svg/@height"/>
--- a/svghmi/gen_index_xhtml.ysl2	Fri Feb 28 17:52:35 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2	Fri Feb 28 22:54:07 2020 +0100
@@ -200,25 +200,14 @@
     // return overlapping geometry for a given element
     // all intersercting element are returned
     // except groups, that must be contained to be counted in
+    const "groups", "/svg:svg | //svg:g";
+
     def "func:overlapping_geometry" {
         param "elt";
         const "g", "$geometry[@Id = $elt/@id]"; 
         const "candidates", "$geometry[@Id != $elt/@id]";
-        result "$candidates[func:intersect($g, .) = 9]";
-/*
-        const "groups", "$candidates[@Id = //svg:g/@id]"; 
-        const "graphic", "$candidates[@Id != $groups/@Id]"; 
-        result "$groups[func:intersect($g, .) = 9] | $graphic[func:intersect($g, .) > 0]";
-        */
-    }
-
-    def "func:sumarized_elements" {
-        param "elements";
-        const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
-        /* TODO exclude globally discardable elements from group fulfillment check */
-        const "filled_groups", "$short_list/parent::svg:*[not(descendant::*[not(self::svg:g)][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)]";
+        result """$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or 
+                              (not(@Id = $groups/@id) and (func:intersect($g, .) > 0 ))]""";
     }
 
     def "func:all_related_elements" {
@@ -229,6 +218,37 @@
         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{
@@ -242,9 +262,8 @@
     }
     
     const "detachable_elements", "func:detachable_elements($hmi_pages)";
-    const "essential_elements", "$detachable_elements | /svg:svg/svg:defs";
-    const "required_elements", "$essential_elements//svg:* | $essential_elements/ancestor-or-self::svg:*";
-    const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
+    // const "essential_elements", "$detachable_elements | /svg:svg/svg:defs";
+    // const "required_elements", "$essential_elements//svg:* | $essential_elements/ancestor-or-self::svg:*";
 
     template "*", mode="index" {
         param "index", "0";
@@ -286,8 +305,8 @@
      */
     template "@* | node()", mode="inline_svg" {
       /* use real xsl:copy instead copy-of alias from yslt.yml2 */
-      xsl:copy apply "@* | node()", mode="inline_svg";
-      /* TODO filter out globally discardable elements */
+      if "not(@id = $discardable_elements/@id)"
+          xsl:copy apply "@* | node()", mode="inline_svg";
     }
 
     /* replaces inkscape's height and width hints. forces fit */