Add set_net_color: set/clear an individual net's display color override - #376
Add set_net_color: set/clear an individual net's display color override#376JMcordobamendez wants to merge 1 commit into
Conversation
|
Reviewed — the design is right and the diligence shows (the atomic .kicad_pro write, clear:true deleting the key rather than writing a sentinel, validating the net against NetsByName before touching the file, and cross-checking the dispatch entry against the failure mode documented in test_assign_net_to_class). NETINFO_ITEM genuinely has no color accessor, so pure JSON persistence in net_settings.net_colors is the correct shape, and this closes #375. Two changes needed before it can merge, the first of which will fail CI as filed:
One behavioral question to settle in the PR description rather than change: set_net_color hard-fails when no .kicad_pro exists next to the board, where assign_net_to_class (which this mirrors) degrades to a warning because it still updates SWIG state. Here there is no SWIG state to update, so hard-failing is defensible — just say so explicitly so the asymmetry reads as designed rather than accidental. CI was approved to run on this PR today; expect the registry failure above until item 1 lands. |
Closes mixelpixx#375. No tool currently exposes the PCB editor's "Net colors" panel. net_settings.net_colors lives only in <project>.kicad_pro, with no SWIG counterpart (NETINFO_ITEM has no color getter/setter), so this is pure JSON persistence following the same read/modify/write-atomically shape already used by assign_net_to_class. - set_net_color(net, color?, clear?): color is a #RRGGBB hex string, translated to KiCad's "rgb(r, g, b)" net_colors format. clear: true removes the override, reverting the net to its automatic/class color. - Validates the net exists on the board before writing (same check as assign_net_to_class). - Wired in all three places a tool needs to reach the router: TS schema (src/tools/routing.ts), the Python dispatch table (kicad_interface.py), and the Python-side tool_schemas.py registry — the last one because assign_net_to_class previously shipped without a dispatch-table entry (see test_assign_net_to_class.py's docstring) and I didn't want to repeat that gap for a new tool. - 25 new tests (tests/test_set_net_color.py) mirroring test_assign_net_to_class.py: hex parsing, the pure JSON transform, atomic file round-trip, and RoutingCommands.set_net_color wiring with a mocked board. Verified against a real KiCad 10.0.5 install (Windows, SWIG backend): opened a real multi-sheet board, set/overwrote/cleared colors on real nets, confirmed the .kicad_pro round-trips correctly and unrelated project content is untouched. Full test suite: 1806 passed (9 pre-existing failures unrelated to this change — Freerouting needs Java, which isn't installed in this environment, plus one Windows path- separator test).
c3d1494 to
2bc8431
Compare
|
Thanks for the review — all three points addressed. Rebased onto 1. Registry. While there, 2. The lazy regex. Gone. 3. The CIThe three failures were two causes, both fixed:
Verified locally with the same versions CI pins (Black 26.3.1, isort 8.0.1, Two things I found but deliberately did not change
Re-verified the behaviour end-to-end after the rebase against a realistic |
Closes #375.
What
set_net_color(net, color?, clear?)- set or clear an individual net'sdisplay color override (the PCB editor's "Net colors" panel). Cosmetic
only, doesn't touch routing or design rules.
Why this shape
net_settings.net_colorslives only in<project>.kicad_pro, as a flat{net_name: "rgb(r, g, b)"}map. There's no SWIG counterpart to keep insync -
NETINFO_ITEMhas no color getter/setter at all (checked the fullclass in
pcbnew.py) - so this is pure JSON persistence, following thesame read/modify/write-atomically shape
assign_net_to_classalreadyuses for net-class membership.
color: a#RRGGBBhex string, translated to KiCad's own"rgb(r, g, b)"format.clear: trueremoves the override entirely (rather than writing someempty/sentinel color), reverting the net to its automatic/class color
assign_net_to_classuses.Why this hard-fails without a
.kicad_pro, whereassign_net_to_classwarnsThe two look inconsistent on purpose, and it is worth stating so the
asymmetry reads as designed.
assign_net_to_classmirrors its change into SWIG state as well as theproject file. By the time it discovers the project file is missing, the
in-memory board has already been updated - the operation genuinely half
succeeded, and failing outright would misreport what happened. A warning
is the accurate answer there.
set_net_colorhas no SWIG half.NETINFO_ITEMexposes no coloraccessor, so
net_settings.net_colorsin the.kicad_prois theentire operation. With no project file there is nothing updated
anywhere, and returning a warning would tell the caller the color was
set when nothing was. So it fails.
Where it's wired
src/tools/routing.ts- Zod schema.src/tools/registry.ts-routingcategory entry, sosearch_toolscan discover it.
python/commands/routing.py-apply_net_color_to_project_settings/persist_net_color_to_project(pure functions, no SWIG) +RoutingCommands.set_net_color.python/kicad_interface.py- dispatch table entry.python/schemas/tool_schemas.py- matching entry for the Python-sideschema registry (
create_netclass/assign_net_to_classboth have onethere too).
README.md/docs/TOOL_INVENTORY.md- counts and listings.I added the
kicad_interface.pydispatch entry deliberately carefully:tests/test_assign_net_to_class.py's docstring documents that toolshipping registered in TS/the router but missing from the dispatch
table, silently returning
"Unknown command"for every call. Wanted tomake sure this one didn't repeat that.
Testing
tests/test_set_net_color.py(28 tests, new): hex parsing, the pureJSON transform (add/overwrite/clear, null-safety on a fresh project's
net_colors: null), atomic file round-trip, andRoutingCommands.set_net_colorwiring against a mocked board.failed. The failure is
test_ipc_open_board_path.py::test_returns_full_path_composed_from_project_and_filename,which is Windows-only and pre-existing - it asserts a POSIX path
against an
os.path.joinresult. Confirmed it fails identically on aclean
aa53d52worktree without this branch; it passes on CI's Linuxrunners.
tscbuilds clean, 73/73 vitest pass (includingregistry-completenessandreadme-counts).isort 8.0.1, flake8 7.3.0 over
python/andtests/, plus prettierand eslint on the changed files.
backend) on a real multi-sheet board: opened the project, set a color
on an uncolored net, overwrote an existing net's color, cleared
another, hit a nonexistent net and an invalid hex - all behaved as
expected, and the
.kicad_proround-trips correctly with unrelatedcontent untouched.
Happy to adjust scope or naming if you'd rather this look different -
net-class-level color (
NETCLASS.SetPcbColor, which does have a SWIGbinding) would be a reasonable follow-up but felt like a separate PR.