Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create stencil for adhesive layers #374

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions kikit/export.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
# Based on https://github.com/KiCad/kicad-source-mirror/blob/master/demos/python_scripts_examples/gen_gerber_and_drill_files_board.py
import sys
import os
from dataclasses import dataclass

from pcbnewTransition import pcbnew
from pcbnewTransition.pcbnew import *

from kikit.defs import Layer


@dataclass
class LayerToPlot:
name: str
id: int
description: str


CuTop = LayerToPlot("CuTop", pcbnew.F_Cu, "Top layer")
CuBottom = LayerToPlot("CuBottom", pcbnew.B_Cu, "Bottom layer")
PasteBottom = LayerToPlot("PasteBottom", pcbnew.B_Paste, "Paste Bottom")
PasteTop = LayerToPlot("PasteTop", pcbnew.F_Paste, "Paste top")
SilkTop = LayerToPlot("SilkTop", pcbnew.F_SilkS, "Silk top")
SilkBottom = LayerToPlot("SilkBottom", pcbnew.B_SilkS, "Silk top")
MaskBottom = LayerToPlot("MaskBottom", pcbnew.B_Mask, "Mask bottom")
MaskTop = LayerToPlot("MaskTop", pcbnew.F_Mask, "Mask top")
EdgeCuts = LayerToPlot("EdgeCuts", pcbnew.Edge_Cuts, "Edges")
CmtUser = LayerToPlot("CmtUser", pcbnew.Cmts_User, "V-CUT")
AdhesiveTop = LayerToPlot("AdhesiveTop", pcbnew.F_Adhes, "Adhesive top")
AdhesiveBottom = LayerToPlot("AdhesiveBottom", pcbnew.B_Adhes, "Adhesive bottom")

fullGerberPlotPlan = [
# name, id, comment
("CuTop", F_Cu, "Top layer"),
("CuBottom", B_Cu, "Bottom layer"),
("PasteBottom", B_Paste, "Paste Bottom"),
("PasteTop", F_Paste, "Paste top"),
("SilkTop", F_SilkS, "Silk top"),
("SilkBottom", B_SilkS, "Silk top"),
("MaskBottom", B_Mask, "Mask bottom"),
("MaskTop", F_Mask, "Mask top"),
("EdgeCuts", Edge_Cuts, "Edges"),
("CmtUser", Cmts_User, "V-CUT")
CuTop,
CuBottom,
PasteBottom,
PasteTop,
SilkTop,
SilkBottom,
MaskBottom,
MaskTop,
EdgeCuts,
CmtUser
]

exportSettingsJlcpcb = {
Expand Down Expand Up @@ -52,12 +73,13 @@
}


def hasCopper(plotPlan):
for _, layer, _ in plotPlan:
if layer in [F_Cu, B_Cu]:
def hasCopper(plotPlan: list[LayerToPlot]):
for layer_to_plot in plotPlan:
if layer_to_plot.id in [F_Cu, B_Cu]:
return True
return False


def setExcludeEdgeLayer(plotOptions, excludeEdge):
try:
plotOptions.SetExcludeEdgeLayer(excludeEdge)
Expand All @@ -67,7 +89,7 @@ def setExcludeEdgeLayer(plotOptions, excludeEdge):
else:
plotOptions.SetLayerSelection(LSET(Layer.Edge_Cuts))

