Skip to content

Commit 61e4251

Browse files
inductors
1 parent ed13296 commit 61e4251

7 files changed

+53
-72
lines changed
44.7 KB
Binary file not shown.

dist/schemascii-0.2.2.tar.gz

54.9 KB
Binary file not shown.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "schemascii"
7-
version = "0.2.1"
7+
version = "0.2.2"
88
description = "Render ASCII-art schematics to SVG"
99
readme = "README.md"
1010
authors = [{ name = "dragoncoder047", email = "[email protected]" }]

schemascii/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .utils import XML
99
from .errors import *
1010

11-
__version__ = "0.2.1"
11+
__version__ = "0.2.2"
1212

1313

1414
def render(filename: str, text: str = None, **options) -> str:

schemascii/components_render.py

+45-22
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def sort_terminals(
8888
return sort_terminals
8989

9090

91+
@component("R", "RV", "VR")
92+
@n_terminal(2)
93+
@no_ambiguous
9194
def resistor(
9295
box: Cbox,
9396
terminals: list[Terminal],
@@ -106,16 +109,11 @@ def resistor(
106109
points.append(t1 - rect(i / 4, angle) +
107110
pow(-1, i) * rect(1, quad_angle) / 4)
108111
points.append(t2)
109-
text_pt = make_text_point(t1, t2, **options)
110112
return (polylinegon(points, **options)
111113
+ make_variable(mid, angle, "V" in box.type, **options)
112114
+ id_text(
113115
box, bom_data, terminals, (("Ω", False), ("W", False)),
114-
text_pt, **options))
115-
116-
117-
# Register it
118-
component("R", "RV", "VR")(n_terminal(2)(no_ambiguous(resistor)))
116+
make_text_point(t1, t2, **options), **options))
119117

120118

121119
@component("C", "CV", "VC")
@@ -138,13 +136,42 @@ def capacitor(
138136
(complex(.4, .25), complex(-.4, .25)),
139137
(complex(.4, -.25), complex(-.4, -.25)),
140138
], mid, angle)
141-
text_pt = make_text_point(t1, t2, **options)
142139
return (bunch_o_lines(lines, **options)
143140
+ make_plus(terminals, mid, angle, **options)
144141
+ make_variable(mid, angle, "V" in box.type, **options)
145142
+ id_text(
146143
box, bom_data, terminals, (("F", True), ("V", False)),
147-
text_pt, **options))
144+
make_text_point(t1, t2, **options), **options))
145+
146+
147+
@component("L", "VL", "LV")
148+
@no_ambiguous
149+
def inductor(
150+
box: Cbox,
151+
terminals: list[Terminal],
152+
bom_data: BOMData,
153+
**options):
154+
"""Draw an inductor (coil, choke, etc)
155+
bom:henries"""
156+
t1, t2 = terminals[0].pt, terminals[1].pt
157+
vec = t1 - t2
158+
mid = (t1 + t2) / 2
159+
length = abs(vec)
160+
angle = phase(vec)
161+
scale = options["scale"]
162+
data = f"M{t1.real * scale} {t1.imag * scale}"
163+
dxdy = rect(scale, angle)
164+
for _ in range(int(length)):
165+
data += f"a1 1 0 01{-dxdy.real} {dxdy.imag}"
166+
return (XML.path(
167+
d=data,
168+
stroke=options["stroke"],
169+
fill="transparent",
170+
stroke__width=options["stroke_width"])
171+
+ make_variable(mid, angle, "V" in box.type, **options)
172+
+ id_text(
173+
box, bom_data, terminals, (("H", False),),
174+
make_text_point(t1, t2, **options), **options))
148175

149176

150177
@component("B", "BT", "BAT")
@@ -169,10 +196,9 @@ def battery(
169196
(complex(.5, -.16), complex(-.5, -.16)),
170197
(complex(.25, -.5), complex(-.25, -.5)),
171198
], mid, angle)
172-
text_pt = make_text_point(t1, t2, **options)
173199
return (id_text(
174200
box, bom_data, terminals, (("V", False), ("Ah", False)),
175-
text_pt, **options)
201+
make_text_point(t1, t2, **options), **options)
176202
+ bunch_o_lines(lines, **options))
177203

178204

@@ -195,12 +221,13 @@ def diode(
195221
(t1, mid + rect(-.3, angle)),
196222
deep_transform((-.3-.3j, .3-.3j), mid, angle)]
197223
triangle = deep_transform((-.3j, .3+.3j, -.3+.3j), mid, angle)
198-
text_pt = make_text_point(t1, t2, **options)
199-
light_emitting = "LED", "IR"
224+
light_emitting = box.type in ("LED", "IR")
225+
fill_override = {"stroke": bom_data.data} if box.type == "LED" else {}
200226
return ((light_arrows(mid, angle, True, **options)
201-
if box.type in light_emitting else "")
202-
+ id_text(box, bom_data, terminals, None, text_pt, **options)
203-
+ bunch_o_lines(lines, **options)
227+
if light_emitting else "")
228+
+ id_text(box, bom_data, terminals, None,
229+
make_text_point(t1, t2, **options), **options)
230+
+ bunch_o_lines(lines, **(options | fill_override))
204231
+ polylinegon(triangle, True, **options))
205232

206233

