svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 3097 a098b2dd9dff
parent 3094 3e184f1e1012
child 3103 677764fba71d
equal deleted inserted replaced
3096:fc5a0b1ece10 3097:a098b2dd9dff
    53         <xsl:text>,</xsl:text>
    53         <xsl:text>,</xsl:text>
    54       </xsl:if>
    54       </xsl:if>
    55       <xsl:text>
    55       <xsl:text>
    56 </xsl:text>
    56 </xsl:text>
    57     </xsl:for-each>
    57     </xsl:for-each>
    58     <xsl:text>]
    58     <xsl:text>];
       
    59 </xsl:text>
       
    60     <xsl:text>
       
    61 </xsl:text>
       
    62     <xsl:text>var hmitree_paths = [
       
    63 </xsl:text>
       
    64     <xsl:for-each select="$indexed_hmitree/*">
       
    65       <xsl:text>    /* </xsl:text>
       
    66       <xsl:value-of select="@index"/>
       
    67       <xsl:text> </xsl:text>
       
    68       <xsl:value-of select="substring(local-name(), 5)"/>
       
    69       <xsl:text> */ "</xsl:text>
       
    70       <xsl:value-of select="@hmipath"/>
       
    71       <xsl:text>"</xsl:text>
       
    72       <xsl:if test="position()!=last()">
       
    73         <xsl:text>,</xsl:text>
       
    74       </xsl:if>
       
    75       <xsl:text>
       
    76 </xsl:text>
       
    77     </xsl:for-each>
       
    78     <xsl:text>];
    59 </xsl:text>
    79 </xsl:text>
    60     <xsl:text>
    80     <xsl:text>
    61 </xsl:text>
    81 </xsl:text>
    62     <xsl:text>
    82     <xsl:text>
    63 </xsl:text>
    83 </xsl:text>
   120       </xsl:with-param>
   140       </xsl:with-param>
   121     </xsl:apply-templates>
   141     </xsl:apply-templates>
   122   </xsl:template>
   142   </xsl:template>
   123   <xsl:template mode="parselabel" match="*">
   143   <xsl:template mode="parselabel" match="*">
   124     <xsl:variable name="label" select="@inkscape:label"/>
   144     <xsl:variable name="label" select="@inkscape:label"/>
       
   145     <xsl:variable name="id" select="@id"/>
   125     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
   146     <xsl:variable name="description" select="substring-after($label,'HMI:')"/>
   126     <xsl:variable name="_args" select="substring-before($description,'@')"/>
   147     <xsl:variable name="_args" select="substring-before($description,'@')"/>
   127     <xsl:variable name="args">
   148     <xsl:variable name="args">
   128       <xsl:choose>
   149       <xsl:choose>
   129         <xsl:when test="$_args">
   150         <xsl:when test="$_args">
   146       </xsl:choose>
   167       </xsl:choose>
   147     </xsl:variable>
   168     </xsl:variable>
   148     <xsl:if test="$type">
   169     <xsl:if test="$type">
   149       <widget>
   170       <widget>
   150         <xsl:attribute name="id">
   171         <xsl:attribute name="id">
   151           <xsl:value-of select="@id"/>
   172           <xsl:value-of select="$id"/>
   152         </xsl:attribute>
   173         </xsl:attribute>
   153         <xsl:attribute name="type">
   174         <xsl:attribute name="type">
   154           <xsl:value-of select="$type"/>
   175           <xsl:value-of select="$type"/>
   155         </xsl:attribute>
   176         </xsl:attribute>
   156         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   177         <xsl:for-each select="str:split(substring-after($args, ':'), ':')">
   162         </xsl:for-each>
   183         </xsl:for-each>
   163         <xsl:variable name="paths" select="substring-after($description,'@')"/>
   184         <xsl:variable name="paths" select="substring-after($description,'@')"/>
   164         <xsl:for-each select="str:split($paths, '@')">
   185         <xsl:for-each select="str:split($paths, '@')">
   165           <xsl:if test="string-length(.) &gt; 0">
   186           <xsl:if test="string-length(.) &gt; 0">
   166             <path>
   187             <path>
       
   188               <xsl:variable name="pathminmax" select="str:split(.,',')"/>
       
   189               <xsl:variable name="path" select="$pathminmax[1]"/>
       
   190               <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/>
   167               <xsl:attribute name="value">
   191               <xsl:attribute name="value">
   168                 <xsl:value-of select="."/>
   192                 <xsl:value-of select="$path"/>
   169               </xsl:attribute>
   193               </xsl:attribute>
   170               <xsl:variable name="path" select="."/>
       
   171               <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
       
   172               <xsl:choose>
   194               <xsl:choose>
   173                 <xsl:when test="count($item) = 1">
   195                 <xsl:when test="$pathminmaxcount = 3">
   174                   <xsl:attribute name="index">
   196                   <xsl:attribute name="min">
   175                     <xsl:value-of select="$item/@index"/>
   197                     <xsl:value-of select="$pathminmax[2]"/>
   176                   </xsl:attribute>
   198                   </xsl:attribute>
       
   199                   <xsl:attribute name="max">
       
   200                     <xsl:value-of select="$pathminmax[3]"/>
       
   201                   </xsl:attribute>
       
   202                 </xsl:when>
       
   203                 <xsl:when test="$pathminmaxcount = 2">
       
   204                   <xsl:message terminate="yes">
       
   205                     <xsl:text>Widget id:</xsl:text>
       
   206                     <xsl:value-of select="$id"/>
       
   207                     <xsl:text> label:</xsl:text>
       
   208                     <xsl:value-of select="$label"/>
       
   209                     <xsl:text> has wrong syntax of path section </xsl:text>
       
   210                     <xsl:value-of select="$pathminmax"/>
       
   211                   </xsl:message>
       
   212                 </xsl:when>
       
   213               </xsl:choose>
       
   214               <xsl:choose>
       
   215                 <xsl:when test="regexp:test($path,'^\.[a-zA-Z0-9_]+')">
   177                   <xsl:attribute name="type">
   216                   <xsl:attribute name="type">
   178                     <xsl:value-of select="local-name($item)"/>
   217                     <xsl:text>PAGE_LOCAL</xsl:text>
       
   218                   </xsl:attribute>
       
   219                 </xsl:when>
       
   220                 <xsl:when test="regexp:test($path,'^[a-zA-Z0-9_]+')">
       
   221                   <xsl:attribute name="type">
       
   222                     <xsl:text>HMI_LOCAL</xsl:text>
   179                   </xsl:attribute>
   223                   </xsl:attribute>
   180                 </xsl:when>
   224                 </xsl:when>
   181                 <xsl:otherwise>
   225                 <xsl:otherwise>
   182                   <xsl:choose>
   226                   <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/>
   183                     <xsl:when test="regexp:test($path,'^\.[a-zA-Z0-9_]+')">
   227                   <xsl:variable name="pathtype" select="local-name($item)"/>
   184                       <xsl:attribute name="type">
   228                   <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')">
   185                         <xsl:text>PAGE_LOCAL</xsl:text>
   229                     <xsl:message terminate="yes">
   186                       </xsl:attribute>
   230                       <xsl:text>Widget id:</xsl:text>
   187                     </xsl:when>
   231                       <xsl:value-of select="$id"/>
   188                     <xsl:when test="regexp:test($path,'^[a-zA-Z0-9_]+')">
   232                       <xsl:text> label:</xsl:text>
   189                       <xsl:attribute name="type">
   233                       <xsl:value-of select="$label"/>
   190                         <xsl:text>HMI_LOCAL</xsl:text>
   234                       <xsl:text> path section </xsl:text>
   191                       </xsl:attribute>
   235                       <xsl:value-of select="$pathminmax"/>
   192                     </xsl:when>
   236                       <xsl:text> use min and max on non mumeric value</xsl:text>
   193                   </xsl:choose>
   237                     </xsl:message>
       
   238                   </xsl:if>
       
   239                   <xsl:if test="count($item) = 1">
       
   240                     <xsl:attribute name="index">
       
   241                       <xsl:value-of select="$item/@index"/>
       
   242                     </xsl:attribute>
       
   243                     <xsl:attribute name="type">
       
   244                       <xsl:value-of select="$pathtype"/>
       
   245                     </xsl:attribute>
       
   246                   </xsl:if>
   194                 </xsl:otherwise>
   247                 </xsl:otherwise>
   195               </xsl:choose>
   248               </xsl:choose>
   196             </path>
   249             </path>
   197           </xsl:if>
   250           </xsl:if>
   198         </xsl:for-each>
   251         </xsl:for-each>
  1221 </xsl:text>
  1274 </xsl:text>
  1222     <xsl:text>        let index = this.indexes[varnum];
  1275     <xsl:text>        let index = this.indexes[varnum];
  1223 </xsl:text>
  1276 </xsl:text>
  1224     <xsl:text>        if(typeof(index) == "string"){
  1277     <xsl:text>        if(typeof(index) == "string"){
  1225 </xsl:text>
  1278 </xsl:text>
       
  1279     <xsl:text>            /* XXX return index as path */
       
  1280 </xsl:text>
  1226     <xsl:text>            index = page_local_index(index, this.container_id);
  1281     <xsl:text>            index = page_local_index(index, this.container_id);
  1227 </xsl:text>
  1282 </xsl:text>
  1228     <xsl:text>        } else {
  1283     <xsl:text>        } else {
  1229 </xsl:text>
  1284 </xsl:text>
  1230     <xsl:text>            if(this.relativeness[varnum]){
  1285     <xsl:text>            if(this.relativeness[varnum]){
  1231 </xsl:text>
  1286 </xsl:text>
  1232     <xsl:text>                index += this.offset;
  1287     <xsl:text>                index += this.offset;
  1233 </xsl:text>
  1288 </xsl:text>
  1234     <xsl:text>            }
  1289     <xsl:text>            }
  1235 </xsl:text>
  1290 </xsl:text>
       
  1291     <xsl:text>            /* XXX check for hmi_paths and return path */
       
  1292 </xsl:text>
  1236     <xsl:text>        }
  1293     <xsl:text>        }
  1237 </xsl:text>
  1294 </xsl:text>
  1238     <xsl:text>        return index;
  1295     <xsl:text>        return index;
  1239 </xsl:text>
  1296 </xsl:text>
  1240     <xsl:text>    }
  1297     <xsl:text>    }
  1241 </xsl:text>
  1298 </xsl:text>
       
  1299     <xsl:text>
       
  1300 </xsl:text>
  1242     <xsl:text>    change_hmi_value(index, opstr) {
  1301     <xsl:text>    change_hmi_value(index, opstr) {
  1243 </xsl:text>
  1302 </xsl:text>
  1244     <xsl:text>        let realindex = this.get_variable_index(index);
  1303     <xsl:text>        let realindex = this.get_variable_index(index);
  1245 </xsl:text>
  1304 </xsl:text>
  1246     <xsl:text>        if(realindex == undefined) return undefined;
  1305     <xsl:text>        if(realindex == undefined) return undefined;
  1247 </xsl:text>
  1306 </xsl:text>
  1248     <xsl:text>        return change_hmi_value(realindex, opstr);
  1307     <xsl:text>        let old_val = cache[realindex];
       
  1308 </xsl:text>
       
  1309     <xsl:text>        let new_val = eval_operation_string(old_val, opstr);
       
  1310 </xsl:text>
       
  1311     <xsl:text>        return apply_hmi_value(realindex, new_val);
  1249 </xsl:text>
  1312 </xsl:text>
  1250     <xsl:text>    }
  1313     <xsl:text>    }
  1251 </xsl:text>
  1314 </xsl:text>
  1252     <xsl:text>
  1315     <xsl:text>
  1253 </xsl:text>
  1316 </xsl:text>
  3993   <xsl:template mode="widget_class" match="widget[@type='Input']">
  4056   <xsl:template mode="widget_class" match="widget[@type='Input']">
  3994     <xsl:text>    class InputWidget extends Widget{
  4057     <xsl:text>    class InputWidget extends Widget{
  3995 </xsl:text>
  4058 </xsl:text>
  3996     <xsl:text>         on_op_click(opstr) {
  4059     <xsl:text>         on_op_click(opstr) {
  3997 </xsl:text>
  4060 </xsl:text>
  3998     <xsl:text>             let new_val = this.change_hmi_value(0, opstr);
  4061     <xsl:text>             this.change_hmi_value(0, opstr);
  3999 </xsl:text>
  4062 </xsl:text>
  4000     <xsl:text>         }
  4063     <xsl:text>         }
  4001 </xsl:text>
  4064 </xsl:text>
  4002     <xsl:text>         edit_callback(new_val) {
  4065     <xsl:text>         edit_callback(new_val) {
  4003 </xsl:text>
  4066 </xsl:text>
  6825 </xsl:text>
  6888 </xsl:text>
  6826           <xsl:text>const quotes = {"'":null, '"':null};
  6889           <xsl:text>const quotes = {"'":null, '"':null};
  6827 </xsl:text>
  6890 </xsl:text>
  6828           <xsl:text>
  6891           <xsl:text>
  6829 </xsl:text>
  6892 </xsl:text>
       
  6893           <xsl:text>function eval_operation_string(old_val, opstr) {
       
  6894 </xsl:text>
       
  6895           <xsl:text>    let op = opstr[0];
       
  6896 </xsl:text>
       
  6897           <xsl:text>    let given_val;
       
  6898 </xsl:text>
       
  6899           <xsl:text>    if(opstr.length &lt; 2) 
       
  6900 </xsl:text>
       
  6901           <xsl:text>        return undefined;
       
  6902 </xsl:text>
       
  6903           <xsl:text>    if(opstr[1] in quotes){
       
  6904 </xsl:text>
       
  6905           <xsl:text>        if(opstr.length &lt; 3) 
       
  6906 </xsl:text>
       
  6907           <xsl:text>            return undefined;
       
  6908 </xsl:text>
       
  6909           <xsl:text>        if(opstr[opstr.length-1] == opstr[1]){
       
  6910 </xsl:text>
       
  6911           <xsl:text>            given_val = opstr.slice(2,opstr.length-1);
       
  6912 </xsl:text>
       
  6913           <xsl:text>        }
       
  6914 </xsl:text>
       
  6915           <xsl:text>    } else {
       
  6916 </xsl:text>
       
  6917           <xsl:text>        given_val = Number(opstr.slice(1));
       
  6918 </xsl:text>
       
  6919           <xsl:text>    }
       
  6920 </xsl:text>
       
  6921           <xsl:text>    let new_val;
       
  6922 </xsl:text>
       
  6923           <xsl:text>    switch(op){
       
  6924 </xsl:text>
       
  6925           <xsl:text>      case "=":
       
  6926 </xsl:text>
       
  6927           <xsl:text>        new_val = given_val;
       
  6928 </xsl:text>
       
  6929           <xsl:text>        break;
       
  6930 </xsl:text>
       
  6931           <xsl:text>      case "+":
       
  6932 </xsl:text>
       
  6933           <xsl:text>        new_val = old_val + given_val;
       
  6934 </xsl:text>
       
  6935           <xsl:text>        break;
       
  6936 </xsl:text>
       
  6937           <xsl:text>      case "-":
       
  6938 </xsl:text>
       
  6939           <xsl:text>        new_val = old_val - given_val;
       
  6940 </xsl:text>
       
  6941           <xsl:text>        break;
       
  6942 </xsl:text>
       
  6943           <xsl:text>      case "*":
       
  6944 </xsl:text>
       
  6945           <xsl:text>        new_val = old_val * given_val;
       
  6946 </xsl:text>
       
  6947           <xsl:text>        break;
       
  6948 </xsl:text>
       
  6949           <xsl:text>      case "/":
       
  6950 </xsl:text>
       
  6951           <xsl:text>        new_val = old_val / given_val;
       
  6952 </xsl:text>
       
  6953           <xsl:text>        break;
       
  6954 </xsl:text>
       
  6955           <xsl:text>    }
       
  6956 </xsl:text>
       
  6957           <xsl:text>    return new_val;
       
  6958 </xsl:text>
       
  6959           <xsl:text>}
       
  6960 </xsl:text>
       
  6961           <xsl:text>
       
  6962 </xsl:text>
       
  6963           <xsl:text>/*
       
  6964 </xsl:text>
  6830           <xsl:text>function change_hmi_value(index, opstr) {
  6965           <xsl:text>function change_hmi_value(index, opstr) {
  6831 </xsl:text>
  6966 </xsl:text>
  6832           <xsl:text>    let op = opstr[0];
       
  6833 </xsl:text>
       
  6834           <xsl:text>    let given_val;
       
  6835 </xsl:text>
       
  6836           <xsl:text>    if(opstr.length &lt; 2) 
       
  6837 </xsl:text>
       
  6838           <xsl:text>        return undefined; // TODO raise
       
  6839 </xsl:text>
       
  6840           <xsl:text>    if(opstr[1] in quotes){
       
  6841 </xsl:text>
       
  6842           <xsl:text>        if(opstr.length &lt; 3) 
       
  6843 </xsl:text>
       
  6844           <xsl:text>            return undefined; // TODO raise
       
  6845 </xsl:text>
       
  6846           <xsl:text>        if(opstr[opstr.length-1] == opstr[1]){
       
  6847 </xsl:text>
       
  6848           <xsl:text>            given_val = opstr.slice(2,opstr.length-1);
       
  6849 </xsl:text>
       
  6850           <xsl:text>        }
       
  6851 </xsl:text>
       
  6852           <xsl:text>    } else {
       
  6853 </xsl:text>
       
  6854           <xsl:text>        given_val = Number(opstr.slice(1));
       
  6855 </xsl:text>
       
  6856           <xsl:text>    }
       
  6857 </xsl:text>
       
  6858           <xsl:text>    let old_val = cache[index];
  6967           <xsl:text>    let old_val = cache[index];
  6859 </xsl:text>
  6968 </xsl:text>
  6860           <xsl:text>    let new_val;
  6969           <xsl:text>    let new_val = eval_operation_string(old_val, opstr);
  6861 </xsl:text>
       
  6862           <xsl:text>    switch(op){
       
  6863 </xsl:text>
       
  6864           <xsl:text>      case "=":
       
  6865 </xsl:text>
       
  6866           <xsl:text>        new_val = given_val;
       
  6867 </xsl:text>
       
  6868           <xsl:text>        break;
       
  6869 </xsl:text>
       
  6870           <xsl:text>      case "+":
       
  6871 </xsl:text>
       
  6872           <xsl:text>        new_val = old_val + given_val;
       
  6873 </xsl:text>
       
  6874           <xsl:text>        break;
       
  6875 </xsl:text>
       
  6876           <xsl:text>      case "-":
       
  6877 </xsl:text>
       
  6878           <xsl:text>        new_val = old_val - given_val;
       
  6879 </xsl:text>
       
  6880           <xsl:text>        break;
       
  6881 </xsl:text>
       
  6882           <xsl:text>      case "*":
       
  6883 </xsl:text>
       
  6884           <xsl:text>        new_val = old_val * given_val;
       
  6885 </xsl:text>
       
  6886           <xsl:text>        break;
       
  6887 </xsl:text>
       
  6888           <xsl:text>      case "/":
       
  6889 </xsl:text>
       
  6890           <xsl:text>        new_val = old_val / given_val;
       
  6891 </xsl:text>
       
  6892           <xsl:text>        break;
       
  6893 </xsl:text>
       
  6894           <xsl:text>    }
       
  6895 </xsl:text>
  6970 </xsl:text>
  6896           <xsl:text>    if(new_val != undefined &amp;&amp; old_val != new_val)
  6971           <xsl:text>    if(new_val != undefined &amp;&amp; old_val != new_val)
  6897 </xsl:text>
  6972 </xsl:text>
  6898           <xsl:text>        send_hmi_value(index, new_val);
  6973           <xsl:text>        send_hmi_value(index, new_val);
  6899 </xsl:text>
  6974 </xsl:text>
  6900           <xsl:text>    // TODO else raise
  6975           <xsl:text>    // TODO else raise
  6901 </xsl:text>
  6976 </xsl:text>
  6902           <xsl:text>    return new_val;
  6977           <xsl:text>    return new_val;
  6903 </xsl:text>
  6978 </xsl:text>
  6904           <xsl:text>}
  6979           <xsl:text>}
       
  6980 </xsl:text>
       
  6981           <xsl:text>*/
  6905 </xsl:text>
  6982 </xsl:text>
  6906           <xsl:text>
  6983           <xsl:text>
  6907 </xsl:text>
  6984 </xsl:text>
  6908           <xsl:text>var current_visible_page;
  6985           <xsl:text>var current_visible_page;
  6909 </xsl:text>
  6986 </xsl:text>