@@ -88,6 +88,9 @@ def sort_terminals(
88
88
return sort_terminals
89
89
90
90
91
+ @component ("R" , "RV" , "VR" )
92
+ @n_terminal (2 )
93
+ @no_ambiguous
91
94
def resistor (
92
95
box : Cbox ,
93
96
terminals : list [Terminal ],
@@ -106,16 +109,11 @@ def resistor(
106
109
points .append (t1 - rect (i / 4 , angle ) +
107
110
pow (- 1 , i ) * rect (1 , quad_angle ) / 4 )
108
111
points .append (t2 )
109
- text_pt = make_text_point (t1 , t2 , ** options )
110
112
return (polylinegon (points , ** options )
111
113
+ make_variable (mid , angle , "V" in box .type , ** options )
112
114
+ id_text (
113
115
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 ))
119
117
120
118
121
119
@component ("C" , "CV" , "VC" )
@@ -138,13 +136,42 @@ def capacitor(
138
136
(complex (.4 , .25 ), complex (- .4 , .25 )),
139
137
(complex (.4 , - .25 ), complex (- .4 , - .25 )),
140
138
], mid , angle )
141
- text_pt = make_text_point (t1 , t2 , ** options )
142
139
return (bunch_o_lines (lines , ** options )
143
140
+ make_plus (terminals , mid , angle , ** options )
144
141
+ make_variable (mid , angle , "V" in box .type , ** options )
145
142
+ id_text (
146
143
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 ))
148
175
149
176
150
177
@component ("B" , "BT" , "BAT" )
@@ -169,10 +196,9 @@ def battery(
169
196
(complex (.5 , - .16 ), complex (- .5 , - .16 )),
170
197
(complex (.25 , - .5 ), complex (- .25 , - .5 )),
171
198
], mid , angle )
172
- text_pt = make_text_point (t1 , t2 , ** options )
173
199
return (id_text (
174
200
box , bom_data , terminals , (("V" , False ), ("Ah" , False )),
175
- text_pt , ** options )
201
+ make_text_point ( t1 , t2 , ** options ) , ** options )
176
202
+ bunch_o_lines (lines , ** options ))
177
203
178
204
@@ -195,12 +221,13 @@ def diode(
195
221
(t1 , mid + rect (- .3 , angle )),
196
222
deep_transform ((- .3 - .3j , .3 - .3j ), mid , angle )]
197
223
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 {}
200
226
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 ))
204
231
+ polylinegon (triangle , True , ** options ))
205
232
206
233
@@ -337,7 +364,7 @@ def transistor(
337
364
# x = (m^2 x1 - m y1 + m y2 + x2)/(m^2 + 1)
338
365
slope = diff .imag / diff .real
339
366
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 )
341
368
mid = complex (mid_x , slope * (mid_x - ap .real ) + ap .imag )
342
369
theta = phase (ap - sp )
343
370
backwards = 1 if is_clockwise ([ae , se , ctl ]) else - 1
@@ -371,8 +398,8 @@ def transistor(
371
398
mid - rect (1 , theta ) + rect (1 , thetaquarter )),
372
399
])
373
400
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 )
376
403
+ bunch_o_lines (out_lines , ** options ))
377
404
378
405
# code for drawing stuff
@@ -390,10 +417,6 @@ def transistor(
390
417
'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' ,
391
418
# jumper pads
392
419
'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',
397
420
# loudspeaker
398
421
'LS' : 'M0-1V-.5H-.25V.5H.25V-.5H0M0 1V.5ZM1-1 .25-.5V.5L1 1Z' ,
399
422
# electret mic
0 commit comments