From 409b18c83def15c61bf2b3a16b932f2d5a611662 Mon Sep 17 00:00:00 2001 From: Judson Stephenson Date: Thu, 4 Jun 2026 14:51:49 -0500 Subject: [PATCH] fix(board-view): frame get_board_2d_view to the board, not the A4 sheet kicad-cli's `pcb export svg` defaults to `--page-size-mode 0` (the full drawing sheet), so only the area inside the sheet is plotted -- board geometry past the page edge is left out. Pass `--exclude-drawing-sheet` and `--page-size-mode 2` (board area only) so the output is sized to the board's bounding box and the full board is rendered. Both flags exist since KiCad 7, so KiCad 8/9 are unaffected. --- python/commands/board/view.py | 8 ++++++++ tests/test_get_board_2d_view_save_to_file.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/python/commands/board/view.py b/python/commands/board/view.py index 8156ecf..bc9d78f 100644 --- a/python/commands/board/view.py +++ b/python/commands/board/view.py @@ -198,6 +198,14 @@ class BoardViewCommands: output_svg, "--mode-single", "--black-and-white", + # Render the board, not the drawing sheet. kicad-cli's + # default (page-size-mode 0) plots only the area inside the + # sheet, so board geometry past the page edge is left out. + # Mode 2 sizes the output to the board's bounding box; + # --exclude-drawing-sheet drops the title block. + "--exclude-drawing-sheet", + "--page-size-mode", + "2", ] if layers: cmd += ["--layers", ",".join(layers)] diff --git a/tests/test_get_board_2d_view_save_to_file.py b/tests/test_get_board_2d_view_save_to_file.py index 5e3f7a5..17940c0 100644 --- a/tests/test_get_board_2d_view_save_to_file.py +++ b/tests/test_get_board_2d_view_save_to_file.py @@ -79,6 +79,19 @@ def test_inline_png_returns_base64_image_data(tmp_path): assert "filePath" not in result +@pytest.mark.unit +def test_export_frames_to_board_area(tmp_path): + """The export drops the drawing sheet and crops to the board area, so a small + board isn't rendered on a mostly-empty A4 page (kicad-cli's default).""" + cmd, root, board_path = _make_view_cmd(tmp_path) + w1, w2, w3 = _patch_kicad_cli(root) + with w1, w2 as run, w3, patch("commands.board.view._svg_to_png", return_value=_FAKE_PNG): + cmd.get_board_2d_view({"pcbPath": str(board_path), "format": "png"}) + argv = run.call_args[0][0] + assert "--exclude-drawing-sheet" in argv + assert argv[argv.index("--page-size-mode") + 1] == "2" + + @pytest.mark.unit def test_inline_svg_returns_base64_image_data(tmp_path): """responseMode='inline' with format='svg' returns base64-encoded SVG in imageData."""