Merge 320977e2ec213f9983c6c151190971ed726167bc into 7cf9244af17e644bd15f69198b0acf07445d2cb4

This commit is contained in:
kvid 2025-02-16 20:56:01 +00:00 committed by GitHub
commit 22d4c2b958
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 6 deletions

View File

@ -392,6 +392,24 @@ If any component is defined in the `connectors` or `cables` sections but not ref
# Character to split template and designator for autogenerated components # Character to split template and designator for autogenerated components
template_separator: <str> # Default = '.' template_separator: <str> # Default = '.'
# Terms to be replaced by user defined terms
terminology: <terminology> # see below
```
## Terminology
A selection of terms can optionally be replaced by user defined terms.
This is a simple literal replacement of such terms in the diagram and BOM output. The original term is assumed in grammatical variations, like "{pin}s" and "{shield}ed", and that might create weird results in some use cases.
These are the supported terms (all entries are optional):
```yaml
terminology:
pin: <str>
wire: <str>
shield: <str>
``` ```

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from dataclasses import InitVar, dataclass, field from dataclasses import InitVar, asdict, dataclass, field, replace
from enum import Enum, auto from enum import Enum, auto
from pathlib import Path from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union from typing import Dict, List, Optional, Tuple, Union
@ -47,6 +47,19 @@ class Metadata(dict):
pass pass
@dataclass
class Terminology:
"""Terms that the user might want to override"""
pin: Optional[PlainText] = None
wire: Optional[PlainText] = None
shield: Optional[PlainText] = None
def fully_populated(self):
"""Return a copy where empty field values are replaced with their names"""
return replace(self, **{k: v or k for k, v in asdict(self).items()})
@dataclass @dataclass
class Options: class Options:
fontname: PlainText = "arial" fontname: PlainText = "arial"
@ -58,6 +71,7 @@ class Options:
color_mode: ColorMode = "SHORT" color_mode: ColorMode = "SHORT"
mini_bom_mode: bool = True mini_bom_mode: bool = True
template_separator: str = "." template_separator: str = "."
terminology: Optional[Terminology] = None
def __post_init__(self): def __post_init__(self):
if not self.bgcolor_node: if not self.bgcolor_node:
@ -68,6 +82,7 @@ class Options:
self.bgcolor_cable = self.bgcolor_node self.bgcolor_cable = self.bgcolor_node
if not self.bgcolor_bundle: if not self.bgcolor_bundle:
self.bgcolor_bundle = self.bgcolor_cable self.bgcolor_bundle = self.bgcolor_cable
self.terminology = Terminology(**(self.terminology or {}))
@dataclass @dataclass

View File

@ -77,6 +77,7 @@ class Harness:
self.mates = [] self.mates = []
self._bom = [] # Internal Cache for generated bom self._bom = [] # Internal Cache for generated bom
self.additional_bom_items = [] self.additional_bom_items = []
self.terminology = self.options.terminology.fully_populated()
def add_connector(self, name: str, *args, **kwargs) -> None: def add_connector(self, name: str, *args, **kwargs) -> None:
check_old(f"Connector '{name}'", OLD_CONNECTOR_ATTR, kwargs) check_old(f"Connector '{name}'", OLD_CONNECTOR_ATTR, kwargs)
@ -200,7 +201,7 @@ class Harness:
html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))], html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))],
[html_line_breaks(connector.type), [html_line_breaks(connector.type),
html_line_breaks(connector.subtype), html_line_breaks(connector.subtype),
f'{connector.pincount}-pin' if connector.show_pincount else None, f'{connector.pincount}-{self.terminology.pin}' if connector.show_pincount else None,
translate_color(connector.color, self.options.color_mode) if connector.color else None, translate_color(connector.color, self.options.color_mode) if connector.color else None,
html_colorbar(connector.color)], html_colorbar(connector.color)],
'<!-- connector table -->' if connector.style != 'simple' else None, '<!-- connector table -->' if connector.style != 'simple' else None,
@ -419,7 +420,7 @@ class Harness:
wirehtml.append(" <tr><td>&nbsp;</td></tr>") # spacer wirehtml.append(" <tr><td>&nbsp;</td></tr>") # spacer
wirehtml.append(" <tr>") wirehtml.append(" <tr>")
wirehtml.append(" <td><!-- s_in --></td>") wirehtml.append(" <td><!-- s_in --></td>")
wirehtml.append(" <td>Shield</td>") wirehtml.append(f" <td>{self.terminology.shield.title()}</td>")
wirehtml.append(" <td><!-- s_out --></td>") wirehtml.append(" <td><!-- s_out --></td>")
wirehtml.append(" </tr>") wirehtml.append(" </tr>")
if isinstance(cable.shield, str): if isinstance(cable.shield, str):

View File

@ -107,7 +107,11 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
"Connector" "Connector"
+ (f", {connector.type}" if connector.type else "") + (f", {connector.type}" if connector.type else "")
+ (f", {connector.subtype}" if connector.subtype else "") + (f", {connector.subtype}" if connector.subtype else "")
+ (f", {connector.pincount} pins" if connector.show_pincount else "") + (
f", {connector.pincount} {harness.terminology.pin}s"
if connector.show_pincount
else ""
)
+ ( + (
f", {translate_color(connector.color, harness.options.color_mode)}" f", {translate_color(connector.color, harness.options.color_mode)}"
if connector.color if connector.color
@ -140,7 +144,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
if cable.gauge if cable.gauge
else " wires" else " wires"
) )
+ (" shielded" if cable.shield else "") + (f" {harness.terminology.shield}ed" if cable.shield else "")
+ ( + (
f", {translate_color(cable.color, harness.options.color_mode)}" f", {translate_color(cable.color, harness.options.color_mode)}"
if cable.color if cable.color
@ -160,7 +164,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
# add each wire from the bundle to the bom # add each wire from the bundle to the bom
for index, color in enumerate(cable.colors): for index, color in enumerate(cable.colors):
description = ( description = (
"Wire" harness.terminology.wire.title()
+ (f", {cable.type}" if cable.type else "") + (f", {cable.type}" if cable.type else "")
+ (f", {cable.gauge} {cable.gauge_unit}" if cable.gauge else "") + (f", {cable.gauge} {cable.gauge_unit}" if cable.gauge else "")
+ ( + (