Beispiel #1
0
 def _boardGridPos(self, destination, i, j, boardSize, horSpace, verSpace):
     # Remove 0.001 mm to compensate for numerical imprecision when
     # merging coincident edges of boards
     return wxPoint(
         destination[0] + j *
         (boardSize.GetWidth() + horSpace - FromMM(0.001)), destination[1] +
         i * (boardSize.GetHeight() + verSpace - FromMM(0.001)))
Beispiel #2
0
def test_readLength():
    assert readLength("4.24mm") == FromMM(4.24)
    assert readLength("4.24 mm") == FromMM(4.24)
    assert readLength("4mm") == FromMM(4)

    assert readLength("1m") == FromMM(1000)
    assert readLength("1cm") == FromMM(10)

    assert readLength("1mil") == FromMils(1)
    assert readLength("1inch") == FromMils(1000)
Beispiel #3
0
 def _makeSingleInnerTabs(self, destination, rows, cols, boardSize,
                          verSpace, horSpace, verTabWidth, horTabWidth,
                          radius):
     """
     Create inner tabs in board grid by placing exactly one in the middle
     """
     lastRow = lambda x: x == rows - 1
     lastCol = lambda x: x == cols - 1
     cuts = []
     for i, j in product(range(rows), range(cols)):
         dest = self._boardGridPos(destination, i, j, boardSize, horSpace,
                                   verSpace)
         if not lastRow(i):
             # Add bottom tab
             xOffset, width = self._singleTabSize(boardSize.GetWidth(),
                                                  verTabWidth, horSpace,
                                                  lastCol(j))
             tab = wxRect(dest[0] + xOffset,
                          dest[1] + boardSize.GetHeight(), width, verSpace)
             cuts.append(
                 ((tab.GetX(), tab.GetY()), (tab.GetX() + tab.GetWidth(),
                                             tab.GetY())))
             if tab.GetHeight() != 0:
                 cuts.append(((tab.GetX(), tab.GetY() + tab.GetHeight()),
                              (tab.GetX() + tab.GetWidth(),
                               tab.GetY() + tab.GetHeight())))
                 tab = expandRect(tab, FromMM(0.001))
                 self.appendSubstrate(tab, radius)
         if not lastCol(j):
             # Add right tab
             yOffset, height = self._singleTabSize(boardSize.GetHeight(),
                                                   horTabWidth, verSpace,
                                                   lastRow(i))
             tab = wxRect(dest[0] + boardSize.GetWidth(), dest[1] + yOffset,
                          horSpace, height)
             cuts.append(((tab.GetX(), tab.GetY()),
                          (tab.GetX(), tab.GetY() + tab.GetHeight())))
             if tab.GetHeight() != 0:
                 cuts.append(((tab.GetX() + tab.GetWidth(),
                               tab.GetY()), (tab.GetX() + tab.GetWidth(),
                                             tab.GetY() + tab.GetHeight())))
                 tab = expandRect(tab, FromMM(0.001))
                 self.appendSubstrate(tab, radius)
     return cuts
Beispiel #4
0
 def _configure_plot_ctrl(self, po, output_dir):
     super()._configure_plot_ctrl(po, output_dir)
     po.SetSubtractMaskFromSilk(self.subtract_mask_from_silk)
     po.SetUseGerberProtelExtensions(self.use_protel_extensions)
     po.SetGerberPrecision(5 if self.gerber_precision == 4.5 else 6)
     po.SetCreateGerberJobFile(self.create_gerber_job_file)
     po.SetUseGerberX2format(self.use_gerber_x2_attributes)
     po.SetIncludeGerberNetlistInfo(self.use_gerber_net_attributes)
     po.SetUseAuxOrigin(self.use_aux_axis_as_origin)
     po.SetLineWidth(FromMM(self.line_width))
     setattr(po, 'gerber_job_file', self.gerber_job_file)
Beispiel #5
0
 def units(fixed, intOrWidget):
     from pcbnew import FromMils, FromMM, ToMils, ToMM
     if intOrWidget == fixed.MM:
         fixed.value = FromMM(intOrWidget.get_value())
         testVal = FromMils(fixed.Mils.get_value())
         if fixed.value != testVal:
             setV = ToMils(fixed.value)
             fixed.Mils.set_value(setV)
             if __name__ == "__main__":
                 fixed.logView.insert_end("%gmils\n" % setV)
     elif intOrWidget == fixed.Mils:
         fixed.value = FromMils(intOrWidget.get_value())
         testVal = FromMM(fixed.MM.get_value())
         if fixed.value != testVal:
             setV = ToMM(fixed.value)
             fixed.MM.set_value(setV)
             if __name__ == "__main__":
                 fixed.logView.insert_end("%gmm\n" % setV)
     elif type(intOrWidget) == int:
         fixed.value = intOrWidget
         fixed.MM.set_value(ToMM(intOrWidget))
         fixed.Mils.set_value(ToMils(intOrWidget))
