svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2844 eee5dcd9fc92
parent 2843 94696b3f69fb
child 2845 61548f7d1bef
equal deleted inserted replaced
2843:94696b3f69fb 2844:eee5dcd9fc92
    71     const "categories", "exsl:node-set($_categories)";
    71     const "categories", "exsl:node-set($_categories)";
    72     const "_indexed_hmitree" apply "$hmitree", mode="index";
    72     const "_indexed_hmitree" apply "$hmitree", mode="index";
    73     const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)";
    73     const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)";
    74 
    74 
    75 
    75 
    76     // TODO globally discardable elements, not (used by | ancestor of) any page
    76     // returns all directly or indirectly refered elements
    77 
    77     def "func:refered_elements" {
       
    78         param "elems";
       
    79         const "descend", "$elems/descendant-or-self::svg:*";
       
    80         const "clones", "$descend[self::svg:use]";
       
    81         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
       
    82         choose {
       
    83             when "$originals" 
       
    84                 result "$descend | func:refered_elements($originals)";
       
    85             otherwise
       
    86                 result "$descend";
       
    87         }
       
    88     }
       
    89 
       
    90     def "func:intersect_1d" {
       
    91         /* it is assumed that a1 > a0 and b1 > b0 */
       
    92         param "a0";
       
    93         param "a1";
       
    94         param "b0";
       
    95         param "b1";
       
    96 
       
    97         const "d0", "$a0 >= $b0";
       
    98         const "d1", "$a1 >= $b1";
       
    99         choose {
       
   100             when "not($d0) and $d1"
       
   101                 result "3"; /* a included in b */
       
   102             when "$d0 and not($d1)"
       
   103                 result "2"; /* b included in a */
       
   104             when "$d0 = $d1 and $b0 < $a1"
       
   105                 result "1"; /* a and b are overlapped */
       
   106             otherwise
       
   107                 result "0"; /* no intersection*/
       
   108         }
       
   109     }
       
   110 
       
   111     def "func:intersect" {
       
   112         param "a";
       
   113         param "b";
       
   114 
       
   115         const "x_intersect", "func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)";
       
   116 
       
   117         choose{
       
   118             when "$x_intersect != 0"{
       
   119                 const "y_intersect", "func:intersect_1d($a/@y, $a/@y+$a/@w, $b/@y, $b/@y+$b/@w)";
       
   120                 result "$x_intersect * $y_intersect";
       
   121             }
       
   122             otherwise result "0";
       
   123         }
       
   124     }
       
   125 
       
   126     // return overlapping geometry a given element
       
   127     def "func:overlapping_geometry" {
       
   128         param "elt";
       
   129         /* only included groups are returned */
       
   130         /* all other elemenst are returne when overlapping*/
       
   131         const "g", "$geometry[@Id = $elt/@id]"; 
       
   132         result """$geometry[@Id != $elt/@id and func:intersect(., $g) = 4]""";
       
   133     }
       
   134 
       
   135     def "func:sumarized_elements" {
       
   136         param "elements";
       
   137         const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
       
   138         /* TODO exclude globally discardable elements from group fulfillment check */
       
   139         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)])]";
       
   140         const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
       
   141         result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
       
   142     }
       
   143 
       
   144     def "func:all_related_elements" {
       
   145         param "page";
       
   146         const "page_overlapping_geometry", "func:overlapping_geometry($page)";
       
   147         const "page_overlapping_elements", "//svg:*[@id = $page_overlapping_geometry/@Id]";
       
   148         const "page_sub_elements", "func:refered_elements($page | $page_overlapping_elements)";
       
   149         result "$page_sub_elements";
       
   150     }
       
   151 
       
   152     def "func:detachable_elements" {
       
   153         param "pages"; 
       
   154         choose{
       
   155             when "$pages"{
       
   156                 result """func:sumarized_elements(func:all_related_elements($pages[1]))
       
   157                           | func:detachable_elements($pages[position()!=1])""";
       
   158             }otherwise{
       
   159                 result "/..";
       
   160             }
       
   161         }
       
   162     }
       
   163     
       
   164     const "detachable_elements", "func:detachable_elements($hmi_pages)";
       
   165     const "essential_elements", "$detachable_elements | /svg:svg/svg:defs";
       
   166     const "required_elements", "$essential_elements//svg:* | $essential_elements/ancestor-or-self::svg:*";
       
   167     const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
    78 
   168 
    79     template "*", mode="index" {
   169     template "*", mode="index" {
    80         param "index", "0";
   170         param "index", "0";
    81         param "parentpath", "''";
   171         param "parentpath", "''";
    82         const "content" {
   172         const "content" {
   191             apply "$hmitree", mode="testtree";
   281             apply "$hmitree", mode="testtree";
   192         }
   282         }
   193         comment {
   283         comment {
   194             apply "$indexed_hmitree", mode="testtree";
   284             apply "$indexed_hmitree", mode="testtree";
   195         }
   285         }
       
   286         comment {
       
   287             | Detachable :
       
   288             foreach "$detachable_elements"{
       
   289                 | «@id»
       
   290             }
       
   291         }
       
   292         comment {
       
   293             | Discardable :
       
   294             foreach "$discardable_elements"{
       
   295                 | «@id»
       
   296             }
       
   297         }
   196         /**/
   298         /**/
   197         html xmlns="http://www.w3.org/1999/xhtml"
   299         html xmlns="http://www.w3.org/1999/xhtml"
   198              xmlns:svg="http://www.w3.org/2000/svg"
   300              xmlns:svg="http://www.w3.org/2000/svg"
   199              xmlns:xlink="http://www.w3.org/1999/xlink" {
   301              xmlns:xlink="http://www.w3.org/1999/xlink" {
   200             head;
   302             head;
   250                 }
   352                 }
   251             }
   353             }
   252         }
   354         }
   253 
   355 
   254         result "exsl:node-set($ast)";
   356         result "exsl:node-set($ast)";
   255     }
       
   256 
       
   257     // returns all directly or indirectly refered elements
       
   258     def "func:refered_elements" {
       
   259         param "elems";
       
   260         const "descend", "$elems/descendant-or-self::svg:*";
       
   261         const "clones", "$descend[self::svg:use]";
       
   262         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
       
   263         choose {
       
   264             when "$originals" 
       
   265                 result "$descend | func:refered_elements($originals)";
       
   266             otherwise
       
   267                 result "$descend";
       
   268         }
       
   269     }
       
   270 
       
   271     // return included geometry a given element
       
   272     def "func:included_geometry" {
       
   273         param "elt";
       
   274         const "g", "$geometry[@Id = $elt/@id]"; 
       
   275         result """$geometry[@Id != $elt/@id and
       
   276                            @x >= $g/@x and @y >= $g/@y and 
       
   277                            @x+@w <= $g/@x+$g/@w and @y+@h <= $g/@y+$g/@h]""";
       
   278 
       
   279     }
       
   280 
       
   281     def "func:sumarized_elements" {
       
   282         param "elements";
       
   283         const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
       
   284         /* TODO exclude globally discardable elements from group fulfillment check */
       
   285         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)])]";
       
   286         const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
       
   287         result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
       
   288     }
       
   289 
       
   290     def "func:all_related_elements" {
       
   291         param "page";
       
   292         const "page_included_geometry", "func:included_geometry($page)";
       
   293         const "page_sub_elements", "func:refered_elements($page)";
       
   294 
       
   295         const "page_included_elements", "//svg:*[@id = $page_included_geometry/@Id]";
       
   296         result "$page_sub_elements | $page_included_elements";
       
   297     }
   357     }
   298 
   358 
   299     function "scripts"
   359     function "scripts"
   300     {
   360     {
   301         | //(function(){
   361         | //(function(){
   378             |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   438             |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   379             |         widgets: [
   439             |         widgets: [
   380             foreach "$all_page_ids" {
   440             foreach "$all_page_ids" {
   381             |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
   441             |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
   382             }
   442             }
   383             |         ]
   443             |         ],
   384             |         required_elements: [
   444             |         required_elements: [
   385             foreach "$shorter_list" {
   445             foreach "$shorter_list" {
   386             |             "«@id»",
   446             |             "«@id»",
   387             }
   447             }
   388             |         ]
   448             |         ]