svghmi/gen_index_xhtml.ysl2
author Edouard Tisserant
Tue, 17 Mar 2020 10:34:26 +0100
branchsvghmi
changeset 2876 d2adbc273125
parent 2875 6a12e1084deb
child 2877 682bce953795
permissions -rw-r--r--
SVGHMI: moved debug code
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;
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    18
in xsl decl svgfunc(name, xmlns="http://www.w3.org/2000/svg") alias template;
2840
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
    19
2873
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
    20
!debug_output_calls = []
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
    21
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    22
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
    23
            /* 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
    24
            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
    25
            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
    26
            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
    27
            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
    28
            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
    29
            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
    30
            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
    31
            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
    32
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
    33
            /* 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
    34
            xmlns:ns="beremiz"
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    35
            extension-element-prefixes="ns func exsl regexp str dyn"
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    36
            exclude-result-prefixes="ns str regexp exsl func dyn" {
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    37
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    38
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
    39
    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
    40
    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
    41
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    42
    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
    43
2795
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    44
    const "default_page" choose {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    45
        when "count($hmi_pages) > 1" {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    46
            const "Home_page", 
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    47
                "$hmi_pages[func:parselabel(@inkscape:label)/widget/arg[1]/@value = 'Home']";
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    48
            choose {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    49
                when "$Home_page" > Home
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    50
                otherwise {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    51
                    error "No Home page defined!";
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    52
                }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    53
            }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    54
        }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    55
        when "count($hmi_pages) = 0" {
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    56
            error "No page defined!";
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    57
        }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    58
        otherwise > «func:parselabel($hmi_pages/@inkscape:label)/widget/arg[1]/@value»
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    59
    }
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
    60
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    61
    const "_categories" {
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    62
        noindex > HMI_ROOT
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    63
        noindex > HMI_PLC_STATUS
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    64
        noindex > HMI_CURRENT_PAGE
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    65
    }
2791
d022523cb621 SVGHMI: now generating JS object describing widgets and pointing to SVG elements
Edouard Tisserant
parents: 2790
diff changeset
    66
    const "categories", "exsl:node-set($_categories)";
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    67
2873
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
    68
    include geometry.ysl2
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
    69
2875
6a12e1084deb SVGHMI: created detachable_elements.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2874
diff changeset
    70
    include detachable_elements.ysl2
2867
901c89c0cc08 SVGHMI: unsignificant changes or changes in generated code
Edouard Tisserant
parents: 2866
diff changeset
    71
2873
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
    72
    include hmi_tree.ysl2
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    73
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    74
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
    75
    def "func:is_descendant_path" {
2870
634b43d69897 SVGHMI: relative pages and page jumps
Edouard Tisserant
parents: 2869
diff changeset
    76
        param "descend";
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
    77
        param "ancest";
2870
634b43d69897 SVGHMI: relative pages and page jumps
Edouard Tisserant
parents: 2869
diff changeset
    78
        result "string-length($ancest) > 0 and starts-with($descend,$ancest)";
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
    79
    }
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    80
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    81
    //////////////// Inline SVG
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    82
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    83
    // Identity template :
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    84
    //  - copy every attributes 
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    85
    //  - copy every sub-elements
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
    86
    template "@* | node()", mode="inline_svg" {
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    87
      // use real xsl:copy instead copy-of alias from yslt.yml2
2846
7b1db17287b6 SVGHMI: now compute discardable elements first so that we can do better grouping of required elements when sumarizing.
Edouard Tisserant
parents: 2845
diff changeset
    88
      if "not(@id = $discardable_elements/@id)"
7b1db17287b6 SVGHMI: now compute discardable elements first so that we can do better grouping of required elements when sumarizing.
Edouard Tisserant
parents: 2845
diff changeset
    89
          xsl:copy apply "@* | node()", mode="inline_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
    90
    }
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
    91
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    92
    // replaces inkscape's height and width hints. forces fit
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
    93
    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
    94
    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
    95
    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
    96
        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
    97
        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
    98
        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
    99
        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
   100
    }
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
   101
    // ensure that coordinate in CSV file generated by inkscape are in default reference frame
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
   102
    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
   103
        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
   104
    }
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
   105
    // ensure that coordinate in CSV file generated by inkscape match svg default unit
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
   106
    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
   107
        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
   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
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   110
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   111
    //////////////// Clone Unlinking
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   112
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   113
    // svg:use (inkscape's clones) inside a widgets are
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   114
    // replaced by real elements they refer in order to :
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   115
    //  - allow finding "needle" element in "meter" widget,
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   116
    //    even if "needle" is in a group refered by a svg use.
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   117
    //  - if "needle" is visible through a svg:use for
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   118
    //    each instance of the widget, then needle would show
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   119
    //    the same position in all instances
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   120
    //
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   121
    // For now, clone unlinkink applies to descendants of all widget except HMI:Page
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   122
    // TODO: narrow application of clone unlinking to active elements,
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   123
    //       while keeping static decoration cloned
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   124
    const "to_unlink", "$hmi_elements[not(@id = $hmi_pages)]//svg:use";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   125
    svgtmpl "svg:use", mode="inline_svg"
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   126
    {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   127
        choose {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   128
            when "@id = $to_unlink/@id"
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   129
                call "unlink_clone";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   130
            otherwise
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   131
                xsl:copy apply "@* | node()", mode="inline_svg";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   132
        }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   133
    }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   134
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   135
    // to unlink a clone, an group containing a copy of target element is created
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   136
    // that way, style and transforms can be preserved
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   137
    const "_excluded_use_attrs" {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   138
        name > href
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   139
        name > width
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   140
        name > height
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   141
        name > x
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   142
        name > y
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   143
    }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   144
    const "excluded_use_attrs","exsl:node-set($_excluded_use_attrs)";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   145
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   146
    svgfunc "unlink_clone"{
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   147
        g{
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   148
            // include non excluded attributes
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   149
            foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   150
                attrib "{name()}" > «.»
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   151
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   152
            const "targetid","substring-after(@xlink:href,'#')";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   153
            apply "//svg:*[@id = $targetid]", mode="unlink_clone"{
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   154
                with "seed","@id";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   155
            }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   156
        }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   157
    }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   158
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   159
    // clone unlinking is really similar to deep-copy
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   160
    // all nodes are sytematically copied
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   161
    svgtmpl "@id", mode="unlink_clone" {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   162
        param "seed";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   163
        attrib "id" > «$seed»_«.»
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   164
    }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   165
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   166
    svgtmpl "@*", mode="unlink_clone" xsl:copy;
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   167
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   168
    // copying widgets would have unwanted effect
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   169
    // instead widget is refered through a svg:use.
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   170
    svgtmpl "svg:*", mode="unlink_clone" {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   171
        param "seed";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   172
        choose {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   173
            // node recursive copy ends when finding a widget
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   174
            when "@id = $hmi_elements/@id" {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   175
                // place a clone instead of copying
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   176
                use{
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   177
                    attrib "xlink:href" > «concat('#',@id)»
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   178
                }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   179
            }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   180
            otherwise {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   181
                xsl:copy apply "@* | node()", mode="unlink_clone" {
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   182
                    with "seed","$seed";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   183
                }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   184
            }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   185
        }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   186
    }
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
   187
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   188
    /*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
   189
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   190
    const "result_svg" apply "/", mode="inline_svg";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   191
    const "result_svg_ns", "exsl:node-set($result_svg)";
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   192
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
   193
    template "/" {
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   194
        comment > Made with SVGHMI. https://beremiz.org
2873
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
   195
022db76c3bff SVGHMI : create hmi_tree.ysl2, rename bbox_intersect.ysl2 into geometry.ysl2 and move more code into. Add per included ysl2 file debug output.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2872
diff changeset
   196
        // use python to call all debug output from included definitions
2874
b67af0b8dc72 SVGHMI: more debug code moved to hmi_tree.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2873
diff changeset
   197
        // '&bug' is a workaround for pyPEG that choke on yml2 python results not parsing to a single call
b67af0b8dc72 SVGHMI: more debug code moved to hmi_tree.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2873
diff changeset
   198
        !"&bug {"+"\n".join(["comment {\n| \n| %s:\n call \"%s\";\n| \n}"%(n,n) for n in debug_output_calls]) +"}"!
b67af0b8dc72 SVGHMI: more debug code moved to hmi_tree.ysl2
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2873
diff changeset
   199
2844
eee5dcd9fc92 SVGHMI: detachable and discardable elements sets, Reworked geometric intersection, toward more accurate page content detection.
Edouard Tisserant
parents: 2843
diff changeset
   200
        comment {
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   201
            | Unlinked :
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   202
            foreach "$to_unlink"{
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   203
                | «@id»
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   204
            }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   205
        }
2814
2cabc4773885 SVGHMI: HMI_LABEL and HMI_CLASS become HMI_NODE.
Edouard Tisserant
parents: 2810
diff changeset
   206
        /**/
