svghmi/widgets_common.ysl2
author Edouard Tisserant
Tue, 23 Aug 2022 12:19:44 +0200
changeset 3594 30f7eade322f
parent 3593 122b1094b8e6
child 3595 375626e60b63
permissions -rw-r--r--
SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.

HMI tree paths can be prefixed with a variable name "@name=/MY/HMI/VAR"
Widget declarations can end with a "#" followed by a JS expression that refers to name given to variables.
Widget is disabled if expression's result is false.

Commit includes some more-or-less related generated code refactoring, that should simplify extending widget's variables attributes.
2884
50b9832c51fc SVGHMI: update Makefile to pick all changes to any dependency
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
     1
// widgets_common.ysl2
50b9832c51fc SVGHMI: update Makefile to pick all changes to any dependency
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2883
diff changeset
     2
2808
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
     3
in xsl decl labels(*ptr, name="defs_by_labels") alias call-template {
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
     4
    with "hmi_element", "$hmi_element";
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
     5
    with "labels"{text *ptr};
2937
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     6
    content;
2808
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
     7
};
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
     8
2937
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     9
decl optional_labels(*ptr) alias - {
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    10
    /* TODO add some per label xslt variable to check if exist */
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    11
    labels(*ptr){
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    12
        with "mandatory","'no'";
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    13
        content;
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    14
    }
2836
ce6cecdb7320 SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents: 2834
diff changeset
    15
};
ce6cecdb7320 SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents: 2834
diff changeset
    16
3522
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    17
decl warning_labels(*ptr) alias - {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    18
    labels(*ptr){
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    19
        with "mandatory","'warn'";
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    20
        content;
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    21
    }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    22
};
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    23
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
    24
decl activable() alias - {
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
    25
    |     activable_sub:{
3522
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
    26
    warning_labels("/active /inactive") {
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
    27
        content;
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
    28
    }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
    29
    |     }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
    30
};
2937
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    31
decl activable_labels(*ptr) alias - {
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    32
    optional_labels(*ptr) {
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    33
        with "subelements","'active inactive'";
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    34
        content;
9226a830fbc3 SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    35
    }
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
    36
};
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
    37
3233
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    38
in xsl decl widget_desc(%name, match="widget[@type='%name']", mode="widget_desc") alias template {
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    39
    type > «@type»
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    40
    content;
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    41
};
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    42
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: 3162
diff changeset
    43
in xsl decl widget_class(%name, *clsname="%nameWidget", match="widget[@type='%name']", mode="widget_class") alias template {
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: 3162
diff changeset
    44
    | class `text **clsname` extends Widget{
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: 3162
diff changeset
    45
    content;
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: 3162
diff changeset
    46
    | }
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: 3162
diff changeset
    47
};
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: 3162
diff changeset
    48
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: 3162
diff changeset
    49
in xsl decl widget_defs(%name, match="widget[@type='%name']", mode="widget_defs") alias template {
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: 3162
diff changeset
    50
    param "hmi_element";
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: 3162
diff changeset
    51
    content;
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: 3162
diff changeset
    52
};
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: 3162
diff changeset
    53
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: 3162
diff changeset
    54
in xsl decl widget_page(%name, match="widget[@type='%name']", mode="widget_page") alias template {
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: 3162
diff changeset
    55
    param "page_desc";
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: 3162
diff changeset
    56
    content;
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: 3162
diff changeset
    57
};
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: 3162
diff changeset
    58
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: 3162
diff changeset
    59
decl gen_index_xhtml alias - {
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: 3162
diff changeset
    60
    content;
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: 3162
diff changeset
    61
};
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: 3162
diff changeset
    62
2955
64e603b84aa3 SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2954
diff changeset
    63
