Skip to content

Commit 6202262

Browse files
add support for variable components
1 parent 5856e3f commit 6202262

File tree

4 files changed

+51
-36
lines changed

4 files changed

+51
-36
lines changed

designators.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(copied from <https://en.wikipedia.org/wiki/Reference_designator>)
1+
(copied from <https://en.wikipedia.org/wiki/Reference_designator> and edited lightly)
22

33
| Designator | Component type | Implemented? |
44
|:--:|:--|:--:|
@@ -8,6 +8,7 @@
88
| B, BT, BAT | Battery | Yes |
99
| BR | Bridge rectifier ||
1010
| C | Capacitor | Yes |
11+
| CV, VC | Variable capacitor | Yes |
1112
| CN | Connector ||
1213
| CRT | Cathode ray tube ||
1314
| D, LED, CR | Diode (all types, including LED), thyristor | Yes |
@@ -40,7 +41,6 @@
4041
| MCB | Miniature circuit breaker ||
4142
| MIC, MK | Microphone ||
4243
| MOSFET | Metal-oxide-semiconductor field-effect transistor ||
43-
| MOV | Metal-oxide varistor ||
4444
| MP | Mechanical part (including screws and fasteners) ||
4545
| NE | Neon lamp ||
4646
| OP | Opto-isolator ||
@@ -51,9 +51,9 @@
5151
| PU | Pickup ||
5252
| Q | Transistor (all types) ||
5353
| R | Resistor | Yes |
54+
| RV, VR | Variable resistor (potentiometer or rheostat) | Yes |
5455
| RN | Resistor network ||
5556
| RT | Thermistor ||
56-
| RV | Varistor, Variable resistor ||
5757
| S, SW | Switch (all types, including buttons) ||
5858
| SCR | Silicon-controlled rectifier ||
5959
| SUS | Silicon unilateral switch ||
@@ -64,10 +64,8 @@
6464
| TP | Test point ||
6565
| TUN | Tuner ||
6666
| V | Vacuum tube ||
67-
| VC | Variable capacitor ||
68-
| VDR | Voltage-dependent resistor ||
67+
| VDR, MOV | Voltage-dependent resistor (varistor) ||
6968
| VFD | Vacuum fluorescent display ||
70-
| VR | Voltage regulator (voltage reference), Variable resistor (potentiometer or rheostat) ||
7169
| VT | Voltage transformer ||
72-
| W | Wire ||
70+
| W | Wire | (implicit) |
7371
| X, XTAL, Y | Crystal oscillator, ceramic resonator ||

schemascii/components_render.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from math import pi
44
from utils import (Cbox, Terminal, BOMData, XML, Side,
55
polylinegon, id_text, make_text_point,
6-
bunch_o_lines, deep_transform, make_plus)
6+
bunch_o_lines, deep_transform, make_plus, make_variable)
77
from metric import format_metric_unit
88

99
RENDERERS = {}
@@ -79,7 +79,7 @@ def sort_terminals(
7979
return sort_terminals
8080

8181

82-
@component("R")
82+
@component("R", "RV", "VR")
8383
@n_terminal(2)
8484
@no_ambiguous
8585
def resistor(
@@ -90,6 +90,7 @@ def resistor(
9090
"Draw a resistor"
9191
t1, t2 = terminals[0].pt, terminals[1].pt
9292
vec = t1 - t2
93+
mid = (t1 + t2) / 2
9394
length = abs(vec)
9495
angle = phase(vec)
9596
quad_angle = angle + pi / 2
@@ -99,13 +100,14 @@ def resistor(
99100
pow(-1, i) * rect(1, quad_angle) / 4)
100101
points.append(t2)
101102
text_pt = make_text_point(t1, t2, **kwargs)
102-
return (id_text(
103+
return (polylinegon(points, **kwargs)
104+
+ make_variable(mid, angle, "V" in box.type, **kwargs)
105+
+ id_text(
103106
box, bom_data, terminals, (("&ohm;", False), ("W", False)),
104-
text_pt, **kwargs)
105-
+ polylinegon(points, **kwargs))
107+
text_pt, **kwargs))
106108

107109

108-
@component("C")
110+
@component("C", "CV", "VC")
109111
@polarized
110112
@no_ambiguous
111113
def capacitor(
@@ -124,11 +126,12 @@ def capacitor(
124126
(complex(.4, -.25), complex(-.4, -.25)),
125127
], mid, angle)
126128
text_pt = make_text_point(t1, t2, **kwargs)
127-
return (id_text(
129+
return (bunch_o_lines(lines, **kwargs)
130+
+ make_plus(terminals, mid, angle, **kwargs)
131+
+ make_variable(mid, angle, "V" in box.type, **kwargs)
132+
+ id_text(
128133
box, bom_data, terminals, (("F", True), ("V", False)),
129-
text_pt, **kwargs)
130-
+ bunch_o_lines(lines, **kwargs)
131-
+ make_plus(terminals, mid, angle, **kwargs))
134+
text_pt, **kwargs))
132135

133136

134137
@component("B", "BT", "BAT")
@@ -185,7 +188,7 @@ def diode(
185188
Side.RIGHT: pi,
186189
Side.TOP: pi / 2,
187190
Side.LEFT: 0,
188-
Side.RIGHT: 3 * pi / 2,
191+
Side.BOTTOM: 3 * pi / 2,
189192
}
190193

191194

schemascii/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,19 @@ def make_plus(
200200
[(.125, -.125), (.125j, -.125j)], 0, theta),
201201
center + deep_transform(.33+.75j, 0, theta), 0), **kwargs),
202202
class_="plus")
203+
204+
205+
def make_variable(
206+
center: complex,
207+
theta: float,
208+
is_variable: bool = True,
209+
**options) -> str:
210+
"Draw a 'variable' arrow across the component."
211+
if not is_variable:
212+
return ""
213+
theta = theta % pi
214+
return bunch_o_lines(deep_transform([
215+
(-.75+.5j, .75-.5j),
216+
(.75-.5j, .5-.55j),
217+
(.75-.5j, .7-.25j),
218+
], center, theta), **options)

test_data/test_resistors.txt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
*-------------------------------#B.Foo
2-
| +
1+
*--------------------------------*
2+
| |
33
*---+D1--+LED1--* D1:2N7001 +
4-
| LED1:red B1
5-
*--------* |B1:5V,100m
6-
| |
7-
R4 R4:.3k *-----------* C3:2200u,2.5
8-
| |
9-
*---R.Heater--|---* R.Heater:0.0081K,0.5K
10-
| | | R3:2000
11-
*----R3-------|---*-------*
12-
| |
13-
*--------------*-----C3+---*
14-
a
4+
| | LED1:red B1
5+
| *--------* |B1:3.7V,6
6+
| | |
7+
| R4 R4:.3k *-----------* C3:2200u,2.5
8+
| | |
9+
| *---R.Heater--|---* R.Heater:0.0081K,0.5K
10+
| | | | VR3:2000
11+
| *----VR3------|---*-------*
12+
| | |
13+
| *--------------*-----C3+---*
14+
| 2 |
15+
| .~~~. *----CV1 CV1:5p
16+
*--1:U1 :3-----*
1517
.~~~.
16-
---d:U1 :b---
17-
.~~~.
18-
c
19-
|
20-
U1:RAND04
18+
U1:7805

0 commit comments

Comments
 (0)