svghmi/gen_index_xhtml.ysl2
author Edouard Tisserant
Fri, 21 Feb 2020 16:22:44 +0100
branchsvghmi
changeset 2842 2f73f001955a
parent 2841 7c6050cde9e3
child 2843 94696b3f69fb
permissions -rw-r--r--
SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
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
     1
include yslt_noindent.yml2
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
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
     3
// overrides yslt's output function to set CDATA
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
     4
decl output(method, cdata-section-elements="xhtml:script");
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
     5
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
     6
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
     7
    with "hmi_element", "$hmi_element";
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
     8
    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
     9
};
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
    10
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
    11
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
    12
    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
    13
    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
    14
    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
    15
};
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
    16
2840
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
    17
in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template;
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
    18
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    19
istylesheet
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
    20
            /* From Inkscape */
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
    21
            xmlns:dc="http://purl.org/dc/elements/1.1/"
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
    22
            xmlns:cc="http://creativecommons.org/ns#"
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
    23
            xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
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
    24
            xmlns:svg="http://www.w3.org/2000/svg"
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
    25
            xmlns:xlink="http://www.w3.org/1999/xlink"
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
    26
            xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
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
    27
            xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
    28
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
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
    29
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
    30
            /* Our namespace to invoke python code */
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
    31
            xmlns:ns="beremiz"
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
    32
            extension-element-prefixes="ns func"
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
    33
            exclude-result-prefixes="ns str regexp exsl func" {
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    34
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    35
    /* This retrieves geometry obtained through "inkscape -S"
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    36
     * already parsed by python and presented as a list of
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
     * <bbox x="0" y="0" w="42" h="42">
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
    38
     */
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    39
    const "geometry", "ns:GetSVGGeometry()";
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    40
    const "hmitree", "ns:GetHMITree()";
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    41
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
    42
    const "svg_root_id", "/svg:svg/@id";
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
    43
    const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]";
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    44
    const "hmi_geometry", "$geometry[@Id = $hmi_elements/@id]";
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    45
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    46
    const "hmi_pages", "$hmi_elements[func:parselabel(@inkscape:label)/widget/@type = 'Page']";
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    47
2795
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    48
    const "default_page" choose {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    49
        when "count($hmi_pages) > 1" {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    50
            const "Home_page", 
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    51
                "$hmi_pages[func:parselabel(@inkscape:label)/widget/arg[1]/@value = 'Home']";
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    52
            choose {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    53
                when "$Home_page" > Home
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    54
                otherwise {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    55
                    error "No Home page defined!";
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    56
                }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    57
            }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    58
        }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    59
        when "count($hmi_pages) = 0" {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    60
            error "No page defined!";
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    61
        }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    62
        otherwise > «func:parselabel($hmi_pages/@inkscape:label)/widget/arg[1]/@value»
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    63
    }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    64
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    65
    const "_categories" {
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    66
        noindex > HMI_ROOT
2814
2cabc4773885 SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents: 2810
diff changeset
    67
        noindex > HMI_NODE
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    68
        noindex > HMI_PLC_STATUS
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    69
        noindex > HMI_CURRENT_PAGE
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    70
    }
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    71
    const "categories", "exsl:node-set($_categories)";
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    72
    const "_indexed_hmitree" apply "$hmitree", mode="index";
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    73
    const "indexed_hmitree", "exsl:node-set($_indexed_hmitree)";
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    74
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    75
    template "*", mode="index" {
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    76
        param "index", "0";
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    77
        param "parentpath", "''";
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    78
        const "content" {
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    79
            const "path"
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    80
                choose {
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    81
                    when "local-name() = 'HMI_ROOT'" > «$parentpath»
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    82
                    otherwise > «$parentpath»/«@name»
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    83
                }
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    84
            choose {
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    85
                when "not(local-name() = $categories/noindex)" {
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    86
                    xsl:copy {
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    87
                        attrib "index" > «$index»
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    88
                        attrib "hmipath" > «$path»
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    89
                        foreach "@*" xsl:copy;
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    90
                    }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    91
                    /* no node expected below value nodes */
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    92
                }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    93
                otherwise {
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    94
                    apply "*[1]", mode="index"{
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    95
                        with "index", "$index";
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    96
                        with "parentpath" > «$path»
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    97
                    }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    98
                }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    99
            }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   100
        }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   101
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   102
        copy "$content";
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   103
        apply "following-sibling::*[1]", mode="index" {
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   104
            with "index", "$index + count(exsl:node-set($content)/*)";
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
   105
            with "parentpath" > «$parentpath»
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   106
        }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   107
    }
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   108
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
   109
    /* Identity template :
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
   110
     *  - copy every attributes 
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
   111
     *  - copy every sub-elements
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
   112
     */
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
   113
    template "@* | node()", mode="inline_svg" {
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
   114
      /* use real xsl:copy instead copy-of alias from yslt.yml2 */
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
   115
      xsl:copy apply "@* | node()", mode="inline_svg";
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
   116
    }
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
   117
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
   118
    /* replaces inkscape's height and width hints. forces fit */
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
   119
    template "svg:svg/@width", mode="inline_svg";
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
   120
    template "svg:svg/@height", mode="inline_svg";
