Skip to content

Commit 49ffa8a

Browse files
author
devbisme
committed
Merge branch 'multi_unit_name' of https://github.com/mairas/KiPart into unitdisplayname
2 parents 069ece4 + 947679e commit 49ffa8a

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

kipart/kipart.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,13 @@ def symbol_to_csv_rows(symbol):
612612
rows.append(["pin", "name", "type", "side", "unit", "style", "hidden"])
613613

614614
# Process units and pins
615-
for unit_id, unit in enumerate(units, 1):
616-
unit_id = symbol_name + "_" + str(unit_id)
615+
for unit_index, unit in enumerate(units, 1):
616+
# Check if the unit has a custom unit_name, otherwise use unit number
617+
unit_name_search = unit.search("/symbol/unit_name", ignore_case=True)
618+
if unit_name_search:
619+
unit_id = unit_name_search[0][1]
620+
else:
621+
unit_id = str(unit_index)
617622
pins = unit.search("/symbol/pin", ignore_case=True)
618623
for pin in pins:
619624
number = pin.search("/pin/number", ignore_case=True)[0][1]
@@ -1110,6 +1115,11 @@ def rows_to_symbol(
11101115

11111116
# Begin instantiating the Sexp for this unit of the symbol.
11121117
unit_sexp = Sexp(["symbol", total_unit_name])
1118+
1119+
# If the unit has a custom name defined in the CSV and it's a multi-unit symbol,
1120+
# add the unit_name to the KiCad symbol definition
1121+
if len(units) > 1 and unit_id != DEFAULT_UNIT_ID:
1122+
unit_sexp.append(["unit_name", unit_id])
11131123

11141124
# Calculate dimensions for each side of the symbol unit based on pin counts and text sizes.
11151125
# At this point, we assume each side is oriented vertically with horizontal pins

tests/unit/test_kipart.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def test_symbol_to_csv_rows():
112112
["Reference:", "U"],
113113
["Value:", "my_part"],
114114
["pin", "name", "type", "side", "unit", "style", "hidden"],
115-
["1", "P1", "input", "left", "my_part_1", "line", "no"],
116-
["2", "P2", "output", "right", "my_part_1", "line", "yes"],
115+
["1", "P1", "input", "left", "1", "line", "no"],
116+
["2", "P2", "output", "right", "1", "line", "yes"],
117117
]
118118
rows = symbol_to_csv_rows(Sexp(sexp))
119119
assert rows == expected_rows
@@ -314,13 +314,13 @@ def test_library_to_csv(tmp_path):
314314
["Reference:", "U"],
315315
["Value:", "my_part"],
316316
["pin", "name", "type", "side", "unit", "style", "hidden"],
317-
["1", "P1", "input", "left", "my_part_1", "line", "no"],
317+
["1", "P1", "input", "left", "1", "line", "no"],
318318
[],
319319
["part2", ""],
320320
["Reference:", "U"],
321321
["Value:", "part2"],
322322
["pin", "name", "type", "side", "unit", "style", "hidden"],
323-
["1", "OUT", "output", "left", "part2_1", "line", "no"],
323+
["1", "OUT", "output", "left", "1", "line", "no"],
324324
]
325325
with open(output_path) as f:
326326
reader = csv.reader(f)

0 commit comments

Comments
 (0)