533 */ |
533 */ |
534 |
534 |
535 | var hmi_widgets = { |
535 | var hmi_widgets = { |
536 foreach "$hmi_elements" { |
536 foreach "$hmi_elements" { |
537 const "widget", "func:parselabel(@inkscape:label)/widget"; |
537 const "widget", "func:parselabel(@inkscape:label)/widget"; |
|
538 const "eltid","@id"; |
538 | "«@id»": { |
539 | "«@id»": { |
539 | type: "«$widget/@type»", |
540 | type: "«$widget/@type»", |
540 | args: [ |
541 | args: [ |
541 foreach "$widget/arg" |
542 foreach "$widget/arg" |
542 | "«@value»"`if "position()!=last()" > ,` |
543 | "«@value»"`if "position()!=last()" > ,` |
545 foreach "$widget/path" { |
546 foreach "$widget/path" { |
546 const "hmipath","@value"; |
547 const "hmipath","@value"; |
547 const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]"; |
548 const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]"; |
548 choose { |
549 choose { |
549 when "count($hmitree_match) = 0" { |
550 when "count($hmitree_match) = 0" { |
550 warning > No match for path "«$hmipath»" in HMI tree |
551 warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«$hmipath»" in HMI tree |
551 } |
552 } |
552 otherwise { |
553 otherwise { |
553 | «$hmitree_match/@index»`if "position()!=last()" > ,` |
554 | «$hmitree_match/@index»`if "position()!=last()" > ,` |
554 } |
555 } |
555 } |
556 } |
704 |
705 |
705 } |
706 } |
706 template "widget[@type='Meter']", mode="widget_defs" { |
707 template "widget[@type='Meter']", mode="widget_defs" { |
707 param "hmi_element"; |
708 param "hmi_element"; |
708 | frequency: 10, |
709 | frequency: 10, |
709 labels("value min max needle range"); |
710 labels("needle range"); |
|
711 optional_labels("value min max"); |
710 | dispatch: function(value) { |
712 | dispatch: function(value) { |
711 | this.value_elt.textContent = String(value); |
713 | if(this.value_elt) |
|
714 | this.value_elt.textContent = String(value); |
712 | let [min,max,totallength] = this.range; |
715 | let [min,max,totallength] = this.range; |
713 | let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); |
716 | let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); |
714 | let tip = this.range_elt.getPointAtLength(length); |
717 | let tip = this.range_elt.getPointAtLength(length); |
715 | this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); |
718 | this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); |
716 | }, |
719 | }, |
717 | origin: undefined, |
720 | origin: undefined, |
718 | range: undefined, |
721 | range: undefined, |
719 | init: function() { |
722 | init: function() { |
720 | this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()] |
723 | let min = this.min_elt ? Number(this.min_elt.textContent) : 0; |
|
724 | let max = this.max_elt ? Number(this.max_elt.textContent) : 100; |
|
725 | this.range = [min, max, this.range_elt.getTotalLength()] |
721 | this.origin = this.needle_elt.getPointAtLength(0); |
726 | this.origin = this.needle_elt.getPointAtLength(0); |
722 | }, |
727 | }, |
723 } |
728 } |
724 |
729 |
725 def "func:escape_quotes" { |
730 def "func:escape_quotes" { |