2840
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
   121
    svgtmpl "svg:svg", mode="inline_svg" svg {
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
   122
        attrib "preserveAspectRatio" > none
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
   123
        attrib "height" > 100vh
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
   124
        attrib "width" > 100vw
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
   125
        apply "@* | node()", mode="inline_svg";
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
   126
    }
2837
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   127
    /* ensure that coordinate in CSV file generated by inkscape are in default reference frame */
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   128
    template "svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]", mode="inline_svg" {
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   129
        error > ViewBox settings other than X=0, Y=0 and Scale=1 are not supported
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   130
    }
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   131
    /* ensure that coordinate in CSV file generated by inkscape match svg default unit */
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   132
    template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   133
        error > All units must be set to "px" in Inkscape's document properties
53d9eb6a7498 SVGHMI: ensure that coordinate in CSV file generated by inkscape are both matching svg default unit and in default reference frame
Edouard Tisserant
parents: 2836
diff changeset
   134
    }
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
   135
2842
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   136
    /* clone unlinkink until widget for better perf with webkit */
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   137
    svgtmpl "svg:use", mode="inline_svg" 
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   138
    {
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   139
        g{
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   140
            attrib "style" > «@style»
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   141
            attrib "transform" > «@transform»
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   142
            /* keep same id and label in case it is a widget */
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   143
            //attrib "inkscape:label","@inkscape:label";
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   144
            attrib "id" > «@id»
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   145
            const "targetid","substring-after(@xlink:href,'#')";
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   146
            apply "//svg:*[@id = $targetid]", mode="unlink_clone";
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   147
        }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   148
    }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   149
    svgtmpl "@*", mode="unlink_clone" xsl:copy;
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   150
    svgtmpl "svg:*", mode="unlink_clone" {
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   151
        choose {
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   152
            when "@id = $hmi_elements/@id" {
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   153
                use{
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   154
                    attrib "xlink:href" > «concat('#',@id)»
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   155
                }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   156
            }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   157
            otherwise {
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   158
                xsl:copy apply "@* | node()", mode="unlink_clone";
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   159
            }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   160
        }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   161
    }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   162
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   163
    // template "svg:use/@style", mode="inline_svg"{
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   164
    //     attrib "style" > all:initial;
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   165
    //     //«.»
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   166
    // }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   167
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   168
    // template "svg:*[concat('#',@id) = //svg:use/@xlink:href]/@style", mode="inline_svg"{
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   169
    //     attrib "style" > all:unset;
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   170
    //     //«.»
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   171
    // }
2f73f001955a SVGHMI: attempt to optimize for webkit, because of really slow style recompute in svg:use : "unlink clones" (as in inkscape) but stop deep-copy when meeting a widget, and create a new clone instead.
Edouard Tisserant
parents: 2841
diff changeset
   172
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   173
    /*const "mark" > =HMI=\n*/
