From d079fd26e58231a65eb64b7f6dfd571ce3dd8058 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Tue, 25 Nov 2025 17:17:27 -0800 Subject: [PATCH 1/2] Allow custom properties, which go below the symbol body Custom properties can have an asterisk in the name to make them hidden. --- kipart/kipart.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/kipart/kipart.py b/kipart/kipart.py index ab5aa1c..3439b9e 100644 --- a/kipart/kipart.py +++ b/kipart/kipart.py @@ -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 @@ -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 @@ -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(): @@ -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. @@ -1343,13 +1355,15 @@ 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_y = min(unit_bottom_right_corner, key=lambda c: c[1])[1] for name, [value, x_offset, y_offset, justify, hide] in properties.items(): + anchor_y = tl_y if y_offset >= 0 else br_y 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]], From 54f59397d6ab9266fc98007d22d0668e815a5da1 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Tue, 25 Nov 2025 18:25:49 -0800 Subject: [PATCH 2/2] Add a little breathing room on the properties --- kipart/kipart.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kipart/kipart.py b/kipart/kipart.py index 3439b9e..a0f9e5f 100644 --- a/kipart/kipart.py +++ b/kipart/kipart.py @@ -1355,9 +1355,11 @@ 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(): - anchor_y = tl_y if y_offset >= 0 else br_y + size = FONT_SIZE + anchor_y = tl_y + size / 2 if y_offset >= 0 else br_y - size / 2 symbol_sexp.append( [ "property", @@ -1366,7 +1368,7 @@ def rows_to_symbol( ["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], ],