svghmi/widget_meter.ysl2
author usveticic
Wed, 16 Sep 2020 09:41:52 +0200
branchsvghmi
changeset 3056 827bf284feec
parent 3045 f6d428330e04
child 3104 14d15712fcca
permissions -rw-r--r--
Button, ToggleButton and slider updated. Error to warning when building

Button fixed so it doesn't release until it gets feedback from plc

Toggle button changed so it makes changes instantly. There was too big delay if we waited for feedback.

Slider added new features need some changes for final version.
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
     1
// widget_meter.ysl2
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
     2
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     3
template "widget[@type='Meter']", mode="widget_class"{
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     4
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     5
    class MeterWidget extends Widget{
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     6
        frequency = 10;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     7
        origin = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     8
        range = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
     9
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    10
        dispatch(value) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    11
            if(this.value_elt)
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    12
                this.value_elt.textContent = String(value);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    13
            let [min,max,totallength] = this.range;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    14
            let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    15
            let tip = this.range_elt.getPointAtLength(length);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    16
            this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    17
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    18
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    19
        init() {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    20
            let min = this.min_elt ?
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    21
                        Number(this.min_elt.textContent) :
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    22
                        this.args.length >= 1 ? this.args[0] : 0;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    23
            let max = this.max_elt ?
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    24
                        Number(this.max_elt.textContent) :
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    25
                        this.args.length >= 2 ? this.args[1] : 100;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    26
            this.range = [min, max, this.range_elt.getTotalLength()]
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    27
            this.origin = this.needle_elt.getPointAtLength(0);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    28
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    29
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    30
    }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    31
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    32
}
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    33
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    34
template "widget[@type='Meter']", mode="widget_defs" {
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    35
    param "hmi_element";
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    36
    labels("needle range");
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    37
    optional_labels("value min max");
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    38
    |,
2883
8e3d130399b0 SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2882
diff changeset
    39
}
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
    40
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
    41