@@ -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
9194def 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
0 commit comments