@@ -50,10 +50,12 @@ def de_ambiguous(
5050 if len (bom_data ) > 1 :
5151 raise BOMError (
5252 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 , "" )]
5355 return func (
5456 box ,
5557 terminals ,
56- bom_data [0 ] if bom_data else None ,
58+ bom_data [0 ],
5759 ** options )
5860 return de_ambiguous
5961
@@ -86,7 +88,7 @@ def sort_terminals(
8688def resistor (
8789 box : Cbox ,
8890 terminals : list [Terminal ],
89- bom_data : BOMData | None ,
91+ bom_data : BOMData ,
9092 ** options ):
9193 "Draw a resistor"
9294 t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -114,7 +116,7 @@ def resistor(
114116def capacitor (
115117 box : Cbox ,
116118 terminals : list [Terminal ],
117- bom_data : BOMData | None ,
119+ bom_data : BOMData ,
118120 ** options ):
119121 "Draw a capacitor"
120122 t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -141,7 +143,7 @@ def capacitor(
141143def battery (
142144 box : Cbox ,
143145 terminals : list [Terminal ],
144- bom_data : BOMData | None ,
146+ bom_data : BOMData ,
145147 ** options ):
146148 "Draw a battery cell"
147149 t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -168,7 +170,7 @@ def battery(
168170def diode (
169171 box : Cbox ,
170172 terminals : list [Terminal ],
171- bom_data : BOMData | None ,
173+ bom_data : BOMData ,
172174 ** options ):
173175 "Draw a diode or LED"
174176 t1 , t2 = terminals [0 ].pt , terminals [1 ].pt
@@ -198,13 +200,14 @@ def diode(
198200def integrated_circuit (
199201 box : Cbox ,
200202 terminals : list [Terminal ],
201- bom_data : BOMData | None ,
203+ bom_data : BOMData ,
202204 ** options ):
203205 "Draw an IC"
204206 label_style = options ["label" ]
205207 scale = options ["scale" ]
206208 sz = (box .p2 - box .p1 ) * scale
207209 mid = (box .p2 + box .p1 ) * scale / 2
210+ part_num , * pin_labels = map (str .strip , bom_data .data .split ("," ))
208211 out = XML .rect (
209212 x = box .p1 .real * scale ,
210213 y = box .p1 .imag * scale ,
@@ -218,20 +221,59 @@ def integrated_circuit(
218221 term .pt ,
219222 term .pt + rect (1 , SIDE_TO_ANGLE_MAP [term .side ])
220223 )], ** 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" ])
231241 warn ("ICs are not fully implemented yet." )
232242 return out
233243
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
235277# https://github.com/pfalstad/circuitjs1/tree/master/src/com/lushprojects/circuitjs1/client
236278# https://github.com/KenKundert/svg_schematic/blob/0abb5dc/svg_schematic.py
237279# https://yqnn.github.io/svg-path-editor/
0 commit comments