svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2946 76ebf973c47e
parent 2944 2a20038fbea9
child 2949 e50908ddec60
equal deleted inserted replaced
2945:69f395c01c09 2946:76ebf973c47e
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet xmlns:func="http://exslt.org/functions" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:epilogue="epilogue" xmlns:svg="http://www.w3.org/2000/svg" xmlns:str="http://exslt.org/strings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:preamble="preamble" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:debug="debug" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue">
     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:debug="debug" xmlns:preamble="preamble" xmlns:declarations="declarations" xmlns:definitions="definitions" xmlns:epilogue="epilogue" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions">
     3   <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
     3   <xsl:output cdata-section-elements="xhtml:script" method="xml"/>
     4   <xsl:variable name="svg" select="/svg:svg"/>
     4   <xsl:variable name="svg" select="/svg:svg"/>
     5   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     5   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     6   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
     6   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
     7   <xsl:variable name="_categories">
     7   <xsl:variable name="_categories">
     8     <noindex>
     8     <noindex>
   381       </xsl:otherwise>
   381       </xsl:otherwise>
   382     </xsl:choose>
   382     </xsl:choose>
   383   </func:function>
   383   </func:function>
   384   <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages | $keypads)"/>
   384   <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages | $keypads)"/>
   385   <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
   385   <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
   386   <epilogue:detachable-elements/>
   386   <declarations:detachable-elements/>
   387   <xsl:template match="epilogue:detachable-elements">
   387   <xsl:template match="declarations:detachable-elements">
   388     <xsl:text>
   388     <xsl:text>
   389 </xsl:text>
   389 </xsl:text>
   390     <xsl:text>var detachable_elements = {
   390     <xsl:text>var detachable_elements = {
   391 </xsl:text>
   391 </xsl:text>
   392     <xsl:for-each select="$detachable_elements">
   392     <xsl:for-each select="$detachable_elements">
   525       <xsl:text>,</xsl:text>
   525       <xsl:text>,</xsl:text>
   526     </xsl:if>
   526     </xsl:if>
   527     <xsl:text>
   527     <xsl:text>
   528 </xsl:text>
   528 </xsl:text>
   529   </xsl:template>
   529   </xsl:template>
   530   <epilogue:page-desc/>
   530   <declarations:page-desc/>
   531   <xsl:template match="epilogue:page-desc">
   531   <xsl:template match="declarations:page-desc">
   532     <xsl:text>
   532     <xsl:text>
   533 </xsl:text>
   533 </xsl:text>
   534     <xsl:text>var page_desc = {
   534     <xsl:text>var page_desc = {
   535 </xsl:text>
   535 </xsl:text>
   536     <xsl:apply-templates mode="page_desc" select="$hmi_pages"/>
   536     <xsl:apply-templates mode="page_desc" select="$hmi_pages"/>
   894     <xsl:text>'].on_click(evt)");
   894     <xsl:text>'].on_click(evt)");
   895 </xsl:text>
   895 </xsl:text>
   896     <xsl:text>    },
   896     <xsl:text>    },
   897 </xsl:text>
   897 </xsl:text>
   898   </xsl:template>
   898   </xsl:template>
       
   899   <xsl:template mode="widget_defs" match="widget[@type='Button']">
       
   900     <xsl:param name="hmi_element"/>
       
   901     <xsl:text>frequency: 5,
       
   902 </xsl:text>
       
   903     <xsl:text>init: function() {
       
   904 </xsl:text>
       
   905     <xsl:text>    this.element.addEventListener(
       
   906 </xsl:text>
       
   907     <xsl:text>      "mousedown",
       
   908 </xsl:text>
       
   909     <xsl:text>      evt =&gt; {
       
   910 </xsl:text>
       
   911     <xsl:text>          change_hmi_value(this.indexes[0], "=1");
       
   912 </xsl:text>
       
   913     <xsl:text>      });
       
   914 </xsl:text>
       
   915     <xsl:text>    this.element.addEventListener(
       
   916 </xsl:text>
       
   917     <xsl:text>      "mouseup",
       
   918 </xsl:text>
       
   919     <xsl:text>      evt =&gt; {
       
   920 </xsl:text>
       
   921     <xsl:text>          change_hmi_value(this.indexes[0], "=0");
       
   922 </xsl:text>
       
   923     <xsl:text>      });
       
   924 </xsl:text>
       
   925     <xsl:text>},
       
   926 </xsl:text>
       
   927   </xsl:template>
       
   928   <xsl:template mode="widget_defs" match="widget[@type='CircularBar']">
       
   929     <xsl:param name="hmi_element"/>
       
   930     <xsl:text>frequency: 10,
       
   931 </xsl:text>
       
   932     <xsl:call-template name="defs_by_labels">
       
   933       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
   934       <xsl:with-param name="labels">
       
   935         <xsl:text>path</xsl:text>
       
   936       </xsl:with-param>
       
   937     </xsl:call-template>
       
   938     <xsl:call-template name="defs_by_labels">
       
   939       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
   940       <xsl:with-param name="labels">
       
   941         <xsl:text>value min max</xsl:text>
       
   942       </xsl:with-param>
       
   943       <xsl:with-param name="mandatory" select="'no'"/>
       
   944     </xsl:call-template>
       
   945     <xsl:text>dispatch: function(value) {
       
   946 </xsl:text>
       
   947     <xsl:text>    if(this.value_elt)
       
   948 </xsl:text>
       
   949     <xsl:text>        this.value_elt.textContent = String(value);
       
   950 </xsl:text>
       
   951     <xsl:text>    let [min,max,start,end] = this.range;
       
   952 </xsl:text>
       
   953     <xsl:text>    let [cx,cy] = this.center;
       
   954 </xsl:text>
       
   955     <xsl:text>    let [rx,ry] = this.proportions;
       
   956 </xsl:text>
       
   957     <xsl:text>    let tip = start + (end-start)*Number(value)/(max-min);
       
   958 </xsl:text>
       
   959     <xsl:text>    let size = 0;
       
   960 </xsl:text>
       
   961     <xsl:text>    if (tip-start &gt; Math.PI) {
       
   962 </xsl:text>
       
   963     <xsl:text>        size = 1;
       
   964 </xsl:text>
       
   965     <xsl:text>    } else {
       
   966 </xsl:text>
       
   967     <xsl:text>        size = 0;
       
   968 </xsl:text>
       
   969     <xsl:text>    }
       
   970 </xsl:text>
       
   971     <xsl:text>    this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+" A "+rx+","+ry+" 0 "+size+" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip)));
       
   972 </xsl:text>
       
   973     <xsl:text>},
       
   974 </xsl:text>
       
   975     <xsl:text>range: undefined,
       
   976 </xsl:text>
       
   977     <xsl:text>init: function() {
       
   978 </xsl:text>
       
   979     <xsl:text>    let start = Number(this.path_elt.getAttribute('sodipodi:start'));
       
   980 </xsl:text>
       
   981     <xsl:text>    let end = Number(this.path_elt.getAttribute('sodipodi:end'));
       
   982 </xsl:text>
       
   983     <xsl:text>    let cx = Number(this.path_elt.getAttribute('sodipodi:cx'));
       
   984 </xsl:text>
       
   985     <xsl:text>    let cy = Number(this.path_elt.getAttribute('sodipodi:cy'));
       
   986 </xsl:text>
       
   987     <xsl:text>    let rx = Number(this.path_elt.getAttribute('sodipodi:rx'));
       
   988 </xsl:text>
       
   989     <xsl:text>    let ry = Number(this.path_elt.getAttribute('sodipodi:ry'));
       
   990 </xsl:text>
       
   991     <xsl:text>    if (ry == 0) {
       
   992 </xsl:text>
       
   993     <xsl:text>        ry = rx;
       
   994 </xsl:text>
       
   995     <xsl:text>    }
       
   996 </xsl:text>
       
   997     <xsl:text>    if (start &gt; end) {
       
   998 </xsl:text>
       
   999     <xsl:text>        end = end + 2*Math.PI;
       
  1000 </xsl:text>
       
  1001     <xsl:text>    }
       
  1002 </xsl:text>
       
  1003     <xsl:text>    let min = this.min_elt ?
       
  1004 </xsl:text>
       
  1005     <xsl:text>              Number(this.min_elt.textContent) :
       
  1006 </xsl:text>
       
  1007     <xsl:text>              this.args.length &gt;= 1 ? this.args[0] : 0;
       
  1008 </xsl:text>
       
  1009     <xsl:text>    let max = this.max_elt ?
       
  1010 </xsl:text>
       
  1011     <xsl:text>              Number(this.max_elt.textContent) :
       
  1012 </xsl:text>
       
  1013     <xsl:text>              this.args.length &gt;= 2 ? this.args[1] : 100;
       
  1014 </xsl:text>
       
  1015     <xsl:text>    this.range = [min, max, start, end];
       
  1016 </xsl:text>
       
  1017     <xsl:text>    this.center = [cx, cy];
       
  1018 </xsl:text>
       
  1019     <xsl:text>    this.proportions = [rx, ry];
       
  1020 </xsl:text>
       
  1021     <xsl:text>},
       
  1022 </xsl:text>
       
  1023   </xsl:template>
   899   <xsl:template mode="widget_defs" match="widget[@type='Display']">
  1024   <xsl:template mode="widget_defs" match="widget[@type='Display']">
   900     <xsl:param name="hmi_element"/>
  1025     <xsl:param name="hmi_element"/>
   901     <xsl:text>    frequency: 5,
  1026     <xsl:text>    frequency: 5,
   902 </xsl:text>
  1027 </xsl:text>
   903     <xsl:text>    dispatch: function(value) {
  1028     <xsl:text>    dispatch: function(value) {
  1542     <xsl:text>    unsub: foreach_unsubscribe,
  1667     <xsl:text>    unsub: foreach_unsubscribe,
  1543 </xsl:text>
  1668 </xsl:text>
  1544     <xsl:text>    apply_cache: foreach_apply_cache,
  1669     <xsl:text>    apply_cache: foreach_apply_cache,
  1545 </xsl:text>
  1670 </xsl:text>
  1546   </xsl:template>
  1671   </xsl:template>
  1547   <epilogue:foreach/>
  1672   <definitions:foreach/>
  1548   <xsl:template match="epilogue:foreach">
  1673   <xsl:template match="definitions:foreach">
  1549     <xsl:text>function foreach_unsubscribe(){
  1674     <xsl:text>function foreach_unsubscribe(){
  1550 </xsl:text>
  1675 </xsl:text>
  1551     <xsl:text>    for(let item of this.items){
  1676     <xsl:text>    for(let item of this.items){
  1552 </xsl:text>
  1677 </xsl:text>
  1553     <xsl:text>        for(let widget of item) {
  1678     <xsl:text>        for(let widget of item) {
  1954           <xsl:text>")</xsl:text>
  2079           <xsl:text>")</xsl:text>
  1955         </xsl:message>
  2080         </xsl:message>
  1956       </xsl:if>
  2081       </xsl:if>
  1957     </xsl:if>
  2082     </xsl:if>
  1958   </xsl:template>
  2083   </xsl:template>
  1959   <epilogue:jump/>
  2084   <declarations:jump/>
  1960   <xsl:template match="epilogue:jump">
  2085   <xsl:template match="declarations:jump">
  1961     <xsl:text>var jumps_need_update = false;
  2086     <xsl:text>var jumps_need_update = false;
  1962 </xsl:text>
  2087 </xsl:text>
  1963     <xsl:text>var jump_history = [[default_page, undefined]];
  2088     <xsl:text>var jump_history = [[default_page, undefined]];
  1964 </xsl:text>
  2089 </xsl:text>
  1965     <xsl:text>
  2090     <xsl:text>
  1973     <xsl:text>};
  2098     <xsl:text>};
  1974 </xsl:text>
  2099 </xsl:text>
  1975     <xsl:text>
  2100     <xsl:text>
  1976 </xsl:text>
  2101 </xsl:text>
  1977   </xsl:template>
  2102   </xsl:template>
  1978   <epilogue:keypad/>
  2103   <declarations:keypad/>
  1979   <xsl:template match="epilogue:keypad">
  2104   <xsl:template match="declarations:keypad">
  1980     <xsl:text>
  2105     <xsl:text>
  1981 </xsl:text>
  2106 </xsl:text>
  1982     <xsl:text>var keypads = {
  2107     <xsl:text>var keypads = {
  1983 </xsl:text>
  2108 </xsl:text>
  1984     <xsl:for-each select="$keypads_descs">
  2109     <xsl:for-each select="$keypads_descs">
  2334         <xsl:text> :
  2459         <xsl:text> :
  2335 </xsl:text>
  2460 </xsl:text>
  2336         <xsl:apply-templates select="."/>
  2461         <xsl:apply-templates select="."/>
  2337       </xsl:comment>
  2462       </xsl:comment>
  2338     </xsl:for-each>
  2463     </xsl:for-each>
  2339     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
  2464     <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  2340       <head/>
  2465       <head/>
  2341       <body style="margin:0;overflow:hidden;">
  2466       <body style="margin:0;overflow:hidden;">
  2342         <xsl:copy-of select="$result_svg"/>
  2467         <xsl:copy-of select="$result_svg"/>
  2343         <script>
  2468         <script>
       
  2469           <xsl:text>
       
  2470 //
       
  2471 //
       
  2472 // Early independent declarations 
       
  2473 //
       
  2474 //
       
  2475 </xsl:text>
  2344           <xsl:apply-templates select="document('')/*/preamble:*"/>
  2476           <xsl:apply-templates select="document('')/*/preamble:*"/>
       
  2477           <xsl:text>
       
  2478 //
       
  2479 //
       
  2480 // Declarations depending on preamble 
       
  2481 //
       
  2482 //
       
  2483 </xsl:text>
       
  2484           <xsl:apply-templates select="document('')/*/declarations:*"/>
       
  2485           <xsl:text>
       
  2486 //
       
  2487 //
       
  2488 // Order independent declaration and code 
       
  2489 //
       
  2490 //
       
  2491 </xsl:text>
       
  2492           <xsl:apply-templates select="document('')/*/definitions:*"/>
       
  2493           <xsl:text>
       
  2494 //
       
  2495 //
       
  2496 // Statements that needs to be at the end 
       
  2497 //
       
  2498 //
       
  2499 </xsl:text>
  2345           <xsl:apply-templates select="document('')/*/epilogue:*"/>
  2500           <xsl:apply-templates select="document('')/*/epilogue:*"/>
  2346           <xsl:text>// svghmi.js
  2501           <xsl:text>// svghmi.js
  2347 </xsl:text>
  2502 </xsl:text>
  2348           <xsl:text>
  2503           <xsl:text>
  2349 </xsl:text>
  2504 </xsl:text>