diff -r 5d9ae04ee50f -r bd20f9112014 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Jan 18 10:32:13 2021 +0100 +++ b/svghmi/gen_index_xhtml.xslt Tue Jan 19 11:57:13 2021 +0100 @@ -1,6 +1,6 @@ - - + + @@ -573,22 +573,14 @@ jumps: [ - - - - - - - - hmi_widgets[" - - "] - - , - - - + hmi_widgets[" + + "] + + , + + ], @@ -706,6 +698,11 @@ All units must be set to "px" in Inkscape's document properties + + + + + @@ -929,6 +926,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + /* + + */ + + + + + var translations = { + + + " + + ":{ + + } + + , + + + + + }; + + + + + + @@ -1295,16 +1346,12 @@ overshot(new_val, max) { - // TODO: use a Toast - } undershot(new_val, min) { - // TODO: use a Toast - } @@ -2023,9 +2070,19 @@ dispatch(value) { + this.display_val = value; + + this.request_animate(); + + } + + + + animate(){ + if(this.value_elt) - this.value_elt.textContent = String(value); + this.value_elt.textContent = String(this.display_val); let [min,max,start,end] = this.range; @@ -2033,21 +2090,29 @@ let [rx,ry] = this.proportions; - let tip = start + (end-start)*Number(value)/(max-min); + let tip = start + (end-start)*Number(this.display_val)/(max-min); let size = 0; - if (tip-start > Math.PI) { + + + if (tip-start > Math.PI) size = 1; - } else { + else size = 0; - } - - this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+" A "+rx+","+ry+" 0 "+size+" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip))); + + + this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+ + + " A "+rx+","+ry+ + + " 0 "+size+ + + " 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip))); } @@ -2055,41 +2120,31 @@ init() { - let start = Number(this.path_elt.getAttribute('sodipodi:start')); - - let end = Number(this.path_elt.getAttribute('sodipodi:end')); - - let cx = Number(this.path_elt.getAttribute('sodipodi:cx')); - - let cy = Number(this.path_elt.getAttribute('sodipodi:cy')); - - let rx = Number(this.path_elt.getAttribute('sodipodi:rx')); - - let ry = Number(this.path_elt.getAttribute('sodipodi:ry')); - - if (ry == 0) { + let [start, end, cx, cy, rx, ry] = ["start", "end", "cx", "cy", "rx", "ry"]. + + map(tag=>Number(this.path_elt.getAttribute('sodipodi:'+tag))) + + + + if (ry == 0) ry = rx; - } - - if (start > end) { + + + if (start > end) end = end + 2*Math.PI; - } - - let min = this.min_elt ? - - Number(this.min_elt.textContent) : - - this.args.length >= 1 ? this.args[0] : 0; - - let max = this.max_elt ? - - Number(this.max_elt.textContent) : - - this.args.length >= 2 ? this.args[1] : 100; + + + let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? + + Number(elt.textContent) : + + this.args.length >= i+1 ? this.args[i] : def); + + this.range = [min, max, start, end]; @@ -2117,8 +2172,6 @@ - - class CircularSliderWidget extends Widget{ @@ -3835,10 +3888,10 @@ text box button highlight - // It is assumed that list content conforms to Array interface. - content: [ + /* TODO : Support HMI:List */ + " @@ -4638,142 +4691,146 @@ } - - - - - - active inactive - - - - - - - - - - disabled - - - + + class JumpWidget extends Widget{ + + + + activable = false; + + active = false; + + disabled = false; + + frequency = 2; + + + + update_activity() { + + if(this.active) { + + /* show active */ + + this.active_elt.setAttribute("style", this.active_elt_style); + + /* hide inactive */ + + this.inactive_elt.setAttribute("style", "display:none"); + + } else { + + /* show inactive */ + + this.inactive_elt.setAttribute("style", this.inactive_elt_style); + + /* hide active */ + + this.active_elt.setAttribute("style", "display:none"); + + } + + } + + + + make_on_click() { + + let that = this; + + const name = this.args[0]; + + return function(evt){ + + /* TODO: suport path pointing to local variable whom value + + would be an HMI_TREE index to jump to a relative page */ + + const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined; + + switch_page(name, index); + + } + + } + + + + notify_page_change(page_name, index) { + + if(this.activable) { + + const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; + + const ref_name = this.args[0]; + + this.active = ((ref_name == undefined || ref_name == page_name) && index == ref_index); + + this.update_activity(); + + } + + } + + + + dispatch(value) { + + this.disabled = !Number(value); + + if(this.disabled) { + + /* show disabled */ + + this.disabled_elt.setAttribute("style", this.disabled_elt_style); + + /* hide inactive */ + + this.inactive_elt.setAttribute("style", "display:none"); + + /* hide active */ + + this.active_elt.setAttribute("style", "display:none"); + + } else { + + /* hide disabled */ + + this.disabled_elt.setAttribute("style", "display:none"); + + this.update_activity(); + + } + + } + + } + - + + + active inactive + + - + + + disabled + + - - active: false, - - - disabled: false, - - frequency: 2, - - dispatch: function(value) { - - this.disabled = !Number(value); - - this.update(); - - }, - - - update: function(){ - - - if(this.disabled) { - - /* show disabled */ - - this.disabled_elt.setAttribute("style", this.active_elt_style); - - /* hide inactive */ - - this.inactive_elt.setAttribute("style", "display:none"); - - /* hide active */ - - this.active_elt.setAttribute("style", "display:none"); - - } else { - - /* hide disabled */ - - this.disabled_elt.setAttribute("style", "display:none"); - - - if(this.active) { - - /* show active */ - - this.active_elt.setAttribute("style", this.active_elt_style); - - /* hide inactive */ - - this.inactive_elt.setAttribute("style", "display:none"); - - } else { - - /* show inactive */ - - this.inactive_elt.setAttribute("style", this.inactive_elt_style); - - /* hide active */ - - this.active_elt.setAttribute("style", "display:none"); - - } - - - } - - - }, - - - - notify_page_change: function(page_name, index){ - - const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; - - const ref_name = this.args[0]; - - this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index); - - this.update(); - - }, - - - make_on_click(){ - - let that = this; - - const name = this.args[0]; - - return function(evt){ - - const index = that.indexes.length > 0 ? that.indexes[0] + that.offset : undefined; - - switch_page(name, index); - - } - - }, - init: function() { this.element.onclick = this.make_on_click(); @@ -4783,6 +4840,8 @@ this.inactive_elt_style = this.inactive_elt.getAttribute("style"); + this.activable = true; + @@ -5360,13 +5419,23 @@ dispatch(value) { + this.display_val = value; + + this.request_animate(); + + } + + + + animate(){ + if(this.value_elt) - this.value_elt.textContent = String(value); + this.value_elt.textContent = String(this.display_val); let [min,max,totallength] = this.range; - let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); + let length = Math.max(0,Math.min(totallength,(Number(this.display_val)-min)*totallength/(max-min))); let tip = this.range_elt.getPointAtLength(length); @@ -5378,17 +5447,13 @@ init() { - let min = this.min_elt ? - - Number(this.min_elt.textContent) : - - this.args.length >= 1 ? this.args[0] : 0; - - let max = this.max_elt ? - - Number(this.max_elt.textContent) : - - this.args.length >= 2 ? this.args[1] : 100; + let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? + + Number(elt.textContent) : + + this.args.length >= i+1 ? this.args[i] : def); + + this.range = [min, max, this.range_elt.getTotalLength()] @@ -5416,8 +5481,6 @@ - - class MultiStateWidget extends Widget{ @@ -6396,7 +6459,7 @@ - +