Edouard@2753: edouard@2994: edouard@2994: edouard@2941: Edouard@2879: Edouard@2877: Edouard@2790: Edouard@2790: Edouard@2790: HMI_PLC_STATUS Edouard@2790: Edouard@2790: Edouard@2790: HMI_CURRENT_PAGE Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2867: Edouard@2867: Edouard@2867: Edouard@2867: edouard@2941: edouard@2941: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2941: var hmi_hash = [ edouard@2941: edouard@2941: ]; edouard@2941: edouard@2941: edouard@2941: edouard@2941: var heartbeat_index = edouard@2941: edouard@2941: ; edouard@2941: edouard@2941: edouard@2941: edouard@2941: var hmitree_types = [ edouard@2941: edouard@2941: edouard@2941: /* edouard@2941: edouard@2941: edouard@2941: edouard@2941: */ " edouard@2941: edouard@2941: " edouard@2941: edouard@2941: , edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2941: ] edouard@2941: edouard@2941: edouard@2941: edouard@2949: edouard@2949: edouard@2941: Edouard@2791: Edouard@2790: Edouard@2791: Edouard@2790: Edouard@2791: Edouard@2791: edouard@2890: edouard@2890: / edouard@2890: edouard@2890: edouard@2890: / edouard@2890: Edouard@2791: Edouard@2791: Edouard@2791: Edouard@2791: / Edouard@2791: Edouard@2791: Edouard@2791: Edouard@2791: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2791: Edouard@2791: Edouard@2791: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2867: Edouard@2867: Edouard@2867: Edouard@2867: Edouard@2867: Edouard@2867: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2791: Edouard@2791: Edouard@2791: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2790: Edouard@2791: Edouard@2791: Edouard@2791: Edouard@2790: Edouard@2790: edouard@2886: edouard@2886: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: Edouard@2792: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: Edouard@2793: Edouard@2793: Edouard@2793: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: Edouard@2869: Edouard@2913: Edouard@2913: Edouard@2913: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: edouard@2886: Edouard@2885: edouard@2894: edouard@2894: edouard@2894: edouard@2894: edouard@2894: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: =" Edouard@2877: Edouard@2877: " Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: edouard@2940: edouard@2940: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: Edouard@2877: Raw HMI tree Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Indexed HMI tree Edouard@2877: Edouard@2877: edouard@2886: edouard@2886: edouard@2886: Parsed Widgets edouard@2886: edouard@2886: edouard@2886: edouard@2949: edouard@2949: Edouard@2877: Edouard@2877: edouard@2939: edouard@2940: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: Edouard@2877: ID, x, y, w, h Edouard@2877: Edouard@2879: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: edouard@2949: edouard@2949: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2887: Edouard@2887: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2887: Edouard@2877: Home Edouard@2877: Edouard@2877: Edouard@2877: No Home page defined! Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: No page defined! Edouard@2877: Edouard@2877: edouard@2886: Edouard@2877: Edouard@2877: Edouard@2877: edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2941: var default_page = " edouard@2941: edouard@2941: "; edouard@2941: edouard@2949: edouard@2949: edouard@2941: edouard@2941: edouard@2941: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2913: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2913: Edouard@2877: edouard@2943: edouard@2943: edouard@2941: edouard@2941: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2941: var detachable_elements = { edouard@2941: edouard@2941: edouard@2941: " edouard@2941: edouard@2941: ":[id(" edouard@2941: edouard@2941: "), id(" edouard@2941: edouard@2941: ")] edouard@2941: edouard@2941: , edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2941: } edouard@2941: edouard@2949: edouard@2949: edouard@2941: Edouard@2888: Edouard@2888: Edouard@2888: Edouard@2877: edouard@2886: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2877: Edouard@2877: " Edouard@2877: Edouard@2877: ": { Edouard@2877: Edouard@2877: bbox: [ Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: ], Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Page id=" Edouard@2877: Edouard@2877: " : No match for path " Edouard@2877: Edouard@2877: " in HMI tree Edouard@2877: Edouard@2877: Edouard@2877: page_index: Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: Edouard@2877: relative_widgets: [ Edouard@2877: Edouard@2877: Edouard@2877: hmi_widgets[" Edouard@2877: Edouard@2877: "] Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: ], Edouard@2877: Edouard@2877: absolute_widgets: [ Edouard@2877: Edouard@2901: Edouard@2877: hmi_widgets[" Edouard@2877: Edouard@2877: "] Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: ], Edouard@2877: Edouard@2903: jumps: [ Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: hmi_widgets[" Edouard@2903: Edouard@2903: "] Edouard@2903: Edouard@2903: , Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: ], Edouard@2903: Edouard@2877: required_detachables: { Edouard@2877: Edouard@2877: Edouard@2877: " Edouard@2877: Edouard@2877: ": detachable_elements[" Edouard@2877: Edouard@2877: "] Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: } Edouard@2877: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2877: } Edouard@2877: Edouard@2877: , Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: edouard@2943: edouard@2943: edouard@2941: edouard@2941: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2941: var page_desc = { edouard@2941: edouard@2941: edouard@2941: } edouard@2941: edouard@2949: edouard@2949: edouard@2941: Edouard@2901: edouard@2939: edouard@2940: edouard@2941: edouard@2941: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: Edouard@2888: DETACHABLES: Edouard@2888: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2888: In Foreach: Edouard@2888: Edouard@2888: Edouard@2888: Edouard@2888: Edouard@2888: Edouard@2888: Edouard@2888: edouard@2949: edouard@2949: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: none Edouard@2877: Edouard@2877: Edouard@2877: 100vh Edouard@2877: Edouard@2877: Edouard@2877: 100vw Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: ViewBox settings other than X=0, Y=0 and Scale=1 are not supported Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: All units must be set to "px" in Inkscape's document properties Edouard@2877: Edouard@2877: edouard@2996: edouard@2996: edouard@2996: edouard@2996: Edouard@2877: edouard@2996: Edouard@2877: edouard@2996: edouard@2996: edouard@2996: edouard@2996: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: href Edouard@2877: Edouard@2877: Edouard@2877: width Edouard@2877: Edouard@2877: Edouard@2877: height Edouard@2877: Edouard@2877: Edouard@2877: x Edouard@2877: Edouard@2877: Edouard@2877: y Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2969: Edouard@2969: Edouard@2969: transform Edouard@2969: Edouard@2969: Edouard@2969: style Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2877: edouard@2996: Edouard@2969: Edouard@2877: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: ; Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2969: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: _ Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: Edouard@2877: edouard@2941: edouard@2941: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2941: let id = document.getElementById.bind(document); edouard@2941: edouard@2941: var svg_root = id(" edouard@2941: edouard@2941: "); edouard@2941: edouard@2949: edouard@2949: edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2904: Unlinked : edouard@2904: Edouard@2878: Edouard@2878: Edouard@2878: Edouard@2878: Edouard@2878: edouard@2996: Not to unlink : edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2949: edouard@2949: Edouard@2878: edouard@2955: edouard@2886: Edouard@2881: edouard@2954: edouard@2954: edouard@2954: " edouard@2954: edouard@2954: " edouard@2954: edouard@2954: , edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: Widget edouard@2954: edouard@2954: id=" edouard@2954: edouard@2954: " : No match for path " edouard@2954: edouard@2954: " in HMI tree edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: , edouard@2954: edouard@2954: edouard@2954: edouard@2954: edouard@2954: Edouard@2881: " Edouard@2881: edouard@2949: ": new Edouard@2881: edouard@2954: Widget (" Edouard@2881: edouard@2954: ",[ edouard@2954: edouard@2954: ],[ edouard@2954: edouard@2954: ],{ Edouard@2881: Edouard@2881: Edouard@2881: Edouard@2881: edouard@2949: }) Edouard@2881: Edouard@2881: , Edouard@2881: Edouard@2881: Edouard@2793: Edouard@2792: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: class Widget { edouard@2949: edouard@2962: offset = 0; edouard@2962: edouard@2962: frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ edouard@2962: Edouard@2980: unsubscribable = false; Edouard@2980: edouard@2954: constructor(elt_id,args,indexes,members){ edouard@2954: edouard@2961: this.element_id = elt_id; edouard@2961: edouard@2954: this.element = id(elt_id); edouard@2954: edouard@2954: this.args = args; edouard@2954: edouard@2954: this.indexes = indexes; edouard@2954: edouard@2949: Object.keys(members).forEach(prop => this[prop]=members[prop]); edouard@2949: edouard@2949: } edouard@2949: edouard@2961: edouard@2961: edouard@2954: unsub(){ edouard@2954: edouard@2954: /* remove subsribers */ edouard@2954: Edouard@2980: if(!this.unsubscribable) for(let index of this.indexes){ edouard@2954: edouard@2954: let idx = index + this.offset; edouard@2954: edouard@2954: subscribers[idx].delete(this); edouard@2954: edouard@2954: } edouard@2954: edouard@2954: this.offset = 0; edouard@2954: edouard@2954: } edouard@2954: edouard@2954: edouard@2954: edouard@2954: sub(new_offset=0){ edouard@2954: edouard@2954: /* set the offset because relative */ edouard@2954: edouard@2954: this.offset = new_offset; edouard@2954: edouard@2954: /* add this's subsribers */ edouard@2954: Edouard@2980: if(!this.unsubscribable) for(let index of this.indexes){ edouard@2954: edouard@2954: subscribers[index + new_offset].add(this); edouard@2954: edouard@2954: } edouard@2954: edouard@2954: need_cache_apply.push(this); edouard@2954: edouard@2954: } edouard@2954: edouard@2954: edouard@2954: edouard@2954: apply_cache() { edouard@2954: Edouard@2980: if(!this.unsubscribable) for(let index of this.indexes){ edouard@2954: edouard@2954: /* dispatch current cache in newly opened page widgets */ edouard@2954: edouard@2954: let realindex = index+this.offset; edouard@2954: edouard@2954: let cached_val = cache[realindex]; edouard@2954: edouard@2954: if(cached_val != undefined) edouard@2954: edouard@2954: dispatch_value_to_widget(this, realindex, cached_val, cached_val); edouard@2954: edouard@2954: } edouard@2954: edouard@2954: } edouard@2954: edouard@2954: edouard@2954: edouard@3003: get_idx(index) { edouard@3003: edouard@3003: let orig = this.indexes[index]; edouard@3003: edouard@3003: return this.offset ? orig + this.offset : orig; edouard@3003: edouard@3003: } edouard@3003: edouard@3004: change_hmi_value(index,opstr) { edouard@3004: edouard@3004: return change_hmi_value(this.get_idx(index), opstr); edouard@3004: edouard@3004: } edouard@3004: edouard@3004: edouard@3004: edouard@3004: apply_hmi_value(index, new_val) { edouard@3004: edouard@3004: return apply_hmi_value(this.get_idx(0), new_val); edouard@3004: edouard@3004: } edouard@3004: edouard@2949: } edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: class edouard@2949: edouard@2949: Widget extends Widget{ edouard@2949: edouard@2949: /* empty class, as edouard@2949: edouard@2949: widget didn't provide any */ edouard@2949: edouard@2949: } edouard@2949: edouard@2949: edouard@2997: edouard@2955: edouard@2941: edouard@2941: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2941: var hmi_widgets = { edouard@2941: edouard@2955: edouard@2941: } edouard@2941: edouard@2949: edouard@2949: edouard@2941: Edouard@2808: Edouard@2808: Edouard@2808: edouard@2920: Edouard@2800: Edouard@2834: Edouard@2808: Edouard@2807: edouard@2920: Edouard@2836: edouard@2920: Edouard@2836: edouard@2920: Edouard@2836: Edouard@2836: widget must have a Edouard@2836: Edouard@2836: element Edouard@2836: Edouard@2836: Edouard@2836: Edouard@2836: Edouard@2852: Edouard@2807: edouard@2847: _elt: id(" edouard@2920: Edouard@2836: "), Edouard@2836: edouard@2920: edouard@2920: edouard@2920: edouard@2920: _sub: { edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: widget must have a edouard@2920: edouard@2920: / edouard@2920: edouard@2920: element edouard@2920: edouard@2920: edouard@2920: /* missing edouard@2920: edouard@2920: / edouard@2920: edouard@2920: element */ edouard@2920: edouard@2920: edouard@2920: edouard@2920: " edouard@2920: edouard@2920: ": id(" edouard@2920: edouard@2920: ") edouard@2920: edouard@2920: , edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: edouard@2920: }, edouard@2920: edouard@2920: Edouard@2836: Edouard@2836: Edouard@2807: Edouard@2808: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: Edouard@2829: edouard@2961: edouard@2961: class BackWidget extends Widget{ edouard@2961: edouard@2961: on_click(evt) { Edouard@2902: Edouard@2902: if(jump_history.length > 1){ Edouard@2902: Edouard@2902: jump_history.pop(); Edouard@2902: Edouard@2902: let [page_name, index] = jump_history.pop(); Edouard@2902: Edouard@2902: switch_page(page_name, index); Edouard@2902: Edouard@2902: } Edouard@2902: edouard@2961: } edouard@2961: edouard@2961: init() { edouard@2961: edouard@2961: this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); edouard@2961: edouard@2961: } edouard@2961: edouard@2961: } edouard@2961: edouard@2961: dgaberscek@2976: dgaberscek@2976: dgaberscek@2976: dgaberscek@2976: dgaberscek@2976: dgaberscek@2976: active inactive dgaberscek@2976: dgaberscek@2976: dgaberscek@2976: dgaberscek@2976: frequency: 5, dgaberscek@2976: dgaberscek@2976: on_mouse_down: function(evt) { dgaberscek@2976: dgaberscek@2976: if (this.active_style && this.inactive_style) { dgaberscek@2976: dgaberscek@2976: this.active_elt.setAttribute("style", this.active_style); dgaberscek@2976: dgaberscek@2976: this.inactive_elt.setAttribute("style", "display:none"); edouard@2961: edouard@2961: } edouard@2961: edouard@3004: this.apply_hmi_value(0, 1); dgaberscek@2976: dgaberscek@2976: }, dgaberscek@2976: dgaberscek@2976: on_mouse_up: function(evt) { dgaberscek@2976: dgaberscek@2976: if (this.active_style && this.inactive_style) { dgaberscek@2976: dgaberscek@2976: this.active_elt.setAttribute("style", "display:none"); dgaberscek@2976: dgaberscek@2976: this.inactive_elt.setAttribute("style", this.inactive_style); dgaberscek@2976: dgaberscek@2976: } dgaberscek@2976: edouard@3004: this.apply_hmi_value(0, 0); dgaberscek@2976: dgaberscek@2976: }, dgaberscek@2976: dgaberscek@2976: active_style: undefined, dgaberscek@2976: dgaberscek@2976: inactive_style: undefined, dgaberscek@2976: dgaberscek@2976: init: function() { dgaberscek@2976: dgaberscek@2976: this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; dgaberscek@2976: dgaberscek@2976: this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; dgaberscek@2976: dgaberscek@2976: if (this.active_style && this.inactive_style) { dgaberscek@2976: dgaberscek@2976: this.active_elt.setAttribute("style", "display:none"); dgaberscek@2976: dgaberscek@2976: this.inactive_elt.setAttribute("style", this.inactive_style); dgaberscek@2976: dgaberscek@2976: } dgaberscek@2976: dgaberscek@2976: this.element.setAttribute("onmousedown", "hmi_widgets[' dgaberscek@2976: dgaberscek@2976: '].on_mouse_down(evt)"); dgaberscek@2976: dgaberscek@2976: this.element.setAttribute("onmouseup", "hmi_widgets[' dgaberscek@2976: dgaberscek@2976: '].on_mouse_up(evt)"); dgaberscek@2976: dgaberscek@2976: }, dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: frequency: 10, dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: path dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: value min max dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dgaberscek@2944: dispatch: function(value) { dgaberscek@2944: dgaberscek@2944: if(this.value_elt) dgaberscek@2944: dgaberscek@2944: this.value_elt.textContent = String(value); dgaberscek@2944: dgaberscek@2944: let [min,max,start,end] = this.range; dgaberscek@2944: dgaberscek@2944: let [cx,cy] = this.center; dgaberscek@2944: dgaberscek@2944: let [rx,ry] = this.proportions; dgaberscek@2944: dgaberscek@2944: let tip = start + (end-start)*Number(value)/(max-min); dgaberscek@2944: dgaberscek@2944: let size = 0; dgaberscek@2944: dgaberscek@2944: if (tip-start > Math.PI) { dgaberscek@2944: dgaberscek@2944: size = 1; dgaberscek@2944: dgaberscek@2944: } else { dgaberscek@2944: dgaberscek@2944: size = 0; dgaberscek@2944: dgaberscek@2944: } dgaberscek@2944: dgaberscek@2944: 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))); dgaberscek@2944: dgaberscek@2944: }, dgaberscek@2944: dgaberscek@2944: range: undefined, dgaberscek@2944: dgaberscek@2944: init: function() { dgaberscek@2944: dgaberscek@2944: let start = Number(this.path_elt.getAttribute('sodipodi:start')); dgaberscek@2944: dgaberscek@2944: let end = Number(this.path_elt.getAttribute('sodipodi:end')); dgaberscek@2944: dgaberscek@2944: let cx = Number(this.path_elt.getAttribute('sodipodi:cx')); dgaberscek@2944: dgaberscek@2944: let cy = Number(this.path_elt.getAttribute('sodipodi:cy')); dgaberscek@2944: dgaberscek@2944: let rx = Number(this.path_elt.getAttribute('sodipodi:rx')); dgaberscek@2944: dgaberscek@2944: let ry = Number(this.path_elt.getAttribute('sodipodi:ry')); dgaberscek@2944: dgaberscek@2944: if (ry == 0) { dgaberscek@2944: dgaberscek@2944: ry = rx; dgaberscek@2944: dgaberscek@2944: } dgaberscek@2944: dgaberscek@2944: if (start > end) { dgaberscek@2944: dgaberscek@2944: end = end + 2*Math.PI; dgaberscek@2944: dgaberscek@2944: } dgaberscek@2944: dgaberscek@2944: let min = this.min_elt ? dgaberscek@2944: dgaberscek@2944: Number(this.min_elt.textContent) : dgaberscek@2944: dgaberscek@2944: this.args.length >= 1 ? this.args[0] : 0; dgaberscek@2944: dgaberscek@2944: let max = this.max_elt ? dgaberscek@2944: dgaberscek@2944: Number(this.max_elt.textContent) : dgaberscek@2944: dgaberscek@2944: this.args.length >= 2 ? this.args[1] : 100; dgaberscek@2944: dgaberscek@2944: this.range = [min, max, start, end]; dgaberscek@2944: dgaberscek@2944: this.center = [cx, cy]; dgaberscek@2944: dgaberscek@2944: this.proportions = [rx, ry]; dgaberscek@2944: dgaberscek@2944: }, dgaberscek@2944: dgaberscek@2944: edouard@2998: edouard@2998: class DisplayWidget extends Widget{ edouard@2998: edouard@2998: frequency = 5; edouard@2998: edouard@2998: dispatch(value) { edouard@2998: edouard@2998: this.element.textContent = String(value); edouard@2998: edouard@2998: } edouard@2998: edouard@2998: } edouard@2998: edouard@2998: edouard@2883: edouard@2883: edouard@2998: edouard@2998: edouard@2998: Display Widget id=" edouard@2998: edouard@2998: " is not a svg::text element edouard@2998: edouard@2998: edouard@2883: Edouard@2922: Edouard@2922: Edouard@2922: Edouard@2922: Edouard@2922: edouard@2926: text box button Edouard@2922: Edouard@2922: Edouard@2922: dispatch: function(value) { Edouard@2922: edouard@2924: if(!this.opened) this.set_selection(value); Edouard@2922: Edouard@2922: }, Edouard@2922: Edouard@2922: init: function() { Edouard@2922: edouard@2926: this.button_elt.setAttribute("onclick", "hmi_widgets[' Edouard@2922: edouard@2926: '].on_button_click()"); Edouard@2922: Edouard@2936: // Save original size of rectangle edouard@2923: edouard@2923: this.box_bbox = this.box_elt.getBBox() edouard@2923: Edouard@2936: Edouard@2936: Edouard@2936: // Compute margins Edouard@2936: Edouard@2936: text_bbox = this.text_elt.getBBox() Edouard@2936: Edouard@2936: lmargin = text_bbox.x - this.box_bbox.x; Edouard@2936: Edouard@2936: tmargin = text_bbox.y - this.box_bbox.y; edouard@2923: edouard@2926: this.margins = [lmargin, tmargin].map(x => Math.max(x,0)); edouard@2923: Edouard@2936: Edouard@2936: Edouard@2936: // It is assumed that list content conforms to Array interface. edouard@2931: edouard@2931: this.content = [ edouard@2931: edouard@2931: edouard@2931: " edouard@2931: edouard@2931: ", edouard@2931: edouard@2931: edouard@2931: ]; edouard@2923: Edouard@2936: Edouard@2936: Edouard@2936: // Index of first visible element in the menu, when opened Edouard@2936: edouard@2924: this.menu_offset = 0; edouard@2923: Edouard@2936: Edouard@2936: Edouard@2936: // How mutch to lift the menu vertically so that it does not cross bottom border Edouard@2936: edouard@2923: this.lift = 0; edouard@2923: Edouard@2936: Edouard@2936: Edouard@2936: // Event handlers cannot be object method ('this' is unknown) Edouard@2936: Edouard@2936: // as a workaround, handler given to addEventListener is bound in advance. Edouard@2936: Edouard@2936: this.bound_close_on_click_elsewhere = this.close_on_click_elsewhere.bind(this); Edouard@2936: Edouard@2936: Edouard@2936: edouard@2924: this.opened = false; edouard@2924: Edouard@2936: }, Edouard@2936: Edouard@2936: // Called when a menu entry is clicked edouard@2924: edouard@2924: on_selection_click: function(selection) { edouard@2924: edouard@2926: this.close(); edouard@2926: edouard@3004: this.apply_hmi_value(0, selection); edouard@2924: edouard@2923: }, Edouard@2922: edouard@2926: on_button_click: function() { edouard@2926: edouard@2926: this.open(); edouard@2926: edouard@2926: }, edouard@2926: Edouard@2936: on_backward_click: function(){ Edouard@2936: Edouard@2936: this.scroll(false); edouard@2926: edouard@2926: }, edouard@2926: edouard@2926: on_forward_click:function(){ edouard@2926: Edouard@2936: this.scroll(true); edouard@2926: edouard@2926: }, edouard@2926: edouard@2926: set_selection: function(value) { edouard@2926: edouard@2934: let display_str; edouard@2934: edouard@2934: if(value >= 0 && value < this.content.length){ edouard@2934: Edouard@2936: // if valid selection resolve content Edouard@2936: edouard@2934: display_str = this.content[value]; edouard@2934: edouard@2934: this.last_selection = value; edouard@2934: edouard@2934: } else { edouard@2934: Edouard@2936: // otherwise show problem Edouard@2936: edouard@2934: display_str = "?"+String(value)+"?"; edouard@2934: edouard@2934: } edouard@2934: Edouard@2936: // It is assumed that first span always stays, Edouard@2936: Edouard@2936: // and contains selection when menu is closed Edouard@2936: edouard@2934: this.text_elt.firstElementChild.textContent = display_str; edouard@2926: edouard@2926: }, edouard@2926: edouard@2926: grow_text: function(up_to) { edouard@2926: edouard@2926: let count = 1; edouard@2926: edouard@2926: let txt = this.text_elt; edouard@2926: edouard@2926: let first = txt.firstElementChild; edouard@2926: Edouard@2936: // Real world (pixels) boundaries of current page Edouard@2936: edouard@2926: let bounds = svg_root.getBoundingClientRect(); edouard@2926: edouard@2926: this.lift = 0; edouard@2926: edouard@2926: while(count < up_to) { edouard@2926: edouard@2926: let next = first.cloneNode(); edouard@2926: Edouard@2936: // relative line by line text flow instead of absolute y coordinate Edouard@2936: edouard@2926: next.removeAttribute("y"); edouard@2926: edouard@2926: next.setAttribute("dy", "1.1em"); edouard@2926: Edouard@2936: // default content to allow computing text element bbox Edouard@2936: edouard@2926: next.textContent = "..."; edouard@2926: Edouard@2936: // append new span to text element Edouard@2936: edouard@2926: txt.appendChild(next); edouard@2926: Edouard@2936: // now check if text extended by one row fits to page Edouard@2936: Edouard@2936: // FIXME : exclude margins to be more accurate on box size Edouard@2936: edouard@2926: let rect = txt.getBoundingClientRect(); edouard@2926: edouard@2926: if(rect.bottom > bounds.bottom){ edouard@2926: Edouard@2936: // in case of overflow at the bottom, lift up one row Edouard@2936: edouard@2926: let backup = first.getAttribute("dy"); edouard@2926: Edouard@2936: // apply lift asr a dy added too first span (y attrib stays) Edouard@2936: edouard@2926: first.setAttribute("dy", "-"+String((this.lift+1)*1.1)+"em"); edouard@2926: edouard@2926: rect = txt.getBoundingClientRect(); edouard@2926: edouard@2926: if(rect.top > bounds.top){ edouard@2926: edouard@2926: this.lift += 1; edouard@2926: edouard@2926: } else { edouard@2926: Edouard@2936: // if it goes over the top, then backtrack Edouard@2936: Edouard@2936: // restore dy attribute on first span Edouard@2936: edouard@2926: if(backup) edouard@2926: edouard@2926: first.setAttribute("dy", backup); edouard@2926: edouard@2926: else edouard@2926: edouard@2926: first.removeAttribute("dy"); edouard@2926: Edouard@2936: // remove unwanted child Edouard@2936: edouard@2926: txt.removeChild(next); edouard@2926: edouard@2926: return count; edouard@2926: edouard@2926: } edouard@2926: edouard@2926: } edouard@2926: edouard@2926: count++; edouard@2924: edouard@2924: } edouard@2924: edouard@2924: return count; edouard@2924: edouard@2924: }, edouard@2924: edouard@2933: close_on_click_elsewhere: function(e) { edouard@2930: Edouard@2936: // inhibit events not targetting spans (menu items) edouard@2930: edouard@2933: if(e.target.parentNode !== this.text_elt){ edouard@2930: edouard@2930: e.stopPropagation(); edouard@2930: Edouard@2936: // close menu in case click is outside box Edouard@2936: edouard@2933: if(e.target !== this.box_elt) edouard@2933: edouard@2933: this.close(); edouard@2933: edouard@2933: } edouard@2933: edouard@2930: }, edouard@2930: edouard@2924: close: function(){ edouard@2924: Edouard@2936: // Stop hogging all click events Edouard@2936: Edouard@2936: svg_root.removeEventListener("click", this.bound_close_on_click_elsewhere, true); Edouard@2936: Edouard@2936: // Restore position and sixe of widget elements edouard@2932: edouard@2924: this.reset_text(); edouard@2924: edouard@2924: this.reset_box(); edouard@2924: Edouard@2936: // Put the button back in place Edouard@2936: edouard@2926: this.element.appendChild(this.button_elt); edouard@2926: Edouard@2936: // Mark as closed (to allow dispatch) Edouard@2936: edouard@2932: this.opened = false; edouard@2932: Edouard@2936: // Dispatch last cached value Edouard@2936: edouard@2930: this.apply_cache(); edouard@2930: edouard@2924: }, edouard@2924: Edouard@2936: // Set text content when content is smaller than menu (no scrolling) Edouard@2936: edouard@2924: set_complete_text: function(){ edouard@2924: edouard@2924: let spans = this.text_elt.children; edouard@2924: edouard@2924: let c = 0; edouard@2924: edouard@2924: for(let item of this.content){ edouard@2924: edouard@2924: let span=spans[c]; edouard@2924: edouard@2924: span.textContent = item; edouard@2924: edouard@2924: span.setAttribute("onclick", "hmi_widgets[' edouard@2924: edouard@2924: '].on_selection_click("+c+")"); edouard@2924: edouard@2924: c++; edouard@2924: edouard@2924: } edouard@2924: edouard@2924: }, edouard@2924: Edouard@2936: // Move partial view : Edouard@2936: Edouard@2936: // false : upward, lower value Edouard@2936: Edouard@2936: // true : downward, higher value Edouard@2936: Edouard@2936: scroll: function(forward){ edouard@2925: edouard@2925: let contentlength = this.content.length; edouard@2925: edouard@2925: let spans = this.text_elt.children; edouard@2925: edouard@2925: let spanslength = spans.length; edouard@2925: Edouard@2936: // reduce accounted menu size according to jumps Edouard@2936: edouard@2925: if(this.menu_offset != 0) spanslength--; edouard@2925: edouard@2925: if(this.menu_offset < contentlength - 1) spanslength--; edouard@2925: edouard@2925: if(forward){ edouard@2925: edouard@2925: this.menu_offset = Math.min( edouard@2925: edouard@2925: contentlength - spans.length + 1, edouard@2925: edouard@2925: this.menu_offset + spanslength); edouard@2925: edouard@2925: }else{ edouard@2925: edouard@2925: this.menu_offset = Math.max( edouard@2925: edouard@2925: 0, edouard@2925: edouard@2925: this.menu_offset - spanslength); edouard@2925: edouard@2925: } edouard@2925: edouard@2925: console.log(this.menu_offset); edouard@2925: edouard@2925: this.set_partial_text(); edouard@2925: edouard@2925: }, edouard@2925: Edouard@2936: // Setup partial view text content Edouard@2936: Edouard@2936: // with jumps at first and last entry when appropriate Edouard@2936: edouard@2924: set_partial_text: function(){ edouard@2924: edouard@2924: let spans = this.text_elt.children; edouard@2924: edouard@2925: let contentlength = this.content.length; edouard@2925: edouard@2925: let spanslength = spans.length; edouard@2924: edouard@2924: let i = this.menu_offset, c = 0; edouard@2924: edouard@2925: while(c < spanslength){ edouard@2925: edouard@2925: let span=spans[c]; edouard@2924: Edouard@2936: // backward jump only present if not exactly at start Edouard@2936: edouard@2924: if(c == 0 && i != 0){ edouard@2924: edouard@2925: span.textContent = "↑ ↑ ↑"; edouard@2925: edouard@2925: span.setAttribute("onclick", "hmi_widgets[' edouard@2925: edouard@2925: '].on_backward_click()"); edouard@2925: Edouard@2936: // presence of forward jump when not right at the end Edouard@2936: edouard@2925: }else if(c == spanslength-1 && i < contentlength - 1){ edouard@2925: edouard@2925: span.textContent = "↓ ↓ ↓"; edouard@2925: edouard@2925: span.setAttribute("onclick", "hmi_widgets[' edouard@2925: edouard@2925: '].on_forward_click()"); edouard@2925: Edouard@2936: // otherwise normal content Edouard@2936: edouard@2925: }else{ edouard@2924: edouard@2924: span.textContent = this.content[i]; edouard@2924: edouard@2924: span.setAttribute("onclick", "hmi_widgets[' edouard@2924: edouard@2924: '].on_selection_click("+i+")"); edouard@2924: edouard@2924: i++; edouard@2924: edouard@2924: } edouard@2924: edouard@2924: c++; edouard@2924: edouard@2924: } edouard@2923: edouard@2923: }, edouard@2923: edouard@2923: open: function(){ edouard@2923: edouard@2924: let length = this.content.length; edouard@2924: Edouard@2936: // systematically reset text, to strip eventual whitespace spans Edouard@2936: edouard@2924: this.reset_text(); edouard@2924: Edouard@2936: // grow as much as needed or possible Edouard@2936: edouard@2924: let slots = this.grow_text(length); edouard@2924: Edouard@2936: // Depending on final size Edouard@2936: edouard@2924: if(slots == length) { edouard@2924: Edouard@2936: // show all at once Edouard@2936: edouard@2924: this.set_complete_text(); edouard@2923: edouard@2923: } else { edouard@2923: Edouard@2936: // eventualy align menu to current selection, compensating for lift edouard@2934: edouard@2934: let offset = this.last_selection - this.lift; edouard@2934: edouard@2934: if(offset > 0) edouard@2934: edouard@2934: this.menu_offset = Math.min(offset + 1, length - slots + 1); edouard@2934: edouard@2934: else edouard@2934: edouard@2934: this.menu_offset = 0; edouard@2934: Edouard@2936: // show surrounding values Edouard@2936: edouard@2924: this.set_partial_text(); edouard@2923: edouard@2923: } edouard@2923: Edouard@2936: // Now that text size is known, we can set the box around it Edouard@2936: edouard@2924: this.adjust_box_to_text(); edouard@2924: Edouard@2936: // Take button out until menu closed Edouard@2936: edouard@2926: this.element.removeChild(this.button_elt); edouard@2926: Edouard@2936: // Rise widget to top by moving it to last position among siblings Edouard@2936: edouard@2930: this.element.parentNode.appendChild(this.element.parentNode.removeChild(this.element)); edouard@2930: edouard@2930: // disable interaction with background edouard@2930: Edouard@2936: svg_root.addEventListener("click", this.bound_close_on_click_elsewhere, true); Edouard@2936: Edouard@2936: // mark as open edouard@2924: edouard@2924: this.opened = true; edouard@2924: edouard@2924: }, edouard@2924: Edouard@2936: // Put text element in normalized state Edouard@2936: edouard@2924: reset_text: function(){ edouard@2923: edouard@2923: let txt = this.text_elt; edouard@2923: edouard@2924: let first = txt.firstElementChild; edouard@2924: Edouard@2936: // remove attribute eventually added to first text line while opening Edouard@2936: edouard@2924: first.removeAttribute("onclick"); edouard@2924: edouard@2924: first.removeAttribute("dy"); edouard@2924: Edouard@2936: // keep only the first line of text Edouard@2936: edouard@2923: for(let span of Array.from(txt.children).slice(1)){ edouard@2923: edouard@2923: txt.removeChild(span) edouard@2923: edouard@2923: } edouard@2923: edouard@2923: }, edouard@2923: Edouard@2936: // Put rectangle element in saved original state Edouard@2936: edouard@2924: reset_box: function(){ edouard@2924: edouard@2924: let m = this.box_bbox; edouard@2924: edouard@2924: let b = this.box_elt; edouard@2924: edouard@2924: b.x.baseVal.value = m.x; edouard@2924: edouard@2924: b.y.baseVal.value = m.y; edouard@2924: edouard@2924: b.width.baseVal.value = m.width; edouard@2924: edouard@2924: b.height.baseVal.value = m.height; edouard@2924: edouard@2924: }, edouard@2924: Edouard@2936: // Use margin and text size to compute box size Edouard@2936: edouard@2924: adjust_box_to_text: function(){ edouard@2923: edouard@2926: let [lmargin, tmargin] = this.margins; edouard@2923: edouard@2923: let m = this.text_elt.getBBox(); edouard@2923: edouard@2924: let b = this.box_elt; edouard@2924: edouard@2924: b.x.baseVal.value = m.x - lmargin; edouard@2924: edouard@2924: b.y.baseVal.value = m.y - tmargin; edouard@2924: edouard@2926: b.width.baseVal.value = 2 * lmargin + m.width; edouard@2926: edouard@2926: b.height.baseVal.value = 2 * tmargin + m.height; Edouard@2922: Edouard@2922: }, Edouard@2922: Edouard@2922: edouard@2892: edouard@2892: edouard@2894: edouard@2894: edouard@2894: edouard@2894: edouard@2894: edouard@2894: edouard@2894: Edouard@2893: index_pool: [ Edouard@2893: edouard@2894: edouard@2894: edouard@2894: edouard@2894: edouard@2894: , edouard@2894: edouard@2894: edouard@2894: edouard@2894: Edouard@2893: ], Edouard@2893: edouard@2896: init: function() { Edouard@2893: Edouard@2893: Edouard@2893: edouard@2896: edouard@2896: edouard@2896: edouard@2896: id(" Edouard@2893: edouard@2896: ").setAttribute("onclick", "hmi_widgets[' edouard@2896: edouard@2896: '].on_click(' edouard@2896: edouard@2896: ', evt)"); Edouard@2893: Edouard@2893: edouard@2896: Edouard@2893: Edouard@2895: this.items = [ Edouard@2893: Edouard@2893: Edouard@2893: Edouard@2893: Edouard@2893: Edouard@2893: edouard@2894: edouard@2894: Edouard@2895: [ /* item=" Edouard@2893: edouard@2894: " path=" edouard@2894: edouard@2894: " */ edouard@2892: Edouard@2893: Edouard@2893: Edouard@2893: Missing item labeled Edouard@2893: Edouard@2893: in ForEach widget Edouard@2893: Edouard@2893: Edouard@2893: Edouard@2893: edouard@2894: edouard@2894: edouard@2894: Widget id=" edouard@2894: edouard@2894: " label=" edouard@2894: edouard@2894: " is having wrong path. Accroding to ForEach widget ancestor id=" edouard@2894: edouard@2896: ", path should be descendant of " edouard@2894: edouard@2896: ". edouard@2894: edouard@2894: Edouard@2895: hmi_widgets[" edouard@2892: edouard@2892: "] edouard@2892: edouard@2892: , edouard@2892: edouard@2892: edouard@2892: edouard@2892: Edouard@2895: ] edouard@2892: edouard@2892: , edouard@2892: edouard@2892: edouard@2892: edouard@2892: Edouard@2895: ] Edouard@2895: Edouard@2895: }, Edouard@2895: Edouard@2895: item_offset: 0, edouard@2892: edouard@2954: edouard@2954: edouard@2954: class ForEachWidget extends Widget{ edouard@2954: edouard@2954: unsub(){ edouard@2954: edouard@2954: for(let item of this.items){ edouard@2954: edouard@2954: for(let widget of item) { edouard@2954: edouard@2954: widget.unsub(); edouard@2954: edouard@2954: } edouard@2942: edouard@2942: } edouard@2942: edouard@2954: this.offset = 0; edouard@2954: edouard@2942: } edouard@2942: edouard@2954: edouard@2954: edouard@3003: foreach_widgets_do(todo){ edouard@3003: edouard@3003: for(let i = 0; i < this.items.length; i++) { edouard@3003: edouard@3003: let item = this.items[i]; edouard@3003: edouard@3003: let orig_item_index = this.index_pool[i]; edouard@3003: edouard@3003: let item_index = this.index_pool[i+this.item_offset]; edouard@3003: edouard@3003: let item_index_offset = item_index - orig_item_index; edouard@3003: edouard@3003: for(let widget of item) { edouard@3003: edouard@3003: todo(widget).call(widget, this.offset + item_index_offset); edouard@3003: edouard@3003: } edouard@3003: edouard@3003: } edouard@3003: edouard@3003: } edouard@3003: edouard@3003: edouard@3003: edouard@3003: sub(new_offset=0){ edouard@2954: edouard@2954: this.offset = new_offset; edouard@2954: edouard@3003: this.foreach_widgets_do(w=>w.sub); edouard@2954: edouard@2954: } edouard@2954: edouard@2954: edouard@2954: edouard@2954: apply_cache() { edouard@2954: edouard@3003: this.foreach_widgets_do(w=>w.apply_cache); edouard@2954: edouard@2954: } edouard@2954: edouard@2954: edouard@2954: edouard@2954: on_click(opstr, evt) { edouard@2954: edouard@2954: let new_item_offset = eval(String(this.item_offset)+opstr); edouard@2954: edouard@2954: if(new_item_offset + this.items.length > this.index_pool.length) { edouard@2954: edouard@2954: if(this.item_offset + this.items.length == this.index_pool.length) edouard@2954: edouard@2954: new_item_offset = 0; edouard@2954: edouard@2954: else edouard@2954: edouard@2954: new_item_offset = this.index_pool.length - this.items.length; edouard@2954: edouard@2954: } else if(new_item_offset < 0) { edouard@2954: edouard@2954: if(this.item_offset == 0) edouard@2954: edouard@2954: new_item_offset = this.index_pool.length - this.items.length; edouard@2954: edouard@2954: else edouard@2954: edouard@2954: new_item_offset = 0; edouard@2954: edouard@2954: } edouard@2954: edouard@2954: this.item_offset = new_item_offset; edouard@2954: edouard@2954: this.unsub(); edouard@2954: edouard@2954: this.sub(this.offset); edouard@2954: edouard@2954: update_subscriptions(); edouard@2954: edouard@2954: need_cache_apply.push(this); edouard@2954: edouard@2954: jumps_need_update = true; edouard@2954: edouard@2954: requestHMIAnimation(); edouard@2954: edouard@2954: } edouard@2942: edouard@2942: } edouard@2942: edouard@2942: Edouard@2800: Edouard@2801: Edouard@2836: Edouard@2836: Edouard@2836: Edouard@2836: Edouard@2836: value Edouard@2836: Edouard@2836: Edouard@2836: Edouard@2836: Edouard@2861: Edouard@2836: Edouard@2861: edouard@2851: frequency: 5, Edouard@2836: Edouard@2836: Edouard@2913: last_val: undefined, Edouard@2913: edouard@2851: dispatch: function(value) { Edouard@2801: Edouard@2913: this.last_val = value; Edouard@2913: Edouard@2861: edouard@2851: this.value_elt.textContent = String(value); Edouard@2836: Edouard@2836: edouard@2851: }, Edouard@2801: Edouard@2801: edouard@2851: init: function() { Edouard@2801: Edouard@2801: edouard@2851: id(" Edouard@2801: Edouard@2913: ").setAttribute("onclick", "hmi_widgets[' Edouard@2913: Edouard@2913: '].on_edit_click()"); Edouard@2801: Edouard@2801: Edouard@2829: edouard@2851: id(" Edouard@2801: Edouard@2913: ").setAttribute("onclick", "hmi_widgets[' Edouard@2913: Edouard@2913: '].on_op_click(' Edouard@2829: Edouard@2913: ')"); Edouard@2801: Edouard@2801: edouard@2851: }, Edouard@2801: Edouard@2913: on_op_click: function(opstr) { Edouard@2913: edouard@3004: let new_val = this.change_hmi_value(0, opstr); Edouard@2913: Edouard@2913: }, Edouard@2913: Edouard@2913: on_edit_click: function(opstr) { Edouard@2913: Edouard@2913: edit_value(" Edouard@2913: Edouard@2913: ", " Edouard@2913: Edouard@2917: ", this, this.last_val); Edouard@2913: Edouard@2913: }, Edouard@2913: Edouard@2913: edit_callback: function(new_val) { Edouard@2913: edouard@3004: this.apply_hmi_value(0, new_val); Edouard@2913: Edouard@2913: }, Edouard@2913: Edouard@2801: edouard@2994: edouard@2994: class JsonTableWidget extends Widget{ edouard@2994: edouard@2996: do_http_request() { edouard@2996: edouard@2996: const query = { edouard@2996: edouard@2996: offset: '42', edouard@2996: edouard@2996: filter: '*powerloss*', edouard@2996: edouard@2996: args: this.args edouard@2996: edouard@2996: }; edouard@2996: edouard@2996: edouard@2996: edouard@2996: const options = { edouard@2996: edouard@2996: method: 'POST', edouard@2996: edouard@2996: body: JSON.stringify(query), edouard@2996: edouard@2996: headers: {'Content-Type': 'application/json'} edouard@2996: edouard@2996: } edouard@2996: edouard@2996: edouard@2996: edouard@2996: fetch(this.args[0], options) edouard@2996: edouard@2996: .then(res => res.json()) edouard@2996: edouard@2996: .then(this.spread_json_data); edouard@2996: edouard@2996: edouard@2996: edouard@2996: } edouard@2996: edouard@2996: dispatch(value) { edouard@2996: edouard@2996: this.do_http_request(); edouard@2996: edouard@2996: } edouard@2996: edouard@2994: on_click(evt) { edouard@2994: edouard@2996: this.do_http_request(); edouard@2994: edouard@2994: } edouard@2994: edouard@2994: init() { edouard@2994: edouard@2994: this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); edouard@2994: edouard@2994: } edouard@2994: edouard@2994: } edouard@2994: edouard@2994: edouard@2996: edouard@2997: edouard@2996: JsonTable Widget can't contain element of type edouard@2996: edouard@2996: . edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2997: edouard@2997: edouard@2997: edouard@2997: edouard@2997: Clones (svg:use) in JsonTable Widget must point to a valid HMI:List widget or HMI:List item. Reference " edouard@2997: edouard@2997: " is not valid. edouard@2997: edouard@2997: edouard@2997: console.log(" edouard@2996: edouard@2996: ", " edouard@2996: edouard@2996: ", edouard@2996: edouard@2996: ); edouard@2996: edouard@2997: id(" edouard@2997: edouard@2997: ").setAttribute("xlink:href", edouard@2997: edouard@2997: "#"+hmi_widgets[" edouard@2997: edouard@2997: "].items[ edouard@2997: edouard@2997: ]); edouard@2997: edouard@2996: edouard@2996: edouard@2996: edouard@2997: console.log(" edouard@2996: edouard@2996: ", " edouard@2996: edouard@2996: ", edouard@2996: edouard@2996: ); edouard@2996: edouard@2997: id(" edouard@2997: edouard@2997: ").textContent = String( edouard@2997: edouard@2997: ); edouard@2997: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2997: let obj_ edouard@2996: edouard@2996: = edouard@2996: edouard@2996: edouard@2996: ; edouard@2996: edouard@2996: edouard@2996: edouard@2996: obj_ edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: data edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2996: forward backward cursor edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2997: spread_json_data: function(jdata) { edouard@2997: edouard@2997: console.log(jdata); edouard@2996: edouard@2996: edouard@2996: edouard@2996: edouard@2997: } edouard@2996: edouard@2996: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: active inactive Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: disabled Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: edouard@2883: edouard@2883: Edouard@2906: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2903: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2906: active: false, Edouard@2906: Edouard@2906: Edouard@2906: disabled: false, Edouard@2906: Edouard@2906: frequency: 2, Edouard@2906: Edouard@2906: dispatch: function(value) { Edouard@2906: Edouard@2906: this.disabled = !Number(value); Edouard@2906: Edouard@2906: this.update(); Edouard@2906: Edouard@2906: }, Edouard@2906: Edouard@2906: Edouard@2906: update: function(){ Edouard@2906: Edouard@2906: Edouard@2906: if(this.disabled) { Edouard@2906: Edouard@2906: /* show disabled */ Edouard@2906: Edouard@2906: this.disabled_elt.setAttribute("style", this.active_elt_style); Edouard@2906: Edouard@2906: /* hide inactive */ Edouard@2906: Edouard@2906: this.inactive_elt.setAttribute("style", "display:none"); Edouard@2906: Edouard@2906: /* hide active */ Edouard@2906: Edouard@2906: this.active_elt.setAttribute("style", "display:none"); Edouard@2906: Edouard@2906: } else { Edouard@2906: Edouard@2906: /* hide disabled */ Edouard@2906: Edouard@2906: this.disabled_elt.setAttribute("style", "display:none"); Edouard@2906: Edouard@2906: Edouard@2906: if(this.active) { Edouard@2906: Edouard@2906: /* show active */ Edouard@2906: Edouard@2906: this.active_elt.setAttribute("style", this.active_elt_style); Edouard@2906: Edouard@2906: /* hide inactive */ Edouard@2906: Edouard@2906: this.inactive_elt.setAttribute("style", "display:none"); Edouard@2906: Edouard@2906: } else { Edouard@2906: Edouard@2906: /* show inactive */ Edouard@2906: Edouard@2906: this.inactive_elt.setAttribute("style", this.inactive_elt_style); Edouard@2906: Edouard@2906: /* hide active */ Edouard@2906: Edouard@2906: this.active_elt.setAttribute("style", "display:none"); Edouard@2906: Edouard@2906: } Edouard@2906: Edouard@2906: Edouard@2906: } Edouard@2906: Edouard@2906: Edouard@2906: }, Edouard@2906: Edouard@2906: edouard@2883: on_click: function(evt) { edouard@2883: Edouard@2898: const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; Edouard@2898: Edouard@2902: const name = this.args[0]; Edouard@2902: Edouard@2902: switch_page(name, index); edouard@2883: edouard@2883: }, edouard@2883: Edouard@2906: Edouard@2903: notify_page_change: function(page_name, index){ Edouard@2903: Edouard@2903: const ref_index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined; Edouard@2903: Edouard@2903: const ref_name = this.args[0]; Edouard@2903: Edouard@2906: this.active =((ref_name == undefined || ref_name == page_name) && index == ref_index); Edouard@2906: Edouard@2906: this.update(); Edouard@2903: Edouard@2903: }, Edouard@2903: Edouard@2903: edouard@2883: init: function() { edouard@2883: edouard@2883: this.element.setAttribute("onclick", "hmi_widgets[' edouard@2883: edouard@2883: '].on_click(evt)"); edouard@2883: Edouard@2906: Edouard@2903: this.active_elt_style = this.active_elt.getAttribute("style"); Edouard@2903: Edouard@2903: this.inactive_elt_style = this.inactive_elt.getAttribute("style"); Edouard@2903: Edouard@2903: Edouard@2906: Edouard@2906: edouard@2954: this.disabled_elt_style = this.disabled_elt.getAttribute("style"); Edouard@2906: Edouard@2906: Edouard@2906: Edouard@2980: this.unsubscribable = true; Edouard@2906: Edouard@2906: Edouard@2906: edouard@2954: }, edouard@2954: Edouard@2906: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: Jump id=" Edouard@2901: Edouard@2901: " to page " Edouard@2901: Edouard@2901: " with incompatible path " Edouard@2901: Edouard@2901: (must be same class as " Edouard@2901: Edouard@2901: ") Edouard@2901: Edouard@2901: Edouard@2901: Edouard@2901: edouard@2943: edouard@2943: edouard@2949: edouard@2949: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2942: var jumps_need_update = false; edouard@2942: edouard@2942: var jump_history = [[default_page, undefined]]; edouard@2942: edouard@2942: edouard@2942: edouard@2942: function update_jumps() { edouard@2942: edouard@2942: page_desc[current_visible_page].jumps.map(w=>w.notify_page_change(current_visible_page,current_page_index)); edouard@2942: edouard@2942: jumps_need_update = false; edouard@2942: edouard@2942: }; edouard@2942: edouard@2942: edouard@2942: edouard@2949: edouard@2949: edouard@2942: edouard@2943: edouard@2943: edouard@2941: edouard@2941: edouard@2949: /* edouard@2949: edouard@2949: */ edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2949: edouard@2941: var keypads = { edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2941: edouard@2941: " edouard@2941: edouard@2941: ":[" edouard@2941: edouard@2941: ", edouard@2941: edouard@2941: , edouard@2941: edouard@2941: ], edouard@2941: edouard@2941: edouard@2941: edouard@2941: } edouard@2941: edouard@2949: edouard@2949: edouard@2941: Edouard@2913: Edouard@2917: Edouard@2917: Edouard@2917: Edouard@2917: Edouard@2917: Esc Enter BackSpace Keys Info Value Edouard@2917: Edouard@2917: Edouard@2917: Edouard@2917: Edouard@2917: edouard@2920: Sign Space NumDot Edouard@2917: Edouard@2917: Edouard@2917: edouard@2920: edouard@2920: edouard@2920: edouard@2920: CapsLock Shift edouard@2920: edouard@2920: edouard@2920: edouard@2920: Edouard@2913: init: function() { Edouard@2913: Edouard@2917: Edouard@2917: id(" Edouard@2917: Edouard@2917: ").setAttribute("onclick", "hmi_widgets[' Edouard@2917: Edouard@2917: '].on_key_click(' Edouard@2917: Edouard@2917: ')"); Edouard@2917: Edouard@2917: edouard@2920: Edouard@2917: if(this. Edouard@2917: Edouard@2917: _elt) Edouard@2917: Edouard@2917: this. Edouard@2917: Edouard@2917: _elt.setAttribute("onclick", "hmi_widgets[' Edouard@2917: Edouard@2917: '].on_ Edouard@2917: Edouard@2917: _click()"); Edouard@2917: Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: on_key_click: function(symbols) { Edouard@2917: Edouard@2917: var syms = symbols.split(" "); Edouard@2917: edouard@2919: this.shift |= this.caps; edouard@2919: edouard@2919: this.editstr += syms[this.shift?syms.length-1:0]; Edouard@2917: Edouard@2917: this.shift = false; Edouard@2917: Edouard@2917: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: on_Esc_click: function() { Edouard@2917: Edouard@2917: end_modal.call(this); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: on_Enter_click: function() { Edouard@2917: Edouard@2917: end_modal.call(this); Edouard@2917: Edouard@2917: callback_obj = this.result_callback_obj; Edouard@2917: Edouard@2917: callback_obj.edit_callback(this.editstr); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: on_BackSpace_click: function() { Edouard@2917: Edouard@2917: this.editstr = this.editstr.slice(0,this.editstr.length-1); Edouard@2917: Edouard@2917: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: on_Sign_click: function() { Edouard@2917: Edouard@2917: if(this.editstr[0] == "-") Edouard@2917: Edouard@2917: this.editstr = this.editstr.slice(1,this.editstr.length); Edouard@2917: Edouard@2917: else Edouard@2917: Edouard@2917: this.editstr = "-" + this.editstr; Edouard@2917: edouard@2920: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: edouard@2920: on_NumDot_click: function() { edouard@2920: edouard@2920: if(this.editstr.indexOf(".") == "-1"){ edouard@2920: edouard@2920: this.editstr += "."; edouard@2920: edouard@2920: this.update(); edouard@2920: edouard@2920: } edouard@2920: edouard@2920: }, edouard@2920: Edouard@2917: on_Space_click: function() { Edouard@2917: Edouard@2917: this.editstr += " "; Edouard@2917: edouard@2920: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: caps: false, Edouard@2917: edouard@2920: _caps: undefined, edouard@2920: Edouard@2917: on_CapsLock_click: function() { Edouard@2917: Edouard@2917: this.caps = !this.caps; Edouard@2917: edouard@2920: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: shift: false, Edouard@2917: edouard@2920: _shift: undefined, edouard@2920: Edouard@2917: on_Shift_click: function() { Edouard@2917: edouard@2920: this.shift = !this.shift; edouard@2920: edouard@2920: this.caps = false; edouard@2920: edouard@2920: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: Edouard@2917: coordinates: [ Edouard@2917: Edouard@2917: , Edouard@2917: Edouard@2917: ], Edouard@2917: Edouard@2917: editstr: "", Edouard@2917: edouard@2920: _editstr: undefined, edouard@2920: Edouard@2917: result_callback_obj: undefined, Edouard@2917: Edouard@2917: start_edit: function(info, valuetype, callback_obj, initial) { Edouard@2917: Edouard@2917: show_modal.call(this); Edouard@2917: Edouard@2917: this.editstr = initial; Edouard@2917: Edouard@2917: this.result_callback_obj = callback_obj; Edouard@2917: Edouard@2917: this.Info_elt.textContent = info; Edouard@2917: Edouard@2917: this.shift = false; Edouard@2917: Edouard@2917: this.caps = false; Edouard@2917: Edouard@2917: this.update(); Edouard@2917: Edouard@2917: }, Edouard@2917: Edouard@2917: update: function() { Edouard@2917: edouard@2920: if(this.editstr != this._editstr){ edouard@2920: edouard@2920: this._editstr = this.editstr; edouard@2920: edouard@2920: this.Value_elt.textContent = this.editstr; edouard@2920: edouard@2920: } edouard@2920: edouard@2920: if(this.shift != this._shift){ edouard@2920: edouard@2920: this._shift = this.shift; edouard@2920: edouard@2920: (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub); edouard@2920: edouard@2920: } edouard@2920: edouard@2920: if(this.caps != this._caps){ edouard@2920: edouard@2920: this._caps = this.caps; edouard@2920: edouard@2920: (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub); edouard@2920: edouard@2920: } Edouard@2917: Edouard@2913: }, Edouard@2913: Edouard@2913: edouard@2997: edouard@2997: edouard@2997: items: { edouard@2997: edouard@2997: edouard@2997: edouard@2997: edouard@2997: : " edouard@2997: edouard@2997: ", edouard@2997: edouard@2997: edouard@2997: }, edouard@2997: edouard@2997: edouard@2883: edouard@2883: edouard@2883: frequency: 10, edouard@2883: edouard@2883: edouard@2883: edouard@2883: edouard@2883: needle range edouard@2883: edouard@2883: edouard@2883: edouard@2883: edouard@2883: edouard@2883: value min max edouard@2883: edouard@2883: edouard@2883: edouard@2883: dispatch: function(value) { edouard@2883: edouard@2883: if(this.value_elt) edouard@2883: edouard@2883: this.value_elt.textContent = String(value); edouard@2883: edouard@2883: let [min,max,totallength] = this.range; edouard@2883: edouard@2883: let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); edouard@2883: edouard@2883: let tip = this.range_elt.getPointAtLength(length); edouard@2883: edouard@2883: this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); edouard@2883: edouard@2883: }, edouard@2883: edouard@2883: origin: undefined, edouard@2883: edouard@2883: range: undefined, edouard@2883: edouard@2883: init: function() { edouard@2883: edouard@2883: let min = this.min_elt ? edouard@2883: edouard@2883: Number(this.min_elt.textContent) : edouard@2883: edouard@2883: this.args.length >= 1 ? this.args[0] : 0; edouard@2883: edouard@2883: let max = this.max_elt ? edouard@2883: edouard@2883: Number(this.max_elt.textContent) : edouard@2883: edouard@2883: this.args.length >= 2 ? this.args[1] : 100; edouard@2883: edouard@2883: this.range = [min, max, this.range_elt.getTotalLength()] edouard@2883: edouard@2883: this.origin = this.needle_elt.getPointAtLength(0); edouard@2883: edouard@2883: }, Edouard@2800: Edouard@2797: edouard@2962: edouard@2962: class SwitchWidget extends Widget{ edouard@2962: edouard@2962: frequency = 5; edouard@2962: edouard@2962: dispatch(value) { edouard@2962: edouard@2962: for(let choice of this.choices){ edouard@2962: edouard@2962: if(value != choice.value){ edouard@2962: edouard@2962: choice.elt.setAttribute("style", "display:none"); edouard@2962: edouard@2962: } else { edouard@2962: edouard@2962: choice.elt.setAttribute("style", choice.style); edouard@2962: edouard@2962: } edouard@2962: edouard@2962: } edouard@2962: edouard@2962: } edouard@2962: edouard@2962: } edouard@2962: edouard@2962: Edouard@2839: Edouard@2839: edouard@2851: choices: [ Edouard@2839: Edouard@2907: Edouard@2969: Edouard@2839: edouard@2851: { edouard@2851: edouard@2851: elt:id(" Edouard@2839: Edouard@2839: "), Edouard@2839: edouard@2851: style:" Edouard@2839: Edouard@2839: ", Edouard@2839: edouard@2851: value: Edouard@2839: Edouard@2839: Edouard@2839: edouard@2851: } Edouard@2839: Edouard@2839: , Edouard@2839: Edouard@2839: Edouard@2839: Edouard@2839: edouard@2851: ], Edouard@2801: Edouard@2801: dgaberscek@2977: dgaberscek@2977: dgaberscek@2977: dgaberscek@2977: dgaberscek@2977: dgaberscek@2977: active inactive dgaberscek@2977: dgaberscek@2977: dgaberscek@2977: frequency: 5, dgaberscek@2977: dgaberscek@2977: state: 0, dgaberscek@2977: dgaberscek@2977: dispatch: function(value) { dgaberscek@2977: dgaberscek@2977: this.state = value; dgaberscek@2977: dgaberscek@2977: if (this.state) { dgaberscek@2977: dgaberscek@2977: this.active_elt.setAttribute("style", this.active_style); dgaberscek@2977: dgaberscek@2977: this.inactive_elt.setAttribute("style", "display:none"); dgaberscek@2977: dgaberscek@2977: this.state = 0; dgaberscek@2977: dgaberscek@2977: } else { dgaberscek@2977: dgaberscek@2977: this.inactive_elt.setAttribute("style", this.inactive_style); dgaberscek@2977: dgaberscek@2977: this.active_elt.setAttribute("style", "display:none"); dgaberscek@2977: dgaberscek@2977: this.state = 1; dgaberscek@2977: dgaberscek@2977: } dgaberscek@2977: dgaberscek@2977: }, dgaberscek@2977: dgaberscek@2977: on_click: function(evt) { dgaberscek@2977: edouard@3004: this.apply_hmi_value(0, this.state); dgaberscek@2977: dgaberscek@2977: }, dgaberscek@2977: dgaberscek@2977: active_style: undefined, dgaberscek@2977: dgaberscek@2977: inactive_style: undefined, dgaberscek@2977: dgaberscek@2977: init: function() { dgaberscek@2977: dgaberscek@2977: this.active_style = this.active_elt.style.cssText; dgaberscek@2977: dgaberscek@2977: this.inactive_style = this.inactive_elt.style.cssText; dgaberscek@2977: dgaberscek@2977: this.element.setAttribute("onclick", "hmi_widgets[' dgaberscek@2977: dgaberscek@2977: '].on_click(evt)"); dgaberscek@2977: dgaberscek@2977: }, dgaberscek@2977: dgaberscek@2977: edouard@2883: edouard@2883: edouard@2883: Made with SVGHMI. https://beremiz.org edouard@2883: edouard@2949: edouard@2949: edouard@2949: edouard@2994: edouard@2883: edouard@2883: edouard@2883: edouard@2883: edouard@2883: edouard@2883: edouard@2883: Edouard@2753: