Skip to content
New issue

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

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

Already on GitHub? # to your account

KiCad 7: Optional property IDs #78

Merged
merged 2 commits into from
Mar 9, 2023
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
25 changes: 14 additions & 11 deletions src/kiutils/items/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class Font():

color: Optional[ColorRGBA] = None
"""The optional ``color`` token specifies the color of the text element

Available since KiCad v7"""

@classmethod
Expand Down Expand Up @@ -451,8 +451,8 @@ class Effects():
"""The optional ``hide`` token defines if the text is hidden"""

href: Optional[str] = None
"""The optional ``href`` token specifies a link that the text element represents.
"""The optional ``href`` token specifies a link that the text element represents.

Available since KiCad v7"""

@classmethod
Expand Down Expand Up @@ -810,15 +810,17 @@ class Property():
value: str = ""
"""The ``value`` string defines the value of the property"""

id: int = 0
"""The id token defines an integer ID for the property and must be unique"""
id: Optional[int] = None
"""The ``id`` token defines an integer ID for the property and must be unique.

Optional since KiCad v7, but required in older versions"""

position: Position = field(default_factory=lambda: Position(angle=0))
"""The ``position`` defines the X and Y coordinates as well as the rotation angle of the property.
All three items will initially be set to zero."""

effects: Optional[Effects] = None
"""The ``effects`` section defines how the text is displayed"""
"""The optional ``effects`` section defines how the text is displayed"""

@classmethod
def from_sexpr(cls, exp: list) -> Property:
Expand Down Expand Up @@ -863,8 +865,9 @@ def to_sexpr(self, indent: int = 4, newline: bool = True) -> str:
endline = '\n' if newline else ''

posA = f' {self.position.angle}' if self.position.angle is not None else ''
id = f' (id {self.id})' if self.id is not None else ''

expression = f'{indents}(property "{dequote(self.key)}" "{dequote(self.value)}" (id {self.id}) (at {self.position.X} {self.position.Y}{posA})'
expression = f'{indents}(property "{dequote(self.key)}" "{dequote(self.value)}"{id} (at {self.position.X} {self.position.Y}{posA})'
if self.effects is not None:
expression += f'\n{self.effects.to_sexpr(indent+2)}'
expression += f'{indents}){endline}'
Expand Down Expand Up @@ -1005,21 +1008,21 @@ def to_sexpr(self, indent: int = 4, newline: bool = True) -> str:
@dataclass
class Fill():
"""The ``fill`` token defines how schematic and symbol graphical items are filled
Documentation:

Documentation:
- https://dev-docs.kicad.org/en/file-formats/sexpr-intro/index.html#_fill_definition
"""

type: str = "none"
"""The ``type`` attribute defines how the graphical item is filled. Defaults to ``None``.
"""The ``type`` attribute defines how the graphical item is filled. Defaults to ``None``.
Possible values are:
- ``none``: Graphic is not filled
- ``outline``: Graphic item filled with the line color
- ``background``: Graphic item filled with the theme background color"""

color: Optional[ColorRGBA] = None
"""The optional ``color`` token defines the color of the filled item.

Available since KiCad v7"""

@classmethod
Expand Down