svghmi/parse_labels.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 13 Apr 2021 21:04:46 +0200
branchsvghmi
changeset 3229 c5be4fd425e7
parent 3221 3d307ad803ea
child 3230 95f07764991f
permissions -rw-r--r--
SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.

Multiple widget DnD and mutiple variable still make no sense because all path are replaced with same path, but atleast min/max value are preserved...
3221
3d307ad803ea SVGHMI: Widget Library Picker now transforms SVG widget before allowing DnD. Transform is just identity forn now, but label parsing have already been included. To be continued.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3205
diff changeset
     1
// parse_labels.ysl2
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
     2
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
     3
2882
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
     4
//  Parses:
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
     5
//  "HMI:WidgetType:param1:param2@path1,path1min,path1max@path2"
2882
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
     6
//
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
     7
//  Into:
2893
d57a12b8f5db SVGHMI: added func:get_hmi_tree_elt to match HMI tree node from path. Continue implementing ForEach widget : force order and completeness of items list. Now also collecting ForEach buttons.
Edouard Tisserant
parents: 2890
diff changeset
     8
//  widget type="WidgetType" id="blah456" {
2882
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
     9
//      arg value="param1";
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
    10
//      arg value="param2";
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    11
//      path value=".path1" index=".path1" min="path1min" max="path1max" type="PAGE_LOCAL";
3060
4d20b92282e3 SVGHMI: Documentation fix
Edouard Tisserant
parents: 3017
diff changeset
    12
//      path value="/path1" index="348" type="HMI_INT";
4d20b92282e3 SVGHMI: Documentation fix
Edouard Tisserant
parents: 3017
diff changeset
    13
//      path value="path4" index="path4" type="HMI_LOCAL";
2882
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
    14
//  }
ac08a5d15c15 SVGHMI: moving comments
Edouard Tisserant
parents: 2877
diff changeset
    15
//
2886
6c82fad8be65 SVGHMI: Simplification and optimization. func:parselabel becomes a template.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2885
diff changeset
    16
template "*", mode="parselabel" {
6c82fad8be65 SVGHMI: Simplification and optimization. func:parselabel becomes a template.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2885
diff changeset
    17
    const "label","@inkscape:label";
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    18
    const "id","@id";
2877
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    19
    const "description", "substring-after($label,'HMI:')";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    20
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    21
    const "_args", "substring-before($description,'@')";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    22
    const "args" choose {
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    23
        when "$_args" value "$_args";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    24
        otherwise value "$description";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    25
    }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    26
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    27
    const "_type", "substring-before($args,':')";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    28
    const "type" choose {
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    29
        when "$_type" value "$_type";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    30
        otherwise value "$args";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    31
    }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    32
2886
6c82fad8be65 SVGHMI: Simplification and optimization. func:parselabel becomes a template.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2885
diff changeset
    33
    if "$type" widget {
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    34
        attrib "id" > «$id»
2877
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    35
        attrib "type" > «$type»
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    36
        foreach "str:split(substring-after($args, ':'), ':')" {
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    37
            arg {
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    38
                attrib "value" > «.»
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    39
            }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    40
        }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    41
        const "paths", "substring-after($description,'@')";
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    42
        foreach "str:split($paths, '@')" {
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    43
            if "string-length(.) > 0" path {
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    44
                const "pathminmax", "str:split(.,',')";
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    45
                const "path", "$pathminmax[1]";
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    46
                const "pathminmaxcount", "count($pathminmax)";
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    47
                attrib "value" > «$path»
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
    48
                choose {
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    49
                    when "$pathminmaxcount = 3" {
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    50
                        attrib "min" > «$pathminmax[2]»
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    51
                        attrib "max" > «$pathminmax[3]»
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    52
                    }
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    53
                    when "$pathminmaxcount = 2" {
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    54
                        error > Widget id:«$id» label:«$label» has wrong syntax of path section «$pathminmax»
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    55
                    }
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    56
                }
3229
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    57
                if "$indexed_hmitree" choose {
3127
d4dfd47f8156 SVGHMI: Enforce formating HMI_LOCAL and PAGE_LOCAL variables until the end of variable name
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3097
diff changeset
    58
                    when "regexp:test($path,'^\.[a-zA-Z0-9_]+$')" {
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    59
                        attrib "type" > PAGE_LOCAL
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    60
                    }
3127
d4dfd47f8156 SVGHMI: Enforce formating HMI_LOCAL and PAGE_LOCAL variables until the end of variable name
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3097
diff changeset
    61
                    when "regexp:test($path,'^[a-zA-Z0-9_]+$')" {
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    62
                        attrib "type" > HMI_LOCAL
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
    63
                    }
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
    64
                    otherwise {
3097
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    65
                        const "item", "$indexed_hmitree/*[@hmipath = $path]";
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    66
                        const "pathtype", "local-name($item)";
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    67
                        if "$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')" {
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    68
                            error > Widget id:«$id» label:«$label» path section «$pathminmax» use min and max on non mumeric value
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    69
                        }
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    70
                        if "count($item) = 1" {
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    71
                            attrib "index" > «$item/@index»
a098b2dd9dff SVGHMI: Added parsing of min and max value that can be given as @path,min,max in widget description
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3060
diff changeset
    72
                            attrib "type" > «$pathtype»
3017
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
    73
                        }
15e2df3e5610 SVGHMI: Intermediate state while implementing local HMI variables. Now write to cache only (no send), still need to implement dispatch on change.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
    74
                    }
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2904
diff changeset
    75
                }
2877
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    76
            }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    77
        }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    78
    }
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    79
}
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2874
diff changeset
    80
3229
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    81
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    82
// Templates to generate label back from parsed tree
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    83
template "arg", mode="genlabel" > :«@value»
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    84
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    85
template "path", mode="genlabel" {
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    86
    > @«@value»
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    87
    if "string-length(@min)>0 or string-length(@max)>0"  > :«@min»:«@max»
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    88
}
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    89
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    90
template "widget", mode="genlabel" {
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    91
    > HMI:«@type»
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    92
    apply "arg", mode="genlabel";
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    93
    apply "path", mode="genlabel";
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    94
}
c5be4fd425e7 SVGHMI: still quite naive path substitution whn prepearing widget for DnD, but now uses label generation.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3221
diff changeset
    95