svghmi/widget_multistate.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 01 Oct 2021 02:52:25 +0200
changeset 3354 819b0bdfa705
parent 3241 fe945f1f48b7
child 3577 6c7a7b22bec9
permissions -rw-r--r--
SVGHMI: add files missing in ee9e98c856a : Add TextList widget, add support for TextList in DropDown widget, move List, TextStyleList and TextList widget code in dedicated file with documentation.
3014
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
     1
// widget_multistate.ysl2
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
     2
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     3
widget_defs("MultiState") {
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     4
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     5
    longdesc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     6
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     7
    Mutlistateh widget hides all subelements whose label do not match given
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     8
    variable value representation. For exemple if given variable type
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     9
    is HMI_INT and value is 1, then elements with label '1' will be displayed.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    10
    Label can have comments, so '1#some comment' would also match. If matching
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    11
    variable of type HMI_STRING, then double quotes must be used. For exemple,
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    12
    '"hello"' or '"hello"#another comment' match HMI_STRING 'hello'.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    13
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    14
    Click on widget changes variable value to next value in given list, or to
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    15
    first one if not initialized to value already part of the list.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    16
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    17
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    18
    shortdesc > Show elements whose label match value.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    19
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    20
    // TODO: add optional format/precision argument to support floating points
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    21
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    22
    path name="value" accepts="HMI_INT,HMI_STRING" > value to compare to labels
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    23
    
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    24
}
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    25
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: 3018
diff changeset
    26
widget_class("MultiState")
3014
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    27
    ||
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    28
        frequency = 5;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    29
        state = 0;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    30
        dispatch(value) {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    31
            this.state = value;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    32
            for(let choice of this.choices){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    33
                if(this.state != choice.value){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    34
                    choice.elt.setAttribute("style", "display:none");
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    35
                } else {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    36
                    choice.elt.setAttribute("style", choice.style);
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    37
                }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    38
            }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    39
        }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    40
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    41
        on_click(evt) {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    42
            //get current selected value
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    43
            let next_ind;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    44
            for(next_ind=0; next_ind<this.choices.length; next_ind++){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    45
                if(this.state == this.choices[next_ind].value){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    46
                   next_ind = next_ind + 1;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    47
                   break;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    48
                }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    49
            }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    50
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    51
            //get next selected value
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    52
            if(this.choices.length > next_ind){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    53
                this.state = this.choices[next_ind].value;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    54
            }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    55
            else{
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    56
                this.state = this.choices[0].value;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    57
            }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    58
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    59
            //post value to plc
3018
Edouard Tisserant
parents: 3014
diff changeset
    60
            this.apply_hmi_value(0, this.state);
3014
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    61
        }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    62
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    63
        init() {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    64
            this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    65
        }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    66
    ||
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    67
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: 3018
diff changeset
    68
widget_defs("MultiState") {
3014
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    69
    |     choices: [
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    70
    const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    71
    foreach "$result_svg_ns//*[@id = $hmi_element/@id]//*[regexp:test(@inkscape:label,$regex)]" {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    72
        const "literal", "regexp:match(@inkscape:label,$regex)[2]";
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    73
    |         {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    74
    |             elt:id("«@id»"),
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    75
    |             style:"«@style»",
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    76
    |             value:«$literal»
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    77
    |         }`if "position()!=last()" > ,`
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    78
    }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    79
    |     ],
3018
Edouard Tisserant
parents: 3014
diff changeset
    80
}