Source code for jitxlib.symbols.ferrite.ferrite

"""
Ferrite symbols for JITX Standard Library

This module provides ferrite bead symbol definitions with tilted rectangle body.
"""

from __future__ import annotations
import math
from dataclasses import dataclass, replace
from typing import TYPE_CHECKING, cast

from jitx.shapes import Shape
from jitx.shapes.primitive import Polyline
from jitx.symbol import Direction, Pin
from jitx.transform import Transform

from ..label import LabelConfigurable, LabelledSymbol

if TYPE_CHECKING:
    from ..context import SymbolStyleContext


# Ferrite constants
DEF_FERRITE_PITCH = 2.0
DEF_FERRITE_LINE_WIDTH = 0.05
DEF_FERRITE_BODY_WIDTH = 0.9
DEF_FERRITE_BODY_HEIGHT = 0.4
DEF_FERRITE_BODY_ANGLE = -30.0  # Degrees


[docs] @dataclass class FerriteConfig(LabelConfigurable): """ Configuration for ferrite symbols Defines the geometric and visual parameters for ferrite bead symbols. """ pitch: float = DEF_FERRITE_PITCH """Distance between pin points""" line_width: float = DEF_FERRITE_LINE_WIDTH """Width of the ferrite lines""" body_width: float = DEF_FERRITE_BODY_WIDTH """Width of the ferrite body rectangle""" body_height: float = DEF_FERRITE_BODY_HEIGHT """Height of the ferrite body rectangle""" body_angle: float = DEF_FERRITE_BODY_ANGLE """Rotation angle of the body rectangle in degrees"""
[docs] class FerriteSymbol[T: FerriteConfig](LabelledSymbol): """ Ferrite bead symbol with graphics and pins. The ferrite symbol consists of a vertical porch line through a tilted rectangle body. Pins: 'p[1]', 'p[2]' (non-polarized) """ config: T porch: Shape[Polyline] body: Shape[Polyline] p: dict[int, Pin] def _symbol_style_config(self, context: SymbolStyleContext | None = None) -> T: """Symbol style config for this ferrite symbol.""" if context is None: config = FerriteConfig() else: config = context.ferrite_config return cast(T, config) def _lookup_config( self, config: T | None = None, context: SymbolStyleContext | None = None ) -> T: """Lookup the config for this symbol.""" if config is None: return self._symbol_style_config(context) return config def __init__(self, config: T | None = None, **kwargs): """ Initialize ferrite symbol. Args: config: Config object, or None to use defaults **kwargs: Individual parameters to override defaults """ from ..context import SymbolStyleContext context = SymbolStyleContext.get() config = self._lookup_config(config, context) self.config = replace(config, **kwargs) self._build_ferrite_glyphs() self._build_pins() self._build_labels(ref=Direction.Right, value=Direction.Right) def _build_ferrite_glyphs(self) -> None: """Build the ferrite body and porch line.""" p2 = self.pitch / 2.0 bw2 = self.body_width / 2.0 bh2 = self.body_height / 2.0 # Porch line (vertical line from pin to pin, through body) self.porch = Polyline(self.line_width, [(0.0, p2), (0.0, -p2)]) # Body rectangle (rotated) # Create rectangle points centered at origin body_pts = [ (-bw2, bh2), (bw2, bh2), (bw2, -bh2), (-bw2, -bh2), (-bw2, bh2), ] body_shape = Polyline(self.line_width, body_pts) # Apply rotation transform self.body = Transform((0.0, 0.0), self.body_angle) * body_shape def _build_pins(self) -> None: """Build 'p[1]' and 'p[2]' symbol pins.""" w = math.floor(self.pitch / 2) self.p = { 1: Pin(at=(0, w), direction=Direction.Up), 2: Pin(at=(0, -w), direction=Direction.Down), } @property def pitch(self) -> float: """See :attr:`~.FerriteConfig.pitch`.""" return self.config.pitch @property def line_width(self) -> float: """See :attr:`~.FerriteConfig.line_width`.""" return self.config.line_width @property def body_width(self) -> float: """See :attr:`~.FerriteConfig.body_width`.""" return self.config.body_width @property def body_height(self) -> float: """See :attr:`~.FerriteConfig.body_height`.""" return self.config.body_height @property def body_angle(self) -> float: """See :attr:`~.FerriteConfig.body_angle`.""" return self.config.body_angle @property def label_config(self) -> LabelConfigurable: """Configuration object that provides label configuration""" return self.config