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

Better additional component BOM table #226

Draft
wants to merge 38 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0f3b5e9
Skip assignment and return expression directly
kvid Nov 14, 2020
6525537
Simplify get_bom_index() parameters
kvid Nov 14, 2020
45b13ef
Use the same lambda in get_bom_index() as for deduplicating BOM
kvid Nov 14, 2020
da453db
Convert dataclass object to dict to use the same lambda
kvid Nov 14, 2020
347f1e3
Redefine the common lambda to an ordinary function
kvid Nov 14, 2020
6378b96
Simplify BOM header row logic
kvid Nov 14, 2020
d2f8034
Simplify collecting designators for a joined BOM entry
kvid Nov 14, 2020
e1d7bab
Simplify deduplication and sorting of collected designators
kvid Nov 14, 2020
74462cd
Remove parentheses around return expressions
kvid Nov 16, 2020
10b1198
Move out code from inner loop into helper functions
kvid Nov 26, 2020
cdca708
Move BOM sorting above grouping to use groupby()
kvid Nov 27, 2020
f13f8a7
Make the BOM grouping function return string tuple for sorting
kvid Nov 27, 2020
96d393d
Use a generator expressions and raise exception if failing
kvid Nov 27, 2020
1d653c4
Replace accumulation loop with sum expressions
kvid Nov 30, 2020
12e570f
Add function type hints and doc strings
kvid Nov 30, 2020
c22c42e
Add BOMEntry type alias
kvid Dec 1, 2020
d6d0d2a
Rename extra variable to part for consistency
kvid Jan 3, 2021
d15eeb1
Build output string in one big expression
kvid Jan 3, 2021
2e24498
Move default qty value=1 to BOM deduplication
kvid Jan 5, 2021
8e7c48d
Eliminate local variable
kvid Jan 5, 2021
30dbd95
Rename the 'item' key to 'description' in all BOMEntry dicts
kvid Jan 6, 2021
183a943
Move repeated code into new optional_fields() function
kvid Jan 6, 2021
523d0c6
Group common function arguments into a dict
kvid Jan 9, 2021
8c26c8f
New addit. compo. BOM table proof of concept
formatc1702 Mar 23, 2021
e61d14b
Create `bom_bubble()` function
formatc1702 Mar 23, 2021
53fefa8
Add `note` attribute to additional components
formatc1702 Mar 23, 2021
0dc02fe
Correctly determine qty
formatc1702 Mar 23, 2021
9a93d86
remove `component_table_entry()` as separate func.
formatc1702 Mar 23, 2021
4338b7a
Remove header row for additional components
formatc1702 Mar 23, 2021
7e168ea
Improve GraphViz output, remove debug print
formatc1702 Mar 23, 2021
f928bc7
Add BOM bubble cell to cables
formatc1702 Mar 23, 2021
aaf88d7
Remove vertical separators in BOM table
formatc1702 Mar 23, 2021
6aa53f6
Remove unused columns in BOM table
formatc1702 Mar 23, 2021
09d5496
Add new `bom_item_number` property to components
formatc1702 Mar 23, 2021
1f86c97
Fix rendering bug for empty add.comp. table
formatc1702 Mar 23, 2021
b4a0ae5
Implement additional parameter table
formatc1702 Mar 23, 2021
37bf530
Allow line breaks in additional parameters
formatc1702 Mar 23, 2021
9821ca3
Update demo02 to showcase more features
formatc1702 Mar 23, 2021
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
145 changes: 101 additions & 44 deletions examples/demo02.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,126 @@
templates: # defining templates to be used later on
- &molex_f
type: Molex KK 254
subtype: female
- &con_i2c
pinlabels: [GND, +5V, SCL, SDA]
- &wire_i2c
category: bundle
gauge: 0.14 mm2
colors: [BK, RD, YE, GN]

