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

Feature/additional components #115

Merged
merged 30 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
389e480
Add bom ignore option for cables and connectors
Tyler-Ward Jul 19, 2020
84c9db6
Add connector aditional bom components
Tyler-Ward Jul 20, 2020
064fbc6
Add support for connectioncount as a qty option
Tyler-Ward Jul 20, 2020
6680e55
Clean up construction of connectors_extra list
Tyler-Ward Jul 21, 2020
9a1bc20
Add extra components to connector nodes in graph
Tyler-Ward Jul 21, 2020
1a8942a
Add support for cables to have extra components
Tyler-Ward Jul 21, 2020
94d6fc9
Add units to graph output
Tyler-Ward Sep 17, 2020
bb37b37
Split qty into multiple fields
Tyler-Ward Sep 17, 2020
668ee0a
Fix wrong designation in bom for cable additions
Tyler-Ward Sep 19, 2020
e852df5
Fix bad check for pn being set
Tyler-Ward Sep 19, 2020
22e6fb5
Fix conector additions to multiply quantity rather than replace it
Tyler-Ward Sep 20, 2020
983c322
Add error handling for missing type in additional components.
Tyler-Ward Sep 20, 2020
0e929fe
Reformat aditional component rendering in conector and cable nodes
Tyler-Ward Sep 20, 2020
038938c
Fix bugs from the the error handling additions.
Tyler-Ward Sep 20, 2020
3e1e9b7
remove bom designators for connector extras with show_name=false
Tyler-Ward Sep 20, 2020
c6c54b0
Add Bom referenced parts lists for aditional components
Tyler-Ward Sep 26, 2020
5170631
Update Tutorial 08 sources to include additional components
Tyler-Ward Sep 26, 2020
7c67a9e
Implement suggested code cleanup
Tyler-Ward Sep 29, 2020
abcccbd
Move calculation of qty_multiplier into wv_helper
Tyler-Ward Sep 29, 2020
3faaff6
Simplify several function calls and typehint qty multipliers
Tyler-Ward Oct 1, 2020
20622e0
Move qty_multiplier functions into Connector and cable dataclasses
Tyler-Ward Oct 1, 2020
a450c82
Make description for additional components a property
Tyler-Ward Oct 1, 2020
cb3e3f4
Deduplicate additional components functions
Tyler-Ward Oct 5, 2020
b7f184e
Moved bom entry description generation to be in order of aperance
Tyler-Ward Oct 6, 2020
715fe36
Remove brackets arround if statements and shorten bom dict opperatiions
Tyler-Ward Oct 17, 2020
e6c21bd
Fix issue with deduplication of connectors.
Tyler-Ward Oct 17, 2020
5e0827b
Improve multiline field handling to avoid unwanted spaces
Tyler-Ward Oct 18, 2020
f128ea2
Add additional_components to the syntax documentation.
Tyler-Ward Oct 18, 2020
052348c
Remove unused functions and code formatting tweaks
Tyler-Ward Oct 20, 2020
4eeff65
Remove aditional component type capitilisation and swap to rstrip.
Tyler-Ward Oct 20, 2020
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
57 changes: 39 additions & 18 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ additional_bom_items: # custom items to add to BOM
notes: <str>

# product information (all optional)
pn: <str> # [internal] part number
mpn: <str> # manufacturer part number
manufacturer: <str> # manufacturer name
ignore_in_bom: <bool> # if set to true the connector is not added to the BOM
pn: <str> # [internal] part number
mpn: <str> # manufacturer part number
manufacturer: <str> # manufacturer name
additional_components: # additional components
- <additional-component> # additional component (see below)

# pinout information
# at least one of the following must be specified
Expand Down Expand Up @@ -108,9 +111,12 @@ Since the auto-incremented and auto-assigned designator is not known to the user
notes: <str>

# product information (all optional)
pn: <str> # [internal] part number
mpn: <str> # manufacturer part number
manufacturer: <str> # manufacturer name
ignore_in_bom: <bool> # if set to true the cable or wires are not added to the BOM
pn: <str> # [internal] part number
mpn: <str> # manufacturer part number
manufacturer: <str> # manufacturer name
additional_components: # additional components
- <additional-component> # additional component (see below)

# conductor information
# the following combinations are permitted:
Expand Down Expand Up @@ -212,27 +218,42 @@ For connectors with `autogenerate: true`, a new instance, with auto-generated de
- `<int>-<int>` auto-expands to a range.


## BOM items
## BOM items and additional components

Connectors (both regular, and auto-generated), cables, and wires of a bundle are automatically added to the BOM.
Connectors (both regular, and auto-generated), cables, and wires of a bundle are automatically added to the BOM,
unless the `ignore_in_bom` attribute is set to `true`.
Additional items can be added to the BOM as either part of a connector or cable or on their own.

