svghmi/widget_multistate.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 16 Oct 2024 12:18:14 +0200
changeset 4030 45532de22b75
parent 3577 6c7a7b22bec9
permissions -rw-r--r--
TESTS: Update Matiec revision in GH workflow
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
            }
3577
6c7a7b22bec9 IDE+Runtime: fix exception when reconnecting with non-empty trace/force list.
Edouard Tisserant
parents: 3241
diff changeset
    39
            // TODO : use RequestAnimate and animate()
3014
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
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    42
        on_click(evt) {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    43
            //get current selected value
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    44
            let next_ind;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    45
            for(next_ind=0; next_ind<this.choices.length; next_ind++){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    46
                if(this.state == this.choices[next_ind].value){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    47
                   next_ind = next_ind + 1;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    48
                   break;
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
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    52
            //get next selected value
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    53
            if(this.choices.length > next_ind){
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    54
                this.state = this.choices[next_ind].value;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    55
            }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    56
            else{
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    57
                this.state = this.choices[0].value;
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
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    60
            //post value to plc
3018
Edouard Tisserant
parents: 3014
diff changeset
    61
            this.apply_hmi_value(0, this.state);
3014
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
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    64
        init() {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    65
            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
    66
        }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    67
    ||
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    68
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
    69
widget_defs("MultiState") {
3014
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    70
    |     choices: [
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    71
    const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    72
    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
    73
        const "literal", "regexp:match(@inkscape:label,$regex)[2]";
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    74
    |         {
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    75
    |             elt:id("«@id»"),
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    76
    |             style:"«@style»",
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    77
    |             value:«$literal»
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    78
    |         }`if "position()!=last()" > ,`
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    79
    }
1a3fd83d9136 Create new multistate widget which extand class widget
usveticic
parents:
diff changeset
    80
    |     ],
3018
Edouard Tisserant
parents: 3014
diff changeset
    81
}