2840
e588f25e6c74 SVGHMI: Better and less verbose SVG namespace handling in XSLT transform
Edouard Tisserant
parents: 2839
diff changeset
   207
        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
   208
             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
   209
             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
   210
            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
   211
            body style="margin:0;overflow:hidden;" {
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   212
                copy "$result_svg";
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   213
                script{
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   214
                    call "scripts";
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   215
                }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   216
            }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   217
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   218
    }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   219
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   220
    /*
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   221
        Parses:
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   222
        "HMI:WidgetType:param1:param2@path1@path2"
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   223
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   224
        Into:
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   225
        widget type="WidgetType" {
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   226
            arg value="param1";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   227
            arg value="param2";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   228
            path value="path1";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   229
            path value="path2";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   230
        }
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   231
    */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   232
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   233
    def "func:parselabel" {
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   234
        param "label";
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   235
        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
   236
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   237
        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
   238
        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
   239
            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
   240
            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
   241
        }
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
        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
   244
        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
   245
            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
   246
            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
   247
        }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   248
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   249
        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
   250
            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
   251
            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
   252
                arg {
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   253
                    attrib "value" > «.»
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   254
                }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   255
            }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   256
            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
   257
            foreach "str:split($paths, '@')" {
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   258
                if "string-length(.) > 0" path {
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   259
                    attrib "value" > «.»
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   260
                    const "path", ".";
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   261
                    const "item", "$indexed_hmitree/*[@hmipath = $path]";
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   262
                    if "count($item) = 1"
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   263
                        attrib "index" > «$item/@index»
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   264
                }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   265
            }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   266
        }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   267
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   268
        result "exsl:node-set($ast)";
