Skip to content

Commit

Permalink
inductors
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoncoder047 authored Mar 20, 2023
1 parent ed13296 commit 61e4251
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 72 deletions.
Binary file added dist/schemascii-0.2.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/schemascii-0.2.2.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "schemascii"
version = "0.2.1"
version = "0.2.2"
description = "Render ASCII-art schematics to SVG"
readme = "README.md"
authors = [{ name = "dragoncoder047", email = "101021094+dragoncoder047@users.noreply.github.com" }]
Expand Down
2 changes: 1 addition & 1 deletion schemascii/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .utils import XML
from .errors import *

__version__ = "0.2.1"
__version__ = "0.2.2"


def render(filename: str, text: str = None, **options) -> str:
Expand Down
67 changes: 45 additions & 22 deletions schemascii/components_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def sort_terminals(
return sort_terminals


@component("R", "RV", "VR")
@n_terminal(2)
@no_ambiguous
def resistor(
box: Cbox,
terminals: list[Terminal],
Expand All @@ -106,16 +109,11 @@ def resistor(
points.append(t1 - rect(i / 4, angle) +
pow(-1, i) * rect(1, quad_angle) / 4)
points.append(t2)
text_pt = make_text_point(t1, t2, **options)
return (polylinegon(points, **options)
+ make_variable(mid, angle, "V" in box.type, **options)
+ id_text(
box, bom_data, terminals, (("Ω", False), ("W", False)),
text_pt, **options))


# Register it
component("R", "RV", "VR")(n_terminal(2)(no_ambiguous(resistor)))
make_text_point(t1, t2, **options), **options))


@component("C", "CV", "VC")
Expand All @@ -138,13 +136,42 @@ def capacitor(
(complex(.4, .25), complex(-.4, .25)),
(complex(.4, -.25), complex(-.4, -.25)),
], mid, angle)
text_pt = make_text_point(t1, t2, **options)
return (bunch_o_lines(lines, **options)
+ make_plus(terminals, mid, angle, **options)
+ make_variable(mid, angle, "V" in box.type, **options)
+ id_text(
box, bom_data, terminals, (("F", True), ("V", False)),
text_pt, **options))
make_text_point(t1, t2, **options), **options))


@component("L", "VL", "LV")
@no_ambiguous
def inductor(
box: Cbox,
terminals: list[Terminal],
bom_data: BOMData,
**options):
"""Draw an inductor (coil, choke, etc)
bom:henries"""
t1, t2 = terminals[0].pt, terminals[1].pt
vec = t1 - t2
mid = (t1 + t2) / 2
length = abs(vec)
angle = phase(vec)
scale = options["scale"]
data = f"M{t1.real * scale} {t1.imag * scale}"
dxdy = rect(scale, angle)
for _ in range(int(length)):
data += f"a1 1 0 01{-dxdy.real} {dxdy.imag}"
return (XML.path(
d=data,
stroke=options["stroke"],
fill="transparent",
stroke__width=options["stroke_width"])
+ make_variable(mid, angle, "V" in box.type, **options)
+ id_text(
box, bom_data, terminals, (("H", False),),
make_text_point(t1, t2, **options), **options))


@component("B", "BT", "BAT")
Expand All @@ -169,10 +196,9 @@ def battery(
(complex(.5, -.16), complex(-.5, -.16)),
(complex(.25, -.5), complex(-.25, -.5)),
], mid, angle)
text_pt = make_text_point(t1, t2, **options)
return (id_text(
box, bom_data, terminals, (("V", False), ("Ah", False)),
text_pt, **options)
make_text_point(t1, t2, **options), **options)
+ bunch_o_lines(lines, **options))


Expand All @@ -195,12 +221,13 @@ def diode(
(t1, mid + rect(-.3, angle)),
deep_transform((-.3-.3j, .3-.3j), mid, angle)]
triangle = deep_transform((-.3j, .3+.3j, -.3+.3j), mid, angle)
text_pt = make_text_point(t1, t2, **options)
light_emitting = "LED", "IR"
light_emitting = box.type in ("LED", "IR")
fill_override = {"stroke": bom_data.data} if box.type == "LED" else {}
return ((light_arrows(mid, angle, True, **options)
if box.type in light_emitting else "")
+ id_text(box, bom_data, terminals, None, text_pt, **options)
+ bunch_o_lines(lines, **options)
if light_emitting else "")
+ id_text(box, bom_data, terminals, None,
make_text_point(t1, t2, **options), **options)
+ bunch_o_lines(lines, **(options | fill_override))
+ polylinegon(triangle, True, **options))


Expand Down Expand Up @@ -337,7 +364,7 @@ def transistor(
# x = (m^2 x1 - m y1 + m y2 + x2)/(m^2 + 1)
slope = diff.imag / diff.real
mid_x = (slope ** 2 * ap.real - slope * ap.imag + slope *
ctl.pt.imag + ctl.pt.real) / (slope ** 2 + 1)
ctl.pt.imag + ctl.pt.real) / (slope ** 2 + 1)
mid = complex(mid_x, slope * (mid_x - ap.real) + ap.imag)
theta = phase(ap - sp)
backwards = 1 if is_clockwise([ae, se, ctl]) else -1
Expand Down Expand Up @@ -371,8 +398,8 @@ def transistor(
mid - rect(1, theta) + rect(1, thetaquarter)),
])
out_lines.append((mid + rect(1, thetaquarter), ctl.pt))
text_pt = make_text_point(ap, sp, **options)
return (id_text(box, bom_data, [ae, se], None, text_pt, **options)
return (id_text(box, bom_data, [ae, se], None,
make_text_point(ap, sp, **options), **options)
+ bunch_o_lines(out_lines, **options))

# code for drawing stuff
Expand All @@ -390,10 +417,6 @@ def transistor(
'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',
# jumper pads
'JP': 'M0-1Q-1-1-1-.25H1Q1-1 0-1ZM0 1Q-1 1-1 .25H1Q1 1 0 1',
# inductor style 1 (humps)
'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',
# inductor style 2 (coil)
# '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',
# loudspeaker
'LS': 'M0-1V-.5H-.25V.5H.25V-.5H0M0 1V.5ZM1-1 .25-.5V.5L1 1Z',
# electret mic
Expand Down
1 change: 1 addition & 0 deletions supported-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Instead, edit schemascii/components_render.py and run scripts/cdoc.py to re-gene
|:--:|:--|:--:|:--|
| `R`, `RV`, `VR` | Resistor, Variable resistor, etc. | `ohms[,watts]` | |
| `C`, `CV`, `VC` | Draw a capacitor, variable capacitor, etc. | `farads[,volts]` | `+` = positive |
| `L`, `VL`, `LV` | Draw an inductor (coil, choke, etc) | `henries` | |
| `B`, `BT`, `BAT` | Draw a battery cell. | `volts[,amp-hours]` | `+` = positive |
| `D`, `LED`, `CR`, `IR` | Draw a diode or LED. | `part-number` | `+` = positive |
| `U`, `IC` | Draw an IC. | `part-number[,pin1-label[,pin2-label[,...]]]` | |
Expand Down
53 changes: 5 additions & 48 deletions test_data/test1.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
-------sMOSFET1d-----
g MOSFET1:nfet:2N7000
*--------
!padding=30!
----------L1------

-------eQ1c-----
b Q1:pnp:TIP102
*------

-------dMOSFET2s-----
g MOSFET2:pfet:2N7001
*--------

-------cQ2e-----
b Q2:npn:TIP103
*------

-------dMOSFET3s-----
g MOSFET3:nfet:2N7000
*--------

-------cQ3e-----
b Q3:pnp:TIP102
*------

-------sMOSFET4d-----
g MOSFET4:pfet:2N7001
*--------

-------eQ4c-----
b Q4:npn:TIP103
*------

--------*
e
.~~~~~.
: :
-------b: Q9 : Q9:pnp:7476
: :
: :
: :
.~~~~~.
c
|
|




!padding=30!
------L2###########-------
L1:220u
L2:330u

0 comments on commit 61e4251

Please sign in to comment.