@@ -337,7 +364,7 @@ def transistor(
337364
# x = (m^2 x1 - m y1 + m y2 + x2)/(m^2 + 1)
338365
slope = diff.imag / diff.real
339366
mid_x = (slope ** 2 * ap.real - slope * ap.imag + slope *
340-
ctl.pt.imag + ctl.pt.real) / (slope ** 2 + 1)
367+
ctl.pt.imag + ctl.pt.real) / (slope ** 2 + 1)
341368
mid = complex(mid_x, slope * (mid_x - ap.real) + ap.imag)
342369
theta = phase(ap - sp)
343370
backwards = 1 if is_clockwise([ae, se, ctl]) else -1
@@ -371,8 +398,8 @@ def transistor(
371398
mid - rect(1, theta) + rect(1, thetaquarter)),
372399
])
373400
out_lines.append((mid + rect(1, thetaquarter), ctl.pt))
374-
text_pt = make_text_point(ap, sp, **options)
375-
return (id_text(box, bom_data, [ae, se], None, text_pt, **options)
401+
return (id_text(box, bom_data, [ae, se], None,
402+
make_text_point(ap, sp, **options), **options)
376403
+ bunch_o_lines(out_lines, **options))
377404

378405
# code for drawing stuff
@@ -390,10 +417,6 @@ def transistor(
390417
'F': 'M0-.9A.1.1 0 000-1.1.1.1 0 000-.9ZM0-1Q.5-.5 0 0T0 1Q-.5.5 0 0T0-1ZM0 1.1A.1.1 0 000 .9.1.1 0 000 1.1Z',
391418
# jumper pads
392419
'JP': 'M0-1Q-1-1-1-.25H1Q1-1 0-1ZM0 1Q-1 1-1 .25H1Q1 1 0 1',
393-
# inductor style 1 (humps)
394-
'L': 'M0-1A.1.1 0 010-.6.1.1 0 010-.2.1.1 0 010 .2.1.1 0 010 .6.1.1 0 010 1 .1.1 0 000 .6.1.1 0 000 .2.1.1 0 000-.2.1.1 0 000-.6.1.1 0 000-1Z',
395-
# inductor style 2 (coil)
396-
# 'L': 'M0-1C1-1 1-.2 0-.2S-1-.8 0-.8 1 0 0 0-1-.6 0-.6 1 .2 0 .2-1-.4 0-.4 1 .4 0 .4-1-.2 0-.2 1 .6 0 .6-1 0 0 0 1 .8 0 .8-1 .2 0 .2 1 1 0 1C1 1 1 .2 0 .2S-1 .8 0 .8 1 0 0 0-1 .6 0 .6 1-.2 0-.2-1 .4 0 .4 1-.4 0-.4-1 .2 0 .2 1-.6 0-.6-1 0 0 0 1-.8 0-.8-1-.2 0-.2 1-1 0-1Z',
397420
# loudspeaker
398421
'LS': 'M0-1V-.5H-.25V.5H.25V-.5H0M0 1V.5ZM1-1 .25-.5V.5L1 1Z',
399422
# electret mic

supported-components.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Instead, edit schemascii/components_render.py and run scripts/cdoc.py to re-gene
1010
|:--:|:--|:--:|:--|
1111
| `R`, `RV`, `VR` | Resistor, Variable resistor, etc. | `ohms[,watts]` | |
1212
| `C`, `CV`, `VC` | Draw a capacitor, variable capacitor, etc. | `farads[,volts]` | `+` = positive |
13+
| `L`, `VL`, `LV` | Draw an inductor (coil, choke, etc) | `henries` | |
1314
| `B`, `BT`, `BAT` | Draw a battery cell. | `volts[,amp-hours]` | `+` = positive |
1415
| `D`, `LED`, `CR`, `IR` | Draw a diode or LED. | `part-number` | `+` = positive |
1516
| `U`, `IC` | Draw an IC. | `part-number[,pin1-label[,pin2-label[,...]]]` | |

test_data/test1.txt

+5-48
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,6 @@
1-
-------sMOSFET1d-----
2-
g MOSFET1:nfet:2N7000
3-
*--------
1+
!padding=30!
2+
----------L1------
43

5-
-------eQ1c-----
6-
b Q1:pnp:TIP102
7-
*------
8-
9-
-------dMOSFET2s-----
10-
g MOSFET2:pfet:2N7001
11-
*--------
12-
13-
-------cQ2e-----
14-
b Q2:npn:TIP103
15-
*------
16-
17-
-------dMOSFET3s-----
18-
g MOSFET3:nfet:2N7000
19-
*--------
20-
21-
-------cQ3e-----
22-
b Q3:pnp:TIP102
23-
*------
24-
25-
-------sMOSFET4d-----
26-
g MOSFET4:pfet:2N7001
27-
*--------
28-
29-
-------eQ4c-----
30-
b Q4:npn:TIP103
31-
*------
32-
33-
--------*
34-
e
35-
.~~~~~.
36-
: :
37-
-------b: Q9 : Q9:pnp:7476
38-
: :
39-
: :
40-
: :
41-
.~~~~~.
42-
c
43-
|
44-
|
45-
46-
47-
48-
49-
!padding=30!
4+
------L2###########-------
5+
L1:220u
6+
L2:330u

0 commit comments

Comments
 (0)