Merge 78434969cd6fb631ed263b282b017ae31817a18c into 7cf9244af17e644bd15f69198b0acf07445d2cb4
This commit is contained in:
commit
fe1579c92f
@ -85,6 +85,10 @@ tweak: # optional tweaking of .gv output
|
|||||||
# loops
|
# loops
|
||||||
loops: <List> # every list item is itself a list of exactly two pins
|
loops: <List> # every list item is itself a list of exactly two pins
|
||||||
# on the connector that are to be shorted
|
# on the connector that are to be shorted
|
||||||
|
|
||||||
|
# optional tweaking of .gv output executed for each instance of this connector
|
||||||
|
tweak: # see below
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Cable attributes
|
## Cable attributes
|
||||||
@ -148,6 +152,9 @@ tweak: # optional tweaking of .gv output
|
|||||||
show_wirecount: <bool> # defaults to true
|
show_wirecount: <bool> # defaults to true
|
||||||
show_wirenumbers: <bool> # defaults to true for cables; false for bundles
|
show_wirenumbers: <bool> # defaults to true for cables; false for bundles
|
||||||
|
|
||||||
|
# optional tweaking of .gv output executed for each instance of this cable
|
||||||
|
tweak: # see below
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Connection sets
|
## Connection sets
|
||||||
@ -451,6 +458,13 @@ Alternatively items can be added to just the BOM by putting them in the section
|
|||||||
# This feature is experimental and might change
|
# This feature is experimental and might change
|
||||||
# or be removed in future versions.
|
# or be removed in future versions.
|
||||||
|
|
||||||
|
placeholder: <str> # Substring to be replaced with node name
|
||||||
|
# An empty string as placeholder disable replacements.
|
||||||
|
# When placeholder is absent, the global placeholder is used.
|
||||||
|
# For tweak sections in connectors and cables, all substrings
|
||||||
|
# matching the placeholder text will be replaced with the name
|
||||||
|
# of connector/cable in all override and append entries.
|
||||||
|
|
||||||
override: # dict of .gv entries to override
|
override: # dict of .gv entries to override
|
||||||
# Each entry is identified by its leading string
|
# Each entry is identified by its leading string
|
||||||
# in lines beginning with a TAB character.
|
# in lines beginning with a TAB character.
|
||||||
|
|||||||
@ -72,6 +72,7 @@ class Options:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Tweak:
|
class Tweak:
|
||||||
|
placeholder: Optional[PlainText] = None
|
||||||
override: Optional[Dict[Designator, Dict[str, Optional[str]]]] = None
|
override: Optional[Dict[Designator, Dict[str, Optional[str]]]] = None
|
||||||
append: Union[str, List[str], None] = None
|
append: Union[str, List[str], None] = None
|
||||||
|
|
||||||
@ -164,11 +165,14 @@ class Connector:
|
|||||||
loops: List[List[Pin]] = field(default_factory=list)
|
loops: List[List[Pin]] = field(default_factory=list)
|
||||||
ignore_in_bom: bool = False
|
ignore_in_bom: bool = False
|
||||||
additional_components: List[AdditionalComponent] = field(default_factory=list)
|
additional_components: List[AdditionalComponent] = field(default_factory=list)
|
||||||
|
tweak: Optional[Tweak] = None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
|
|
||||||
if isinstance(self.image, dict):
|
if isinstance(self.image, dict):
|
||||||
self.image = Image(**self.image)
|
self.image = Image(**self.image)
|
||||||
|
if self.tweak is not None:
|
||||||
|
self.tweak = Tweak(**self.tweak)
|
||||||
|
|
||||||
self.ports_left = False
|
self.ports_left = False
|
||||||
self.ports_right = False
|
self.ports_right = False
|
||||||
@ -274,11 +278,14 @@ class Cable:
|
|||||||
show_wirenumbers: Optional[bool] = None
|
show_wirenumbers: Optional[bool] = None
|
||||||
ignore_in_bom: bool = False
|
ignore_in_bom: bool = False
|
||||||
additional_components: List[AdditionalComponent] = field(default_factory=list)
|
additional_components: List[AdditionalComponent] = field(default_factory=list)
|
||||||
|
tweak: Optional[Tweak] = None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
|
|
||||||
if isinstance(self.image, dict):
|
if isinstance(self.image, dict):
|
||||||
self.image = Image(**self.image)
|
self.image = Image(**self.image)
|
||||||
|
if self.tweak is not None:
|
||||||
|
self.tweak = Tweak(**self.tweak)
|
||||||
|
|
||||||
if isinstance(self.gauge, str): # gauge and unit specified
|
if isinstance(self.gauge, str): # gauge and unit specified
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -17,8 +17,8 @@ from wireviz.DataClasses import (
|
|||||||
MatePin,
|
MatePin,
|
||||||
Metadata,
|
Metadata,
|
||||||
Options,
|
Options,
|
||||||
Tweak,
|
|
||||||
Side,
|
Side,
|
||||||
|
Tweak,
|
||||||
)
|
)
|
||||||
from wireviz.svgembed import embed_svg_images_file
|
from wireviz.svgembed import embed_svg_images_file
|
||||||
from wireviz.wv_bom import (
|
from wireviz.wv_bom import (
|
||||||
@ -29,6 +29,7 @@ from wireviz.wv_bom import (
|
|||||||
component_table_entry,
|
component_table_entry,
|
||||||
generate_bom,
|
generate_bom,
|
||||||
get_additional_component_table,
|
get_additional_component_table,
|
||||||
|
make_list,
|
||||||
pn_info_string,
|
pn_info_string,
|
||||||
)
|
)
|
||||||
from wireviz.wv_colors import get_color_hex, translate_color
|
from wireviz.wv_colors import get_color_hex, translate_color
|
||||||
@ -78,12 +79,42 @@ class Harness:
|
|||||||
self._bom = [] # Internal Cache for generated bom
|
self._bom = [] # Internal Cache for generated bom
|
||||||
self.additional_bom_items = []
|
self.additional_bom_items = []
|
||||||
|
|
||||||
|
def extend_tweak(self, node: Union[Connector, Cable]) -> None:
|
||||||
|
"""Extend self.tweak with node.tweak after replacing placeholders."""
|
||||||
|
if node.tweak:
|
||||||
|
ph = node.tweak.placeholder
|
||||||
|
# An empty string is a legal value to avoid the global placeholder
|
||||||
|
if ph is None: # This must therefore be a test for None!
|
||||||
|
ph = self.tweak.placeholder # Use the global placeholder
|
||||||
|
# Create function rph() to replace any placeholder with node name
|
||||||
|
rph = (lambda s: s.replace(ph, node.name)) if ph else lambda s: s
|
||||||
|
n_override = node.tweak.override or {}
|
||||||
|
s_override = self.tweak.override or {}
|
||||||
|
for id, n_dict in n_override.items():
|
||||||
|
id = rph(id)
|
||||||
|
s_dict = s_override.get(id, {})
|
||||||
|
for k, v in n_dict.items():
|
||||||
|
k, v = rph(k), rph(v)
|
||||||
|
if k in s_dict and v != s_dict[k]:
|
||||||
|
raise ValueError(
|
||||||
|
f"{node.name}.tweak.override.{id}.{k} conflicts with another"
|
||||||
|
)
|
||||||
|
s_dict[k] = v
|
||||||
|
s_override[id] = s_dict or None # Will never be None?
|
||||||
|
self.tweak.override = s_override or None
|
||||||
|
self.tweak.append = (
|
||||||
|
make_list(self.tweak.append)
|
||||||
|
+ [rph(v) for v in make_list(node.tweak.append)]
|
||||||
|
) or None
|
||||||
|
|
||||||
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)
|
||||||
self.connectors[name] = Connector(name, *args, **kwargs)
|
self.connectors[name] = Connector(name, *args, **kwargs)
|
||||||
|
self.extend_tweak(self.connectors[name])
|
||||||
|
|
||||||
def add_cable(self, name: str, *args, **kwargs) -> None:
|
def add_cable(self, name: str, *args, **kwargs) -> None:
|
||||||
self.cables[name] = Cable(name, *args, **kwargs)
|
self.cables[name] = Cable(name, *args, **kwargs)
|
||||||
|
self.extend_tweak(self.cables[name])
|
||||||
|
|
||||||
def add_mate_pin(self, from_name, from_pin, to_name, to_pin, arrow_type) -> None:
|
def add_mate_pin(self, from_name, from_pin, to_name, to_pin, arrow_type) -> None:
|
||||||
self.mates.append(MatePin(from_name, from_pin, to_name, to_pin, arrow_type))
|
self.mates.append(MatePin(from_name, from_pin, to_name, to_pin, arrow_type))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user