svghmi/inline_svg.ysl2
author Edouard Tisserant
Mon, 30 Mar 2020 14:26:42 +0200
branchsvghmi
changeset 2906 3b4a1319da09
parent 2904 92d115d8828d
child 2909 0519fdce9a59
permissions -rw-r--r--
SVGHMI: Jump widget, if it has a 'disabled' labeled element, reflects value of the pointed HMITree variable by showing this element when value is False, and behaving normaly otherwise.
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     1
// inline_svg.ysl2
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     2
//
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     3
// Produce Inline SVG element of resulting XHTML page.
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
     4
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     5
// Identity template :
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     6
//  - copy every attributes 
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     7
//  - copy every sub-elements
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     8
template "@* | node()", mode="inline_svg" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
     9
  // use real xsl:copy instead copy-of alias from yslt.yml2
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    10
  if "not(@id = $discardable_elements/@id)"
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    11
      xsl:copy apply "@* | node()", mode="inline_svg";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    12
}
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    13
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    14
// replaces inkscape's height and width hints. forces fit
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    15
template "svg:svg/@width", mode="inline_svg";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    16
template "svg:svg/@height", mode="inline_svg";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    17
svgtmpl "svg:svg", mode="inline_svg" svg {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    18
    attrib "preserveAspectRatio" > none
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    19
    attrib "height" > 100vh
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    20
    attrib "width" > 100vw
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    21
    apply "@* | node()", mode="inline_svg";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    22
}
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    23
// ensure that coordinate in CSV file generated by inkscape are in default reference frame
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    24
template "svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]", mode="inline_svg" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    25
    error > ViewBox settings other than X=0, Y=0 and Scale=1 are not supported
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    26
}
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    27
// ensure that coordinate in CSV file generated by inkscape match svg default unit
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    28
template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    29
    error > All units must be set to "px" in Inkscape's document properties
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    30
}
2792
0c0d3895b036 SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents: 2791
diff changeset
    31
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    32
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    33
//////////////// Clone Unlinking
2877
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2876
diff changeset
    34
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    35
// svg:use (inkscape's clones) inside a widgets are
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    36
// replaced by real elements they refer in order to :
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    37
//  - allow finding "needle" element in "meter" widget,
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    38
//    even if "needle" is in a group refered by a svg use.
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    39
//  - if "needle" is visible through a svg:use for
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    40
//    each instance of the widget, then needle would show
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    41
//    the same position in all instances
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    42
//
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    43
// For now, clone unlinkink applies to descendants of all widget except HMI:Page
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    44
// TODO: narrow application of clone unlinking to active elements,
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    45
//       while keeping static decoration cloned
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    46
const "to_unlink", "$hmi_elements[not(@id = $hmi_pages)]//svg:use";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    47
svgtmpl "svg:use", mode="inline_svg"
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    48
{
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    49
    choose {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    50
        when "@id = $to_unlink/@id"
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    51
            call "unlink_clone";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    52
        otherwise
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    53
            xsl:copy apply "@* | node()", mode="inline_svg";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    54
    }
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    55
}
2877
682bce953795 SVGHMI: detachable_elements.ysl2 becomes detachable_pages.ysl2, and includes logic to process pages elements. Other minor code moves.
Edouard Tisserant
parents: 2876
diff changeset
    56
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    57
// to unlink a clone, an group containing a copy of target element is created
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    58
// that way, style and transforms can be preserved
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    59
const "_excluded_use_attrs" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    60
    name > href
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    61
    name > width
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    62
    name > height
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    63
    name > x
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    64
    name > y
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    65
}
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    66
const "excluded_use_attrs","exsl:node-set($_excluded_use_attrs)";
2794
c10069a02ed0 SVGHMI: deduce pages content out of geometry (elements contained in page bounding box are in)
Edouard Tisserant
parents: 2793
diff changeset
    67
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    68
svgfunc "unlink_clone"{
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    69
    g{
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    70
        // include non excluded attributes
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    71
        foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    72
            attrib "{name()}" > «.»
2853
6d39beb19f38 SVGHMI: whitespaces and comments
Edouard Tisserant
parents: 2852
diff changeset
    73
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    74
        const "targetid","substring-after(@xlink:href,'#')";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    75
        apply "//svg:*[@id = $targetid]", mode="unlink_clone"{
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    76
            with "seed","@id";
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    77
        }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    78
    }
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    79
}
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    80
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    81
// clone unlinking is really similar to deep-copy
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    82
// all nodes are sytematically copied
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    83
svgtmpl "@id", mode="unlink_clone" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    84
    param "seed";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    85
    attrib "id" > «$seed»_«.»
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    86
}
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    87
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    88
svgtmpl "@*", mode="unlink_clone" xsl:copy;
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
    89
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    90
// copying widgets would have unwanted effect
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    91
// instead widget is refered through a svg:use.
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    92
svgtmpl "svg:*", mode="unlink_clone" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    93
    param "seed";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    94
    choose {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    95
        // node recursive copy ends when finding a widget
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    96
        when "@id = $hmi_elements/@id" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    97
            // place a clone instead of copying
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    98
            use{
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
    99
                attrib "xlink:href" > «concat('#',@id)»
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   100
            }
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   101
        }
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   102
        otherwise {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   103
            xsl:copy apply "@* | node()", mode="unlink_clone" {
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   104
                with "seed","$seed";
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   105
            }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   106
        }
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   107
    }
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   108
}
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   109
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   110
/*const "mark" > =HMI=\n*/
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   111
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   112
const "result_svg" apply "/", mode="inline_svg";
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   113
const "result_svg_ns", "exsl:node-set($result_svg)";
2854
c7d5f46cc306 SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents: 2853
diff changeset
   114
2904
92d115d8828d SVGHMI: collect debug data through xslt reflectivity instead of yml2/python trick
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2878
diff changeset
   115
reflect:inline_svg;
92d115d8828d SVGHMI: collect debug data through xslt reflectivity instead of yml2/python trick
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2878
diff changeset
   116
template "reflect:inline-svg", mode="debug" {
92d115d8828d SVGHMI: collect debug data through xslt reflectivity instead of yml2/python trick
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2878
diff changeset
   117
    | Unlinked :
2878
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   118
    foreach "$to_unlink"{
bec552270ad1 SVGHMI: added inline_svg.ysl2
Edouard Tisserant
parents: 2877
diff changeset
   119
        | «@id»
2808
dc78ffa5253d SVGHMI: SVG viewport now defined so that HMI take scales and fit to the view. Implemented page switch through viewport change, no hiding of widget for now.
Edouard Tisserant
parents: 2807
diff changeset
   120
    }
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
   121
}