author | Edouard Tisserant |
Tue, 26 May 2020 09:58:20 +0200 | |
branch | svghmi |
changeset 2971 | f0a822ef9fa0 |
parent 2968 | 556ef07a7e31 |
child 2995 | 7769e7c7f925 |
permissions | -rw-r--r-- |
2878 | 1 |
// inline_svg.ysl2 |
2 |
// |
|
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 |
|
2937
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2909
diff
changeset
|
5 |
// Since stylesheet output namespace is xhtml, templates that output svg have to be explicitely declared as such |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2909
diff
changeset
|
6 |
in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2909
diff
changeset
|
7 |
in xsl decl svgfunc(name, xmlns="http://www.w3.org/2000/svg") alias template; |
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2909
diff
changeset
|
8 |
|
9226a830fbc3
SVGHMI: moving code wher it belongs, and reformulate some declarations for better readability.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2909
diff
changeset
|
9 |
|
2878 | 10 |
// Identity template : |
11 |
// - copy every attributes |
|
12 |
// - copy every sub-elements |
|
13 |
template "@* | node()", mode="inline_svg" { |
|
14 |
// use real xsl:copy instead copy-of alias from yslt.yml2 |
|
15 |
if "not(@id = $discardable_elements/@id)" |
|
16 |
xsl:copy apply "@* | node()", mode="inline_svg"; |
|
17 |
} |
|
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
18 |
|
2878 | 19 |
// replaces inkscape's height and width hints. forces fit |
20 |
template "svg:svg/@width", mode="inline_svg"; |
|
21 |
template "svg:svg/@height", mode="inline_svg"; |
|
22 |
svgtmpl "svg:svg", mode="inline_svg" svg { |
|
23 |
attrib "preserveAspectRatio" > none |
|
24 |
attrib "height" > 100vh |
|
25 |
attrib "width" > 100vw |
|
26 |
apply "@* | node()", mode="inline_svg"; |
|
27 |
} |
|
28 |
// ensure that coordinate in CSV file generated by inkscape are in default reference frame |
|
29 |
template "svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]", mode="inline_svg" { |
|
30 |
error > ViewBox settings other than X=0, Y=0 and Scale=1 are not supported |
|
31 |
} |
|
32 |
// ensure that coordinate in CSV file generated by inkscape match svg default unit |
|
33 |
template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" { |
|
34 |
error > All units must be set to "px" in Inkscape's document properties |
|
35 |
} |
|
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
36 |
|
2941
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
37 |
////// Clone unlinking |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
38 |
// |
2878 | 39 |
// svg:use (inkscape's clones) inside a widgets are |
40 |
// replaced by real elements they refer in order to : |
|
41 |
// - allow finding "needle" element in "meter" widget, |
|
42 |
// even if "needle" is in a group refered by a svg use. |
|
43 |
// - if "needle" is visible through a svg:use for |
|
44 |
// each instance of the widget, then needle would show |
|
45 |
// the same position in all instances |
|
46 |
// |
|
47 |
// For now, clone unlinkink applies to descendants of all widget except HMI:Page |
|
48 |
// TODO: narrow application of clone unlinking to active elements, |
|
49 |
// while keeping static decoration cloned |
|
2967
fc5fbf087b93
SVGHMI: Applies clone unlinking to widget themselves, not only to clones inside widgets.
Edouard Tisserant
parents:
2941
diff
changeset
|
50 |
const "to_unlink", "$hmi_elements[not(@id = $hmi_pages)]/descendant-or-self::svg:use"; |
2878 | 51 |
svgtmpl "svg:use", mode="inline_svg" |
52 |
{ |
|
53 |
choose { |
|
54 |
when "@id = $to_unlink/@id" |
|
55 |
call "unlink_clone"; |
|
56 |
otherwise |
|
57 |
xsl:copy apply "@* | node()", mode="inline_svg"; |
|
58 |
} |
|
59 |
} |
|
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
|
60 |
|
2878 | 61 |
// to unlink a clone, an group containing a copy of target element is created |
62 |
// that way, style and transforms can be preserved |
|
63 |
const "_excluded_use_attrs" { |
|
64 |
name > href |
|
65 |
name > width |
|
66 |
name > height |
|
67 |
name > x |
|
68 |
name > y |
|
69 |
} |
|
70 |
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
|
71 |
|
2968
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
72 |
const "_merge_use_attrs" { |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
73 |
name > transform |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
74 |
name > style |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
75 |
} |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
76 |
const "merge_use_attrs","exsl:node-set($_merge_use_attrs)"; |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
77 |
|
2878 | 78 |
svgfunc "unlink_clone"{ |
2968
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
79 |
const "targetid","substring-after(@xlink:href,'#')"; |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
80 |
const "target", "//svg:*[@id = $targetid]"; |
2878 | 81 |
g{ |
2968
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
82 |
choose { |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
83 |
when "$target[self::svg:g]" { |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
84 |
foreach "@*[not(local-name() = $excluded_use_attrs/name | $merge_use_attrs)]" |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
85 |
attrib "{name()}" > «.» |
2853 | 86 |
|
2968
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
87 |
if "@style | $target/@style" |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
88 |
attrib "style" { |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
89 |
> «@style» |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
90 |
if "@style and $target/@style" > ; |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
91 |
> «$target/@style» |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
92 |
} |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
93 |
|
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
94 |
if "@transform | $target/@transform" |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
95 |
attrib "transform" { |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
96 |
> «@transform» |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
97 |
if "@transform and $target/@transform" > |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
98 |
> «$target/@transform» |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
99 |
} |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
100 |
|
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
101 |
apply "$target/*", mode="unlink_clone"{ |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
102 |
with "seed","@id"; |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
103 |
} |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
104 |
} |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
105 |
otherwise { |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
106 |
// include non excluded attributes |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
107 |
foreach "@*[not(local-name() = $excluded_use_attrs/name)]" |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
108 |
attrib "{name()}" > «.» |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
109 |
|
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
110 |
apply "$target", mode="unlink_clone"{ |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
111 |
with "seed","@id"; |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
112 |
} |
556ef07a7e31
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
Edouard Tisserant
parents:
2967
diff
changeset
|
113 |
} |
2854
c7d5f46cc306
SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents:
2853
diff
changeset
|
114 |
} |
c7d5f46cc306
SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents:
2853
diff
changeset
|
115 |
} |
2878 | 116 |
} |
2854
c7d5f46cc306
SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents:
2853
diff
changeset
|
117 |
|
2878 | 118 |
// clone unlinking is really similar to deep-copy |
119 |
// all nodes are sytematically copied |
|
120 |
svgtmpl "@id", mode="unlink_clone" { |
|
121 |
param "seed"; |
|
122 |
attrib "id" > «$seed»_«.» |
|
123 |
} |
|
2854
c7d5f46cc306
SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents:
2853
diff
changeset
|
124 |
|
2878 | 125 |
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
|
126 |
|
2878 | 127 |
// copying widgets would have unwanted effect |
128 |
// instead widget is refered through a svg:use. |
|
129 |
svgtmpl "svg:*", mode="unlink_clone" { |
|
130 |
param "seed"; |
|
131 |
choose { |
|
132 |
// node recursive copy ends when finding a widget |
|
133 |
when "@id = $hmi_elements/@id" { |
|
134 |
// place a clone instead of copying |
|
135 |
use{ |
|
136 |
attrib "xlink:href" > «concat('#',@id)» |
|
137 |
} |
|
138 |
} |
|
139 |
otherwise { |
|
140 |
xsl:copy apply "@* | node()", mode="unlink_clone" { |
|
141 |
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
|
142 |
} |
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 |
} |
2878 | 145 |
} |
2854
c7d5f46cc306
SVGHMI: unlink clones (i.e. deep copy elements refered by svg:use) inside widget.
Edouard Tisserant
parents:
2853
diff
changeset
|
146 |
|
2878 | 147 |
const "result_svg" apply "/", mode="inline_svg"; |
148 |
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
|
149 |
|
2941
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
150 |
emit "preamble:inline-svg" { |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
151 |
| let id = document.getElementById.bind(document); |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
152 |
| var svg_root = id("«$svg/@id»"); |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
153 |
} |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
154 |
|
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
155 |
emit "debug:clone-unlinking" { |
ef13a4007538
SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2940
diff
changeset
|
156 |
| |
2904
92d115d8828d
SVGHMI: collect debug data through xslt reflectivity instead of yml2/python trick
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2878
diff
changeset
|
157 |
| Unlinked : |
2878 | 158 |
foreach "$to_unlink"{ |
159 |
| «@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
|
160 |
} |
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
|
161 |
} |