diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 5b4bb068..b31897d7 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from dataclasses import InitVar, dataclass, field +from dataclasses import InitVar, asdict, dataclass, field, replace from enum import Enum, auto from pathlib import Path from typing import Dict, List, Optional, Tuple, Union @@ -47,6 +47,18 @@ class Metadata(dict): 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 class Options: fontname: PlainText = "arial" @@ -58,6 +70,7 @@ class Options: color_mode: ColorMode = "SHORT" mini_bom_mode: bool = True template_separator: str = "." + terminology: Optional[Terminology] = None def __post_init__(self): if not self.bgcolor_node: @@ -68,6 +81,7 @@ def __post_init__(self): self.bgcolor_cable = self.bgcolor_node if not self.bgcolor_bundle: self.bgcolor_bundle = self.bgcolor_cable + self.terminology = Terminology(**(self.terminology or {})) @dataclass diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 30468a6a..a5333e4b 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -77,6 +77,7 @@ def __post_init__(self): self.mates = [] self._bom = [] # Internal Cache for generated bom self.additional_bom_items = [] + self.terminology = self.options.terminology.fully_populated() def add_connector(self, name: str, *args, **kwargs) -> None: check_old(f"Connector '{name}'", OLD_CONNECTOR_ATTR, kwargs) @@ -200,7 +201,7 @@ def create_graph(self) -> Graph: html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))], [html_line_breaks(connector.type), 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, html_colorbar(connector.color)], '' if connector.style != 'simple' else None, @@ -419,7 +420,7 @@ def create_graph(self) -> Graph: wirehtml.append("