|
29 | 29 | component_table_entry,
|
30 | 30 | generate_bom,
|
31 | 31 | get_additional_component_table,
|
| 32 | + make_list, |
32 | 33 | pn_info_string,
|
33 | 34 | )
|
34 | 35 | from wireviz.wv_colors import get_color_hex, translate_color
|
@@ -78,12 +79,41 @@ def __post_init__(self):
|
78 | 79 | self._bom = [] # Internal Cache for generated bom
|
79 | 80 | self.additional_bom_items = []
|
80 | 81 |
|
| 82 | + def join_tweak(self, node: Union[Connector, Cable]) -> None: |
| 83 | + """Join node.tweak with self.tweak after replacing placeholders.""" |
| 84 | + if node.tweak: |
| 85 | + ph = node.tweak.placeholder |
| 86 | + if ph is None: |
| 87 | + ph = self.tweak.placeholder |
| 88 | + # Create function rph() to replace placeholder with node name. |
| 89 | + rph = (lambda s: s.replace(ph, node.name)) if ph else lambda s: s |
| 90 | + n_override = node.tweak.override or {} |
| 91 | + s_override = self.tweak.override or {} |
| 92 | + for id, n_dict in n_override.items(): |
| 93 | + id = rph(id) |
| 94 | + s_dict = s_override.get(id, {}) |
| 95 | + for k, v in n_dict.items(): |
| 96 | + k = rph(k) |
| 97 | + v = rph(v) |
| 98 | + if k in s_dict and v != s_dict[k]: |
| 99 | + ValueError( |
| 100 | + f"{node.name}.tweak.override.{id}.{k} conflicts with another" |
| 101 | + ) |
| 102 | + s_dict[k] = v |
| 103 | + s_override[id] = s_dict |
| 104 | + self.tweak.override = s_override |
| 105 | + self.tweak.append = make_list(self.tweak.append) + [ |
| 106 | + rph(v) for v in make_list(node.tweak.append) |
| 107 | + ] |
| 108 | + |
81 | 109 | def add_connector(self, name: str, *args, **kwargs) -> None:
|
82 | 110 | check_old(f"Connector '{name}'", OLD_CONNECTOR_ATTR, kwargs)
|
83 | 111 | self.connectors[name] = Connector(name, *args, **kwargs)
|
| 112 | + self.join_tweak(self.connectors[name]) |
84 | 113 |
|
85 | 114 | def add_cable(self, name: str, *args, **kwargs) -> None:
|
86 | 115 | self.cables[name] = Cable(name, *args, **kwargs)
|
| 116 | + self.join_tweak(self.cables[name]) |
87 | 117 |
|
88 | 118 | def add_mate_pin(self, from_name, from_pin, to_name, to_pin, arrow_type) -> None:
|
89 | 119 | self.mates.append(MatePin(from_name, from_pin, to_name, to_pin, arrow_type))
|
|
0 commit comments