Add strip length specs for connectors (port of upstream PR #446)
Some checks are pending
Create Examples / build (ubuntu-22.04, 3.7) (push) Waiting to run
Create Examples / build (ubuntu-22.04, 3.8) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.10) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.11) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.12) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.9) (push) Waiting to run
Some checks are pending
Create Examples / build (ubuntu-22.04, 3.7) (push) Waiting to run
Create Examples / build (ubuntu-22.04, 3.8) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.10) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.11) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.12) (push) Waiting to run
Create Examples / build (ubuntu-latest, 3.9) (push) Waiting to run
Connectors now support a 'strip' property with sleeve and insulation length specifications, rendered in the diagram node and available in the data model for BOM/manufacturing use.
This commit is contained in:
parent
c84e6fb3ad
commit
5f54ab1f0d
@ -293,6 +293,42 @@ class AdditionalComponent(GraphicalComponent):
|
||||
self.explicit_qty = False
|
||||
|
||||
|
||||
@dataclass
|
||||
class StripSpec:
|
||||
"""Strip length specification for sleeve or insulation."""
|
||||
length: float = 0
|
||||
length_unit: str = "mm"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.length} {self.length_unit}" if self.length > 0 else ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class Strip:
|
||||
"""Wire stripping specifications for a connector."""
|
||||
sleeve: Optional[StripSpec] = None
|
||||
insulation: Optional[StripSpec] = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if isinstance(self.sleeve, str):
|
||||
self.sleeve = Strip._parse_length(self.sleeve)
|
||||
if isinstance(self.insulation, str):
|
||||
self.insulation = Strip._parse_length(self.insulation)
|
||||
|
||||
@staticmethod
|
||||
def _parse_length(spec: str) -> StripSpec:
|
||||
parts = spec.strip().split(" ", 1)
|
||||
try:
|
||||
length = float(parts[0])
|
||||
except (ValueError, IndexError):
|
||||
raise Exception(
|
||||
f"Strip length '{spec}' must be a number, "
|
||||
"or number and unit separated by a space"
|
||||
)
|
||||
unit = parts[1].strip() if len(parts) > 1 else "mm"
|
||||
return StripSpec(length=length, length_unit=unit)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TopLevelGraphicalComponent(GraphicalComponent): # abstract class
|
||||
# component properties
|
||||
@ -317,6 +353,7 @@ class Connector(TopLevelGraphicalComponent):
|
||||
shorts_hide_lable: bool = False
|
||||
# pin information in particular
|
||||
pincount: Optional[int] = None
|
||||
strip: Optional[Strip] = None
|
||||
pins: List[Pin] = field(default_factory=list) # legacy
|
||||
pinlabels: List[Pin] = field(default_factory=list) # legacy
|
||||
pincolors: List[str] = field(default_factory=list) # legacy
|
||||
@ -367,6 +404,11 @@ class Connector(TopLevelGraphicalComponent):
|
||||
if isinstance(self.image, dict):
|
||||
self.image = Image(**self.image)
|
||||
|
||||
if isinstance(self.strip, dict):
|
||||
self.strip = Strip(**self.strip)
|
||||
elif self.strip is None:
|
||||
self.strip = Strip()
|
||||
|
||||
self.ports_left = False
|
||||
self.ports_right = False
|
||||
self.visible_pins = {}
|
||||
|
||||
@ -63,6 +63,16 @@ def gv_node_component(component: Component) -> Table:
|
||||
str(component.color) if component.color else None,
|
||||
]
|
||||
|
||||
# strip info for connectors
|
||||
line_strip = None
|
||||
if isinstance(component, Connector) and (component.strip.sleeve or component.strip.insulation):
|
||||
strip_parts = []
|
||||
if component.strip.sleeve:
|
||||
strip_parts.append(f"Strip sleeve: {component.strip.sleeve}")
|
||||
if component.strip.insulation:
|
||||
strip_parts.append(f"Strip insulation: {component.strip.insulation}")
|
||||
line_strip = [Td(" | ".join(strip_parts))]
|
||||
|
||||
if component.additional_parameters:
|
||||
line_additional_parameters = nested_table_dict(component.additional_parameters)
|
||||
else:
|
||||
@ -87,6 +97,7 @@ def gv_node_component(component: Component) -> Table:
|
||||
line_name,
|
||||
line_pn,
|
||||
line_info,
|
||||
line_strip,
|
||||
line_additional_parameters,
|
||||
line_ports,
|
||||
line_image,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user