Make prefix for autogenerated component names configurable
`edotor.net` does not seem to like leading underscores, which makes GraphViz debugging difficult.
This commit is contained in:
parent
9cb9ede487
commit
18782444b1
@ -42,6 +42,8 @@ MetadataKeys = PlainText # Literal['title', 'description', 'notes', ...]
|
|||||||
|
|
||||||
Side = Enum("Side", "LEFT RIGHT")
|
Side = Enum("Side", "LEFT RIGHT")
|
||||||
|
|
||||||
|
AUTOGENERATED_PREFIX = "AUTOGENERATED_"
|
||||||
|
|
||||||
|
|
||||||
class Metadata(dict):
|
class Metadata(dict):
|
||||||
pass
|
pass
|
||||||
@ -163,6 +165,10 @@ class Connector:
|
|||||||
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)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_autogenerated(self):
|
||||||
|
return self.name.startswith(AUTOGENERATED_PREFIX)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
|
|
||||||
if isinstance(self.image, dict):
|
if isinstance(self.image, dict):
|
||||||
@ -196,8 +202,7 @@ class Connector:
|
|||||||
raise Exception("Pins are not unique")
|
raise Exception("Pins are not unique")
|
||||||
|
|
||||||
if self.show_name is None:
|
if self.show_name is None:
|
||||||
# hide designators for simple and for auto-generated connectors by default
|
self.show_name = self.style != "simple" and not self.is_autogenerated
|
||||||
self.show_name = self.style != "simple" and self.name[0:2] != "__"
|
|
||||||
|
|
||||||
if self.show_pincount is None:
|
if self.show_pincount is None:
|
||||||
# hide pincount for simple (1 pin) connectors by default
|
# hide pincount for simple (1 pin) connectors by default
|
||||||
@ -269,6 +274,10 @@ class Cable:
|
|||||||
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)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_autogenerated(self):
|
||||||
|
return self.name.startswith(AUTOGENERATED_PREFIX)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
|
|
||||||
if isinstance(self.image, dict):
|
if isinstance(self.image, dict):
|
||||||
@ -360,8 +369,7 @@ class Cable:
|
|||||||
raise Exception("lists of part data are only supported for bundles")
|
raise Exception("lists of part data are only supported for bundles")
|
||||||
|
|
||||||
if self.show_name is None:
|
if self.show_name is None:
|
||||||
# hide designators for auto-generated cables by default
|
self.show_name = not self.is_autogenerated
|
||||||
self.show_name = self.name[0:2] != "__"
|
|
||||||
|
|
||||||
if self.show_wirenumbers is None:
|
if self.show_wirenumbers is None:
|
||||||
# by default, show wire numbers for cables, hide for bundles
|
# by default, show wire numbers for cables, hide for bundles
|
||||||
|
|||||||
@ -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 (
|
||||||
@ -650,7 +650,6 @@ class Harness:
|
|||||||
graph = self.graph
|
graph = self.graph
|
||||||
return embed_svg_images(graph.pipe(format="svg").decode("utf-8"), Path.cwd())
|
return embed_svg_images(graph.pipe(format="svg").decode("utf-8"), Path.cwd())
|
||||||
|
|
||||||
|
|
||||||
def output(
|
def output(
|
||||||
self,
|
self,
|
||||||
filename: (str, Path),
|
filename: (str, Path),
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import yaml
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent)) # add src/wireviz to PATH
|
sys.path.insert(0, str(Path(__file__).parent.parent)) # add src/wireviz to PATH
|
||||||
|
|
||||||
from wireviz.DataClasses import Metadata, Options, Tweak
|
from wireviz.DataClasses import AUTOGENERATED_PREFIX, Metadata, Options, Tweak
|
||||||
from wireviz.Harness import Harness
|
from wireviz.Harness import Harness
|
||||||
from wireviz.wv_helper import (
|
from wireviz.wv_helper import (
|
||||||
expand,
|
expand,
|
||||||
@ -164,7 +164,7 @@ def parse(
|
|||||||
autogenerated_designators[template] = (
|
autogenerated_designators[template] = (
|
||||||
autogenerated_designators.get(template, 0) + 1
|
autogenerated_designators.get(template, 0) + 1
|
||||||
)
|
)
|
||||||
designator = f"__{template}_{autogenerated_designators[template]}"
|
designator = f"{AUTOGENERATED_PREFIX}{template}_{autogenerated_designators[template]}"
|
||||||
# check if redefining existing component to different template
|
# check if redefining existing component to different template
|
||||||
if designator in designators_and_templates:
|
if designator in designators_and_templates:
|
||||||
if designators_and_templates[designator] != template:
|
if designators_and_templates[designator] != template:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user