template "svg:*", mode="hmi_widgets" {
2886
6c82fad8be65 SVGHMI: Simplification and optimization. func:parselabel becomes a template.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2884
diff changeset
    64
    const "widget", "func:widget(@id)";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    65
    const "eltid","@id";
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
    66
    const "args" foreach "$widget/arg" > "«func:escape_quotes(@value)»"`if "position()!=last()" > ,`
2950
1e53d8b60ee9 SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2949
diff changeset
    67
    const "indexes" foreach "$widget/path" {
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    68
        if "position()!=last()" > ,
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    69
    }
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    70
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    71
    const "variables" foreach "$widget/path" {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    72
        > [
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    73
        choose {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    74
            when "not(@index)" {
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
    75
                choose {
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
    76
                    when "not(@type)" {
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3026
diff changeset
    77
                        warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    78
                        > undefined
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
    79
                    }
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
    80
                    when "@type = 'PAGE_LOCAL'" 
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    81
                        > "«@value»"
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
    82
                    when "@type = 'HMI_LOCAL'" 
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    83
                        > hmi_local_index("«@value»")
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    84
                    otherwise 
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    85
                        error > Internal error while processing widget's non indexed HMI tree path : unknown type
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
    86
                }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    87
            }
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    88
            otherwise {
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    89
                > «@index»
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    90
            }
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    91
        }
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    92
        > , {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    93
        if "@min and @max"{
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    94
                > minmax:[«@min», «@max»]
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    95
                if "@assign"
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    96
                    > ,
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    97
        }
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    98
        if "@assign"
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
    99
                > assign:"«@assign»"
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   100
        > }]
3099
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   101
        if "position()!=last()" > ,
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   102
    }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   103
3408
13c5cac55ac7 SVGHMI: add syntax for widget update frequency in widget label: HMI:WidgetType|freq:arg0:arg1@path
Edouard Tisserant
parents: 3233
diff changeset
   104
    const "freq" choose {
3412
04c4835ca376 SVGHMI: Fixed support for frequency parsing in widget label
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3408
diff changeset
   105
        when "$widget/@freq"
3455
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   106
            > "«$widget/@freq»"
3408
13c5cac55ac7 SVGHMI: add syntax for widget update frequency in widget label: HMI:WidgetType|freq:arg0:arg1@path
Edouard Tisserant
parents: 3233
diff changeset
   107
        otherwise
13c5cac55ac7 SVGHMI: add syntax for widget update frequency in widget label: HMI:WidgetType|freq:arg0:arg1@path
Edouard Tisserant
parents: 3233
diff changeset
   108
            > undefined
13c5cac55ac7 SVGHMI: add syntax for widget update frequency in widget label: HMI:WidgetType|freq:arg0:arg1@path
Edouard Tisserant
parents: 3233
diff changeset
   109
    }
13c5cac55ac7 SVGHMI: add syntax for widget update frequency in widget label: HMI:WidgetType|freq:arg0:arg1@path
Edouard Tisserant
parents: 3233
diff changeset
   110
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   111
    const "enable_expr" choose{
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   112
        when "$widget/@enable_expr"
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   113
            > true
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   114
        otherwise
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   115
            > false
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   116
    }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   117
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   118
    |   "«@id»": new «$widget/@type»Widget ("«@id»",«$freq»,[«$args»],[«$variables»],«$enable_expr»,{
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   119
    if "$widget/@enable_expr" {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   120
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   121
    |       assignments: [],
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   122
    |       compute_enable: function(value, oldval, varnum) {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   123
    |         let result = false;
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   124
    |         do {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   125
        foreach "$widget/path" {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   126
            const "varid","generate-id()";
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   127
            const "varnum","position()-1";
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   128
            if "@assign" foreach "$widget/path[@assign]" if "$varid = generate-id()" {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   129
    |           if(varnum == «$varnum») this.assignments[«position()-1»] = value;
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   130
    |           let «@assign» = this.assignments[«position()-1»];
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   131
    |           if(«@assign» == undefined) break;
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   132
            }
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   133
        }
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   134
    |           result = «$widget/@enable_expr»;
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   135
    |         } while(0);
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   136
    |         this.enable(result);
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   137
    |       },
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   138
    }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   139
    apply "$widget", mode="widget_defs" with "hmi_element",".";
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   140
    |   })`if "position()!=last()" > ,`
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   141
}
2948
faaf677ea99d SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
   142
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   143
emit "preamble:local-variable-indexes" {
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   144
    ||
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3139
diff changeset
   145
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   146
    let hmi_locals = {};
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   147
    var last_remote_index = hmitree_types.length - 1;
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   148
    var next_available_index = hmitree_types.length;
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   149
    let cookies = new Map(document.cookie.split("; ").map(s=>s.split("=")));
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   150
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   151
    const local_defaults = {
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   152
    ||
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   153
    foreach "$parsed_widgets/widget[starts-with(@type,'VarInit')]"{
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   154
        if "count(path) != 1" error > VarInit «@id» must have only one variable given.
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   155
        if "path/@type != 'PAGE_LOCAL' and path/@type != 'HMI_LOCAL'" error > VarInit «@id» only applies to HMI variable.
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   156
        >     "«path/@value»":
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   157
        choose {
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   158
            when "@type = 'VarInitPersistent'" > cookies.has("«path/@value»")?cookies.get("«path/@value»"):«arg[1]/@value»
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   159
            otherwise > «arg[1]/@value»
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   160
        }
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   161
        > \n
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   162
        if "position()!=last()" > ,
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   163
    }
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   164
    ||
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   165
    };
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   166
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   167
    const persistent_locals = new Set([
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   168
    ||
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   169
    foreach "$parsed_widgets/widget[@type='VarInitPersistent']"{
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   170
    |    "«path/@value»"`if "position()!=last()" > ,`
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   171
    }
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   172
    ||
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   173
    ]);
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   174
    var persistent_indexes = new Map();
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   175
    var cache = hmitree_types.map(_ignored => undefined);
3152
c80a5a7198ea SVGHMI: Switch from {object} to Map for "updates" global, for performance but also preventing wierd behaviour when iterating
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3142
diff changeset
   176
    var updates = new Map();
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   177
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   178
    function page_local_index(varname, pagename){
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   179
        let pagevars = hmi_locals[pagename];
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   180
        let new_index;
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   181
        if(pagevars == undefined){
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   182
            new_index = next_available_index++;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   183
            hmi_locals[pagename] = {[varname]:new_index}
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   184
        } else {
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   185
            let result = pagevars[varname];
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   186
            if(result != undefined) {
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   187
                return result;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   188
            }
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   189
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   190
            new_index = next_available_index++;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   191
            pagevars[varname] = new_index;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   192
        }
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   193
        let defaultval = local_defaults[varname];
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   194
        if(defaultval != undefined) {
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   195
            cache[new_index] = defaultval; 
3152
c80a5a7198ea SVGHMI: Switch from {object} to Map for "updates" global, for performance but also preventing wierd behaviour when iterating
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3142
diff changeset
   196
            updates.set(new_index, defaultval);
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   197
            if(persistent_locals.has(varname))
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   198
                persistent_indexes.set(new_index, varname);
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   199
        }
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   200
        return new_index;
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   201
    }
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   202
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   203
    function hmi_local_index(varname){
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   204
        return page_local_index(varname, "HMI_LOCAL");
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   205
    }
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   206
    ||
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   207
}
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   208
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   209
emit "preamble:widget-base-class" {
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   210
    ||
3019
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   211
    var pending_widget_animates = [];
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   212
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   213
    function _hide(elt, placeholder){
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   214
        if(elt.parentNode != null)
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   215
            placeholder.parentNode.removeChild(elt);
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   216
    }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   217
    function _show(elt, placeholder){
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   218
        placeholder.parentNode.insertBefore(elt, placeholder);
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   219
    }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   220
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   221
    function set_activation_state(eltsub, state){
3522
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   222
        if(eltsub.active_elt != undefined){
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   223
            if(eltsub.active_elt_placeholder == undefined){
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   224
                eltsub.active_elt_placeholder = document.createComment("");
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   225
                eltsub.active_elt.parentNode.insertBefore(eltsub.active_elt_placeholder, eltsub.active_elt);
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   226
            }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   227
            (state?_show:_hide)(eltsub.active_elt, eltsub.active_elt_placeholder);
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   228
        }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   229
        if(eltsub.inactive_elt != undefined){
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   230
            if(eltsub.inactive_elt_placeholder == undefined){
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   231
                eltsub.inactive_elt_placeholder = document.createComment("");
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   232
                eltsub.inactive_elt.parentNode.insertBefore(eltsub.inactive_elt_placeholder, eltsub.inactive_elt);
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   233
            }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   234
            ((state || state==undefined)?_hide:_show)(eltsub.inactive_elt, eltsub.inactive_elt_placeholder);
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   235
        }
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   236
    }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   237
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   238
    function activate_activable(eltsub) {
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   239
        set_activation_state(eltsub, true);
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   240
    }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   241
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   242
    function inactivate_activable(eltsub) {
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   243
        set_activation_state(eltsub, false);
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   244
    }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   245
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   246
    class Widget {
2963
113e2f2e324d SVGHMI: more Widget properties declared ES6 style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2958
diff changeset
   247
        offset = 0;
113e2f2e324d SVGHMI: more Widget properties declared ES6 style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2958
diff changeset
   248
        frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
2980
2a21d6060d64 SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons.
Edouard Tisserant
parents: 2963
diff changeset
   249
        unsubscribable = false;
3019
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   250
        pending_animate = false;
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   251
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   252
        constructor(elt_id, freq, args, variables, enable_expr, members){
2958
895d3f2b1786 SVGHMI: Back button updated to class style
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2955
diff changeset
   253
            this.element_id = elt_id;
2950
1e53d8b60ee9 SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2949
diff changeset
   254
            this.element = id(elt_id);
1e53d8b60ee9 SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2949
diff changeset
   255
            this.args = args;
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   256
            [this.indexes, this.variables_options] = (variables.length>0) ? zip(...variables) : [[],[]];
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   257
            this.indexes_length = this.indexes.length;
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   258
            this.enable_expr = enable_expr;
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   259
            Object.keys(members).forEach(prop => this[prop]=members[prop]);
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   260
            this.lastapply = this.indexes.map(() => undefined);
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   261
            this.inhibit = this.indexes.map(() => undefined);
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   262
            this.pending = this.indexes.map(() => undefined);
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   263
            this.bound_uninhibit = this.uninhibit.bind(this);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   264
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   265
            this.lastdispatch = this.indexes.map(() => undefined);
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   266
            this.deafen = this.indexes.map(() => undefined);
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   267
            this.incoming = this.indexes.map(() => undefined);
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   268
            this.bound_undeafen = this.undeafen.bind(this);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   269
3417
9b9775d230f5 SVGHMI: fix again appication of frequency value when given in label. Use it on PushButton instance in svghmi test.
Edouard Tisserant
parents: 3412
diff changeset
   270
            this.forced_frequency = freq;
3453
e5967a2ae2bb SVGHMI: allow widgets to disable clipping on variables given with min and max. Setting this.clip = false disables clipping.
Edouard Tisserant
parents: 3452
diff changeset
   271
            this.clip = true;
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   272
        }
2958
895d3f2b1786 SVGHMI: Back button updated to class style
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2955
diff changeset
   273
3455
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   274
        do_init(){
3473
1202b47e7e63 SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
Edouard Tisserant
parents: 3455
diff changeset
   275
            let forced = this.forced_frequency;
1202b47e7e63 SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
Edouard Tisserant
parents: 3455
diff changeset
   276
            if(forced !== undefined){
3455
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   277
                /*
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   278
                once every 10 seconds : 10s
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   279
                once per minute : 1m
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   280
                once per hour : 1h
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   281
                once per day : 1d
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   282
                */
3473
1202b47e7e63 SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
Edouard Tisserant
parents: 3455
diff changeset
   283
                let unit = forced.slice(-1);
3455
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   284
                let factor = {
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   285
                    "s":1,
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   286
                    "m":60,
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   287
                    "h":3600,
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   288
                    "d":86400}[unit];
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   289
3473
1202b47e7e63 SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
Edouard Tisserant
parents: 3455
diff changeset
   290
                this.frequency = factor ? 1/(factor * Number(forced.slice(0,-1)))
1202b47e7e63 SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
Edouard Tisserant
parents: 3455
diff changeset
   291
                                          : Number(forced);
3455
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   292
            }
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   293
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   294
            let init = this.init;
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   295
            if(typeof(init) == "function"){
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   296
                try {
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   297
                    init.call(this);
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   298
                } catch(err) {
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   299
                    console.log(err);
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   300
                }
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   301
            }
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   302
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   303
            if(this.enable_expr){
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   304
                this.disabled_elt = null;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   305
                this.enabled_elts = [];
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   306
                this.enable_state = false;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   307
                this.enable_displayed_state = false;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   308
                for(let child of Array.from(this.element.children)){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   309
                    if(child.getAttribute("inkscape:label")=="disabled"){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   310
                        this.disabled_elt = child;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   311
                    }else{
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   312
                        this.enabled_elts.push(child);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   313
                        this.element.removeChild(child);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   314
                    }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   315
                }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   316
            }
3455
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   317
        }
2716cd8e498d SVGHMI: Add support for forcing widget update frequency with period longer than a second. As an example, "HMI:Display|10s@/myvar" updates variable every 10 seconds.
Edouard Tisserant
parents: 3453
diff changeset
   318
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   319
        unsub(){
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   320
            /* remove subsribers */
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   321
            if(!this.unsubscribable)
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   322
                for(let i = 0; i < this.indexes_length; i++) {
3139
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   323
                    /* flush updates pending because of inhibition */
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3139
diff changeset
   324
                    let inhibition = this.inhibit[i];
3139
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   325
                    if(inhibition != undefined){
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   326
                        clearTimeout(inhibition);
3142
2637bb6a6bb0 SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3139
diff changeset
   327
                        this.lastapply[i] = undefined;
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   328
                        this.uninhibit(i);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   329
                    }
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   330
                    let deafened = this.deafen[i];
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   331
                    if(deafened != undefined){
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   332
                        clearTimeout(deafened);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   333
                        this.lastdispatch[i] = undefined;
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   334
                        this.undeafen(i);
3139
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   335
                    }
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   336
                    let index = this.indexes[i];
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   337
                    if(this.relativeness[i])
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   338
                        index += this.offset;
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   339
                    subscribers(index).delete(this);
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   340
                }
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   341
            this.offset = 0;
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   342
            this.relativeness = undefined;
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   343
        }
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   344
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   345
        sub(new_offset=0, relativeness, container_id){
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   346
            this.offset = new_offset;
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   347
            this.relativeness = relativeness;
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   348
            this.container_id = container_id ;
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   349
            /* add this's subsribers */
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   350
            if(!this.unsubscribable)
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   351
                for(let i = 0; i < this.indexes_length; i++) {
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   352
                    let index = this.get_variable_index(i);
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   353
                    if(index == undefined) continue;
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   354
                    subscribers(index).add(this);
3005
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   355
                }
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   356
            need_cache_apply.push(this); 
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   357
        }
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   358
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   359
        apply_cache() {
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   360
            if(!this.unsubscribable) for(let index in this.indexes){
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   361
                /* dispatch current cache in newly opened page widgets */
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
   362
                let realindex = this.get_variable_index(index);
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   363
                if(realindex == undefined) continue;
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   364
                let cached_val = cache[realindex];
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   365
                if(cached_val != undefined)
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   366
                    this._dispatch(cached_val, cached_val, index);
2951
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   367
            }
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   368
        }
506fe9272660 SVGHMI: Widget's specific sub/unsub traits are now wxpressed in widget's class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2950
diff changeset
   369
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   370
        get_variable_index(varnum) {
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   371
            let index = this.indexes[varnum];
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   372
            if(typeof(index) == "string"){
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   373
                index = page_local_index(index, this.container_id);
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   374
            } else {
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   375
                if(this.relativeness[varnum]){
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   376
                    index += this.offset;
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   377
                }
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   378
            }
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3007
diff changeset
   379
            return index;
3001
003fd80ff0b8 SVGHMI: add get_idx(index) to widget objects to factorize a bit code repeated accross widgets. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2997
diff changeset
   380
        }
3098
5823b73b132f SVGHMI: decoupled operation string evaluation from HMI variable uptdate in change_hmi_variable(), paving the way for min/max boundaries enforcement
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3058
diff changeset
   381
3099
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   382
        overshot(new_val, max) {
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   383
        }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   384
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   385
        undershot(new_val, min) {
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   386
        }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   387
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   388
        clip_min_max(index, new_val) {
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   389
            let minmax = this.variables_options[index].minmax;
3099
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   390
            if(minmax !== undefined && typeof new_val == "number") {
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   391
                let [min,max] = minmax;
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   392
                if(new_val < min){
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   393
                    this.undershot(new_val, min);
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   394
                    return min;
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   395
                }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   396
                if(new_val > max){
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   397
                    this.overshot(new_val, max);
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   398
                    return max;
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   399
                }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   400
            }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   401
            return new_val;
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   402
        }
c7d14130401f SVGHMI: Added clipping to min and max value for all widget using @path,min,max syntax. Added overshot() and undershot() methods to widget base class, called when value is limited to max or min respectively.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3098
diff changeset
   403
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   404
        change_hmi_value(index, opstr) {
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   405
            let realindex = this.get_variable_index(index);
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   406
            if(realindex == undefined) return undefined;
3098
5823b73b132f SVGHMI: decoupled operation string evaluation from HMI variable uptdate in change_hmi_variable(), paving the way for min/max boundaries enforcement
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3058
diff changeset
   407
            let old_val = cache[realindex];
5823b73b132f SVGHMI: decoupled operation string evaluation from HMI variable uptdate in change_hmi_variable(), paving the way for min/max boundaries enforcement
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3058
diff changeset
   408
            let new_val = eval_operation_string(old_val, opstr);
3453
e5967a2ae2bb SVGHMI: allow widgets to disable clipping on variables given with min and max. Setting this.clip = false disables clipping.
Edouard Tisserant
parents: 3452
diff changeset
   409
            if(this.clip)
e5967a2ae2bb SVGHMI: allow widgets to disable clipping on variables given with min and max. Setting this.clip = false disables clipping.
Edouard Tisserant
parents: 3452
diff changeset
   410
                new_val = this.clip_min_max(index, new_val);
3098
5823b73b132f SVGHMI: decoupled operation string evaluation from HMI variable uptdate in change_hmi_variable(), paving the way for min/max boundaries enforcement
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3058
diff changeset
   411
            return apply_hmi_value(realindex, new_val);
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3001
diff changeset
   412
        }
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3001
diff changeset
   413
3139
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   414
        _apply_hmi_value(index, new_val) {
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   415
            let realindex = this.get_variable_index(index);
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   416
            if(realindex == undefined) return undefined;
3453
e5967a2ae2bb SVGHMI: allow widgets to disable clipping on variables given with min and max. Setting this.clip = false disables clipping.
Edouard Tisserant
parents: 3452
diff changeset
   417
            if(this.clip)
e5967a2ae2bb SVGHMI: allow widgets to disable clipping on variables given with min and max. Setting this.clip = false disables clipping.
Edouard Tisserant
parents: 3452
diff changeset
   418
                new_val = this.clip_min_max(index, new_val);
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   419
            return apply_hmi_value(realindex, new_val);
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3001
diff changeset
   420
        }
3006
bbffdefd2eed SVGHMI: JS refactoring continued : "dispatch_value_to_widget" becomes widget class member "new_hmi_value" (was also broken by previous relativeness commit)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3005
diff changeset
   421
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   422
        uninhibit(index){
3139
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   423
            this.inhibit[index] = undefined;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   424
            let new_val = this.pending[index];
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   425
            this.pending[index] = undefined;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   426
            return this.apply_hmi_value(index, new_val);
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   427
        }
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   428
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   429
        apply_hmi_value(index, new_val) {
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   430
            if(this.inhibit[index] == undefined){
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   431
                let now = Date.now();
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   432
                let min_interval = 1000/this.frequency;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   433
                let lastapply = this.lastapply[index];
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   434
                if(lastapply == undefined || now > lastapply + min_interval){
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   435
                    this.lastapply[index] = now;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   436
                    return this._apply_hmi_value(index, new_val);
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   437
                }
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   438
                else {
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   439
                    let elapsed = now - lastapply;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   440
                    this.pending[index] = new_val;
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   441
                    this.inhibit[index] = setTimeout(this.bound_uninhibit, min_interval - elapsed, index);
3139
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   442
                }
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   443
            }
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   444
            else {
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   445
                this.pending[index] = new_val;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   446
                return new_val;
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   447
            }
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   448
        }
1f5ca646ce6e SVGHMI: Add inhibition to widget's apply_hmi_value() so that it does not change variable more frquently than given widget's frequency. This prevents flooding network with many update if browser is producing events at high rate, as for exemple when dragging ScrollBar's cursor.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3135
diff changeset
   449
3006
bbffdefd2eed SVGHMI: JS refactoring continued : "dispatch_value_to_widget" becomes widget class member "new_hmi_value" (was also broken by previous relativeness commit)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3005
diff changeset
   450
        new_hmi_value(index, value, oldval) {
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   451
            // TODO avoid searching, store index at sub()
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   452
            for(let i = 0; i < this.indexes_length; i++) {
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   453
                let refindex = this.get_variable_index(i);
3058
6ea4b7e1a9ed Merge + fix side effects of making warning instead of errors in case of missing HMI variable
Edouard Tisserant
parents: 3040 3056
diff changeset
   454
                if(refindex == undefined) continue;
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   455
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   456
                if(index == refindex) {
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   457
                    this._dispatch(value, oldval, i);
3025
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   458
                    break;
48e7e336c052 SVGHMI: HMI:VarInit:"a string"@a_value : empty widget (i.e. empty svg:group) that initialize content of local variables to value given as first argument.
Edouard Tisserant
parents: 3024
diff changeset
   459
                }
3006
bbffdefd2eed SVGHMI: JS refactoring continued : "dispatch_value_to_widget" becomes widget class member "new_hmi_value" (was also broken by previous relativeness commit)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3005
diff changeset
   460
            }
bbffdefd2eed SVGHMI: JS refactoring continued : "dispatch_value_to_widget" becomes widget class member "new_hmi_value" (was also broken by previous relativeness commit)
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3005
diff changeset
   461
        }
3019
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   462
        
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   463
        undeafen(index){
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   464
            this.deafen[index] = undefined;
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   465
            let [new_val, old_val] = this.incoming[index];
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   466
            this.incoming[index] = undefined;
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   467
            this.dispatch(new_val, old_val, index);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   468
        }
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   469
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   470
        enable(enabled){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   471
            if(this.enable_state != enabled){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   472
                this.enable_state = enabled;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   473
                this.request_animate();
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   474
            }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   475
        }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   476
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   477
        animate_enable(){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   478
            if(this.enable_state && !this.enable_displayed_state){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   479
                //show widget
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   480
                for(let child of this.enabled_elts){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   481
                    this.element.appendChild(child);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   482
                }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   483
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   484
                //hide disabled content
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   485
                if(this.disabled_elt && this.disabled_elt.parentNode != null)
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   486
                    this.element.removeChild(this.disabled_elt);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   487
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   488
                this.enable_displayed_state = true;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   489
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   490
            }else if(!this.enable_state && this.enable_displayed_state){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   491
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   492
                //hide widget
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   493
                for(let child of this.enabled_elts){
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   494
                    if(child.parentNode != null)
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   495
                        this.element.removeChild(child);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   496
                }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   497
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   498
                //show disabled content
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   499
                if(this.disabled_elt)
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   500
                    this.element.appendChild(this.disabled_elt);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   501
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   502
                this.enable_displayed_state = false;
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   503
            }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   504
        }
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   505
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   506
        _dispatch(value, oldval, varnum) {
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   507
            let dispatch = this.dispatch;
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   508
            let has_dispatch = dispatch != undefined;
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   509
            if(has_dispatch || this.enable_expr){
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   510
                if(this.deafen[varnum] == undefined){
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   511
                    let now = Date.now();
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   512
                    let min_interval = 1000/this.frequency;
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   513
                    let lastdispatch = this.lastdispatch[varnum];
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   514
                    if(lastdispatch == undefined || now > lastdispatch + min_interval){
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   515
                        this.lastdispatch[varnum] = now;
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   516
                        if(has_dispatch) try {
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   517
                            dispatch.call(this, value, oldval, varnum);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   518
                        } catch(err) {
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   519
                            console.log(err);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   520
                        }
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   521
                        if(this.enable_expr) try {
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   522
                            this.compute_enable(value, oldval, varnum);
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   523
                        } catch(err) {
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   524
                            console.log(err);
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   525
                        }
3504
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   526
                    }
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   527
                    else {
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   528
                        let elapsed = now - lastdispatch;
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   529
                        this.incoming[varnum] = [value, oldval];
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   530
                        this.deafen[varnum] = setTimeout(this.bound_undeafen, min_interval - elapsed, varnum);
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   531
                    }
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   532
                }
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   533
                else {
9d895a103019 SVGHMI: add widget update rate limit on variable change.
Edouard Tisserant
parents: 3473
diff changeset
   534
                    this.incoming[varnum] = [value, oldval];
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   535
                }
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   536
            }
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   537
        }
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   538
3019
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   539
        _animate(){
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   540
            if(this.enable_expr)
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   541
                this.animate_enable();
3594
30f7eade322f SVGHMI: add support for "enable expressions" with arbitrary variable name assignment.
Edouard Tisserant
parents: 3593
diff changeset
   542
            if(this.animate != undefined && (!this.enable_expr || this.enable_state))
3593
122b1094b8e6 SVGHMI: preliminary implementation of a general enable bit for all widgets, using "#" at the end of widget declaration, and a "disabled" element that becomes visible instead of widget when disabled.
Edouard Tisserant
parents: 3556
diff changeset
   543
                this.animate();
3019
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   544
            this.pending_animate = false;
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   545
        }
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   546
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   547
        request_animate(){
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   548
            if(!this.pending_animate){
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   549
                pending_widget_animates.push(this);
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   550
                this.pending_animate = true;
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   551
                requestHMIAnimation();
497aac6522a3 SVGHMI: provide request_animate() to Widget authors so that they can register redraw code when events lead to redraw. Widget member animate() is called when it is time to update DOM.
Edouard Tisserant
parents: 3007
diff changeset
   552
            }
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   553
        }
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   554
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   555
        set_activation_state(state){
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   556
            set_activation_state(this.activable_sub, state);
3125
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   557
        }
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   558
    }
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   559
    ||
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   560
}
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   561
3128
32a4675af377 SVGHMI: Added HMI:VarInitPersistent to initialize persistent HMI_LOCAL and PAGE_LOCAL variables, stored as cookies in browser.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3125
diff changeset
   562
