Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support fix of tstamp and Graphic Items for Kicad 8 #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# kiutils - CHANGELOG

## v1.4.9 - 10.09.2024
- Fixed: support for KiCad 8: Updated handling to accommodate renaming of `tstamp` to `uuid`.
- Added: Net name association for GrPoly in graphic items on the board.

## v1.4.8 - 03.02.2024

### Non-breaking changes
Expand Down Expand Up @@ -68,7 +72,7 @@ This release adds initial KiCad v7 support.
- Changed: Default value of `Stroke.type` from "dash" to "default" - (PR #63)
- Changed: `Stroke.color` is now optional - (PR #63)
- Changed: `Stroke.type` is now optional - (PR #82)
- Changed: `Schematic.uuid` is now optional - (PR #63)
- Changed: `Schematic.tstamp` is now optional - (PR #63)
- Changed: `Property.id` is now optional - (PR #78)
- Changed: `SymbolPin.nameEffects` and `SymbolPin.numberEffects` are now optional - (PR #82)
- Changed: `PlotSettings.svgUseInch` and `PlotSettings.excludeEdgeLayer` are now optional - (PR #85)
Expand Down Expand Up @@ -126,7 +130,7 @@ This release adds initial KiCad v7 support.
- Changed: Replaced relative imports with absolute imports in the module structure - (PR #24)
- Changed: Migrated test framework to Python's `unittest` - (PR #21)
- Changed: `unit` token in class `kiutils.items.schitems.SchematicSymbol()` is now optional - (PR #26)
- Changed: `uuid` token in class `kiutils.schematic.Schematic()` is now optional - (PR #26)
- Changed: `tstamp` token in class `kiutils.schematic.Schematic()` is now optional - (PR #26)
- Changed: Order of how newlines are generated in `kiutils.schematic.Schematic().to_sexpr()` - (PR #26)
- Fixed: `angle` set to 0.0 (was `None`) when creating a new `kiutils.items.common.Property()` object (PR #27, fixes #19)
- Fixed: Footprint attributes object (`kiutils.footprint.Attributes()`) missing when certain
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = kiutils
version = 1.4.8
version = 1.4.9
author = Marvin Mager
author_email = [email protected]
description = Simple and SCM-friendly KiCad file parser for KiCad 6.0 and up
Expand Down
20 changes: 10 additions & 10 deletions src/kiutils/footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ class Pad():
"""The optional ``net`` token defines the integer number and name string of the net connection
for the pad."""

tstamp: Optional[str] = None # Used since KiCad 6
"""The optional ``tstamp`` token defines the unique identifier of the pad object"""
uuid: Optional[str] = None # Used since KiCad 6 and renamed to uuid for kicad 8
"""The optional ``uuid`` token defines the unique identifier of the pad object"""

pinFunction: Optional[str] = None
"""The optional ``pinFunction`` token attribute defines the associated schematic symbol pin name"""
Expand Down Expand Up @@ -521,7 +521,7 @@ def from_sexpr(cls, exp: list) -> Pad:
for chamfer in item[1:]:
object.chamfer.append(chamfer)
if item[0] == 'net': object.net = Net().from_sexpr(item)
if item[0] == 'tstamp': object.tstamp = item[1]
if item[0] == 'uuid': object.uuid = item[1]
if item[0] == 'pinfunction': object.pinFunction = item[1]
if item[0] == 'pintype': object.pinType = item[1]
if item[0] == 'die_length': object.dieLength = item[1]
Expand Down Expand Up @@ -590,7 +590,7 @@ def to_sexpr(self, indent: int = 2, newline: bool = True) -> str:
if net != '' or pf != '' or pt != '':
schematicSymbolAssociated = True

tstamp = f' (tstamp {self.tstamp})' if self.tstamp is not None else ''
uuid = f' (uuid {self.uuid})' if self.uuid is not None else ''

if len(self.chamfer) > 0:
champferFound = True
Expand Down Expand Up @@ -657,7 +657,7 @@ def to_sexpr(self, indent: int = 2, newline: bool = True) -> str:
expression += f'\n{primitive.to_sexpr(newline=False,indent=indent+4)}'
expression += f'\n{indents} )'

expression += f'{tstamp}){endline}'
expression += f'{uuid}){endline}'
return expression

@dataclass
Expand Down Expand Up @@ -729,8 +729,8 @@ def libId(self, symbol_id: str):
tedit: str = remove_prefix(hex(calendar.timegm(datetime.datetime.now().utctimetuple())), '0x')
"""The ``tedit`` token defines a the last time the footprint was edited"""

tstamp: Optional[str] = None
"""The ``tstamp`` token defines the unique identifier for the footprint. This only applies
uuid: Optional[str] = None
"""The ``uuid`` token defines the unique identifier for the footprint. This only applies
to footprints defined in the board file format."""

position: Optional[Position] = None
Expand Down Expand Up @@ -869,7 +869,7 @@ def from_sexpr(cls, exp: list) -> Footprint:
if item[0] == 'generator': object.generator = item[1]
if item[0] == 'layer': object.layer = item[1]
if item[0] == 'tedit': object.tedit = item[1]
if item[0] == 'tstamp': object.tstamp = item[1]
if item[0] == 'uuid': object.uuid = item[1]
if item[0] == 'descr': object.description = item[1]
if item[0] == 'tags': object.tags = item[1]
if item[0] == 'path': object.path = item[1]
Expand Down Expand Up @@ -1024,14 +1024,14 @@ def to_sexpr(self, indent=0, newline=True, layerInFirstLine=False) -> str:
placed = ' placed' if self.placed else ''
version = f' (version {self.version})' if self.version is not None else ''
generator = f' (generator {self.generator})' if self.generator is not None else ''
tstamp = f' (tstamp {self.tstamp})' if self.tstamp is not None else ''
uuid = f' (uuid {self.uuid})' if self.uuid is not None else ''

expression = f'{indents}(footprint "{dequote(self.libId)}"{locked}{placed}{version}{generator}'
if layerInFirstLine:
expression += f' (layer "{dequote(self.layer)}")\n'
else:
expression += f'\n{indents} (layer "{dequote(self.layer)}")\n'
expression += f'{indents} (tedit {self.tedit}){tstamp}\n'
expression += f'{indents} (tedit {self.tedit}){uuid}\n'

if self.position is not None:
angle = f' {self.position.angle}' if self.position.angle is not None else ''
Expand Down
36 changes: 18 additions & 18 deletions src/kiutils/items/brditems.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ class Segment():
"""The ``net`` token defines by the net ordinal number which net in the net
section that the segment is part of"""

tstamp: str = ""
"""The ``tstamp`` token defines the unique identifier of the line object"""
uuid: str = ""
"""The ``uuid`` token defines the unique identifier of the line object"""

@classmethod
def from_sexpr(cls, exp: list) -> Segment:
Expand Down Expand Up @@ -813,7 +813,7 @@ def from_sexpr(cls, exp: list) -> Segment:
if item[0] == 'width': object.width = item[1]
if item[0] == 'layer': object.layer = item[1]
if item[0] == 'net': object.net = item[1]
if item[0] == 'tstamp': object.tstamp = item[1]
if item[0] == 'uuid': object.uuid = item[1]
return object

def to_sexpr(self, indent=2, newline=True) -> str:
Expand All @@ -830,7 +830,7 @@ def to_sexpr(self, indent=2, newline=True) -> str:
endline = '\n' if newline else ''
locked = ' locked' if self.locked else ''

return f'{indents}(segment{locked} (start {self.start.X} {self.start.Y}) (end {self.end.X} {self.end.Y}) (width {self.width}) (layer "{dequote(self.layer)}") (net {self.net}) (tstamp {self.tstamp})){endline}'
return f'{indents}(segment{locked} (start {self.start.X} {self.start.Y}) (end {self.end.X} {self.end.Y}) (width {self.width}) (layer "{dequote(self.layer)}") (net {self.net}) (uuid {self.uuid})){endline}'

@dataclass
class Via():
Expand Down Expand Up @@ -873,8 +873,8 @@ class Via():
"""The ``net`` token defines by net ordinal number which net in the net section that
the via is part of"""

tstamp: Optional[str] = None
"""The ``tstamp`` token defines the unique identifier of the via"""
uuid: Optional[str] = None
"""The ``uuid`` token defines the unique identifier of the via"""

@classmethod
def from_sexpr(cls, exp: list) -> Via:
Expand Down Expand Up @@ -912,7 +912,7 @@ def from_sexpr(cls, exp: list) -> Via:
if item[0] == 'keep_end_layers': object.keepEndLayers = True
if item[0] == 'free': object.free = True
if item[0] == 'net': object.net = item[1]
if item[0] == 'tstamp': object.tstamp = item[1]
if item[0] == 'uuid': object.uuid = item[1]
return object

def to_sexpr(self, indent=2, newline=True) -> str:
Expand All @@ -937,9 +937,9 @@ def to_sexpr(self, indent=2, newline=True) -> str:
rum = f' (remove_unused_layers)' if self.removeUnusedLayers else ''
kel = f' (keep_end_layers)' if self.keepEndLayers else ''
free = f' (free)' if self.free else ''
tstamp = f' (tstamp {self.tstamp})' if self.tstamp is not None else ''
uuid = f' (uuid {self.uuid})' if self.uuid is not None else ''

return f'{indents}(via{type}{locked} (at {self.position.X} {self.position.Y}) (size {self.size}) (drill {self.drill}) (layers{layers}){rum}{kel}{free} (net {self.net}){tstamp}){endline}'
return f'{indents}(via{type}{locked} (at {self.position.X} {self.position.Y}) (size {self.size}) (drill {self.drill}) (layers{layers}){rum}{kel}{free} (net {self.net}){uuid}){endline}'

@dataclass
class Arc():
Expand Down Expand Up @@ -972,8 +972,8 @@ class Arc():
"""The ``net`` token defines the net ordinal number which net in the net section that arc is part
of. Defaults to 0."""

tstamp: Optional[str] = None
"""The optional ``tstamp`` token defines the unique identifier of the arc"""
uuid: Optional[str] = None
"""The optional ``uuid`` token defines the unique identifier of the arc"""

@classmethod
def from_sexpr(cls, exp: list) -> Arc:
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def from_sexpr(cls, exp: list) -> Arc:
elif item[0] == 'width': object.width = item[1]
elif item[0] == 'layer': object.layer = item[1]
elif item[0] == 'net': object.net = item[1]
elif item[0] == 'tstamp': object.tstamp = item[1]
elif item[0] == 'uuid': object.uuid = item[1]
return object

def to_sexpr(self, indent=2, newline=True) -> str:
Expand All @@ -1023,12 +1023,12 @@ def to_sexpr(self, indent=2, newline=True) -> str:
endline = '\n' if newline else ''

locked = f' locked' if self.locked else ''
tstamp = f' (tstamp {self.tstamp})' if self.tstamp is not None else ''
uuid = f' (uuid {self.uuid})' if self.uuid is not None else ''

expression = f'{indents}(arc{locked} (start {self.start.X} {self.start.Y}) '
expression += f'(mid {self.mid.X} {self.mid.Y}) (end {self.end.X} {self.end.Y}) '
expression += f'(width {self.width}) (layer "{dequote(self.layer)}") '
expression += f'(net {self.net}){tstamp}){endline}'
expression += f'(net {self.net}){uuid}){endline}'
return expression


Expand All @@ -1055,8 +1055,8 @@ class Target():
layer: str = "F.Cu"
"""The ``layer`` token sets the canonical layer where the target marker resides"""

tstamp: Optional[str] = None
"""The ``tstamp`` token defines the unique identifier of the target"""
uuid: Optional[str] = None
"""The ``uuid`` token defines the unique identifier of the target"""

@classmethod
def from_sexpr(cls, exp: list) -> Target:
Expand Down Expand Up @@ -1085,7 +1085,7 @@ def from_sexpr(cls, exp: list) -> Target:
if item[0] == 'size': object.size = item[1]
if item[0] == 'width': object.width = item[1]
if item[0] == 'layer': object.layer = item[1]
if item[0] == 'tstamp': object.tstamp = item[1]
if item[0] == 'uuid': object.uuid = item[1]
return object

def to_sexpr(self, indent=2, newline=True) -> str:
Expand All @@ -1101,4 +1101,4 @@ def to_sexpr(self, indent=2, newline=True) -> str:
indents = ' '*indent
endline = '\n' if newline else ''

return f'{indents}(target {self.type} (at {self.position.X} {self.position.Y}) (size {self.size}) (width {self.width}) (layer "{self.layer}") (tstamp {self.tstamp})){endline}'
return f'{indents}(target {self.type} (at {self.position.X} {self.position.Y}) (size {self.size}) (width {self.width}) (layer "{self.layer}") (uuid {self.uuid})){endline}'
8 changes: 4 additions & 4 deletions src/kiutils/items/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ class Dimension():
layer: str = "F.Cu"
"""The ``layer`` token defines the canonical layer the polygon resides on"""

tstamp: Optional[str] = None
"""The ``tstamp`` token defines the unique identifier for the footprint. This only applies
uuid: Optional[str] = None
"""The ``uuid`` token defines the unique identifier for the footprint. This only applies
to footprints defined in the board file format."""

pts: List[Position] = field(default_factory=list)
Expand Down Expand Up @@ -286,7 +286,7 @@ def from_sexpr(cls, exp: list) -> Dimension:
continue
if item[0] == 'type': object.type = item[1]
if item[0] == 'layer': object.layer = item[1]
if item[0] == 'tstamp': object.tstamp = item[1]
if item[0] == 'uuid': object.uuid = item[1]
if item[0] == 'height': object.height = item[1]
if item[0] == 'orientation': object.orientation = item[1]
if item[0] == 'leader_length': object.leaderLength = item[1]
Expand Down Expand Up @@ -321,7 +321,7 @@ def to_sexpr(self, indent: int = 2, newline: bool = True) -> str:
if len(points) == 0:
raise Exception("Number of points must not be zero")

expression = f'{indents}(dimension (type {self.type}) (layer "{self.layer}") (tstamp {self.tstamp})\n'
expression = f'{indents}(dimension (type {self.type}) (layer "{self.layer}") (uuid {self.uuid})\n'
expression += f'{indents} (pts{points})\n'
if self.height is not None:
expression += f'{indents} (height {self.height})\n'
Expand Down
Loading