svghmi/gen_index_xhtml.xslt
changeset 3414 0ff608310312
parent 3410 eac5832a1489
child 3418 a1d9a0353053
equal deleted inserted replaced
3413:2e84a2782295 3414:0ff608310312
   184         <xsl:otherwise>
   184         <xsl:otherwise>
   185           <xsl:value-of select="$args"/>
   185           <xsl:value-of select="$args"/>
   186         </xsl:otherwise>
   186         </xsl:otherwise>
   187       </xsl:choose>
   187       </xsl:choose>
   188     </xsl:variable>
   188     </xsl:variable>
   189     <xsl:variable name="freq" select="substring-after($typefreq,':')"/>
   189     <xsl:variable name="freq" select="substring-after($typefreq,'|')"/>
   190     <xsl:variable name="_type" select="substring-before($typefreq,'|')"/>
   190     <xsl:variable name="_type" select="substring-before($typefreq,'|')"/>
   191     <xsl:variable name="type">
   191     <xsl:variable name="type">
   192       <xsl:choose>
   192       <xsl:choose>
   193         <xsl:when test="$_type">
   193         <xsl:when test="$_type">
   194           <xsl:value-of select="$_type"/>
   194           <xsl:value-of select="$_type"/>
   204           <xsl:value-of select="$id"/>
   204           <xsl:value-of select="$id"/>
   205         </xsl:attribute>
   205         </xsl:attribute>
   206         <xsl:attribute name="type">
   206         <xsl:attribute name="type">
   207           <xsl:value-of select="$type"/>
   207           <xsl:value-of select="$type"/>
   208         </xsl:attribute>
   208         </xsl:attribute>
   209         <xsl:if test="freq">
   209         <xsl:if test="$freq">
   210           <xsl:attribute name="frequency">
   210           <xsl:attribute name="freq">
   211             <xsl:value-of select="$freq"/>
   211             <xsl:value-of select="$freq"/>
   212           </xsl:attribute>
   212           </xsl:attribute>
   213         </xsl:if>
   213         </xsl:if>
   214         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   214         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   215           <arg>
   215           <arg>
  1245         </xsl:if>
  1245         </xsl:if>
  1246       </xsl:for-each>
  1246       </xsl:for-each>
  1247     </xsl:variable>
  1247     </xsl:variable>
  1248     <xsl:variable name="freq">
  1248     <xsl:variable name="freq">
  1249       <xsl:choose>
  1249       <xsl:choose>
  1250         <xsl:when test="$widget/freq">
  1250         <xsl:when test="$widget/@freq">
  1251           <xsl:value-of select="$widget/freq"/>
  1251           <xsl:value-of select="$widget/@freq"/>
  1252         </xsl:when>
  1252         </xsl:when>
  1253         <xsl:otherwise>
  1253         <xsl:otherwise>
  1254           <xsl:text>undefined</xsl:text>
  1254           <xsl:text>undefined</xsl:text>
  1255         </xsl:otherwise>
  1255         </xsl:otherwise>
  1256       </xsl:choose>
  1256       </xsl:choose>
  2212     </shortdesc>
  2212     </shortdesc>
  2213     <path name="value" accepts="HMI_BOOL">
  2213     <path name="value" accepts="HMI_BOOL">
  2214       <xsl:text>Boolean variable</xsl:text>
  2214       <xsl:text>Boolean variable</xsl:text>
  2215     </path>
  2215     </path>
  2216   </xsl:template>
  2216   </xsl:template>
       
  2217   <xsl:variable name="_push_button_fsm">
       
  2218     <fsm>
       
  2219       <state name="init">
       
  2220         <on-dispatch value="false">
       
  2221           <jump state="reflect_off"/>
       
  2222         </on-dispatch>
       
  2223         <on-dispatch value="true">
       
  2224           <jump state="reflect_on"/>
       
  2225         </on-dispatch>
       
  2226       </state>
       
  2227       <state name="reflect_on">
       
  2228         <show eltname="active"/>
       
  2229         <on-mouse position="down">
       
  2230           <jump state="on"/>
       
  2231         </on-mouse>
       
  2232         <on-mouse position="up">
       
  2233           <jump state="off"/>
       
  2234         </on-mouse>
       
  2235         <on-dispatch value="false">
       
  2236           <jump state="reflect_off"/>
       
  2237         </on-dispatch>
       
  2238       </state>
       
  2239       <state name="on">
       
  2240         <hmi-value value="true"/>
       
  2241         <show eltname="active"/>
       
  2242         <on-mouse position="up">
       
  2243           <jump state="off"/>
       
  2244         </on-mouse>
       
  2245         <on-dispatch value="false">
       
  2246           <jump state="reflect_off"/>
       
  2247         </on-dispatch>
       
  2248       </state>
       
  2249       <state name="reflect_off">
       
  2250         <show eltname="inactive"/>
       
  2251         <on-mouse position="down">
       
  2252           <jump state="on"/>
       
  2253         </on-mouse>
       
  2254         <on-mouse position="up">
       
  2255           <jump state="off"/>
       
  2256         </on-mouse>
       
  2257         <on-dispatch value="true">
       
  2258           <jump state="reflect_on"/>
       
  2259         </on-dispatch>
       
  2260       </state>
       
  2261       <state name="off">
       
  2262         <hmi-value value="false"/>
       
  2263         <show eltname="inactive"/>
       
  2264         <on-mouse position="down">
       
  2265           <jump state="on"/>
       
  2266         </on-mouse>
       
  2267         <on-dispatch value="true">
       
  2268           <jump state="reflect_on"/>
       
  2269         </on-dispatch>
       
  2270       </state>
       
  2271     </fsm>
       
  2272   </xsl:variable>
  2217   <xsl:variable name="_button_fsm">
  2273   <xsl:variable name="_button_fsm">
  2218     <fsm>
  2274     <fsm>
  2219       <state name="init">
  2275       <state name="init">
  2220         <on-dispatch value="false">
  2276         <on-dispatch value="false">
  2221           <jump state="released"/>
  2277           <jump state="released"/>
  2342   <xsl:template mode="actions" match="state">
  2398   <xsl:template mode="actions" match="state">
  2343     <xsl:text>    </xsl:text>
  2399     <xsl:text>    </xsl:text>
  2344     <xsl:value-of select="@name"/>
  2400     <xsl:value-of select="@name"/>
  2345     <xsl:text>_action(){
  2401     <xsl:text>_action(){
  2346 </xsl:text>
  2402 </xsl:text>
       
  2403     <xsl:text>console.log("Entering state </xsl:text>
       
  2404     <xsl:value-of select="@name"/>
       
  2405     <xsl:text>");
       
  2406 </xsl:text>
  2347     <xsl:apply-templates mode="actions" select="*"/>
  2407     <xsl:apply-templates mode="actions" select="*"/>
  2348     <xsl:text>    }
  2408     <xsl:text>    }
  2349 </xsl:text>
  2409 </xsl:text>
  2350   </xsl:template>
  2410   </xsl:template>
  2351   <xsl:template mode="actions" match="show">
  2411   <xsl:template mode="actions" match="show">
  2360     <xsl:text>        this.apply_hmi_value(0, </xsl:text>
  2420     <xsl:text>        this.apply_hmi_value(0, </xsl:text>
  2361     <xsl:value-of select="@value"/>
  2421     <xsl:value-of select="@value"/>
  2362     <xsl:text>);
  2422     <xsl:text>);
  2363 </xsl:text>
  2423 </xsl:text>
  2364   </xsl:template>
  2424   </xsl:template>
       
  2425   <xsl:template name="generated_button_class">
       
  2426     <xsl:param name="fsm"/>
       
  2427     <xsl:text>    frequency = 5;
       
  2428 </xsl:text>
       
  2429     <xsl:text>    display = "inactive";
       
  2430 </xsl:text>
       
  2431     <xsl:text>    state = "init";
       
  2432 </xsl:text>
       
  2433     <xsl:text>    dispatch(value) {
       
  2434 </xsl:text>
       
  2435     <xsl:apply-templates mode="dispatch_transition" select="$fsm"/>
       
  2436     <xsl:text>    }
       
  2437 </xsl:text>
       
  2438     <xsl:text>    onmouseup(evt) {
       
  2439 </xsl:text>
       
  2440     <xsl:text>        svg_root.removeEventListener("pointerup", this.bound_onmouseup, true);
       
  2441 </xsl:text>
       
  2442     <xsl:apply-templates mode="mouse_transition" select="$fsm">
       
  2443       <xsl:with-param name="position" select="'up'"/>
       
  2444     </xsl:apply-templates>
       
  2445     <xsl:text>    }
       
  2446 </xsl:text>
       
  2447     <xsl:text>    onmousedown(evt) {
       
  2448 </xsl:text>
       
  2449     <xsl:text>        svg_root.addEventListener("pointerup", this.bound_onmouseup, true);
       
  2450 </xsl:text>
       
  2451     <xsl:apply-templates mode="mouse_transition" select="$fsm">
       
  2452       <xsl:with-param name="position" select="'down'"/>
       
  2453     </xsl:apply-templates>
       
  2454     <xsl:text>    }
       
  2455 </xsl:text>
       
  2456     <xsl:apply-templates mode="actions" select="$fsm"/>
       
  2457     <xsl:text>    animate(){
       
  2458 </xsl:text>
       
  2459     <xsl:text>        if (this.active_elt &amp;&amp; this.inactive_elt) {
       
  2460 </xsl:text>
       
  2461     <xsl:for-each select="str:split('active inactive')">
       
  2462       <xsl:text>            if(this.display == "</xsl:text>
       
  2463       <xsl:value-of select="."/>
       
  2464       <xsl:text>")
       
  2465 </xsl:text>
       
  2466       <xsl:text>                this.</xsl:text>
       
  2467       <xsl:value-of select="."/>
       
  2468       <xsl:text>_elt.style.display = "";
       
  2469 </xsl:text>
       
  2470       <xsl:text>            else
       
  2471 </xsl:text>
       
  2472       <xsl:text>                this.</xsl:text>
       
  2473       <xsl:value-of select="."/>
       
  2474       <xsl:text>_elt.style.display = "none";
       
  2475 </xsl:text>
       
  2476     </xsl:for-each>
       
  2477     <xsl:text>        }
       
  2478 </xsl:text>
       
  2479     <xsl:text>    }
       
  2480 </xsl:text>
       
  2481     <xsl:text>    init() {
       
  2482 </xsl:text>
       
  2483     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
       
  2484 </xsl:text>
       
  2485     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
       
  2486 </xsl:text>
       
  2487     <xsl:text>    }
       
  2488 </xsl:text>
       
  2489   </xsl:template>
  2365   <xsl:template match="widget[@type='Button']" mode="widget_class">
  2490   <xsl:template match="widget[@type='Button']" mode="widget_class">
  2366     <xsl:text>class </xsl:text>
  2491     <xsl:text>class </xsl:text>
  2367     <xsl:text>ButtonWidget</xsl:text>
  2492     <xsl:text>ButtonWidget</xsl:text>
  2368     <xsl:text> extends Widget{
  2493     <xsl:text> extends Widget{
  2369 </xsl:text>
  2494 </xsl:text>
  2370     <xsl:variable name="fsm" select="exsl:node-set($_button_fsm)"/>
  2495     <xsl:variable name="fsm" select="exsl:node-set($_button_fsm)"/>
  2371     <xsl:text>    frequency = 5;
  2496     <xsl:call-template name="generated_button_class">
  2372 </xsl:text>
  2497       <xsl:with-param name="fsm" select="$fsm"/>
  2373     <xsl:text>    display = "inactive";
  2498     </xsl:call-template>
  2374 </xsl:text>
       
  2375     <xsl:text>    state = "init";
       
  2376 </xsl:text>
       
  2377     <xsl:text>    dispatch(value) {
       
  2378 </xsl:text>
       
  2379     <xsl:apply-templates mode="dispatch_transition" select="$fsm"/>
       
  2380     <xsl:text>    }
       
  2381 </xsl:text>
       
  2382     <xsl:text>    onmouseup(evt) {
       
  2383 </xsl:text>
       
  2384     <xsl:text>        svg_root.removeEventListener("pointerup", this.bound_onmouseup, true);
       
  2385 </xsl:text>
       
  2386     <xsl:apply-templates mode="mouse_transition" select="$fsm">
       
  2387       <xsl:with-param name="position" select="'up'"/>
       
  2388     </xsl:apply-templates>
       
  2389     <xsl:text>    }
       
  2390 </xsl:text>
       
  2391     <xsl:text>    onmousedown(evt) {
       
  2392 </xsl:text>
       
  2393     <xsl:text>        svg_root.addEventListener("pointerup", this.bound_onmouseup, true);
       
  2394 </xsl:text>
       
  2395     <xsl:apply-templates mode="mouse_transition" select="$fsm">
       
  2396       <xsl:with-param name="position" select="'down'"/>
       
  2397     </xsl:apply-templates>
       
  2398     <xsl:text>    }
       
  2399 </xsl:text>
       
  2400     <xsl:apply-templates mode="actions" select="$fsm"/>
       
  2401     <xsl:text>    animate(){
       
  2402 </xsl:text>
       
  2403     <xsl:text>        if (this.active_elt &amp;&amp; this.inactive_elt) {
       
  2404 </xsl:text>
       
  2405     <xsl:for-each select="str:split('active inactive')">
       
  2406       <xsl:text>            if(this.display == "</xsl:text>
       
  2407       <xsl:value-of select="."/>
       
  2408       <xsl:text>")
       
  2409 </xsl:text>
       
  2410       <xsl:text>                this.</xsl:text>
       
  2411       <xsl:value-of select="."/>
       
  2412       <xsl:text>_elt.style.display = "";
       
  2413 </xsl:text>
       
  2414       <xsl:text>            else
       
  2415 </xsl:text>
       
  2416       <xsl:text>                this.</xsl:text>
       
  2417       <xsl:value-of select="."/>
       
  2418       <xsl:text>_elt.style.display = "none";
       
  2419 </xsl:text>
       
  2420     </xsl:for-each>
       
  2421     <xsl:text>        }
       
  2422 </xsl:text>
       
  2423     <xsl:text>    }
       
  2424 </xsl:text>
       
  2425     <xsl:text>    init() {
       
  2426 </xsl:text>
       
  2427     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
       
  2428 </xsl:text>
       
  2429     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
       
  2430 </xsl:text>
       
  2431     <xsl:text>    }
       
  2432 </xsl:text>
       
  2433     <xsl:text>}
  2499     <xsl:text>}
  2434 </xsl:text>
  2500 </xsl:text>
  2435   </xsl:template>
  2501   </xsl:template>
  2436   <xsl:template match="widget[@type='Button']" mode="widget_defs">
  2502   <xsl:template match="widget[@type='Button']" mode="widget_defs">
       
  2503     <xsl:param name="hmi_element"/>
       
  2504     <xsl:call-template name="defs_by_labels">
       
  2505       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
  2506       <xsl:with-param name="labels">
       
  2507         <xsl:text>active inactive</xsl:text>
       
  2508       </xsl:with-param>
       
  2509       <xsl:with-param name="mandatory" select="'no'"/>
       
  2510     </xsl:call-template>
       
  2511   </xsl:template>
       
  2512   <xsl:template match="widget[@type='PushButton']" mode="widget_class">
       
  2513     <xsl:text>class </xsl:text>
       
  2514     <xsl:text>PushButtonWidget</xsl:text>
       
  2515     <xsl:text> extends Widget{
       
  2516 </xsl:text>
       
  2517     <xsl:variable name="fsm" select="exsl:node-set($_push_button_fsm)"/>
       
  2518     <xsl:call-template name="generated_button_class">
       
  2519       <xsl:with-param name="fsm" select="$fsm"/>
       
  2520     </xsl:call-template>
       
  2521     <xsl:text>}
       
  2522 </xsl:text>
       
  2523   </xsl:template>
       
  2524   <xsl:template match="widget[@type='PushButton']" mode="widget_defs">
  2437     <xsl:param name="hmi_element"/>
  2525     <xsl:param name="hmi_element"/>
  2438     <xsl:call-template name="defs_by_labels">
  2526     <xsl:call-template name="defs_by_labels">
  2439       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2527       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2440       <xsl:with-param name="labels">
  2528       <xsl:with-param name="labels">
  2441         <xsl:text>active inactive</xsl:text>
  2529         <xsl:text>active inactive</xsl:text>
  8711 </xsl:text>
  8799 </xsl:text>
  8712           <xsl:text>
  8800           <xsl:text>
  8713 </xsl:text>
  8801 </xsl:text>
  8714           <xsl:text>function send_hmi_value(index, value) {
  8802           <xsl:text>function send_hmi_value(index, value) {
  8715 </xsl:text>
  8803 </xsl:text>
       
  8804           <xsl:text>    console.log("send_hmi_value("+index+", "+value+")")
       
  8805 </xsl:text>
  8716           <xsl:text>    if(index &gt; last_remote_index){
  8806           <xsl:text>    if(index &gt; last_remote_index){
  8717 </xsl:text>
  8807 </xsl:text>
  8718           <xsl:text>        updates.set(index, value);
  8808           <xsl:text>        updates.set(index, value);
  8719 </xsl:text>
  8809 </xsl:text>
  8720           <xsl:text>
  8810           <xsl:text>
  8759 </xsl:text>
  8849 </xsl:text>
  8760           <xsl:text>
  8850           <xsl:text>
  8761 </xsl:text>
  8851 </xsl:text>
  8762           <xsl:text>function apply_hmi_value(index, new_val) {
  8852           <xsl:text>function apply_hmi_value(index, new_val) {
  8763 </xsl:text>
  8853 </xsl:text>
  8764           <xsl:text>    let old_val = cache[index];
  8854           <xsl:text>    console.log("apply_hmi_value("+index+", "+new_val+")")
  8765 </xsl:text>
  8855 </xsl:text>
  8766           <xsl:text>    if(new_val != undefined &amp;&amp; old_val != new_val)
  8856           <xsl:text>    /*let old_val = cache[index];*/
       
  8857 </xsl:text>
       
  8858           <xsl:text>    if(new_val != undefined /*&amp;&amp; old_val != new_val*/)
  8767 </xsl:text>
  8859 </xsl:text>
  8768           <xsl:text>        send_hmi_value(index, new_val);
  8860           <xsl:text>        send_hmi_value(index, new_val);
  8769 </xsl:text>
  8861 </xsl:text>
  8770           <xsl:text>    return new_val;
  8862           <xsl:text>    return new_val;
  8771 </xsl:text>
  8863 </xsl:text>