const "excluded_types", "str:split('Page VarInit VarInitPersistent')";
3120
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   563
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   564
// Key to filter unique types
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   565
key "TypesKey", "widget", "@type";
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   566
3007
360300a8b995 SVGHMI : have to move some JS declarations from "preamble" to "declarations" and others from "declarations" to "definitions" section to make room for JS libraries that would be used by widget classes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3006
diff changeset
   567
emit "declarations:hmi-classes" {
3120
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   568
    const "used_widget_types", """$parsed_widgets/widget[
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   569
                                    generate-id() = generate-id(key('TypesKey', @type)) and 
7ecaefe38f6f SVGHMI: Remove recursive walk in parsed widget to find unique type and use xsl:key instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3119
diff changeset
   570
                                    not(@type = $excluded_types)]""";
2948
faaf677ea99d SVGHMI: Add an exslt function to collect used widget types, in order to only include necessary JS definitions in furure changes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
   571
    apply "$used_widget_types", mode="widget_class";
3556
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   572
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   573
}
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   574
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   575
template "widget", mode="widget_class" {
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   576
    ||
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   577
    class «@type»Widget extends Widget{
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   578
        /* empty class, as «@type» widget didn't provide any */
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   579
    }
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   580
    ||
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   581
    warning > «@type» widget is used in SVG but widget type is not declared
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   582
}
2949
e50908ddec60 SVGHMI: One class per widget type, widget objects are instances of these classes, and members are passed through constructor. This allows to keep compatible with previous widget_defs template used in most widgets.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2948
diff changeset
   583
