author | Edouard Tisserant |
Mon, 30 Mar 2020 14:26:42 +0200 | |
branch | svghmi |
changeset 2906 | 3b4a1319da09 |
parent 2904 | 92d115d8828d |
child 2909 | 0519fdce9a59 |
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 |
|
2878 | 5 |
// Identity template : |
6 |
// - copy every attributes |
|
7 |
// - copy every sub-elements |
|
8 |
template "@* | node()", mode="inline_svg" { |
|
9 |
// use real xsl:copy instead copy-of alias from yslt.yml2 |
|
10 |
if "not(@id = $discardable_elements/@id)" |
|
11 |
xsl:copy apply "@* | node()", mode="inline_svg"; |
|
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 | 14 |
// replaces inkscape's height and width hints. forces fit |
15 |
template "svg:svg/@width", mode="inline_svg"; |
|
16 |
template "svg:svg/@height", mode="inline_svg"; |
|
17 |
svgtmpl "svg:svg", mode="inline_svg" svg { |
|
18 |
attrib "preserveAspectRatio" > none |
|
19 |
attrib "height" > 100vh |
|
20 |
attrib "width" > 100vw |
|
21 |
apply "@* | node()", mode="inline_svg"; |
|
22 |
} |
|
23 |
// ensure that coordinate in CSV file generated by inkscape are in default reference frame |
|
24 |
template "svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]", mode="inline_svg" { |
|
25 |
error > ViewBox settings other than X=0, Y=0 and Scale=1 are not supported |
|
26 |
} |
|
27 |
// ensure that coordinate in CSV file generated by inkscape match svg default unit |
|
28 |
template "sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']", mode="inline_svg" { |
|
29 |
error > All units must be set to "px" in Inkscape's document properties |
|
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 | 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 | 35 |
// svg:use (inkscape's clones) inside a widgets are |
36 |
// replaced by real elements they refer in order to : |
|
37 |
// - allow finding "needle" element in "meter" widget, |
|
38 |
// even if "needle" is in a group refered by a svg use. |
|
39 |
// - if "needle" is visible through a svg:use for |
|
40 |
// each instance of the widget, then needle would show |
|
41 |
// the same position in all instances |
|
42 |
// |
|
43 |
// For now, clone unlinkink applies to descendants of all widget except HMI:Page |
|
44 |
// TODO: narrow application of clone unlinking to active elements, |
|
45 |
// while keeping static decoration cloned |
|
46 |
const "to_unlink", "$hmi_elements[not(@id = $hmi_pages)]//svg:use"; |
|
47 |
svgtmpl "svg:use", mode="inline_svg" |
|
48 |
{ |
|
49 |
choose { |
|
50 |
when "@id = $to_unlink/@id" |
|
51 |
call "unlink_clone"; |
|
52 |
otherwise |
|
53 |
xsl:copy apply "@* | node()", mode="inline_svg"; |
|
54 |
} |
|
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 | 57 |
// to unlink a clone, an group containing a copy of target element is created |
58 |
// that way, style and transforms can be preserved |
|
59 |
const "_excluded_use_attrs" { |
|
60 |
name > href |
|
61 |
name > width |
|
62 |
name > height |
|
63 |
name > x |
|
64 |
name > y |
|
65 |
} |
|
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 | 68 |
svgfunc "unlink_clone"{ |
69 |
g{ |
|
70 |
// include non excluded attributes |
|
71 |
foreach "@*[not(local-name() = $excluded_use_attrs/name)]" |
|
72 |
attrib "{name()}" > «.» |
|
2853 | 73 |
|
2878 | 74 |
const "targetid","substring-after(@xlink:href,'#')"; |
75 |
apply "//svg:*[@id = $targetid]", mode="unlink_clone"{ |
|
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 | 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 | 81 |
// clone unlinking is really similar to deep-copy |
82 |
// all nodes are sytematically copied |
|
83 |
svgtmpl "@id", mode="unlink_clone" { |
|
84 |
param "seed"; |
|
85 |
attrib "id" > «$seed»_«.» |
|
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 | 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 | 90 |
// copying widgets would have unwanted effect |
91 |
// instead widget is refered through a svg:use. |
|
92 |
svgtmpl "svg:*", mode="unlink_clone" { |
|
93 |
param "seed"; |
|
94 |
choose { |
|
95 |
// node recursive copy ends when finding a widget |
|
96 |
when "@id = $hmi_elements/@id" { |
|
97 |
// place a clone instead of copying |
|
98 |
use{ |
|
99 |
attrib "xlink:href" > «concat('#',@id)» |
|
100 |
} |
|
101 |
} |
|
102 |
otherwise { |
|
103 |
xsl:copy apply "@* | node()", mode="unlink_clone" { |
|
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 | 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 | 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 | 112 |
const "result_svg" apply "/", mode="inline_svg"; |
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 | 118 |
foreach "$to_unlink"{ |
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 |
} |