Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions kipart/kipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ def rows_to_symbol(

# Extract user-specified properties between part name and pin data column names
row_idx = 1
custom_props = 0
for row in symbol_rows[1:]:
if len(row) == 2 and row[0].strip().endswith(":"):
row_idx += 1
Expand Down Expand Up @@ -994,7 +995,16 @@ def rows_to_symbol(
"fp_filters": "ki_fp_filters",
}[label.lower()]
except KeyError:
raise KeyError(f"Invalid property label '{label}' in part {part_name}")
# Custom properties go below the symbol
if "*" in label:
hide = "yes"
y = 0
label = label.replace("*", "")
else:
hide = "no"
y = -GRID_SPACING * (custom_props * 2 + 0.5)
custom_props += 1
properties[label] = [None, 0, y, "right", hide]
properties[label][0] = value
else:
# End of property rows, break out of the loop
Expand Down Expand Up @@ -1103,9 +1113,10 @@ def rows_to_symbol(
# after the properties are added below.
unit_sexps = []

# Store the coords of the top-left corner for each unit so we can place the
# Store the coords of the corners for each unit so we can place the
# properties where they won't run into any of the different-sized units.
unit_top_left_corner = []
unit_bottom_right_corner = []

# Create the Sexp for each unit and add it to the symbol Sexp.
for unit_id, unit in units.items():
Expand Down Expand Up @@ -1206,8 +1217,9 @@ def rows_to_symbol(
# Add the rectangle to the unit Sexp
unit_sexp.append(rect_sexp)

# Store the top-left corner of the unit for placing properties later.
# Store the corners of the unit for placing properties later.
unit_top_left_corner.append((x0, y1))
unit_bottom_right_corner.append((x1, y0))

if debug:
# For debugging, show the boxes that contain the pins on each side.
Expand Down Expand Up @@ -1343,16 +1355,20 @@ def rows_to_symbol(
# such that it doesn't overlap any of the different-sized units.
tl_x = min(unit_top_left_corner, key=lambda c: c[0])[0]
tl_y = max(unit_top_left_corner, key=lambda c: c[1])[1]
br_x = max(unit_bottom_right_corner, key=lambda c: c[0])[0]
br_y = min(unit_bottom_right_corner, key=lambda c: c[1])[1]
for name, [value, x_offset, y_offset, justify, hide] in properties.items():
size = FONT_SIZE
anchor_y = tl_y + size / 2 if y_offset >= 0 else br_y - size / 2
symbol_sexp.append(
[
"property",
name,
value,
["at", tl_x + x_offset, tl_y + y_offset, 0],
["at", tl_x + x_offset, anchor_y + y_offset, 0],
[
"effects",
["font", ["size", FONT_SIZE, FONT_SIZE]],
["font", ["size", size, size]],
["justify", justify],
["hide", hide],
],
Expand Down