Last active
October 23, 2020 10:26
-
-
Save Bolukan/fa35bbaff3eef0e5fb19760aad938e3c to your computer and use it in GitHub Desktop.
Create outline (cut edges and silk) of d1 mini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# execfile(r'[ENTER YOUR PATH]\d1mini_kicad.py') | |
import os | |
import sys | |
import pcbnew | |
# Cut the Edges of a typical d1 mini board | |
board = pcbnew.GetBoard() | |
aLayerCuts = board.GetLayerID('Edge.Cuts') | |
aSilkFront = board.GetLayerID('F.SilkS') | |
aSilkBack = board.GetLayerID('B.SilkS') | |
SILK_TO_EDGE = 0.2 | |
def ArcLayer(cx, cy, sx, sy, a, aLayer, aWidth): | |
"""! | |
Draw an arc based on centre, start and angle | |
@param cx: the x coordinate of the arc centre | |
@param cy: the y coordinate of the arc centre | |
@param sx: the relative x coordinate of the arc start point | |
@param sy: the relative y coordinate of the arc start point | |
@param a: the arc's central angle (in deci-degrees) | |
@param aLayer: the layer id to draw on | |
@param aWidth: the width of the drawing | |
""" | |
center = pcbnew.wxPoint(pcbnew.Millimeter2iu(cx), pcbnew.Millimeter2iu(cy)) | |
start = pcbnew.wxPoint(pcbnew.Millimeter2iu(cx + sx), pcbnew.Millimeter2iu(cy + sy)) | |
arc = pcbnew.DRAWSEGMENT(board) | |
arc.SetShape(pcbnew.S_ARC) | |
arc.SetLayer(aLayer) | |
arc.SetWidth(pcbnew.Millimeter2iu(aWidth)) | |
arc.SetCenter(center) | |
arc.SetArcStart(start) | |
arc.SetAngle(10*a) | |
board.Add(arc) | |
def LineLayer(sx, sy, ex, ey, aLayer, aWidth): | |
"""! | |
Draw a line based on absolute start en end | |
@param sx: the x coordinate of the starting point | |
@param sy: the y coordinate of the starting point | |
@param ex: the x coordinate of the ending point | |
@param ey: the y coordinate of the ending point | |
@param aLayer: the layer id to draw on | |
@param aWidth: the width of the drawing | |
""" | |
start = pcbnew.wxPoint(pcbnew.Millimeter2iu(sx), pcbnew.Millimeter2iu(sy)) | |
end = pcbnew.wxPoint(pcbnew.Millimeter2iu(ex), pcbnew.Millimeter2iu(ey)) | |
line = pcbnew.DRAWSEGMENT(board) | |
line.SetShape(pcbnew.S_SEGMENT) | |
line.SetLayer(aLayer) | |
line.SetWidth(pcbnew.Millimeter2iu(aWidth)) | |
line.SetStart(start) | |
line.SetEnd(end) | |
board.Add(line) | |
def Arc(cx, cy, sx, sy, a, inside): | |
"""! | |
Draw an arc based on centre, start and angle | |
@param cx: the x coordinate of the arc centre | |
@param cy: the y coordinate of the arc centre | |
@param sx: the relative x coordinate of the arc start point | |
@param sy: the relative y coordinate of the arc start point | |
@param a: the arc's central angle (in deci-degrees) | |
@param inside: 1 for inside and -1 for outside | |
""" | |
ArcLayer(cx, cy, sx, sy, a, aLayerCuts, 0.05) | |
if sx > 0: | |
sx = sx - inside * SILK_TO_EDGE | |
if sx < 0: | |
sx = sx + inside * SILK_TO_EDGE | |
if sy > 0: | |
sy = sy - inside * SILK_TO_EDGE | |
if sy < 0: | |
sy = sy + inside * SILK_TO_EDGE | |
ArcLayer(cx, cy, sx, sy, a, aSilkFront, 0.1524) | |
ArcLayer(cx, cy, sx, sy, a, aSilkBack, 0.1524) | |
def Line(sx, sy, ex, ey, ox, oy): | |
"""! | |
Draw a line based on absolute start en end | |
@param sx: the x coordinate of the starting point | |
@param sy: the y coordinate of the starting point | |
@param ex: the x coordinate of the ending point | |
@param ey: the y coordinate of the ending point | |
""" | |
LineLayer(sx, sy, ex, ey, aLayerCuts, 0.05) | |
if ox != 0 or oy != 0: | |
LineLayer(sx + ox, sy + oy, ex + ox, ey + oy, aSilkFront, 0.1524) | |
LineLayer(sx + ox, sy + oy, ex + ox, ey + oy, aSilkBack, 0.1524) | |
def d1mini(rx, ry): | |
"""! | |
Draw outline of d1 mini | |
@param rx: the x coordinate of the left-top | |
@param ry: the y coordinate of the left-top | |
""" | |
# width and height | |
w = 25.6 # 25.4 + 0.2 | |
h = 34.2 | |
at = 2.64 # 2.54 + 0.1 arc at top | |
ab = 0.508 # choose your number: small arc at bottom | |
asm = 2*0.254 # small arc | |
hrst = 7.38 - 0.376 # some extra distance to pin | |
hrst2 = 6.50 # 0.88 space | |
wrst = 2.54 # 2.54 space | |
# left-top arc | |
Arc(rx + at, ry + at, 0, -at, -90, 1) | |
# right-top arc | |
Arc(rx + (w - at), ry + at, at, 0, -90, 1) | |
# line between | |
Line(rx + at, ry, rx + (w - at), ry, 0, SILK_TO_EDGE) | |
# Left | |
Line(rx, ry + at, rx, ry + (h - hrst - asm), SILK_TO_EDGE, 0) # vertical | |
Arc(rx + asm, ry + (h - hrst - asm), -asm, 0, -90, 1) # bending inside | |
Line(rx + asm, ry + (h - hrst), rx + (wrst - (hrst-hrst2)), ry + (h - hrst), 0, -SILK_TO_EDGE) # horizontal | |
Arc(rx + (wrst - (hrst - hrst2)), ry + (h - hrst2), (hrst-hrst2), 0, -90, -1) # bending back to down | |
Line(rx + wrst, ry + (h - hrst2), rx + wrst, ry + (h - ab), SILK_TO_EDGE, 0) # vertical | |
Arc(rx + wrst + ab, ry + (h - ab), -ab, 0, -90, 1) # bending to bottom | |
# Right | |
Line(rx + w, ry + at, rx + w, ry + (h - ab), -SILK_TO_EDGE, 0) | |
Arc(rx + (w - ab), ry + (h - ab), 0, ab, -90, 1) | |
# Bottom | |
Line(rx + wrst + ab, ry + h, rx + (w - ab), ry + h, 0, -SILK_TO_EDGE) | |
# reference points | |
rx = 50 | |
ry = 0 | |
d1mini(rx, ry) | |
pcbnew.Refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment