def Circle(self, x, y, r, filled=False): """! Draw a circle at (x,y) of radius r If filled is true, the thickness and radius of the line will be set such that the circle appears filled @param x: the x co-ordinate of the arc centre @param y: the y co-ordinate of the arc centre @param r: the circle's radius @param filled: True to draw a filled circle, False to use the current DC line thickness """ circle = pcbnew.EDGE_MODULE(self.module) start = self.TransformPoint(x, y) if filled: circle.SetWidth(r) end = self.TransformPoint(x, y + r / 2) else: circle.SetWidth(self.dc['lineThickness']) end = self.TransformPoint(x, y + r) circle.SetLayer(self.dc['layer']) circle.SetShape(pcbnew.S_CIRCLE) circle.SetStartEnd(start, end) self.module.Add(circle)
def Arc(self, cx, cy, sx, sy, a): """! Draw an arc based on centre, start and angle The transform matrix is applied Note that this won't work properly if the result is not a circular arc (e.g. a horizontal scale) @param cx: the x co-ordinate of the arc centre @param cy: the y co-ordinate of the arc centre @param sx: the x co-ordinate of the arc start point @param sy: the y co-ordinate of the arc start point @param a: the arc's central angle (in deci-degrees) """ circle = pcbnew.EDGE_MODULE(self.module) circle.SetWidth(self.dc['lineThickness']) center = self.TransformPoint(cx, cy) start = self.TransformPoint(sx, sy) circle.SetLayer(self.dc['layer']) circle.SetShape(pcbnew.S_ARC) # check if the angle needs to be reverse (a flip scaling) if cmp(self.dc['transform'][0], 0) != cmp(self.dc['transform'][4], 0): a = -a circle.SetAngle(a) circle.SetStartEnd(center, start) self.module.Add(circle)
def Arc(self, cx, cy, sx, sy, a): """ Draw an arc based on centre, start and angle The transform matrix is applied Note that this won't work properly if the result is not a circular arc (eg a horzontal scale) """ circle = pcbnew.EDGE_MODULE(self.module) circle.SetWidth(self.dc['width']) center = self.TransformPoint(cx, cy) start = self.TransformPoint(sx, sy) circle.SetLayer(self.dc['layer']) circle.SetShape(pcbnew.S_ARC) # check if the angle needs to be reverse (a flip scaling) if cmp(self.dc['transform'][0], 0) != cmp(self.dc['transform'][4], 0): a = -a circle.SetAngle(a) circle.SetStartEnd(center, start) self.module.Add(circle)
def Polygon(module, points, layer): '''Draw a polygon through specified points.''' polygon = pcbnew.EDGE_MODULE(module) polygon.SetWidth(0) # Disables outline polygon.SetLayer(layer) polygon.SetShape(pcbnew.S_POLYGON) polygon.SetPolyPoints(points) module.Add(polygon) return module
def add_line(self, start, end, layer='F.SilkS', width=0.15): """Create a graphic line on the module""" a = pcbnew.EDGE_MODULE(self._module) a.SetShape(pcbnew.S_SEGMENT) a.SetStart(_point_mm(start[0], start[1])) a.SetEnd(_point_mm(end[0], end[1])) a.SetLayer(_get_layer(layer)) a.SetWidth(_from_mm(width)) a.SetLocalCoord() self._module.Add(a) return a
def add_circle(self, center, radius, layer='F.SilkS', width=0.15): """Create a graphic circle on the module""" a = pcbnew.EDGE_MODULE(self._module) a.SetShape(pcbnew.S_CIRCLE) a.SetCenter(_point_mm(center[0], center[1])) start_coord = _point_mm(center[0], center[1] + radius) a.SetArcStart(start_coord) a.SetLayer(_get_layer(layer)) a.SetWidth(_from_mm(width)) a.SetLocalCoord() self._module.Add(a) return a
def Line(self, x1, y1, x2, y2): """ Draw a line from (x1, y1) to (x2, y2) """ outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(self.GetLineTickness()) outline.SetLayer(self.GetLayer()) outline.SetShape(pcbnew.S_SEGMENT) start = self.TransformPoint(x1, y1) end = self.TransformPoint(x2, y2) outline.SetStartEnd(start, end) self.module.Add(outline)
def FilledBox(self, x1, y1, x2, y2): box = pcbnew.EDGE_MODULE(self.module) box.SetShape(pcbnew.S_POLYGON) corners = pcbnew.wxPoint_Vector() corners.append(pcbnew.wxPoint(x1, y1)) corners.append(pcbnew.wxPoint(x2, y1)) corners.append(pcbnew.wxPoint(x2, y2)) corners.append(pcbnew.wxPoint(x1, y2)) box.SetPolyPoints(corners) return box
def drawPixelSquareArea( self, layer, size, xposition, yposition): # creates a EDGE_MODULE of polygon type. The polygon is a square polygon = pcbnew.EDGE_MODULE(self.module) polygon.SetShape(pcbnew.S_POLYGON) polygon.SetWidth( 0 ) polygon.SetLayer(layer) halfsize = int(size/2) polygon.GetPolyShape().NewOutline(); polygon.GetPolyShape().Append( halfsize+xposition, halfsize+yposition ) polygon.GetPolyShape().Append( halfsize+xposition, -halfsize+yposition ) polygon.GetPolyShape().Append( -halfsize+xposition, -halfsize+yposition ) polygon.GetPolyShape().Append( -halfsize+xposition, halfsize+yposition ) return polygon
def Arc(self, cx, cy, sx, sy, a): circle = pcbnew.EDGE_MODULE(self.module) circle.SetWidth(self.draw.dc['lineThickness']) center = self.draw.TransformPoint(cx, cy) start = self.draw.TransformPoint(sx, sy) circle.SetLayer(self.draw.dc['layer']) circle.SetShape(pcbnew.S_ARC) circle.SetAngle(a) circle.SetStartEnd(center, start) self.draw.module.Add(circle)
def Line(self, x1, y1, x2, y2): seg = pcbnew.EDGE_MODULE(self.module) seg.SetWidth(pcbnew.FromMM(self.X)) seg.SetLayer(self.layer) seg.SetShape(pcbnew.S_SEGMENT) seg.SetStartEnd( pcbnew.wxPoint( pcbnew.FromMM(x1) + self.position.x, pcbnew.FromMM(y1) + self.position.y), pcbnew.wxPoint( pcbnew.FromMM(x2) + self.position.x, pcbnew.FromMM(y2) + self.position.y)) self.module.Add(seg)
def Polygon(self, points, layer): """ Draw a polygon through specified points """ import pcbnew polygon = pcbnew.EDGE_MODULE(self.module) polygon.SetWidth(0) #Disables outline polygon.SetLayer(layer) polygon.SetShape(pcbnew.S_POLYGON) polygon.SetPolyPoints(points) self.module.Add(polygon)
def drawSquareArea(self, layer, size, xposition, yposition): # creates a EDGE_MODULE of polygon type. The polygon is a square polygon = pcbnew.EDGE_MODULE(self.module) polygon.SetShape(pcbnew.S_POLYGON) polygon.SetWidth(0) polygon.SetLayer(layer) halfsize = size / 2 pos = pcbnew.wxPoint(xposition, yposition) polygon.GetPolyPoints().push_back( pcbnew.wxPoint(halfsize, halfsize) + pos) polygon.GetPolyPoints().push_back( pcbnew.wxPoint(halfsize, -halfsize) + pos) polygon.GetPolyPoints().push_back( pcbnew.wxPoint(-halfsize, -halfsize) + pos) polygon.GetPolyPoints().push_back( pcbnew.wxPoint(-halfsize, halfsize) + pos) return polygon
def Circle(self, x, y, r, filled=False): """ Draw a circle at (x,y) of radius r If filled is true, the thickness and radius of the line will be set such that the circle appears filled """ circle = pcbnew.EDGE_MODULE(self.module) start = self.TransformPoint(x, y) if filled: circle.SetWidth(r) end = self.TransformPoint(x, y + r/2) else: circle.SetWidth(self.dc['lineThickness']) end = self.TransformPoint(x, y + r) circle.SetLayer(self.dc['layer']) circle.SetShape(pcbnew.S_CIRCLE) circle.SetStartEnd(start, end) self.module.Add(circle)
def add_arc(self, center, radius, start_angle, stop_angle, layer='F.SilkS', width=0.15): """Create a graphic arc on the module""" start_coord = radius * cmath.exp(math.radians(start_angle - 90) * 1j) start_coord = _point_mm(start_coord.real, start_coord.imag) angle = stop_angle - start_angle a = pcbnew.EDGE_MODULE(self._module) a.SetShape(pcbnew.S_ARC) a.SetCenter(_point_mm(center[0], center[1])) a.SetArcStart(start_coord) a.SetAngle(angle * 10) a.SetLayer(_get_layer(layer)) a.SetWidth(_from_mm(width)) a.SetLocalCoord() self._module.Add(a) return a
def BuildThisFootprint(self): p = self.parameters pad_count = int(p["Pads"]["*n"]) pad_width = p["Pads"]["width"] pad_height = p["Pads"]["height"] pad_pitch = p["Pads"]["pitch"] shl_width = p["Shield"]["width"] shl_height = p["Shield"]["height"] shl_to_pad = p["Shield"]["shield_to_pad"] shl_from_top = p["Shield"]["from_top"] offsetX = pad_pitch * (pad_count - 1) / 2 size_pad = pcbnew.wxSize(pad_width, pad_height) size_shld = pcbnew.wxSize(shl_width, shl_height) size_text = pcbnew.FromMM(0.8) textposy = pad_height / 2 + pcbnew.FromMM(1) self.draw.Value(0, textposy, size_text) textposy = textposy + pcbnew.FromMM(1.2) self.draw.Reference(0, textposy, size_text) # create a pad array and add it to the module for n in range(0, pad_count): xpos = pad_pitch * n - offsetX pad = self.smdRectPad(self.module, size_pad, pcbnew.wxPoint(xpos, 0), str(n + 1)) self.module.Add(pad) # Mechanical shield pads: left pad and right pad xpos = -shl_to_pad - offsetX pad_s0_pos = pcbnew.wxPoint(xpos, shl_from_top) pad_s0 = self.smdRectPad(self.module, size_shld, pad_s0_pos, "0") xpos = (pad_count - 1) * pad_pitch + shl_to_pad - offsetX pad_s1_pos = pcbnew.wxPoint(xpos, shl_from_top) pad_s1 = self.smdRectPad(self.module, size_shld, pad_s1_pos, "0") self.module.Add(pad_s0) self.module.Add(pad_s1) #add outline outline = pcbnew.EDGE_MODULE(self.module) linewidth = pcbnew.FromMM(0.2) outline.SetWidth(linewidth) margin = pcbnew.FromMM(0.2) # upper line posy = -pad_height / 2 - linewidth / 2 - margin xstart = -pad_pitch * 0.5 - offsetX xend = pad_pitch * pad_count + xstart outline.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xend, posy)) outline.SetLayer(pcbnew.F_SilkS) #default: not needed outline.SetShape(pcbnew.S_SEGMENT) self.module.Add(outline) # lower line outline1 = outline.Duplicate() #copy all settings from outline posy = pad_height / 2 + linewidth / 2 + margin outline1.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xend, posy)) self.module.Add(outline1) # around left mechanical pad (the outline around right pad is mirrored/y axix) outline2 = outline.Duplicate() # vertical segment yend = pad_s0_pos.y + shl_height / 2 + margin outline2.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xstart, yend)) self.module.Add(outline2) outline2_d = pcbnew.EDGE_MODULE(self.module) # right pad side outline2_d.Copy(outline2) outline2_d.SetStartEnd(pcbnew.wxPoint(-xstart, posy), pcbnew.wxPoint(-xstart, yend)) self.module.Add(outline2_d) outline3 = outline.Duplicate() # horizontal segment below the pad posy = yend xend = pad_s0_pos.x - (shl_width / 2 + linewidth + margin * 2) outline3.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xend, posy)) self.module.Add(outline3) outline3_d = pcbnew.EDGE_MODULE(self.module) # right pad side outline3_d.Copy(outline3) outline3_d.SetStartEnd(pcbnew.wxPoint(-xstart, posy), pcbnew.wxPoint(-xend, yend)) self.module.Add(outline3_d) outline4 = outline.Duplicate() # vertical segment at left of the pad xstart = xend yend = posy - (shl_height + linewidth + margin * 2) outline4.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xend, yend)) self.module.Add(outline4) outline4_d = outline.Duplicate() # right pad side outline4_d.SetStartEnd(pcbnew.wxPoint(-xstart, posy), pcbnew.wxPoint(-xend, yend)) self.module.Add(outline4_d) outline5 = outline.Duplicate() # horizontal segment above the pad xstart = xend xend = -pad_pitch * 0.5 - offsetX posy = yend outline5.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xend, yend)) self.module.Add(outline5) outline5_d = outline.Duplicate() # right pad side outline5_d.SetStartEnd(pcbnew.wxPoint(-xstart, posy), pcbnew.wxPoint(-xend, yend)) self.module.Add(outline5_d) outline6 = outline.Duplicate() # vertical segment above the pad xstart = xend yend = -pad_height / 2 - linewidth / 2 - margin outline6.SetStartEnd(pcbnew.wxPoint(xstart, posy), pcbnew.wxPoint(xend, yend)) self.module.Add(outline6) outline6_d = outline.Duplicate() # right pad side outline6_d.SetStartEnd(pcbnew.wxPoint(-xstart, posy), pcbnew.wxPoint(-xend, yend)) self.module.Add(outline6_d)
def BuildFootprint(self): if self.has_errors(): print "Cannot build footprint: Parameters have errors:" print self.parameter_errors return print "Building new QFP footprint with the following parameters:" self.print_parameter_table() self.module = pcbnew.MODULE(None) # create a new module pads = self.parameters num_pads = int(pads["Pads"]["*n"]) pad_width = pads["Pads"]["width"] pad_length = pads["Pads"]["length"] pad_pitch = pads["Pads"]["pitch"] pad_horizontal_pitch = pads["Pads"]["horizontal pitch"] pad_vertical_pitch = pads["Pads"]["vertical pitch"] package_width = pads["Package"]["width"] package_height = pads["Package"]["height"] side_length = pad_pitch * ((num_pads / 4) - 1) offsetX = pad_pitch * ((num_pads / 4) - 1) / 2 text_size = pcbnew.wxSize(pcbnew.FromMM(0.8), pcbnew.FromMM(0.8)) self.module.SetReference("QFP %d" % int(num_pads)) self.module.Reference().SetPos0(pcbnew.wxPoint(0, pcbnew.FromMM(-0.8))) self.module.Reference().SetTextPosition( self.module.Reference().GetPos0()) self.module.Reference().SetSize(text_size) self.module.SetValue("U**") self.module.Value().SetPos0(pcbnew.wxPoint(0, pcbnew.FromMM(+0.8))) self.module.Value().SetTextPosition(self.module.Value().GetPos0()) self.module.Value().SetSize(text_size) fpid = pcbnew.FPID(self.module.GetReference()) #the name in library self.module.SetFPID(fpid) pad_size_left_right = pcbnew.wxSize(pad_length, pad_width) pad_size_bottom_top = pcbnew.wxSize(pad_width, pad_length) for cur_pad in range(0, num_pads): side = int( cur_pad / (num_pads / 4)) # 0 -> left, 1 -> bottom, 2 -> right, 3 -> top if side == 0 or side == 2: pad_size = pad_size_left_right pad_pos_x = -(pad_horizontal_pitch / 2) pad_pos_y = (cur_pad % (num_pads / 4)) * pad_pitch - (side_length / 2) if side == 2: pad_pos_x = -pad_pos_x pad_pos_y = -pad_pos_y else: pad_size = pad_size_bottom_top pad_pos_x = (cur_pad % (num_pads / 4)) * pad_pitch - (side_length / 2) pad_pos_y = -(pad_vertical_pitch / 2) if side == 1: pad_pos_y = -pad_pos_y else: pad_pos_x = -pad_pos_x pad_pos = pcbnew.wxPoint(pad_pos_x, pad_pos_y) pad = self.smd_rect_pad(self.module, pad_size, pad_pos, str(cur_pad + 1)) self.module.Add(pad) half_package_width = package_width / 2 half_package_height = package_height / 2 package_pad_height_offset = abs(package_height - side_length) / 2 - pad_pitch package_pad_width_offset = abs(package_width - side_length) / 2 - pad_pitch # Bottom Left Edge, vertical line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint(-half_package_width, half_package_height - package_pad_height_offset) end = pcbnew.wxPoint(-half_package_width, half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline) # Bottom Left Edge, horizontal line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint(-half_package_width, half_package_height) end = pcbnew.wxPoint(-half_package_width + package_pad_width_offset, half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline) # Bottom Right Edge, vertical line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint(half_package_width, half_package_height - package_pad_height_offset) end = pcbnew.wxPoint(half_package_width, half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline) # Bottom Right Edge, horizontal line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint(half_package_width, half_package_height) end = pcbnew.wxPoint(half_package_width - package_pad_width_offset, half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline) # Top Right Edge, vertical line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint( half_package_width, -half_package_height + package_pad_height_offset) end = pcbnew.wxPoint(half_package_width, -half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline) # Top Right Edge, horizontal line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint(half_package_width, -half_package_height) end = pcbnew.wxPoint(half_package_width - package_pad_width_offset, -half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline) # Top Left Edge, straight line outline = pcbnew.EDGE_MODULE(self.module) outline.SetWidth(pcbnew.FromMM(0.2)) outline.SetLayer(pcbnew.SILKSCREEN_N_FRONT) outline.SetShape(pcbnew.S_SEGMENT) start = pcbnew.wxPoint( -half_package_width, -half_package_height + package_pad_height_offset) end = pcbnew.wxPoint(-half_package_width + package_pad_width_offset, -half_package_height) outline.SetStartEnd(start, end) self.module.Add(outline)