From 9b276981b978dc3166c809e80b1f9f836a9e121b Mon Sep 17 00:00:00 2001 From: Matthew Wildoer Date: Wed, 4 Sep 2024 17:51:47 -0700 Subject: [PATCH] NetTie again --- src/faebryk/library/NetTie.py | 58 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/faebryk/library/NetTie.py b/src/faebryk/library/NetTie.py index be25cd87..cabca41d 100644 --- a/src/faebryk/library/NetTie.py +++ b/src/faebryk/library/NetTie.py @@ -7,49 +7,45 @@ import faebryk.library._F as F from faebryk.core.module import Module from faebryk.core.moduleinterface import ModuleInterface -from faebryk.library import _F as F -from faebryk.library.Constant import Constant from faebryk.library.Electrical import Electrical from faebryk.library.KicadFootprint import KicadFootprint -from faebryk.libs.library import L from faebryk.libs.picker.picker import has_part_picked_remove -from faebryk.libs.util import once logger = logging.getLogger(__name__) -class Size(float, Enum): - _2_0MM = 2.0 - _0_5MM = 0.5 +class NetTie[T: ModuleInterface](Module): + class Size(float, Enum): + _2_0MM = 2.0 + _0_5MM = 0.5 + unnamed: list[T] -@once -def net_tie( - width: Size | Constant[float], - interface_type: type[ModuleInterface] = Electrical, -): - class NetTie(Module): - unnamed = L.list_field(2, interface_type) + def __init__( + self, + width: Size, + interface_type: type[T] = Electrical, + ) -> None: + super().__init__() - def __preinit__( - self, - ) -> None: - self.add_trait(F.can_bridge_defined(*self.unnamed)) + # dynamically construct the interfaces + self.unnamed = self.add([interface_type(), interface_type()], "unnamed") - width_mm = Size(width).value + # add dem trairs + self.add(F.can_bridge_defined(*self.unnamed)) - self.add_trait(F.can_attach_to_footprint_symmetrically()) - self.add_trait(F.has_designator_prefix_defined("H")) - # TODO: "removed" isn't really true, but seems to work - self.add_trait(has_part_picked_remove()) + width_mm = NetTie.Size(width).value - # TODO: generate the kicad footprint instead of loading it - self.add_trait( - F.has_footprint_defined( - KicadFootprint( - f"NetTie:NetTie-2_SMD_Pad{width_mm:.1f}mm", pin_names=["1", "2"] - ) + self.add(F.can_attach_to_footprint_symmetrically()) + self.add(F.has_designator_prefix_defined("H")) + # TODO: "removed" isn't really true, but seems to work + self.add(has_part_picked_remove()) + + # TODO: generate the kicad footprint instead of loading it + self.add( + F.has_footprint_defined( + KicadFootprint( + f"NetTie:NetTie-2_SMD_Pad{width_mm:.1f}mm", pin_names=["1", "2"] ) ) - - return NetTie + )