svghmi/detachable_elements.ysl2
branchsvghmi
changeset 2877 682bce953795
parent 2876 d2adbc273125
child 2878 bec552270ad1
equal deleted inserted replaced
2876:d2adbc273125 2877:682bce953795
     1 // detachable_elements.ysl2
       
     2 //
       
     3 // compute what elements are required by pages
       
     4 // and decide where to cut when removing/attaching 
       
     5 // pages elements on page switch
       
     6 
       
     7 // returns all directly or indirectly refered elements
       
     8 def "func:refered_elements" {
       
     9     param "elems";
       
    10     const "descend", "$elems/descendant-or-self::svg:*";
       
    11     const "clones", "$descend[self::svg:use]";
       
    12     const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
       
    13     choose {
       
    14         when "$originals"
       
    15             result "$descend | func:refered_elements($originals)";
       
    16         otherwise
       
    17             result "$descend";
       
    18     }
       
    19 }
       
    20 
       
    21 def "func:all_related_elements" {
       
    22     param "page";
       
    23     const "page_overlapping_geometry", "func:overlapping_geometry($page)";
       
    24     const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]";
       
    25     const "page_sub_elements", "func:refered_elements($page | $page_overlapping_elements)";
       
    26     result "$page_sub_elements";
       
    27 }
       
    28 
       
    29 def "func:required_elements" {
       
    30     param "pages"; 
       
    31     choose{
       
    32         when "$pages"{
       
    33             result """func:all_related_elements($pages[1])
       
    34                       | func:required_elements($pages[position()!=1])""";
       
    35         }otherwise{
       
    36             result "/..";
       
    37         }
       
    38     }
       
    39 }
       
    40 
       
    41 const "required_elements",
       
    42     """//svg:defs/descendant-or-self::svg:*
       
    43        | func:required_elements($hmi_pages)/ancestor-or-self::svg:*""";
       
    44 
       
    45 const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
       
    46 
       
    47 def "func:sumarized_elements" {
       
    48     param "elements";
       
    49     const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
       
    50     const "filled_groups", """$short_list/parent::svg:*[
       
    51         not(descendant::*[
       
    52             not(self::svg:g) and
       
    53             not(@id = $discardable_elements/@id) and
       
    54             not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)
       
    55         ])]""";
       
    56     const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
       
    57     result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
       
    58 }
       
    59 
       
    60 def "func:detachable_elements" {
       
    61     param "pages";
       
    62     choose{
       
    63         when "$pages"{
       
    64             result """func:sumarized_elements(func:all_related_elements($pages[1]))
       
    65                       | func:detachable_elements($pages[position()!=1])""";
       
    66         }otherwise{
       
    67             result "/..";
       
    68         }
       
    69     }
       
    70 }
       
    71 
       
    72 // Avoid nested detachables
       
    73 const "_detachable_elements", "func:detachable_elements($hmi_pages)";
       
    74 const "detachable_elements", "$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]";
       
    75 
       
    76 function "debug_detachables" {
       
    77     foreach "$detachable_elements"{
       
    78         |  «@id»
       
    79     }
       
    80 }
       
    81 !debug_output_calls.append("debug_detachables")