svghmi/gen_dnd_widget_svg.xslt
changeset 3621 da020d88db0c
parent 3507 e87a2daace80
child 3630 921f620577e8
equal deleted inserted replaced
3613:7af7a23e4adb 3621:da020d88db0c
     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">
       
     9     <xsl:text>
       
    10 </xsl:text>
       
    11   </xsl:variable>
       
    12   <xsl:variable name="twonewlines" select="concat($newline,$newline)"/>
     8   <xsl:template mode="parselabel" match="*">
    13   <xsl:template mode="parselabel" match="*">
     9     <xsl:variable name="label" select="@inkscape:label"/>
    14     <xsl:variable name="label" select="@inkscape:label"/>
       
    15     <xsl:variable name="desc" select="svg:desc"/>
       
    16     <xsl:variable name="len" select="string-length($label)"/>
       
    17     <xsl:variable name="has_continuation" select="substring($label,$len,1)='\'"/>
       
    18     <xsl:variable name="full_decl">
       
    19       <xsl:choose>
       
    20         <xsl:when test="$has_continuation">
       
    21           <xsl:variable name="_continuation" select="substring-before($desc, $twonewlines)"/>
       
    22           <xsl:variable name="continuation">
       
    23             <xsl:choose>
       
    24               <xsl:when test="$_continuation">
       
    25                 <xsl:value-of select="$_continuation"/>
       
    26               </xsl:when>
       
    27               <xsl:otherwise>
       
    28                 <xsl:value-of select="$desc"/>
       
    29               </xsl:otherwise>
       
    30             </xsl:choose>
       
    31           </xsl:variable>
       
    32           <xsl:value-of select="concat(substring($label,1,$len - 1),translate($continuation,$newline,''))"/>
       
    33         </xsl:when>
       
    34         <xsl:otherwise>
       
    35           <xsl:value-of select="$label"/>
       
    36         </xsl:otherwise>
       
    37       </xsl:choose>
       
    38     </xsl:variable>
    10     <xsl:variable name="id" select="@id"/>
    39     <xsl:variable name="id" select="@id"/>
    11     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    40     <xsl:variable name="declaration" select="substring-after($full_decl,'HMI:')"/>
    12     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    41     <xsl:variable name="_args" select="substring-before($declaration,'@')"/>
    13     <xsl:variable name="args">
    42     <xsl:variable name="args">
    14       <xsl:choose>
    43       <xsl:choose>
    15         <xsl:when test="$_args">
    44         <xsl:when test="$_args">
    16           <xsl:value-of select="$_args"/>
    45           <xsl:value-of select="$_args"/>
    17         </xsl:when>
    46         </xsl:when>
    18         <xsl:otherwise>
    47         <xsl:otherwise>
    19           <xsl:value-of select="$description"/>
    48           <xsl:value-of select="$declaration"/>
    20         </xsl:otherwise>
    49         </xsl:otherwise>
    21       </xsl:choose>
    50       </xsl:choose>
    22     </xsl:variable>
    51     </xsl:variable>
    23     <xsl:variable name="_typefreq" select="substring-before($args,':')"/>
    52     <xsl:variable name="_typefreq" select="substring-before($args,':')"/>
    24     <xsl:variable name="typefreq">
    53     <xsl:variable name="typefreq">
    55           <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]?'))">
    56             <xsl:message terminate="yes">
    85             <xsl:message terminate="yes">
    57               <xsl:text>Widget id:</xsl:text>
    86               <xsl:text>Widget id:</xsl:text>
    58               <xsl:value-of select="$id"/>
    87               <xsl:value-of select="$id"/>
    59               <xsl:text> label:</xsl:text>
    88               <xsl:text> label:</xsl:text>
    60               <xsl:value-of select="$label"/>
    89               <xsl:value-of select="$full_decl"/>
    61               <xsl:text> has wrong syntax of frequency forcing </xsl:text>
    90               <xsl:text> has wrong syntax of frequency forcing </xsl:text>
    62               <xsl:value-of select="$freq"/>
    91               <xsl:value-of select="$freq"/>
    63             </xsl:message>
    92             </xsl:message>
    64           </xsl:if>
    93           </xsl:if>
    65           <xsl:attribute name="freq">
    94           <xsl:attribute name="freq">
    66             <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"/>
    67           </xsl:attribute>
   115           </xsl:attribute>
    68         </xsl:if>
   116         </xsl:if>
    69         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   117         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
    70           <arg>
   118           <arg>
    71             <xsl:attribute name="value">
   119             <xsl:attribute name="value">
    72               <xsl:value-of select="."/>
   120               <xsl:value-of select="."/>
    73             </xsl:attribute>
   121             </xsl:attribute>
    74           </arg>
   122           </arg>
    75         </xsl:for-each>
   123         </xsl:for-each>
    76         <xsl:variable name="paths" select="substring-after($description,'@')"/>
       
    77         <xsl:for-each select="str:split($paths, '@')">
   124         <xsl:for-each select="str:split($paths, '@')">
    78           <xsl:if test="string-length(.) &gt; 0">
   125           <xsl:if test="string-length(.) &gt; 0">
    79             <path>
   126             <path>
    80               <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],'=')"/>
    81               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
   129               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
    82               <xsl:variable name="path" select="$path_match[2]"/>
   130               <xsl:variable name="path" select="$path_match[3]"/>
    83               <xsl:variable name="path_accepts" select="$path_match[3]"/>
       
    84               <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>
    85               <xsl:attribute name="value">
   141               <xsl:attribute name="value">
    86                 <xsl:value-of select="$path"/>
   142                 <xsl:value-of select="$path"/>
    87               </xsl:attribute>
   143               </xsl:attribute>
    88               <xsl:if test="string-length($path_accepts)">
   144               <xsl:if test="$pathassign">
    89                 <xsl:attribute name="accepts">
   145                 <xsl:attribute name="assign">
    90                   <xsl:value-of select="$path_accepts"/>
   146                   <xsl:value-of select="$pathassign"/>
    91                 </xsl:attribute>
   147                 </xsl:attribute>
    92               </xsl:if>
   148               </xsl:if>
    93               <xsl:choose>
   149               <xsl:choose>
    94                 <xsl:when test="$pathminmaxcount = 2">
   150                 <xsl:when test="$pathminmaxcount = 2">
    95                   <xsl:attribute name="min">
   151                   <xsl:attribute name="min">
   102                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
   158                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
   103                   <xsl:message terminate="yes">
   159                   <xsl:message terminate="yes">
   104                     <xsl:text>Widget id:</xsl:text>
   160                     <xsl:text>Widget id:</xsl:text>
   105                     <xsl:value-of select="$id"/>
   161                     <xsl:value-of select="$id"/>
   106                     <xsl:text> label:</xsl:text>
   162                     <xsl:text> label:</xsl:text>
   107                     <xsl:value-of select="$label"/>
   163                     <xsl:value-of select="$full_decl"/>
   108                     <xsl:text> has wrong syntax of path section </xsl:text>
   164                     <xsl:text> has wrong syntax of path section </xsl:text>
   109                     <xsl:value-of select="$pathminmax"/>
   165                     <xsl:value-of select="$pathminmax"/>
   110                   </xsl:message>
   166                   </xsl:message>
   111                 </xsl:when>
   167                 </xsl:when>
   112               </xsl:choose>
   168               </xsl:choose>
   128                     <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')">
   129                       <xsl:message terminate="yes">
   185                       <xsl:message terminate="yes">
   130                         <xsl:text>Widget id:</xsl:text>
   186                         <xsl:text>Widget id:</xsl:text>
   131                         <xsl:value-of select="$id"/>
   187                         <xsl:value-of select="$id"/>
   132                         <xsl:text> label:</xsl:text>
   188                         <xsl:text> label:</xsl:text>
   133                         <xsl:value-of select="$label"/>
   189                         <xsl:value-of select="$full_decl"/>
   134                         <xsl:text> path section </xsl:text>
   190                         <xsl:text> path section </xsl:text>
   135                         <xsl:value-of select="$pathminmax"/>
   191                         <xsl:value-of select="$pathminmax"/>
   136                         <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>
   137                       </xsl:message>
   193                       </xsl:message>
   138                     </xsl:if>
   194                     </xsl:if>
   148                 </xsl:choose>
   204                 </xsl:choose>
   149               </xsl:if>
   205               </xsl:if>
   150             </path>
   206             </path>
   151           </xsl:if>
   207           </xsl:if>
   152         </xsl:for-each>
   208         </xsl:for-each>
   153         <xsl:if test="svg:desc">
   209         <xsl:choose>
   154           <desc>
   210           <xsl:when test="$has_continuation">
   155             <xsl:value-of select="svg:desc/text()"/>
   211             <xsl:variable name="_continuation" select="substring-after($desc, $twonewlines)"/>
   156           </desc>
   212             <xsl:if test="$_continuation">
   157         </xsl:if>
   213               <desc>
       
   214                 <xsl:value-of select="$_continuation"/>
       
   215               </desc>
       
   216             </xsl:if>
       
   217           </xsl:when>
       
   218           <xsl:otherwise>
       
   219             <xsl:if test="$desc">
       
   220               <desc>
       
   221                 <xsl:value-of select="$desc/text()"/>
       
   222               </desc>
       
   223             </xsl:if>
       
   224           </xsl:otherwise>
       
   225         </xsl:choose>
   158       </widget>
   226       </widget>
   159     </xsl:if>
   227     </xsl:if>
   160   </xsl:template>
   228   </xsl:template>
   161   <xsl:template mode="genlabel" match="arg">
   229   <xsl:template mode="genlabel" match="arg">
   162     <xsl:text>:</xsl:text>
   230     <xsl:text>:</xsl:text>