diff -r dabad70db1bf -r 15e2df3e5610 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Thu Aug 06 15:01:01 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Sat Aug 08 15:53:28 2020 +0200 @@ -169,14 +169,30 @@ - - - - - - - - + + + + + + + + + + + + + + PAGE_LOCAL + + + + + HMI_LOCAL + + + + + @@ -845,15 +861,35 @@ - - Widget - - id=" - - " : No match for path " - - " in HMI tree - + + + + Widget + + id=" + + " : No match for path " + + " in HMI tree + + + + " + + " + + , + + + + hmi_local_index(" + + ") + + , + + + @@ -905,8 +941,8 @@ - - + + /* @@ -915,6 +951,67 @@ + let hmi_locals = {}; + + var last_remote_index = hmitree_types.length - 1; + + var next_available_index = hmitree_types.length; + + + + function page_local_index(varname, pagename){ + + let pagevars = hmi_locals[pagename]; + + if(pagevars == undefined){ + + let new_index = next_available_index++; + + hmi_locals[pagename] = {varname:new_index} + + return new_index; + + } else { + + let result = pagevars[varname]; + + if(result==undefined){ + + let new_index = next_available_index++; + + pagevars[varname] = new_index; + + return new_index; + + } + + return result; + + } + + } + + + + function hmi_local_index(varname){ + + return page_local_index(varname, "HMI_LOCAL"); + + } + + + + + + + + + /* + + */ + + + class Widget { offset = 0; @@ -965,23 +1062,23 @@ - sub(new_offset=0, relativeness){ + sub(new_offset=0, relativeness, container_id){ this.offset = new_offset; this.relativeness = relativeness; + this.container_id = container_id ; + /* add this's subsribers */ if(!this.unsubscribable) for(let i = 0; i < this.indexes.length; i++) { - let index = this.indexes[i]; - - if(relativeness[i]) - - index += new_offset; + let index = this.get_variable_index(i); + + if(index > last_remote_index) return; subscribers[index].add(this); @@ -995,11 +1092,11 @@ apply_cache() { - if(!this.unsubscribable) for(let index of this.indexes){ + if(!this.unsubscribable) for(let i = 0; i < this.indexes.length; i++) { /* dispatch current cache in newly opened page widgets */ - let realindex = index+this.offset; + let realindex = this.get_variable_index(i); let cached_val = cache[realindex]; @@ -1013,17 +1110,33 @@ - get_idx(index) { - - let orig = this.indexes[index]; - - return this.relativeness[index] ? orig + this.offset : orig; + get_variable_index(varnum) { + + let index = this.indexes[varnum]; + + if(typeof(index) == "string"){ + + let page = this.relativeness[varnum]; + + index = page_local_index(index, this.container_id); + + } else { + + if(this.relativeness[varnum]){ + + index += this.offset; + + } + + } + + return index; } change_hmi_value(index,opstr) { - return change_hmi_value(this.get_idx(index), opstr); + return change_hmi_value(this.get_variable_index(index), opstr); } @@ -1031,7 +1144,7 @@ apply_hmi_value(index, new_val) { - return apply_hmi_value(this.get_idx(0), new_val); + return apply_hmi_value(this.get_variable_index(0), new_val); } @@ -1045,11 +1158,7 @@ for(let i = 0; i < this.indexes.length; i++) { - let refindex = this.indexes[i]; - - if(this.relativeness[i]) - - refindex += this.offset; + let refindex = this.get_variable_index(i); @@ -4056,6 +4165,20 @@ function send_hmi_value(index, value) { + if(index > last_remote_index){ + + cache[index] = value; + + console.log("updated local variable ",index,value); + + /* TODO : dispatch value ASAP */ + + return; + + } + + + let iectype = hmitree_types[index]; let tobinary = typedarray_types[iectype]; @@ -4250,7 +4373,13 @@ var new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index; - new_desc.widgets.map(([widget,relativeness])=>widget.sub(new_offset,relativeness)); + + + container_id = String([page_name, page_index]); + + + + new_desc.widgets.map(([widget,relativeness])=>widget.sub(new_offset,relativeness,container_id));