def gerberImpl(boardfile, outputdir, plot_plan=fullGerberPlotPlan, drilling=True, settings=exportSettingsJlcpcb):
def gerberImpl(boardfile: str, outputdir: str, plot_plan: list[LayerToPlot]=fullGerberPlotPlan, drilling=True, settings=exportSettingsJlcpcb):
"""
Export board to gerbers.

Expand Down Expand Up @@ -109,16 +131,16 @@ def gerberImpl(boardfile, outputdir, plot_plan=fullGerberPlotPlan, drilling=True
# prepare the gerber job file
jobfile_writer = GERBER_JOBFILE_WRITER(board)

for name, id, comment in plot_plan:
if id <= B_Cu:
for layer_to_plot in plot_plan:
if layer_to_plot.id <= B_Cu:
popt.SetSkipPlotNPTH_Pads(True)
else:
popt.SetSkipPlotNPTH_Pads(False)

pctl.SetLayer(id)
suffix = "" if settings["NoSuffix"] else name
pctl.OpenPlotfile(suffix, PLOT_FORMAT_GERBER, comment)
jobfile_writer.AddGbrFile(id, os.path.basename(pctl.GetPlotFileName()))
pctl.SetLayer(layer_to_plot.id)
suffix = "" if settings["NoSuffix"] else layer_to_plot.name
pctl.OpenPlotfile(suffix, PLOT_FORMAT_GERBER, layer_to_plot.description)
jobfile_writer.AddGbrFile(layer_to_plot.id, os.path.basename(pctl.GetPlotFileName()))
if pctl.PlotLayer() == False:
print("plot error")

Expand Down Expand Up @@ -186,16 +208,15 @@ def pasteDxfExport(board, plotDir):
popt.SetDXFPlotPolygonMode(False)

plot_plan = [
# name, id, comment
("PasteBottom", B_Paste, "Paste Bottom"),
("PasteTop", F_Paste, "Paste top"),
("EdgeCuts", Edge_Cuts, "Edges"),
PasteBottom,
PasteTop,
EdgeCuts
]

output = []
for name, id, comment in plot_plan:
pctl.SetLayer(id)
pctl.OpenPlotfile(name, PLOT_FORMAT_DXF, comment)
for layer_to_plot in plot_plan:
pctl.SetLayer(layer_to_plot.id)
pctl.OpenPlotfile(layer_to_plot.name, PLOT_FORMAT_DXF, layer_to_plot.description)
output.append(pctl.GetPlotFileName())
if pctl.PlotLayer() == False:
print("plot error")
Expand Down
4 changes: 2 additions & 2 deletions kikit/fab/oshpark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os
import shutil
from pathlib import Path
from kikit.export import gerberImpl, exportSettingsOSHPark, fullGerberPlotPlan
from kikit.export import gerberImpl, exportSettingsOSHPark, fullGerberPlotPlan, CmtUser
from kikit.fab.common import ensurePassingDrc, expandNameTemplate

plotPlanNoVCuts = [(name, id, comment) for name, id, comment in fullGerberPlotPlan if name != "CmtUser"]
plotPlanNoVCuts = [layer_to_plot for layer_to_plot in fullGerberPlotPlan if layer_to_plot.id is not CmtUser.id]

def exportOSHPark(board, outputdir, nametemplate, drc):
"""
Expand Down
9 changes: 6 additions & 3 deletions kikit/panelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ def makeCutsToLayer(self, cuts, layer=Layer.Cmts_User, prolongation=fromMm(0)):
self.board.Add(segment)

def addNPTHole(self, position: VECTOR2I, diameter: KiLength,
paste: bool=False, ref: Optional[str]=None) -> None:
paste: bool=False, adhesive: bool=False, ref: Optional[str]=None) -> None:
"""
Add a drilled non-plated hole to the position (`VECTOR2I`) with given
diameter. The paste option allows to place the hole on the paste layers.
Expand All @@ -1515,11 +1515,14 @@ def addNPTHole(self, position: VECTOR2I, diameter: KiLength,
for pad in footprint.Pads():
pad.SetDrillSize(toKiCADPoint((diameter, diameter)))
pad.SetSize(toKiCADPoint((diameter, diameter)))
layerSet = pad.GetLayerSet()
if paste:
layerSet = pad.GetLayerSet()
layerSet.AddLayer(Layer.F_Paste)
layerSet.AddLayer(Layer.B_Paste)
pad.SetLayerSet(layerSet)
if adhesive:
layerSet.AddLayer(Layer.F_Adhes)
layerSet.AddLayer(Layer.B_Adhes)
pad.SetLayerSet(layerSet)
if ref is not None:
footprint.SetReference(ref)
self.board.Add(footprint)
Expand Down
Loading