svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 3103 677764fba71d
parent 3097 a098b2dd9dff
child 3112 bd20f9112014
equal deleted inserted replaced
3102:abb487b56911 3103:677764fba71d
    46       <xsl:value-of select="@index"/>
    46       <xsl:value-of select="@index"/>
    47       <xsl:text>  </xsl:text>
    47       <xsl:text>  </xsl:text>
    48       <xsl:value-of select="@hmipath"/>
    48       <xsl:value-of select="@hmipath"/>
    49       <xsl:text> */ "</xsl:text>
    49       <xsl:text> */ "</xsl:text>
    50       <xsl:value-of select="substring(local-name(), 5)"/>
    50       <xsl:value-of select="substring(local-name(), 5)"/>
    51       <xsl:text>"</xsl:text>
       
    52       <xsl:if test="position()!=last()">
       
    53         <xsl:text>,</xsl:text>
       
    54       </xsl:if>
       
    55       <xsl:text>
       
    56 </xsl:text>
       
    57     </xsl:for-each>
       
    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>
    51       <xsl:text>"</xsl:text>
    72       <xsl:if test="position()!=last()">
    52       <xsl:if test="position()!=last()">
    73         <xsl:text>,</xsl:text>
    53         <xsl:text>,</xsl:text>
    74       </xsl:if>
    54       </xsl:if>
    75       <xsl:text>
    55       <xsl:text>
   976                   <xsl:text>" : No match for path "</xsl:text>
   956                   <xsl:text>" : No match for path "</xsl:text>
   977                   <xsl:value-of select="@value"/>
   957                   <xsl:value-of select="@value"/>
   978                   <xsl:text>" in HMI tree</xsl:text>
   958                   <xsl:text>" in HMI tree</xsl:text>
   979                 </xsl:message>
   959                 </xsl:message>
   980                 <xsl:text>undefined</xsl:text>
   960                 <xsl:text>undefined</xsl:text>
   981                 <xsl:if test="position()!=last()">
       
   982                   <xsl:text>,</xsl:text>
       
   983                 </xsl:if>
       
   984               </xsl:when>
   961               </xsl:when>
   985               <xsl:when test="@type = 'PAGE_LOCAL'">
   962               <xsl:when test="@type = 'PAGE_LOCAL'">
   986                 <xsl:text>"</xsl:text>
   963                 <xsl:text>"</xsl:text>
   987                 <xsl:value-of select="@value"/>
   964                 <xsl:value-of select="@value"/>
   988                 <xsl:text>"</xsl:text>
   965                 <xsl:text>"</xsl:text>
   989                 <xsl:if test="position()!=last()">
       
   990                   <xsl:text>,</xsl:text>
       
   991                 </xsl:if>
       
   992               </xsl:when>
   966               </xsl:when>
   993               <xsl:when test="@type = 'HMI_LOCAL'">
   967               <xsl:when test="@type = 'HMI_LOCAL'">
   994                 <xsl:text>hmi_local_index("</xsl:text>
   968                 <xsl:text>hmi_local_index("</xsl:text>
   995                 <xsl:value-of select="@value"/>
   969                 <xsl:value-of select="@value"/>
   996                 <xsl:text>")</xsl:text>
   970                 <xsl:text>")</xsl:text>
   997                 <xsl:if test="position()!=last()">
       
   998                   <xsl:text>,</xsl:text>
       
   999                 </xsl:if>
       
  1000               </xsl:when>
   971               </xsl:when>
       
   972               <xsl:otherwise>
       
   973                 <xsl:message terminate="yes">
       
   974                   <xsl:text>Internal error while processing widget's non indexed HMI tree path : unknown type</xsl:text>
       
   975                 </xsl:message>
       
   976               </xsl:otherwise>
  1001             </xsl:choose>
   977             </xsl:choose>
  1002           </xsl:when>
   978           </xsl:when>
  1003           <xsl:otherwise>
   979           <xsl:otherwise>
  1004             <xsl:value-of select="@index"/>
   980             <xsl:value-of select="@index"/>
  1005             <xsl:if test="position()!=last()">
       
  1006               <xsl:text>,</xsl:text>
       
  1007             </xsl:if>
       
  1008           </xsl:otherwise>
   981           </xsl:otherwise>
  1009         </xsl:choose>
   982         </xsl:choose>
       
   983         <xsl:if test="position()!=last()">
       
   984           <xsl:text>,</xsl:text>
       
   985         </xsl:if>
       
   986       </xsl:for-each>
       
   987     </xsl:variable>
       
   988     <xsl:variable name="minmaxes">
       
   989       <xsl:for-each select="$widget/path">
       
   990         <xsl:choose>
       
   991           <xsl:when test="@min and @max">
       
   992             <xsl:text>[</xsl:text>
       
   993             <xsl:value-of select="@min"/>
       
   994             <xsl:text>,</xsl:text>
       
   995             <xsl:value-of select="@max"/>
       
   996             <xsl:text>]</xsl:text>
       
   997           </xsl:when>
       
   998           <xsl:otherwise>
       
   999             <xsl:text>undefined</xsl:text>
       
  1000           </xsl:otherwise>
       
  1001         </xsl:choose>
       
  1002         <xsl:if test="position()!=last()">
       
  1003           <xsl:text>,</xsl:text>
       
  1004         </xsl:if>
  1010       </xsl:for-each>
  1005       </xsl:for-each>
  1011     </xsl:variable>
  1006     </xsl:variable>
  1012     <xsl:text>  "</xsl:text>
  1007     <xsl:text>  "</xsl:text>
  1013     <xsl:value-of select="@id"/>
  1008     <xsl:value-of select="@id"/>
  1014     <xsl:text>": new </xsl:text>
  1009     <xsl:text>": new </xsl:text>
  1017     <xsl:value-of select="@id"/>
  1012     <xsl:value-of select="@id"/>
  1018     <xsl:text>",[</xsl:text>
  1013     <xsl:text>",[</xsl:text>
  1019     <xsl:value-of select="$args"/>
  1014     <xsl:value-of select="$args"/>
  1020     <xsl:text>],[</xsl:text>
  1015     <xsl:text>],[</xsl:text>
  1021     <xsl:value-of select="$indexes"/>
  1016     <xsl:value-of select="$indexes"/>
       
  1017     <xsl:text>],[</xsl:text>
       
  1018     <xsl:value-of select="$minmaxes"/>
  1022     <xsl:text>],{
  1019     <xsl:text>],{
  1023 </xsl:text>
  1020 </xsl:text>
  1024     <xsl:apply-templates mode="widget_defs" select="$widget">
  1021     <xsl:apply-templates mode="widget_defs" select="$widget">
  1025       <xsl:with-param name="hmi_element" select="."/>
  1022       <xsl:with-param name="hmi_element" select="."/>
  1026     </xsl:apply-templates>
  1023     </xsl:apply-templates>
  1176 </xsl:text>
  1173 </xsl:text>
  1177     <xsl:text>    pending_animate = false;
  1174     <xsl:text>    pending_animate = false;
  1178 </xsl:text>
  1175 </xsl:text>
  1179     <xsl:text>
  1176     <xsl:text>
  1180 </xsl:text>
  1177 </xsl:text>
  1181     <xsl:text>    constructor(elt_id,args,indexes,members){
  1178     <xsl:text>    constructor(elt_id,args,indexes,minmaxes,members){
  1182 </xsl:text>
  1179 </xsl:text>
  1183     <xsl:text>        this.element_id = elt_id;
  1180     <xsl:text>        this.element_id = elt_id;
  1184 </xsl:text>
  1181 </xsl:text>
  1185     <xsl:text>        this.element = id(elt_id);
  1182     <xsl:text>        this.element = id(elt_id);
  1186 </xsl:text>
  1183 </xsl:text>
  1187     <xsl:text>        this.args = args;
  1184     <xsl:text>        this.args = args;
  1188 </xsl:text>
  1185 </xsl:text>
  1189     <xsl:text>        this.indexes = indexes;
  1186     <xsl:text>        this.indexes = indexes;
  1190 </xsl:text>
  1187 </xsl:text>
       
  1188     <xsl:text>        this.minmaxes = minmaxes;
       
  1189 </xsl:text>
  1191     <xsl:text>        Object.keys(members).forEach(prop =&gt; this[prop]=members[prop]);
  1190     <xsl:text>        Object.keys(members).forEach(prop =&gt; this[prop]=members[prop]);
  1192 </xsl:text>
  1191 </xsl:text>
  1193     <xsl:text>    }
  1192     <xsl:text>    }
  1194 </xsl:text>
  1193 </xsl:text>
  1195     <xsl:text>
  1194     <xsl:text>
  1274 </xsl:text>
  1273 </xsl:text>
  1275     <xsl:text>        let index = this.indexes[varnum];
  1274     <xsl:text>        let index = this.indexes[varnum];
  1276 </xsl:text>
  1275 </xsl:text>
  1277     <xsl:text>        if(typeof(index) == "string"){
  1276     <xsl:text>        if(typeof(index) == "string"){
  1278 </xsl:text>
  1277 </xsl:text>
  1279     <xsl:text>            /* XXX return index as path */
       
  1280 </xsl:text>
       
  1281     <xsl:text>            index = page_local_index(index, this.container_id);
  1278     <xsl:text>            index = page_local_index(index, this.container_id);
  1282 </xsl:text>
  1279 </xsl:text>
  1283     <xsl:text>        } else {
  1280     <xsl:text>        } else {
  1284 </xsl:text>
  1281 </xsl:text>
  1285     <xsl:text>            if(this.relativeness[varnum]){
  1282     <xsl:text>            if(this.relativeness[varnum]){
  1286 </xsl:text>
  1283 </xsl:text>
  1287     <xsl:text>                index += this.offset;
  1284     <xsl:text>                index += this.offset;
  1288 </xsl:text>
  1285 </xsl:text>
  1289     <xsl:text>            }
  1286     <xsl:text>            }
  1290 </xsl:text>
  1287 </xsl:text>
  1291     <xsl:text>            /* XXX check for hmi_paths and return path */
       
  1292 </xsl:text>
       
  1293     <xsl:text>        }
  1288     <xsl:text>        }
  1294 </xsl:text>
  1289 </xsl:text>
  1295     <xsl:text>        return index;
  1290     <xsl:text>        return index;
  1296 </xsl:text>
  1291 </xsl:text>
  1297     <xsl:text>    }
  1292     <xsl:text>    }
  1298 </xsl:text>
  1293 </xsl:text>
  1299     <xsl:text>
  1294     <xsl:text>
  1300 </xsl:text>
  1295 </xsl:text>
       
  1296     <xsl:text>    overshot(new_val, max) {
       
  1297 </xsl:text>
       
  1298     <xsl:text>        // TODO: use a Toast
       
  1299 </xsl:text>
       
  1300     <xsl:text>    }
       
  1301 </xsl:text>
       
  1302     <xsl:text>
       
  1303 </xsl:text>
       
  1304     <xsl:text>    undershot(new_val, min) {
       
  1305 </xsl:text>
       
  1306     <xsl:text>        // TODO: use a Toast
       
  1307 </xsl:text>
       
  1308     <xsl:text>    }
       
  1309 </xsl:text>
       
  1310     <xsl:text>
       
  1311 </xsl:text>
       
  1312     <xsl:text>    clip_min_max(index, new_val) {
       
  1313 </xsl:text>
       
  1314     <xsl:text>        let minmax = this.minmaxes[index];
       
  1315 </xsl:text>
       
  1316     <xsl:text>        if(minmax !== undefined &amp;&amp; typeof new_val == "number") {
       
  1317 </xsl:text>
       
  1318     <xsl:text>            let [min,max] = minmax;
       
  1319 </xsl:text>
       
  1320     <xsl:text>            if(new_val &lt; min){
       
  1321 </xsl:text>
       
  1322     <xsl:text>                this.undershot(new_val, min);
       
  1323 </xsl:text>
       
  1324     <xsl:text>                return min;
       
  1325 </xsl:text>
       
  1326     <xsl:text>            }
       
  1327 </xsl:text>
       
  1328     <xsl:text>            if(new_val &gt; max){
       
  1329 </xsl:text>
       
  1330     <xsl:text>                this.overshot(new_val, max);
       
  1331 </xsl:text>
       
  1332     <xsl:text>                return max;
       
  1333 </xsl:text>
       
  1334     <xsl:text>            }
       
  1335 </xsl:text>
       
  1336     <xsl:text>        }
       
  1337 </xsl:text>
       
  1338     <xsl:text>        return new_val;
       
  1339 </xsl:text>
       
  1340     <xsl:text>    }
       
  1341 </xsl:text>
       
  1342     <xsl:text>
       
  1343 </xsl:text>
  1301     <xsl:text>    change_hmi_value(index, opstr) {
  1344     <xsl:text>    change_hmi_value(index, opstr) {
  1302 </xsl:text>
  1345 </xsl:text>
  1303     <xsl:text>        let realindex = this.get_variable_index(index);
  1346     <xsl:text>        let realindex = this.get_variable_index(index);
  1304 </xsl:text>
  1347 </xsl:text>
  1305     <xsl:text>        if(realindex == undefined) return undefined;
  1348     <xsl:text>        if(realindex == undefined) return undefined;
  1306 </xsl:text>
  1349 </xsl:text>
  1307     <xsl:text>        let old_val = cache[realindex];
  1350     <xsl:text>        let old_val = cache[realindex];
  1308 </xsl:text>
  1351 </xsl:text>
  1309     <xsl:text>        let new_val = eval_operation_string(old_val, opstr);
  1352     <xsl:text>        let new_val = eval_operation_string(old_val, opstr);
  1310 </xsl:text>
  1353 </xsl:text>
       
  1354     <xsl:text>        new_val = this.clip_min_max(index, new_val);
       
  1355 </xsl:text>
  1311     <xsl:text>        return apply_hmi_value(realindex, new_val);
  1356     <xsl:text>        return apply_hmi_value(realindex, new_val);
  1312 </xsl:text>
  1357 </xsl:text>
  1313     <xsl:text>    }
  1358     <xsl:text>    }
  1314 </xsl:text>
  1359 </xsl:text>
  1315     <xsl:text>
  1360     <xsl:text>
  1317     <xsl:text>    apply_hmi_value(index, new_val) {
  1362     <xsl:text>    apply_hmi_value(index, new_val) {
  1318 </xsl:text>
  1363 </xsl:text>
  1319     <xsl:text>        let realindex = this.get_variable_index(index);
  1364     <xsl:text>        let realindex = this.get_variable_index(index);
  1320 </xsl:text>
  1365 </xsl:text>
  1321     <xsl:text>        if(realindex == undefined) return undefined;
  1366     <xsl:text>        if(realindex == undefined) return undefined;
       
  1367 </xsl:text>
       
  1368     <xsl:text>        new_val = this.clip_min_max(index, new_val);
  1322 </xsl:text>
  1369 </xsl:text>
  1323     <xsl:text>        return apply_hmi_value(realindex, new_val);
  1370     <xsl:text>        return apply_hmi_value(realindex, new_val);
  1324 </xsl:text>
  1371 </xsl:text>
  1325     <xsl:text>    }
  1372     <xsl:text>    }
  1326 </xsl:text>
  1373 </xsl:text>
  4066 </xsl:text>
  4113 </xsl:text>
  4067     <xsl:text>             this.apply_hmi_value(0, new_val);
  4114     <xsl:text>             this.apply_hmi_value(0, new_val);
  4068 </xsl:text>
  4115 </xsl:text>
  4069     <xsl:text>         }
  4116     <xsl:text>         }
  4070 </xsl:text>
  4117 </xsl:text>
       
  4118     <xsl:text>
       
  4119 </xsl:text>
       
  4120     <xsl:text>         overshot(new_val, max) {
       
  4121 </xsl:text>
       
  4122     <xsl:text>             this.last_display = "max: "+max;
       
  4123 </xsl:text>
       
  4124     <xsl:text>             this.request_animate();
       
  4125 </xsl:text>
       
  4126     <xsl:text>         }
       
  4127 </xsl:text>
       
  4128     <xsl:text>
       
  4129 </xsl:text>
       
  4130     <xsl:text>         undershot(new_val, min) {
       
  4131 </xsl:text>
       
  4132     <xsl:text>             this.last_display = "min: "+min;
       
  4133 </xsl:text>
       
  4134     <xsl:text>             this.request_animate();
       
  4135 </xsl:text>
       
  4136     <xsl:text>         }
       
  4137 </xsl:text>
       
  4138     <xsl:text>
       
  4139 </xsl:text>
       
  4140     <xsl:text>
       
  4141 </xsl:text>
  4071     <xsl:text>    }
  4142     <xsl:text>    }
  4072 </xsl:text>
  4143 </xsl:text>
  4073   </xsl:template>
  4144   </xsl:template>
  4074   <xsl:template mode="widget_defs" match="widget[@type='Input']">
  4145   <xsl:template mode="widget_defs" match="widget[@type='Input']">
  4075     <xsl:param name="hmi_element"/>
  4146     <xsl:param name="hmi_element"/>
  4114     <xsl:if test="$have_edit">
  4185     <xsl:if test="$have_edit">
  4115       <xsl:text>        this.last_val = value;
  4186       <xsl:text>        this.last_val = value;
  4116 </xsl:text>
  4187 </xsl:text>
  4117     </xsl:if>
  4188     </xsl:if>
  4118     <xsl:if test="$have_value">
  4189     <xsl:if test="$have_value">
  4119       <xsl:text>        this.value_elt.textContent = String(value);
  4190       <xsl:text>        this.last_display = value;
       
  4191 </xsl:text>
       
  4192       <xsl:text>        this.request_animate();
  4120 </xsl:text>
  4193 </xsl:text>
  4121     </xsl:if>
  4194     </xsl:if>
  4122     <xsl:text>    },
  4195     <xsl:text>    },
  4123 </xsl:text>
  4196 </xsl:text>
       
  4197     <xsl:if test="$have_value">
       
  4198       <xsl:text>    animate: function(){
       
  4199 </xsl:text>
       
  4200       <xsl:text>        this.value_elt.textContent = String(this.last_display);
       
  4201 </xsl:text>
       
  4202       <xsl:text>    },
       
  4203 </xsl:text>
       
  4204     </xsl:if>
  4124     <xsl:text>    init: function() {
  4205     <xsl:text>    init: function() {
  4125 </xsl:text>
  4206 </xsl:text>
  4126     <xsl:if test="$have_edit">
  4207     <xsl:if test="$have_edit">
  4127       <xsl:text>        this.edit_elt.onclick = () =&gt; edit_value(
  4208       <xsl:text>        this.edit_elt.onclick = () =&gt; edit_value(
  4128 </xsl:text>
  4209 </xsl:text>
  5137 </xsl:text>
  5218 </xsl:text>
  5138     <xsl:text>             this.Value_elt.textContent = this.editstr;
  5219     <xsl:text>             this.Value_elt.textContent = this.editstr;
  5139 </xsl:text>
  5220 </xsl:text>
  5140     <xsl:text>         }
  5221     <xsl:text>         }
  5141 </xsl:text>
  5222 </xsl:text>
  5142     <xsl:text>         if(this.shift != this._shift){
  5223     <xsl:text>         if(this.Shift_sub &amp;&amp; this.shift != this._shift){
  5143 </xsl:text>
  5224 </xsl:text>
  5144     <xsl:text>             this._shift = this.shift;
  5225     <xsl:text>             this._shift = this.shift;
  5145 </xsl:text>
  5226 </xsl:text>
  5146     <xsl:text>             (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub);
  5227     <xsl:text>             (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub);
  5147 </xsl:text>
  5228 </xsl:text>
  5148     <xsl:text>         }
  5229     <xsl:text>         }
  5149 </xsl:text>
  5230 </xsl:text>
  5150     <xsl:text>         if(this.caps != this._caps){
  5231     <xsl:text>         if(this.CapsLock_sub &amp;&amp; this.caps != this._caps){
  5151 </xsl:text>
  5232 </xsl:text>
  5152     <xsl:text>             this._caps = this.caps;
  5233     <xsl:text>             this._caps = this.caps;
  5153 </xsl:text>
  5234 </xsl:text>
  5154     <xsl:text>             (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub);
  5235     <xsl:text>             (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub);
  5155 </xsl:text>
  5236 </xsl:text>