svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2893 d57a12b8f5db
parent 2892 27dd409fba1d
child 2894 4cf9ad35e6d0
equal deleted inserted replaced
2892:27dd409fba1d 2893:d57a12b8f5db
    72       <xsl:with-param name="parentpath">
    72       <xsl:with-param name="parentpath">
    73         <xsl:value-of select="$parentpath"/>
    73         <xsl:value-of select="$parentpath"/>
    74       </xsl:with-param>
    74       </xsl:with-param>
    75     </xsl:apply-templates>
    75     </xsl:apply-templates>
    76   </xsl:template>
    76   </xsl:template>
       
    77   <func:function name="func:get_hmi_tree_elt">
       
    78     <xsl:param name="path"/>
       
    79     <xsl:param name="root" select="$hmitree"/>
       
    80     <xsl:message>
       
    81       <xsl:text>get_hmi_tree_elt </xsl:text>
       
    82       <xsl:value-of select="$path"/>
       
    83     </xsl:message>
       
    84     <xsl:if test="not(starts-with($path, '/'))">
       
    85       <xsl:message terminate="yes">
       
    86         <xsl:text>Given path "</xsl:text>
       
    87         <xsl:value-of select="$path"/>
       
    88         <xsl:text>" should start with a "/"</xsl:text>
       
    89       </xsl:message>
       
    90     </xsl:if>
       
    91     <xsl:variable name="stripped" select="substring($path, 2)"/>
       
    92     <xsl:variable name="token">
       
    93       <xsl:choose>
       
    94         <xsl:when test="contains($stripped, '/')">
       
    95           <xsl:value-of select="substring-before($stripped, '/')"/>
       
    96         </xsl:when>
       
    97         <xsl:otherwise>
       
    98           <xsl:value-of select="$stripped"/>
       
    99         </xsl:otherwise>
       
   100       </xsl:choose>
       
   101     </xsl:variable>
       
   102     <xsl:choose>
       
   103       <xsl:when test="string-length($token) = 0">
       
   104         <func:result select="$root"/>
       
   105       </xsl:when>
       
   106       <xsl:otherwise>
       
   107         <xsl:variable name="rest" select="substring-after($stripped, $token)"/>
       
   108         <xsl:variable name="match" select="$root/*[@name = $token]"/>
       
   109         <xsl:choose>
       
   110           <xsl:when test="string-length($rest) &gt; 0">
       
   111             <func:result select="func:get_hmi_tree_el($rest, $match)"/>
       
   112           </xsl:when>
       
   113           <xsl:otherwise>
       
   114             <func:result select="$match"/>
       
   115           </xsl:otherwise>
       
   116         </xsl:choose>
       
   117       </xsl:otherwise>
       
   118     </xsl:choose>
       
   119   </func:function>
    77   <xsl:template mode="parselabel" match="*">
   120   <xsl:template mode="parselabel" match="*">
    78     <xsl:variable name="label" select="@inkscape:label"/>
   121     <xsl:variable name="label" select="@inkscape:label"/>
    79     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
   122     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    80     <xsl:variable name="_args" select="substring-before($description,'@')"/>
   123     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    81     <xsl:variable name="args">
   124     <xsl:variable name="args">
   598           </xsl:message>
   641           </xsl:message>
   599         </xsl:when>
   642         </xsl:when>
   600         <xsl:otherwise>
   643         <xsl:otherwise>
   601           <xsl:text>        </xsl:text>
   644           <xsl:text>        </xsl:text>
   602           <xsl:value-of select="@index"/>
   645           <xsl:value-of select="@index"/>
   603           <xsl:text> /*</xsl:text>
   646           <xsl:text> /* </xsl:text>
   604           <xsl:value-of select="$widget/path"/>
   647           <xsl:value-of select="@value"/>
   605           <xsl:text>*/ </xsl:text>
   648           <xsl:text> */ </xsl:text>
   606           <xsl:if test="position()!=last()">
   649           <xsl:if test="position()!=last()">
   607             <xsl:text>,</xsl:text>
   650             <xsl:text>,</xsl:text>
   608           </xsl:if>
   651           </xsl:if>
   609           <xsl:text>
   652           <xsl:text>
   610 </xsl:text>
   653 </xsl:text>
   709 </xsl:text>
   752 </xsl:text>
   710     <xsl:text>                    // do something
   753     <xsl:text>                    // do something
   711 </xsl:text>
   754 </xsl:text>
   712     <xsl:text>    },
   755     <xsl:text>    },
   713 </xsl:text>
   756 </xsl:text>
       
   757     <xsl:text>    index_pool: [
       
   758 </xsl:text>
       
   759     <xsl:text>    ],
       
   760 </xsl:text>
       
   761     <xsl:text>    buttons: [
       
   762 </xsl:text>
       
   763     <xsl:variable name="class" select="arg[1]/@value"/>
       
   764     <xsl:variable name="prefix" select="concat($class,':')"/>
       
   765     <xsl:variable name="buttons_regex" select="concat('^',$prefix,'[+\-][0-9]+')"/>
       
   766     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label, $buttons_regex)]">
       
   767       <xsl:text>        ["</xsl:text>
       
   768       <xsl:value-of select="substring-after(@inkscape:label, concat(arg[1]/@value, ':'))"/>
       
   769       <xsl:text>", id("</xsl:text>
       
   770       <xsl:value-of select="@id"/>
       
   771       <xsl:text>")]</xsl:text>
       
   772       <xsl:if test="position()!=last()">
       
   773         <xsl:text>,</xsl:text>
       
   774       </xsl:if>
       
   775       <xsl:text>
       
   776 </xsl:text>
       
   777     </xsl:for-each>
       
   778     <xsl:text>    ],
       
   779 </xsl:text>
   714     <xsl:text>    init: function() {
   780     <xsl:text>    init: function() {
   715 </xsl:text>
   781 </xsl:text>
   716     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
   782     <xsl:text>        /* TODO elt.setAttribute("onclick", "hmi_widgets['</xsl:text>
   717       <xsl:text>        id("</xsl:text>
   783     <xsl:value-of select="$hmi_element/@id"/>
   718       <xsl:value-of select="@id"/>
   784     <xsl:text>'].on_click(evt)");*/
   719       <xsl:text>").addEventListener(
   785 </xsl:text>
   720 </xsl:text>
       
   721       <xsl:text>            "click", 
       
   722 </xsl:text>
       
   723       <xsl:text>            evt =&gt; {let new_val = "</xsl:text>
       
   724       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
       
   725       <xsl:text>");
       
   726 </xsl:text>
       
   727       <xsl:text>                    // do something with new_val
       
   728 </xsl:text>
       
   729       <xsl:text>                   });
       
   730 </xsl:text>
       
   731     </xsl:for-each>
       
   732     <xsl:text>    },
   786     <xsl:text>    },
   733 </xsl:text>
   787 </xsl:text>
   734     <xsl:text>    widgets: [
   788     <xsl:text>    items: [
   735 </xsl:text>
   789 </xsl:text>
   736     <xsl:variable name="labels_regex" select="concat('^',arg[1]/@value,':[0-9]+')"/>
   790     <xsl:variable name="base_path" select="path/@value"/>
   737     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label, $labels_regex)]">
   791     <xsl:variable name="items_regex" select="concat('^',$prefix,'[0-9]+')"/>
       
   792     <xsl:variable name="unordered_items" select="$hmi_element//*[regexp:test(@inkscape:label, $items_regex)]"/>
       
   793     <xsl:for-each select="$unordered_items">
       
   794       <xsl:variable name="elt_label" select="concat($prefix, string(position()))"/>
       
   795       <xsl:variable name="elt" select="$unordered_items[@inkscape:label = $elt_label]"/>
       
   796       <xsl:text>  /* </xsl:text>
       
   797       <xsl:apply-templates mode="testtree" select="func:get_hmi_tree_elt($base_path)"/>
       
   798       <xsl:text> */
       
   799 </xsl:text>
   738       <xsl:text>      [ /* </xsl:text>
   800       <xsl:text>      [ /* </xsl:text>
   739       <xsl:value-of select="@inkscape:label"/>
   801       <xsl:value-of select="$elt_label"/>
   740       <xsl:text> */
   802       <xsl:text> */
   741 </xsl:text>
   803 </xsl:text>
   742       <xsl:variable name="elt" select="."/>
   804       <xsl:if test="count($elt)=0">
   743       <xsl:for-each select="func:refered_elements(.)[@id = $hmi_elements/@id][not(@id = $elt/@id)]">
   805         <xsl:message terminate="yes">
       
   806           <xsl:text>Missing item labeled </xsl:text>
       
   807           <xsl:value-of select="$elt_label"/>
       
   808           <xsl:text> in ForEach widget </xsl:text>
       
   809           <xsl:value-of select="$hmi_element/@id"/>
       
   810         </xsl:message>
       
   811       </xsl:if>
       
   812       <xsl:for-each select="func:refered_elements($elt)[@id = $hmi_elements/@id][not(@id = $elt/@id)]">
   744         <xsl:text>        hmi_widgets["</xsl:text>
   813         <xsl:text>        hmi_widgets["</xsl:text>
   745         <xsl:value-of select="@id"/>
   814         <xsl:value-of select="@id"/>
   746         <xsl:text>"]</xsl:text>
   815         <xsl:text>"]</xsl:text>
   747         <xsl:if test="position()!=last()">
   816         <xsl:if test="position()!=last()">
   748           <xsl:text>,</xsl:text>
   817           <xsl:text>,</xsl:text>
   761 </xsl:text>
   830 </xsl:text>
   762   </xsl:template>
   831   </xsl:template>
   763   <xsl:template mode="widget_subscribe" match="widget[@type='ForEach']">
   832   <xsl:template mode="widget_subscribe" match="widget[@type='ForEach']">
   764     <xsl:text>    sub: function(off){
   833     <xsl:text>    sub: function(off){
   765 </xsl:text>
   834 </xsl:text>
   766     <xsl:text>        subscribe.call(this,off)
   835     <xsl:text>        subscribe.call(this,off);
   767 </xsl:text>
   836 </xsl:text>
   768     <xsl:text>    },
   837     <xsl:text>    },
   769 </xsl:text>
   838 </xsl:text>
   770     <xsl:text>    unsub: function(){
   839     <xsl:text>    unsub: function(){
   771 </xsl:text>
   840 </xsl:text>
   772     <xsl:text>        unsubscribe.call(this)
   841     <xsl:text>        unsubscribe.call(this);
   773 </xsl:text>
   842 </xsl:text>
   774     <xsl:text>    },
   843     <xsl:text>    },
   775 </xsl:text>
   844 </xsl:text>
   776   </xsl:template>
   845   </xsl:template>
   777   <xsl:template mode="widget_defs" match="widget[@type='Input']">
   846   <xsl:template mode="widget_defs" match="widget[@type='Input']">