Skip to content

Commit 41a990f

Browse files
port over inductor
1 parent 0dfcbde commit 41a990f

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

schemascii/components_render.py renamed to schemascii/OLD_components_render.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
make_text_point,
1616
bunch_o_lines,
1717
deep_transform,
18-
make_plus,
19-
make_variable,
2018
sort_terminals_counterclockwise,
2119
light_arrows,
2220
sort_for_flags,
23-
is_clockwise,
24-
)
21+
is_clockwise)
2522
from .errors import TerminalsError, BOMError, UnsupportedComponentError
2623

2724
# pylint: disable=unbalanced-tuple-unpacking
@@ -97,42 +94,6 @@ def sort_terminals(
9794
return sort_terminals
9895

9996

100-
@component("L", "VL", "LV")
101-
@n_terminal(2)
102-
@no_ambiguous
103-
def inductor(box: Cbox, terminals: list[Terminal],
104-
bom_data: BOMData, **options):
105-
"""Draw an inductor (coil, choke, etc)
106-
bom:henries"""
107-
t1, t2 = terminals[0].pt, terminals[1].pt
108-
vec = t1 - t2
109-
mid = (t1 + t2) / 2
110-
length = abs(vec)
111-
angle = phase(vec)
112-
scale = options["scale"]
113-
data = f"M{t1.real * scale} {t1.imag * scale}"
114-
dxdy = rect(scale, angle)
115-
for _ in range(int(length)):
116-
data += f"a1 1 0 01 {-dxdy.real} {dxdy.imag}"
117-
return (
118-
XML.path(
119-
d=data,
120-
stroke=options["stroke"],
121-
fill="transparent",
122-
stroke__width=options["stroke_width"],
123-
)
124-
+ make_variable(mid, angle, "V" in box.type, **options)
125-
+ id_text(
126-
box,
127-
bom_data,
128-
terminals,
129-
(("H", False),),
130-
make_text_point(t1, t2, **options),
131-
**options,
132-
)
133-
)
134-
135-
13697
@component("B", "BT", "BAT")
13798
@polarized
13899
@no_ambiguous

schemascii/components/inductor.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from cmath import phase, rect
2+
3+
import schemascii.components as _c
4+
import schemascii.data_consumer as _dc
5+
import schemascii.utils as _utils
6+
7+
8+
class Inductor(_c.PolarizedTwoTerminalComponent, _c.SimpleComponent,
9+
ids=("L",), namespaces=(":inductor",)):
10+
options = [
11+
"inherit",
12+
_dc.Option("value", str, "Inductance in henries"),
13+
_dc.Option("current", str, "Maximum current rating in amps", None)
14+
]
15+
16+
@property
17+
def value_format(self):
18+
return [("value", "H", False, self.is_variable),
19+
("current", "A", False)]
20+
21+
def render(self, **options) -> str:
22+
t1, t2 = self.terminals[0].pt, self.terminals[1].pt
23+
vec = t1 - t2
24+
length = abs(vec)
25+
angle = phase(vec)
26+
scale = options["scale"]
27+
data = f"M{t1.real * scale} {t1.imag * scale}"
28+
d = rect(scale, angle)
29+
for _ in range(int(length)):
30+
data += f"a1 1 0 01 {-d.real} {d.imag}"
31+
return (
32+
_utils.XML.path(d=data, stroke=options["stroke"],
33+
fill="transparent",
34+
stroke__width=options["stroke_width"])
35+
+ self.format_id_text(
36+
_utils.make_text_point(t1, t2, **options), **options))
37+
38+
39+
class VariableInductor(Inductor, ids=("VL", "LV")):
40+
is_variable = True
41+
42+
def render(self, **options):
43+
t1, t2 = self.terminals[0].pt, self.terminals[1].pt
44+
return (super().render(**options)
45+
+ _utils.make_variable(
46+
(t1 + t2) / 2, phase(t1 - t2), **options))

scripts/docs.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
import re
33
import os
44
from itertools import groupby
5-
from schemascii.components_render import RENDERERS
65

7-
# pylint: disable=unspecified-encoding,missing-function-docstring,invalid-name
8-
# pylint: disable=not-an-iterable
9-
# cSpell:ignore siht etareneg redner iicsa stpircs nettirwrevo ylpmis segnahc
10-
# cSpell:ignore mehcs daetsn detareneg yllacitamotua codc stnenopmoc lliw ruo
11-
# cSpell:ignore sgnirtscod
6+
raise NotImplementedError("TODO: re-write docs generator script "
7+
"after I re-do the cmdline help text")
128

139
TOP = ("# Supported Schemascii Components\n\n<!--\n"
1410
+ "".join(reversed("/stpircs nur dna\nyp.redner_stnenopmoc/iicsa"

0 commit comments

Comments
 (0)