8000 maybe implement terminals · dragoncoder047/schemascii@bee7c8c · GitHub
[go: up one dir, main page]

Skip to content

Commit bee7c8c

Browse files
maybe implement terminals
1 parent 8537dd1 commit bee7c8c

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ C3:100u
3434
C4:10p
3535
D1:1N4001
3636
D2:1N4001
37-
U1:NE555,8,7,6,2,1,5,3,4
37+
U1:NE555,7,6,2,1,5,3,4,8
3838
J1:-5V
3939
J2:GND
4040
```

schemascii/components_render.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from warnings import warn
55
from .utils import (Cbox, Terminal, BOMData, XML, Side,
66
polylinegon, id_text, make_text_point,
7-
bunch_o_lines, deep_transform, make_plus, make_variable)
7+
bunch_o_lines, deep_transform, make_plus, make_variable,
8+
sort_counterclockwise)
89
from .errors import TerminalsError, BOMError, UnsupportedComponentError
910

1011
RENDERERS = {}
@@ -221,7 +222,7 @@ def integrated_circuit(
221222
term.pt,
222223
term.pt + rect(1, SIDE_TO_ANGLE_MAP[term.side])
223224
)], **options)
224-
if "V" in label_style:
225+
if "V" in label_style and part_num:
225226
out += XML.text(
226227
XML.tspan(part_num, class_="part-num"),
227228
x=mid.real,
@@ -238,7 +239,20 @@ def integrated_circuit(
238239
text__anchor="middle",
239240
font__size=options["scale"],
240241
fill=options["stroke"])
241-
warn("ICs are not fully implemented yet. Pin labels have not been rendered.")
242+
s_terminals = sort_counterclockwise(terminals)
243+
for terminal, label in zip(s_terminals, pin_labels):
244+
sc_text_pt = terminal.pt * scale
245+
out += XML.text(
246+
label,
247+
x=sc_text_pt.real,
248+
y=sc_text_pt.imag,
249+
text__anchor=("start" if (terminal.side in (Side.TOP, Side.BOTTOM))
250+
else "middle"),
251+
font__size=options["scale"],
252+
fill=options["stroke"],
253+
class_="pin-label")
254+
warn("ICs are not fully implemented yet. "
255+
"Pin labels may have not been rendered correctly.")
242256
return out
243257

244258

schemascii/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import namedtuple
2+
from itertools import groupby, chain
23
from enum import IntEnum
34
from math import pi
45
from cmath import phase, rect
@@ -221,3 +222,17 @@ def make_variable(
221222
(.75-.5j, .5-.55j),
222223
(.75-.5j, .7-.25j),
223224
], center, theta), **options)
225+
226+
227+
def sort_counterclockwise(terminals: list[Terminal]) -> list[Terminal]:
228+
"Sort the terminals in counterclockwise order."
229+
partitioned = {
230+
side: list(filtered_terminals)
231+
for side, filtered_terminals in groupby(
232+
terminals,
233+
lambda t: t.side)}
234+
return list(chain(
235+
sorted(partitioned[Side.LEFT], key=lambda t: t.pt.imag),
236+
sorted(partitioned[Side.BOTTOM], key=lambda t: t.pt.real),
237+
sorted(partitioned[Side.RIGHT], key=lambda t: -t.pt.imag),
238+
sorted(partitioned[Side.TOP], key=lambda t: -t.pt.real)))

test_data/test_charge_pump.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ C3:100u
2121
C4:10p
2222
D1:1N4001
2323
D2:1N4001
24-
U1:NE555,8,7,6,2,1,5,3,4
24+
U1:NE555,7,6,2,1,5,3,4,8
2525
J1:-5V
2626
J2:GND

test_data/test_resistors.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| | LED1:red B1
55
| *--------* |B1:3.7V,6
66
| | |
7-
| R4 R4:.3k *-----------* C3:2200u,2.5
7+
| R4 R4:.3k *-----------* C3:22000u,2.5
88
| | |
99
| *---R.Heater--|---* R.Heater:0.0081K,0.5K
1010
| | | | VR3:2000
@@ -15,4 +15,6 @@
1515
| .~~~. *-CV1-* CV1:5p
1616
*--1:U1 :3-----*
1717
.~~~.
18-
U1:7805
18+
4
19+
*-----
20+
U1:,1,2,3,4

0 commit comments

Comments
 (0)
0