svghmi/widget_switch.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 05 Apr 2021 18:22:30 +0200
branchsvghmi
changeset 3222 6adeeb16ac3e
parent 3220 ec365ef396b1
child 3232 7bdb766c2a4d
permissions -rw-r--r--
SVGHMI: Widget DnD to Inkscape : Added source SVG widget label parsing and pass selecte HMI subtree to XSLT tranform, so that SVG containing multiple widgets can later be matched against hmi tree fragments, in order to DnD complex groups of widgets.
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
2962
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     3
template "widget[@type='Switch']", mode="widget_class"
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     4
    ||
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     5
    class SwitchWidget extends Widget{
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     6
        frequency = 5;
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     7
        dispatch(value) {
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     8
            for(let choice of this.choices){
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
     9
                if(value != choice.value){
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    10
                    choice.elt.setAttribute("style", "display:none");
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    11
                } else {
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    12
                    choice.elt.setAttribute("style", choice.style);
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    13
                }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    14
            }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    15
        }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    16
    }
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    17
    ||
02ea529fd08c SVGHMI: Switch widget now use class declaration
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2907
diff changeset
    18
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
    19
template "widget[@type='Switch']", mode="widget_defs" {
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
    20
    param "hmi_element";
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
    21
    |     choices: [
2907
1695122a5e16 SVGHMI: HMI:Switch now accepts boolean values 'true' and 'false'
Edouard Tisserant
parents: 2883
diff changeset
    22
    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
    23
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
    24
    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
    25
    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
    26
    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
    27
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
    28
    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
    29
        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
    30
    |         {
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
    31
    |             elt:id("«@id»"),
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
    32
    |             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
    33
    |             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
    34
    |         }`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
    35
    }
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
    36
    |     ],
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
    37
}