svghmi/gen_index_xhtml.xslt
changeset 3521 4345b3c9b9de
parent 3517 dacf329abdd9
child 3525 c2f7e9bda366
equal deleted inserted replaced
3520:b27e50143083 3521:4345b3c9b9de
  1456 </xsl:text>
  1456 </xsl:text>
  1457     <xsl:text>var pending_widget_animates = [];
  1457     <xsl:text>var pending_widget_animates = [];
  1458 </xsl:text>
  1458 </xsl:text>
  1459     <xsl:text>
  1459     <xsl:text>
  1460 </xsl:text>
  1460 </xsl:text>
       
  1461     <xsl:text>function _hide(elt, placeholder){
       
  1462 </xsl:text>
       
  1463     <xsl:text>    if(elt.parentNode != null)
       
  1464 </xsl:text>
       
  1465     <xsl:text>        placeholder.parentNode.removeChild(elt);
       
  1466 </xsl:text>
       
  1467     <xsl:text>}
       
  1468 </xsl:text>
       
  1469     <xsl:text>function _show(elt, placeholder){
       
  1470 </xsl:text>
       
  1471     <xsl:text>    placeholder.parentNode.insertBefore(elt, placeholder);
       
  1472 </xsl:text>
       
  1473     <xsl:text>}
       
  1474 </xsl:text>
       
  1475     <xsl:text>
       
  1476 </xsl:text>
       
  1477     <xsl:text>function set_activation_state(eltsub, state){
       
  1478 </xsl:text>
       
  1479     <xsl:text>    if(eltsub.active_elt_placeholder == undefined){
       
  1480 </xsl:text>
       
  1481     <xsl:text>        eltsub.active_elt_placeholder = document.createComment("");
       
  1482 </xsl:text>
       
  1483     <xsl:text>        eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt);
       
  1484 </xsl:text>
       
  1485     <xsl:text>        eltsub.inactive_elt_placeholder = document.createComment("");
       
  1486 </xsl:text>
       
  1487     <xsl:text>        eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt);
       
  1488 </xsl:text>
       
  1489     <xsl:text>    }
       
  1490 </xsl:text>
       
  1491     <xsl:text>    (state?_show:_hide)(eltsub.active_elt, eltsub.active_elt_placeholder);
       
  1492 </xsl:text>
       
  1493     <xsl:text>    ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder);
       
  1494 </xsl:text>
       
  1495     <xsl:text>}
       
  1496 </xsl:text>
       
  1497     <xsl:text>
       
  1498 </xsl:text>
       
  1499     <xsl:text>function activate_activable(eltsub) {
       
  1500 </xsl:text>
       
  1501     <xsl:text>    set_activation_state(eltsub, true);
       
  1502 </xsl:text>
       
  1503     <xsl:text>}
       
  1504 </xsl:text>
       
  1505     <xsl:text>
       
  1506 </xsl:text>
       
  1507     <xsl:text>function inactivate_activable(eltsub) {
       
  1508 </xsl:text>
       
  1509     <xsl:text>    set_activation_state(eltsub, false);
       
  1510 </xsl:text>
       
  1511     <xsl:text>}
       
  1512 </xsl:text>
       
  1513     <xsl:text>
       
  1514 </xsl:text>
  1461     <xsl:text>class Widget {
  1515     <xsl:text>class Widget {
  1462 </xsl:text>
  1516 </xsl:text>
  1463     <xsl:text>    offset = 0;
  1517     <xsl:text>    offset = 0;
  1464 </xsl:text>
  1518 </xsl:text>
  1465     <xsl:text>    frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
  1519     <xsl:text>    frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
  1948 </xsl:text>
  2002 </xsl:text>
  1949     <xsl:text>            requestHMIAnimation();
  2003     <xsl:text>            requestHMIAnimation();
  1950 </xsl:text>
  2004 </xsl:text>
  1951     <xsl:text>        }
  2005     <xsl:text>        }
  1952 </xsl:text>
  2006 </xsl:text>
  1953     <xsl:text>
  2007     <xsl:text>    }
  1954 </xsl:text>
  2008 </xsl:text>
  1955     <xsl:text>    }
  2009     <xsl:text>
  1956 </xsl:text>
  2010 </xsl:text>
  1957     <xsl:text>
  2011     <xsl:text>    set_activation_state(state){
  1958 </xsl:text>
  2012 </xsl:text>
  1959     <xsl:text>    activate_activable(eltsub) {
  2013     <xsl:text>        set_activation_state(this.activable_sub, state);
  1960 </xsl:text>
       
  1961     <xsl:text>        eltsub.inactive.style.display = "none";
       
  1962 </xsl:text>
       
  1963     <xsl:text>        eltsub.active.style.display = "";
       
  1964 </xsl:text>
       
  1965     <xsl:text>    }
       
  1966 </xsl:text>
       
  1967     <xsl:text>
       
  1968 </xsl:text>
       
  1969     <xsl:text>    inactivate_activable(eltsub) {
       
  1970 </xsl:text>
       
  1971     <xsl:text>        eltsub.active.style.display = "none";
       
  1972 </xsl:text>
       
  1973     <xsl:text>        eltsub.inactive.style.display = "";
       
  1974 </xsl:text>
  2014 </xsl:text>
  1975     <xsl:text>    }
  2015     <xsl:text>    }
  1976 </xsl:text>
  2016 </xsl:text>
  1977     <xsl:text>}
  2017     <xsl:text>}
  1978 </xsl:text>
  2018 </xsl:text>
  2086 </xsl:text>
  2126 </xsl:text>
  2087                 </xsl:when>
  2127                 </xsl:when>
  2088                 <xsl:otherwise>
  2128                 <xsl:otherwise>
  2089                   <xsl:text>        "</xsl:text>
  2129                   <xsl:text>        "</xsl:text>
  2090                   <xsl:value-of select="$subname"/>
  2130                   <xsl:value-of select="$subname"/>
  2091                   <xsl:text>": id("</xsl:text>
  2131                   <xsl:text>_elt": id("</xsl:text>
  2092                   <xsl:value-of select="$subelt/@id"/>
  2132                   <xsl:value-of select="$subelt/@id"/>
  2093                   <xsl:text>")</xsl:text>
  2133                   <xsl:text>")</xsl:text>
  2094                   <xsl:if test="position()!=last()">
  2134                   <xsl:if test="position()!=last()">
  2095                     <xsl:text>,</xsl:text>
  2135                     <xsl:text>,</xsl:text>
  2096                   </xsl:if>
  2136                   </xsl:if>
  2603     <xsl:text>    }
  2643     <xsl:text>    }
  2604 </xsl:text>
  2644 </xsl:text>
  2605     <xsl:apply-templates mode="actions" select="$fsm"/>
  2645     <xsl:apply-templates mode="actions" select="$fsm"/>
  2606     <xsl:text>    animate(){
  2646     <xsl:text>    animate(){
  2607 </xsl:text>
  2647 </xsl:text>
  2608     <xsl:text>        if (this.active_elt &amp;&amp; this.inactive_elt) {
  2648     <xsl:text>        this.set_activation_state(this.display == "active");
  2609 </xsl:text>
       
  2610     <xsl:for-each select="str:split('active inactive')">
       
  2611       <xsl:text>            if(this.display == "</xsl:text>
       
  2612       <xsl:value-of select="."/>
       
  2613       <xsl:text>")
       
  2614 </xsl:text>
       
  2615       <xsl:text>                this.</xsl:text>
       
  2616       <xsl:value-of select="."/>
       
  2617       <xsl:text>_elt.style.display = "";
       
  2618 </xsl:text>
       
  2619       <xsl:text>            else
       
  2620 </xsl:text>
       
  2621       <xsl:text>                this.</xsl:text>
       
  2622       <xsl:value-of select="."/>
       
  2623       <xsl:text>_elt.style.display = "none";
       
  2624 </xsl:text>
       
  2625     </xsl:for-each>
       
  2626     <xsl:text>        }
       
  2627 </xsl:text>
  2649 </xsl:text>
  2628     <xsl:text>    }
  2650     <xsl:text>    }
  2629 </xsl:text>
  2651 </xsl:text>
  2630     <xsl:text>    init() {
  2652     <xsl:text>    init() {
  2631 </xsl:text>
  2653 </xsl:text>
  2632     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
  2654     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
  2633 </xsl:text>
  2655 </xsl:text>
  2634     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
  2656     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
       
  2657 </xsl:text>
       
  2658     <xsl:text>        this.set_activation_state(undefined);
  2635 </xsl:text>
  2659 </xsl:text>
  2636     <xsl:text>    }
  2660     <xsl:text>    }
  2637 </xsl:text>
  2661 </xsl:text>
  2638   </xsl:template>
  2662   </xsl:template>
  2639   <xsl:template match="widget[@type='Button']" mode="widget_class">
  2663   <xsl:template match="widget[@type='Button']" mode="widget_class">
  2650     <xsl:text>}
  2674     <xsl:text>}
  2651 </xsl:text>
  2675 </xsl:text>
  2652   </xsl:template>
  2676   </xsl:template>
  2653   <xsl:template match="widget[@type='Button']" mode="widget_defs">
  2677   <xsl:template match="widget[@type='Button']" mode="widget_defs">
  2654     <xsl:param name="hmi_element"/>
  2678     <xsl:param name="hmi_element"/>
       
  2679     <xsl:text>    activable_sub:{
       
  2680 </xsl:text>
  2655     <xsl:call-template name="defs_by_labels">
  2681     <xsl:call-template name="defs_by_labels">
  2656       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2682       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2657       <xsl:with-param name="labels">
  2683       <xsl:with-param name="labels">
  2658         <xsl:text>active inactive</xsl:text>
  2684         <xsl:text>/active /inactive</xsl:text>
  2659       </xsl:with-param>
  2685       </xsl:with-param>
  2660       <xsl:with-param name="mandatory" select="'no'"/>
       
  2661     </xsl:call-template>
  2686     </xsl:call-template>
       
  2687     <xsl:text>    }
       
  2688 </xsl:text>
  2662   </xsl:template>
  2689   </xsl:template>
  2663   <xsl:template match="widget[@type='PushButton']" mode="widget_class">
  2690   <xsl:template match="widget[@type='PushButton']" mode="widget_class">
  2664     <xsl:text>class </xsl:text>
  2691     <xsl:text>class </xsl:text>
  2665     <xsl:text>PushButtonWidget</xsl:text>
  2692     <xsl:text>PushButtonWidget</xsl:text>
  2666     <xsl:text> extends Widget{
  2693     <xsl:text> extends Widget{
  2674     <xsl:text>}
  2701     <xsl:text>}
  2675 </xsl:text>
  2702 </xsl:text>
  2676   </xsl:template>
  2703   </xsl:template>
  2677   <xsl:template match="widget[@type='PushButton']" mode="widget_defs">
  2704   <xsl:template match="widget[@type='PushButton']" mode="widget_defs">
  2678     <xsl:param name="hmi_element"/>
  2705     <xsl:param name="hmi_element"/>
       
  2706     <xsl:text>    activable_sub:{
       
  2707 </xsl:text>
  2679     <xsl:call-template name="defs_by_labels">
  2708     <xsl:call-template name="defs_by_labels">
  2680       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2709       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  2681       <xsl:with-param name="labels">
  2710       <xsl:with-param name="labels">
  2682         <xsl:text>active inactive</xsl:text>
  2711         <xsl:text>/active /inactive</xsl:text>
  2683       </xsl:with-param>
  2712       </xsl:with-param>
  2684       <xsl:with-param name="mandatory" select="'no'"/>
       
  2685     </xsl:call-template>
  2713     </xsl:call-template>
       
  2714     <xsl:text>    }
       
  2715 </xsl:text>
  2686   </xsl:template>
  2716   </xsl:template>
  2687   <xsl:template match="widget[@type='CircularBar']" mode="widget_desc">
  2717   <xsl:template match="widget[@type='CircularBar']" mode="widget_desc">
  2688     <type>
  2718     <type>
  2689       <xsl:value-of select="@type"/>
  2719       <xsl:value-of select="@type"/>
  2690     </type>
  2720     </type>
  5872 </xsl:text>
  5902 </xsl:text>
  5873     <xsl:text>         if(this.Shift_sub &amp;&amp; this.shift != this._shift){
  5903     <xsl:text>         if(this.Shift_sub &amp;&amp; this.shift != this._shift){
  5874 </xsl:text>
  5904 </xsl:text>
  5875     <xsl:text>             this._shift = this.shift;
  5905     <xsl:text>             this._shift = this.shift;
  5876 </xsl:text>
  5906 </xsl:text>
  5877     <xsl:text>             (this.shift?this.activate_activable:this.inactivate_activable)(this.Shift_sub);
  5907     <xsl:text>             set_activation_state(this.Shift_sub, this.shift);
  5878 </xsl:text>
  5908 </xsl:text>
  5879     <xsl:text>         }
  5909     <xsl:text>         }
  5880 </xsl:text>
  5910 </xsl:text>
  5881     <xsl:text>         if(this.CapsLock_sub &amp;&amp; this.caps != this._caps){
  5911     <xsl:text>         if(this.CapsLock_sub &amp;&amp; this.caps != this._caps){
  5882 </xsl:text>
  5912 </xsl:text>
  5883     <xsl:text>             this._caps = this.caps;
  5913     <xsl:text>             this._caps = this.caps;
  5884 </xsl:text>
  5914 </xsl:text>
  5885     <xsl:text>             (this.caps?this.activate_activable:this.inactivate_activable)(this.CapsLock_sub);
  5915     <xsl:text>             set_activation_state(this.CapsLock_sub, this.caps);
  5886 </xsl:text>
  5916 </xsl:text>
  5887     <xsl:text>         }
  5917     <xsl:text>         }
  5888 </xsl:text>
  5918 </xsl:text>
  5889     <xsl:text>     }
  5919     <xsl:text>     }
  5890 </xsl:text>
  5920 </xsl:text>
  7657 </xsl:text>
  7687 </xsl:text>
  7658     <xsl:text>            } else {
  7688     <xsl:text>            } else {
  7659 </xsl:text>
  7689 </xsl:text>
  7660     <xsl:text>                if(choice.parent != undefined){
  7690     <xsl:text>                if(choice.parent != undefined){
  7661 </xsl:text>
  7691 </xsl:text>
  7662     <xsl:text>                    choice.parent.appendChild(choice.elt);
  7692     <xsl:text>                    choice.parent.insertBefore(choice.elt,choice.sibling);
  7663 </xsl:text>
  7693 </xsl:text>
  7664     <xsl:text>                    choice.parent = undefined;
  7694     <xsl:text>                    choice.parent = undefined;
  7665 </xsl:text>
  7695 </xsl:text>
  7666     <xsl:text>                }
  7696     <xsl:text>                }
  7667 </xsl:text>
  7697 </xsl:text>
  7680 </xsl:text>
  7710 </xsl:text>
  7681     <xsl:variable name="regex" select="'^(&quot;[^&quot;].*&quot;|\-?[0-9]+|false|true)(#.*)?$'"/>
  7711     <xsl:variable name="regex" select="'^(&quot;[^&quot;].*&quot;|\-?[0-9]+|false|true)(#.*)?$'"/>
  7682     <xsl:variable name="subelts" select="$result_widgets[@id = $hmi_element/@id]//*"/>
  7712     <xsl:variable name="subelts" select="$result_widgets[@id = $hmi_element/@id]//*"/>
  7683     <xsl:variable name="subwidgets" select="$subelts//*[@id = $hmi_widgets/@id]"/>
  7713     <xsl:variable name="subwidgets" select="$subelts//*[@id = $hmi_widgets/@id]"/>
  7684     <xsl:variable name="accepted" select="$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]"/>
  7714     <xsl:variable name="accepted" select="$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]"/>
  7685     <xsl:for-each select="$accepted[regexp:test(@inkscape:label,$regex)]">
  7715     <xsl:variable name="choices" select="$accepted[regexp:test(@inkscape:label,$regex)]"/>
       
  7716     <xsl:for-each select="$choices">
  7686       <xsl:variable name="literal" select="regexp:match(@inkscape:label,$regex)[2]"/>
  7717       <xsl:variable name="literal" select="regexp:match(@inkscape:label,$regex)[2]"/>
       
  7718       <xsl:variable name="sibling" select="following-sibling::*[not(@id = $choices/@id)][position()=1]"/>
  7687       <xsl:text>        {
  7719       <xsl:text>        {
  7688 </xsl:text>
  7720 </xsl:text>
  7689       <xsl:text>            elt:id("</xsl:text>
  7721       <xsl:text>            elt:id("</xsl:text>
  7690       <xsl:value-of select="@id"/>
  7722       <xsl:value-of select="@id"/>
  7691       <xsl:text>"),
  7723       <xsl:text>"),
  7692 </xsl:text>
  7724 </xsl:text>
  7693       <xsl:text>            parent:undefined,
  7725       <xsl:text>            parent:undefined,
  7694 </xsl:text>
  7726 </xsl:text>
       
  7727       <xsl:choose>
       
  7728         <xsl:when test="count($sibling)=0">
       
  7729           <xsl:text>            sibling:null,
       
  7730 </xsl:text>
       
  7731         </xsl:when>
       
  7732         <xsl:otherwise>
       
  7733           <xsl:text>            sibling:id("</xsl:text>
       
  7734           <xsl:value-of select="$sibling/@id"/>
       
  7735           <xsl:text>"),
       
  7736 </xsl:text>
       
  7737         </xsl:otherwise>
       
  7738       </xsl:choose>
  7695       <xsl:text>            value:</xsl:text>
  7739       <xsl:text>            value:</xsl:text>
  7696       <xsl:value-of select="$literal"/>
  7740       <xsl:value-of select="$literal"/>
  7697       <xsl:text>
  7741       <xsl:text>
  7698 </xsl:text>
  7742 </xsl:text>
  7699       <xsl:text>        }</xsl:text>
  7743       <xsl:text>        }</xsl:text>
  7849 </xsl:text>
  7893 </xsl:text>
  7850     <xsl:text>    }
  7894     <xsl:text>    }
  7851 </xsl:text>
  7895 </xsl:text>
  7852     <xsl:text>
  7896     <xsl:text>
  7853 </xsl:text>
  7897 </xsl:text>
  7854     <xsl:text>    activate(val) {
       
  7855 </xsl:text>
       
  7856     <xsl:text>        let [active, inactive] = val ? ["","none"] : ["none", ""];
       
  7857 </xsl:text>
       
  7858     <xsl:text>        if (this.active_elt)
       
  7859 </xsl:text>
       
  7860     <xsl:text>            this.active_elt.style.display = active;
       
  7861 </xsl:text>
       
  7862     <xsl:text>        if (this.inactive_elt)
       
  7863 </xsl:text>
       
  7864     <xsl:text>            this.inactive_elt.style.display = inactive;
       
  7865 </xsl:text>
       
  7866     <xsl:text>    }
       
  7867 </xsl:text>
       
  7868     <xsl:text>
       
  7869 </xsl:text>
       
  7870     <xsl:text>    animate(){
  7898     <xsl:text>    animate(){
  7871 </xsl:text>
  7899 </xsl:text>
  7872     <xsl:text>        // redraw toggle button on screen refresh
  7900     <xsl:text>        // redraw toggle button on screen refresh
  7873 </xsl:text>
  7901 </xsl:text>
  7874     <xsl:text>        this.activate(this.state);
  7902     <xsl:text>        this.set_activation_state(this.state);
  7875 </xsl:text>
  7903 </xsl:text>
  7876     <xsl:text>    }
  7904     <xsl:text>    }
  7877 </xsl:text>
  7905 </xsl:text>
  7878     <xsl:text>
  7906     <xsl:text>
  7879 </xsl:text>
  7907 </xsl:text>
  7880     <xsl:text>    init() {
  7908     <xsl:text>    init() {
  7881 </xsl:text>
  7909 </xsl:text>
  7882     <xsl:text>        this.activate(false);
       
  7883 </xsl:text>
       
  7884     <xsl:text>        this.element.onclick = (evt) =&gt; this.on_click(evt);
  7910     <xsl:text>        this.element.onclick = (evt) =&gt; this.on_click(evt);
       
  7911 </xsl:text>
       
  7912     <xsl:text>        this.set_activation_state(undefined);
  7885 </xsl:text>
  7913 </xsl:text>
  7886     <xsl:text>    }
  7914     <xsl:text>    }
  7887 </xsl:text>
  7915 </xsl:text>
  7888     <xsl:text>}
  7916     <xsl:text>}
  7889 </xsl:text>
  7917 </xsl:text>
  7890   </xsl:template>
  7918   </xsl:template>
  7891   <xsl:template match="widget[@type='ToggleButton']" mode="widget_defs">
  7919   <xsl:template match="widget[@type='ToggleButton']" mode="widget_defs">
  7892     <xsl:param name="hmi_element"/>
  7920     <xsl:param name="hmi_element"/>
       
  7921     <xsl:text>    activable_sub:{
       
  7922 </xsl:text>
  7893     <xsl:call-template name="defs_by_labels">
  7923     <xsl:call-template name="defs_by_labels">
  7894       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  7924       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  7895       <xsl:with-param name="labels">
  7925       <xsl:with-param name="labels">
  7896         <xsl:text>active inactive</xsl:text>
  7926         <xsl:text>/active /inactive</xsl:text>
  7897       </xsl:with-param>
  7927       </xsl:with-param>
  7898       <xsl:with-param name="mandatory" select="'no'"/>
       
  7899     </xsl:call-template>
  7928     </xsl:call-template>
       
  7929     <xsl:text>    }
       
  7930 </xsl:text>
  7900   </xsl:template>
  7931   </xsl:template>
  7901   <xsl:template match="widget[@type='XYGraph']" mode="widget_desc">
  7932   <xsl:template match="widget[@type='XYGraph']" mode="widget_desc">
  7902     <type>
  7933     <type>
  7903       <xsl:value-of select="@type"/>
  7934       <xsl:value-of select="@type"/>
  7904     </type>
  7935     </type>