3119
17a9c7a334f7 SVGHMI: Fix browser side exception when some widget are not used, and are then discarded and not present in final SVG. In that case JS code was still making reference to discarded widget elements and was raising exception at init.
Edouard Tisserant
parents: 3101
diff changeset
   584
const "included_ids","$parsed_widgets/widget[not(@type = $excluded_types) and not(@id = $discardable_elements/@id)]/@id";
3121
8094494113b6 SVGHMI: Prevent excluded widget to appear in generated pages' widget list.
Edouard Tisserant
parents: 3119
diff changeset
   585
const "hmi_widgets","$hmi_elements[@id = $included_ids]";
3162
fbe1ffaa56cf SVGHMI: More build time optimization : def_by_label now takes far less time.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3152
diff changeset
   586
const "result_widgets","$result_svg_ns//*[@id = $hmi_widgets/@id]";
2955
64e603b84aa3 SVGHMI: Exclude non-widget HMI:* labeled elements from hmi_widget. Namely : HMI:Page HMI:Lang and HMI:List have been excluded.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2954
diff changeset
   587
3007
360300a8b995 SVGHMI : have to move some JS declarations from "preamble" to "declarations" and others from "declarations" to "definitions" section to make room for JS libraries that would be used by widget classes.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3006
diff changeset
   588
