svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2853 6d39beb19f38
parent 2852 f7349ca820c9
child 2854 c7d5f46cc306
equal deleted inserted replaced
2852:f7349ca820c9 2853:6d39beb19f38
    76     // returns all directly or indirectly refered elements
    76     // returns all directly or indirectly refered elements
    77     def "func:refered_elements" {
    77     def "func:refered_elements" {
    78         param "elems";
    78         param "elems";
    79         const "descend", "$elems/descendant-or-self::svg:*";
    79         const "descend", "$elems/descendant-or-self::svg:*";
    80         const "clones", "$descend[self::svg:use]";
    80         const "clones", "$descend[self::svg:use]";
    81         // TODO optimize using Xpath' id()
       
    82         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
    81         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
    83         choose {
    82         choose {
    84             when "$originals" 
    83             when "$originals"
    85                 result "$descend | func:refered_elements($originals)";
    84                 result "$descend | func:refered_elements($originals)";
    86             otherwise
    85             otherwise
    87                 result "$descend";
    86                 result "$descend";
    88         }
    87         }
    89     }
    88     }
    90 
    89 
    91     def "func:intersect_1d" {
    90     def "func:intersect_1d" {
    92         /* it is assumed that a1 > a0 and b1 > b0 */
    91         // it is assumed that a1 > a0 and b1 > b0
    93         param "a0";
    92         param "a0";
    94         param "a1";
    93         param "a1";
    95         param "b0";
    94         param "b0";
    96         param "b1";
    95         param "b1";
    97 
    96 
   142     //    |   |  |  |
   141     //    |   |  |  |
   143     //    |   '-----'
   142     //    |   '-----'
   144     //    |a     |
   143     //    |a     |
   145     //    '------'
   144     //    '------'
   146     //
   145     //
   147     // 2 - overlapping 
   146     // 2 - overlapping
   148     //        .-----.    
   147     //        .-----.
   149     //        |  a  |
   148     //        |  a  |
   150     //    .---|-----|---.
   149     //    .---|-----|---.
   151     //    |   '-----'   |
   150     //    |   '-----'   |
   152     //    | b           |
   151     //    | b           |
   153     //    '-------------'
   152     //    '-------------'
   154     //
   153     //
   155     // 3 - overlapping 
   154     // 3 - overlapping
   156     //        .-----.    
   155     //        .-----.
   157     //        |  b  |    
   156     //        |  b  |
   158     //    .---|-----|---.
   157     //    .---|-----|---.
   159     //    |   '-----'   |
   158     //    |   '-----'   |
   160     //    | a           |
   159     //    | a           |
   161     //    '-------------'
   160     //    '-------------'
   162     //
   161     //
   166     //    |   |  a  |   |
   165     //    |   |  a  |   |
   167     //    |b  '-----'   |
   166     //    |b  '-----'   |
   168     //    '-------------'
   167     //    '-------------'
   169     //
   168     //
   170     // 6 - overlapping
   169     // 6 - overlapping
   171     //        .----.    
   170     //        .----.
   172     //        |   b|    
   171     //        |   b|
   173     //    .---|----|---.
   172     //    .---|----|---.
   174     //    |a  |    |   |
   173     //    |a  |    |   |
   175     //    '---|----|---'
   174     //    '---|----|---'
   176     //        '----'
   175     //        '----'
   177     //
   176     //
   198     }
   197     }
   199 
   198 
   200     // return overlapping geometry for a given element
   199     // return overlapping geometry for a given element
   201     // all intersercting element are returned
   200     // all intersercting element are returned
   202     // except groups, that must be contained to be counted in
   201     // except groups, that must be contained to be counted in
   203     const "groups", "/svg:svg | //svg:g";
       
   204 
       
   205     def "func:overlapping_geometry" {
   202     def "func:overlapping_geometry" {
   206         param "elt";
   203         param "elt";
       
   204         const "groups", "/svg:svg | //svg:g";
   207         const "g", "$geometry[@Id = $elt/@id]"; 
   205         const "g", "$geometry[@Id = $elt/@id]"; 
   208         const "candidates", "$geometry[@Id != $elt/@id]";
   206         const "candidates", "$geometry[@Id != $elt/@id]";
   209         result """$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or 
   207         result """$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or 
   210                               (not(@Id = $groups/@id) and (func:intersect($g, .) > 0 ))]""";
   208                               (not(@Id = $groups/@id) and (func:intersect($g, .) > 0 ))]""";
   211     }
   209     }
   228                 result "/..";
   226                 result "/..";
   229             }
   227             }
   230         }
   228         }
   231     }
   229     }
   232 
   230 
   233     const "required_elements", 
   231     const "required_elements",
   234         """//svg:defs/descendant-or-self::svg:*
   232         """//svg:defs/descendant-or-self::svg:*
   235            | func:required_elements($hmi_pages)/ancestor-or-self::svg:*""";
   233            | func:required_elements($hmi_pages)/ancestor-or-self::svg:*""";
   236 
   234 
   237     const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
   235     const "discardable_elements", "//svg:*[not(@id = $required_elements/@id)]";
   238 
   236 
   239     def "func:sumarized_elements" {
   237     def "func:sumarized_elements" {
   240         param "elements";
   238         param "elements";
   241         const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
   239         const "short_list", "$elements[not(ancestor::*/@id = $elements/@id)]";
   242         const "filled_groups", """$short_list/parent::svg:*[
   240         const "filled_groups", """$short_list/parent::svg:*[
   243             not(descendant::*[
   241             not(descendant::*[
   244                 not(self::svg:g) and 
   242                 not(self::svg:g) and
   245                 not(@id = $discardable_elements/@id) and
   243                 not(@id = $discardable_elements/@id) and
   246                 not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)
   244                 not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)
   247             ])]""";
   245             ])]""";
   248         const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
   246         const "groups_to_add", "$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]";
   249         result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
   247         result "$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]";
   250     }
   248     }
   251 
   249 
   252     def "func:detachable_elements" {
   250     def "func:detachable_elements" {
   253         param "pages"; 
   251         param "pages";
   254         choose{
   252         choose{
   255             when "$pages"{
   253             when "$pages"{
   256                 result """func:sumarized_elements(func:all_related_elements($pages[1]))
   254                 result """func:sumarized_elements(func:all_related_elements($pages[1]))
   257                           | func:detachable_elements($pages[position()!=1])""";
   255                           | func:detachable_elements($pages[position()!=1])""";
   258             }otherwise{
   256             }otherwise{
   259                 result "/..";
   257                 result "/..";
   260             }
   258             }
   261         }
   259         }
   262     }
   260     }
   263     
   261 
   264     const "detachable_elements", "func:detachable_elements($hmi_pages)";
   262     const "detachable_elements", "func:detachable_elements($hmi_pages)";
   265     // const "essential_elements", "$detachable_elements | /svg:svg/svg:defs";
   263 
   266     // const "required_elements", "$essential_elements//svg:* | $essential_elements/ancestor-or-self::svg:*";
   264 
       
   265 
       
   266     //////////////// HMI Tree Index
   267 
   267 
   268     template "*", mode="index" {
   268     template "*", mode="index" {
   269         param "index", "0";
   269         param "index", "0";
   270         param "parentpath", "''";
   270         param "parentpath", "''";
   271         const "content" {
   271         const "content" {
   297             with "index", "$index + count(exsl:node-set($content)/*)";
   297             with "index", "$index + count(exsl:node-set($content)/*)";
   298             with "parentpath" > «$parentpath»
   298             with "parentpath" > «$parentpath»
   299         }
   299         }
   300     }
   300     }
   301 
   301 
   302     /* Identity template :
   302 
   303      *  - copy every attributes 
   303 
   304      *  - copy every sub-elements
   304     //////////////// Inline SVG
   305      */
   305 
       
   306     // Identity template :
       
   307     //  - copy every attributes 
       
   308     //  - copy every sub-elements
   306     template "@* | node()", mode="inline_svg" {
   309     template "@* | node()", mode="inline_svg" {
   307       /* use real xsl:copy instead copy-of alias from yslt.yml2 */
   310       // use real xsl:copy instead copy-of alias from yslt.yml2
   308       if "not(@id = $discardable_elements/@id)"
   311       if "not(@id = $discardable_elements/@id)"
   309           xsl:copy apply "@* | node()", mode="inline_svg";
   312           xsl:copy apply "@* | node()", mode="inline_svg";
   310     }
   313     }
   311 
   314 
   312     /* replaces inkscape's height and width hints. forces fit */
   315     // replaces inkscape's height and width hints. forces fit
   313     template "svg:svg/@width", mode="inline_svg";
   316     template "svg:svg/@width", mode="inline_svg";
   314     template "svg:svg/@height", mode="inline_svg";
   317     template "svg:svg/@height", mode="inline_svg";
   315     svgtmpl "svg:svg", mode="inline_svg" svg {
   318     svgtmpl "svg:svg", mode="inline_svg" svg {
   316         attrib "preserveAspectRatio" > none
   319         attrib "preserveAspectRatio" > none
   317         attrib "height" > 100vh
   320         attrib "height" > 100vh
   318         attrib "width" > 100vw
   321         attrib "width" > 100vw
   319         apply "@* | node()", mode="inline_svg";
   322         apply "@* | node()", mode="inline_svg";
   320     }
   323     }
   321     /* ensure that coordinate in CSV file generated by inkscape are in default reference frame */
   324     // ensure that coordinate in CSV file generated by inkscape are in default reference frame
   322     template "svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]", mode="inline_svg" {
   325     template "svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]", mode="inline_svg" {
   323         error > ViewBox settings other than X=0, Y=0 and Scale=1 are not supported
   326         error > ViewBox settings other than X=0, Y=0 and Scale=1 are not supported
   324     }
   327     }
   325     /* ensure that coordinate in CSV file generated by inkscape match svg default unit */
   328     // ensure that coordinate in CSV file generated by inkscape match svg default unit
   326     template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
   329     template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
   327         error > All units must be set to "px" in Inkscape's document properties
   330         error > All units must be set to "px" in Inkscape's document properties
   328     }
   331     }
   329 
   332 
   330     
   333     
   368     // }
   371     // }
   369 
   372 
   370     /*const "mark" > =HMI=\n*/
   373     /*const "mark" > =HMI=\n*/
   371 
   374 
   372     /* copy root node and add geometry as comment for a test */
   375     /* copy root node and add geometry as comment for a test */
   373     template "/" { 
   376     template "/" {
   374         comment > Made with SVGHMI. https://beremiz.org
   377         comment > Made with SVGHMI. https://beremiz.org
   375         /* DEBUG DATA */
   378         /* DEBUG DATA */
   376         comment {
   379         comment {
   377             apply "$hmi_geometry", mode="testgeo";
   380             apply "$hmi_geometry", mode="testgeo";
   378         }
   381         }
   624                 when "not($elt_id)" {
   627                 when "not($elt_id)" {
   625                     if "$mandatory='yes'" {
   628                     if "$mandatory='yes'" {
   626                         // TODO FIXME error > «$widget_type» widget must have a «$name» element
   629                         // TODO FIXME error > «$widget_type» widget must have a «$name» element
   627                         warning > «$widget_type» widget must have a «$name» element
   630                         warning > «$widget_type» widget must have a «$name» element
   628                     }
   631                     }
   629                     // otherwise produce nothing 
   632                     // otherwise produce nothing
   630                 }
   633                 }
   631                 otherwise {
   634                 otherwise {
   632                     |     «$name»_elt: id("«$elt_id»"),
   635                     |     «$name»_elt: id("«$elt_id»"),
   633                 }
   636                 }
   634             }
   637             }