svghmi/analyse_widget.xslt
branchwxPython4
changeset 3615 5c983ead9db0
parent 3582 7dcd0de97e6f
child 3630 921f620577e8
equal deleted inserted replaced
3614:0e0252339e83 3615:5c983ead9db0
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     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:svg="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn svg inkscape">
     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:svg="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn svg inkscape">
     3   <xsl:output method="xml"/>
     3   <xsl:output method="xml"/>
     4   <xsl:variable name="indexed_hmitree" select="/.."/>
     4   <xsl:variable name="indexed_hmitree" select="/.."/>
     5   <xsl:variable name="pathregex" select="'^([^\[,]+)(\[[^\]]+\])?([-.\d,]*)$'"/>
     5   <xsl:variable name="pathregex" select="'^(\w+=)?([^,=]+)([-.\d,]*)$'"/>
     6   <xsl:variable name="newline">
     6   <xsl:variable name="newline">
     7     <xsl:text>
     7     <xsl:text>
     8 </xsl:text>
     8 </xsl:text>
     9   </xsl:variable>
     9   </xsl:variable>
    10   <xsl:variable name="twonewlines" select="concat($newline,$newline)"/>
    10   <xsl:variable name="twonewlines" select="concat($newline,$newline)"/>
    11   <xsl:template mode="parselabel" match="*">
    11   <xsl:template mode="parselabel" match="*">
    12     <xsl:variable name="part" select="@inkscape:label"/>
    12     <xsl:variable name="label" select="@inkscape:label"/>
    13     <xsl:variable name="desc" select="svg:desc"/>
    13     <xsl:variable name="desc" select="svg:desc"/>
    14     <xsl:variable name="len" select="string-length($part)"/>
    14     <xsl:variable name="len" select="string-length($label)"/>
    15     <xsl:variable name="has_continuation" select="substring($part,$len,1)='\'"/>
    15     <xsl:variable name="has_continuation" select="substring($label,$len,1)='\'"/>
    16     <xsl:variable name="label">
    16     <xsl:variable name="full_decl">
    17       <xsl:choose>
    17       <xsl:choose>
    18         <xsl:when test="$has_continuation">
    18         <xsl:when test="$has_continuation">
    19           <xsl:variable name="_continuation" select="substring-before($desc, $twonewlines)"/>
    19           <xsl:variable name="_continuation" select="substring-before($desc, $twonewlines)"/>
    20           <xsl:variable name="continuation">
    20           <xsl:variable name="continuation">
    21             <xsl:choose>
    21             <xsl:choose>
    25               <xsl:otherwise>
    25               <xsl:otherwise>
    26                 <xsl:value-of select="$desc"/>
    26                 <xsl:value-of select="$desc"/>
    27               </xsl:otherwise>
    27               </xsl:otherwise>
    28             </xsl:choose>
    28             </xsl:choose>
    29           </xsl:variable>
    29           </xsl:variable>
    30           <xsl:value-of select="concat(substring($part,1,$len - 1),translate($continuation,$newline,''))"/>
    30           <xsl:value-of select="concat(substring($label,1,$len - 1),translate($continuation,$newline,''))"/>
    31         </xsl:when>
    31         </xsl:when>
    32         <xsl:otherwise>
    32         <xsl:otherwise>
    33           <xsl:value-of select="$part"/>
    33           <xsl:value-of select="$label"/>
    34         </xsl:otherwise>
    34         </xsl:otherwise>
    35       </xsl:choose>
    35       </xsl:choose>
    36     </xsl:variable>
    36     </xsl:variable>
    37     <xsl:variable name="id" select="@id"/>
    37     <xsl:variable name="id" select="@id"/>
    38     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
    38     <xsl:variable name="declaration" select="substring-after($full_decl,'HMI:')"/>
    39     <xsl:variable name="_args" select="substring-before($description,'@')"/>
    39     <xsl:variable name="_args" select="substring-before($declaration,'@')"/>
    40     <xsl:variable name="args">
    40     <xsl:variable name="args">
    41       <xsl:choose>
    41       <xsl:choose>
    42         <xsl:when test="$_args">
    42         <xsl:when test="$_args">
    43           <xsl:value-of select="$_args"/>
    43           <xsl:value-of select="$_args"/>
    44         </xsl:when>
    44         </xsl:when>
    45         <xsl:otherwise>
    45         <xsl:otherwise>
    46           <xsl:value-of select="$description"/>
    46           <xsl:value-of select="$declaration"/>
    47         </xsl:otherwise>
    47         </xsl:otherwise>
    48       </xsl:choose>
    48       </xsl:choose>
    49     </xsl:variable>
    49     </xsl:variable>
    50     <xsl:variable name="_typefreq" select="substring-before($args,':')"/>
    50     <xsl:variable name="_typefreq" select="substring-before($args,':')"/>
    51     <xsl:variable name="typefreq">
    51     <xsl:variable name="typefreq">
    82           <xsl:if test="not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))">
    82           <xsl:if test="not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))">
    83             <xsl:message terminate="yes">
    83             <xsl:message terminate="yes">
    84               <xsl:text>Widget id:</xsl:text>
    84               <xsl:text>Widget id:</xsl:text>
    85               <xsl:value-of select="$id"/>
    85               <xsl:value-of select="$id"/>
    86               <xsl:text> label:</xsl:text>
    86               <xsl:text> label:</xsl:text>
    87               <xsl:value-of select="$label"/>
    87               <xsl:value-of select="$full_decl"/>
    88               <xsl:text> has wrong syntax of frequency forcing </xsl:text>
    88               <xsl:text> has wrong syntax of frequency forcing </xsl:text>
    89               <xsl:value-of select="$freq"/>
    89               <xsl:value-of select="$freq"/>
    90             </xsl:message>
    90             </xsl:message>
    91           </xsl:if>
    91           </xsl:if>
    92           <xsl:attribute name="freq">
    92           <xsl:attribute name="freq">
    93             <xsl:value-of select="$freq"/>
    93             <xsl:value-of select="$freq"/>
       
    94           </xsl:attribute>
       
    95         </xsl:if>
       
    96         <xsl:variable name="tail" select="substring-after($declaration,'@')"/>
       
    97         <xsl:variable name="taillen" select="string-length($tail)"/>
       
    98         <xsl:variable name="has_enable" select="contains($tail, '#')"/>
       
    99         <xsl:variable name="paths">
       
   100           <xsl:choose>
       
   101             <xsl:when test="$has_enable">
       
   102               <xsl:value-of select="substring-before($tail,'#')"/>
       
   103             </xsl:when>
       
   104             <xsl:otherwise>
       
   105               <xsl:value-of select="$tail"/>
       
   106             </xsl:otherwise>
       
   107           </xsl:choose>
       
   108         </xsl:variable>
       
   109         <xsl:if test="$has_enable">
       
   110           <xsl:variable name="enable_expr" select="substring-after($tail,'#')"/>
       
   111           <xsl:attribute name="enable_expr">
       
   112             <xsl:value-of select="$enable_expr"/>
    94           </xsl:attribute>
   113           </xsl:attribute>
    95         </xsl:if>
   114         </xsl:if>
    96         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   115         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
    97           <arg>
   116           <arg>
    98             <xsl:attribute name="value">
   117             <xsl:attribute name="value">
    99               <xsl:value-of select="."/>
   118               <xsl:value-of select="."/>
   100             </xsl:attribute>
   119             </xsl:attribute>
   101           </arg>
   120           </arg>
   102         </xsl:for-each>
   121         </xsl:for-each>
   103         <xsl:variable name="paths" select="substring-after($description,'@')"/>
       
   104         <xsl:for-each select="str:split($paths, '@')">
   122         <xsl:for-each select="str:split($paths, '@')">
   105           <xsl:if test="string-length(.) &gt; 0">
   123           <xsl:if test="string-length(.) &gt; 0">
   106             <path>
   124             <path>
   107               <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/>
   125               <xsl:variable name="path_match" select="regexp:match(.,$pathregex)"/>
       
   126               <xsl:variable name="pathassign" select="substring-before($path_match[2],'=')"/>
   108               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
   127               <xsl:variable name="pathminmax" select="str:split($path_match[4],',')"/>
   109               <xsl:variable name="path" select="$path_match[2]"/>
   128               <xsl:variable name="path" select="$path_match[3]"/>
   110               <xsl:variable name="path_accepts" select="$path_match[3]"/>
       
   111               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
   129               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
       
   130               <xsl:if test="not($path)">
       
   131                 <xsl:message terminate="yes">
       
   132                   <xsl:text>Widget id:</xsl:text>
       
   133                   <xsl:value-of select="$id"/>
       
   134                   <xsl:text> label:</xsl:text>
       
   135                   <xsl:value-of select="$full_decl"/>
       
   136                   <xsl:text> has wrong syntax</xsl:text>
       
   137                 </xsl:message>
       
   138               </xsl:if>
   112               <xsl:attribute name="value">
   139               <xsl:attribute name="value">
   113                 <xsl:value-of select="$path"/>
   140                 <xsl:value-of select="$path"/>
   114               </xsl:attribute>
   141               </xsl:attribute>
   115               <xsl:if test="string-length($path_accepts)">
   142               <xsl:if test="$pathassign">
   116                 <xsl:attribute name="accepts">
   143                 <xsl:attribute name="assign">
   117                   <xsl:value-of select="$path_accepts"/>
   144                   <xsl:value-of select="$pathassign"/>
   118                 </xsl:attribute>
   145                 </xsl:attribute>
   119               </xsl:if>
   146               </xsl:if>
   120               <xsl:choose>
   147               <xsl:choose>
   121                 <xsl:when test="$pathminmaxcount = 2">
   148                 <xsl:when test="$pathminmaxcount = 2">
   122                   <xsl:attribute name="min">
   149                   <xsl:attribute name="min">
   129                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
   156                 <xsl:when test="$pathminmaxcount = 1 or $pathminmaxcount &gt; 2">
   130                   <xsl:message terminate="yes">
   157                   <xsl:message terminate="yes">
   131                     <xsl:text>Widget id:</xsl:text>
   158                     <xsl:text>Widget id:</xsl:text>
   132                     <xsl:value-of select="$id"/>
   159                     <xsl:value-of select="$id"/>
   133                     <xsl:text> label:</xsl:text>
   160                     <xsl:text> label:</xsl:text>
   134                     <xsl:value-of select="$label"/>
   161                     <xsl:value-of select="$full_decl"/>
   135                     <xsl:text> has wrong syntax of path section </xsl:text>
   162                     <xsl:text> has wrong syntax of path section </xsl:text>
   136                     <xsl:value-of select="$pathminmax"/>
   163                     <xsl:value-of select="$pathminmax"/>
   137                   </xsl:message>
   164                   </xsl:message>
   138                 </xsl:when>
   165                 </xsl:when>
   139               </xsl:choose>
   166               </xsl:choose>
   155                     <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
   182                     <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
   156                       <xsl:message terminate="yes">
   183                       <xsl:message terminate="yes">
   157                         <xsl:text>Widget id:</xsl:text>
   184                         <xsl:text>Widget id:</xsl:text>
   158                         <xsl:value-of select="$id"/>
   185                         <xsl:value-of select="$id"/>
   159                         <xsl:text> label:</xsl:text>
   186                         <xsl:text> label:</xsl:text>
   160                         <xsl:value-of select="$label"/>
   187                         <xsl:value-of select="$full_decl"/>
   161                         <xsl:text> path section </xsl:text>
   188                         <xsl:text> path section </xsl:text>
   162                         <xsl:value-of select="$pathminmax"/>
   189                         <xsl:value-of select="$pathminmax"/>
   163                         <xsl:text> use min and max on non mumeric value</xsl:text>
   190                         <xsl:text> use min and max on non mumeric value</xsl:text>
   164                       </xsl:message>
   191                       </xsl:message>
   165                     </xsl:if>
   192                     </xsl:if>
   272       <xsl:text>Boolean variable</xsl:text>
   299       <xsl:text>Boolean variable</xsl:text>
   273     </path>
   300     </path>
   274   </xsl:template>
   301   </xsl:template>
   275   <xsl:template name="generated_button_class">
   302   <xsl:template name="generated_button_class">
   276     <xsl:param name="fsm"/>
   303     <xsl:param name="fsm"/>
   277     <xsl:text>    display = "inactive";
       
   278 </xsl:text>
       
   279     <xsl:text>    state = "init";
   304     <xsl:text>    state = "init";
   280 </xsl:text>
   305 </xsl:text>
   281     <xsl:text>    dispatch(value) {
   306     <xsl:text>    dispatch(value) {
   282 </xsl:text>
   307 </xsl:text>
   283     <xsl:apply-templates mode="dispatch_transition" select="$fsm"/>
   308     <xsl:apply-templates mode="dispatch_transition" select="$fsm"/>
   300       <xsl:with-param name="position" select="'down'"/>
   325       <xsl:with-param name="position" select="'down'"/>
   301     </xsl:apply-templates>
   326     </xsl:apply-templates>
   302     <xsl:text>    }
   327     <xsl:text>    }
   303 </xsl:text>
   328 </xsl:text>
   304     <xsl:apply-templates mode="actions" select="$fsm"/>
   329     <xsl:apply-templates mode="actions" select="$fsm"/>
   305     <xsl:text>    animate(){
       
   306 </xsl:text>
       
   307     <xsl:text>        this.set_activation_state(this.display == "active");
       
   308 </xsl:text>
       
   309     <xsl:text>    }
       
   310 </xsl:text>
       
   311     <xsl:text>    init() {
   330     <xsl:text>    init() {
   312 </xsl:text>
   331 </xsl:text>
   313     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
   332     <xsl:text>        this.bound_onmouseup = this.onmouseup.bind(this);
   314 </xsl:text>
   333 </xsl:text>
   315     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
   334     <xsl:text>        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
   316 </xsl:text>
   335 </xsl:text>
   317     <xsl:text>        this.set_activation_state(undefined);
   336     <xsl:text>        this.activity_state = undefined;
   318 </xsl:text>
   337 </xsl:text>
   319     <xsl:text>    }
   338     <xsl:text>    }
   320 </xsl:text>
   339 </xsl:text>
   321   </xsl:template>
   340   </xsl:template>
   322   <xsl:template match="widget[@type='CircularBar']" mode="widget_desc">
   341   <xsl:template match="widget[@type='CircularBar']" mode="widget_desc">
   602   <xsl:template match="widget[@type='Jump']" mode="widget_desc">
   621   <xsl:template match="widget[@type='Jump']" mode="widget_desc">
   603     <type>
   622     <type>
   604       <xsl:value-of select="@type"/>
   623       <xsl:value-of select="@type"/>
   605     </type>
   624     </type>
   606     <longdesc>
   625     <longdesc>
   607       <xsl:text>Jump widget brings focus to a different page. Mandatory single argument
   626       <xsl:text>Jump widget brings focus to a different page. Mandatory first argument
   608 </xsl:text>
   627 </xsl:text>
   609       <xsl:text>gives name of the page.
   628       <xsl:text>gives name of the page.
   610 </xsl:text>
   629 </xsl:text>
   611       <xsl:text>
   630       <xsl:text>
   612 </xsl:text>
   631 </xsl:text>
   613       <xsl:text>Optional single path is used as new reference when jumping to a relative
   632       <xsl:text>If first path is pointint to HMI_NODE variable is used as new reference
   614 </xsl:text>
   633 </xsl:text>
   615       <xsl:text>page, it must point to a HMI_NODE.
   634       <xsl:text>when jumping to a relative page.
       
   635 </xsl:text>
       
   636       <xsl:text>
       
   637 </xsl:text>
       
   638       <xsl:text>Additional arguments are unordered options:
       
   639 </xsl:text>
       
   640       <xsl:text>
       
   641 </xsl:text>
       
   642       <xsl:text>- Absolute: force page jump to be not relative even if first path is of type HMI_NODE
       
   643 </xsl:text>
       
   644       <xsl:text>
       
   645 </xsl:text>
       
   646       <xsl:text>- name=value: Notify PLC about jump by setting variable with path having same name assigned
   616 </xsl:text>
   647 </xsl:text>
   617       <xsl:text>
   648       <xsl:text>
   618 </xsl:text>
   649 </xsl:text>
   619       <xsl:text>"active"+"inactive" labeled elements can be provided and reflect current
   650       <xsl:text>"active"+"inactive" labeled elements can be provided and reflect current
   620 </xsl:text>
   651 </xsl:text>
   621       <xsl:text>page being shown.
   652       <xsl:text>page being shown.
   622 </xsl:text>
   653 </xsl:text>
   623       <xsl:text>
   654       <xsl:text>
   624 </xsl:text>
   655 </xsl:text>
   625       <xsl:text>"disabled" labeled element, if provided, is shown instead of "active" or
   656       <xsl:text>Exemples:
   626 </xsl:text>
   657 </xsl:text>
   627       <xsl:text>"inactive" widget when pointed HMI_NODE is null.
   658       <xsl:text>
       
   659 </xsl:text>
       
   660       <xsl:text>Relative jump:
       
   661 </xsl:text>
       
   662       <xsl:text>
       
   663 </xsl:text>
       
   664       <xsl:text>HMI:Jump:RelativePage@/PUMP9
       
   665 </xsl:text>
       
   666       <xsl:text>HMI:Jump:RelativePage@/PUMP9@role=.userrole#role=="admin"
       
   667 </xsl:text>
       
   668       <xsl:text>
       
   669 </xsl:text>
       
   670       <xsl:text>Absolute jump:
       
   671 </xsl:text>
       
   672       <xsl:text>
       
   673 </xsl:text>
       
   674       <xsl:text>HMI:Jump:AbsolutePage
       
   675 </xsl:text>
       
   676       <xsl:text>HMI:Jump:AbsolutePage@role=.userrole#role=="admin"
       
   677 </xsl:text>
       
   678       <xsl:text>
       
   679 </xsl:text>
       
   680       <xsl:text>Forced absolute jump:
       
   681 </xsl:text>
       
   682       <xsl:text>
       
   683 </xsl:text>
       
   684       <xsl:text>HMI:Jump:AbsolutePage:Absolute@/PUMP9
       
   685 </xsl:text>
       
   686       <xsl:text>HMI:Jump:AbsolutePage:Absolute:notify=1@notify=/PUMP9
       
   687 </xsl:text>
       
   688       <xsl:text>
       
   689 </xsl:text>
       
   690       <xsl:text>Jump with feedback
       
   691 </xsl:text>
       
   692       <xsl:text>
       
   693 </xsl:text>
       
   694       <xsl:text>HMI:Jump:AbsolutePage:notify=1@notify=.did_jump
       
   695 </xsl:text>
       
   696       <xsl:text>
   628 </xsl:text>
   697 </xsl:text>
   629     </longdesc>
   698     </longdesc>
   630     <shortdesc>
   699     <shortdesc>
   631       <xsl:text>Jump to given page</xsl:text>
   700       <xsl:text>Jump to given page</xsl:text>
   632     </shortdesc>
   701     </shortdesc>
   635     </arg>
   704     </arg>
   636     <path name="reference" count="optional" accepts="HMI_NODE">
   705     <path name="reference" count="optional" accepts="HMI_NODE">
   637       <xsl:text>reference for relative jump</xsl:text>
   706       <xsl:text>reference for relative jump</xsl:text>
   638     </path>
   707     </path>
   639   </xsl:template>
   708   </xsl:template>
       
   709   <func:function name="func:is_relative_jump">
       
   710     <xsl:param name="widget"/>
       
   711     <func:result select="$widget/path and $widget/path[1]/@type='HMI_NODE' and not($widget/arg[position()&gt;1 and @value = 'Absolute'])"/>
       
   712   </func:function>
   640   <xsl:template match="widget[@type='Keypad']" mode="widget_desc">
   713   <xsl:template match="widget[@type='Keypad']" mode="widget_desc">
   641     <type>
   714     <type>
   642       <xsl:value-of select="@type"/>
   715       <xsl:value-of select="@type"/>
   643     </type>
   716     </type>
   644     <longdesc>
   717     <longdesc>