|
1 <?xml version="1.0"?> |
|
2 |
|
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:doc="tooldoc" xmlns:s="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> |
|
4 <xsl:import href="overlay.xsl"/> |
|
5 <xsl:output method="xml"/> |
|
6 <xsl:variable name="Size"> |
|
7 <xsl:choose> |
|
8 <xsl:when test="/s:svg[substring-after(@class,'-')='fixed' and @class!='component-fixed']"> |
|
9 <xsl:value-of select="//s:g[@class=substring-before(/s:svg/@class,'-')]/s:rect/@width"/> |
|
10 </xsl:when> |
|
11 <xsl:otherwise><xsl:value-of select="//s:g[@class='component']/s:use/@width"/></xsl:otherwise> |
|
12 </xsl:choose> |
|
13 </xsl:variable> |
|
14 <xsl:key name="Using" match="Bin" use="@name"/> |
|
15 <xsl:key name="Used-by" match="dep" use="@name"/> |
|
16 <xsl:key name="Id" match="component|collection|subblock|block" use="translate(@name,' ','')"/> |
|
17 |
|
18 <xsl:template match="/" mode="my-prefix">dep-</xsl:template> |
|
19 <xsl:template match="/SystemDefinition" mode="is-present"><xsl:param name="id"/> |
|
20 <xsl:for-each select="key('Id',$id)"> |
|
21 <xsl:choose> |
|
22 <xsl:when test="not(/SystemDefinition/systemModel/@detail-type='fixed')"><xsl:if test="self::component">1</xsl:if></xsl:when> |
|
23 <xsl:when test="name()=/SystemDefinition/systemModel/@detail">1</xsl:when> |
|
24 <xsl:when test="/SystemDefinition/systemModel/@detail='subblock' and self::block and not(subblock)">1</xsl:when> |
|
25 </xsl:choose> |
|
26 </xsl:for-each> |
|
27 </xsl:template> |
|
28 |
|
29 |
|
30 |
|
31 <xsl:template match="/" mode="my-legend"> |
|
32 <!-- height="9" width="17" --> |
|
33 <s:text text-anchor="end" dominant-baseline="mathematical" class="label" x="3" y="3" width="5">Uses</s:text> |
|
34 <s:text text-anchor="end" dominant-baseline="mathematical" class="label" x="3" y="6" width="5">Used by</s:text> |
|
35 <s:path d="M 4 3 L 14 3" class="arrow" style="stroke-width:0.3!important"/> |
|
36 <s:path d="M 4 6 L 14 6" class="arrowF" style="stroke-width:0.3!important"/> |
|
37 </xsl:template> |
|
38 |
|
39 <xsl:template match="*" mode="my-defs"> |
|
40 <xsl:variable name="width"> |
|
41 <xsl:choose> |
|
42 <xsl:when test="/SystemDefinition/systemModel/@detail='layer'">4.8</xsl:when> |
|
43 <xsl:when test="/SystemDefinition/systemModel/@detail='block'">2.4</xsl:when> |
|
44 <xsl:when test="/SystemDefinition/systemModel/@detail='subblock'">1.2</xsl:when> |
|
45 <xsl:when test="/SystemDefinition/systemModel/@detail='collection'">0.6</xsl:when> |
|
46 <xsl:otherwise>0.3</xsl:otherwise> |
|
47 </xsl:choose> |
|
48 </xsl:variable> |
|
49 <s:defs> |
|
50 <s:marker id="Triangle" |
|
51 viewBox="-1 -1 7 7" refX="5" refY="2" |
|
52 markerUnits="strokeWidth" |
|
53 markerWidth="6" markerHeight="6" |
|
54 orient="auto"> |
|
55 <s:polygon style="fill:black;stroke:black;" points="0,0 5,2 0,4 0,0"/> |
|
56 </s:marker> |
|
57 <s:marker id="TriangleF" |
|
58 viewBox="-1 -1 7 7" refX="0" refY="2" |
|
59 markerUnits="strokeWidth" |
|
60 markerWidth="6" markerHeight="6" |
|
61 orient="auto"> |
|
62 <s:polygon style="fill:blue;stroke:blue;" points="5,0 5,4 0,2 5,0"/> |
|
63 </s:marker> |
|
64 <s:style type="text/css"> |
|
65 path.arrow { |
|
66 marker-end: url(#Triangle); |
|
67 fill:none;stroke: black; |
|
68 stroke-width: <xsl:value-of select="$width"/>px; |
|
69 } |
|
70 path.arrowF { |
|
71 marker-start: url(#TriangleF); |
|
72 fill:none;stroke: blue; |
|
73 stroke-width: <xsl:value-of select="$width"/>px; |
|
74 } |
|
75 </s:style> |
|
76 </s:defs> |
|
77 </xsl:template> |
|
78 |
|
79 |
|
80 <xsl:template match="component|collection|block|subblock|layer" mode="id"><xsl:value-of select="translate(@name,' ','')"/></xsl:template> |
|
81 <xsl:template mode="owner" match="dep"> |
|
82 <xsl:for-each select="key('Using',@name)"> |
|
83 <xsl:choose> |
|
84 <xsl:when test="/SystemDefinition/systemModel/@detail='layer'"><xsl:apply-templates select="ancestor::layer" mode="id"/></xsl:when> |
|
85 <xsl:when test="/SystemDefinition/systemModel/@detail='block'"><xsl:apply-templates select="ancestor::block" mode="id"/></xsl:when> |
|
86 <xsl:when test="/SystemDefinition/systemModel/@detail='subblock' and ancestor::subblock"><xsl:apply-templates select="ancestor::subblock" mode="id"/></xsl:when> |
|
87 <xsl:when test="/SystemDefinition/systemModel/@detail='subblock'"><xsl:apply-templates select="ancestor::block" mode="id"/></xsl:when> |
|
88 <xsl:when test="/SystemDefinition/systemModel/@detail='collection'"><xsl:apply-templates select="../../.." mode="id"/></xsl:when> |
|
89 <xsl:otherwise><xsl:apply-templates select="../.." mode="id"/></xsl:otherwise> |
|
90 </xsl:choose> |
|
91 <xsl:text> </xsl:text> |
|
92 </xsl:for-each> |
|
93 </xsl:template> |
|
94 |
|
95 <xsl:template match="/SystemDefinition" mode="deps"><xsl:param name="id"/> |
|
96 <xsl:for-each select="key('Id',$id)/descendant-or-self::component/Build/Bin/dep"> |
|
97 <xsl:apply-templates select="." mode="owner"/> |
|
98 </xsl:for-each> |
|
99 </xsl:template> |
|
100 |
|
101 <xsl:template match="/SystemDefinition" mode="used"><xsl:param name="id"/> |
|
102 <xsl:for-each select="key('Id',$id)/descendant-or-self::component/Build/Bin"> |
|
103 <xsl:for-each select="key('Used-by',@name)/../../.."> |
|
104 <xsl:choose> |
|
105 <xsl:when test="/SystemDefinition/systemModel/@detail='layer'"><xsl:apply-templates select="ancestor::layer" mode="id"/></xsl:when> |
|
106 <xsl:when test="/SystemDefinition/systemModel/@detail='block'"><xsl:apply-templates select="ancestor::block" mode="id"/></xsl:when> |
|
107 <xsl:when test="/SystemDefinition/systemModel/@detail='subblock' and ancestor::subblock"><xsl:apply-templates select="ancestor::subblock" mode="id"/></xsl:when> |
|
108 <xsl:when test="/SystemDefinition/systemModel/@detail='subblock'"><xsl:apply-templates select="ancestor::block" mode="id"/></xsl:when> |
|
109 <xsl:when test="/SystemDefinition/systemModel/@detail='collection'"><xsl:apply-templates select=".." mode="id"/></xsl:when> |
|
110 <xsl:otherwise><xsl:apply-templates select="." mode="id"/></xsl:otherwise> |
|
111 </xsl:choose> |
|
112 <xsl:text> </xsl:text> |
|
113 </xsl:for-each> |
|
114 </xsl:for-each> |
|
115 </xsl:template> |
|
116 |
|
117 |
|
118 |
|
119 <xsl:template match="s:g" mode="my-overlay"><xsl:param name="id"/> |
|
120 <xsl:variable name="libs"> |
|
121 <xsl:apply-templates select="document($Data,/)/*" mode="deps"> |
|
122 <xsl:with-param name="id" select="$id"/> |
|
123 </xsl:apply-templates> |
|
124 </xsl:variable> |
|
125 <xsl:variable name="pos"> |
|
126 <xsl:apply-templates select="." mode="item-pos"/> |
|
127 </xsl:variable> |
|
128 <xsl:variable name="h"> |
|
129 <xsl:apply-templates select="." mode="height"/> |
|
130 </xsl:variable> |
|
131 |
|
132 <xsl:if test="$libs!=''"> |
|
133 <xsl:call-template name="lines"> |
|
134 <xsl:with-param name="origin" select="$pos"/> |
|
135 <xsl:with-param name="from" select="$id"/> |
|
136 <xsl:with-param name="height" select="$h"/> |
|
137 <xsl:with-param name="list" select="$libs"/> |
|
138 <xsl:with-param name="class" select="'arrow'"/> |
|
139 </xsl:call-template> |
|
140 </xsl:if> |
|
141 <xsl:variable name="used"> |
|
142 <xsl:apply-templates select="document($Data,/)/*" mode="used"> |
|
143 <xsl:with-param name="id" select="$id"/> |
|
144 </xsl:apply-templates> |
|
145 </xsl:variable> |
|
146 <xsl:if test="$used!=''"> |
|
147 <xsl:call-template name="lines"> |
|
148 <xsl:with-param name="origin" select="$pos"/> |
|
149 <xsl:with-param name="from" select="$id"/> |
|
150 <xsl:with-param name="height" select="$h"/> |
|
151 <xsl:with-param name="list" select="$used"/> |
|
152 <xsl:with-param name="class" select="'arrowF'"/> |
|
153 </xsl:call-template> |
|
154 </xsl:if> |
|
155 </xsl:template> |
|
156 |
|
157 <!-- drawing lines follows --> |
|
158 |
|
159 <xsl:template name="lines"><xsl:param name="list"/><xsl:param name="from"/><xsl:param name="height"/><xsl:param name="origin"/><xsl:param name="class"/> |
|
160 <xsl:variable name="id" select="substring-before($list,' ')"/> |
|
161 <xsl:variable name="next"><xsl:value-of select="substring-after($list,' ')"/></xsl:variable> |
|
162 <xsl:if test="not(contains(concat(' ',$next),concat(' ',$id,' '))) and $id!=$from and $id!=''"> |
|
163 <xsl:call-template name="draw-line"> |
|
164 <xsl:with-param name="class" select="$class"/> |
|
165 <xsl:with-param name="h0" select="$height"/> |
|
166 <xsl:with-param name="origin" select="$origin"/> |
|
167 <xsl:with-param name="end"><xsl:apply-templates select="key('id',$id)" mode="item-pos"/></xsl:with-param> |
|
168 <xsl:with-param name="h1"><xsl:apply-templates select="key('id',$id)" mode="height"/></xsl:with-param> |
|
169 </xsl:call-template> |
|
170 </xsl:if> |
|
171 <xsl:if test="$next!=''"><xsl:call-template name="lines"> |
|
172 <xsl:with-param name="list" select="$next"/> |
|
173 <xsl:with-param name="origin" select="$origin"/> |
|
174 <xsl:with-param name="height" select="$height"/> |
|
175 <xsl:with-param name="from" select="$from"/> |
|
176 <xsl:with-param name="class" select="$class"/> |
|
177 </xsl:call-template></xsl:if> |
|
178 </xsl:template> |
|
179 |
|
180 |
|
181 <xsl:template name="draw-line"><xsl:param name="origin"/><xsl:param name="end"/><xsl:param name="class"/> |
|
182 <xsl:param name="h0"/><xsl:param name="h1"/> |
|
183 <xsl:variable name="x0" select="substring-before($origin,',')"/> |
|
184 <xsl:variable name="y0" select="substring-after($origin,',')"/> |
|
185 <xsl:variable name="x1" select="substring-before($end,',')"/> |
|
186 <xsl:variable name="y1" select="substring-after($end,',')"/> |
|
187 <xsl:variable name="dx" select="$x1 - $x0"/> |
|
188 <xsl:variable name="dy" select="$y1 - $y0"/> |
|
189 <xsl:variable name="sgnY" select="($y1 > $y0) * 2 - 1"/> |
|
190 <xsl:variable name="sgnX" select="($x1 > $x0) * 2 - 1"/> |
|
191 <xsl:if test="contains(substring-after($origin,','),',')">/<xsl:value-of select="$origin"/>/</xsl:if> |
|
192 |
|
193 <s:path class="{$class}"><xsl:attribute name="d"> |
|
194 <xsl:choose> |
|
195 <xsl:when test="$dy=0"> |
|
196 <xsl:call-template name="draw-curve"> |
|
197 <xsl:with-param name="origin" select="$origin"/> |
|
198 <xsl:with-param name="end" select="$end"/> |
|
199 <xsl:with-param name="h0" select="$h0"/> |
|
200 <xsl:with-param name="h1" select="$h1"/> |
|
201 </xsl:call-template> |
|
202 </xsl:when> |
|
203 <xsl:when test="$dx=0"> |
|
204 <xsl:call-template name="draw-vcurve"> |
|
205 <xsl:with-param name="origin" select="$origin"/> |
|
206 <xsl:with-param name="end" select="$end"/> |
|
207 <xsl:with-param name="h0" select="$h0"/> |
|
208 <xsl:with-param name="h1" select="$h1"/> |
|
209 </xsl:call-template> |
|
210 </xsl:when> |
|
211 <xsl:otherwise> |
|
212 <xsl:text>M</xsl:text> |
|
213 |
|
214 <xsl:choose> |
|
215 <xsl:when test="$dx > 0 and (($dy > 0 and ($dx * $h0 >= $dy* $Size)) or ($dy <= 0 and ($dx * $h0 >= -$dy* $Size)))"> |
|
216 <!-- crop against E side of origin --> |
|
217 <xsl:variable name="y-off" select="$Size * 0.5 * $dy div $dx "/> |
|
218 <xsl:value-of select="concat($x0 + 0.5 * $Size,',',$y0 + $y-off)"/> |
|
219 </xsl:when> |
|
220 <xsl:when test="$dy > 0 and (($dx >= 0 and $dx * $h0 < $dy * $Size) or ($dx <= 0 and -$dx * $h0 < $dy* $Size))"> <!-- and dx < dy --> |
|
221 <!-- crop against S side of origin --> |
|
222 <xsl:variable name="x-off" select="$h0 * 0.5 * $dx div $dy"/> |
|
223 <xsl:value-of select="concat($x0 + $x-off, ',' ,$y0 + 0.5 * $h0)"/> |
|
224 </xsl:when> |
|
225 <xsl:when test="$dy < 0 and (($dx >= 0 and $dx * $h0 < -$dy* $Size) or ($dx <= 0 and -$dx * $h0 < -$dy* $Size))"> |
|
226 <!-- crop against N side of origin --> |
|
227 <xsl:variable name="x-off" select="- $h0 * 0.5 * $dx div $dy"/> |
|
228 <xsl:value-of select="concat($x0 + $x-off, ',' ,$y0 - 0.5 * $h0 )"/> |
|
229 </xsl:when> |
|
230 <xsl:otherwise> |
|
231 <!-- crop against W side or origin --> |
|
232 <xsl:variable name="y-off" select=" - $Size * 0.5 * $dy div $dx "/> |
|
233 <xsl:value-of select="concat($x0 - 0.5 * $Size,',',$y0 + $y-off)"/> |
|
234 </xsl:otherwise> |
|
235 </xsl:choose> |
|
236 <xsl:text>L </xsl:text> |
|
237 <xsl:choose> |
|
238 <xsl:when test="$dx > 0 and (($dy > 0 and ($dx * $h1 >= $dy* $Size)) or ($dy <= 0 and ($dx * $h1 >= -$dy* $Size)))"> |
|
239 <!-- crop against W side of end --> |
|
240 <xsl:value-of select="concat($x1 - 0.5 * $Size,',',$y0 + ($dx - 0.5 * $Size) * $dy div $dx)"/> |
|
241 </xsl:when> |
|
242 <xsl:when test="$dy > 0 and (($dx >= 0 and $dx * $h1 < $dy * $Size) or ($dx <= 0 and -$dx * $h1 < $dy* $Size))"> <!-- and dx < dy --> |
|
243 <!-- crop against N side of end --> |
|
244 <xsl:value-of select="concat($x0 + ($dy - 0.5 * $h1) * $dx div $dy , ',' , $y1 - 0.5 * $h1)"/> |
|
245 </xsl:when> |
|
246 <xsl:when test="$dy < 0 and (($dx >= 0 and $dx * $h1 < -$dy* $Size) or ($dx <= 0 and -$dx * $h1 < -$dy* $Size))"> |
|
247 <!-- crop against S side of end --> |
|
248 <xsl:value-of select="concat($x0 + ($dy + 0.5 * $h1) * $dx div $dy , ',' , $y1 + 0.5 * $h1)"/> |
|
249 </xsl:when> |
|
250 <xsl:otherwise> |
|
251 <!-- crop against E side of end --> |
|
252 <xsl:value-of select="concat($x1 + 0.5 * $Size,',',$y0 + ($dx + 0.5 * $Size) * $dy div $dx)"/> |
|
253 </xsl:otherwise> |
|
254 </xsl:choose> |
|
255 </xsl:otherwise> |
|
256 </xsl:choose> |
|
257 </xsl:attribute> |
|
258 </s:path> |
|
259 </xsl:template> |
|
260 |
|
261 <xsl:template name="draw-curve"><xsl:param name="origin"/><xsl:param name="end"/><xsl:param name="class"/> |
|
262 <xsl:param name="h0"/><xsl:param name="h1"/> |
|
263 <xsl:variable name="x0" select="substring-before($origin,',')"/> |
|
264 <xsl:variable name="y0" select="substring-after($origin,',')"/> |
|
265 <xsl:variable name="x1" select="substring-before($end,',')"/> |
|
266 <xsl:variable name="y1" select="substring-after($end,',')"/> |
|
267 <xsl:variable name="dx" select="$x1 - $x0"/> |
|
268 <xsl:variable name="up" select="floor($dx) mod 2 != 0"/> <!-- line is above or below componetns --> |
|
269 <xsl:variable name="sgn" select="($dx > 0 ) * 2 - 1"/> |
|
270 <!-- offset the x-coord so that if the components are next to each other the connection is from nearer the edge of the side |
|
271 and if they're very far apart the connection's closer to the centre of the side. This way the centre of the edge is not too busy |
|
272 (x-off approches zero as length goes to infiniity)--> |
|
273 <xsl:variable name="x-off" select="0.25 * $sgn * $Size * $Size div ($sgn * $dx)"/> |
|
274 <xsl:value-of select="concat('M',$x0 + $x-off,',')"/> |
|
275 <xsl:choose> |
|
276 <xsl:when test="($up and ($x1 > $x0)) or (not($up) and ($x1 < $x0)) "><xsl:value-of select="$y0 + (0.5*$h0)"/>c</xsl:when> |
|
277 <xsl:otherwise><xsl:value-of select="$y0 - (0.5*$h0)"/>c</xsl:otherwise> |
|
278 </xsl:choose> |
|
279 <xsl:variable name="peak"> |
|
280 <xsl:choose> <!-- don't think i need the 0.5 * h0 --> |
|
281 <xsl:when test="$up"><xsl:value-of select="$sgn * (0.5 * $h0 + ($sgn * $dx div 8))"/></xsl:when> |
|
282 <xsl:otherwise><xsl:value-of select="- $sgn * (0.5 * $h0 + ($sgn * $dx div 8))"/></xsl:otherwise> |
|
283 </xsl:choose> |
|
284 </xsl:variable> |
|
285 <xsl:value-of select="concat(($dx - $x-off * 2) div 3 , ', ', $peak,' ',$dx - $x-off * 2 ,',', 2 * $peak, ' ',$dx - $x-off * 2,',0')"/> |
|
286 </xsl:template> |
|
287 |
|
288 <xsl:template name="draw-vcurve"><xsl:param name="origin"/><xsl:param name="end"/><xsl:param name="class"/> |
|
289 <xsl:param name="h0"/><xsl:param name="h1"/> |
|
290 <xsl:variable name="x0" select="substring-before($origin,',')"/> |
|
291 <xsl:variable name="y0" select="substring-after($origin,',')"/> |
|
292 <xsl:variable name="x1" select="substring-before($end,',')"/> |
|
293 <xsl:variable name="y1" select="substring-after($end,',')"/> |
|
294 <xsl:variable name="dy" select="$y1 - $y0"/> |
|
295 <xsl:variable name="left" select="floor($dy) mod 2 != 0"/> <!-- line is above or below componetns --> |
|
296 <xsl:variable name="sgn" select="($dy > 0 ) * 2 - 1"/> |
|
297 <!-- offset the y-coord so that if the components are next to each other the connection is from nearer the edge of the side |
|
298 and if they're very far apart the connection's closer to the centre of the side. This way the centre of the edge is not too busy |
|
299 (y-off approches zero as length goes to infiniity)--> |
|
300 <xsl:variable name="y-off" select="0.25 * $sgn * $h0 * ($h0 +$h1) div ($sgn * $dy)"/> |
|
301 |
|
302 <xsl:text>M</xsl:text> |
|
303 <xsl:choose> |
|
304 <xsl:when test="($left and ($y1 > $y0)) or (not($left) and ($y1 < $y0)) "><xsl:value-of select="$x0 + (0.5*$Size)"/></xsl:when> |
|
305 <xsl:otherwise><xsl:value-of select="$x0 - (0.5*$Size)"/></xsl:otherwise> |
|
306 </xsl:choose> |
|
307 <xsl:text>,</xsl:text> |
|
308 <xsl:value-of select="$y0 + $y-off"/> |
|
309 |
|
310 <xsl:text>c</xsl:text> |
|
311 <xsl:variable name="y-off1" select="0.25 * $sgn * $h1 * ($h0 +$h1) div ($sgn * $dy)"/> |
|
312 <xsl:variable name="peak"><!-- don't think i need the 0.5 * Size --> |
|
313 <xsl:choose> |
|
314 <xsl:when test="$left"><xsl:value-of select="$sgn * (0.5 * $Size + ($sgn * $dy div 8))"/></xsl:when> |
|
315 <xsl:otherwise><xsl:value-of select="- $sgn * (0.5 * $Size + ($sgn * $dy div 8))"/></xsl:otherwise> |
|
316 </xsl:choose> |
|
317 </xsl:variable> |
|
318 <xsl:value-of select="concat($peak, ', ', ($dy - $y-off1 - $y-off) div 3 , ' ' , 2 * $peak, ' ',$dy - $y-off1 - $y-off , ' 0,',$dy - $y-off1 - $y-off)"/> |
|
319 </xsl:template> |
|
320 |
|
321 </xsl:stylesheet> |