def BuildFootprint(self): """! Actually make the footprint. We defer all but the set-up to the implementing class """ self.buildmessages = "" self.module = pcbnew.FOOTPRINT(None) # create a new module # Perform default checks on all parameters for p in self.params: p.ClearErrors() p.Check() # use defaults self.CheckParameters() # User error checks if self.AnyErrors(): # Errors were detected! self.buildmessages = ("Cannot build footprint: " "Parameters have errors:\n") for p in self.params: if len(p.error_list) > 0: self.buildmessages += "['{page}']['{name}']:\n".format( page=p.page, name=p.name) for error in p.error_list: self.buildmessages += "\t" + error + "\n" return self.buildmessages = ( "Building new {name} footprint with the following parameters:\n". format(name=self.name)) self.buildmessages += self.Show() self.draw = FootprintWizardDrawingAids(self.module) self.module.SetValue(self.GetValue()) self.module.SetReference("%s**" % self.GetReferencePrefix()) fpid = pcbnew.LIB_ID("", self.module.GetValue() ) # the lib name (empty) and the name in library self.module.SetFPID(fpid) self.SetModule3DModel() # add a 3D module if specified thick = self.GetTextThickness() self.module.Reference().SetTextThickness(thick) self.module.Value().SetTextThickness(thick) self.BuildThisFootprint() # implementer's build function return
def npth(self, diameter, x, y): """put a npth in pcb with given diameter and location""" module = pcbnew.FOOTPRINT(self.pcb) npth = pcbnew.PAD(module) npth.SetAttribute(pcbnew.PAD_ATTRIB_NPTH) npth.SetShape(pcbnew.PAD_SHAPE_CIRCLE) npth.SetSize(pcbnew.wxSizeMM(diameter, diameter)) npth.SetDrillShape(pcbnew.PAD_DRILL_SHAPE_CIRCLE) npth.SetDrillSize(pcbnew.wxSizeMM(diameter, diameter)) module.Add(npth) self.pcb.Add(module) loc = pcbnew.wxPointMM(x, y) module.SetPosition(loc)
def pcb_instanciate_one_board(pcb, lsItems, vector, angle, center): global boardcount boardcount = boardcount + 1 for Item in lsItems: #newItem = Item.Duplicate() #pcb.Add(newItem) # temporary, due to Kicad inconsistency if type(Item) is FOOTPRINT: newItem = pcbnew.FOOTPRINT( Item) # creates new FOOTPRINT n as a copy of m pcb.Add(newItem) newItem.SetPosition(Item.GetPosition()) else: newItem = Item.Duplicate() pcb.Add(newItem) #end temporary, due to Kicad inconsistency if angle: newItem.Rotate(center, angle * 10) # kicad uses decidegrees .... newItem.Move(vector) # replace the marker "##PCBNUMBER##" by tha ctual number of this copy if type(newItem) is PCB_TEXT: # text = newItem.GetText() text = re.sub(r'\##PCBNUMBER##', str(boardcount), text) newItem.SetText(text) # renumerate FOOTPRINTs including the PCB number if type(newItem) is FOOTPRINT: if enumeration_base: ref = newItem.GetReference() if isinstance(enumeration_base, numbers.Number): match = re.match(r"(\D+)(\d+)", ref) if match: items = match.groups() ref_letter = (items[0]).encode('ascii', 'ignore') ref_num = int(items[1]) ref = "%s%i" % (ref_letter, ref_num + boardcount * enumeration_base) else: ref = re.sub(enumeration_base, str(boardcount), ref) newItem.SetReference(ref) return
def parse_footprints(self): # type: (list) -> list footprints = [] for f in self.footprints: ref = f.GetReference() # bounding box if hasattr(pcbnew, 'MODULE'): f_copy = pcbnew.MODULE(f) else: f_copy = pcbnew.FOOTPRINT(f) f_copy.SetOrientation(0) f_copy.SetPosition(pcbnew.wxPoint(0, 0)) mrect = f_copy.GetFootprintRect() bbox = { "pos": self.normalize(f.GetPosition()), "relpos": self.normalize(mrect.GetPosition()), "size": self.normalize(mrect.GetSize()), "angle": f.GetOrientation() * 0.1, } # graphical drawings drawings = [] for d in f.GraphicalItems(): # we only care about copper ones, silkscreen is taken care of if d.GetLayer() not in [pcbnew.F_Cu, pcbnew.B_Cu]: continue drawing = self.parse_drawing(d) if not drawing: continue drawings.append({ "layer": "F" if d.GetLayer() == pcbnew.F_Cu else "B", "drawing": drawing, }) # footprint pads pads = [] for p in f.Pads(): pad_dict = self.parse_pad(p) if pad_dict is not None: pads.append((p.GetPadName(), pad_dict)) if pads: # Try to guess first pin name. pads = sorted(pads, key=lambda el: el[0]) pin1_pads = [p for p in pads if p[0] in ['1', 'A', 'A1', 'P1', 'PAD1']] if pin1_pads: pin1_pad_name = pin1_pads[0][0] else: # No pads have common first pin name, pick lexicographically smallest. pin1_pad_name = pads[0][0] for pad_name, pad_dict in pads: if pad_name == pin1_pad_name: pad_dict['pin1'] = 1 pads = [p[1] for p in pads] # add footprint footprints.append({ "ref": ref, "bbox": bbox, "pads": pads, "drawings": drawings, "layer": { pcbnew.F_Cu: "F", pcbnew.B_Cu: "B" }.get(f.GetLayer()) }) return footprints