Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Implement footprint changes
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Sep 11, 2024
1 parent b983965 commit 1c904c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
23 changes: 22 additions & 1 deletion src/faebryk/exporters/pcb/kicad/pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ def apply_netlist(pcb_path: Path, netlist_path: Path):
nl_comps = {c.ref: c for c in netlist.export.components.comps}
comps_added = nl_comps.keys() - pcb_comps.keys()
comps_removed = pcb_comps.keys() - nl_comps.keys()
comps_matched = nl_comps.keys() & pcb_comps.keys()
comps_changed: dict[str, C_kicad_pcb_file.C_kicad_pcb.C_pcb_footprint] = {}

logger.debug(f"Comps matched: {comps_matched}")
for comp_name in comps_matched:
nl_comp = nl_comps[comp_name]
pcb_comp = pcb_comps[comp_name]

# update
if pcb_comp.name != nl_comp.footprint:
comps_removed.add(comp_name)
comps_added.add(comp_name)
comps_changed[comp_name] = pcb_comp
continue

pcb_comp.propertys["Value"].value = nl_comp.value

logger.debug(f"Comps removed: {comps_removed}")
for comp_name in comps_removed:
Expand All @@ -189,9 +205,14 @@ def apply_netlist(pcb_path: Path, netlist_path: Path):
footprint.propertys["Reference"].value = comp_name
footprint.propertys["Value"].value = comp.value

at = C_xyr(x=0, y=0, r=0)
if comp_name in comps_changed:
# TODO also need to do geo rotations and stuff
at = comps_changed[comp_name].at

pcb_comp = C_kicad_pcb_file.C_kicad_pcb.C_pcb_footprint(
uuid=gen_uuid(mark=""),
at=C_xyr(x=0, y=0, r=0),
at=at,
pads=[
C_kicad_pcb_file.C_kicad_pcb.C_pcb_footprint.C_pad(
uuid=gen_uuid(mark=""),
Expand Down
10 changes: 5 additions & 5 deletions src/faebryk/library/Mounting_Hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: MIT

import logging
from enum import StrEnum, auto
from enum import StrEnum

import faebryk.library._F as F
from faebryk.core.module import Module
Expand All @@ -15,10 +15,10 @@
class Mounting_Hole(Module):
class PadType(StrEnum):
NoPad = ""
Pad = auto()
Pad_TopBottom = auto()
Pad_TopOnly = auto()
Pad_Via = auto()
Pad = "Pad"
Pad_TopBottom = "Pad_TopBottom"
Pad_TopOnly = "Pad_TopOnly"
Pad_Via = "Pad_Via"

attach_to_footprint: F.can_attach_to_footprint_symmetrically
designator_prefix = L.f_field(F.has_designator_prefix_defined)("H")
Expand Down
3 changes: 0 additions & 3 deletions src/faebryk/libs/app/pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,5 @@ def apply_netlist(pcb_path: Path, netlist_path: Path, netlist_has_changed: bool
project.dumps(prj_path)

# Import netlist into pcb
if not netlist_has_changed:
return

logger.info(f"Apply netlist to {pcb_path}")
PCB.apply_netlist(pcb_path, netlist_path)
5 changes: 3 additions & 2 deletions src/faebryk/libs/kicad/fileformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ class C_kicad_netlist_file(SEXP_File):
class C_netlist:
@dataclass
class C_components:
@dataclass
@dataclass(kw_only=True)
class C_component:
@dataclass
class C_property:
Expand All @@ -1304,7 +1304,8 @@ class C_sheetpath:
value: str
footprint: str
propertys: dict[str, C_property] = field(
**sexp_field(multidict=True, key=lambda x: x.name)
**sexp_field(multidict=True, key=lambda x: x.name),
default_factory=dict,
)
tstamps: str
fields: C_fields = field(default_factory=C_fields)
Expand Down

0 comments on commit 1c904c4

Please sign in to comment.