2793
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   269
    }
2a97688c94c5 SVGHMI: use func:function for parsing labels so that it can be used in predicates
Edouard Tisserant
parents: 2792
diff changeset
   270
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   271
    function "scripts"
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   272
    {
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
   273
        | //(function(){
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   274
        |
2847
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   275
        | id = idstr => document.getElementById(idstr);
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   276
        |
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
   277
        | 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
   278
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   279
        /* TODO re-enable
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   280
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   281
        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
   282
            var Page;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   283
            var Input;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   284
            var Display;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   285
            var res = [];
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
        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
   288
        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
   289
                     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
   290
              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
   291
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   292
            return res;
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   293
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   294
        ||
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   295
        */
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   296
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
   297
        | 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
   298
        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
   299
            const "widget", "func:parselabel(@inkscape:label)/widget";
2856
1b529ba018ad SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2855
diff changeset
   300
            const "eltid","@id";
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   301
        |   "«@id»": {
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   302
        |     type: "«$widget/@type»",
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   303
        |     args: [
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
   304
            foreach "$widget/arg"
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   305
        |         "«@value»"`if "position()!=last()" > ,`
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   306
        |     ],
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   307
        |     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
   308
            foreach "$widget/path" {
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
   309
                choose {
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   310
                    when "not(@index)" {
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   311
                        warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
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
   312
                    }
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
   313
                    otherwise {
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   314
        |             «@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
   315
                    }
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
   316
                }
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
   317
            }
2855
525211a54b14 SVGHMI: more whitespace fixes
Edouard Tisserant
parents: 2854
diff changeset
   318
        |     ],
525211a54b14 SVGHMI: more whitespace fixes
Edouard Tisserant
parents: 2854
diff changeset
   319
        |     element: id("«@id»"),
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   320
            apply "$widget", mode="widget_defs" with "hmi_element",".";
2855
525211a54b14 SVGHMI: more whitespace fixes
Edouard Tisserant
parents: 2854
diff changeset
   321
        |   }`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
   322
        }
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
   323
        | }
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
   324
        |
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
   325
        | 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
   326
        |
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   327
        | var hmitree_types = [
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2797
diff changeset
   328
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   329
        foreach "$indexed_hmitree/*" {
2849
bb89a2fbb4e0 SVGHMI: re-indenting
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2848
diff changeset
   330
        |     /* «@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
   331
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   332
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
   333
        | ]
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   334
        |
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   335
2847
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   336
        | var detachable_elements = {
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   337
        foreach "$detachable_elements"{
2850
e38654ec6281 SVGHMI: detach/re-attach elements required by pages on page switch
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2849
diff changeset
   338
        |     "«@id»":[id("«@id»"), id("«../@id»")]`if "position()!=last()" > ,`
2847
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   339
        }
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   340
        | }
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   341
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   342
        |
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   343
        | var page_desc = {
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   344
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
   345
        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
   346
            const "desc", "func:parselabel(@inkscape:label)/widget";
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   347
            const "page", ".";
2855
525211a54b14 SVGHMI: more whitespace fixes
Edouard Tisserant
parents: 2854
diff changeset
   348
            const "p", "$geometry[@Id = $page/@id]";
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   349
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   350
            const "page_all_elements", "func:all_related_elements($page)";
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   351
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   352
            const "all_page_widgets","$hmi_elements[@id = $page_all_elements/@id and @id != $page/@id]";
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   353
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   354
            const "page_relative_widgets",
2870
634b43d69897 SVGHMI: relative pages and page jumps
Edouard Tisserant
parents: 2869
diff changeset
   355
                "$all_page_widgets[func:is_descendant_path(func:parselabel(@inkscape:label)/widget/path/@value, $desc/path/@value)]";
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   356
2858
39c8d6079f0f SVGHMI: Fix disapearing elements in case of nested detachable elements.
Edouard Tisserant
parents: 2857
diff changeset
   357
            // Take closest ancestor in detachable_elements
39c8d6079f0f SVGHMI: Fix disapearing elements in case of nested detachable elements.
Edouard Tisserant
parents: 2857
diff changeset
   358
            // since nested detachable elements are filtered out
39c8d6079f0f SVGHMI: Fix disapearing elements in case of nested detachable elements.
Edouard Tisserant
parents: 2857
diff changeset
   359
            const "required_detachables", 
39c8d6079f0f SVGHMI: Fix disapearing elements in case of nested detachable elements.
Edouard Tisserant
parents: 2857
diff changeset
   360
                """func:sumarized_elements($page_all_elements)/
39c8d6079f0f SVGHMI: Fix disapearing elements in case of nested detachable elements.
Edouard Tisserant
parents: 2857
diff changeset
   361
                   ancestor-or-self::*[@id = $detachable_elements/@id]""";
2843
94696b3f69fb SVGHMI : still trying to optimize. Added xslt code to identitfy minimum set of elements needed by a particular page. Plan is to remove unseen/unused elements from the DOM, and re-appending them later when used, on page switch. Disabled previous optimization.
Edouard Tisserant
parents: 2842
diff changeset
   362
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   363
            |   "«$desc/arg[1]/@value»": {
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   364
            |     widget: hmi_widgets["«@id»"],
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   365
            |     bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   366
            if "$desc/path/@value" {
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   367
                if "count($desc/path/@index)=0"
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   368
                    warning > Page id="«$page/@id»" : No match for path "«$desc/path/@value»" in HMI tree
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   369
            |     page_index: «$desc/path/@index»,
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   370
            }
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   371
            |     relative_widgets: [
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   372
            foreach "$page_relative_widgets" {
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   373
            |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   374
            }
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   375
            |     ],
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   376
            |     absolute_widgets: [
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   377
            foreach "$all_page_widgets[not(@id = $page_relative_widgets/@id)]" {
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   378
            |         hmi_widgets["«@id»"]`if "position()!=last()" > ,`
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   379
            }
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   380
            |     ],
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   381
            |     required_detachables: {
2847
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   382
            foreach "$required_detachables" {
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   383
            |         "«@id»": detachable_elements["«@id»"]`if "position()!=last()" > ,`
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   384
            }
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   385
            |     }
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   386
            |   }`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
   387
        }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   388
        | }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   389
