Skip to content

Commit c4e2744

Browse files
committed
Fix courtyard exclusion ordering in panels
1 parent 69bdc63 commit c4e2744

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

kikit/drc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ def deserializeExclusion(exclusionText: str, board: pcbnew.BOARD) -> DrcExclusio
356356

357357
def serializeExclusion(exclusion: DrcExclusion) -> str:
358358
objIds = [x.m_Uuid.AsString() for x in exclusion.objects]
359+
# KiCad checks courtyard overlaps in UUID order. Duplicating footprints
360+
# assigns new UUIDs, so preserving the source violation's item order makes
361+
# the copied exclusion match only when the new UUIDs happen to have the
362+
# same relative order.
363+
if exclusion.type == "courtyards_overlap":
364+
objIds.sort()
359365
while len(objIds) < 2:
360366
objIds.append("00000000-0000-0000-0000-000000000000")
361367
return "|".join([

test/units/test_drc.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from types import SimpleNamespace
2+
3+
from kikit.drc import DrcExclusion, serializeExclusion
4+
5+
6+
def item_with_uuid(uuid_value):
7+
return SimpleNamespace(
8+
m_Uuid=SimpleNamespace(AsString=lambda: uuid_value)
9+
)
10+
11+
12+
def test_serializeExclusionSortsCourtyardOverlapItemsByUuid():
13+
exclusion = DrcExclusion(
14+
"courtyards_overlap",
15+
(10, 20),
16+
[item_with_uuid("bbbbbbbb"), item_with_uuid("aaaaaaaa")]
17+
)
18+
19+
assert serializeExclusion(exclusion) == (
20+
"courtyards_overlap|10|20|aaaaaaaa|bbbbbbbb"
21+
)
22+
23+
24+
def test_serializeExclusionPreservesItemOrderForOtherViolations():
25+
exclusion = DrcExclusion(
26+
"clearance",
27+
(10, 20),
28+
[item_with_uuid("bbbbbbbb"), item_with_uuid("aaaaaaaa")]
29+
)
30+
31+
assert serializeExclusion(exclusion) == (
32+
"clearance|10|20|bbbbbbbb|aaaaaaaa"
33+
)

0 commit comments

Comments
 (0)