fix: unwrap nested params in add_board_outline (SWIG + IPC paths)

Claude sends {shape:'rectangle', params:{x,y,width,height,...}} but handlers
were reading params.get('width') on the outer dict → None → wrong board size.

outline.py: extract inner = params.get('params', params) at method start,
read all dimensions from inner dict.

kicad_interface.py (_ipc_add_board_outline): delegate 'rectangle' to SWIG
path (same as 'rounded_rectangle') so Claude's shape+dims call is handled
correctly. For polygon IPC path: also unwrap inner params for points/width.
This commit is contained in:
Tom
2026-03-07 01:43:43 +01:00
parent f4d516f5c3
commit 44c5e7f388
2 changed files with 24 additions and 15 deletions

View File

@@ -27,28 +27,33 @@ class BoardOutlineCommands:
"errorDetails": "Load or create a board first",
}
# Claude sends dimensions nested inside a "params" key:
# {"shape": "rectangle", "params": {"x": 0, "y": 0, "width": 38, ...}}
# Unwrap the inner dict if present so we read dimensions from the right level.
inner = params.get("params", params)
shape = params.get("shape", "rectangle")
width = params.get("width")
height = params.get("height")
radius = params.get("radius")
width = inner.get("width")
height = inner.get("height")
radius = inner.get("radius")
# Accept both "cornerRadius" and "radius" (schema uses "radius" for rounded_rectangle)
corner_radius = params.get("cornerRadius", params.get("radius", 0) if shape == "rounded_rectangle" else 0)
points = params.get("points", [])
unit = params.get("unit", "mm")
corner_radius = inner.get("cornerRadius", inner.get("radius", 0) if shape == "rounded_rectangle" else 0)
points = inner.get("points", [])
unit = inner.get("unit", "mm")
# Position: accept top-left corner (x/y) or center (centerX/centerY).
# Default: top-left at (0,0) so the board occupies positive coordinate space
# and is consistent with component placement coordinates.
x = params.get("x")
y = params.get("y")
x = inner.get("x")
y = inner.get("y")
if x is not None or y is not None:
ox = x if x is not None else 0.0
oy = y if y is not None else 0.0
center_x = ox + (width or 0) / 2.0
center_y = oy + (height or 0) / 2.0
else:
raw_cx = params.get("centerX")
raw_cy = params.get("centerY")
raw_cx = inner.get("centerX")
raw_cy = inner.get("centerY")
if raw_cx is not None or raw_cy is not None:
center_x = raw_cx if raw_cx is not None else 0.0
center_y = raw_cy if raw_cy is not None else 0.0

View File

@@ -2192,9 +2192,11 @@ print("ok")
and correctly generates PCB_SHAPE arcs for rounded corners.
"""
shape = params.get("shape", "rectangle")
if shape == "rounded_rectangle":
# IPC path only supports straight segments — fall back to SWIG for arcs
logger.info("_ipc_add_board_outline: delegating rounded_rectangle to SWIG path for arc support")
if shape in ("rounded_rectangle", "rectangle"):
# IPC path only supports straight segments from a points list,
# but Claude sends rectangle/rounded_rectangle as shape+width+height.
# Fall back to the SWIG path which correctly handles both shapes.
logger.info(f"_ipc_add_board_outline: delegating {shape} to SWIG path")
return self.board_commands.add_board_outline(params)
try:
@@ -2205,8 +2207,10 @@ print("ok")
board = self.ipc_board_api._get_board()
points = params.get("points", [])
width = params.get("width", 0.1)
# Unwrap nested params (Claude sends {"shape":..., "params":{...}})
inner = params.get("params", params)
points = inner.get("points", params.get("points", []))
width = inner.get("width", params.get("width", 0.1))
if len(points) < 2:
return {