svghmi/widgets_common.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 18 Mar 2020 09:16:14 +0100
branchsvghmi
changeset 2883 8e3d130399b0
parent 2881 svghmi/widget_common.ysl2@3bb49f93d48c
child 2884 50b9832c51fc
permissions -rw-r--r--
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
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
     1
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
     2
    with "hmi_element", "$hmi_element";
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
     3
    with "labels"{text *ptr};
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
     4
};
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
     5
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
     6
in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template {
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
     7
    with "hmi_element", "$hmi_element";
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
     8
    with "labels"{text *ptr};
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
     9
    with "mandatory","'no'";
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
    10
};
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
    11
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    12
template "svg:*", mode="hmi_elements" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    13
    const "widget", "func:parselabel(@inkscape:label)/widget";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    14
    const "eltid","@id";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    15
    |   "«@id»": {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    16
    |     type: "«$widget/@type»",
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    17
    |     args: [
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    18
        foreach "$widget/arg"
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    19
    |         "«@value»"`if "position()!=last()" > ,`
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    20
    |     ],
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    21
    |     indexes: [
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    22
    foreach "$widget/path" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    23
        choose {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    24
            when "not(@index)" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    25
                warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    26
            }
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    27
            otherwise {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    28
    |             «@index»`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
    29
            }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    30
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    31
    }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    32
    |     ],
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    33
    |     element: id("«@id»"),
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    34
    apply "$widget", mode="widget_defs" with "hmi_element",".";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    35
    |   }`if "position()!=last()" > ,`
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    36
}
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
    37
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
    38
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    39
function "defs_by_labels" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    40
    param "labels","''";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    41
    param "mandatory","'yes'";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    42
    param "hmi_element";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    43
    const "widget_type","@type";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    44
    foreach "str:split($labels)" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    45
        const "name",".";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    46
        const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id";
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    47
        choose {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    48
            when "not($elt_id)" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    49
                if "$mandatory='yes'" {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    50
                    // TODO FIXME error > «$widget_type» widget must have a «$name» element
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    51
                    warning > «$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
    52
                }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    53
                // 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
    54
            }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    55
            otherwise {
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    56
                |     «$name»_elt: id("«$elt_id»"),
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
    57
            }
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
    58
        }
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
    59
    }
2881
3bb49f93d48c SVGHMI: added widget_common.ysl2
Edouard Tisserant
parents: 2880
diff changeset
    60
}
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
    61
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
    62
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
    63
    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
    64
    // have to use a python string to enter escaped quote
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
    65
    const "frst", !"substring-before($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
    66
    const "frstln", "string-length($frst)";
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
    67
    choose {
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
    68
        when "$frstln > 0 and string-length($txt) > $frstln" {
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
    69
            result !"concat($frst,'\\\"',func:escape_quotes(substring-after($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
    70
        }
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
    71
        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
    72
            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
    73
        }
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
    74
    }
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
    75
}
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
    76