Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Implement single wire cable #405

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class Cable:
spn: Union[MultilineHypertext, List[MultilineHypertext], None] = None
pn: Union[Hypertext, List[Hypertext], None] = None
category: Optional[str] = None
style: Optional[str] = None
type: Optional[MultilineHypertext] = None
gauge: Optional[float] = None
gauge_unit: Optional[str] = None
Expand All @@ -270,6 +271,7 @@ class Cable:
show_name: Optional[bool] = None
show_wirecount: bool = True
show_wirenumbers: Optional[bool] = None
show_colorname: bool = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a different name:

Suggested change
show_colorname: bool = True
show_wirecolor_text: bool = True

Alternatively show_color_text, but then someone might expect it to also affect showing the cable.color (jacket color) text. Do you want that?

I suggest text instead of name because the text might be different text representations of the colors, depending on options.color_mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we are on the same page here. In a single-core cable, the color of the wire and the jacket would be identical. Anyway thanks for mentioning this, because it needs to apply to multi-core cables as well.

IMO neither text nor name is needed. In order to keep it intuitive, I consider the following for alignment with the other show_ switches:

cables:
  w:
    color: BK           # jacket color box, omit this to hide it all
    show_color: plain   # only hide the text from jacket color box
    show_color: text    # only show the text and hide the bgcolor

    colors: [GY]        # wire color (list), omit this for defaults
    show_colors: plain  # hide the color text from individual wires
    show_colors: text   # only show the text without wire coloring

Copy link
Collaborator

@kvid kvid Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This increases the code complexity slightly, but it seems easier to read, and hopefully is easier to understand as well.

I assume you'll also allow the values True for showing everything and False for showing nothing.

With None as default value for show_colors, you can set it in __post_init__() default plain for your single-core cable use case and True otherwise.

PS: Maybe we in a future separate PR will consider collecting all show_* switches like this:

    show:
      color: text
      colors: True
      wirecount: False

ignore_in_bom: bool = False
additional_components: List[AdditionalComponent] = field(default_factory=list)

Expand Down Expand Up @@ -362,9 +364,14 @@ def __post_init__(self) -> None:
else:
raise Exception("lists of part data are only supported for bundles")


if self.show_name is None:
# hide designators for auto-generated cables by default
self.show_name = self.name[0:2] != "__"
# hide designators for simple and for auto-generated cables by default
self.show_name = self.style != "simple" and self.name[0:2] != "__"

if self.show_wirecount is None:
# hide wirecount for simple (1 pin) connectors by default
self.show_wirecount = self.style != "simple"

if self.show_wirenumbers is None:
# by default, show wire numbers for cables, hide for bundles
Expand Down
2 changes: 1 addition & 1 deletion src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def create_graph(self) -> Graph:
colorstr = wv_colors.translate_color(
connection_color, self.options.color_mode
)
if colorstr:
if colorstr and cable.show_colorname:
wireinfo.append(colorstr)
if cable.wirelabels:
wireinfo.append(wirelabel if wirelabel is not None else "")
Expand Down
Loading