kicad-sch-api 0.3.1__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kicad-sch-api might be problematic. Click here for more details.

@@ -1138,6 +1138,55 @@ class Schematic:
1138
1138
  logger.debug(f"Added text box: '{text}' at {position} size {size}")
1139
1139
  return text_box.uuid
1140
1140
 
1141
+ def add_image(
1142
+ self,
1143
+ position: Union[Point, Tuple[float, float]],
1144
+ data: str,
1145
+ scale: float = 1.0,
1146
+ uuid: Optional[str] = None,
1147
+ ) -> str:
1148
+ """
1149
+ Add an image element.
1150
+
1151
+ Args:
1152
+ position: Image position
1153
+ data: Base64-encoded image data
1154
+ scale: Image scale factor (default 1.0)
1155
+ uuid: Optional UUID (auto-generated if None)
1156
+
1157
+ Returns:
1158
+ UUID of created image element
1159
+ """
1160
+ if isinstance(position, tuple):
1161
+ position = Point(position[0], position[1])
1162
+
1163
+ from .types import Image
1164
+
1165
+ import uuid as uuid_module
1166
+
1167
+ image = Image(
1168
+ uuid=uuid if uuid else str(uuid_module.uuid4()),
1169
+ position=position,
1170
+ data=data,
1171
+ scale=scale,
1172
+ )
1173
+
1174
+ if "images" not in self._data:
1175
+ self._data["images"] = []
1176
+
1177
+ self._data["images"].append(
1178
+ {
1179
+ "uuid": image.uuid,
1180
+ "position": {"x": image.position.x, "y": image.position.y},
1181
+ "data": image.data,
1182
+ "scale": image.scale,
1183
+ }
1184
+ )
1185
+ self._modified = True
1186
+
1187
+ logger.debug(f"Added image at {position} with {len(data)} bytes of data")
1188
+ return image.uuid
1189
+
1141
1190
  def add_rectangle(
1142
1191
  self,
1143
1192
  start: Union[Point, Tuple[float, float]],
@@ -1592,9 +1641,7 @@ class Schematic:
1592
1641
  break
1593
1642
 
1594
1643
  # Fix string/symbol conversion issues in pin definitions
1595
- print(f"🔧 DEBUG: Before fix - checking for pin definitions...")
1596
1644
  self._fix_symbol_strings_recursively(modified_data)
1597
- print(f"🔧 DEBUG: After fix - symbol strings fixed")
1598
1645
 
1599
1646
  return modified_data
1600
1647
 
@@ -1607,15 +1654,10 @@ class Schematic:
1607
1654
  if isinstance(item, list):
1608
1655
  # Check for pin definitions that need fixing
1609
1656
  if len(item) >= 3 and item[0] == sexpdata.Symbol("pin"):
1610
- print(
1611
- f"🔧 DEBUG: Found pin definition: {item[:3]} - types: {[type(x) for x in item[:3]]}"
1612
- )
1613
1657
  # Fix pin type and shape - ensure they are symbols not strings
1614
1658
  if isinstance(item[1], str):
1615
- print(f"🔧 DEBUG: Converting pin type '{item[1]}' to symbol")
1616
1659
  item[1] = sexpdata.Symbol(item[1]) # pin type: "passive" -> passive
1617
1660
  if len(item) >= 3 and isinstance(item[2], str):
1618
- print(f"🔧 DEBUG: Converting pin shape '{item[2]}' to symbol")
1619
1661
  item[2] = sexpdata.Symbol(item[2]) # pin shape: "line" -> line
1620
1662
 
1621
1663
  # Recursively process nested lists
@@ -372,6 +372,20 @@ class SchematicRectangle:
372
372
  )
373
373
 
374
374
 
375
+ @dataclass
376
+ class Image:
377
+ """Image element in schematic."""
378
+
379
+ uuid: str
380
+ position: Point
381
+ data: str # Base64-encoded image data
382
+ scale: float = 1.0
383
+
384
+ def __post_init__(self):
385
+ if not self.uuid:
386
+ self.uuid = str(uuid4())
387
+
388
+
375
389
  @dataclass
376
390
  class Net:
377
391
  """Electrical net connecting components."""
@@ -0,0 +1,26 @@
1
+ """
2
+ Geometry module for KiCad schematic symbol bounding box calculations.
3
+
4
+ This module provides accurate bounding box calculations for KiCad symbols,
5
+ including font metrics and symbol geometry analysis.
6
+
7
+ Migrated from circuit-synth to kicad-sch-api for better architectural separation.
8
+ """
9
+
10
+ from .font_metrics import (
11
+ DEFAULT_PIN_LENGTH,
12
+ DEFAULT_PIN_NAME_OFFSET,
13
+ DEFAULT_PIN_NUMBER_SIZE,
14
+ DEFAULT_PIN_TEXT_WIDTH_RATIO,
15
+ DEFAULT_TEXT_HEIGHT,
16
+ )
17
+ from .symbol_bbox import SymbolBoundingBoxCalculator
18
+
19
+ __all__ = [
20
+ "SymbolBoundingBoxCalculator",
21
+ "DEFAULT_TEXT_HEIGHT",
22
+ "DEFAULT_PIN_LENGTH",
23
+ "DEFAULT_PIN_NAME_OFFSET",
24
+ "DEFAULT_PIN_NUMBER_SIZE",
25
+ "DEFAULT_PIN_TEXT_WIDTH_RATIO",
26
+ ]
@@ -0,0 +1,20 @@
1
+ """
2
+ Font metrics and text rendering constants for KiCad schematic text.
3
+
4
+ These constants are used for accurate text bounding box calculations
5
+ and symbol spacing in schematic layouts.
6
+ """
7
+
8
+ # KiCad default text size in mm
9
+ # Increased to better match actual KiCad rendering
10
+ DEFAULT_TEXT_HEIGHT = 2.54 # 100 mils (doubled from 50 mils)
11
+
12
+ # Default pin dimensions
13
+ DEFAULT_PIN_LENGTH = 2.54 # 100 mils
14
+ DEFAULT_PIN_NAME_OFFSET = 0.508 # 20 mils - offset from pin endpoint to label text
15
+ DEFAULT_PIN_NUMBER_SIZE = 1.27 # 50 mils
16
+
17
+ # Text width ratio for proportional font rendering
18
+ # KiCad uses proportional fonts where average character width is ~0.65x height
19
+ # This prevents label text from extending beyond calculated bounding boxes
20
+ DEFAULT_PIN_TEXT_WIDTH_RATIO = 0.65 # Width to height ratio for pin text (proportional font average)