From dd388470be31d19e88839e5bdb711f44a495a1ae Mon Sep 17 00:00:00 2001 From: Mattia Fiumara Date: Wed, 25 Mar 2026 18:09:24 +0100 Subject: [PATCH] Add layer option to move_component to support flipping components Adds an optional `layer` parameter (e.g., 'F.Cu', 'B.Cu') to the move_component tool. When specified, the component is flipped to the target layer if it's not already on it. The response now also includes the component's layer after the move. Co-Authored-By: Claude Opus 4.6 --- python/commands/component.py | 12 +++++++++++- src/tools/component.ts | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/python/commands/component.py b/python/commands/component.py index c1bb98c..472fec0 100644 --- a/python/commands/component.py +++ b/python/commands/component.py @@ -176,6 +176,7 @@ class ComponentCommands: reference = params.get("reference") position = params.get("position") rotation = params.get("rotation") + layer = params.get("layer") if not reference or not position: return { @@ -204,6 +205,14 @@ class ComponentCommands: angle = pcbnew.EDA_ANGLE(rotation, pcbnew.DEGREES_T) module.SetOrientation(angle) + # Flip to target layer if specified + if layer: + current_layer = self.board.GetLayerName(module.GetLayer()) + if layer == "B.Cu" and current_layer != "B.Cu": + module.Flip(module.GetPosition(), False) + elif layer == "F.Cu" and current_layer != "F.Cu": + module.Flip(module.GetPosition(), False) + return { "success": True, "message": f"Moved component: {reference}", @@ -214,7 +223,8 @@ class ComponentCommands: "y": position["y"], "unit": position["unit"] }, - "rotation": rotation if rotation is not None else module.GetOrientation().AsDegrees() + "rotation": rotation if rotation is not None else module.GetOrientation().AsDegrees(), + "layer": self.board.GetLayerName(module.GetLayer()) } } diff --git a/src/tools/component.ts b/src/tools/component.ts index 8c9d773..e4da70f 100644 --- a/src/tools/component.ts +++ b/src/tools/component.ts @@ -117,8 +117,12 @@ export function registerComponentTools( .number() .optional() .describe("Optional new rotation in degrees"), + layer: z + .string() + .optional() + .describe("Optional target layer (e.g., 'F.Cu', 'B.Cu') - flips component if needed"), }, - async ({ reference, position, rotation }) => { + async ({ reference, position, rotation, layer }) => { logger.debug( `Moving component: ${reference} to ${position.x},${position.y} ${position.unit}`, ); @@ -126,6 +130,7 @@ export function registerComponentTools( reference, position, rotation, + layer, }); return {