Beispiel #6
0
 def _configure_plot_ctrl(self, po, output_dir):
     super()._configure_plot_ctrl(po, output_dir)
     po.SetSubtractMaskFromSilk(self.subtract_mask_from_silk)
     po.SetUseGerberProtelExtensions(self.use_protel_extensions)
     po.SetGerberPrecision(5 if self.gerber_precision == 4.5 else 6)
     po.SetCreateGerberJobFile(self.create_gerber_job_file)
     po.SetUseGerberX2format(self.use_gerber_x2_attributes)
     po.SetIncludeGerberNetlistInfo(self.use_gerber_net_attributes)
     po.SetUseAuxOrigin(self.use_aux_axis_as_origin)
     po.SetDrillMarksType(0)
     if GS.kicad_version_n < KICAD_VERSION_5_99:
         po.SetLineWidth(FromMM(self.line_width))
     else:
         po.SetDisableGerberMacros(self.disable_aperture_macros)
     setattr(po, 'gerber_job_file', self.gerber_job_file)
Beispiel #7
0
 def _configure_plot_ctrl(self, po, output_dir):
     super()._configure_plot_ctrl(po, output_dir)
     po.SetWidthAdjust(self.width_adjust)
     po.SetFineScaleAdjustX(self.scale_adjust_x)
     po.SetFineScaleAdjustX(self.scale_adjust_y)
     po.SetA4Output(self.a4_output)
     po.SetPlotMode(SKETCH if self.sketch_plot else FILLED)
     po.SetLineWidth(FromMM(self.line_width))
     po.SetNegative(self.negative_plot)
     po.SetMirror(self.mirror_plot)
     # Scaling/Autoscale
     if self.scaling == AUTO_SCALE:
         po.SetAutoScale(True)
         po.SetScale(1)
     else:
         po.SetAutoScale(False)
         po.SetScale(self.scaling)
Beispiel #8
0
 def appendVerticalTab(destination, i, outerVerTabThickness):
     dest = self._boardGridPos(destination, 0, i, boardSize, horSpace,
                               verSpace)
     spaceSize = outerHorTabThickness if lastCol(i) else horSpace
     xOffset, width = self._singleTabSize(boardSize.GetWidth(),
                                          verTabWidth, spaceSize, False)
     tab = wxRect(dest[0] + xOffset, dest[1] - outerVerTabThickness,
                  width, outerVerTabThickness)
     if i == 0 and verTabWidth == 0:
         tab.SetX(tab.GetX() - outerHorTabThickness)
         tab.SetWidth(tab.GetWidth() + outerHorTabThickness)
     cuts.append(
         ((tab.GetX(), tab.GetY() + tab.GetHeight()),
          (tab.GetX() + tab.GetWidth(), tab.GetY() + tab.GetHeight())))
     tab = normalizeRect(tab)
     tab = expandRect(tab, FromMM(0.001))
     self.appendSubstrate(tab, radius)
Beispiel #9
0
 def appendHorizontalTab(destination, i, outerHorTabThickness):
     dest = self._boardGridPos(destination, i, 0, boardSize, horSpace,
                               verSpace)
     spaceSize = outerVerTabThickness if lastRow(i) else verSpace
     yOffset, height = self._singleTabSize(boardSize.GetHeight(),
                                           horTabWidth, spaceSize,
                                           False)
     tab = wxRect(dest[0] - outerHorTabThickness, dest[1] + yOffset,
                  outerHorTabThickness, height)
     if i == 0 and horTabWidth == 0:
         tab.SetY(tab.GetY() - outerVerTabThickness)
         tab.SetHeight(tab.GetHeight() + outerVerTabThickness)
     cuts.append(
         ((tab.GetX() + tab.GetWidth(), tab.GetY()),
          (tab.GetX() + tab.GetWidth(), tab.GetY() + tab.GetHeight())))
     tab = normalizeRect(tab)
     tab = expandRect(tab, FromMM(0.001))
     self.appendSubstrate(tab, radius)
