Skip to content

Commit

Permalink
Add options.terminology to override certain terms
Browse files Browse the repository at this point in the history
These terms can optionally be overrided by user defined terms:
  pin, wire, shield
  • Loading branch information
kvid committed Jun 30, 2024
1 parent 5905041 commit c6ebcba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)],
'<!-- connector table -->' if connector.style != 'simple' else None,
Expand Down Expand Up @@ -419,7 +420,7 @@ def create_graph(self) -> Graph:
wirehtml.append(" <tr><td>&nbsp;</td></tr>") # spacer
wirehtml.append(" <tr>")
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(" </tr>")
if isinstance(cable.shield, str):
Expand Down
6 changes: 3 additions & 3 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
"Connector"
+ (f", {connector.type}" if connector.type 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)}"
if connector.color
Expand Down Expand Up @@ -140,7 +140,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
if cable.gauge
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)}"
if cable.color
Expand All @@ -160,7 +160,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
# add each wire from the bundle to the bom
for index, color in enumerate(cable.colors):
description = (
"Wire"
harness.terminology.wire.title()
+ (f", {cable.type}" if cable.type else "")
+ (f", {cable.gauge} {cable.gauge_unit}" if cable.gauge else "")
+ (
Expand Down

0 comments on commit c6ebcba

Please sign in to comment.