<!-- unless the `ignore_in_bom` attribute is set to `true` (#115) -->
Parts can be added to a connector or cable in the section `<additional-component>` which will also list them in the graph.

Additional BOM entries can be generated in the sections marked `<bom-item>` above.
```yaml
-
type: <str> # type of additional component
# all the following are optional:
subtype: <str> # additional description (only shown in bom)
qty: <int/float> # qty to add to the bom (defaults to 1)
qty_multiplier: <str> # multiplies qty by a feature of the parent component
# when used in a connector:
# pincount number of pins of connector
# populated number of populated positions in a connector
# when used in a cable:
# wirecount number of wires of cable/bundle
# terminations number of terminations on a cable/bundle
# length length of cable/bundle
# total_length sum of lengths of each wire in the bundle
unit: <str>
pn: <str> # [internal] part number
mpn: <str> # manufacturer part number
manufacturer: <str> # manufacturer name
```

<!-- BOM items inside connectors/cables are not implemented yet, but should be soon (#50) -->
Alternatively items can be added to just the BOM by putting them in the section `<bom-item>` above.

```yaml
-
description: <str>
qty: <int/str> # when used in the additional_bom_items section:
# <int> manually specify qty.
# when used within a component:
# <int> manually specify qty.
# pincount match number of pins of connector
# wirecount match number of wires of cable/bundle
# connectioncount match number of connected pins
# all the following are optional:
qty: <int/float> # qty to add to the bom (defaults to 1)
unit: <str>
designators: <List>
pn: <str> # [internal] part number
Expand Down
54 changes: 54 additions & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from wireviz.wv_helper import int2tuple, aspect_ratio
from wireviz import wv_colors

# Literal type aliases below are commented to avoid requiring python 3.8
ConnectorMultiplier = str # = Literal['pincount', 'populated']
CableMultiplier = str # = Literal['wirecount', 'terminations', 'length', 'total_length']

Comment on lines +11 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason the Literals are commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from @kvid's comment #115 (comment)

Note that the Literal type specifier is in comments to avoid requiring Python 3.8.

I have checked my 2.7 install and literals aernt supported, doing some searching I cant find any reference to this method of specifying literals so not sure if this is a standard implementation method or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Understood. Let's keep it like this then, perhaps add a comment behind the comment explaining this.

Copy link
Collaborator

Choose a reason for hiding this comment

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


@dataclass
class Image:
Expand Down Expand Up @@ -43,6 +47,21 @@ def __post_init__(self, gv_dir):
if self.width:
self.height = self.width / aspect_ratio(gv_dir.joinpath(self.src))

@dataclass
class AdditionalComponent:
type: str
subtype: Optional[str] = None
manufacturer: Optional[str] = None
mpn: Optional[str] = None
pn: Optional[str] = None
qty: float = 1
unit: Optional[str] = None
qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = None

@property
def description(self) -> str:
return self.type.rstrip() + (f', {self.subtype.rstrip()}' if self.subtype else '')


@dataclass
class Connector:
Expand All @@ -65,6 +84,8 @@ class Connector:
hide_disconnected_pins: bool = False
autogenerate: bool = False
loops: List[Any] = field(default_factory=list)
ignore_in_bom: bool = False
additional_components: List[AdditionalComponent] = field(default_factory=list)

def __post_init__(self):

Expand Down Expand Up @@ -114,9 +135,23 @@ def __post_init__(self):
if len(loop) != 2:
raise Exception('Loops must be between exactly two pins!')

for i, item in enumerate(self.additional_components):
if isinstance(item, dict):
self.additional_components[i] = AdditionalComponent(**item)
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved

def activate_pin(self, pin):
self.visible_pins[pin] = True

Tyler-Ward marked this conversation as resolved.
Show resolved Hide resolved
def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> int:
if not qty_multiplier:
return 1
elif qty_multiplier == 'pincount':
return self.pincount
elif qty_multiplier == 'populated':
return sum(self.visible_pins.values())
else:
raise ValueError(f'invalid qty multiplier parameter for connector {qty_multiplier}')


@dataclass
class Cable:
Expand All @@ -139,6 +174,8 @@ class Cable:
color_code: Optional[str] = None
show_name: bool = True
show_wirecount: bool = True
ignore_in_bom: bool = False
additional_components: List[AdditionalComponent] = field(default_factory=list)

def __post_init__(self):

Expand Down Expand Up @@ -196,6 +233,9 @@ def __post_init__(self):
else:
raise Exception('lists of part data are only supported for bundles')

for i, item in enumerate(self.additional_components):
if isinstance(item, dict):
self.additional_components[i] = AdditionalComponent(**item)
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved

Tyler-Ward marked this conversation as resolved.
Show resolved Hide resolved
def connect(self, from_name, from_pin, via_pin, to_name, to_pin):
from_pin = int2tuple(from_pin)
Expand All @@ -207,6 +247,20 @@ def connect(self, from_name, from_pin, via_pin, to_name, to_pin):
# self.connections.append((from_name, from_pin[i], via_pin[i], to_name, to_pin[i]))
self.connections.append(Connection(from_name, from_pin[i], via_pin[i], to_name, to_pin[i]))

def get_qty_multiplier(self, qty_multiplier: Optional[CableMultiplier]) -> float:
if not qty_multiplier:
return 1
elif qty_multiplier == 'wirecount':
return self.wirecount
elif qty_multiplier == 'terminations':
return len(self.connections)
elif qty_multiplier == 'length':
return self.length
elif qty_multiplier == 'total_length':
return self.length * self.wirecount
else:
raise ValueError(f'invalid qty multiplier parameter for cable {qty_multiplier}')


@dataclass
class Connection:
Expand Down
Loading