--- a/svghmi/gen_index_xhtml.xslt Wed Aug 12 15:24:02 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Thu Aug 13 11:30:18 2020 +0200
@@ -875,7 +875,7 @@
<xsl:when test="@type = 'PAGE_LOCAL'">
- <xsl:value-of select="substring(@value, 1)"/>
+ <xsl:value-of select="@value"/> <xsl:if test="position()!=last()">
@@ -976,9 +976,10 @@
<xsl:text> only applies to HMI variable.</xsl:text>
- <xsl:value-of select="arg[0]"/>
<xsl:value-of select="path/@value"/>
+ <xsl:text>":</xsl:text> + <xsl:value-of select="arg[1]/@value"/> <xsl:if test="position()!=last()">
@@ -1021,6 +1022,14 @@
+ <xsl:text> let defaultval = local_defaults[varname]; + <xsl:text> console.log("page_local_index creat local", varname, pagename, new_index, defaultval); + <xsl:text> if(defaultval != undefined) + <xsl:text> cache[new_index] = defaultval; <xsl:text> return new_index;
@@ -1132,7 +1141,11 @@
<xsl:text> apply_cache() {
- <xsl:text> if(!this.unsubscribable) for(let index of this.indexes){
+ <xsl:text> let dispatch = this.dispatch; + <xsl:text> if(dispatch == undefined) return; + <xsl:text> if(!this.unsubscribable) for(let index in this.indexes){ <xsl:text> /* dispatch current cache in newly opened page widgets */
@@ -1142,7 +1155,15 @@
<xsl:text> if(cached_val != undefined)
- <xsl:text> this.new_hmi_value(realindex, cached_val, cached_val);
+ <xsl:text> dispatch.call(this, cached_val, cached_val, index); + <xsl:text> } catch(err) { + <xsl:text> console.log(err); @@ -1190,50 +1211,34 @@
<xsl:text> new_hmi_value(index, value, oldval) {
- <xsl:text> // TODO avoid searching, store index at sub()
- <xsl:text> for(let i = 0; i < this.indexes.length; i++) {
- <xsl:text> let refindex = this.get_variable_index(i);
- <xsl:text> if(index == refindex) {
- <xsl:text> let d = this.dispatch;
- <xsl:text> if(typeof(d) == "function"){
- <xsl:text> d.call(this, value, oldval, i);
- <xsl:text> else if(typeof(d) == "object"){
- <xsl:text> d[i].call(this, value, oldval);
- <xsl:text> /* else dispatch_0, ..., dispatch_n ? */
- <xsl:text> throw new Error("Dunno how to dispatch to widget at index = " + index);
+ <xsl:text> // TODO avoid searching, store index at sub() + <xsl:text> let dispatch = this.dispatch; + <xsl:text> if(dispatch == undefined) return; + <xsl:text> for(let i = 0; i < this.indexes.length; i++) { + <xsl:text> let refindex = this.get_variable_index(i); + <xsl:text> if(index == refindex) { + <xsl:text> dispatch.call(this, value, oldval, i); + <xsl:text> } catch(err) { + <xsl:text> console.log(err); - <xsl:text> } catch(err) {
- <xsl:text> console.log(err);
--- a/svghmi/widgets_common.ysl2 Wed Aug 12 15:24:02 2020 +0200
+++ b/svghmi/widgets_common.ysl2 Thu Aug 13 11:30:18 2020 +0200
@@ -32,7 +32,7 @@
error > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
when "@type = 'PAGE_LOCAL'"
- > "«substring(@value, 1)»"`if "position()!=last()" > ,`
+ > "«@value»"`if "position()!=last()" > ,` when "@type = 'HMI_LOCAL'"
> hmi_local_index("«@value»")`if "position()!=last()" > ,`
@@ -75,6 +75,15 @@
var last_remote_index = hmitree_types.length - 1;
var next_available_index = hmitree_types.length;
+ const local_defaults = { + foreach "$parsed_widgets/widget[@type = 'VarInit']"{ + if "count(path) != 1" error > VarInit «@id» must have only one variable given. + if "path/@type != 'PAGE_LOCAL' and path/@type != 'HMI_LOCAL'" error > VarInit «@id» only applies to HMI variable. + | "«path/@value»":«arg[1]/@value»`if "position()!=last()" > ,` var cache = hmitree_types.map(_ignored => undefined);
function page_local_index(varname, pagename){
@@ -92,6 +101,9 @@
new_index = next_available_index++;
pagevars[varname] = new_index;
+ let defaultval = local_defaults[varname]; + if(defaultval != undefined) + cache[new_index] = defaultval; @@ -146,12 +158,18 @@
- if(!this.unsubscribable) for(let index of this.indexes){
+ let dispatch = this.dispatch; + if(dispatch == undefined) return; + if(!this.unsubscribable) for(let index in this.indexes){ /* dispatch current cache in newly opened page widgets */
let realindex = this.get_variable_index(index);
let cached_val = cache[realindex];
if(cached_val != undefined)
- this.new_hmi_value(realindex, cached_val, cached_val);
+ dispatch.call(this, cached_val, cached_val, index); @@ -175,28 +193,20 @@
new_hmi_value(index, value, oldval) {
- // TODO avoid searching, store index at sub()
- for(let i = 0; i < this.indexes.length; i++) {
- let refindex = this.get_variable_index(i);
+ // TODO avoid searching, store index at sub() + let dispatch = this.dispatch; + if(dispatch == undefined) return; + for(let i = 0; i < this.indexes.length; i++) { + let refindex = this.get_variable_index(i); - if(index == refindex) {
- if(typeof(d) == "function"){
- d.call(this, value, oldval, i);
- else if(typeof(d) == "object"){
- d[i].call(this, value, oldval);
- /* else dispatch_0, ..., dispatch_n ? */
- throw new Error("Dunno how to dispatch to widget at index = " + index);
+ if(index == refindex) { + dispatch.call(this, value, oldval, i);
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed Aug 12 15:24:02 2020 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu Aug 13 11:30:18 2020 +0200
@@ -182,12 +182,12 @@
inkscape:document-units="px"
- inkscape:current-layer="g5231"
+ inkscape:current-layer="hmi0" - inkscape:zoom="0.35355339"
- inkscape:cx="228.48319"
- inkscape:cy="161.32426"
+ inkscape:cx="840.93557" + inkscape:cy="117.51363" inkscape:window-width="1800"
inkscape:window-height="836"
@@ -5722,8 +5722,11 @@
id="tspan1611-1">PAGE_LOCAL variables</tspan></text>
- inkscape:label="HMI:VariableInit:42@level" />
+ inkscape:label="HMI:VarInit:42@level" /> - inkscape:label="HMI:VariableInit:"a string"@paff"
+ inkscape:label="HMI:VarInit:"a string"@paff" + inkscape:label="HMI:VarInit:"a page string"@.piff" />