emit "declarations:hmi-elements" {
2941
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2937
diff changeset
   589
    | var hmi_widgets = {
3121
8094494113b6 SVGHMI: Prevent excluded widget to appear in generated pages' widget list.
Edouard Tisserant
parents: 3119
diff changeset
   590
    apply "$hmi_widgets", mode="hmi_widgets";
2941
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2937
diff changeset
   591
    | }
3556
5d73bed497de SVGHMI: Warn at build time when SVG refers to non-existing widget types.
Edouard Tisserant
parents: 3522
diff changeset
   592
    |
2941
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2937
diff changeset
   593
}
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2937
diff changeset
   594
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   595
function "defs_by_labels" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   596
    param "labels","''";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   597
    param "mandatory","'yes'";
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   598
    param "subelements","/..";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   599
    param "hmi_element";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   600
    const "widget_type","@type";
3522
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   601
    const "widget_id","@id";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   602
    foreach "str:split($labels)" {
3452
a0bd2c4cb8f7 SVGHMI: allow designating widget's sub-elements as main element child rather than descendant. Names staring with "/" in yslt call to labels() only match direct widget childs.
Edouard Tisserant
parents: 3417
diff changeset
   603
        const "absolute", "starts-with(., '/')";
a0bd2c4cb8f7 SVGHMI: allow designating widget's sub-elements as main element child rather than descendant. Names staring with "/" in yslt call to labels() only match direct widget childs.
Edouard Tisserant
parents: 3417
diff changeset
   604
        const "name","substring(.,number($absolute)+1)";
a0bd2c4cb8f7 SVGHMI: allow designating widget's sub-elements as main element child rather than descendant. Names staring with "/" in yslt call to labels() only match direct widget childs.
Edouard Tisserant
parents: 3417
diff changeset
   605
        const "widget","$result_widgets[@id = $hmi_element/@id]";
a0bd2c4cb8f7 SVGHMI: allow designating widget's sub-elements as main element child rather than descendant. Names staring with "/" in yslt call to labels() only match direct widget childs.
Edouard Tisserant
parents: 3417
diff changeset
   606
        const "elt","($widget//*[not($absolute) and @inkscape:label=$name] | $widget/*[$absolute and @inkscape:label=$name])[1]";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   607
        choose {
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   608
            when "not($elt/@id)" {
3522
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   609
                if "$mandatory!='no'" {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   610
                    const "errmsg" > «$widget_type» widget (id=«$widget_id») must have a «$name» element
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   611
                    choose { 
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   612
                        when "$mandatory='yes'" {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   613
                            error > «$errmsg»
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   614
                        }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   615
                        otherwise {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   616
                            warning > «$errmsg»
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   617
                        }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   618
                    }
2834
6ac6a9dff594 SVGHMI: be a bit more tolerant with missing HMI paths or missing elements in widgets : continue build (with warning) and fail silently at runtime.
Edouard Tisserant
parents: 2833
diff changeset
   619
                }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   620
                // otherwise produce nothing
2797
c5ba1e77f054 SVGHMI: added a widgets description object, accessed by id. Added frequency to widgets, as separate template to allow future customization. Excluded non svg elements (i.e inkscape Sets) with HMI: labels from widgets.
Edouard Tisserant
parents: 2796
diff changeset
   621
            }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   622
            otherwise {
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   623
                |     «$name»_elt: id("«$elt/@id»"),
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   624
                if "$subelements" {
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   625
                |     «$name»_sub: {
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   626
                    foreach "str:split($subelements)" {
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   627
                        const "subname",".";
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   628
                        const "subelt","$elt/*[@inkscape:label=$subname][1]";
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   629
                        choose {
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   630
                            when "not($subelt/@id)" {
3522
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   631
                                if "$mandatory!='no'" {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   632
                                    const "errmsg" > «$widget_type» widget (id=«$widget_id») must have a «$name»/«$subname» element
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   633
                                    choose { 
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   634
                                        when "$mandatory='yes'" {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   635
                                            error > «$errmsg»
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   636
                                        }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   637
                                        otherwise {
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   638
                                            warning > «$errmsg»
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   639
                                        }
f3a14422d56e SVGHMI: add warning_labels, same as optional_labels but emits warnings at build time if element is missing.
Edouard Tisserant
parents: 3520
diff changeset
   640
                                    }
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   641
                                }
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   642
                |         /* missing «$name»/«$subname» element */
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   643
                            }
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   644
                            otherwise {
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3504
diff changeset
   645
                |         "«$subname»_elt": id("«$subelt/@id»")`if "position()!=last()" > ,`
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   646
                            }
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   647
                        }
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   648
                    }
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   649
                |     },
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2897
diff changeset
   650
                }
2836
ce6cecdb7320 SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents: 2834
diff changeset
   651
            }
2808
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
   652
        }
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
   653
    }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   654
}
2808
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
   655
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: 2881
diff changeset
   656
def "func:escape_quotes" {
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: 2881
diff changeset
   657
    param "txt";
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: 2881
diff changeset
   658
    // have to use a python string to enter escaped quote
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
   659
    // const "frstln", "string-length($frst)";
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: 2881
diff changeset
   660
    choose {
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
   661
        when !"contains($txt,'\"')"! {
Edouard Tisserant
parents: 3022 3019
diff changeset
   662
            result !"concat(substring-before($txt,'\"'),'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!;
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: 2881
diff changeset
   663
        }
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: 2881
diff changeset
   664
        otherwise {
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: 2881
diff changeset
   665
            result "$txt";
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: 2881
diff changeset
   666
        }
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: 2881
diff changeset
   667
    }
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: 2881
diff changeset
   668
}
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: 2881
diff changeset
   669