svghmi/gen_dnd_widget_svg.xslt
branchwxPython4
changeset 3615 5c983ead9db0
parent 3582 7dcd0de97e6f
child 3630 921f620577e8
equal deleted inserted replaced
3614:0e0252339e83 3615:5c983ead9db0
     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:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn">
     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:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn">
     3   <xsl:output method="xml"/>
     3   <xsl:output method="xml"/>
     4   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     4   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     5   <xsl:variable name="widgetparams" select="ns:GetWidgetParams()"/>
     5   <xsl:variable name="widgetparams" select="ns:GetWidgetParams()"/>
     6   <xsl:variable name="indexed_hmitree" select="/.."/>
     6   <xsl:variable name="indexed_hmitree" select="/.."/>
     7   <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([-.\d,]*)$'"/>
     7   <xsl:variable name="pathregex" select="'^(\w+=)?([^,=]+)([-.\d,]*)$'"/>
     8   <xsl:variable name="newline">
     8   <xsl:variable name="newline">
     9     <xsl:text>
     9     <xsl:text>
    10 </xsl:text>
    10 </xsl:text>
    11   </xsl:variable>
    11   </xsl:variable>
    12   <xsl:variable name="twonewlines" select="concat($newline,$newline)"/>
    12   <xsl:variable name="twonewlines" select="concat($newline,$newline)"/>
    13   <xsl:template mode="parselabel" match="*">
    13   <xsl:template mode="parselabel" match="*">
    14     <xsl:variable name="part" select="@inkscape:label"/>
    14     <xsl:variable name="label" select="@inkscape:label"/>
    15     <xsl:variable name="desc" select="svg:desc"/>
    15     <xsl:variable name="desc" select="svg:desc"/>
    16     <xsl:variable name="len" select="string-length($part)"/>
    16     <xsl:variable name="len" select="string-length($label)"/>
    17     <xsl:variable name="has_continuation" select="substring($part,$len,1)='\'"/>
    17     <xsl:variable name="has_continuation" select="substring($label,$len,1)='\'"/>
    18     <xsl:variable name="label">
    18     <xsl:variable name="full_decl">
    19       <xsl:choose>
    19       <xsl:choose>
    20         <xsl:when test="$has_continuation">
    20         <xsl:when test="$has_continuation">
    21           <xsl:variable name="_continuation" select="substring-before($desc, $twonewlines)"/>
    21           <xsl:variable name="_continuation" select="substring-before($desc, $twonewlines)"/>
    22           <xsl:variable name="continuation">
    22           <xsl:variable name="continuation">
    23             <xsl:choose>
    23             <xsl:choose>
    27               <xsl:otherwise>
    27               <xsl:otherwise>
    28                 <xsl:value-of select="$desc"/>
    28                 <xsl:value-of select="$desc"/>
    29               </xsl:otherwise>
    29               </xsl:otherwise>
    30             </xsl:choose>
    30             </xsl:choose>
    31           </xsl:variable>
    31           </xsl:variable>
    32           <xsl:value-of select="concat(substring($part,1,$len - 1),translate($continuation,$newline,''))"/>
    32           <xsl:value-of select="concat(substring($label,1,$len - 1),translate($continuation,$newline,''))"/>
    33         </xsl:when>
    33         </xsl:when>
    34         <xsl:otherwise>
    34         <xsl:otherwise>
    35           <xsl:value-of select="$part"/>
    35           <xsl:value-of select="$label"/>
    36         </xsl:otherwise>
    36         </xsl:otherwise>
    37       </xsl:choose>
    37       </xsl:choose>
    38     </xsl:variable>
    38     </xsl:variable>
    39     <xsl:variable name="id" select="@id"/>
    39     <xsl:variable name="id" select="@id"/>
    40     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    40     <xsl:variable name="declaration" select="substring-after($full_decl,'HMI:')"/>
    41     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    41     <xsl:variable name="_args" select="substring-before($declaration,'@')"/>
    42     <xsl:variable name="args">
    42     <xsl:variable name="args">
    43       <xsl:choose>
    43       <xsl:choose>
    44         <xsl:when test="$_args">
    44         <xsl:when test="$_args">
    45           <xsl:value-of select="$_args"/>
    45           <xsl:value-of select="$_args"/>
    46         </xsl:when>
    46         </xsl:when>
    47         <xsl:otherwise>
    47         <xsl:otherwise>
    48           <xsl:value-of select="$description"/>
    48           <xsl:value-of select="$declaration"/>
    49         </xsl:otherwise>
    49         </xsl:otherwise>
    50       </xsl:choose>
    50       </xsl:choose>
    51     </xsl:variable>
    51     </xsl:variable>
    52     <xsl:variable name="_typefreq" select="substring-before($args,':')"/>
    52     <xsl:variable name="_typefreq" select="substring-before($args,':')"/>
    53     <xsl:variable name="typefreq">
    53     <xsl:variable name="typefreq">
    84           <xsl:if test="not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))">
    84           <xsl:if test="not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))">
    85             <xsl:message terminate="yes">
    85             <xsl:message terminate="yes">
    86               <xsl:text>Widget id:</xsl:text>
    86               <xsl:text>Widget id:</xsl:text>
    87               <xsl:value-of select="$id"/>
    87               <xsl:value-of select="$id"/>
    88               <xsl:text> label:</xsl:text>
    88               <xsl:text> label:</xsl:text>
    89               <xsl:value-of select="$label"/>
    89               <xsl:value-of select="$full_decl"/>
    90               <xsl:text> has wrong syntax of frequency forcing </xsl:text>
    90               <xsl:text> has wrong syntax of frequency forcing </xsl:text>
    91               <xsl:value-of select="$freq"/>
    91               <xsl:value-of select="$freq"/>
    92             </xsl:message>
    92             </xsl:message>
    93           </xsl:if>
    93           </xsl:if>
    94           <xsl:attribute name="freq">
    94           <xsl:attribute name="freq">
    95             <xsl:value-of select="$freq"/>
    95             <xsl:value-of select="$freq"/>
       
    96           </xsl:attribute>
       
    97         </xsl:if>
       
    98         <xsl:variable name="tail" select="substring-after($declaration,'@')"/>
       
    99         <xsl:variable name="taillen" select="string-length($tail)"/>
       
   100         <xsl:variable name="has_enable" select="contains($tail, '#')"/>
       
   101         <xsl:variable name="paths">
       
   102           <xsl:choose>
       
   103             <xsl:when test="$has_enable">
       
   104               <xsl:value-of select="substring-before($tail,'#')"/>
       
   105             </xsl:when>
       
   106             <xsl:otherwise>
       
   107               <xsl:value-of select="$tail"/>
       
   108             </xsl:otherwise>
       
   109           </xsl:choose>
       
   110         </xsl:variable>
       
   111         <xsl:if test="$has_enable">
       
   112           <xsl:variable name="enable_expr" select="substring-after($tail,'#')"/>
       
   113           <xsl:attribute name="enable_expr">
       
   114             <xsl:value-of select="$enable_expr"/>
    96           </xsl:attribute>
   115           </xsl:attribute>
    97         </xsl:if>
   116         </xsl:if>
    98         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   117         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
    99           <arg>
   118           <arg>
   100             <xsl:attribute name="value">
   119             <xsl:attribute name="value">
   101               <xsl:value-of select="."/>
   120               <xsl:value-of select="."/>
   102             </xsl:attribute>
   121             </xsl:attribute>
   103           </arg>
   122           </arg>
   104         </xsl:for-each>
   123         </xsl:for-each>
   105         <xsl:variable name="paths" select="substring-after($description,'@')"/>
       
   106         <xsl:for-each select="str:split($paths, '@')">
   124         <xsl:for-each select="str:split($paths, '@')">
   107           <xsl:if test="string-length(.) &gt; 0">
   125           <xsl:if test="string-length(.) &gt; 0">
   108             <path>
   126             <path>
   109               <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/>
   127               <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/>
       
   128               <xsl:variable name="pathassign" select="substring-before($path_match[2],'=')"/>
   110               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
   129               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
   111               <xsl:variable name="path" select="$path_match[2]"/>
   130               <xsl:variable name="path" select="$path_match[3]"/>
   112               <xsl:variable name="path_accepts" select="$path_match[3]"/>
       
   113               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
   131               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
       
   132               <xsl:if test="not($path)">
       
   133                 <xsl:message terminate="yes">
       
   134                   <xsl:text>Widget id:</xsl:text>
       
   135                   <xsl:value-of select="$id"/>
       
   136                   <xsl:text> label:</xsl:text>
       
   137                   <xsl:value-of select="$full_decl"/>
       
   138                   <xsl:text> has wrong syntax</xsl:text>
       
   139                 </xsl:message>
       
   140               </xsl:if>
   114               <xsl:attribute name="value">
   141               <xsl:attribute name="value">
   115                 <xsl:value-of select="$path"/>
   142                 <xsl:value-of select="$path"/>
   116               </xsl:attribute>
   143               </xsl:attribute>
   117               <xsl:if test="string-length($path_accepts)">
   144               <xsl:if test="$pathassign">
   118                 <xsl:attribute name="accepts">
   145                 <xsl:attribute name="assign">
   119                   <xsl:value-of select="$path_accepts"/>
   146                   <xsl:value-of select="$pathassign"/>
   120                 </xsl:attribute>
   147                 </xsl:attribute>
   121               </xsl:if>
   148               </xsl:if>
   122               <xsl:choose>
   149               <xsl:choose>
   123                 <xsl:when test="$pathminmaxcount = 2">
   150                 <xsl:when test="$pathminmaxcount = 2">
   124                   <xsl:attribute name="min">
   151                   <xsl:attribute name="min">
   131                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
   158                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
   132                   <xsl:message terminate="yes">
   159                   <xsl:message terminate="yes">
   133                     <xsl:text>Widget id:</xsl:text>
   160                     <xsl:text>Widget id:</xsl:text>
   134                     <xsl:value-of select="$id"/>
   161                     <xsl:value-of select="$id"/>
   135                     <xsl:text> label:</xsl:text>
   162                     <xsl:text> label:</xsl:text>
   136                     <xsl:value-of select="$label"/>
   163                     <xsl:value-of select="$full_decl"/>
   137                     <xsl:text> has wrong syntax of path section </xsl:text>
   164                     <xsl:text> has wrong syntax of path section </xsl:text>
   138                     <xsl:value-of select="$pathminmax"/>
   165                     <xsl:value-of select="$pathminmax"/>
   139                   </xsl:message>
   166                   </xsl:message>
   140                 </xsl:when>
   167                 </xsl:when>
   141               </xsl:choose>
   168               </xsl:choose>
   157                     <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
   184                     <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
   158                       <xsl:message terminate="yes">
   185                       <xsl:message terminate="yes">
   159                         <xsl:text>Widget id:</xsl:text>
   186                         <xsl:text>Widget id:</xsl:text>
   160                         <xsl:value-of select="$id"/>
   187                         <xsl:value-of select="$id"/>
   161                         <xsl:text> label:</xsl:text>
   188                         <xsl:text> label:</xsl:text>
   162                         <xsl:value-of select="$label"/>
   189                         <xsl:value-of select="$full_decl"/>
   163                         <xsl:text> path section </xsl:text>
   190                         <xsl:text> path section </xsl:text>
   164                         <xsl:value-of select="$pathminmax"/>
   191                         <xsl:value-of select="$pathminmax"/>
   165                         <xsl:text> use min and max on non mumeric value</xsl:text>
   192                         <xsl:text> use min and max on non mumeric value</xsl:text>
   166                       </xsl:message>
   193                       </xsl:message>
   167                     </xsl:if>
   194                     </xsl:if>