fix(board-view): rebase onto main — fold responseMode + restore jpg
Rebased onto current main (d765bfe). Merged changes:
Board view (kicad-cli, cffi-free):
- Replace pcbnew/PLOT_CONTROLLER + cairosvg with kicad-cli SVG export
and cffi-free PNG conversion: pymupdf → inkscape → imagemagick chain
- pcbPath optional param with fallback to loaded board
- Restore jpg output via PIL post-processing on PNG bytes
- responseMode inline/file from main's #161: inline returns imageData,
file writes <board>_2d_view.<ext> and returns filePath
- shutil.which for cross-platform kicad-cli lookup
- Explicit TimeoutExpired catch; errorDetails on all error returns
- Validate fmt strictly; TypeScript returns image type for inline png/jpg
Schematic view (kicad_interface.py):
- Same cffi-free _svg_to_png helper for get_schematic_view and
get_schematic_view_region (pymupdf → inkscape → imagemagick)
Tests:
- Update test_get_board_2d_view_save_to_file.py to mock subprocess/
kicad-cli and _svg_to_png instead of PLOT_CONTROLLER/cairosvg
- All 5 responseMode tests pass
This commit is contained in:
@@ -229,29 +229,32 @@ BOARD_TOOLS = [
|
||||
"name": "get_board_2d_view",
|
||||
"title": "Render Board Preview",
|
||||
"description": (
|
||||
"Generates a 2D visual representation of the current board state as a PNG, JPG, or SVG image. "
|
||||
"Renders a 2D image of the PCB via kicad-cli (no pcbnew/cffi dependency). "
|
||||
"Supports PNG, JPG, and SVG output. "
|
||||
"Use responseMode to control how the image is returned. "
|
||||
'responseMode="inline" (default) returns the image bytes as a base64-encoded imageData '
|
||||
"string in the JSON response — convenient for small boards but may exceed message-size limits on "
|
||||
"large designs. "
|
||||
'responseMode="inline" (default) returns the image as base64-encoded imageData — '
|
||||
"convenient for small boards but may exceed message-size limits on large designs. "
|
||||
'responseMode="file" writes the image next to the .kicad_pcb file as '
|
||||
"<board>_2d_view.<ext> and returns a filePath; callers that can open local files should "
|
||||
"prefer this mode for large boards."
|
||||
"<board>_2d_view.<ext> and returns a filePath; prefer this mode for large boards."
|
||||
),
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"pcbPath": {
|
||||
"type": "string",
|
||||
"description": "Absolute path to the .kicad_pcb file. Falls back to the currently loaded board if omitted.",
|
||||
},
|
||||
"width": {
|
||||
"type": "number",
|
||||
"description": "Image width in pixels (default: 800)",
|
||||
"description": "Image width in pixels (default: 1600)",
|
||||
"minimum": 100,
|
||||
"default": 800,
|
||||
"default": 1600,
|
||||
},
|
||||
"height": {
|
||||
"type": "number",
|
||||
"description": "Image height in pixels (default: 600)",
|
||||
"description": "Image height in pixels (default: 1200)",
|
||||
"minimum": 100,
|
||||
"default": 600,
|
||||
"default": 1200,
|
||||
},
|
||||
"format": {
|
||||
"type": "string",
|
||||
@@ -262,7 +265,7 @@ BOARD_TOOLS = [
|
||||
"layers": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Optional list of layer names to include; all enabled layers if omitted",
|
||||
"description": "Layer names to include, e.g. [\"F.Cu\",\"B.Cu\",\"Edge.Cuts\"]. Omit for all layers.",
|
||||
},
|
||||
"responseMode": {
|
||||
"type": "string",
|
||||
@@ -270,7 +273,7 @@ BOARD_TOOLS = [
|
||||
"default": "inline",
|
||||
"description": (
|
||||
"How to return the image. "
|
||||
'"inline" (default): base64-encoded bytes in the imageData response field. '
|
||||
'"inline" (default): base64-encoded bytes in imageData. '
|
||||
'"file": write to <board>_2d_view.<ext> next to the PCB and return filePath.'
|
||||
),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user