2782
723e420dfe72 SVGHMI: added transformation of code given in inkscape's description fields into javascript functions
Edouard Tisserant
parents: 2780
diff changeset
   174
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
   175
    /* copy root node and add geometry as comment for a test */
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   176
    template "/" { 
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   177
        comment > Made with SVGHMI. https://beremiz.org
2814
2cabc4773885 SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents: 2810
diff changeset
   178
        /* DEBUG DATA */
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
   179
        comment {
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
   180
            apply "$hmi_geometry", mode="testgeo";
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
   181
        }
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
   182
        comment {
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
   183
            apply "$hmitree", mode="testtree";
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
   184
        }
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
   185
        comment {
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
   186
            apply "$indexed_hmitree", mode="testtree";
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
   187
        }
2814
2cabc4773885 SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents: 2810
diff changeset
   188
        /**/
2840
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
   189
        html xmlns="http://www.w3.org/1999/xhtml"
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
   190
             xmlns:svg="http://www.w3.org/2000/svg"
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
   191
             xmlns:xlink="http://www.w3.org/1999/xlink" {
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   192
            head;
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
   193
            body style="margin:0;overflow:hidden;" {
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
   194
                apply "svg:svg", mode="inline_svg";
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   195
                script{
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   196
                    call "scripts";
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   197
                }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   198
            }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   199
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   200
    }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   201
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   202
    /*
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   203
        Parses:
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   204
        "HMI:WidgetType:param1:param2@path1@path2"
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   205
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   206
        Into:
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   207
        widget type="WidgetType" {
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   208
            arg value="param1";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   209
            arg value="param2";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   210
            path value="path1";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   211
            path value="path2";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   212
        }
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   213
    */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   214
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   215
    func:function name="func:parselabel" {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   216
        param "label";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   217
        const "description", "substring-after($label,'HMI:')";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   218
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   219
        const "_args", "substring-before($description,'@')";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   220
        const "args" choose {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   221
            when "$_args" value "$_args";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   222
            otherwise value "$description";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   223
        }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   224
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   225
        const "_type", "substring-before($args,':')";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   226
        const "type" choose {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   227
            when "$_type" value "$_type";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   228
            otherwise value "$args";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   229
        }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   230
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   231
        const "ast" if "$type" widget {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   232
            attrib "type" > «$type»
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   233
            foreach "str:split(substring-after($args, ':'), ':')" {
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   234
                arg {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   235
                    attrib "value" > «.»
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   236
                }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   237
            }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   238
            const "paths", "substring-after($description,'@')";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   239
            foreach "str:split($paths, '@')" {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   240
                path {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   241
                    attrib "value" > «.»
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   242
                }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   243
            }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   244
        }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   245
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   246
        func:result select="exsl:node-set($ast)"
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   247
    }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   248
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   249
    // returns all directly or indirectly refered elements
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   250
    func:function name="func:refered_elements" {
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   251
        param "elems";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   252
        const "descend", "$elems/descendant-or-self::svg:*";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   253
        const "clones", "$descend[self::svg:use]";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   254
        const "reals", "$descend[not(self::svg:use)]";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   255
        const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   256
        choose {
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   257
            when "$originals" 
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   258
                func:result select="$reals | func:refered_elements($originals)";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   259
            otherwise
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   260
                func:result select="$reals";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   261
        }
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   262
    }
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   263
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   264
    function "scripts"
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   265
    {
2799
f5da343b9b63 SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents: 2798
diff changeset
   266
        | //(function(){
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   267
        |
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
   268
        | var hmi_hash = [«$hmitree/@hash»]; 
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   269
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   270
        /* TODO re-enable
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   271
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   272
        function evaluate_js_from_descriptions() {
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   273
            var Page;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   274
            var Input;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   275
            var Display;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   276
            var res = [];
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   277
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   278
        const "midmark" > \n«$mark»
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   279
        apply """//*[contains(child::svg:desc, $midmark) or \
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   280
                     starts-with(child::svg:desc, $mark)]""",2 
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   281
              mode="code_from_descs";
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   282
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   283
            return res;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   284
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   285
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   286
        */
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   287
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
   288
        | var hmi_widgets = {
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
   289
        foreach "$hmi_elements" {
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
   290
            const "widget", "func:parselabel(@inkscape:label)/widget";
2833
e74123b966ac SVGHMI : fixed bug happening when some SVG ids are containing dashes
Edouard Tisserant
parents: 2829
diff changeset
   291
            | "«@id»": {
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
   292
            |     type: "«$widget/@type»",
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
   293
            |     args: [
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
   294
            foreach "$widget/arg"
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
   295
            |         "«@value»"`if "position()!=last()" > ,`
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
   296
            |     ],
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   297
            |     indexes: [
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
   298
            foreach "$widget/path" {
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
   299
                const "hmipath","@value";
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
   300
                const "hmitree_match","$indexed_hmitree/*[@hmipath = $hmipath]";
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
   301
                choose {
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
   302
                    when "count($hmitree_match) = 0" {
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
   303
                        warning > No match for path "«$hmipath»" in HMI tree
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
   304
                    }
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
   305
                    otherwise {
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
   306
            |         «$hmitree_match/@index»`if "position()!=last()" > ,`
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
   307
                    }
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
   308
                }
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
   309
            }
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   310
            |     ],
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   311
            |     element: document.getElementById("«@id»"),
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   312
            apply "$widget", mode="widget_defs" with "hmi_element",".";
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
   313
            | }`if "position()!=last()" > ,`
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
   314
        }
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
   315
        | }
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
   316
        |
2822
9101a72a1da0 SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents: 2814
diff changeset
   317
        | var heartbeat_index = «$indexed_hmitree/*[@hmipath = '/HEARTBEAT']/@index»;
9101a72a1da0 SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents: 2814
diff changeset
   318
        |
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   319
        | var hmitree_types = [
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   320
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   321
        foreach "$indexed_hmitree/*" {
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   322
            | /* «@index»  «@hmipath» */ "«substring(local-name(), 5)»"`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
   323
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   324
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
   325
        | ]
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   326
        |
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   327
        | var page_desc = {
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   328
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   329
        foreach "$hmi_pages" {
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   330
            const "desc", "func:parselabel(@inkscape:label)/widget";
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
   331
            const "page", "."; 
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
   332
            const "p", "$hmi_geometry[@Id = $page/@id]"; 
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
   333
            const "page_ids","""$hmi_geometry[@Id != $page/@id and 
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
   334
                                @x >= $p/@x and @y >= $p/@y and 
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
   335
                                @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id""";
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   336
            const "page_sub_ids", "func:refered_elements($page)[@id = $hmi_elements/@id]/@id";
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   337
            const "all_page_ids","$page_ids | $page_sub_ids[not(. = $page_ids)]"; 
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   338
            |     "«$desc/arg[1]/@value»": {
2841
7c6050cde9e3 SVGHMI: optimize browser work by hiding (display:none) pages that are not displayed.
Edouard Tisserant
parents: 2840
diff changeset
   339
            |         widget: hmi_widgets["«@id»"],
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
   340
            |         bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   341
            |         widgets: [
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   342
            foreach "$all_page_ids" {
2833
e74123b966ac SVGHMI : fixed bug happening when some SVG ids are containing dashes
Edouard Tisserant
parents: 2829
diff changeset
   343
            |             hmi_widgets["«.»"]`if "position()!=last()" > ,`
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
   344
            }
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
   345
            |         ]
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
   346
            |     }`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
   347
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   348
        | }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   349
2795
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
   350
        |
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
   351
        | var default_page = "«$default_page»";
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
   352
        | var svg_root = document.getElementById("«$svg_root_id»");
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   353
        include text svghmi.js
2799
f5da343b9b63 SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents: 2798
diff changeset
   354
        | //})();
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   355
    }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   356
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   357
    // template "*", mode="code_from_descs" {
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   358
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   359
    //     {
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   360
    //         var path, role, name, priv;
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   361
    //         var id = "«@id»";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   362
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   363
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   364
    //     /* if label is used, use it as default name */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   365
    //     if "@inkscape:label"
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   366
    //         |> name = "«@inkscape:label»";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   367
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   368
    //     | /* -------------- */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   369
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   370
    //     // this breaks indent, but fixing indent could break string literals
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   371
    //     value "substring-after(svg:desc, $mark)";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   372
    //     // nobody reads generated code anyhow...
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   373
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   374
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   375
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   376
    //         /* -------------- */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   377
    //         res.push({
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   378
    //             path:path,
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   379
    //             role:role,
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   380
    //             name:name,
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   381
    //             priv:priv
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   382
    //         })
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   383
    //     }
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   384
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   385
    // }
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   386
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   387
2814
2cabc4773885 SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents: 2810
diff changeset
   388
    /**/
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
   389
    template "bbox", mode="testgeo"{
2763
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   390
        | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   391
    }
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   392
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   393
    template "*", mode="testtree"{
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   394
        param "indent", "''";
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   395
        > «$indent» «local-name()» 
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   396
        foreach "@*" > «local-name()»=«.» 
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
   397
        > \n
2763
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   398
        apply "*", mode="testtree" {
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   399
            with "indent" value "concat($indent,'>')"
ce04d79b8e57 Pass HMITree to SVG transform. It seems it could really help to reduce JS tree binding logic in the end.
Edouard Tisserant
parents: 2756
diff changeset
   400
        };
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
   401
    }
