svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2979 9442f6a6449e
parent 2977 82f062408e70
child 2980 2a21d6060d64
equal deleted inserted replaced
2975:8e8812f13d9d 2979:9442f6a6449e
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     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">
     2 <xsl:stylesheet xmlns:ns="beremiz" xmlns:definitions="definitions" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:func="http://exslt.org/functions" xmlns:epilogue="epilogue" xmlns:preamble="preamble" 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:svg="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:declarations="declarations" xmlns:debug="debug" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0">
     3   <xsl:output cdata-section-elements="xhtml:script" method="xml"/>
     3   <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
     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>
  1150     <xsl:text>    }
  1150     <xsl:text>    }
  1151 </xsl:text>
  1151 </xsl:text>
  1152     <xsl:text>}
  1152     <xsl:text>}
  1153 </xsl:text>
  1153 </xsl:text>
  1154   </xsl:template>
  1154   </xsl:template>
  1155   <xsl:template mode="widget_class" match="widget[@type='Button']">
  1155   <xsl:template mode="widget_defs" match="widget[@type='Button']">
  1156     <xsl:text>class ButtonWidget extends Widget{
  1156     <xsl:param name="hmi_element"/>
  1157 </xsl:text>
  1157     <xsl:call-template name="defs_by_labels">
  1158     <xsl:text>    frequency = 5;
  1158       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  1159 </xsl:text>
  1159       <xsl:with-param name="labels">
  1160     <xsl:text>    init() {
  1160         <xsl:text>active inactive</xsl:text>
  1161 </xsl:text>
  1161       </xsl:with-param>
  1162     <xsl:text>        // TODO : use attributes to allow interaction through svg:use
  1162       <xsl:with-param name="mandatory" select="'no'"/>
  1163 </xsl:text>
  1163     </xsl:call-template>
  1164     <xsl:text>        // TODO : deal with dragging
  1164     <xsl:text>frequency: 5,
  1165 </xsl:text>
  1165 </xsl:text>
  1166     <xsl:text>        this.element.addEventListener(
  1166     <xsl:text>on_mouse_down: function(evt) {
  1167 </xsl:text>
  1167 </xsl:text>
  1168     <xsl:text>          "mousedown",
  1168     <xsl:text>    if (this.active_style &amp;&amp; this.inactive_style) {
  1169 </xsl:text>
  1169 </xsl:text>
  1170     <xsl:text>          evt =&gt; {
  1170     <xsl:text>        this.active_elt.setAttribute("style", this.active_style);
  1171 </xsl:text>
  1171 </xsl:text>
  1172     <xsl:text>              change_hmi_value(this.indexes[0], "=1");
  1172     <xsl:text>        this.inactive_elt.setAttribute("style", "display:none");
  1173 </xsl:text>
       
  1174     <xsl:text>          });
       
  1175 </xsl:text>
       
  1176     <xsl:text>        this.element.addEventListener(
       
  1177 </xsl:text>
       
  1178     <xsl:text>          "mouseup",
       
  1179 </xsl:text>
       
  1180     <xsl:text>          evt =&gt; {
       
  1181 </xsl:text>
       
  1182     <xsl:text>              change_hmi_value(this.indexes[0], "=0");
       
  1183 </xsl:text>
       
  1184     <xsl:text>          });
       
  1185 </xsl:text>
  1173 </xsl:text>
  1186     <xsl:text>    }
  1174     <xsl:text>    }
  1187 </xsl:text>
  1175 </xsl:text>
  1188     <xsl:text>}
  1176     <xsl:text>    change_hmi_value(this.indexes[0], "=1");
       
  1177 </xsl:text>
       
  1178     <xsl:text>},
       
  1179 </xsl:text>
       
  1180     <xsl:text>on_mouse_up: function(evt) {
       
  1181 </xsl:text>
       
  1182     <xsl:text>    if (this.active_style &amp;&amp; this.inactive_style) {
       
  1183 </xsl:text>
       
  1184     <xsl:text>        this.active_elt.setAttribute("style", "display:none");
       
  1185 </xsl:text>
       
  1186     <xsl:text>        this.inactive_elt.setAttribute("style", this.inactive_style);
       
  1187 </xsl:text>
       
  1188     <xsl:text>    }
       
  1189 </xsl:text>
       
  1190     <xsl:text>    change_hmi_value(this.indexes[0], "=0");
       
  1191 </xsl:text>
       
  1192     <xsl:text>},
       
  1193 </xsl:text>
       
  1194     <xsl:text>active_style: undefined,
       
  1195 </xsl:text>
       
  1196     <xsl:text>inactive_style: undefined,
       
  1197 </xsl:text>
       
  1198     <xsl:text>init: function() {
       
  1199 </xsl:text>
       
  1200     <xsl:text>  this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
       
  1201 </xsl:text>
       
  1202     <xsl:text>  this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
       
  1203 </xsl:text>
       
  1204     <xsl:text>  if (this.active_style &amp;&amp; this.inactive_style) {
       
  1205 </xsl:text>
       
  1206     <xsl:text>      this.active_elt.setAttribute("style", "display:none");
       
  1207 </xsl:text>
       
  1208     <xsl:text>      this.inactive_elt.setAttribute("style", this.inactive_style);
       
  1209 </xsl:text>
       
  1210     <xsl:text>  }
       
  1211 </xsl:text>
       
  1212     <xsl:text>  this.element.setAttribute("onmousedown", "hmi_widgets['</xsl:text>
       
  1213     <xsl:value-of select="$hmi_element/@id"/>
       
  1214     <xsl:text>'].on_mouse_down(evt)");
       
  1215 </xsl:text>
       
  1216     <xsl:text>  this.element.setAttribute("onmouseup", "hmi_widgets['</xsl:text>
       
  1217     <xsl:value-of select="$hmi_element/@id"/>
       
  1218     <xsl:text>'].on_mouse_up(evt)");
       
  1219 </xsl:text>
       
  1220     <xsl:text>},
  1189 </xsl:text>
  1221 </xsl:text>
  1190   </xsl:template>
  1222   </xsl:template>
  1191   <xsl:template mode="widget_defs" match="widget[@type='CircularBar']">
  1223   <xsl:template mode="widget_defs" match="widget[@type='CircularBar']">
  1192     <xsl:param name="hmi_element"/>
  1224     <xsl:param name="hmi_element"/>
  1193     <xsl:text>frequency: 10,
  1225     <xsl:text>frequency: 10,
  2695 </xsl:text>
  2727 </xsl:text>
  2696     </xsl:for-each>
  2728     </xsl:for-each>
  2697     <xsl:text>    ],
  2729     <xsl:text>    ],
  2698 </xsl:text>
  2730 </xsl:text>
  2699   </xsl:template>
  2731   </xsl:template>
       
  2732   <xsl:template mode="widget_defs" match="widget[@type='ToggleButton']">
       
  2733     <xsl:param name="hmi_element"/>
       
  2734     <xsl:call-template name="defs_by_labels">
       
  2735       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
  2736       <xsl:with-param name="labels">
       
  2737         <xsl:text>active inactive</xsl:text>
       
  2738       </xsl:with-param>
       
  2739     </xsl:call-template>
       
  2740     <xsl:text>    frequency: 5,
       
  2741 </xsl:text>
       
  2742     <xsl:text>    state: 0,
       
  2743 </xsl:text>
       
  2744     <xsl:text>    dispatch: function(value) {
       
  2745 </xsl:text>
       
  2746     <xsl:text>        this.state = value;
       
  2747 </xsl:text>
       
  2748     <xsl:text>        if (this.state) {
       
  2749 </xsl:text>
       
  2750     <xsl:text>            this.active_elt.setAttribute("style", this.active_style);
       
  2751 </xsl:text>
       
  2752     <xsl:text>            this.inactive_elt.setAttribute("style", "display:none");
       
  2753 </xsl:text>
       
  2754     <xsl:text>            this.state = 0;
       
  2755 </xsl:text>
       
  2756     <xsl:text>        } else {
       
  2757 </xsl:text>
       
  2758     <xsl:text>            this.inactive_elt.setAttribute("style", this.inactive_style);
       
  2759 </xsl:text>
       
  2760     <xsl:text>            this.active_elt.setAttribute("style", "display:none");
       
  2761 </xsl:text>
       
  2762     <xsl:text>            this.state = 1;
       
  2763 </xsl:text>
       
  2764     <xsl:text>        }
       
  2765 </xsl:text>
       
  2766     <xsl:text>    },
       
  2767 </xsl:text>
       
  2768     <xsl:text>    on_click: function(evt) {
       
  2769 </xsl:text>
       
  2770     <xsl:text>        change_hmi_value(this.indexes[0], "="+this.state);
       
  2771 </xsl:text>
       
  2772     <xsl:text>    },
       
  2773 </xsl:text>
       
  2774     <xsl:text>    active_style: undefined,
       
  2775 </xsl:text>
       
  2776     <xsl:text>    inactive_style: undefined,
       
  2777 </xsl:text>
       
  2778     <xsl:text>    init: function() {
       
  2779 </xsl:text>
       
  2780     <xsl:text>        this.active_style = this.active_elt.style.cssText;
       
  2781 </xsl:text>
       
  2782     <xsl:text>        this.inactive_style = this.inactive_elt.style.cssText;
       
  2783 </xsl:text>
       
  2784     <xsl:text>        this.element.setAttribute("onclick", "hmi_widgets['</xsl:text>
       
  2785     <xsl:value-of select="$hmi_element/@id"/>
       
  2786     <xsl:text>'].on_click(evt)");
       
  2787 </xsl:text>
       
  2788     <xsl:text>    },
       
  2789 </xsl:text>
       
  2790   </xsl:template>
  2700   <xsl:template match="/">
  2791   <xsl:template match="/">
  2701     <xsl:comment>
  2792     <xsl:comment>
  2702       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
  2793       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
  2703     </xsl:comment>
  2794     </xsl:comment>
  2704     <xsl:comment>
  2795     <xsl:comment>
  2705       <xsl:apply-templates select="document('')/*/debug:*"/>
  2796       <xsl:apply-templates select="document('')/*/debug:*"/>
  2706     </xsl:comment>
  2797     </xsl:comment>
  2707     <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  2798     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
  2708       <head/>
  2799       <head/>
  2709       <body style="margin:0;overflow:hidden;">
  2800       <body style="margin:0;overflow:hidden;">
  2710         <xsl:copy-of select="$result_svg"/>
  2801         <xsl:copy-of select="$result_svg"/>
  2711         <script>
  2802         <script>
  2712           <xsl:text>
  2803           <xsl:text>
  3269 </xsl:text>
  3360 </xsl:text>
  3270           <xsl:text>        given_val = Number(opstr.slice(1));
  3361           <xsl:text>        given_val = Number(opstr.slice(1));
  3271 </xsl:text>
  3362 </xsl:text>
  3272           <xsl:text>    }
  3363           <xsl:text>    }
  3273 </xsl:text>
  3364 </xsl:text>
  3274           <xsl:text>    console.log(opstr, given_val);
       
  3275 </xsl:text>
       
  3276           <xsl:text>    let old_val = cache[index];
  3365           <xsl:text>    let old_val = cache[index];
  3277 </xsl:text>
  3366 </xsl:text>
  3278           <xsl:text>    let new_val;
  3367           <xsl:text>    let new_val;
  3279 </xsl:text>
  3368 </xsl:text>
  3280           <xsl:text>    switch(op){
  3369           <xsl:text>    switch(op){