svghmi/widget_switch.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 17 Jan 2022 15:17:47 +0100
changeset 3407 2f5c30054d50
parent 3386 608f48ad3dfc
child 3513 7d4a16e59337
permissions -rw-r--r--
OPC-UA client: "static" class was forgotten for open62541 client structure preventing multiple client.
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: 2882
diff changeset
     1
// widget_switch.ysl2
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2763
diff changeset
     2
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     3
widget_desc("Switch") {
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     4
    longdesc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     5
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     6
    Switch 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
     7
    variable current 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
     8
    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
     9
    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
    10
    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
    11
    '"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
    12
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    13
3386
608f48ad3dfc SVGHMI: multiple non significant changes: doc fixes, modern style access to attributes, enforce double quotes around member name in object literals.
Edouard Tisserant
parents: 3241
diff changeset
    14
    shortdesc > Show elements whose label matches value.
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
    15
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    16
    // 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
    17
    // TODO: support (in)equations and ranges
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
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
    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
    20
    
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    21
}
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
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: 3220
diff changeset
    23
widget_class("Switch")
2962
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    24
    ||
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    25
        frequency = 5;
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    26
        dispatch(value) {
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    27
            for(let choice of this.choices){
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    28
                if(value != choice.value){
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    29
                    choice.elt.setAttribute("style", "display:none");
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    30
                } else {
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    31
                    choice.elt.setAttribute("style", choice.style);
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    32
                }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    33
            }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    34
        }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    35
    ||
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    36
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: 3220
diff changeset
    37
widget_defs("Switch") {
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: 2882
diff changeset
    38
    |     choices: [
2907
1695122a5e16 SVGHMI: HMI:Switch now accepts boolean values 'true' and 'false'
Edouard Tisserant
parents: 2883
diff changeset
    39
    const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
3220
ec365ef396b1 SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
Edouard Tisserant
parents: 2969
diff changeset
    40
ec365ef396b1 SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
Edouard Tisserant
parents: 2969
diff changeset
    41
    const "subelts", "$result_widgets[@id = $hmi_element/@id]//*";
ec365ef396b1 SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
Edouard Tisserant
parents: 2969
diff changeset
    42
    const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]";
ec365ef396b1 SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
Edouard Tisserant
parents: 2969
diff changeset
    43
    const "accepted", "$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]";
ec365ef396b1 SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
Edouard Tisserant
parents: 2969
diff changeset
    44
ec365ef396b1 SVGHMI: Ensure that when widgets are nested in HMI:Switch widget, their sub-elements are taken as switch's choice in case their label match the syntax.
Edouard Tisserant
parents: 2969
diff changeset
    45
    foreach "$accepted[regexp:test(@inkscape:label,$regex)]" {
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: 2882
diff changeset
    46
        const "literal", "regexp:match(@inkscape:label,$regex)[2]";
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: 2882
diff changeset
    47
    |         {
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: 2882
diff changeset
    48
    |             elt:id("«@id»"),
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
    49
                  // TODO : use style.display = "none" to hide element
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: 2882
diff changeset
    50
    |             style:"«@style»",
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: 2882
diff changeset
    51
    |             value:«$literal»
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: 2882
diff changeset
    52
    |         }`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
    53
    }
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: 2882
diff changeset
    54
    |     ],
2753
9a7e12e96399 SVGHMI: Added XSLT transformation, Makefile to get XSLT from ysl2 (copy of plcopen/Makefile) and a minimal stylesheet to start with.
Edouard Tisserant
parents:
diff changeset
    55
}