Skip to content

Commit c534555

Browse files
committed
Add options.terminology to override certain terms
These terms can optionally be replaced by user defined terms: pin, wire, shield Resolves #331 basic feature
1 parent 7cf9244 commit c534555

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/wireviz/DataClasses.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from dataclasses import InitVar, dataclass, field
3+
from dataclasses import InitVar, asdict, dataclass, field, replace
44
from enum import Enum, auto
55
from pathlib import Path
66
from typing import Dict, List, Optional, Tuple, Union
@@ -47,6 +47,19 @@ class Metadata(dict):
4747
pass
4848

4949

50+
@dataclass
51+
class Terminology:
52+
"""Terms that the user might want to override"""
53+
54+
pin: Optional[PlainText] = None
55+
wire: Optional[PlainText] = None
56+
shield: Optional[PlainText] = None
57+
58+
def fully_populated(self):
59+
"""Return a copy where empty field values are replaced with their names"""
60+
return replace(self, **{k: v or k for k, v in asdict(self).items()})
61+
62+
5063
@dataclass
5164
class Options:
5265
fontname: PlainText = "arial"
@@ -58,6 +71,7 @@ class Options:
5871
color_mode: ColorMode = "SHORT"
5972
mini_bom_mode: bool = True
6073
template_separator: str = "."
74+
terminology: Optional[Terminology] = None
6175

6276
def __post_init__(self):
6377
if not self.bgcolor_node:
@@ -68,6 +82,7 @@ def __post_init__(self):
6882
self.bgcolor_cable = self.bgcolor_node
6983
if not self.bgcolor_bundle:
7084
self.bgcolor_bundle = self.bgcolor_cable
85+
self.terminology = Terminology(**(self.terminology or {}))
7186

7287

7388
@dataclass

src/wireviz/Harness.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def __post_init__(self):
7777
self.mates = []
7878
self._bom = [] # Internal Cache for generated bom
7979
self.additional_bom_items = []
80+
self.terminology = self.options.terminology.fully_populated()
8081

8182
def add_connector(self, name: str, *args, **kwargs) -> None:
8283
check_old(f"Connector '{name}'", OLD_CONNECTOR_ATTR, kwargs)
@@ -200,7 +201,7 @@ def create_graph(self) -> Graph:
200201
html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))],
201202
[html_line_breaks(connector.type),
202203
html_line_breaks(connector.subtype),
203-
f'{connector.pincount}-pin' if connector.show_pincount else None,
204+
f'{connector.pincount}-{self.terminology.pin}' if connector.show_pincount else None,
204205
translate_color(connector.color, self.options.color_mode) if connector.color else None,
205206
html_colorbar(connector.color)],
206207
'<!-- connector table -->' if connector.style != 'simple' else None,
@@ -419,7 +420,7 @@ def create_graph(self) -> Graph:
419420
wirehtml.append(" <tr><td>&nbsp;</td></tr>") # spacer
420421
wirehtml.append(" <tr>")
421422
wirehtml.append(" <td><!-- s_in --></td>")
422-
wirehtml.append(" <td>Shield</td>")
423+
wirehtml.append(f" <td>{self.terminology.shield.title()}</td>")
423424
wirehtml.append(" <td><!-- s_out --></td>")
424425
wirehtml.append(" </tr>")
425426
if isinstance(cable.shield, str):

src/wireviz/wv_bom.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
107107
"Connector"
108108
+ (f", {connector.type}" if connector.type else "")
109109
+ (f", {connector.subtype}" if connector.subtype else "")
110-
+ (f", {connector.pincount} pins" if connector.show_pincount else "")
110+
+ (
111+
f", {connector.pincount} {harness.terminology.pin}s"
112+
if connector.show_pincount
113+
else ""
114+
)
111115
+ (
112116
f", {translate_color(connector.color, harness.options.color_mode)}"
113117
if connector.color
@@ -140,7 +144,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
140144
if cable.gauge
141145
else " wires"
142146
)
143-
+ (" shielded" if cable.shield else "")
147+
+ (f" {harness.terminology.shield}ed" if cable.shield else "")
144148
+ (
145149
f", {translate_color(cable.color, harness.options.color_mode)}"
146150
if cable.color
@@ -160,7 +164,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]:
160164
# add each wire from the bundle to the bom
161165
for index, color in enumerate(cable.colors):
162166
description = (
163-
"Wire"
167+
harness.terminology.wire.title()
164168
+ (f", {cable.type}" if cable.type else "")
165169
+ (f", {cable.gauge} {cable.gauge_unit}" if cable.gauge else "")
166170
+ (

0 commit comments

Comments
 (0)