-
Notifications
You must be signed in to change notification settings - Fork 219
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
Changes from 28 commits
389e480
84c9db6
064fbc6
6680e55
9a1bc20
1a8942a
94d6fc9
bb37b37
668ee0a
e852df5
22e6fb5
983c322
0e929fe
038938c
3e1e9b7
c6c54b0
5170631
7c67a9e
abcccbd
3faaff6
20622e0
a450c82
cb3e3f4
b7f184e
715fe36
e6c21bd
5e0827b
f128ea2
052348c
4eeff65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,9 @@ | |||||
from wireviz.wv_helper import int2tuple, aspect_ratio | ||||||
from wireviz import wv_colors | ||||||
|
||||||
ConnectorMultiplier = str # = Literal['pincount', 'populated'] | ||||||
CableMultiplier = str # = Literal['wirecount', 'terminations', 'length', 'total_length'] | ||||||
|
||||||
|
||||||
@dataclass | ||||||
class Image: | ||||||
|
@@ -43,6 +46,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.capitalize().strip() + (f', {self.subtype.strip()}' if self.subtype else '') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest reversing your latest changes here to remove the two
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed to avoid some graphicial odities in the diagram. Without the strip if either string is a multiline string (defined with | as in the examples) a traling newline is added which causes issues when the fields are joined together in the cell. Most of the other cells ignore this problem as the trailing removing them and generating the diagram gives with mini bom The alternatives could be either getting user to use the |- symbol instead (should update the docs in this case). or moving the cleanup of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I'd argue having that little There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My question is, where does the need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The capitialise was originaly added to create more consistent bom formatting. We can remove this and pass that requirment onto the user if they care about it as this would be fairly intuative for a user to know what to change (unlike the newlines). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with your decision to remove the |
||||||
|
||||||
|
||||||
@dataclass | ||||||
class Connector: | ||||||
|
@@ -65,6 +83,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): | ||||||
|
||||||
|
@@ -114,9 +134,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: | ||||||
|
@@ -139,6 +173,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): | ||||||
|
||||||
|
@@ -196,6 +232,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) | ||||||
|
@@ -207,6 +246,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: | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason the
Literal
s are commented out?There was a problem hiding this comment.
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)
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New in version 3.8 is specified by https://docs.python.org/3/library/typing.html#typing.Literal