2795
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
   390
        |
c0cf62bb9aa7 SVGHMI compute default page
Edouard Tisserant
parents: 2794
diff changeset
   391
        | var default_page = "«$default_page»";
2847
dffade5c83d3 SVGHMI: fix some JS + add generation of detachable elements, to be continued
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2846
diff changeset
   392
        | var svg_root = id("«$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
   393
        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
   394
        | //})();
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   395
    }
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
   396
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   397
    // template "*", mode="code_from_descs" {
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   398
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   399
    //     {
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   400
    //         var path, role, name, priv;
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   401
    //         var id = "«@id»";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   402
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   403
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   404
    //     /* 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
   405
    //     if "@inkscape:label"
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   406
    //         |> name = "«@inkscape:label»";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   407
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   408
    //     | /* -------------- */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   409
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   410
    //     // 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
   411
    //     value "substring-after(svg:desc, $mark)";
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   412
    //     // nobody reads generated code anyhow...
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   413
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   414
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   415
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   416
    //         /* -------------- */
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   417
    //         res.push({
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   418
    //             path:path,
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   419
    //             role:role,
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   420
    //             name:name,
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   421
    //             priv:priv
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   422
    //         })
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   423
    //     }
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   424
    //     ||
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   425
    // }
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   426
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
   427
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
   428
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
   429
    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
   430
        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
   431
        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
   432
        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
   433
        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
   434
        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
   435
            const "name",".";
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   436
            const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@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
   437
            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
   438
                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
   439
                    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
   440
                        // 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
   441
                        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
   442
                    }
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
   443
                    // otherwise produce nothing
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
   444
                }
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
   445
                otherwise {
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   446
                    |     «$name»_elt: id("«$elt_id»"),
2836
ce6cecdb7320 SVGHMI : still behave, even if important things are missing in SVG widget definitions (ex: needle missing for Meter widget)
Edouard Tisserant
parents: 2834
diff changeset
   447
                }
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
   448
            }
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
   449
        }
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
   450
    }
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
   451
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
   452
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   453
    template "widget[@type='Display']", mode="widget_defs" {
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   454
        param "hmi_element";
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   455
        |     frequency: 5,
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   456
        |     dispatch: function(value) {
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   457
        choose {
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   458
            when "$hmi_element[self::svg:text]"{
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   459
            // TODO : care about <tspan> ?
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   460
        |       this.element.textContent = String(value);
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   461
            }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   462
            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
   463
                warning > Display widget as a group not implemented
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   464
            }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   465
        }
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   466
        |     },
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   467
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   468
    }
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   469
    template "widget[@type='Meter']", mode="widget_defs" {
2807
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   470
        param "hmi_element";
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   471
        |     frequency: 10,
2856
1b529ba018ad SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2855
diff changeset
   472
        labels("needle range");
1b529ba018ad SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2855
diff changeset
   473
        optional_labels("value min max");
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   474
        |     dispatch: function(value) {
2856
1b529ba018ad SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2855
diff changeset
   475
        |         if(this.value_elt)
1b529ba018ad SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2855
diff changeset
   476
        |             this.value_elt.textContent = String(value);
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   477
        |         let [min,max,totallength] = this.range;
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   478
        |         let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   479
        |         let tip = this.range_elt.getPointAtLength(length);
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   480
        |         this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y);
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   481
        |     },
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   482
        |     origin: undefined,
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   483
        |     range: undefined,
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   484
        |     init: function() {
2857
a5c781b2f8f9 SVGHMI: Meter widget accepts 2 arguments : min and max, taken in account when min or max text element is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2856
diff changeset
   485
        |         let min = this.min_elt ?
a5c781b2f8f9 SVGHMI: Meter widget accepts 2 arguments : min and max, taken in account when min or max text element is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2856
diff changeset
   486
        |                     Number(this.min_elt.textContent) :
a5c781b2f8f9 SVGHMI: Meter widget accepts 2 arguments : min and max, taken in account when min or max text element is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2856
diff changeset
   487
        |                     this.args.length >= 1 ? this.args[0] : 0;
a5c781b2f8f9 SVGHMI: Meter widget accepts 2 arguments : min and max, taken in account when min or max text element is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2856
diff changeset
   488
        |         let max = this.max_elt ?
a5c781b2f8f9 SVGHMI: Meter widget accepts 2 arguments : min and max, taken in account when min or max text element is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2856
diff changeset
   489
        |                     Number(this.max_elt.textContent) :
a5c781b2f8f9 SVGHMI: Meter widget accepts 2 arguments : min and max, taken in account when min or max text element is missing
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2856
diff changeset
   490
        |                     this.args.length >= 2 ? this.args[1] : 100;
2856
1b529ba018ad SVGHMI: More precise error message on missing HMI path. Meter widget now defaults 0-100 range when min and max elements arent's present, without error.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2855
diff changeset
   491
        |         this.range = [min, max, this.range_elt.getTotalLength()]
2852
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   492
        |         this.origin = this.needle_elt.getPointAtLength(0);
f7349ca820c9 SVGHMI: completely fixed indentation of generated widget description. Lets try to keep it as-is until we can use yslt indentation.
Edouard Tisserant
parents: 2851
diff changeset
   493
        |     },
2807
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   494
    }
7fa21b3b5f9f SVGHMI - added simple Meter widget.
Edouard Tisserant
parents: 2806
diff changeset
   495
2829
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   496
    def "func:escape_quotes" {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   497
        param "txt";
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   498
        // 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
   499
        const "frst", !"substring-before($txt,'\"')"!;
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   500
        const "frstln", "string-length($frst)";
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   501
        choose {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   502
            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
   503
                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
   504
            }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   505
            otherwise {
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   506
                result "$txt";
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   507
            }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   508
        }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   509
    }
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   510
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   511
    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
   512
        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
   513
        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
   514
            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
   515
        }
2861
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   516
        const "have_value","string-length($value_elt)>0";
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
   517
        value "$value_elt";
2861
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   518
        if "$have_value"
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   519
        |     frequency: 5,
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   520
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   521
        |     dispatch: function(value) {
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   522
2861
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   523
        if "$have_value"
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   524
        |         this.value_elt.textContent = String(value);
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   525
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   526
        |     },
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
   527
        const "edit_elt_id","$hmi_element/*[@inkscape:label='edit'][1]/@id";
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   528
        |     init: function() {
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
   529
        if "$edit_elt_id" {
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   530
        |         id("«$edit_elt_id»").addEventListener(
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   531
        |             "click", 
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   532
        |             evt => alert('XXX TODO : Edit value'));
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
   533
        }
2829
4c2c50f60730 SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents: 2822
diff changeset
   534
        foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   535
        |         id("«@id»").addEventListener(
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   536
        |             "click", 
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   537
        |             evt => {let new_val = change_hmi_value(this.indexes[0], "«func:escape_quotes(@inkscape:label)»");
2861
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   538
            if "$have_value"{
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   539
        |                     this.value_elt.textContent = String(new_val);
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   540
            }
84c16ece8e10 SVGHMI: fixed repeated error when Input widget is missing 'value' element
Edouard Tisserant
parents: 2858
diff changeset
   541
        |                    });
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   542
                              /* TODO gray out value until refreshed */
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   543
        }
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   544
        |     },
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
   545
    }
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
   546
    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
   547
    }
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
   548
    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
   549
        |     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
   550
    }
