svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2913 ac4328e69079
parent 2907 1695122a5e16
child 2917 c8d923dd707f
equal deleted inserted replaced
2912:d320367eb2ad 2913:ac4328e69079
   125               <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
   125               <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
   126               <xsl:if test="count($item) = 1">
   126               <xsl:if test="count($item) = 1">
   127                 <xsl:attribute name="index">
   127                 <xsl:attribute name="index">
   128                   <xsl:value-of select="$item/@index"/>
   128                   <xsl:value-of select="$item/@index"/>
   129                 </xsl:attribute>
   129                 </xsl:attribute>
       
   130                 <xsl:attribute name="type">
       
   131                   <xsl:value-of select="local-name($item)"/>
       
   132                 </xsl:attribute>
   130               </xsl:if>
   133               </xsl:if>
   131             </path>
   134             </path>
   132           </xsl:if>
   135           </xsl:if>
   133         </xsl:for-each>
   136         </xsl:for-each>
   134       </widget>
   137       </widget>
   257     <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
   260     <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
   258     <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or &#10;                          (not(@Id = $groups/@id) and (func:intersect($g, .) &gt; 0 ))]"/>
   261     <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or &#10;                          (not(@Id = $groups/@id) and (func:intersect($g, .) &gt; 0 ))]"/>
   259   </func:function>
   262   </func:function>
   260   <xsl:variable name="hmi_pages_descs" select="$parsed_widgets/widget[@type = 'Page']"/>
   263   <xsl:variable name="hmi_pages_descs" select="$parsed_widgets/widget[@type = 'Page']"/>
   261   <xsl:variable name="hmi_pages" select="$hmi_elements[@id = $hmi_pages_descs/@id]"/>
   264   <xsl:variable name="hmi_pages" select="$hmi_elements[@id = $hmi_pages_descs/@id]"/>
       
   265   <xsl:variable name="keypads_descs" select="$parsed_widgets/widget[@type = 'Keypad']"/>
       
   266   <xsl:variable name="keypads" select="$hmi_elements[@id = $keypads_descs/@id]"/>
   262   <xsl:variable name="default_page">
   267   <xsl:variable name="default_page">
   263     <xsl:choose>
   268     <xsl:choose>
   264       <xsl:when test="count($hmi_pages) &gt; 1">
   269       <xsl:when test="count($hmi_pages) &gt; 1">
   265         <xsl:choose>
   270         <xsl:choose>
   266           <xsl:when test="$hmi_pages_descs/arg[1]/@value = 'Home'">
   271           <xsl:when test="$hmi_pages_descs/arg[1]/@value = 'Home'">
   309       <xsl:otherwise>
   314       <xsl:otherwise>
   310         <func:result select="/.."/>
   315         <func:result select="/.."/>
   311       </xsl:otherwise>
   316       </xsl:otherwise>
   312     </xsl:choose>
   317     </xsl:choose>
   313   </func:function>
   318   </func:function>
   314   <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:*&#10;       | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/>
   319   <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:*&#10;       | func:required_elements($hmi_pages | $keypads)/ancestor-or-self::svg:*"/>
   315   <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/>
   320   <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/>
   316   <func:function name="func:sumarized_elements">
   321   <func:function name="func:sumarized_elements">
   317     <xsl:param name="elements"/>
   322     <xsl:param name="elements"/>
   318     <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/>
   323     <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/>
   319     <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[&#10;        not(descendant::*[&#10;            not(self::svg:g) and&#10;            not(@id = $discardable_elements/@id) and&#10;            not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)&#10;        ])]"/>
   324     <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[&#10;        not(descendant::*[&#10;            not(self::svg:g) and&#10;            not(@id = $discardable_elements/@id) and&#10;            not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)&#10;        ])]"/>
   329       <xsl:otherwise>
   334       <xsl:otherwise>
   330         <func:result select="/.."/>
   335         <func:result select="/.."/>
   331       </xsl:otherwise>
   336       </xsl:otherwise>
   332     </xsl:choose>
   337     </xsl:choose>
   333   </func:function>
   338   </func:function>
   334   <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages)"/>
   339   <xsl:variable name="_detachable_elements" select="func:detachable_elements($hmi_pages | $keypads)"/>
   335   <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
   340   <xsl:variable name="detachable_elements" select="$_detachable_elements[not(ancestor::*/@id = $_detachable_elements/@id)]"/>
   336   <xsl:variable name="forEach_widgets_ids" select="$parsed_widgets/widget[@type = 'ForEach']/@id"/>
   341   <xsl:variable name="forEach_widgets_ids" select="$parsed_widgets/widget[@type = 'ForEach']/@id"/>
   337   <xsl:variable name="forEach_widgets" select="$hmi_elements[@id = $forEach_widgets_ids]"/>
   342   <xsl:variable name="forEach_widgets" select="$hmi_elements[@id = $forEach_widgets_ids]"/>
   338   <xsl:variable name="in_forEach_widget_ids" select="func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]/@id"/>
   343   <xsl:variable name="in_forEach_widget_ids" select="func:refered_elements($forEach_widgets)[not(@id = $forEach_widgets_ids)]/@id"/>
   339   <xsl:template mode="page_desc" match="svg:*">
   344   <xsl:template mode="page_desc" match="svg:*">
   724   </func:function>
   729   </func:function>
   725   <xsl:template mode="widget_defs" match="widget[@type='Back']">
   730   <xsl:template mode="widget_defs" match="widget[@type='Back']">
   726     <xsl:param name="hmi_element"/>
   731     <xsl:param name="hmi_element"/>
   727     <xsl:text>    on_click: function(evt) {
   732     <xsl:text>    on_click: function(evt) {
   728 </xsl:text>
   733 </xsl:text>
   729     <xsl:text>        console.log("Back !");
       
   730 </xsl:text>
       
   731     <xsl:text>        if(jump_history.length &gt; 1){
   734     <xsl:text>        if(jump_history.length &gt; 1){
   732 </xsl:text>
   735 </xsl:text>
   733     <xsl:text>           jump_history.pop();
   736     <xsl:text>           jump_history.pop();
   734 </xsl:text>
   737 </xsl:text>
   735     <xsl:text>           let [page_name, index] = jump_history.pop();
   738     <xsl:text>           let [page_name, index] = jump_history.pop();
   895     <xsl:value-of select="$value_elt"/>
   898     <xsl:value-of select="$value_elt"/>
   896     <xsl:if test="$have_value">
   899     <xsl:if test="$have_value">
   897       <xsl:text>    frequency: 5,
   900       <xsl:text>    frequency: 5,
   898 </xsl:text>
   901 </xsl:text>
   899     </xsl:if>
   902     </xsl:if>
       
   903     <xsl:text>    last_val: undefined,
       
   904 </xsl:text>
   900     <xsl:text>    dispatch: function(value) {
   905     <xsl:text>    dispatch: function(value) {
       
   906 </xsl:text>
       
   907     <xsl:text>        this.last_val = value;
   901 </xsl:text>
   908 </xsl:text>
   902     <xsl:if test="$have_value">
   909     <xsl:if test="$have_value">
   903       <xsl:text>        this.value_elt.textContent = String(value);
   910       <xsl:text>        this.value_elt.textContent = String(value);
   904 </xsl:text>
   911 </xsl:text>
   905     </xsl:if>
   912     </xsl:if>
   909     <xsl:text>    init: function() {
   916     <xsl:text>    init: function() {
   910 </xsl:text>
   917 </xsl:text>
   911     <xsl:if test="$edit_elt_id">
   918     <xsl:if test="$edit_elt_id">
   912       <xsl:text>        id("</xsl:text>
   919       <xsl:text>        id("</xsl:text>
   913       <xsl:value-of select="$edit_elt_id"/>
   920       <xsl:value-of select="$edit_elt_id"/>
   914       <xsl:text>").addEventListener(
   921       <xsl:text>").setAttribute("onclick", "hmi_widgets['</xsl:text>
   915 </xsl:text>
   922       <xsl:value-of select="$hmi_element/@id"/>
   916       <xsl:text>            "click", 
   923       <xsl:text>'].on_edit_click()");
   917 </xsl:text>
       
   918       <xsl:text>            evt =&gt; alert('XXX TODO : Edit value'));
       
   919 </xsl:text>
   924 </xsl:text>
   920     </xsl:if>
   925     </xsl:if>
   921     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
   926     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
   922       <xsl:text>        id("</xsl:text>
   927       <xsl:text>        id("</xsl:text>
   923       <xsl:value-of select="@id"/>
   928       <xsl:value-of select="@id"/>
   924       <xsl:text>").addEventListener(
   929       <xsl:text>").setAttribute("onclick", "hmi_widgets['</xsl:text>
   925 </xsl:text>
   930       <xsl:value-of select="$hmi_element/@id"/>
   926       <xsl:text>            "click", 
   931       <xsl:text>'].on_op_click('</xsl:text>
   927 </xsl:text>
       
   928       <xsl:text>            evt =&gt; {let new_val = change_hmi_value(this.indexes[0], "</xsl:text>
       
   929       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
   932       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
   930       <xsl:text>");
   933       <xsl:text>')");
   931 </xsl:text>
       
   932       <xsl:if test="$have_value">
       
   933         <xsl:text>                    this.value_elt.textContent = String(new_val);
       
   934 </xsl:text>
       
   935       </xsl:if>
       
   936       <xsl:text>                   });
       
   937 </xsl:text>
   934 </xsl:text>
   938     </xsl:for-each>
   935     </xsl:for-each>
       
   936     <xsl:text>    },
       
   937 </xsl:text>
       
   938     <xsl:text>    on_op_click: function(opstr) {
       
   939 </xsl:text>
       
   940     <xsl:text>        let new_val = change_hmi_value(this.indexes[0], opstr);
       
   941 </xsl:text>
       
   942     <xsl:if test="$have_value">
       
   943       <xsl:text>        this.value_elt.textContent = String(new_val);
       
   944 </xsl:text>
       
   945     </xsl:if>
       
   946     <xsl:text>    },
       
   947 </xsl:text>
       
   948     <xsl:text>    on_edit_click: function(opstr) {
       
   949 </xsl:text>
       
   950     <xsl:text>        edit_value("</xsl:text>
       
   951     <xsl:value-of select="path/@value"/>
       
   952     <xsl:text>", "</xsl:text>
       
   953     <xsl:value-of select="path/@type"/>
       
   954     <xsl:text>", this.edit_callback, this.last_val);
       
   955 </xsl:text>
       
   956     <xsl:text>    },
       
   957 </xsl:text>
       
   958     <xsl:text>    edit_callback: function(new_val) {
       
   959 </xsl:text>
       
   960     <xsl:text>        apply_hmi_value(this.indexes[0], opstr);
       
   961 </xsl:text>
       
   962     <xsl:if test="$have_value">
       
   963       <xsl:text>        this.value_elt.textContent = String(new_val);
       
   964 </xsl:text>
       
   965     </xsl:if>
   939     <xsl:text>    },
   966     <xsl:text>    },
   940 </xsl:text>
   967 </xsl:text>
   941   </xsl:template>
   968   </xsl:template>
   942   <xsl:template name="jump_widget_activity">
   969   <xsl:template name="jump_widget_activity">
   943     <xsl:param name="hmi_element"/>
   970     <xsl:param name="hmi_element"/>
   984         <xsl:text>    frequency: 2,
  1011         <xsl:text>    frequency: 2,
   985 </xsl:text>
  1012 </xsl:text>
   986         <xsl:text>    dispatch: function(value) {
  1013         <xsl:text>    dispatch: function(value) {
   987 </xsl:text>
  1014 </xsl:text>
   988         <xsl:text>        this.disabled = !Number(value);
  1015         <xsl:text>        this.disabled = !Number(value);
   989 </xsl:text>
       
   990         <xsl:text>        console.log("disbled",value);
       
   991 </xsl:text>
  1016 </xsl:text>
   992         <xsl:text>        this.update();
  1017         <xsl:text>        this.update();
   993 </xsl:text>
  1018 </xsl:text>
   994         <xsl:text>    },
  1019         <xsl:text>    },
   995 </xsl:text>
  1020 </xsl:text>
  1159           <xsl:text>")</xsl:text>
  1184           <xsl:text>")</xsl:text>
  1160         </xsl:message>
  1185         </xsl:message>
  1161       </xsl:if>
  1186       </xsl:if>
  1162     </xsl:if>
  1187     </xsl:if>
  1163   </xsl:template>
  1188   </xsl:template>
       
  1189   <xsl:template mode="widget_defs" match="widget[@type='Keypad']">
       
  1190     <xsl:text>    init: function() {
       
  1191 </xsl:text>
       
  1192     <xsl:text>    },
       
  1193 </xsl:text>
       
  1194   </xsl:template>
  1164   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
  1195   <xsl:template mode="widget_defs" match="widget[@type='Meter']">
  1165     <xsl:param name="hmi_element"/>
  1196     <xsl:param name="hmi_element"/>
  1166     <xsl:text>    frequency: 10,
  1197     <xsl:text>    frequency: 10,
  1167 </xsl:text>
  1198 </xsl:text>
  1168     <xsl:call-template name="defs_by_labels">
  1199     <xsl:call-template name="defs_by_labels">
  1286   </xsl:template>
  1317   </xsl:template>
  1287   <xsl:template match="/">
  1318   <xsl:template match="/">
  1288     <xsl:comment>
  1319     <xsl:comment>
  1289       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
  1320       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
  1290     </xsl:comment>
  1321     </xsl:comment>
       
  1322     <xsl:apply-templates mode="debug_as_comment" select="document('')/*/reflect:*"/>
  1291     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
  1323     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
  1292       <head/>
  1324       <head/>
  1293       <body style="margin:0;overflow:hidden;">
  1325       <body style="margin:0;overflow:hidden;">
  1294         <xsl:copy-of select="$result_svg"/>
  1326         <xsl:copy-of select="$result_svg"/>
  1295         <script>
  1327         <script>
  1365     <xsl:text>var page_desc = {
  1397     <xsl:text>var page_desc = {
  1366 </xsl:text>
  1398 </xsl:text>
  1367     <xsl:apply-templates mode="page_desc" select="$hmi_pages"/>
  1399     <xsl:apply-templates mode="page_desc" select="$hmi_pages"/>
  1368     <xsl:text>}
  1400     <xsl:text>}
  1369 </xsl:text>
  1401 </xsl:text>
       
  1402     <xsl:text>var keypads = {
       
  1403 </xsl:text>
       
  1404     <xsl:for-each select="$keypads_descs">
       
  1405       <xsl:variable name="keypad_id" select="@id"/>
       
  1406       <xsl:for-each select="arg">
       
  1407         <xsl:variable name="g" select="$geometry[@Id = $keypad_id]"/>
       
  1408         <xsl:text>    "</xsl:text>
       
  1409         <xsl:value-of select="@value"/>
       
  1410         <xsl:text>":["</xsl:text>
       
  1411         <xsl:value-of select="$keypad_id"/>
       
  1412         <xsl:text>", </xsl:text>
       
  1413         <xsl:value-of select="$g/@x"/>
       
  1414         <xsl:text>, </xsl:text>
       
  1415         <xsl:value-of select="$g/@y"/>
       
  1416         <xsl:text>],
       
  1417 </xsl:text>
       
  1418       </xsl:for-each>
       
  1419     </xsl:for-each>
       
  1420     <xsl:text>}
       
  1421 </xsl:text>
  1370     <xsl:text>
  1422     <xsl:text>
  1371 </xsl:text>
  1423 </xsl:text>
  1372     <xsl:text>var default_page = "</xsl:text>
  1424     <xsl:text>var default_page = "</xsl:text>
  1373     <xsl:value-of select="$default_page"/>
  1425     <xsl:value-of select="$default_page"/>
  1374     <xsl:text>";
  1426     <xsl:text>";
  1857 </xsl:text>
  1909 </xsl:text>
  1858     <xsl:text>};
  1910     <xsl:text>};
  1859 </xsl:text>
  1911 </xsl:text>
  1860     <xsl:text>
  1912     <xsl:text>
  1861 </xsl:text>
  1913 </xsl:text>
       
  1914     <xsl:text>function apply_hmi_value(index, new_val) {
       
  1915 </xsl:text>
       
  1916     <xsl:text>    let old_val = cache[index]
       
  1917 </xsl:text>
       
  1918     <xsl:text>    if(new_val != undefined &amp;&amp; old_val != new_val)
       
  1919 </xsl:text>
       
  1920     <xsl:text>        send_hmi_value(index, new_val);
       
  1921 </xsl:text>
       
  1922     <xsl:text>    return new_val;
       
  1923 </xsl:text>
       
  1924     <xsl:text>}
       
  1925 </xsl:text>
       
  1926     <xsl:text>
       
  1927 </xsl:text>
  1862     <xsl:text>function change_hmi_value(index, opstr) {
  1928     <xsl:text>function change_hmi_value(index, opstr) {
  1863 </xsl:text>
  1929 </xsl:text>
  1864     <xsl:text>    let op = opstr[0];
  1930     <xsl:text>    let op = opstr[0];
  1865 </xsl:text>
  1931 </xsl:text>
  1866     <xsl:text>    let given_val = opstr.slice(1);
  1932     <xsl:text>    let given_val = opstr.slice(1);
  2187 </xsl:text>
  2253 </xsl:text>
  2188     <xsl:text>    jumps_need_update = true;
  2254     <xsl:text>    jumps_need_update = true;
  2189 </xsl:text>
  2255 </xsl:text>
  2190     <xsl:text>    requestHMIAnimation();
  2256     <xsl:text>    requestHMIAnimation();
  2191 </xsl:text>
  2257 </xsl:text>
  2192     <xsl:text>    console.log(opstr, new_item_offset);
       
  2193 </xsl:text>
       
  2194     <xsl:text>}
  2258     <xsl:text>}
  2195 </xsl:text>
  2259 </xsl:text>
  2196     <xsl:text>
  2260     <xsl:text>
  2197 </xsl:text>
  2261 </xsl:text>
  2198     <xsl:text>
  2262     <xsl:text>
  2299 </xsl:text>
  2363 </xsl:text>
  2300     <xsl:text>
  2364     <xsl:text>
  2301 </xsl:text>
  2365 </xsl:text>
  2302     <xsl:text>};
  2366     <xsl:text>};
  2303 </xsl:text>
  2367 </xsl:text>
       
  2368     <xsl:text>
       
  2369 </xsl:text>
       
  2370     <xsl:text>var edit_callback;
       
  2371 </xsl:text>
       
  2372     <xsl:text>function edit_value(path, valuetype, callback, initial) {
       
  2373 </xsl:text>
       
  2374     <xsl:text>
       
  2375 </xsl:text>
       
  2376     <xsl:text>    let [keypadid, xcoord, ycoord] = keypads[valuetype];
       
  2377 </xsl:text>
       
  2378     <xsl:text>    console.log('XXX TODO : Edit value', path, valuetype, callback, initial, keypadid);
       
  2379 </xsl:text>
       
  2380     <xsl:text>    edit_callback = callback;
       
  2381 </xsl:text>
       
  2382     <xsl:text>
       
  2383 </xsl:text>
       
  2384     <xsl:text>    let [element, parent] = detachable_elements[keypadid];
       
  2385 </xsl:text>
       
  2386     <xsl:text>    tmpgrp = document.createElement("g");
       
  2387 </xsl:text>
       
  2388     <xsl:text>    tmpgrpattr = document.createAttribute("transform");
       
  2389 </xsl:text>
       
  2390     <xsl:text>
       
  2391 </xsl:text>
       
  2392     <xsl:text>    let [xdest,ydest] = page_desc[current_visible_page].bbox;
       
  2393 </xsl:text>
       
  2394     <xsl:text>    tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")";
       
  2395 </xsl:text>
       
  2396     <xsl:text>    tmpgrp.setAttributeNode(tmpgrpattr);
       
  2397 </xsl:text>
       
  2398     <xsl:text>
       
  2399 </xsl:text>
       
  2400     <xsl:text>    tmpgrp.appendChild(element);
       
  2401 </xsl:text>
       
  2402     <xsl:text>    parent.appendChild(tmpgrp);
       
  2403 </xsl:text>
       
  2404     <xsl:text>
       
  2405 </xsl:text>
       
  2406     <xsl:text>};
       
  2407 </xsl:text>
       
  2408     <xsl:text>
       
  2409 </xsl:text>
  2304   </xsl:template>
  2410   </xsl:template>
  2305 </xsl:stylesheet>
  2411 </xsl:stylesheet>