svghmi/widget_circularbar.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 07 Sep 2021 09:08:40 +0200
branchwxPython4
changeset 3308 358ccd42e052
parent 3241 fe945f1f48b7
child 3330 c3b1a4bfdf0a
permissions -rw-r--r--
Runtime: avoids using "pipe to self" bailout unblocking trick on windows, since select() only takes sockets.
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     1
// widget_circularbar.ysl2
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     2
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     3
widget_desc("CircularBar") {
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     4
    longdesc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     5
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     6
    CircularBar widget changes the end angle of a "path" labeled arc according
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     7
    to value of the single accepted variable.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     8
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     9
    If "min" a "max" labeled texts are provided, then they are used as
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    10
    respective minimum and maximum value. Otherwise, value is expected to be
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    11
    in between 0 and 100.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    12
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    13
    If "value" labeled text is found, then its content is replaced by value.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    14
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    15
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    16
    shortdesc > Change end angle of Inkscape's arc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    17
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    18
    // TODO: add min/max arguments
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    19
    // TODO: add printf-like format
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    20
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    21
    path name="value" accepts="HMI_INT,HMI_REAL" > Value to display
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    22
    
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    23
}
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3105
diff changeset
    24
widget_class("CircularBar") {
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    25
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    26
        frequency = 10;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    27
        range = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    28
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    29
        dispatch(value) {
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    30
            this.display_val = value;
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    31
            this.request_animate();
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    32
        }
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    33
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    34
        animate(){
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    35
            if(this.value_elt)
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    36
                this.value_elt.textContent = String(this.display_val);
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    37
            let [min,max,start,end] = this.range;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    38
            let [cx,cy] = this.center;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    39
            let [rx,ry] = this.proportions;
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    40
            let tip = start + (end-start)*Number(this.display_val)/(max-min);
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    41
            let size = 0;
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    42
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    43
            if (tip-start > Math.PI)
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    44
                size = 1;
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    45
            else
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    46
                size = 0;
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    47
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    48
            this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    49
                                            " A "+rx+","+ry+
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    50
                                            " 0 "+size+
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    51
                                            " 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip)));
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    52
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    53
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    54
        init() {
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    55
            let [start, end, cx, cy, rx, ry] = ["start", "end", "cx", "cy", "rx", "ry"].
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    56
                map(tag=>Number(this.path_elt.getAttribute('sodipodi:'+tag)))
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    57
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    58
            if (ry == 0) 
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    59
                ry = rx;
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    60
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    61
            if (start > end)
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    62
                end = end + 2*Math.PI;
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    63
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    64
            let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt?
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    65
                Number(elt.textContent) :
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    66
                this.args.length >= i+1 ? this.args[i] : def);
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    67
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    68
            this.range = [min, max, start, end];
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    69
            this.center = [cx, cy];
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    70
            this.proportions = [rx, ry];
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    71
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    72
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    73
}
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    74
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3105
diff changeset
    75
widget_defs("CircularBar") {
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    76
    labels("path");
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    77
    optional_labels("value min max");
3105
8819c8b66a42 SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    78
}