Skip to content
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
44 changes: 34 additions & 10 deletions kikit/panelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,11 +1599,14 @@ def makeTightFrame(self, widthH: KiLength, widthV: KiLength, slotwidth: KiLength

def makeRailsTb(self, thickness: KiLength, minHeight: KiLength = 0,
maxHeight: Optional[KiLength] = None,
minWidth: KiLength = 0,
maxWidth: Optional[KiLength] = None,
vspace: Optional[KiLength] = None) -> None:
"""
Adds a rail to top and bottom. You can specify minimal height the panel
has to feature. You can also specify maximal height of the panel. If the
height would be exceeded, error is set.
height would be exceeded, error is set. You can also specify minimal and
maximal width to extend the rails beyond the board area.

If vspace is specified, the rails are placed at exact vspace distance
from the board bounding box (using boardsBBox). If vspace is None, the
Expand All @@ -1616,26 +1619,38 @@ def makeRailsTb(self, thickness: KiLength, minHeight: KiLength = 0,
self.reportError(toKiCADPoint((maxx, maxy)), f"Panel height {height / units.mm} mm exceeds the limit {maxHeight / units.mm} mm")
if height < minHeight:
thickness = (minHeight - maxy + miny) // 2 - vspace
topRail = box(minx, maxy + vspace, maxx, maxy + vspace + thickness)
bottomRail = box(minx, miny - vspace, maxx, miny - vspace - thickness)
topYInner, topYOuter = maxy + vspace, maxy + vspace + thickness
botYInner, botYOuter = miny - vspace, miny - vspace - thickness
else:
minx, miny, maxx, maxy = self.panelBBox()
height = maxy - miny + 2 * thickness
if maxHeight is not None and height > maxHeight:
self.reportError(toKiCADPoint((maxx, maxy)), f"Panel height {height / units.mm} mm exceeds the limit {maxHeight / units.mm} mm")
if height < minHeight:
thickness = (minHeight - maxy + miny) // 2
topRail = box(minx, maxy, maxx, maxy + thickness)
bottomRail = box(minx, miny, maxx, miny - thickness)
topYInner, topYOuter = maxy, maxy + thickness
botYInner, botYOuter = miny, miny - thickness
width = maxx - minx
if maxWidth is not None and width > maxWidth:
self.reportError(toKiCADPoint((maxx, maxy)), f"Panel width {width / units.mm} mm exceeds the limit {maxWidth / units.mm} mm")
if width < minWidth:
diff = minWidth - width
minx -= diff // 2
maxx += diff - diff // 2
topRail = box(minx, topYInner, maxx, topYOuter)
bottomRail = box(minx, botYInner, maxx, botYOuter)
self.appendSubstrate(topRail)
self.appendSubstrate(bottomRail)

def makeRailsLr(self, thickness: KiLength, minWidth: KiLength = 0,
maxWidth: Optional[KiLength] = None,
minHeight: KiLength = 0,
maxHeight: Optional[KiLength] = None,
hspace: Optional[KiLength] = None) -> None:
"""
Adds a rail to left and right. You can specify minimal width the panel
has to feature.
has to feature. You can also specify minimal and maximal height to
extend the rails beyond the board area.

If hspace is specified, the rails are placed at exact hspace distance
from the board bounding box (using boardsBBox). If hspace is None, the
Expand All @@ -1648,17 +1663,26 @@ def makeRailsLr(self, thickness: KiLength, minWidth: KiLength = 0,
self.reportError(toKiCADPoint((maxx, maxy)), f"Panel width {width / units.mm} mm exceeds the limit {maxWidth / units.mm} mm")
if width < minWidth:
thickness = (minWidth - maxx + minx) // 2 - hspace
leftRail = box(minx - hspace - thickness, miny, minx - hspace, maxy)
rightRail = box(maxx + hspace, miny, maxx + hspace + thickness, maxy)
leftXOuter, leftXInner = minx - hspace - thickness, minx - hspace
rightXInner, rightXOuter = maxx + hspace, maxx + hspace + thickness
else:
minx, miny, maxx, maxy = self.panelBBox()
width = maxx - minx + 2 * thickness
if maxWidth is not None and width > maxWidth:
self.reportError(toKiCADPoint((maxx, maxy)), f"Panel width {width / units.mm} mm exceeds the limit {maxWidth / units.mm} mm")
if width < minWidth:
thickness = (minWidth - maxx + minx) // 2
leftRail = box(minx - thickness, miny, minx, maxy)
rightRail = box(maxx, miny, maxx + thickness, maxy)
leftXOuter, leftXInner = minx - thickness, minx
rightXInner, rightXOuter = maxx, maxx + thickness
height = maxy - miny
if maxHeight is not None and height > maxHeight:
self.reportError(toKiCADPoint((maxx, maxy)), f"Panel height {height / units.mm} mm exceeds the limit {maxHeight / units.mm} mm")
if height < minHeight:
diff = minHeight - height
miny -= diff // 2
maxy += diff - diff // 2
leftRail = box(leftXOuter, miny, leftXInner, maxy)
rightRail = box(rightXInner, miny, rightXOuter, maxy)
self.appendSubstrate(leftRail)
self.appendSubstrate(rightRail)

Expand Down
2 changes: 2 additions & 0 deletions kikit/panelize_ui_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,14 @@ def buildFraming(preset, panel):
if type == "railstb":
panel.makeRailsTb(framingPreset["width"],
framingPreset["mintotalheight"], framingPreset["maxtotalheight"],
framingPreset["mintotalwidth"], framingPreset["maxtotalwidth"],
vspace=framingPreset["vspace"])
addFilletAndChamfer(framingPreset, panel)
return []
if type == "railslr":
panel.makeRailsLr(framingPreset["width"],
framingPreset["mintotalwidth"], framingPreset["maxtotalwidth"],
framingPreset["mintotalheight"], framingPreset["maxtotalheight"],
hspace=framingPreset["hspace"])
addFilletAndChamfer(framingPreset, panel)
return []
Expand Down
8 changes: 4 additions & 4 deletions kikit/panelize_ui_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,19 +506,19 @@ def ppCuts(section):
typeIn(["frame", "railstb", "railslr", "tightframe", "plugin"]),
"Width of the framing"),
"mintotalheight": SLength(
typeIn(["frame", "railstb", "tightframe", "plugin"]),
typeIn(["frame", "railstb", "railslr", "tightframe", "plugin"]),
"Minimal height of the panel"
),
"mintotalwidth": SLength(
typeIn(["frame", "raillr", "tightframe", "plugin"]),
typeIn(["frame", "railstb", "railslr", "tightframe", "plugin"]),
"Minimal width of the panel"
),
"maxtotalheight": SLength(
typeIn(["frame", "railstb", "tightframe", "plugin"]),
typeIn(["frame", "railstb", "railslr", "tightframe", "plugin"]),
"Maximal height of the panel"
),
"maxtotalwidth": SLength(
typeIn(["frame", "raillr", "tightframe", "plugin"]),
typeIn(["frame", "railstb", "railslr", "tightframe", "plugin"]),
"Maximal width of the panel"
),
"slotwidth": SLength(
Expand Down