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

Add unpopulated option to additional components qty multiplier #298

Merged
merged 3 commits into from
Apr 16, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ Parts can be added to a connector or cable in the section `<additional-component
# when used in a connector:
# pincount number of pins of connector
# populated number of populated positions in a connector
# unpopulated number of unpopulated positions
# when used in a cable:
# wirecount number of wires of cable/bundle
# terminations number of terminations on a cable/bundle
Expand Down
4 changes: 3 additions & 1 deletion src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Designator = PlainText # Case insensitive unique name of connector or cable

# Literal type aliases below are commented to avoid requiring python 3.8
ConnectorMultiplier = PlainText # = Literal['pincount', 'populated']
ConnectorMultiplier = PlainText # = Literal['pincount', 'populated', 'unpopulated']
CableMultiplier = (
PlainText # = Literal['wirecount', 'terminations', 'length', 'total_length']
)
Expand Down Expand Up @@ -232,6 +232,8 @@ def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> i
return self.pincount
elif qty_multiplier == "populated":
return sum(self.visible_pins.values())
elif qty_multiplier == 'unpopulated':
return max(0, self.pincount - sum(self.visible_pins.values()))
else:
raise ValueError(
f"invalid qty multiplier parameter for connector {qty_multiplier}"
Expand Down
6 changes: 4 additions & 2 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def get_additional_component_table(
rows = []
if component.additional_components:
rows.append(["Additional components"])
for part in component.additional_components:
# Ignore components that have qty 0
for part in [part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier)]:
common_args = {
"qty": part.qty * component.get_qty_multiplier(part.qty_multiplier),
"unit": part.unit,
Expand Down Expand Up @@ -63,7 +64,8 @@ def get_additional_component_table(
def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOMEntry]:
"""Return a list of BOM entries with additional components."""
bom_entries = []
for part in component.additional_components:
# Ignore components that have qty 0
for part in [part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier)]:
bom_entries.append(
{
"description": part.description,
Expand Down
Loading