def draw_radial(i_hand, i_ring, theta, rad_ofs, theta_ofs): if i_hand == 0: outerRad = outerViaRad else: outerRad = diodeRad ringRad = outerRingRad - (i_ring - 1) * ringSpacing track = pcbnew.TRACK(board) track.SetStart(polar(ringRad, theta)) track.SetEnd(polar(outerRad + rad_ofs, theta)) track.SetWidth(ringWidth * mil) track.SetLayer(layerTable["B.Cu"]) net = board.GetNetsByName()["/Q%02d" % i_ring] board.Add(track) track.SetNet(net) via = pcbnew.VIA(board) via.SetLayerPair(layerTable["F.Cu"], layerTable["B.Cu"]) via.SetPosition(polar(ringRad, theta)) board.Add(via) via.SetNet(net) if i_hand == 0: via = pcbnew.VIA(board) via.SetLayerPair(layerTable["F.Cu"], layerTable["B.Cu"]) via.SetPosition(polar(outerRad + rad_ofs, theta)) board.Add(via) via.SetNet(net) track = pcbnew.TRACK(board) track.SetStart(polar(diodeRad, theta + theta_ofs)) track.SetEnd(polar(outerRad + rad_ofs, theta)) track.SetWidth(ringWidth * mil) track.SetLayer(layerTable["F.Cu"]) net = board.GetNetsByName()["/Q%02d" % i_ring] board.Add(track) track.SetNet(net)
def add_track_via(self, coord, layer_pair=('B.Cu', 'F.Cu'), size=None, drill=None): """Create a via on the board Args: coord: Position of the via layer_pair: Tuple of the connected layers (for example ('B.Cu', 'F.Cu')) size: size of via in mm, or None for current selection drill: size of drill in mm, or None for current selection """ if size == None: size = self._board.GetDesignSettings().GetCurrentViaSize() else: size = _to_iu(size) if drill == None: drill = self._board.GetDesignSettings().GetCurrentViaDrill() else: drill = _to_iu(drill) via = pcbnew.VIA(self._board) #via.SetFlags( IS_NEW ) #via.SetViaType( GetDesignSettings().m.CurrentViaType ) via.SetWidth(size) #via.SetNetCode( GetBoard()->GetHighLightNetCode() ) via.SetEnd(_to_wxpoint(coord[0], coord[1])) via.SetStart(_to_wxpoint(coord[0], coord[1])) via.SetLayerPair(_get_layer(layer_pair[0]), _get_layer(layer_pair[1])) via.SetDrill(drill) self._board.Add(via) return via
def add_via(self, pos=[0, 0], layerIdPair=(0, 31), netName="/GND", size=None, drill=None, vType=pcbnew.VIA_THROUGH): netcode = self._board.GetNetcodeFromNetname(netName) if size == None: size = self._board.GetDesignSettings().GetCurrentViaSize() if drill == None: drill = self._board.GetDesignSettings().GetCurrentViaDrill() if vType == pcbnew.VIA_THROUGH: via = pcbnew.VIA(self._board) via.SetWidth(size) p1 = pcbnew.wxPoint( pos[0], pos[1]) if type(pos) == tuple or type(pos) == list else pos via.SetStart(p1) via.SetEnd(p1) via.SetLayerPair(layerIdPair[0], layerIdPair[1]) via.SetDrill(drill) via.SetViaType(pcbnew.VIA_THROUGH) self._board.Add(via) via.SetNetCode(netcode)
def newVia(board, pos): t = pcbnew.VIA(board) t.SetPosition(pos) t.SetDrillDefault() t.SetWidth(fromMm(1)) board.Add(t) return t
def add_via(position, net): via = pcbnew.VIA(board._obj) via.SetPosition(position) via.SetLayerPair(layertable["F.Cu"], layertable["B.Cu"]) via.SetDrill(int(0.254 * pcbnew.IU_PER_MM)) via.SetWidth(int(0.4064 * pcbnew.IU_PER_MM)) via.SetNet(net) print("Adding via on net %s at %s" % (net.GetNetname(), str(position))) board._obj.Add(via)
def make_via(self, position, net_code): v = pcb.VIA(self.board) self.board.Add(v) v.SetPosition(position) v.SetViaType(pcb.VIA_THROUGH) v.SetLayerPair(LayerFCu, LayerBCu) v.SetNetCode(net_code) v.SetWidth(pcb.FromMM(DEFAULT_TRACK_WIDTH_MM)) return position
def draw_via(pos, layer, net, diameter=0.8 * SCALE, drill=0.4 * SCALE): via = pcbnew.VIA(board) via.SetPosition(pos) via.SetLayer(layer) via.SetWidth(int(diameter)) via.SetDrill(int(drill)) board.Add(via) via.SetNet(net) return via
def via(p1, width=600000): pcb = pcbnew.GetBoard() v = pcbnew.VIA(pcb) pcb.Add(v) v.SetPosition(p1) v.SetLayerPair(pcbnew.F_Cu, pcbnew.B_Cu) v.SetWidth(width) return v
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 _conv_via(via, net_code): v = pcb.VIA(pcb.GetBoard()) v.SetPosition(ToPCB._conv_point(via.position)) v.SetViaType(pcb.VIA_THROUGH) v.SetLayerPair(cad.Layer.F_Cu, cad.Layer.B_Cu) v.SetNetCode(net_code) if via.diameter is not None: v.SetWidth(via.diameter) if via.drill_diameter is not None: v.SetDrill(via.drill_diameter) # v.SetWidth(pcb.FromMM(DEFAULT_TRACK_WIDTH_MM)) pcb.GetBoard().Add(v)
def create_via(board, net, pt): newvia = pcbnew.VIA(board) # need to add before SetNet will work, so just doing it first board.Add(newvia) toplayer = layertable['F.Cu'] bottomlayer = layertable['B.Cu'] newvia.SetNet(net) nc = net.GetNetClass() newvia.SetWidth(nc.GetViaDiameter()) newvia.SetPosition(pcbnew.wxPoint(*pt)) newvia.SetLayerPair(toplayer, bottomlayer) newvia.SetViaType(pcbnew.VIA_THROUGH)
def replicate_tracks(self, x_offset, y_offset): """ method which replicates tracks""" global SCALE # start cloning for sheet in self.sheets_to_clone: sheet_index = self.sheets_to_clone.index(sheet) + 1 net_pairs, net_dict = self.get_net_pairs(sheet) # go through all the tracks for track in self.pivot_tracks: # get from which net we are clonning from_net_name = track.GetNetname() # find to net to_net_name = [item for item in net_pairs if item[0] == from_net_name][0][1] to_net = net_dict[to_net_name] # finally make a copy # this came from Miles Mccoo # https://github.com/mmccoo/kicad_mmccoo/blob/master/replicatelayout/replicatelayout.py if track.GetClass() == "VIA": oldvia = self.board.GetViaByPosition(track.GetPosition()) newvia = pcbnew.VIA(self.board) # need to add before SetNet will work, so just doing it first self.board.Add(newvia) toplayer = -1 bottomlayer = pcbnew.PCB_LAYER_ID_COUNT for l in range(pcbnew.PCB_LAYER_ID_COUNT): if not track.IsOnLayer(l): continue toplayer = max(toplayer, l) bottomlayer = min(bottomlayer, l) newvia.SetLayerPair(toplayer, bottomlayer) newvia.SetPosition(pcbnew.wxPoint(track.GetPosition().x + sheet_index*x_offset*SCALE, track.GetPosition().y + sheet_index*y_offset*SCALE)) newvia.SetViaType(oldvia.GetViaType()) newvia.SetWidth(oldvia.GetWidth()) newvia.SetNet(to_net) else: newtrack = pcbnew.TRACK(self.board) # need to add before SetNet will work, so just doing it first self.board.Add(newtrack) newtrack.SetStart(pcbnew.wxPoint(track.GetStart().x + sheet_index*x_offset*SCALE, track.GetStart().y + sheet_index*y_offset*SCALE)) newtrack.SetEnd(pcbnew.wxPoint(track.GetEnd().x + sheet_index*x_offset*SCALE, track.GetEnd().y + sheet_index*y_offset*SCALE)) newtrack.SetWidth(track.GetWidth()) newtrack.SetLayer(track.GetLayer()) newtrack.SetNet(to_net) pass
def add_vias(): board = pcbnew.GetBoard() layertable = get_layertable() layertable = get_layertable() for x in range(0, 10 * SCALE, SCALE * 2): for y in range(0, 10 * SCALE, SCALE * 2): newvia = pcbnew.VIA(board) board.Add(newvia) newvia.SetLayerPair(layertable["F.Cu"], layertable["B.Cu"]) newvia.SetPosition(pcbnew.wxPoint(x, y)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1 * SCALE) pcbnew.Refresh()
def FillupArea(self): '''Fills selected area with vias.''' drillsize = self.FromUserUnit(float(self.m_txtViaDrillSize.GetValue())) viasize = self.FromUserUnit(float(self.m_txtViaSize.GetValue())) step_x = self.FromUserUnit(float(self.m_txtHSpacing.GetValue())) step_y = self.FromUserUnit(float(self.m_txtVSpacing.GetValue())) clearance = self.FromUserUnit(float(self.m_txtClearance.GetValue())) bbox = self.area.GetBoundingBox() top = bbox.GetTop() bottom = bbox.GetBottom() right = bbox.GetRight() left = bbox.GetLeft() netname = self.m_cbNet.GetStringSelection() netcode = self.board.GetNetcodeFromNetname(netname) #commit = pcbnew.COMMIT() viacount = 0 x = left #Cycle trough area bounding box checking and implanting vias layer = self.area.GetLayer() while x <= right: y = top while y <= bottom: p = pcbnew.wxPoint(x,y) if self.area.HitTestInsideZone(p): via = pcbnew.VIA(self.board) via.SetPosition(p) via.SetLayer(layer) via.SetNetCode(netcode) via.SetDrill(drillsize) via.SetWidth(viasize) via.SetTimeStamp(__timecode__) if not self.CheckOverlap(via): #Check clearance only if clearance value differs from 0 (disabled) if (clearance == 0) or self.CheckClearance(p, self.area, clearance): self.board.Add(via) #commit.Add(via) viacount +=1 y += step_y x += step_x if viacount > 0: wx.MessageBox(_(u"Implanted: %d vias!") % viacount) #commit.Push() pcbnew.Refresh() else: wx.MessageBox(_(u"No vias implanted!"))
def createVias(self, viaPoints, viaDrill, viaSize, netCode): newVias = [] for viaPoint in viaPoints: newVia = pcbnew.VIA(self.boardObj) ts = 55 newVia.SetTimeStamp( ts ) # adding a unique number as timestamp to mark this via as generated by this script self.boardObj.Add(newVia) newVia.SetPosition(pcbnew.wxPoint(viaPoint[0], viaPoint[1])) newVia.SetWidth(viaSize) newVia.SetDrill(viaDrill) newVia.SetViaType(pcbnew.VIA_THROUGH) newVia.SetNetCode(netCode) newVias += [newVia] return newVias
def GroundVias(nets, modules): board = pcbnew.GetBoard() # this blog argues what I'm doing here it bad: # http://www.johngineer.com/blog/?p=1319 # generate a name->layer table so we can lookup layer numbers by name. layertable = {} numlayers = pcbnew.PCB_LAYER_ID_COUNT for i in range(numlayers): layertable[pcbnew.GetBoard().GetLayerName(i)] = i modules = set(modules) nettable = board.GetNetsByName() netcodes = set() for name in nets: if (name in nettable): netcodes.add(nettable[name].GetNet()) toplayer = layertable['F.Cu'] bottomlayer = layertable['B.Cu'] for mod in board.GetModules(): if (mod.GetReference() not in modules): continue for pad in mod.Pads(): netcode = pad.GetNetCode() if (netcode not in netcodes): continue newvia = pcbnew.VIA(board) # need to add before SetNet will work, so just doing it first board.Add(newvia) net = pad.GetNet() newvia.SetNet(net) nc = net.GetNetClass() newvia.SetWidth(nc.GetViaDiameter()) newvia.SetPosition(pad.GetCenter()) newvia.SetLayerPair(toplayer, bottomlayer) newvia.SetViaType(pcbnew.VIA_THROUGH)
def CreateSMTClone2(board, mod, footprintLib, footprintName): new_mod = pcbnew.PCB_IO().FootprintLoad(footprintLib, footprintName) new_mod.SetPosition(ModuleMidPoint(mod)) new_mod.SetOrientation(mod.GetOrientation()) new_mod.SetReference(mod.GetReference()) new_mod.SetValue(mod.GetValue()) new_mod.SetLocalClearance(mod.GetLocalClearance()) board.Add(new_mod) CopyText(mod.Reference(), new_mod.Reference()) CopyText(mod.Value(), new_mod.Value()) for newPad in new_mod.Pads(): oldPad = mod.FindPadByName(newPad.GetName()) net = oldPad.GetNet() newPad.SetNet(net) newPad.SetLocalClearance(oldPad.GetLocalClearance()) # Create via at some offset from the new pad in # the direction of the old pad. TRACK_WIDTH = int(12 * MIL) VIA_DISTANCE = int(30 * MIL) direction = Normalize(oldPad.GetPosition() - newPad.GetPosition()) offset = Scale(direction, VIA_DISTANCE) viaPos = newPad.GetPosition() + offset via = pcbnew.VIA(board) board.Add(via) via.SetPosition(viaPos) via.SetNet(net) via.SetWidth(net.GetNetClass().GetViaDiameter()) via.SetLayerPair(pcbnew.F_Cu, pcbnew.B_Cu) # Create track between new pad and the via. track = pcbnew.TRACK(board) board.Add(track) track.SetStart(newPad.GetPosition()) track.SetEnd(via.GetPosition()) track.SetNet(net) track.SetWidth(int(12 * MIL)) track.SetLayer(pcbnew.F_Cu) return new_mod
def viafy_area(area): #all_vias = [t for t in pcb.GetTracks() if t.GetClass() == 'VIA'] bb = area.GetBoundingBox() top = bb.GetTop() bottom = bb.GetBottom() left = bb.GetLeft() right = bb.GetRight() #netName = area.GetNetname() net = area.GetNet() #print net.GetNet() for x in range(left, right, x_interval): for y in range(top, bottom, y_interval): pt = pcbnew.wxPoint(x, y) if pcb.GetViaByPosition(pt): continue #print pt if area.HitTestFilledArea(pt): if not area.HitTestFilledArea( pcbnew.wxPoint(x - x_interval / 2, y)): continue if not area.HitTestFilledArea( pcbnew.wxPoint(x + x_interval / 2, y)): continue if not area.HitTestFilledArea( pcbnew.wxPoint(x, y - y_interval / 2)): continue if not area.HitTestFilledArea( pcbnew.wxPoint(x, y + y_interval / 2)): continue #print 'hittest yes' v = pcbnew.VIA(pcb) v.SetPosition(pt) v.SetDrill(v_diameter) v.SetWidth(v_diameter * 2) #v.SetNetname(netName) v.SetNetCode(net.GetNet()) pcb.Add(v)
def Run(self): #self.pcb = GetBoard() pcbObj = pcbnew.GetBoard() wx.LogMessage("ciao1") viaOffset = pcbnew.FromMM(2) viaPitch = pcbnew.FromMM(1) netId = pcbObj.GetHighLightNetCode() wx.LogMessage(str(netId)) layertable = {} numlayers = pcbnew.PCB_LAYER_ID_COUNT for i in range(numlayers): layertable[pcbnew.GetBoard().GetLayerName(i)] = i toplayer = layertable['F.Cu'] bottomlayer = layertable['B.Cu'] if (netId != -1): netTracks = pcbObj.TracksInNet(netId) wx.LogMessage("ciao1") trackList = [ [[t.GetStart()[0], t.GetStart()[1]], [t.GetEnd()[0], t.GetEnd()[1]]] for t in netTracks ] viaPoints = generateViaFence(trackList, viaOffset, viaPitch) for track in trackList: ## plt.plot(np.array(track).T[0], np.array(track).T[1], linewidth=1) #print track wx.LogMessage(str(track)) for via in viaPoints: ## plt.plot(via[0], via[1], 'o', markersize=10) newvia = pcbnew.VIA(pcbObj) pcbObj.Add(newvia) #newvia.SetNet(netId) #nc = net.GetNetClass() #newvia.SetWidth(nc.GetViaDiameter()) newvia.SetPosition(wxPoint(via[0],via[1])) #pad.GetCenter()) newvia.SetLayerPair(toplayer, bottomlayer) newvia.SetViaType(pcbnew.VIA_THROUGH) wx.LogMessage("via @: "+str(via[0])+";"+str(via[1])) #print via[0]; print via[1]) wx.LogMessage("ciao4")
def replicate_tracks(self, x_offset, y_offset, polar): """ method which replicates tracks""" global SCALE # start cloning for sheet in self.sheets_to_clone: sheet_index = self.sheets_to_clone.index(sheet) + 1 net_pairs, net_dict = self.get_net_pairs(sheet) # go through all the tracks for track in self.pivot_tracks: # get from which net we are clonning from_net_name = track.GetNetname() # find to net tup = [item for item in net_pairs if item[0] == from_net_name] # if net was not fount, then the track is not part of this sheet and should not be cloned if not tup: pass else: to_net_name = tup[0][1] to_net = net_dict[to_net_name] # finally make a copy # this came from Miles Mccoo, I only extended it with polar support # https://github.com/mmccoo/kicad_mmccoo/blob/master/replicatelayout/replicatelayout.py if track.GetClass() == "VIA": newvia = pcbnew.VIA(self.board) # need to add before SetNet will work, so just doing it first self.board.Add(newvia) toplayer = -1 bottomlayer = pcbnew.PCB_LAYER_ID_COUNT for l in range(pcbnew.PCB_LAYER_ID_COUNT): if not track.IsOnLayer(l): continue toplayer = max(toplayer, l) bottomlayer = min(bottomlayer, l) newvia.SetLayerPair(toplayer, bottomlayer) if polar: # get the pivot point pivot_point = (self.polar_center[0], self.polar_center[1] + x_offset * SCALE) newposition = rotate_around_pivot_point((track.GetPosition().x, track.GetPosition().y), pivot_point, sheet_index * y_offset) else: newposition = (track.GetPosition().x + sheet_index*x_offset*SCALE, track.GetPosition().y + sheet_index*y_offset*SCALE) # convert to tuple of integers newposition = [int(x) for x in newposition] newvia.SetPosition(pcbnew.wxPoint(*newposition)) newvia.SetViaType(track.GetViaType()) newvia.SetWidth(track.GetWidth()) newvia.SetDrill(track.GetDrill()) newvia.SetNet(to_net) else: newtrack = pcbnew.TRACK(self.board) # need to add before SetNet will work, so just doing it first self.board.Add(newtrack) if polar: # get the pivot point pivot_point = (self.polar_center[0], self.polar_center[1] + x_offset * SCALE) newposition = rotate_around_pivot_point((track.GetStart().x, track.GetStart().y), pivot_point, sheet_index * y_offset) # convert to tuple of integers newposition = [int(x) for x in newposition] newtrack.SetStart(pcbnew.wxPoint(*newposition)) newposition = rotate_around_pivot_point((track.GetEnd().x, track.GetEnd().y), pivot_point, sheet_index * y_offset) # convert to tuple of integers newposition = [int(x) for x in newposition] newtrack.SetEnd(pcbnew.wxPoint(*newposition)) else: newtrack.SetStart(pcbnew.wxPoint(track.GetStart().x + sheet_index*x_offset*SCALE, track.GetStart().y + sheet_index*y_offset*SCALE)) newtrack.SetEnd(pcbnew.wxPoint(track.GetEnd().x + sheet_index*x_offset*SCALE, track.GetEnd().y + sheet_index*y_offset*SCALE)) newtrack.SetWidth(track.GetWidth()) newtrack.SetLayer(track.GetLayer()) newtrack.SetNet(to_net)
def replicate_sheet_trackst(fromnet, tonet, offset): board = tonet.GetParent() # remove tonet's old routing for track in board.TracksInNet(tonet.GetNet()): board.Remove(track) for track in board.TracksInNet(fromnet.GetNet()): if track.GetClass() == "VIA": # cloning is an easier way, but I want to ensure I # can create a Via from scratch #newvia = track.Clone() oldvia = board.GetViaByPosition(track.GetPosition()) newvia = pcbnew.VIA(board) # need to add before SetNet will work, so just doing it first board.Add(newvia) toplayer = -1 bottomlayer = pcbnew.PCB_LAYER_ID_COUNT for l in range(pcbnew.PCB_LAYER_ID_COUNT): if not track.IsOnLayer(l): continue toplayer = max(toplayer, l) bottomlayer = min(bottomlayer, l) newvia.SetLayerPair(toplayer, bottomlayer) newvia.SetPosition( pcbnew.wxPoint(track.GetPosition().x + offset[0], track.GetPosition().y + offset[1])) newvia.SetViaType(oldvia.GetViaType()) newvia.SetWidth(oldvia.GetWidth()) newvia.SetNet(tonet) else: newtrack = pcbnew.TRACK(board) # need to add before SetNet will work, so just doing it first board.Add(newtrack) newtrack.SetStart( pcbnew.wxPoint(track.GetStart().x + offset[0], track.GetStart().y + offset[1])) newtrack.SetEnd( pcbnew.wxPoint(track.GetEnd().x + offset[0], track.GetEnd().y + offset[1])) newtrack.SetWidth(track.GetWidth()) newtrack.SetLayer(track.GetLayer()) newtrack.SetNet(tonet) fromzones = [] tozones = [] for zoneid in range(board.GetAreaCount()): zone = board.GetArea(zoneid) if (zone.GetNet().GetNetname() == fromnet.GetNetname()): fromzones.append(zone) continue if (zone.GetNet().GetNetname() == tonet.GetNetname()): tozones.append(zone) continue for zone in tozones: board.Remove(zone) for zone in fromzones: coords = coordsFromPolySet(zone.Outline()) #pdb.set_trace() newzone = board.InsertArea(tonet.GetNet(), 0, zone.GetLayer(), coords[0][0] + int(offset[0]), coords[0][1] + int(offset[1]), pcbnew.CPolyLine.DIAGONAL_EDGE) newoutline = newzone.Outline() for pt in coords[1:]: newoutline.Append(int(pt[0] + offset[0]), int(pt[1] + offset[1])) newzone.Hatch()
def Run(self): pcb = pcbnew.GetBoard() print("Hello Transmission: " + str(dL) + " " + str(R)) for track in pcb.GetTracks(): start = track.GetStart() end = track.GetEnd() # print(track.GetNetCode()) # if track.GetNetCode()==0 : if track.IsSelected(): n = math.floor(track.GetLength() / dL) print("n=" + str(n) + " " + str(track.GetEnd().x) + " " + str(track.GetStart().x)) m = 0 if ((track.GetEnd().x - track.GetStart().x) != 0): a = (track.GetEnd().y - track.GetStart().y) / ( track.GetEnd().x - track.GetStart().x) b = track.GetStart().y - a * track.GetStart().x theta = math.atan(a) print(str(theta)) # for x in range(track.GetStart().x,track.GetEnd().x,int(dL*math.cos(theta))): x = min(track.GetStart().x, track.GetEnd().x) while x < max(track.GetStart().x, track.GetEnd().x): yp = a * x + b + R * math.sin(theta + 3.14159 / 2) xp = x + R * math.cos(theta + 3.14159 / 2) newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, yp)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000) newvia.SetNetCode(gndcode) pcb.Add(newvia) yp = a * x + b + R * math.sin(theta - 3.14159 / 2) xp = x + R * math.cos(theta - 3.14159 / 2) newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, yp)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000) newvia.SetNetCode(gndcode) pcb.Add(newvia) x = x + dL * math.cos(theta) elif track.GetLength() > 0: x = track.GetStart().x print("Vertical: Start: " + str(track.GetStart().y) + " End: " + str(track.GetEnd().y)) y = min(track.GetStart().y, track.GetEnd().y) while y < max(track.GetStart().y, track.GetEnd().y): xp = x + R newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, y)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000) newvia.SetNetCode(gndcode) pcb.Add(newvia) x = x + dL * math.cos(theta) elif track.GetLength() > 0: x = track.GetStart().x print("Vertical: Start: " + str(track.GetStart().y) + " End: " + str(track.GetEnd().y)) y = min(track.GetStart().y, track.GetEnd().y) while y < max(track.GetStart().y, track.GetEnd().y): xp = x + R newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, y)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000) newvia.SetNetCode(gndcode) pcb.Add(newvia) xp = x - R newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, y)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000) newvia.SetNetCode(gndcode) pcb.Add(newvia) y = y + dL pcbnew.Refresh()
def replicate_tracks(self, pivot_anchor_mod, pivot_tracks, anchor_mod, net_pairs): logger.info("Replicating tracks") # get anchor angle with respect to pivot module anchor_angle = anchor_mod.mod.GetOrientationDegrees() # get exact anchor position anchor_pos = anchor_mod.mod.GetPosition() anchor_delta_angle = pivot_anchor_mod.mod.GetOrientationDegrees() - anchor_angle anchor_delta_pos = anchor_pos - pivot_anchor_mod.mod.GetPosition() net_pairs, net_dict = net_pairs # go through all the tracks for track in pivot_tracks: # get from which net we are clonning from_net_name = track.GetNetname() # find to net tup = [item for item in net_pairs if item[0] == from_net_name] # if net was not fount, then the track is not part of this sheet and should not be cloned if not tup: pass else: to_net_name = tup[0][1] to_net = net_dict[to_net_name] # finally make a copy # this came partially from Miles Mccoo # https://github.com/mmccoo/kicad_mmccoo/blob/master/replicatelayout/replicatelayout.py if track.GetClass() == "VIA": newvia = pcbnew.VIA(self.board) # need to add before SetNet will work, so just doing it first self.board.Add(newvia) toplayer = -1 bottomlayer = pcbnew.PCB_LAYER_ID_COUNT for l in range(pcbnew.PCB_LAYER_ID_COUNT): if not track.IsOnLayer(l): continue toplayer = max(toplayer, l) bottomlayer = min(bottomlayer, l) newvia.SetLayerPair(toplayer, bottomlayer) # get module to clone position pivot_track_pos = track.GetPosition() # get relative position with respect to pivot anchor pivot_anchor_pos = pivot_anchor_mod.mod.GetPosition() pivot_mod_delta_pos = pivot_track_pos - pivot_anchor_pos # new orientation is simple old_position = pivot_mod_delta_pos + anchor_pos newposition = rotate_around_pivot_point(old_position, anchor_pos, anchor_delta_angle) # convert to tuple of integers newposition = [int(x) for x in newposition] newvia.SetPosition(pcbnew.wxPoint(*newposition)) newvia.SetViaType(track.GetViaType()) newvia.SetWidth(track.GetWidth()) newvia.SetDrill(track.GetDrill()) newvia.SetNet(to_net) else: newtrack = pcbnew.TRACK(self.board) # need to add before SetNet will work, so just doing it first self.board.Add(newtrack) # get module to clone position pivot_track_pos = track.GetStart() # get relative position with respect to pivot anchor pivot_anchor_pos = pivot_anchor_mod.mod.GetPosition() pivot_mod_delta_pos = pivot_track_pos - pivot_anchor_pos # new orientation is simple old_position = pivot_mod_delta_pos + anchor_pos newposition = rotate_around_pivot_point(old_position, anchor_pos, anchor_delta_angle) newposition = [int(x) for x in newposition] newtrack.SetStart(pcbnew.wxPoint(*newposition)) pivot_track_pos = track.GetEnd() # get relative position with respect to pivot anchor pivot_anchor_pos = pivot_anchor_mod.mod.GetPosition() pivot_mod_delta_pos = pivot_track_pos - pivot_anchor_pos # new orientation is simple old_position = pivot_mod_delta_pos + anchor_pos newposition = rotate_around_pivot_point(old_position, anchor_pos, anchor_delta_angle) newposition = [int(x) for x in newposition] newtrack.SetEnd(pcbnew.wxPoint(*newposition)) newtrack.SetWidth(track.GetWidth()) newtrack.SetLayer(track.GetLayer()) newtrack.SetNet(to_net)
nettable = board.GetNetsByName() netcodes = Set() for name in ["+12V", "+5V", "GND"]: if (name in nettable): netcodes.add(nettable[name].GetNet()) toplayer = layertable['F.Cu'] bottomlayer = layertable['B.Cu'] for mod in board.GetModules(): for pad in mod.Pads(): netcode = pad.GetNetCode() if (netcode not in netcodes): continue newvia = pcbnew.VIA(board) # need to add before SetNet will work, so just doing it first board.Add(newvia) net = pad.GetNet() newvia.SetNet(net) nc = net.GetNetClass() newvia.SetWidth(nc.GetViaDiameter()) newvia.SetPosition(pad.GetCenter()) newvia.SetLayerPair(toplayer, bottomlayer) newvia.SetViaType(pcbnew.VIA_THROUGH) pcbnew.Refresh()
# if track.GetNetCode()==0 : if track.IsSelected(): n = math.floor(track.GetLength() / dL) m = 0 if ((track.GetEnd().x - track.GetStart().x) != 0): a = (track.GetEnd().y - track.GetStart().y) / (track.GetEnd().x - track.GetStart().x) b = track.GetStart().y - a * track.GetStart().x theta = math.atan(a) print(str(theta)) # for x in range(track.GetStart().x,track.GetEnd().x,int(dL*math.cos(theta))): x = min(track.GetStart().x, track.GetEnd().x) while x < max(track.GetStart().x, track.GetEnd().x): yp = a * x + b + R * math.sin(theta + 3.14159 / 2) xp = x + R * math.cos(theta + 3.14159 / 2) newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, yp)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000) newvia.SetNetCode(gndcode) pcb.Add(newvia) yp = a * x + b + R * math.sin(theta - 3.14159 / 2) xp = x + R * math.cos(theta - 3.14159 / 2) newvia = pcbnew.VIA(pcb) newvia.SetLayerPair(pcbnew.PCBNEW_LAYER_ID_START, pcbnew.PCBNEW_LAYER_ID_START + 31) newvia.SetPosition(pcbnew.wxPoint(xp, yp)) newvia.SetViaType(pcbnew.VIA_THROUGH) newvia.SetWidth(1000000)