svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2852 f7349ca820c9
parent 2851 8d15c6238e62
child 2854 c7d5f46cc306
equal deleted inserted replaced
2851:8d15c6238e62 2852:f7349ca820c9
   259       </xsl:for-each>
   259       </xsl:for-each>
   260     </xsl:comment>
   260     </xsl:comment>
   261     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
   261     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
   262       <head/>
   262       <head/>
   263       <body style="margin:0;overflow:hidden;">
   263       <body style="margin:0;overflow:hidden;">
   264         <xsl:apply-templates mode="inline_svg" select="svg:svg"/>
   264         <xsl:variable name="_result_svg">
       
   265           <xsl:apply-templates mode="inline_svg" select="svg:svg"/>
       
   266         </xsl:variable>
       
   267         <xsl:copy-of select="$_result_svg"/>
       
   268         <xsl:variable name="result_svg" select="exsl:node-set($_result_svg)"/>
   265         <script>
   269         <script>
   266           <xsl:call-template name="scripts"/>
   270           <xsl:apply-templates mode="scripts" select="svg:svg"/>
   267         </script>
   271         </script>
   268       </body>
   272       </body>
   269     </html>
   273     </html>
   270   </xsl:template>
   274   </xsl:template>
   271   <func:function name="func:parselabel">
   275   <func:function name="func:parselabel">
   317         </widget>
   321         </widget>
   318       </xsl:if>
   322       </xsl:if>
   319     </xsl:variable>
   323     </xsl:variable>
   320     <func:result select="exsl:node-set($ast)"/>
   324     <func:result select="exsl:node-set($ast)"/>
   321   </func:function>
   325   </func:function>
   322   <xsl:template name="scripts">
   326   <xsl:template mode="scripts" match="svg:svg">
   323     <xsl:text>//(function(){
   327     <xsl:text>//(function(){
   324 </xsl:text>
   328 </xsl:text>
   325     <xsl:text>
   329     <xsl:text>
   326 </xsl:text>
   330 </xsl:text>
   327     <xsl:text>id = idstr =&gt; document.getElementById(idstr);
   331     <xsl:text>id = idstr =&gt; document.getElementById(idstr);
   334 </xsl:text>
   338 </xsl:text>
   335     <xsl:text>var hmi_widgets = {
   339     <xsl:text>var hmi_widgets = {
   336 </xsl:text>
   340 </xsl:text>
   337     <xsl:for-each select="$hmi_elements">
   341     <xsl:for-each select="$hmi_elements">
   338       <xsl:variable name="widget" select="func:parselabel(@inkscape:label)/widget"/>
   342       <xsl:variable name="widget" select="func:parselabel(@inkscape:label)/widget"/>
   339       <xsl:text>    "</xsl:text>
   343       <xsl:text>  "</xsl:text>
   340       <xsl:value-of select="@id"/>
   344       <xsl:value-of select="@id"/>
   341       <xsl:text>": {
   345       <xsl:text>": {
   342 </xsl:text>
   346 </xsl:text>
   343       <xsl:text>        type: "</xsl:text>
   347       <xsl:text>    type: "</xsl:text>
   344       <xsl:value-of select="$widget/@type"/>
   348       <xsl:value-of select="$widget/@type"/>
   345       <xsl:text>",
   349       <xsl:text>",
   346 </xsl:text>
   350 </xsl:text>
   347       <xsl:text>        args: [
   351       <xsl:text>    args: [
   348 </xsl:text>
   352 </xsl:text>
   349       <xsl:for-each select="$widget/arg">
   353       <xsl:for-each select="$widget/arg">
   350         <xsl:text>            "</xsl:text>
   354         <xsl:text>        "</xsl:text>
   351         <xsl:value-of select="@value"/>
   355         <xsl:value-of select="@value"/>
   352         <xsl:text>"</xsl:text>
   356         <xsl:text>"</xsl:text>
   353         <xsl:if test="position()!=last()">
   357         <xsl:if test="position()!=last()">
   354           <xsl:text>,</xsl:text>
   358           <xsl:text>,</xsl:text>
   355         </xsl:if>
   359         </xsl:if>
   356         <xsl:text>
   360         <xsl:text>
   357 </xsl:text>
   361 </xsl:text>
   358       </xsl:for-each>
   362       </xsl:for-each>
   359       <xsl:text>        ],
   363       <xsl:text>    ],
   360 </xsl:text>
   364 </xsl:text>
   361       <xsl:text>        indexes: [
   365       <xsl:text>    indexes: [
   362 </xsl:text>
   366 </xsl:text>
   363       <xsl:for-each select="$widget/path">
   367       <xsl:for-each select="$widget/path">
   364         <xsl:variable name="hmipath" select="@value"/>
   368         <xsl:variable name="hmipath" select="@value"/>
   365         <xsl:variable name="hmitree_match" select="$indexed_hmitree/*[@hmipath = $hmipath]"/>
   369         <xsl:variable name="hmitree_match" select="$indexed_hmitree/*[@hmipath = $hmipath]"/>
   366         <xsl:choose>
   370         <xsl:choose>
   455       <xsl:variable name="page" select="."/>
   459       <xsl:variable name="page" select="."/>
   456       <xsl:variable name="p" select="$geometry[@Id = $page/@id]"/>
   460       <xsl:variable name="p" select="$geometry[@Id = $page/@id]"/>
   457       <xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/>
   461       <xsl:variable name="page_all_elements" select="func:all_related_elements($page)"/>
   458       <xsl:variable name="all_page_ids" select="$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id"/>
   462       <xsl:variable name="all_page_ids" select="$page_all_elements[@id = $hmi_elements/@id and @id != $page/@id]/@id"/>
   459       <xsl:variable name="required_detachables" select="func:sumarized_elements($page_all_elements)"/>
   463       <xsl:variable name="required_detachables" select="func:sumarized_elements($page_all_elements)"/>
   460       <xsl:text>    "</xsl:text>
   464       <xsl:text>  "</xsl:text>
   461       <xsl:value-of select="$desc/arg[1]/@value"/>
   465       <xsl:value-of select="$desc/arg[1]/@value"/>
   462       <xsl:text>": {
   466       <xsl:text>": {
   463 </xsl:text>
   467 </xsl:text>
   464       <xsl:text>        widget: hmi_widgets["</xsl:text>
   468       <xsl:text>    widget: hmi_widgets["</xsl:text>
   465       <xsl:value-of select="@id"/>
   469       <xsl:value-of select="@id"/>
   466       <xsl:text>"],
   470       <xsl:text>"],
   467 </xsl:text>
   471 </xsl:text>
   468       <xsl:text>        bbox: [</xsl:text>
   472       <xsl:text>    bbox: [</xsl:text>
   469       <xsl:value-of select="$p/@x"/>
   473       <xsl:value-of select="$p/@x"/>
   470       <xsl:text>, </xsl:text>
   474       <xsl:text>, </xsl:text>
   471       <xsl:value-of select="$p/@y"/>
   475       <xsl:value-of select="$p/@y"/>
   472       <xsl:text>, </xsl:text>
   476       <xsl:text>, </xsl:text>
   473       <xsl:value-of select="$p/@w"/>
   477       <xsl:value-of select="$p/@w"/>
   474       <xsl:text>, </xsl:text>
   478       <xsl:text>, </xsl:text>
   475       <xsl:value-of select="$p/@h"/>
   479       <xsl:value-of select="$p/@h"/>
   476       <xsl:text>],
   480       <xsl:text>],
   477 </xsl:text>
   481 </xsl:text>
   478       <xsl:text>        widgets: [
   482       <xsl:text>    widgets: [
   479 </xsl:text>
   483 </xsl:text>
   480       <xsl:for-each select="$all_page_ids">
   484       <xsl:for-each select="$all_page_ids">
   481         <xsl:text>            hmi_widgets["</xsl:text>
   485         <xsl:text>        hmi_widgets["</xsl:text>
   482         <xsl:value-of select="."/>
   486         <xsl:value-of select="."/>
   483         <xsl:text>"]</xsl:text>
   487         <xsl:text>"]</xsl:text>
   484         <xsl:if test="position()!=last()">
   488         <xsl:if test="position()!=last()">
   485           <xsl:text>,</xsl:text>
   489           <xsl:text>,</xsl:text>
   486         </xsl:if>
   490         </xsl:if>
   487         <xsl:text>
   491         <xsl:text>
   488 </xsl:text>
   492 </xsl:text>
   489       </xsl:for-each>
   493       </xsl:for-each>
   490       <xsl:text>        ],
   494       <xsl:text>    ],
   491 </xsl:text>
   495 </xsl:text>
   492       <xsl:text>        required_detachables: {
   496       <xsl:text>    required_detachables: {
   493 </xsl:text>
   497 </xsl:text>
   494       <xsl:for-each select="$required_detachables">
   498       <xsl:for-each select="$required_detachables">
   495         <xsl:text>            "</xsl:text>
   499         <xsl:text>        "</xsl:text>
   496         <xsl:value-of select="@id"/>
   500         <xsl:value-of select="@id"/>
   497         <xsl:text>": detachable_elements["</xsl:text>
   501         <xsl:text>": detachable_elements["</xsl:text>
   498         <xsl:value-of select="@id"/>
   502         <xsl:value-of select="@id"/>
   499         <xsl:text>"]</xsl:text>
   503         <xsl:text>"]</xsl:text>
   500         <xsl:if test="position()!=last()">
   504         <xsl:if test="position()!=last()">
   501           <xsl:text>,</xsl:text>
   505           <xsl:text>,</xsl:text>
   502         </xsl:if>
   506         </xsl:if>
   503         <xsl:text>
   507         <xsl:text>
   504 </xsl:text>
   508 </xsl:text>
   505       </xsl:for-each>
   509       </xsl:for-each>
   506       <xsl:text>        }
   510       <xsl:text>    }
   507 </xsl:text>
   511 </xsl:text>
   508       <xsl:text>    }</xsl:text>
   512       <xsl:text>  }</xsl:text>
   509       <xsl:if test="position()!=last()">
   513       <xsl:if test="position()!=last()">
   510         <xsl:text>,</xsl:text>
   514         <xsl:text>,</xsl:text>
   511       </xsl:if>
   515       </xsl:if>
   512       <xsl:text>
   516       <xsl:text>
   513 </xsl:text>
   517 </xsl:text>
  1171               <xsl:text> element</xsl:text>
  1175               <xsl:text> element</xsl:text>
  1172             </xsl:message>
  1176             </xsl:message>
  1173           </xsl:if>
  1177           </xsl:if>
  1174         </xsl:when>
  1178         </xsl:when>
  1175         <xsl:otherwise>
  1179         <xsl:otherwise>
       
  1180           <xsl:text>    </xsl:text>
  1176           <xsl:value-of select="$name"/>
  1181           <xsl:value-of select="$name"/>
  1177           <xsl:text>_elt: id("</xsl:text>
  1182           <xsl:text>_elt: id("</xsl:text>
  1178           <xsl:value-of select="$elt_id"/>
  1183           <xsl:value-of select="$elt_id"/>
  1179           <xsl:text>"),
  1184           <xsl:text>"),
  1180 </xsl:text>
  1185 </xsl:text>
  1182       </xsl:choose>
  1187       </xsl:choose>
  1183     </xsl:for-each>
  1188     </xsl:for-each>
  1184   </xsl:template>
  1189   </xsl:template>
  1185   <xsl:template mode="widget_defs" match="widget[@type='Display']">
  1190   <xsl:template mode="widget_defs" match="widget[@type='Display']">
  1186     <xsl:param name="hmi_element"/>
  1191     <xsl:param name="hmi_element"/>
  1187     <xsl:text>frequency: 5,
  1192     <xsl:text>    frequency: 5,
  1188 </xsl:text>
  1193 </xsl:text>
  1189     <xsl:text>dispatch: function(value) {
  1194     <xsl:text>    dispatch: function(value) {
  1190 </xsl:text>
  1195 </xsl:text>
  1191     <xsl:choose>
  1196     <xsl:choose>
  1192       <xsl:when test="$hmi_element[self::svg:text]">
  1197       <xsl:when test="$hmi_element[self::svg:text]">
  1193         <xsl:text>  this.element.textContent = String(value);
  1198         <xsl:text>      this.element.textContent = String(value);
  1194 </xsl:text>
  1199 </xsl:text>
  1195       </xsl:when>
  1200       </xsl:when>
  1196       <xsl:otherwise>
  1201       <xsl:otherwise>
  1197         <xsl:message terminate="no">
  1202         <xsl:message terminate="no">
  1198           <xsl:text>Display widget as a group not implemented</xsl:text>
  1203           <xsl:text>Display widget as a group not implemented</xsl:text>
  1199         </xsl:message>
  1204         </xsl:message>
  1200       </xsl:otherwise>
  1205       </xsl:otherwise>
  1201     </xsl:choose>
  1206     </xsl:choose>
  1202     <xsl:text>},
  1207     <xsl:text>    },
  1203 </xsl:text>
  1208 </xsl:text>
  1204   </xsl:template>
  1209   </xsl:template>
  1205   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
  1210   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
  1206     <xsl:param name="hmi_element"/>
  1211     <xsl:param name="hmi_element"/>
  1207     <xsl:text>frequency: 10,
  1212     <xsl:text>    frequency: 10,
  1208 </xsl:text>
  1213 </xsl:text>
  1209     <xsl:call-template name="defs_by_labels">
  1214     <xsl:call-template name="defs_by_labels">
  1210       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  1215       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  1211       <xsl:with-param name="labels">
  1216       <xsl:with-param name="labels">
  1212         <xsl:text>value min max needle range</xsl:text>
  1217         <xsl:text>value min max needle range</xsl:text>
  1213       </xsl:with-param>
  1218       </xsl:with-param>
  1214     </xsl:call-template>
  1219     </xsl:call-template>
  1215     <xsl:text>dispatch: function(value) {
  1220     <xsl:text>    dispatch: function(value) {
  1216 </xsl:text>
  1221 </xsl:text>
  1217     <xsl:text>    this.value_elt.textContent = String(value);
  1222     <xsl:text>        this.value_elt.textContent = String(value);
  1218 </xsl:text>
  1223 </xsl:text>
  1219     <xsl:text>    let [min,max,totallength] = this.range;
  1224     <xsl:text>        let [min,max,totallength] = this.range;
  1220 </xsl:text>
  1225 </xsl:text>
  1221     <xsl:text>    let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
  1226     <xsl:text>        let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
  1222 </xsl:text>
  1227 </xsl:text>
  1223     <xsl:text>    let tip = this.range_elt.getPointAtLength(length);
  1228     <xsl:text>        let tip = this.range_elt.getPointAtLength(length);
  1224 </xsl:text>
  1229 </xsl:text>
  1225     <xsl:text>    this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
  1230     <xsl:text>        this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
  1226 </xsl:text>
  1231 </xsl:text>
  1227     <xsl:text>},
  1232     <xsl:text>    },
  1228 </xsl:text>
  1233 </xsl:text>
  1229     <xsl:text>origin: undefined,
  1234     <xsl:text>    origin: undefined,
  1230 </xsl:text>
  1235 </xsl:text>
  1231     <xsl:text>range: undefined,
  1236     <xsl:text>    range: undefined,
  1232 </xsl:text>
  1237 </xsl:text>
  1233     <xsl:text>init: function() {
  1238     <xsl:text>    init: function() {
  1234 </xsl:text>
  1239 </xsl:text>
  1235     <xsl:text>    this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
  1240     <xsl:text>        this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
  1236 </xsl:text>
  1241 </xsl:text>
  1237     <xsl:text>    this.origin = this.needle_elt.getPointAtLength(0);
  1242     <xsl:text>        this.origin = this.needle_elt.getPointAtLength(0);
  1238 </xsl:text>
  1243 </xsl:text>
  1239     <xsl:text>},
  1244     <xsl:text>    },
  1240 </xsl:text>
  1245 </xsl:text>
  1241   </xsl:template>
  1246   </xsl:template>
  1242   <func:function name="func:escape_quotes">
  1247   <func:function name="func:escape_quotes">
  1243     <xsl:param name="txt"/>
  1248     <xsl:param name="txt"/>
  1244     <xsl:variable name="frst" select="substring-before($txt,'&quot;')"/>
  1249     <xsl:variable name="frst" select="substring-before($txt,'&quot;')"/>