This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Core: KiCAD Sch Fileformat #60
Merged
Merged
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e08efe5
Add schematic fileformat
mawildoer 29e2c0c
On the way
mawildoer 8d75839
Accept PathLike to dump things
mawildoer 2e2f00c
1.1 running
mawildoer a314f45
Add colors
mawildoer 5daa8fd
Core: Catch exceptions raised while handling debug logging
mawildoer 0c911a1
Core: Split KiCAD sch file from fileformats
mawildoer e485417
Core: Perhaps overly complete schematic fileformat
mawildoer 00c5183
Add stack decoding information to logging
mawildoer bd03830
Add tests for schematic fileformat
mawildoer 2e49e34
Format imports
mawildoer 1d97df7
import fix and format test_fileformats
mawildoer 8dacff3
pre-commit
mawildoer 226dcec
Add load_dump test to sch
iopapamanoglou 3846fe1
Add support for non-value bools
iopapamanoglou 1c257f8
Add field_autoplaced
iopapamanoglou e3fbbfa
Adjust maybebool to same behavior as kicad
iopapamanoglou f5a9e6b
Add symbol power flag
iopapamanoglou b51cb4c
Merge branch 'main' into mawildoer/kicad-schematic-exporter-2
iopapamanoglou 57f3c07
remove merge artifact
iopapamanoglou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import logging | ||
import uuid | ||
from dataclasses import dataclass, field | ||
from enum import auto | ||
from typing import Optional | ||
|
||
from faebryk.libs.sexp.dataclass_sexp import SymEnum, sexp_field | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# TODO find complete examples of the fileformats, maybe in the kicad repo | ||
|
||
|
||
class UUID(str): | ||
pass | ||
|
||
|
||
@dataclass | ||
class C_xy: | ||
x: float = field(**sexp_field(positional=True)) | ||
y: float = field(**sexp_field(positional=True)) | ||
|
||
def __sub__(self, other: "C_xy") -> "C_xy": | ||
return C_xy(x=self.x - other.x, y=self.y - other.y) | ||
|
||
def __add__(self, other: "C_xy") -> "C_xy": | ||
return C_xy(x=self.x + other.x, y=self.y + other.y) | ||
|
||
def rotate(self, center: "C_xy", angle: float) -> "C_xy": | ||
import math | ||
|
||
angle = -angle # rotate kicad style counter-clockwise | ||
|
||
# Translate point to origin | ||
translated_x = self.x - center.x | ||
translated_y = self.y - center.y | ||
|
||
# Convert angle to radians | ||
angle = math.radians(angle) | ||
|
||
# Rotate | ||
rotated_x = translated_x * math.cos(angle) - translated_y * math.sin(angle) | ||
rotated_y = translated_x * math.sin(angle) + translated_y * math.cos(angle) | ||
|
||
# Translate back | ||
new_x = rotated_x + center.x | ||
new_y = rotated_y + center.y | ||
|
||
return C_xy(x=new_x, y=new_y) | ||
|
||
|
||
@dataclass | ||
class C_xyz: | ||
x: float = field(**sexp_field(positional=True)) | ||
y: float = field(**sexp_field(positional=True)) | ||
z: float = field(**sexp_field(positional=True)) | ||
|
||
|
||
@dataclass | ||
class C_xyr: | ||
x: float = field(**sexp_field(positional=True)) | ||
y: float = field(**sexp_field(positional=True)) | ||
r: float = field(**sexp_field(positional=True), default=0) | ||
|
||
|
||
@dataclass | ||
class C_wh: | ||
w: float = field(**sexp_field(positional=True)) | ||
h: Optional[float] = field(**sexp_field(positional=True), default=None) | ||
|
||
|
||
@dataclass | ||
class C_stroke: | ||
class E_type(SymEnum): | ||
solid = auto() | ||
default = auto() | ||
|
||
width: float | ||
type: E_type | ||
|
||
|
||
@dataclass | ||
class C_effects: | ||
@dataclass | ||
class C_font: | ||
size: C_wh | ||
thickness: Optional[float] = None | ||
|
||
class E_justify(SymEnum): | ||
center = "" | ||
left = auto() | ||
right = auto() | ||
bottom = auto() | ||
top = auto() | ||
normal = "" | ||
mirror = auto() | ||
|
||
font: C_font | ||
justify: Optional[tuple[E_justify, E_justify, E_justify]] = None | ||
# TODO: this should be a Union as it's actually a tuple with 3 positional | ||
# and optional enums: (E_justify_horizontal, E_justify_vertical, E_mirrored) | ||
|
||
|
||
@dataclass | ||
class C_pts: | ||
xys: list[C_xy] = field(**sexp_field(multidict=True), default_factory=list) | ||
|
||
|
||
def gen_uuid(mark: str = ""): | ||
# format: d864cebe-263c-4d3f-bbd6-bb51c6d2a608 | ||
value = uuid.uuid4().hex | ||
|
||
suffix = mark.encode().hex() | ||
if suffix: | ||
value = value[: -len(suffix)] + suffix | ||
|
||
DASH_IDX = [8, 12, 16, 20] | ||
formatted = value | ||
for i, idx in enumerate(DASH_IDX): | ||
formatted = formatted[: idx + i] + "-" + formatted[idx + i :] | ||
|
||
return UUID(formatted) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this because with logging at debug it failed to import this file
The stringification of some edge in the graph was hitting a
NotNone
assertionThis is the best solution IMO though because we shouldn't be killing the program with debug exceptions that might just be caused by import-time execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying!