Merge pull request #196 from gcolonese/feat-schematic-justify

feat(schematic): expose justify directive on field labels via MCP
This commit is contained in:
mixelpixx
2026-05-30 12:15:28 -04:00
committed by GitHub
4 changed files with 409 additions and 7 deletions

View File

@@ -200,11 +200,21 @@ use edit_component instead.`,
x: z.number(),
y: z.number(),
angle: z.number().optional().default(0),
justify: z
.union([z.string(), z.array(z.string())])
.optional()
.describe(
'Text justification: "left", "right", "center", "top", "bottom", or combined ' +
'"left top" / "right bottom". Array form ["left", "top"] is also accepted. ' +
'Omit to leave the existing justify unchanged. Pass "center" to reset to ' +
"the KiCad default (removes the justify directive).",
),
}),
)
.optional()
.describe(
'Reposition field labels: map of field name to {x, y, angle} (e.g. {"Reference": {"x": 12.5, "y": 17.0}})',
"Reposition field labels: map of field name to {x, y, angle, justify?} " +
'(e.g. {"Reference": {"x": 12.5, "y": 17.0, "justify": "left"}})',
),
properties: z
.record(
@@ -252,7 +262,10 @@ use edit_component instead.`,
footprint?: string;
value?: string;
newReference?: string;
fieldPositions?: Record<string, { x: number; y: number; angle?: number }>;
fieldPositions?: Record<
string,
{ x: number; y: number; angle?: number; justify?: string | string[] }
>;
properties?: Record<
string,
| string
@@ -267,6 +280,16 @@ use edit_component instead.`,
>;
removeProperties?: string[];
}) => {
// Normalise array-form justify (["left", "top"]) to the space-separated
// string form ("left top") that the Python backend expects.
if (args.fieldPositions) {
for (const fieldName of Object.keys(args.fieldPositions)) {
const pos = args.fieldPositions[fieldName];
if (Array.isArray(pos.justify)) {
pos.justify = (pos.justify as string[]).join(" ");
}
}
}
const result = await callKicadScript("edit_schematic_component", args);
if (result.success) {
const updated = result.updated ?? {};
@@ -349,6 +372,14 @@ with the \`properties\` parameter instead.`,
"Hide the property text on the schematic canvas. Defaults to true for newly-created custom properties.",
),
fontSize: z.number().optional().describe("Font size in mm for the label (default: 1.27)"),
justify: z
.string()
.optional()
.describe(
'Text justification for the property label. KiCad alignment keywords: "left", "right", ' +
'"center", "top", "bottom", or combined e.g. "left top". Omit to leave unchanged. ' +
'Pass "center" to reset to the KiCad default.',
),
},
async (args: {
schematicPath: string;
@@ -360,6 +391,7 @@ with the \`properties\` parameter instead.`,
angle?: number;
hide?: boolean;
fontSize?: number;
justify?: string;
}) => {
const result = await callKicadScript("set_schematic_component_property", args);
if (result.success) {