svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2843 94696b3f69fb
parent 2842 2f73f001955a
child 2844 eee5dcd9fc92
equal deleted inserted replaced
2842:2f73f001955a 2843:94696b3f69fb
    70     }
    70     }
    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 
       
    76     // TODO globally discardable elements, not (used by | ancestor of) any page
       
    77 
       
    78 
    75     template "*", mode="index" {
    79     template "*", mode="index" {
    76         param "index", "0";
    80         param "index", "0";
    77         param "parentpath", "''";
    81         param "parentpath", "''";
    78         const "content" {
    82         const "content" {
    79             const "path"
    83             const "path"
   111      *  - copy every sub-elements
   115      *  - copy every sub-elements
   112      */
   116      */
   113     template "@* | node()", mode="inline_svg" {
   117     template "@* | node()", mode="inline_svg" {
   114       /* use real xsl:copy instead copy-of alias from yslt.yml2 */
   118       /* use real xsl:copy instead copy-of alias from yslt.yml2 */
   115       xsl:copy apply "@* | node()", mode="inline_svg";
   119       xsl:copy apply "@* | node()", mode="inline_svg";
       
   120       /* TODO filter out globally discardable elements */
   116     }
   121     }
   117 
   122 
   118     /* replaces inkscape's height and width hints. forces fit */
   123     /* replaces inkscape's height and width hints. forces fit */
   119     template "svg:svg/@width", mode="inline_svg";
   124     template "svg:svg/@width", mode="inline_svg";
   120     template "svg:svg/@height", mode="inline_svg";
   125     template "svg:svg/@height", mode="inline_svg";
   131     /* ensure that coordinate in CSV file generated by inkscape match svg default unit */
   136     /* ensure that coordinate in CSV file generated by inkscape match svg default unit */
   132     template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
   137     template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
   133         error > All units must be set to "px" in Inkscape's document properties
   138         error > All units must be set to "px" in Inkscape's document properties
   134     }
   139     }
   135 
   140 
   136     /* clone unlinkink until widget for better perf with webkit */
   141     
   137     svgtmpl "svg:use", mode="inline_svg" 
   142     //// Commented out before implementing runtime DOM remove/append on page switch - would have side effect
   138     {
   143     ////
   139         g{
   144     //// /* clone unlinkink until widget for better perf with webkit */
   140             attrib "style" > «@style»
   145     //// svgtmpl "svg:use", mode="inline_svg" 
   141             attrib "transform" > «@transform»
   146     //// {
   142             /* keep same id and label in case it is a widget */
   147     ////     g{
   143             //attrib "inkscape:label","@inkscape:label";
   148     ////         attrib "style" > «@style»
   144             attrib "id" > «@id»
   149     ////         attrib "transform" > «@transform»
   145             const "targetid","substring-after(@xlink:href,'#')";
   150     ////         /* keep same id and label in case it is a widget */
   146             apply "//svg:*[@id = $targetid]", mode="unlink_clone";
   151     ////         //attrib "inkscape:label","@inkscape:label";
   147         }
   152     ////         attrib "id" > «@id»
   148     }
   153     ////         const "targetid","substring-after(@xlink:href,'#')";
   149     svgtmpl "@*", mode="unlink_clone" xsl:copy;
   154     ////         apply "//svg:*[@id = $targetid]", mode="unlink_clone";
   150     svgtmpl "svg:*", mode="unlink_clone" {
   155     ////     }
   151         choose {
   156     //// }
   152             when "@id = $hmi_elements/@id" {
   157     //// svgtmpl "@*", mode="unlink_clone" xsl:copy;
   153                 use{
   158     //// svgtmpl "svg:*", mode="unlink_clone" {
   154                     attrib "xlink:href" > «concat('#',@id)»
   159     ////     choose {
   155                 }
   160     ////         when "@id = $hmi_elements/@id" {
   156             }
   161     ////             use{
   157             otherwise {
   162     ////                 attrib "xlink:href" > «concat('#',@id)»
   158                 xsl:copy apply "@* | node()", mode="unlink_clone";
   163     ////             }
   159             }
   164     ////         }
   160         }
   165     ////         otherwise {
   161     }
   166     ////             xsl:copy apply "@* | node()", mode="unlink_clone";
       
   167     ////         }
       
   168     ////     }
       
   169     //// }
   162 
   170 
   163     // template "svg:use/@style", mode="inline_svg"{
   171     // template "svg:use/@style", mode="inline_svg"{
   164     //     attrib "style" > all:initial;
   172     //     attrib "style" > all:initial;
   165     //     //«.»
   173     //     //«.»
   166     // }
   174     // }
   210             path value="path1";
   218             path value="path1";
   211             path value="path2";
   219             path value="path2";
   212         }
   220         }
   213     */
   221     */
   214 
   222 
   215     func:function name="func:parselabel" {
   223     def "func:parselabel" {
   216         param "label";
   224         param "label";
   217         const "description", "substring-after($label,'HMI:')";
   225         const "description", "substring-after($label,'HMI:')";
   218 
   226 
   219         const "_args", "substring-before($description,'@')";
   227         const "_args", "substring-before($description,'@')";
   220         const "args" choose {
   228         const "args" choose {
   241                     attrib "value" > «.»
   249                     attrib "value" > «.»
   242                 }
   250                 }
   243             }
   251             }
   244         }
   252         }
   245 
   253 
   246         func:result select="exsl:node-set($ast)"
   254         result "exsl:node-set($ast)";
   247     }
   255     }
   248 
   256 
   249     // returns all directly or indirectly refered elements
   257     // returns all directly or indirectly refered elements
   250     func:function name="func:refered_elements" {
   258     def "func:refered_elements" {
   251         param "elems";
   259         param "elems";
   252         const "descend", "$elems/descendant-or-self::svg:*";
   260         const "descend", "$elems/descendant-or-self::svg:*";
   253         const "clones", "$descend[self::svg:use]";
   261         const "clones", "$descend[self::svg:use]";
   254         const "reals", "$descend[not(self::svg:use)]";
       
   255         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
   262         const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
   256         choose {
   263         choose {
   257             when "$originals" 
   264             when "$originals" 
   258                 func:result select="$reals | func:refered_elements($originals)";
   265                 result "$descend | func:refered_elements($originals)";
   259             otherwise
   266             otherwise
   260                 func:result select="$reals";
   267                 result "$descend";
   261         }
   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";
   262     }
   297     }
   263 
   298 
   264     function "scripts"
   299     function "scripts"
   265     {
   300     {
   266         | //(function(){
   301         | //(function(){
   322             | /* «@index»  «@hmipath» */ "«substring(local-name(), 5)»"`if "position()!=last()" > ,`
   357             | /* «@index»  «@hmipath» */ "«substring(local-name(), 5)»"`if "position()!=last()" > ,`
   323         }
   358         }
   324 
   359 
   325         | ]
   360         | ]
   326         |
   361         |
       
   362 
   327         | var page_desc = {
   363         | var page_desc = {
   328 
   364 
   329         foreach "$hmi_pages" {
   365         foreach "$hmi_pages" {
   330             const "desc", "func:parselabel(@inkscape:label)/widget";
   366             const "desc", "func:parselabel(@inkscape:label)/widget";
   331             const "page", "."; 
   367             const "page", ".";
   332             const "p", "$hmi_geometry[@Id = $page/@id]"; 
   368             const "p", "$geometry[@Id = $page/@id]"; 
   333             const "page_ids","""$hmi_geometry[@Id != $page/@id and 
   369 
   334                                 @x >= $p/@x and @y >= $p/@y and 
   370             const "page_all_elements", "func:all_related_elements($page)";
   335                                 @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id""";
   371 
   336             const "page_sub_ids", "func:refered_elements($page)[@id = $hmi_elements/@id]/@id";
   372             const "all_page_ids","$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id";
   337             const "all_page_ids","$page_ids | $page_sub_ids[not(. = $page_ids)]"; 
   373 
       
   374             const "shorter_list", "func:sumarized_elements($page_all_elements)";
       
   375 
   338             |     "«$desc/arg[1]/@value»": {
   376             |     "«$desc/arg[1]/@value»": {
   339             |         widget: hmi_widgets["«@id»"],
   377             |         widget: hmi_widgets["«@id»"],
   340             |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   378             |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
   341             |         widgets: [
   379             |         widgets: [
   342             foreach "$all_page_ids" {
   380             foreach "$all_page_ids" {
   343             |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
   381             |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
       
   382             }
       
   383             |         ]
       
   384             |         required_elements: [
       
   385             foreach "$shorter_list" {
       
   386             |             "«@id»",
   344             }
   387             }
   345             |         ]
   388             |         ]
   346             |     }`if "position()!=last()" > ,`
   389             |     }`if "position()!=last()" > ,`
   347         }
   390         }
   348         | }
   391         | }