2814
2cabc4773885 SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents: 2810
diff changeset
   402
    /**/
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
   403
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
   404
    function "defs_by_labels" {
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
   405
        param "labels","''";
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
   406
        param "mandatory","'yes'";
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
   407
        param "hmi_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
   408
        const "widget_type","@type";
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
   409
        foreach "str:split($labels)" {
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
   410
            const "name",".";
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
   411
            const "elt_id","$hmi_element//*[@inkscape:label=$name][1]/@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
   412
            choose {
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
   413
                when "not($elt_id)" {
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
   414
                    if "$mandatory='yes'" {
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
   415
                        // TODO FIXME error > «$widget_type» widget must have a «$name» 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
   416
                        warning > «$widget_type» widget must have a «$name» 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
   417
                    }
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
   418
                    // otherwise produce nothing 
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
   419
                }
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
   420
                otherwise {
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
   421
                    | «$name»_elt: document.getElementById("«$elt_id»"),
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
   422
                }
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
   423
            }
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
   424
        }
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
   425
    }
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
   426
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
   427
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   428
    template "widget[@type='Display']", mode="widget_defs" {
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   429
        param "hmi_element";
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   430
        | frequency: 5,
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   431
        | dispatch: function(value) {
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   432
        choose {
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   433
            when "$hmi_element[self::svg:text]"{
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   434
            // TODO : care about <tspan> ?
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   435
        |   this.element.textContent = String(value);
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   436
            }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   437
            otherwise {
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
   438
                warning > Display widget as a group not implemented
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   439
            }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   440
        }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   441
        | },
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   442
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   443
    }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   444
    template "widget[@type='Meter']", mode="widget_defs" {
2807
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   445
        param "hmi_element";
2801
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   446
        | frequency: 10,
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
   447
        labels("value min max needle range");
2807
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   448
        | dispatch: function(value) {
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   449
        |     this.value_elt.textContent = String(value);
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   450
        |     let [min,max,totallength] = this.range;
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   451
        |     let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   452
        |     let tip = this.range_elt.getPointAtLength(length);
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   453
        // TODO : deal with transformations between needle and range
2807
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   454
        |     this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   455
        | },
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   456
        | origin: undefined,
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   457
        | range: undefined,
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   458
        | init: function() {
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   459
        |     this.range = [Number(this.min_elt.textContent), Number(this.max_elt.textContent), this.range_elt.getTotalLength()]
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   460
        |     this.origin = this.needle_elt.getPointAtLength(0);
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   461
        | },
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   462
    }
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   463
2829
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   464
    def "func:escape_quotes" {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   465
        param "txt";
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   466
        // have to use a python string to enter escaped quote
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   467
        const "frst", !"substring-before($txt,'\"')"!;
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   468
        const "frstln", "string-length($frst)";
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   469
        choose {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   470
            when "$frstln > 0 and string-length($txt) > $frstln" {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   471
                result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!;
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   472
            }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   473
            otherwise {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   474
                result "$txt";
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   475
            }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   476
        }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   477
    }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   478
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   479
    template "widget[@type='Input']", mode="widget_defs" {
2801
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   480
        param "hmi_element";
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
   481
        const "value_elt" {
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
   482
            optional_labels("value");
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
   483
        }
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
   484
        value "$value_elt";
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
   485
        if "$value_elt"
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
   486
            | frequency: 5,
2801
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   487
        | dispatch: function(value) {
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
   488
        if "$value_elt"
2801
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   489
        |     this.value_elt.textContent = String(value);
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   490
        | },
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   491
        const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id";
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   492
        | init: function() {
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   493
        if "$edit_elt_id" {
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   494
        |     document.getElementById("«$edit_elt_id»").addEventListener(
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   495
        |         "click", 
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   496
        |         evt => alert('XXX TODO : Edit value'));
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   497
        }
2829
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   498
        foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
2801
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   499
        |     document.getElementById("«@id»").addEventListener(
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   500
        |         "click", 
2829
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   501
        |         evt => {let new_val = change_hmi_value(this.indexes[0], "«func:escape_quotes(@inkscape:label)»");
2806
7d0e81cdedb0 SVGHMI: Quicker update path for input widget when pressing on buttons, do not wait until data comes back, and simply update value text of the pressed widget. Updated PLC prog for more amimated value to display
Edouard Tisserant
parents: 2801
diff changeset
   502
        |                 this.value_elt.textContent = String(new_val);});
7d0e81cdedb0 SVGHMI: Quicker update path for input widget when pressing on buttons, do not wait until data comes back, and simply update value text of the pressed widget. Updated PLC prog for more amimated value to display
Edouard Tisserant
parents: 2801
diff changeset
   503
                          /* could gray out value until refreshed */
2801
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   504
        }
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   505
        | },
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   506
    }
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   507
    template "widget[@type='Button']", mode="widget_defs" {
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   508
    }
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   509
    template "widget[@type='Toggle']", mode="widget_defs" {
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   510
        |     frequency: 5,
390acff12755 SVGHMI: Added init call to all widgets at startup to bind events. More features in Input widget : Edit and Change buttons. WIP HMI->PLC value update, incoherent data detected in C part on update.
Edouard Tisserant
parents: 2800
diff changeset
   511
    }
2839
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   512
    template "widget[@type='Switch']", mode="widget_defs" {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   513
        param "hmi_element";
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   514
        | frequency: 5,
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   515
        | dispatch: function(value) {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   516
        |     for(let choice of this.choices){
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   517
        |         if(value != choice.value){
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   518
        |             choice.elt.setAttribute("style", "display:none");
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   519
        |         } else {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   520
        |             choice.elt.setAttribute("style", choice.style);
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   521
        |         }
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   522
        |     }
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   523
        | },
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   524
        | init: function() {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   525
        |     // Hello Switch
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   526
        | },
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   527
        | choices: [
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   528
        const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+)(#.*)?$'"!;
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   529
        foreach "$hmi_element/*[regexp:test(@inkscape:label,$regex)]" {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   530
            const "literal", "regexp:match(@inkscape:label,$regex)[2]";
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   531
        |     {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   532
        |         elt:document.getElementById("«@id»"),
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   533
        |         style:"«@style»",
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   534
        |         value:«$literal»
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   535
        |     }`if "position()!=last()" > ,`
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   536
        }
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   537
        | ],
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   538
    }
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
   539
    template "widget[@type='Jump']", mode="widget_defs" {
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   540
        param "hmi_element";
2839
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   541
        | on_click: function(evt) {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   542
        |     console.log(evt);
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   543
        |     switch_page(this.args[0]);
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   544
        | },
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
   545
        | init: function() {
2838
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   546
        /* registering event this way doies not "click" through svg:use 
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   547
        |     this.element.onclick = evt => switch_page(this.args[0]);
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   548
        event must be registered by adding attribute to element instead
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   549
        TODO : generalize mouse event handling by global event capture + getElementsAtPoint()
459bf80d3f46 SVGHMI: HMI:Page can now be a svg:g group or a svg:use clone, and included/linked widget are included in page. HMI:Jump was updated to be clickable through svg:use, to be generalized.
Edouard Tisserant
parents: 2837
diff changeset
   550
        */
2839
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   551
        |     this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
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
   552
        | },
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
   553
    }
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
   554
}