2839
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   551
    template "widget[@type='Switch']", mode="widget_defs" {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   552
        param "hmi_element";
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   553
        |     frequency: 5,
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   554
        |     dispatch: function(value) {
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   555
        |         for(let choice of this.choices){
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   556
        |             if(value != choice.value){
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   557
        |                 choice.elt.setAttribute("style", "display:none");
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   558
        |             } else {
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   559
        |                 choice.elt.setAttribute("style", choice.style);
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   560
        |             }
2839
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   561
        |         }
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   562
        |     },
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   563
        |     init: function() {
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   564
        |         // Hello Switch
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   565
        |     },
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   566
        |     choices: [
2839
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   567
        const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+)(#.*)?$'"!;
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   568
        foreach "$hmi_element/*[regexp:test(@inkscape:label,$regex)]" {
f4dd234faa11 SVGHMI: Added mostly untested switch widget
Edouard Tisserant
parents: 2838
diff changeset
   569
            const "literal", "regexp:match(@inkscape:label,$regex)[2]";
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   570
        |         {
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   571
        |             elt:id("«@id»"),
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   572
        |             style:"«@style»",
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   573
        |             value:«$literal»
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   574
        |         }`if "position()!=last()" > ,`
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   575
        }
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   576
        |     ],
2800
68cee1366b9c SVGHMI: dispatching data to minimalist "Display" text widget.
Edouard Tisserant
parents: 2799
diff changeset
   577
    }
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
   578
    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
   579
        param "hmi_element";
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   580
        |     on_click: function(evt) {
2869
d9eb50c015d1 SVGHMI: take care of path given in HMI:Page and HMI:Jump, but do not apply subscription offset for now. Intermediate commit in a "working" state.
Edouard Tisserant
parents: 2868
diff changeset
   581
        |         switch_page(this.args[0], this.indexes[0]);
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   582
        |     },
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   583
        |     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
   584
        /* 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
   585
        |     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
   586
        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
   587
        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
   588
        */
2851
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   589
        |         this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
8d15c6238e62 SVGHMI: re-indent generated JS
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2850
diff changeset
   590
        |     },
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
   591
    }
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
   592
}