feat: move_schematic_component with wire preservation (drag behavior)

When moving a schematic component, connected wires are stretched/shifted
to follow the component (like KiCAD's drag behaviour), preserving
connectivity instead of leaving dangling wire stubs.

Also fixes property labels (value, reference, etc.) so they shift with
the symbol rather than staying at their original positions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Eugene Mikhantyev
2026-03-29 20:18:38 +01:00
parent 74471ce72e
commit a152b75db3
4 changed files with 1100 additions and 25 deletions

View File

@@ -1124,6 +1124,56 @@ Note: operates on .kicad_sch files only. To modify a PCB footprint use edit_comp
},
);
// Move a placed symbol, dragging connected wires
server.tool(
"move_schematic_component",
"Move a placed symbol to a new position in the schematic. By default (preserveWires=true) wire endpoints touching the component's pins are stretched to follow the new position.",
{
schematicPath: z.string().describe("Path to the .kicad_sch file"),
reference: z.string().describe("Reference designator (e.g., R1, U1)"),
position: z
.object({ x: z.number(), y: z.number() })
.describe("New position in schematic mm coordinates"),
preserveWires: z
.boolean()
.optional()
.describe("Stretch connected wire endpoints to follow the move (default true)"),
},
async (args: {
schematicPath: string;
reference: string;
position: { x: number; y: number };
preserveWires?: boolean;
}) => {
const result = await callKicadScript("move_schematic_component", args);
if (result.success) {
const moved = result.wiresMoved ?? 0;
const removed = result.wiresRemoved ?? 0;
return {
content: [
{
type: "text",
text:
`Moved ${args.reference} from (${result.oldPosition.x}, ${result.oldPosition.y}) ` +
`to (${result.newPosition.x}, ${result.newPosition.y})` +
(moved > 0 ? `, ${moved} wire endpoint(s) updated` : "") +
(removed > 0 ? `, ${removed} zero-length wire(s) removed` : ""),
},
],
};
}
return {
content: [
{
type: "text",
text: `Failed to move component: ${result.message || "Unknown error"}`,
},
],
isError: true,
};
},
);
// Sync schematic to PCB board (equivalent to KiCAD F8 / "Update PCB from Schematic")
server.tool(
"sync_schematic_to_board",