Beispiel #10
0
def place_switches(c):
    OFFSET = wxPoint(FromMM(100), FromMM(50))
    KEY_DISTANCE = 19.05

    b = LoadBoard(KICAD_PCB)
    for row in range(5):
        for col in range(6):
            i = col + 6 * row + 1
            m = b.FindModuleByReference(f"SW{i}")
            x = FromMM(KEY_DISTANCE * col)
            y = FromMM(KEY_DISTANCE) * row
            m.SetPosition(wxPoint(x, y) + OFFSET)

            m = b.FindModuleByReference(f"D{i}")
            x = FromMM(KEY_DISTANCE) * col + FromMM(KEY_DISTANCE) / 2
            y = FromMM(KEY_DISTANCE) * row
            m.SetPosition(wxPoint(x, y) + OFFSET)
            m.SetOrientation(270 * 10)

    b.Save(b.GetFileName())
Beispiel #11
0
 def _configure_plot_ctrl(self, po, output_dir):
     super()._configure_plot_ctrl(po, output_dir)
     po.SetMirror(self.mirror_plot)
     po.SetLineWidth(FromMM(self.line_width))
     po.SetNegative(self.negative_plot)
Beispiel #12
0
def processBoard(boardName, plotDir, quiet):
    '''Load board and initialize plot controller'''

    board = LoadBoard(boardName)
    boardbox = board.ComputeBoundingBox()
    boardxl = boardbox.GetX()
    boardyl = boardbox.GetY()
    boardwidth = boardbox.GetWidth()
    boardheight = boardbox.GetHeight()

    if not quiet:
        print(boardxl, boardyl, boardwidth, boardheight)

    pctl = PLOT_CONTROLLER(board)
    pctl.SetColorMode(True)

    popt = pctl.GetPlotOptions()
    popt.SetOutputDirectory(plotDir)
    popt.SetPlotFrameRef(False)
    popt.SetLineWidth(FromMM(0.15))
    popt.SetAutoScale(False)
    popt.SetScale(2)
    popt.SetMirror(False)
    popt.SetUseGerberAttributes(True)
    popt.SetExcludeEdgeLayer(False)
    popt.SetUseAuxOrigin(True)

    layers = [
        ("F_Cu",      F_Cu,      "Top copper"),
        ("In1_Cu",    In1_Cu,    "Inner1 copper"),
        ("In2_Cu",    In2_Cu,    "Inner2 copper"),
        ("In3_Cu",    In3_Cu,    "Inner3 copper"),
        ("In4_Cu",    In4_Cu,    "Inner4 copper"),
        ("B_Cu",      B_Cu,      "Bottom copper"),
        ("F_Adhes",   F_Adhes,   "Adhesive top"),
        ("B_Adhes",   B_Adhes,   "Adhesive bottom"),
        ("F_Paste",   F_Paste,   "Paste top"),
        ("B_Paste",   B_Paste,   "Paste bottom"),
        ("F_SilkS",   F_SilkS,   "Silk top"),
        ("B_SilkS",   B_SilkS,   "Silk top"),
        ("F_Mask",    F_Mask,    "Mask top"),
        ("B_Mask",    B_Mask,    "Mask bottom"),
        ("Dwgs_User", Dwgs_User, "User drawings"),
        ("Cmts_User", Cmts_User, "User comments"),
        ("Eco1_User", Eco1_User, "Eng change order 1"),
        ("Eco2_User", Eco2_User, "Eng change order 1"),
        ("Edge_Cuts", Edge_Cuts, "Edges"),
        ("Margin",    Margin,    "Margin"),
        ("F_CrtYd",   F_CrtYd,   "Courtyard top"),
        ("B_CrtYd",   B_CrtYd,   "Courtyard bottom"),
        ("F_Fab",     F_Fab,     "Fab top"),
        ("B_Fab",     B_Fab,     "Fab bottom")
    ]

    for layer_info in layers:
        pctl.SetLayer(layer_info[1])
        pctl.OpenPlotfile(layer_info[0], PLOT_FORMAT_SVG, layer_info[2])
        layer_name = board.GetLayerName(layer_info[1]).replace(".", "_")
        if layer_info[0] != layer_name:
            pctl.OpenPlotfile(layer_name, PLOT_FORMAT_SVG, layer_info[2])
        pctl.PlotLayer()

    return (boardxl, boardyl, boardwidth, boardheight)