connectors:
X1:
<<: *molex_f # copying items from the template
pinlabels: [GND, +5V, SCL, SDA, MISO, MOSI, SCK, N/C]
type: KK 254
pn: CON-245-8
manufacturer: Molex
mpn: '0022013087'
subtype: female
pincount: 8
pinlabels: [Audio L, Audio R, Audio GND, N/C, I2C GND, I2C +5V, SCL, SDA]
additional_parameters:
Sleeving removal: 20 mm
Insulation removal: 2 mm
additional_components:
-
type: Crimp
pn: CRI-254
manufacturer: Molex
mpn: '008500032'
qty_multiplier: populated
-
type: Label
pn: LAB-444
note: '"C745-X1"'
notes: |
- Attach to main PCB
- Ensure proper contact
- Clamp down cables after attaching
X2:
<<: *molex_f
<<: *con_i2c # it is possible to copy from more than one template
type: 3.5 mm
subtype: jack
color: BK
pins: [T,R,S]
show_pincount: false
pinlabels: [L, R, GND]
image:
src: resources/stereo-phone-plug-TRS.png
caption: Tip, Ring, and Sleeve
X3:
<<: *molex_f
<<: *con_i2c
type: KK 254
subtype: female
pinlabels: [VCC, GND, SCL, SDA]
pincolors: [RD, BK, GN, BU]
X4:
<<: *molex_f
pinlabels: [GND, +12V, MISO, MOSI, SCK]
ferrule_crimp:
type: D-Sub
subtype: female
pincount: 9
pn: CON-D9-F
pinlabels: [GND, +5V, SCL, SDA, N/C, +12V IN, GND, +12V OUT, GND]
additional_components:
-
type: Casing, plastic
pn: CAS-D9
-
type: Mounting screws, M3 x 8
qty: 2
F:
style: simple
autogenerate: true
type: Crimp ferrule
subtype: 0.25 mm²
color: YE
subtype: 0.5 mm²
color: OG

cables:
W1:
<<: *wire_i2c
length: 0.2
wirecount: 3
shield: true
length: 0.5
gauge: 0.25 mm2
show_equiv: true
W2:
<<: *wire_i2c
length: 0.4
colors: [WH, RD, BK]
color: GY
additional_components:
-
type: Heatshrink D=5mm
qty: 15
unit: mm
note: left
-
type: Heatshrink D=5mm
qty: 25
unit: mm
note: right
W2: &wire_i2c
wirecount: 4
length: 0.2
gauge: 0.25 mm2
show_equiv: true
color_code: IEC
W3:
<<: *wire_i2c
color_code: DIN
W4: &wire_power
category: bundle
gauge: 0.14 mm2
length: 0.3
colors: [BK, BU, OG, VT]
show_equiv: true
W4:
gauge: 0.25 mm2
length: 0.3
colors: [BK, RD]
show_name: false
wirecount: 2
colors: [RD, BK]
gauge: 0.5 mm2
show_equiv: true
length: 1.0
additional_parameters:
Twist rate: 10/m
Twist direction: CCW
W5:
<<: *wire_power

connections:
-
- X1: [1-4]
- W1: [1-4]
- X2: [1-4]
- X1: [Audio L, Audio R, Audio GND, Audio GND]
- W1: [1-3,s]
- X2: [T,R,S,S]
-
- X1: [1-4]
- X1: [I2C GND, I2C +5V, SCL, SDA]
- W2: [1-4]
- X3: [1-4]
- X3: [GND, VCC, SCL, SDA]
-
- X1: [1,5-7]
- X1: [I2C GND, I2C +5V, SCL, SDA]
- W3: [1-4]
- X4: [1,3-5]
- X4: [1,2,3,4]
-
- ferrule_crimp
- F
- W4: [1,2]
- X4: [1,2]
- X4: [6,7]
-
- X4: [8,9]
- W5: [1,2]
- F
7 changes: 6 additions & 1 deletion src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Optional, List, Tuple, Union
from typing import Optional, List, Dict, Tuple, Union
from dataclasses import dataclass, field, InitVar
from pathlib import Path

Expand Down Expand Up @@ -76,6 +76,7 @@ class AdditionalComponent:
qty: float = 1
unit: Optional[str] = None
qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = None
note: Optional[str] = None

@property
def description(self) -> str:
Expand All @@ -93,6 +94,7 @@ class Connector:
type: Optional[MultilineHypertext] = None
subtype: Optional[MultilineHypertext] = None
pincount: Optional[int] = None
additional_parameters: Optional[Dict] = None
image: Optional[Image] = None
notes: Optional[MultilineHypertext] = None
pinlabels: List[Pin] = field(default_factory=list)
Expand All @@ -104,6 +106,7 @@ class Connector:
hide_disconnected_pins: bool = False
autogenerate: bool = False
loops: List[List[Pin]] = field(default_factory=list)
bom_item_number: Optional[int] = None
ignore_in_bom: bool = False
additional_components: List[AdditionalComponent] = field(default_factory=list)

Expand Down Expand Up @@ -180,6 +183,7 @@ class Cable:
color: Optional[Color] = None
wirecount: Optional[int] = None
shield: Union[bool, Color] = False
additional_parameters: Optional[Dict] = None
image: Optional[Image] = None
notes: Optional[MultilineHypertext] = None
colors: List[Colors] = field(default_factory=list)
Expand All @@ -188,6 +192,7 @@ class Cable:
show_name: bool = True
show_wirecount: bool = True
show_wirenumbers: Optional[bool] = None
bom_item_number: Optional[int] = None
ignore_in_bom: bool = False
additional_components: List[AdditionalComponent] = field(default_factory=list)

Expand Down
32 changes: 19 additions & 13 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from wireviz.DataClasses import Connector, Cable
from wireviz.wv_colors import get_color_hex
from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \
html_caption, remove_links, html_line_breaks
from wireviz.wv_bom import manufacturer_info_field, component_table_entry, \
html_caption, remove_links, html_line_breaks, bom_bubble, nested_html_table_dict
from wireviz.wv_bom import manufacturer_info_field, \
get_additional_component_table, bom_list, generate_bom
from wireviz.wv_html import generate_html_output
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \
Expand All @@ -24,7 +24,8 @@ class Harness:

def __init__(self):
self.color_mode = 'SHORT'
self.mini_bom_mode = True
self.show_part_numbers = True # TODO: Make configurable via YAML
self.show_bom_item_numbers = True # TODO: Make configurable via YAML
self.connectors = {}
self.cables = {}
self._bom = [] # Internal Cache for generated bom
Expand Down Expand Up @@ -114,17 +115,20 @@ def create_graph(self) -> Graph:
html = []

rows = [[remove_links(connector.name) if connector.show_name else None],
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))],
[html_line_breaks(connector.type),
[bom_bubble(connector.bom_item_number) if self.show_bom_item_numbers else None, # TODO: Show actual BOM number
html_line_breaks(connector.type),
html_line_breaks(connector.subtype),
f'{connector.pincount}-pin' if connector.show_pincount else None,
connector.color, html_colorbar(connector.color)],
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))] if self.show_part_numbers else None,
nested_html_table_dict(connector.additional_parameters),
'<!-- connector table -->' if connector.style != 'simple' else None,
[html_image(connector.image)],
[html_caption(connector.image)]]
rows.extend(get_additional_component_table(self, connector))
rows.append(get_additional_component_table(self, connector))
rows.append([html_line_breaks(connector.notes)])

html.extend(nested_html_table(rows))

if connector.style != 'simple':
Expand Down Expand Up @@ -195,21 +199,23 @@ def create_graph(self) -> Graph:
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'

rows = [[remove_links(cable.name) if cable.show_name else None],
[f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None,
html_line_breaks(manufacturer_info_field(
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
cable.mpn if not isinstance(cable.mpn, list) else None))],
[html_line_breaks(cable.type),
[bom_bubble(cable.bom_item_number) if self.show_bom_item_numbers else None, # TODO: Show actual BOM number
html_line_breaks(cable.type),
f'{cable.wirecount}x' if cable.show_wirecount else None,
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None,
'+ S' if cable.shield else None,
f'{cable.length} {cable.length_unit}' if cable.length > 0 else None,
cable.color, html_colorbar(cable.color)],
[f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None,
html_line_breaks(manufacturer_info_field(
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
cable.mpn if not isinstance(cable.mpn, list) else None))],
nested_html_table_dict(cable.additional_parameters),
'<!-- wire table -->',
[html_image(cable.image)],
[html_caption(cable.image)]]

rows.extend(get_additional_component_table(self, cable))
rows.append(get_additional_component_table(self, cable)) # TODO: reimplement
rows.append([html_line_breaks(cable.notes)])
html.extend(nested_html_table(rows))

Expand Down
Loading