def add_arc(ctr, pos, angle, layer='Edge.Cuts', width=2): pnt_ctr = pnt.to_unit(vec2.round(ctr, PointDigits), UnitMM) pnt_pos = pnt.to_unit(vec2.round(pos, PointDigits), UnitMM) arc = pcbnew.DRAWSEGMENT() arc.SetShape(pcbnew.S_ARC) arc.SetCenter(pnt_ctr) arc.SetArcStart(pnt_pos) arc.SetAngle(10 * angle) arc.SetLayer(pcb.GetLayerID(layer)) arc.SetWidth(scalar_to_unit(width, UnitMM)) pcb.Add(arc) return arc
def add_track(a, b, net, layer, width): pnt_a = pnt.to_unit(vec2.round(a, PointDigits), UnitMM) pnt_b = pnt.to_unit(vec2.round(b, PointDigits), UnitMM) track = pcbnew.TRACK(pcb) track.SetStart(pnt_a) track.SetEnd(pnt_b) if net != None: track.SetNet(net) track.SetLayer(layer) track.SetWidth(scalar_to_unit(width, UnitMM)) track.SetLocked(True) pcb.Add(track) return track
def add_arc2(ctr, pos, end, angle, layer='Edge.Cuts', width=2): pnt_ctr = pnt.to_unit(vec2.round(ctr, PointDigits), UnitMM) pnt_pos = pnt.to_unit(vec2.round(pos, PointDigits), UnitMM) pnt_end = pnt.to_unit(vec2.round(end, PointDigits), UnitMM) arc = pcbnew.DRAWSEGMENT() arc.SetShape(pcbnew.S_ARC) arc.SetCenter(pnt_ctr) arc.SetArcStart(pnt_pos) arc.SetAngle(10 * angle) arc.SetLayer(pcb.GetLayerID(layer)) arc.SetWidth(scalar_to_unit(width, UnitMM)) pcb.Add(arc) arc_start = arc.GetArcStart() arc_end = arc.GetArcEnd() if arc_start[0] != pnt_pos[0] or arc_start[1] != pnt_pos[1]: print('add_arc2: arc_start != pnt_pos !!') if arc_end[0] != pnt_end[0] or arc_end[1] != pnt_end[1]: #print( 'arc_end != pnt_end !!' ) add_line_rawunit(arc_end, pnt_end, layer, width) return arc
def add_line(a, b, layer='Edge.Cuts', width=2): pnt_a = pnt.to_unit(vec2.round(a, PointDigits), UnitMM) pnt_b = pnt.to_unit(vec2.round(b, PointDigits), UnitMM) if True: aa = pnt.from_unit(pnt_a, UnitMM) bb = pnt.from_unit(pnt_b, UnitMM) length = vec2.distance(bb, aa) if length == 0: print("add_line: identical", a) return elif length < 0.001: #print( length, a, b ) None line = pcbnew.DRAWSEGMENT() line.SetStart(pnt_a) line.SetEnd(pnt_b) line.SetLayer(pcb.GetLayerID(layer)) line.SetWidth(scalar_to_unit(width, UnitMM)) pcb.Add(line) return line
def add_zone(rect, layer, idx=0, net_name='GND'): pnts = map(lambda pt: pnt.to_unit(vec2.round(pt, PointDigits), UnitMM), rect) net = pcb.FindNet(net_name).GetNet() zone = pcb.InsertArea(net, idx, layer, pnts[0][0], pnts[0][1], pcbnew.ZONE_CONTAINER.DIAGONAL_EDGE) poly = zone.Outline() for idx, pt in enumerate(pnts): if idx == 0: continue poly.Append(pt[0], pt[1]) return zone, poly
def add_via(pos, net, size): # size [mm] pnt_ = pnt.to_unit(vec2.round(pos, PointDigits), UnitMM) via = pcbnew.VIA(pcb) via.SetPosition(pnt_) via.SetWidth(pcbnew.FromMM(size[0])) via.SetDrill(pcbnew.FromMM(size[1])) via.SetNet(net) #print( net.GetNetname() ) via.SetLayerPair(pcb.GetLayerID('F.Cu'), pcb.GetLayerID('B.Cu')) via.SetLocked(True) pcb.Add(via) return via
def add_text(pos, angle, string, layer='F.SilkS', size=(1, 1), thick=5, hjustify=None, vjustify=None): text = pcbnew.TEXTE_PCB(pcb) text.SetPosition(pnt.to_unit(vec2.round(pos, PointDigits), UnitMM)) text.SetTextAngle(angle * 10) text.SetText(string) text.SetLayer(pcb.GetLayerID(layer)) text.SetTextSize(pcbnew.wxSizeMM(size[0], size[1])) text.SetThickness(scalar_to_unit(thick, UnitMM)) text.SetMirrored(layer[0] == 'B') if hjustify != None: text.SetHorizJustify(hjustify) if vjustify != None: text.SetVertJustify(vjustify) pcb.Add(text) return text
def set_mod_pos_angle(mod_name, pos, angle): mod = get_mod(mod_name) if pos != None: mod.SetPosition(pnt.to_unit(vec2.round(pos, PointDigits), UnitMM)) mod.SetOrientation(10 * angle) return mod