Beispiel #13
0
def __ComputePoints(track, via, hpercent, vpercent, segs, follow_tracks,
                    trackLookup):
    """Compute all teardrop points"""
    start = track.GetStart()
    end = track.GetEnd()
    radius = via[1]/2.0
    w = track.GetWidth()/2

    if vpercent > 100:
        vpercent = 100

    # ensure that start is at the via/pad end
    if __PointDistance(end, via[0]) < radius:
        start, end = end, start

    # get normalized track vector
    # it will be used a base vector pointing in the track direction
    vecT = __NormalizeVector(end - start)

    # Find point of intersection between track and edge of via
    # This normalizes teardrop lengths
    bdelta = FromMM(0.01)
    backoff=0
    while backoff<radius:
        np = start + wxPoint( vecT[0]*backoff, vecT[1]*backoff )
        if __PointDistance(np, via[0]) >= radius:
            break
        backoff += bdelta
    start=np

    # vec now points from via to intersect point
    vec = __NormalizeVector(start - via[0])

    # choose a teardrop length
    targetLength = via[1]*(hpercent/100.0)
    n = min(targetLength, track.GetLength() - backoff)
    consumed = 0

    if follow_tracks:
        # if not long enough, attempt to walk back along the curved track
        while n+consumed < targetLength:
            match, t = __FindTouchingTrack(track, end, trackLookup)
            if (match == False):
                break
    
            # [if angle is outside tolerance: break ?]
    
            consumed += n
            n = min(targetLength-consumed, t.GetLength())
            track = t
            end = t.GetEnd()
            start = t.GetStart()
            if match != STARTPOINT:
                start, end = end, start
    
        # Track may now not point directly at via
        vecT = __NormalizeVector(end - start)

    # if shortened, shrink width too
    if n+consumed < targetLength:
        minVpercent = 100* float(w) / float(radius)
        vpercent = vpercent*n/targetLength + minVpercent*(1-n/targetLength)

    # find point on the track, sharp end of the teardrop
    pointB = start + wxPoint( vecT[0]*n +vecT[1]*w , vecT[1]*n -vecT[0]*w )
    pointA = start + wxPoint( vecT[0]*n -vecT[1]*w , vecT[1]*n +vecT[0]*w )

    # via side points
    d = asin(vpercent/100.0)
    vecC = [vec[0]*cos(d)+vec[1]*sin(d), -vec[0]*sin(d)+vec[1]*cos(d)]
    d = asin(-vpercent/100.0)
    vecE = [vec[0]*cos(d)+vec[1]*sin(d), -vec[0]*sin(d)+vec[1]*cos(d)]
    pointC = via[0] + wxPoint(int(vecC[0] * radius), int(vecC[1] * radius))
    pointE = via[0] + wxPoint(int(vecE[0] * radius), int(vecE[1] * radius))

    # Introduce a last point in order to cover the via centre.
    # If not, the zone won't be filled
    pointD = via[0] + wxPoint(int(vec[0]*-0.5*radius), int(vec[1]*-0.5*radius))

    pts = [pointA, pointB, pointC, pointD, pointE]
    if segs > 2:
        pts = __ComputeCurved(vpercent, w, vecT, via, pts, segs)

    return pts
Beispiel #14
0
 def _configure_plot_ctrl(self, po, output_dir):
     super()._configure_plot_ctrl(po, output_dir)
     po.SetMirror(self.mirror_plot)
     if GS.kicad_version_n < KICAD_VERSION_5_99:
         po.SetLineWidth(FromMM(self.line_width))
     po.SetNegative(self.negative_plot)
Beispiel #15
0
import sys

filename=sys.argv[1]


plotDir = "../new_CAM_PROFI/"

board = pcbnew.LoadBoard(filename)
pctl = pcbnew.PLOT_CONTROLLER(board)

popt = pctl.GetPlotOptions()

popt.SetOutputDirectory(plotDir)

popt.SetPlotFrameRef(False) 
popt.SetLineWidth(FromMM(0.35))

popt.SetAutoScale(False)
popt.SetScale(1)
popt.SetMirror(False)
popt.SetUseGerberAttributes(True)
popt.SetUseGerberProtelExtensions(False)
popt.SetExcludeEdgeLayer(False);
popt.SetScale(1)
popt.SetUseAuxOrigin(True)

popt.SetSubtractMaskFromSilk(False)



plot_plan = [