Skip to content

Commit

Permalink
Validate V-cuts
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Nov 12, 2024
1 parent 86917ce commit f972993
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions kikit/panelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def save(self, reconstructArcs: bool=False, refillAllZones: bool=False,
for e in boardsEdges:
e.SetWidth(edgeWidth)

self._validateVCuts()
vcuts = self._renderVCutH() + self._renderVCutV()
keepouts = []
for cut, clearanceArea in vcuts:
Expand Down Expand Up @@ -1207,6 +1208,32 @@ def _setVCutLabelStyle(self, label, origin, position):
label.SetTextSize(toKiCADPoint((self.vCutSettings.textSize, self.vCutSettings.textSize)))
label.SetHorizJustify(EDA_TEXT_HJUSTIFY_T.GR_TEXT_HJUSTIFY_LEFT)

def _validateVCuts(self, tolerance=fromMm(1)):
"""
Validates V-cuts for cuttitng the PCBs. Renders the violations into the
PCB as a side effect.
"""
if len(self.hVCuts) == 0 and len(self.vVCuts) == 0:
return

collisionPolygons = shapely.ops.unary_union([x.substrates.buffer(-tolerance) for x in self.substrates])
minx, miny, maxx, maxy = self.panelBBox()

lines = \
[LineString([(minx, y), (maxx, y)]) for y in self.hVCuts] + \
[LineString([(x, miny), (x, maxy)]) for x in self.vVCuts]

error_message = "V-Cut cuts the original PCBs. You should:\n"
error_message += "- either reconsider your tab placement,\n"
error_message += "- or use different cut type – e.g., mouse bites."
for line in lines:
for geom in listGeometries(collisionPolygons.intersection(line)):
if geom.is_empty:
continue
annotationPos = sorted(geom.coords, key=lambda p: -p[1])[0]
self._renderLines([geom], Layer.Margin)
self.reportError(toKiCADPoint(annotationPos), error_message)

def _renderVCutV(self):
""" return list of PCB_SHAPE V-Cuts """
bBox = self.boardSubstrate.boundingBox()
Expand Down

0 comments on commit f972993

Please sign in to comment.