@@ -50,10 +50,12 @@ def de_ambiguous(
50
50
if len (bom_data ) > 1 :
51
51
raise BOMError (
52
52
f"Ambiguous BOM data for { box .type } { box .id } : { bom_data !r} " )
53
+ if not bom_data :
54
+ bom_data = [BOMData (box .type , box .id , "" )]
53
55
return func (
54
56
box ,
55
57
terminals ,
56
- bom_data [0 ] if bom_data else None ,
58
+ bom_data [0 ],
57
59
** options )
58
60
return de_ambiguous
59
61
@@ -86,7 +88,7 @@ def sort_terminals(
86
88
def resistor (
87
89
box : Cbox ,
88
90
terminals : list [Terminal ],
89
- bom_data : BOMData | None ,
91
+ bom_data : BOMData ,
90
92
** options ):
91
93
"Draw a resistor"
92
94
t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -114,7 +116,7 @@ def resistor(
114
116
def capacitor (
115
117
box : Cbox ,
116
118
terminals : list [Terminal ],
117
- bom_data : BOMData | None ,
119
+ bom_data : BOMData ,
118
120
** options ):
119
121
"Draw a capacitor"
120
122
t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -141,7 +143,7 @@ def capacitor(
141
143
def battery (
142
144
box : Cbox ,
143
145
terminals : list [Terminal ],
144
- bom_data : BOMData | None ,
146
+ bom_data : BOMData ,
145
147
** options ):
146
148
"Draw a battery cell"
147
149
t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -168,7 +170,7 @@ def battery(
168
170
def diode (
169
171
box : Cbox ,
170
172
terminals : list [Terminal ],
171
- bom_data : BOMData | None ,
173
+ bom_data : BOMData ,
172
174
** options ):
173
175
"Draw a diode or LED"
174
176
t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -198,13 +200,14 @@ def diode(
198
200
def integrated_circuit (
199
201
box : Cbox ,
200
202
terminals : list [Terminal ],
201
- bom_data : BOMData | None ,
203
+ bom_data : BOMData ,
202
204
** options ):
203
205
"Draw an IC"
204
206
label_style = options ["label" ]
205
207
scale = options ["scale" ]
206
208
sz = (box .p2 - box .p1 ) * scale
207
209
mid = (box .p2 + box .p1 ) * scale / 2
210
+ part_num , * pin_labels = map (str .strip , bom_data .data .split ("," ))
208
211
out = XML .rect (
209
212
x = box .p1 .real * scale ,
210
213
y = box .p1 .imag * scale ,
@@ -218,20 +221,59 @@ def integrated_circuit(
218
221
term .pt ,
219
222
term .pt + rect (1 , SIDE_TO_ANGLE_MAP [term .side ])
220
223
)], ** options )
221
- out += XML .text (
222
- (XML .tspan (f"{ box .type } { box .id } " , class_ = "cmp-id" )
223
- * bool ("L" in label_style )),
224
- " " * (bool (bom_data .data ) and "L" in label_style ),
225
- XML .tspan (bom_data .data , class_ = "part-num" ) * bool ("V" in label_style ),
226
- x = mid .real ,
227
- y = mid .imag ,
228
- text__anchor = "middle" ,
229
- font__size = options ["scale" ],
230
- fill = options ["stroke" ])
224
+ if "V" in label_style :
225
+ out += XML .text (
226
+ XML .tspan (part_num , class_ = "part-num" ),
227
+ x = mid .real ,
228
+ y = mid .imag ,
229
+ text__anchor = "middle" ,
230
+ font__size = options ["scale" ],
231
+ fill = options ["stroke" ])
232
+ mid -= 1j * scale
233
+ if "L" in label_style and not options ["nolabels" ]:
234
+ out += XML .text (
235
+ XML .tspan (f"{ box .type } { box .id } " , class_ = "cmp-id" ),
236
+ x = mid .real ,
237
+ y = mid .imag ,
238
+ text__anchor = "middle" ,
239
+ font__size = options ["scale" ],
240
+ fill = options ["stroke" ])
231
241
warn ("ICs are not fully implemented yet." )
232
242
return out
233
243
234
- # code for drawing
244
+
245
+ @component ("J" , "P" )
246
+ @n_terminal (1 )
247
+ @no_ambiguous
248
+ def jack (
249
+ box : Cbox ,
250
+ terminals : list [Terminal ],
251
+ bom_data : BOMData ,
252
+ ** options ):
253
+ "Draw a jack connector or plug"
254
+ scale = options ["scale" ]
255
+ sc_t1 = terminals [0 ].pt * scale
256
+ sc_t2 = sc_t1 + rect (scale , SIDE_TO_ANGLE_MAP [terminals [0 ].side ])
257
+ sc_text_pt = sc_t2 + rect (scale * 2 , SIDE_TO_ANGLE_MAP [terminals [0 ].side ])
258
+ return (
259
+ XML .line (
260
+ x1 = sc_t1 .real ,
261
+ x2 = sc_t2 .real ,
262
+ y1 = sc_t1 .imag ,
263
+ y2 = sc_t2 .imag ,
264
+ stroke__width = options ["stroke_width" ],
265
+ stroke = options ["stroke" ])
266
+ + XML .circle (
267
+ cx = sc_t2 .real ,
268
+ cy = sc_t2 .imag ,
269
+ r = scale / 4 ,
270
+ stroke__width = options ["stroke_width" ],
271
+ stroke = options ["stroke" ],
272
+ fill = "none" )
273
+ + id_text (box , bom_data , terminals , None , sc_text_pt , ** options ))
274
+
275
+
276
+ # code for drawing stuff
235
277
# https://github.com/pfalstad/circuitjs1/tree/master/src/com/lushprojects/circuitjs1/client
236
278
# https://github.com/KenKundert/svg_schematic/blob/0abb5dc/svg_schematic.py
237
279
# https://yqnn.github.io/svg-path-editor/
0 commit comments