svghmi/gen_index_xhtml.xslt
changeset 3525 c2f7e9bda366
parent 3521 4345b3c9b9de
child 3554 611fd1f44ce9
equal deleted inserted replaced
3524:27d298c6f961 3525:c2f7e9bda366
  1474 </xsl:text>
  1474 </xsl:text>
  1475     <xsl:text>
  1475     <xsl:text>
  1476 </xsl:text>
  1476 </xsl:text>
  1477     <xsl:text>function set_activation_state(eltsub, state){
  1477     <xsl:text>function set_activation_state(eltsub, state){
  1478 </xsl:text>
  1478 </xsl:text>
  1479     <xsl:text>    if(eltsub.active_elt_placeholder == undefined){
  1479     <xsl:text>    if(eltsub.active_elt != undefined){
  1480 </xsl:text>
  1480 </xsl:text>
  1481     <xsl:text>        eltsub.active_elt_placeholder = document.createComment("");
  1481     <xsl:text>        if(eltsub.active_elt_placeholder == undefined){
  1482 </xsl:text>
  1482 </xsl:text>
  1483     <xsl:text>        eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt);
  1483     <xsl:text>            eltsub.active_elt_placeholder = document.createComment("");
  1484 </xsl:text>
  1484 </xsl:text>
  1485     <xsl:text>        eltsub.inactive_elt_placeholder = document.createComment("");
  1485     <xsl:text>            eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt);
  1486 </xsl:text>
  1486 </xsl:text>
  1487     <xsl:text>        eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt);
  1487     <xsl:text>        }
  1488 </xsl:text>
  1488 </xsl:text>
  1489     <xsl:text>    }
  1489     <xsl:text>        (state?_show:_hide)(eltsub.active_elt, eltsub.active_elt_placeholder);
  1490 </xsl:text>
  1490 </xsl:text>
  1491     <xsl:text>    (state?_show:_hide)(eltsub.active_elt, eltsub.active_elt_placeholder);
  1491     <xsl:text>    }
  1492 </xsl:text>
  1492 </xsl:text>
  1493     <xsl:text>    ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder);
  1493     <xsl:text>    if(eltsub.inactive_elt != undefined){
       
  1494 </xsl:text>
       
  1495     <xsl:text>        if(eltsub.inactive_elt_placeholder == undefined){
       
  1496 </xsl:text>
       
  1497     <xsl:text>            eltsub.inactive_elt_placeholder = document.createComment("");
       
  1498 </xsl:text>
       
  1499     <xsl:text>            eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt);
       
  1500 </xsl:text>
       
  1501     <xsl:text>        }
       
  1502 </xsl:text>
       
  1503     <xsl:text>        ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder);
       
  1504 </xsl:text>
       
  1505     <xsl:text>    }
  1494 </xsl:text>
  1506 </xsl:text>
  1495     <xsl:text>}
  1507     <xsl:text>}
  1496 </xsl:text>
  1508 </xsl:text>
  1497     <xsl:text>
  1509     <xsl:text>
  1498 </xsl:text>
  1510 </xsl:text>
  2073     <xsl:param name="labels" select="''"/>
  2085     <xsl:param name="labels" select="''"/>
  2074     <xsl:param name="mandatory" select="'yes'"/>
  2086     <xsl:param name="mandatory" select="'yes'"/>
  2075     <xsl:param name="subelements" select="/.."/>
  2087     <xsl:param name="subelements" select="/.."/>
  2076     <xsl:param name="hmi_element"/>
  2088     <xsl:param name="hmi_element"/>
  2077     <xsl:variable name="widget_type" select="@type"/>
  2089     <xsl:variable name="widget_type" select="@type"/>
       
  2090     <xsl:variable name="widget_id" select="@id"/>
  2078     <xsl:for-each select="str:split($labels)">
  2091     <xsl:for-each select="str:split($labels)">
  2079       <xsl:variable name="absolute" select="starts-with(., '/')"/>
  2092       <xsl:variable name="absolute" select="starts-with(., '/')"/>
  2080       <xsl:variable name="name" select="substring(.,number($absolute)+1)"/>
  2093       <xsl:variable name="name" select="substring(.,number($absolute)+1)"/>
  2081       <xsl:variable name="widget" select="$result_widgets[@id = $hmi_element/@id]"/>
  2094       <xsl:variable name="widget" select="$result_widgets[@id = $hmi_element/@id]"/>
  2082       <xsl:variable name="elt" select="($widget//*[not($absolute) and @inkscape:label=$name] | $widget/*[$absolute and @inkscape:label=$name])[1]"/>
  2095       <xsl:variable name="elt" select="($widget//*[not($absolute) and @inkscape:label=$name] | $widget/*[$absolute and @inkscape:label=$name])[1]"/>
  2083       <xsl:choose>
  2096       <xsl:choose>
  2084         <xsl:when test="not($elt/@id)">
  2097         <xsl:when test="not($elt/@id)">
  2085           <xsl:if test="$mandatory='yes'">
  2098           <xsl:if test="$mandatory!='no'">
  2086             <xsl:message terminate="yes">
  2099             <xsl:variable name="errmsg">
  2087               <xsl:value-of select="$widget_type"/>
  2100               <xsl:value-of select="$widget_type"/>
  2088               <xsl:text> widget must have a </xsl:text>
  2101               <xsl:text> widget (id=</xsl:text>
       
  2102               <xsl:value-of select="$widget_id"/>
       
  2103               <xsl:text>) must have a </xsl:text>
  2089               <xsl:value-of select="$name"/>
  2104               <xsl:value-of select="$name"/>
  2090               <xsl:text> element</xsl:text>
  2105               <xsl:text> element</xsl:text>
  2091             </xsl:message>
  2106             </xsl:variable>
       
  2107             <xsl:choose>
       
  2108               <xsl:when test="$mandatory='yes'">
       
  2109                 <xsl:message terminate="yes">
       
  2110                   <xsl:value-of select="$errmsg"/>
       
  2111                 </xsl:message>
       
  2112               </xsl:when>
       
  2113               <xsl:otherwise>
       
  2114                 <xsl:message terminate="no">
       
  2115                   <xsl:value-of select="$errmsg"/>
       
  2116                 </xsl:message>
       
  2117               </xsl:otherwise>
       
  2118             </xsl:choose>
  2092           </xsl:if>
  2119           </xsl:if>
  2093         </xsl:when>
  2120         </xsl:when>
  2094         <xsl:otherwise>
  2121         <xsl:otherwise>
  2095           <xsl:text>    </xsl:text>
  2122           <xsl:text>    </xsl:text>
  2096           <xsl:value-of select="$name"/>
  2123           <xsl:value-of select="$name"/>
  2106             <xsl:for-each select="str:split($subelements)">
  2133             <xsl:for-each select="str:split($subelements)">
  2107               <xsl:variable name="subname" select="."/>
  2134               <xsl:variable name="subname" select="."/>
  2108               <xsl:variable name="subelt" select="$elt/*[@inkscape:label=$subname][1]"/>
  2135               <xsl:variable name="subelt" select="$elt/*[@inkscape:label=$subname][1]"/>
  2109               <xsl:choose>
  2136               <xsl:choose>
  2110                 <xsl:when test="not($subelt/@id)">
  2137                 <xsl:when test="not($subelt/@id)">
  2111                   <xsl:if test="$mandatory='yes'">
  2138                   <xsl:if test="$mandatory!='no'">
  2112                     <xsl:message terminate="yes">
  2139                     <xsl:variable name="errmsg">
  2113                       <xsl:value-of select="$widget_type"/>
  2140                       <xsl:value-of select="$widget_type"/>
  2114                       <xsl:text> widget must have a </xsl:text>
  2141                       <xsl:text> widget (id=</xsl:text>
       
  2142                       <xsl:value-of select="$widget_id"/>
       
  2143                       <xsl:text>) must have a </xsl:text>
  2115                       <xsl:value-of select="$name"/>
  2144                       <xsl:value-of select="$name"/>
  2116                       <xsl:text>/</xsl:text>
  2145                       <xsl:text>/</xsl:text>
  2117                       <xsl:value-of select="$subname"/>
  2146                       <xsl:value-of select="$subname"/>
  2118                       <xsl:text> element</xsl:text>
  2147                       <xsl:text> element</xsl:text>
  2119                     </xsl:message>
  2148                     </xsl:variable>
       
  2149                     <xsl:choose>
       
  2150                       <xsl:when test="$mandatory='yes'">
       
  2151                         <xsl:message terminate="yes">
       
  2152                           <xsl:value-of select="$errmsg"/>
       
  2153                         </xsl:message>
       
  2154                       </xsl:when>
       
  2155                       <xsl:otherwise>
       
  2156                         <xsl:message terminate="no">
       
  2157                           <xsl:value-of select="$errmsg"/>
       
  2158                         </xsl:message>
       
  2159                       </xsl:otherwise>
       
  2160                     </xsl:choose>
  2120                   </xsl:if>
  2161                   </xsl:if>
  2121                   <xsl:text>        /* missing </xsl:text>
  2162                   <xsl:text>        /* missing </xsl:text>
  2122                   <xsl:value-of select="$name"/>
  2163                   <xsl:value-of select="$name"/>
  2123                   <xsl:text>/</xsl:text>
  2164                   <xsl:text>/</xsl:text>
  2124                   <xsl:value-of select="$subname"/>
  2165                   <xsl:value-of select="$subname"/>
  2681     <xsl:call-template name="defs_by_labels">
  2722     <xsl:call-template name="defs_by_labels">
  2682       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2723       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2683       <xsl:with-param name="labels">
  2724       <xsl:with-param name="labels">
  2684         <xsl:text>/active /inactive</xsl:text>
  2725         <xsl:text>/active /inactive</xsl:text>
  2685       </xsl:with-param>
  2726       </xsl:with-param>
       
  2727       <xsl:with-param name="mandatory" select="'warn'"/>
  2686     </xsl:call-template>
  2728     </xsl:call-template>
  2687     <xsl:text>    }
  2729     <xsl:text>    }
  2688 </xsl:text>
  2730 </xsl:text>
  2689   </xsl:template>
  2731   </xsl:template>
  2690   <xsl:template match="widget[@type='PushButton']" mode="widget_class">
  2732   <xsl:template match="widget[@type='PushButton']" mode="widget_class">
  2708     <xsl:call-template name="defs_by_labels">
  2750     <xsl:call-template name="defs_by_labels">
  2709       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2751       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2710       <xsl:with-param name="labels">
  2752       <xsl:with-param name="labels">
  2711         <xsl:text>/active /inactive</xsl:text>
  2753         <xsl:text>/active /inactive</xsl:text>
  2712       </xsl:with-param>
  2754       </xsl:with-param>
       
  2755       <xsl:with-param name="mandatory" select="'warn'"/>
  2713     </xsl:call-template>
  2756     </xsl:call-template>
  2714     <xsl:text>    }
  2757     <xsl:text>    }
  2715 </xsl:text>
  2758 </xsl:text>
  2716   </xsl:template>
  2759   </xsl:template>
  2717   <xsl:template match="widget[@type='CircularBar']" mode="widget_desc">
  2760   <xsl:template match="widget[@type='CircularBar']" mode="widget_desc">
  3480 </xsl:text>
  3523 </xsl:text>
  3481       <xsl:text>format string as first argument.
  3524       <xsl:text>format string as first argument.
  3482 </xsl:text>
  3525 </xsl:text>
  3483     </longdesc>
  3526     </longdesc>
  3484     <shortdesc>
  3527     <shortdesc>
  3485       <xsl:text>Printf-like formated text display </xsl:text>
  3528       <xsl:text>Printf-like formated text display</xsl:text>
  3486     </shortdesc>
  3529     </shortdesc>
  3487     <arg name="format" count="optional" accepts="string">
  3530     <arg name="format" count="optional" accepts="string">
  3488       <xsl:text>printf-like format string when not given as svg:text</xsl:text>
  3531       <xsl:text>printf-like format string when not given as svg:text</xsl:text>
  3489     </arg>
  3532     </arg>
  3490     <path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL">
  3533     <path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL">
  3498 </xsl:text>
  3541 </xsl:text>
  3499     <xsl:text>    frequency = 5;
  3542     <xsl:text>    frequency = 5;
  3500 </xsl:text>
  3543 </xsl:text>
  3501     <xsl:text>    dispatch(value, oldval, index) {
  3544     <xsl:text>    dispatch(value, oldval, index) {
  3502 </xsl:text>
  3545 </xsl:text>
  3503     <xsl:text>        this.fields[index] = value;    
  3546     <xsl:text>        this.fields[index] = value;
       
  3547 </xsl:text>
       
  3548     <xsl:text>        if(!this.ready){
       
  3549 </xsl:text>
       
  3550     <xsl:text>            this.readyfields[index] = true;
       
  3551 </xsl:text>
       
  3552     <xsl:text>            this.ready = this.readyfields.every(x=&gt;x);
       
  3553 </xsl:text>
       
  3554     <xsl:text>        }
  3504 </xsl:text>
  3555 </xsl:text>
  3505     <xsl:text>        this.request_animate();
  3556     <xsl:text>        this.request_animate();
  3506 </xsl:text>
  3557 </xsl:text>
  3507     <xsl:text>    }
  3558     <xsl:text>    }
  3508 </xsl:text>
  3559 </xsl:text>
  3546     </xsl:variable>
  3597     </xsl:variable>
  3547     <xsl:text>    fields: [</xsl:text>
  3598     <xsl:text>    fields: [</xsl:text>
  3548     <xsl:value-of select="$field_initializer"/>
  3599     <xsl:value-of select="$field_initializer"/>
  3549     <xsl:text>],
  3600     <xsl:text>],
  3550 </xsl:text>
  3601 </xsl:text>
       
  3602     <xsl:variable name="readyfield_initializer">
       
  3603       <xsl:for-each select="path">
       
  3604         <xsl:text>false</xsl:text>
       
  3605         <xsl:if test="position()!=last()">
       
  3606           <xsl:text>,</xsl:text>
       
  3607         </xsl:if>
       
  3608       </xsl:for-each>
       
  3609     </xsl:variable>
       
  3610     <xsl:text>    readyfields: [</xsl:text>
       
  3611     <xsl:value-of select="$readyfield_initializer"/>
       
  3612     <xsl:text>],
       
  3613 </xsl:text>
       
  3614     <xsl:text>    ready: false,
       
  3615 </xsl:text>
  3551     <xsl:text>    animate: function(){
  3616     <xsl:text>    animate: function(){
  3552 </xsl:text>
  3617 </xsl:text>
  3553     <xsl:choose>
  3618     <xsl:choose>
  3554       <xsl:when test="$has_format">
  3619       <xsl:when test="$has_format">
  3555         <xsl:text>      if(this.format_elt.getAttribute("lang")) {
  3620         <xsl:text>      if(this.format_elt.getAttribute("lang")) {
  3560 </xsl:text>
  3625 </xsl:text>
  3561         <xsl:text>      }
  3626         <xsl:text>      }
  3562 </xsl:text>
  3627 </xsl:text>
  3563         <xsl:text>      let str = vsprintf(this.format,this.fields);
  3628         <xsl:text>      let str = vsprintf(this.format,this.fields);
  3564 </xsl:text>
  3629 </xsl:text>
  3565         <xsl:text>      multiline_to_svg_text(this.format_elt, str);
  3630         <xsl:text>      multiline_to_svg_text(this.format_elt, str, !this.ready);
  3566 </xsl:text>
  3631 </xsl:text>
  3567       </xsl:when>
  3632       </xsl:when>
  3568       <xsl:otherwise>
  3633       <xsl:otherwise>
  3569         <xsl:text>      let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
  3634         <xsl:text>      let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
  3570 </xsl:text>
  3635 </xsl:text>
  3571         <xsl:text>      multiline_to_svg_text(this.element, str);
  3636         <xsl:text>      multiline_to_svg_text(this.element, str, !this.ready);
  3572 </xsl:text>
  3637 </xsl:text>
  3573       </xsl:otherwise>
  3638       </xsl:otherwise>
  3574     </xsl:choose>
  3639     </xsl:choose>
  3575     <xsl:text>    },
  3640     <xsl:text>    },
  3576 </xsl:text>
  3641 </xsl:text>
  3577     <xsl:text>    
  3642     <xsl:text>
       
  3643 </xsl:text>
       
  3644     <xsl:text>    init: function() {
  3578 </xsl:text>
  3645 </xsl:text>
  3579     <xsl:if test="$has_format">
  3646     <xsl:if test="$has_format">
  3580       <xsl:text>    init: function() {
       
  3581 </xsl:text>
       
  3582       <xsl:text>      this.format = svg_text_to_multiline(this.format_elt);
  3647       <xsl:text>      this.format = svg_text_to_multiline(this.format_elt);
  3583 </xsl:text>
  3648 </xsl:text>
  3584       <xsl:text>    },
       
  3585 </xsl:text>
       
  3586     </xsl:if>
  3649     </xsl:if>
       
  3650     <xsl:text>      this.animate();
       
  3651 </xsl:text>
       
  3652     <xsl:text>    },
       
  3653 </xsl:text>
  3587   </xsl:template>
  3654   </xsl:template>
  3588   <xsl:template match="widget[@type='DropDown']" mode="widget_desc">
  3655   <xsl:template match="widget[@type='DropDown']" mode="widget_desc">
  3589     <type>
  3656     <type>
  3590       <xsl:value-of select="@type"/>
  3657       <xsl:value-of select="@type"/>
  3591     </type>
  3658     </type>
  4780 </xsl:text>
  4847 </xsl:text>
  4781     <xsl:text>         this.alert("min");
  4848     <xsl:text>         this.alert("min");
  4782 </xsl:text>
  4849 </xsl:text>
  4783     <xsl:text>     }
  4850     <xsl:text>     }
  4784 </xsl:text>
  4851 </xsl:text>
       
  4852     <xsl:text>
       
  4853 </xsl:text>
       
  4854     <xsl:text>     display = "";
       
  4855 </xsl:text>
  4785     <xsl:text>}
  4856     <xsl:text>}
  4786 </xsl:text>
  4857 </xsl:text>
  4787   </xsl:template>
  4858   </xsl:template>
  4788   <xsl:template match="widget[@type='Input']" mode="widget_defs">
  4859   <xsl:template match="widget[@type='Input']" mode="widget_defs">
  4789     <xsl:param name="hmi_element"/>
  4860     <xsl:param name="hmi_element"/>
  4860 </xsl:text>
  4931 </xsl:text>
  4861       <xsl:if test="$have_value">
  4932       <xsl:if test="$have_value">
  4862         <xsl:text>        this.value_elt.style.pointerEvents = "none";
  4933         <xsl:text>        this.value_elt.style.pointerEvents = "none";
  4863 </xsl:text>
  4934 </xsl:text>
  4864       </xsl:if>
  4935       </xsl:if>
       
  4936       <xsl:text>        this.animate();
       
  4937 </xsl:text>
  4865     </xsl:if>
  4938     </xsl:if>
  4866     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
  4939     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
  4867       <xsl:text>        id("</xsl:text>
  4940       <xsl:text>        id("</xsl:text>
  4868       <xsl:value-of select="@id"/>
  4941       <xsl:value-of select="@id"/>
  4869       <xsl:text>").onclick = () =&gt; this.on_op_click("</xsl:text>
  4942       <xsl:text>").onclick = () =&gt; this.on_op_click("</xsl:text>
  4870       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
  4943       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
  4871       <xsl:text>");
  4944       <xsl:text>");
  4872 </xsl:text>
  4945 </xsl:text>
  4873     </xsl:for-each>
  4946     </xsl:for-each>
       
  4947     <xsl:if test="$have_value">
       
  4948       <xsl:text>        this.value_elt.textContent = "";
       
  4949 </xsl:text>
       
  4950     </xsl:if>
  4874     <xsl:text>    },
  4951     <xsl:text>    },
  4875 </xsl:text>
  4952 </xsl:text>
  4876   </xsl:template>
  4953   </xsl:template>
  4877   <xsl:template match="widget[@type='JsonTable']" mode="widget_desc">
  4954   <xsl:template match="widget[@type='JsonTable']" mode="widget_desc">
  4878     <type>
  4955     <type>
  7923     <xsl:call-template name="defs_by_labels">
  8000     <xsl:call-template name="defs_by_labels">
  7924       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  8001       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  7925       <xsl:with-param name="labels">
  8002       <xsl:with-param name="labels">
  7926         <xsl:text>/active /inactive</xsl:text>
  8003         <xsl:text>/active /inactive</xsl:text>
  7927       </xsl:with-param>
  8004       </xsl:with-param>
       
  8005       <xsl:with-param name="mandatory" select="'warn'"/>
  7928     </xsl:call-template>
  8006     </xsl:call-template>
  7929     <xsl:text>    }
  8007     <xsl:text>    }
  7930 </xsl:text>
  8008 </xsl:text>
  7931   </xsl:template>
  8009   </xsl:template>
  7932   <xsl:template match="widget[@type='XYGraph']" mode="widget_desc">
  8010   <xsl:template match="widget[@type='XYGraph']" mode="widget_desc">
 10759 </xsl:text>
 10837 </xsl:text>
 10760           <xsl:text>}
 10838           <xsl:text>}
 10761 </xsl:text>
 10839 </xsl:text>
 10762           <xsl:text>
 10840           <xsl:text>
 10763 </xsl:text>
 10841 </xsl:text>
 10764           <xsl:text>function multiline_to_svg_text(elt, str) {
 10842           <xsl:text>function multiline_to_svg_text(elt, str, blank) {
 10765 </xsl:text>
 10843 </xsl:text>
 10766           <xsl:text>    str.split('\n').map((line,i) =&gt; {elt.children[i].textContent = line;});
 10844           <xsl:text>    str.split('\n').map((line,i) =&gt; {elt.children[i].textContent = blank?"":line;});
 10767 </xsl:text>
 10845 </xsl:text>
 10768           <xsl:text>}
 10846           <xsl:text>}
 10769 </xsl:text>
 10847 </xsl:text>
 10770           <xsl:text>
 10848           <xsl:text>
 10771 </xsl:text>
 10849 </xsl:text>