[svg] add annotate_ports arg
This commit is contained in:
parent
46555dbd4d
commit
ad4e9af59d
1 changed files with 24 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ def writefile(
|
|||
top: str,
|
||||
filename: str,
|
||||
custom_attributes: bool = False,
|
||||
annotate_ports: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
Write a Pattern to an SVG file, by first calling .polygonize() on it
|
||||
|
|
@ -44,6 +45,8 @@ def writefile(
|
|||
filename: Filename to write to.
|
||||
custom_attributes: Whether to write non-standard `pattern_layer` attribute to the
|
||||
SVG elements.
|
||||
annotate_ports: If True, draw an arrow for each port (similar to
|
||||
`Pattern.visualize(..., ports=True)`).
|
||||
"""
|
||||
pattern = library[top]
|
||||
|
||||
|
|
@ -79,6 +82,27 @@ def writefile(
|
|||
|
||||
svg_group.add(path)
|
||||
|
||||
if annotate_ports:
|
||||
# Draw arrows for the ports, pointing into the device (per port definition)
|
||||
for port_name, port in pat.ports.items():
|
||||
if port.rotation is not None:
|
||||
p1 = port.offset
|
||||
angle = port.rotation
|
||||
size = 1.0 # arrow size
|
||||
p2 = p1 + size * numpy.array([numpy.cos(angle), numpy.sin(angle)])
|
||||
|
||||
# head
|
||||
head_angle = 0.5
|
||||
h1 = p1 + 0.7 * size * numpy.array([numpy.cos(angle + head_angle), numpy.sin(angle + head_angle)])
|
||||
h2 = p1 + 0.7 * size * numpy.array([numpy.cos(angle - head_angle), numpy.sin(angle - head_angle)])
|
||||
|
||||
line = svg.line(start=p1, end=p2, stroke='green', stroke_width=0.2)
|
||||
head = svg.polyline(points=[h1, p1, h2], fill='none', stroke='green', stroke_width=0.2)
|
||||
|
||||
svg_group.add(line)
|
||||
svg_group.add(head)
|
||||
svg_group.add(svg.text(port_name, insert=p2, font_size=0.5, fill='green'))
|
||||
|
||||
for target, refs in pat.refs.items():
|
||||
if target is None:
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue