From f96d5f28bbeaa735689295e5d753b30e9d0f99bf Mon Sep 17 00:00:00 2001 From: iopapamanoglou Date: Thu, 12 Sep 2024 14:24:09 +0200 Subject: [PATCH] list_f_field --- examples/minimal_led.py | 1 + src/faebryk/core/node.py | 12 ++++++++ src/faebryk/library/Mounting_Hole.py | 3 ++ src/faebryk/library/MultiCapacitor.py | 42 +++++++++++++++++++++++++++ src/faebryk/library/_F.py | 1 + src/faebryk/libs/library/L.py | 1 + 6 files changed, 60 insertions(+) create mode 100644 src/faebryk/library/MultiCapacitor.py diff --git a/examples/minimal_led.py b/examples/minimal_led.py index e9231cb6..504c599b 100644 --- a/examples/minimal_led.py +++ b/examples/minimal_led.py @@ -10,6 +10,7 @@ import typer import faebryk.library._F as F +import faebryk.libs.library.L as L from faebryk.core.module import Module from faebryk.libs.brightness import TypicalLuminousIntensity from faebryk.libs.examples.buildutil import apply_design_to_pcb diff --git a/src/faebryk/core/node.py b/src/faebryk/core/node.py index f39d3234..e688f3a0 100644 --- a/src/faebryk/core/node.py +++ b/src/faebryk/core/node.py @@ -106,6 +106,18 @@ def __() -> T: return _ +def list_f_field[T, **P](n: int, con: Callable[P, T]) -> Callable[P, list[T]]: + assert isinstance(con, type) + + def _(*args: P.args, **kwargs: P.kwargs) -> Callable[[], list[T]]: + def __() -> list[T]: + return [con(*args, **kwargs) for _ in range(n)] + + return _d_field(__) + + return _ + + class NodeException(FaebrykException): def __init__(self, node: "Node", *args: object) -> None: super().__init__(*args) diff --git a/src/faebryk/library/Mounting_Hole.py b/src/faebryk/library/Mounting_Hole.py index 0c7d538a..d73074f3 100644 --- a/src/faebryk/library/Mounting_Hole.py +++ b/src/faebryk/library/Mounting_Hole.py @@ -8,6 +8,7 @@ from faebryk.core.module import Module from faebryk.libs.iso_metric_screw_thread import Iso262_MetricScrewThreadSizes from faebryk.libs.library import L +from faebryk.libs.picker.picker import has_part_picked_remove logger = logging.getLogger(__name__) @@ -45,3 +46,5 @@ def footprint(self): pin_names=[], ) ) + + no_part: has_part_picked_remove diff --git a/src/faebryk/library/MultiCapacitor.py b/src/faebryk/library/MultiCapacitor.py new file mode 100644 index 00000000..b79c0e4e --- /dev/null +++ b/src/faebryk/library/MultiCapacitor.py @@ -0,0 +1,42 @@ +# This file is part of the faebryk project +# SPDX-License-Identifier: MIT + +import logging + +import faebryk.library._F as F # noqa: F401 +from faebryk.libs.library import L # noqa: F401 +from faebryk.libs.units import P +from faebryk.libs.util import times # noqa: F401 + +logger = logging.getLogger(__name__) + + +class MultiCapacitor(F.Capacitor): + """ + TODO: Docstring describing your module + """ + + # ---------------------------------------- + # modules, interfaces, parameters + # ---------------------------------------- + + # ---------------------------------------- + # traits + # ---------------------------------------- + + def __init__(self, count: int): + self._count = count + + @L.rt_field + def capacitors(self) -> list[F.Capacitor]: + return times(self._count, F.Capacitor) + + def __preinit__(self): + # ------------------------------------ + # connections + # ------------------------------------ + + # ------------------------------------ + # parametrization + # ------------------------------------ + pass diff --git a/src/faebryk/library/_F.py b/src/faebryk/library/_F.py index 460de8a6..5f037dc1 100644 --- a/src/faebryk/library/_F.py +++ b/src/faebryk/library/_F.py @@ -127,6 +127,7 @@ from faebryk.library.Mounting_Hole import Mounting_Hole from faebryk.library.can_be_surge_protected import can_be_surge_protected from faebryk.library.is_surge_protected import is_surge_protected +from faebryk.library.MultiCapacitor import MultiCapacitor from faebryk.library.can_be_decoupled import can_be_decoupled from faebryk.library.is_decoupled import is_decoupled from faebryk.library.Potentiometer import Potentiometer diff --git a/src/faebryk/libs/library/L.py b/src/faebryk/libs/library/L.py index bc331c4e..f47577f0 100644 --- a/src/faebryk/libs/library/L.py +++ b/src/faebryk/libs/library/L.py @@ -10,6 +10,7 @@ f_field, list_field, rt_field, + list_f_field, ) logger = logging.getLogger(__name__)