svghmi/widgets_common.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 02 May 2021 23:15:23 +0200
branchsvghmi
changeset 3233 315f17e74ef5
parent 3232 7bdb766c2a4d
child 3408 13c5cac55ac7
permissions -rw-r--r--
SVGHMI: Added widget_desc to declare widget signature and description
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
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
    17
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
    18
    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
    19
        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
    20
        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
    21
    }
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
    22
};
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
    23
3233
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    24
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
    25
    type > «@type»
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    26
    content;
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    27
};
315f17e74ef5 SVGHMI: Added widget_desc to declare widget signature and description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    28
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
    29
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
    30
    | 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
    31
    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
    32
    | }
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
    33
};
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
    34
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
    35
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
    36
    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
    37
    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
    38
};
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
    39
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
    40
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
    41
    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
    42
    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
    43
};
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
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
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
    46
    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
    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
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
    49
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
    50
    const "widget", "func:widget(@id)";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    51
    const "eltid","@id";
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
    52
    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
    53
    const "indexes" foreach "$widget/path" {
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    54
        choose {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    55
            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
    56
                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
    57
                    when "not(@type)" {
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3026
diff changeset
    58
                        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
    59
                        > 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
    60
                    }
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
    61
                    when "@type = 'PAGE_LOCAL'" 
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    62
                        > "«@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
    63
                    when "@type = 'HMI_LOCAL'" 
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    64
                        > hmi_local_index("«@value»")
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    65
                    otherwise 
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    66
                        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
    67
                }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    68
            }
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    69
            otherwise {
3101
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    70
                > «@index»
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    71
            }
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    72
        }
4cbf024a6640 SVGHMI: cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3099
diff changeset
    73
        if "position()!=last()" > ,
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    74
    }
2950
1e53d8b60ee9 SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2949
diff changeset
    75
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
    76
    const "minmaxes" foreach "$widget/path" {
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
    77
        choose {
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
    78
            when "@min and @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
    79
                > [«@min»,«@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
    80
            otherwise
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
    81
                > undefined
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
    82
        }
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
    83
        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
    84
    }
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
    85
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
    86
    |   "«@id»": new «$widget/@type»Widget ("«@id»",[«$args»],[«$indexes»],[«$minmaxes»],{
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    87
    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
    88
    |   })`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
    89
}
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
    90
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
    91
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
    92
    ||
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
    93
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
    94
    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
    95
    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
    96
    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
    97
    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
    98
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
    99
    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
   100
    ||
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
   101
    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
   102
        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
   103
        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
   104
        >     "«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
   105
        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
   106
            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
   107
            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
   108
        }
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
   109
        > \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
   110
        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
   111
    }
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
   112
    ||
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
   113
    };
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
   114
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
   115
    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
   116
    ||
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
   117
    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
   118
    |    "«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
   119
    }
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
   120
    ||
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
   121
    ]);
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
   122
    var persistent_indexes = new Map();
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   123
    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
   124
    var updates = new Map();
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   125
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
   126
    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
   127
        let pagevars = hmi_locals[pagename];
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   128
        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
   129
        if(pagevars == undefined){
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   130
            new_index = next_available_index++;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   131
            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
   132
        } 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
   133
            let result = pagevars[varname];
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   134
            if(result != undefined) {
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   135
                return result;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   136
            }
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   137
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   138
            new_index = next_available_index++;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   139
            pagevars[varname] = new_index;
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   140
        }
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
   141
        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
   142
        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
   143
            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
   144
            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
   145
            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
   146
                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
   147
        }
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   148
        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
   149
    }
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
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
   151
    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
   152
        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
   153
    }
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
   154
    ||
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
   155
}
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
   156
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
   157
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
   158
    ||
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
   159
    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
   160
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
   161
    class Widget {
2963
113e2f2e324d SVGHMI: more Widget properties declared ES6 style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2958
diff changeset
   162
        offset = 0;
113e2f2e324d SVGHMI: more Widget properties declared ES6 style.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2958
diff changeset
   163
        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
   164
        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
   165
        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
   166
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
   167
        constructor(elt_id,args,indexes,minmaxes,members){
2958
895d3f2b1786 SVGHMI: Back button updated to class style
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2955
diff changeset
   168
            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
   169
            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
   170
            this.args = args;
1e53d8b60ee9 SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2949
diff changeset
   171
            this.indexes = indexes;
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
   172
            this.minmaxes = minmaxes;
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
   173
            Object.keys(members).forEach(prop => this[prop]=members[prop]);
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
   174
            this.lastapply = indexes.map(() => 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
   175
            this.inhibit = indexes.map(() => 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
   176
            this.pending = indexes.map(() => 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
   177
            this.bound_unhinibit = this.unhinibit.bind(this);
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
   178
        }
2958
895d3f2b1786 SVGHMI: Back button updated to class style
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2955
diff changeset
   179
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
   180
        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
   181
            /* 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
   182
            if(!this.unsubscribable)
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   183
                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
   184
                    /* 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
   185
                    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
   186
                    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
   187
                        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
   188
                        this.lastapply[i] = undefined;
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
   189
                        this.unhinibit(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
   190
                    }
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
   191
                    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
   192
                    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
   193
                        index += this.offset;
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   194
                    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
   195
                }
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
   196
            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
   197
            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
   198
        }
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   199
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
   200
        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
   201
            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
   202
            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
   203
            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
   204
            /* 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
   205
            if(!this.unsubscribable)
ff9ae4f4e3be SVGHMI: widgets are not anymore binary relative or absolute, but have a "relativeness".
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3004
diff changeset
   206
                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
   207
                    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
   208
                    if(index == undefined) continue;
3022
f6fe42b7ce60 SVGHMI: finished initial implementation of PAGE_LOCAL and HMI_LOCAL variables.
Edouard Tisserant
parents: 3017
diff changeset
   209
                    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
   210
                }
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
   211
            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
   212
        }
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
   213
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
   214
        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
   215
            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
   216
                /* dispatch current cache in newly opened page widgets */
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
   217
                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
   218
                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
   219
                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
   220
                if(cached_val != undefined)
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   221
                    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
   222
            }
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
   223
        }
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
   224
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
   225
        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
   226
            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
   227
            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
   228
                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
   229
            } 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
   230
                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
   231
                    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
   232
                }
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
   233
            }
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
   234
            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
   235
        }
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
   236
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
   237
        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
   238
        }
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
   239
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
   240
        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
   241
        }
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
   242
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
   243
        clip_min_max(index, 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
   244
            let minmax = this.minmaxes[index];
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
   245
            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
   246
                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
   247
                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
   248
                    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
   249
                    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
   250
                }
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
   251
                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
   252
                    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
   253
                    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
   254
                }
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
   255
            }
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
   256
            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
   257
        }
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
   258
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
   259
        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
   260
            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
   261
            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
   262
            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
   263
            let new_val = eval_operation_string(old_val, opstr);
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
   264
            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
   265
            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
   266
        }
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
   267
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
   268
        _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
   269
            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
   270
            if(realindex == undefined) return undefined;
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
   271
            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
   272
            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
   273
        }
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
   274
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
   275
        unhinibit(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
   276
            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
   277
            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
   278
            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
   279
            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
   280
        }
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
   281
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
   282
        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
   283
            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
   284
                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
   285
                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
   286
                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
   287
                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
   288
                    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
   289
                    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
   290
                }
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
   291
                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
   292
                    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
   293
                    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
   294
                    this.inhibit[index] = setTimeout(this.bound_unhinibit, min_interval - elapsed, 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
   295
                }
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
   296
            }
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
   297
            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
   298
                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
   299
                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
   300
            }
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
   301
        }
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
   302
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
   303
        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
   304
            // TODO avoid searching, store index at sub()
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
   305
            for(let i = 0; i < this.indexes.length; i++) {
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
   306
                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
   307
                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
   308
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
   309
                if(index == refindex) {
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   310
                    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
   311
                    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
   312
                }
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
   313
            }
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
   314
        }
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
   315
        
3026
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   316
        _dispatch(value, oldval, varnum) {
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   317
            let dispatch = this.dispatch;
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   318
            if(dispatch != undefined){
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   319
                try {
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   320
                    dispatch.call(this, value, oldval, varnum);
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   321
                } catch(err) {
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   322
                    console.log(err);
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   323
                }
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   324
            }
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   325
        }
d454ed480c0f SVGHMI: factorize dispatch calling logic.
Edouard Tisserant
parents: 3025
diff changeset
   326
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
   327
        _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
   328
            this.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
   329
            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
   330
        }
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
   331
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
   332
        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
   333
            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
   334
                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
   335
                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
   336
                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
   337
            }
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
   338
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
   339
        }
3125
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   340
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   341
        activate_activable(eltsub) {
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   342
            eltsub.inactive.style.display = "none";
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   343
            eltsub.active.style.display = "";
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   344
        }
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   345
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   346
        inactivate_activable(eltsub) {
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   347
            eltsub.active.style.display = "none";
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   348
            eltsub.inactive.style.display = "";
1fb0c07bd97b SVGHMI: widget activable elements : moved code to wher it belongs, rewrote cleaner
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3123
diff changeset
   349
        }
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
   350
    }
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
   351
    ||
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
   352
}
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
   353
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
   354
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
   355
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
   356
// 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
   357
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
   358
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
   359
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
   360
    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
   361
                                    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
   362
                                    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
   363
    apply "$used_widget_types", mode="widget_class";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   364
}
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   365
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
   366
template "widget", mode="widget_class"
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
   367
||
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
   368
class «@type»Widget extends Widget{
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
   369
    /* empty class, as «@type» widget didn't provide any */
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
   370
}
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
   371
||
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
   372
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
   373
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
   374
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
   375
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
   376
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
   377
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
   378
    | var hmi_widgets = {
3121
8094494113b6 SVGHMI: Prevent excluded widget to appear in generated pages' widget list.
Edouard Tisserant
parents: 3119
diff changeset
   379
    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
   380
    | }
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
   381
}
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
   382
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   383
function "defs_by_labels" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   384
    param "labels","''";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   385
    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
   386
    param "subelements","/..";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   387
    param "hmi_element";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   388
    const "widget_type","@type";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   389
    foreach "str:split($labels)" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   390
        const "name",".";
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
   391
        const "elt","$result_widgets[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]";
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   392
        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
   393
            when "not($elt/@id)" {
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   394
                if "$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
   395
                    error > «$widget_type» widget must have a «$name» element
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
   396
                }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   397
                // 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
   398
            }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   399
            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
   400
                |     «$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
   401
                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
   402
                |     «$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
   403
                    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
   404
                        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
   405
                        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
   406
                        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
   407
                            when "not($subelt/@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
   408
                                if "$mandatory='yes'" {
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
   409
                                    error > «$widget_type» widget must have a «$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
   410
                                }
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
   411
                |         /* 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
   412
                            }
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
   413
                            otherwise {
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
   414
                |         "«$subname»": id("«$subelt/@id»")`if "position()!=last()" > ,`
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
   415
                            }
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
   416
                        }
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
   417
                    }
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
   418
                |     },
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
   419
                }
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
   420
            }
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
   421
        }
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
   422
    }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
   423
}
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
   424
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
   425
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
   426
    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
   427
    // have to use a python string to enter escaped quote
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
   428
    // 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
   429
    choose {
3024
Edouard Tisserant
parents: 3022 3019
diff changeset
   430
        when !"contains($txt,'\"')"! {
Edouard Tisserant
parents: 3022 3019
diff changeset
   431
            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
   432
        }
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
   433
        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
   434
            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
   435
        }
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
   436
    }
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
   437
}
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
   438