diff --git a/examples/ex15.bom.tsv b/examples/ex15.bom.tsv index dd1dfe8..ed86637 100644 --- a/examples/ex15.bom.tsv +++ b/examples/ex15.bom.tsv @@ -1,3 +1,6 @@ -Id Description Qty Unit Designators -1 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 -2 Connector, Molex KK 254, female, 7 pins 2 X1, X2 +Id Description Qty Unit Designators Manufacturer MPN +1 2 X2/SH1, X2/SH2 +2 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 +3 Connector, Molex KK 254, female, 7 pins 2 X1, X2 +4 shortPart 1 X1/SH1 WireViz 42XCD42A5 +5 shortPart 42 mm X1/SH2 WireViz 42XCD42A5 diff --git a/examples/ex15.gv b/examples/ex15.gv index 87027cd..d998aab 100644 --- a/examples/ex15.gv +++ b/examples/ex15.gv @@ -76,31 +76,6 @@ graph { - - - - - - - - - - - - - - - - - - - - - - - -
ShortManufacturerM.P.N.LengthDescription
SH1WireViz42XCD42A5shortPart
SH2WireViz42XCD42A542mmshortPart
- > fillcolor="#FFFFFF" shape=box style=filled] edge [color="#000000" headclip=false style="solid,bold" tailclip=false] diff --git a/examples/ex15.html b/examples/ex15.html index b8886d2..51c8492 100644 --- a/examples/ex15.html +++ b/examples/ex15.html @@ -33,308 +33,279 @@ - - - + + + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - - -SH1 - -SH2 - - -GND - - - - -1 - -VCC - - - - -2 - -RX - - - -3 - -TX - - - -4 - -GND - - - - -5 - -VCC - - - - -6 - -GND - - - - -7 - -Short - -Manufacturer - -M.P.N. - -Length - -Description - -SH1 - -WireViz - -42XCD42A5 - - -shortPart - -SH2 - -WireViz - -42XCD42A5 - -42mm - -shortPart + + +X1 + +Molex KK 254 + +female + +7-pin + + +SH1 + +SH2 + + +GND + + + + +1 + +VCC + + + + +2 + +RX + + + +3 + +TX + + + +4 + +GND + + + + +5 + +VCC + + + + +6 + +GND + + + + +7 X1:c--X1:c - + X1:c--X1:c - + X1:c--X1:c - + W1 - - -W1 - -Serial - -4x - -0.25 mm² (24 AWG) - -+ S - -0.2 m -  -X1:1:GND -     1:BN     -X2:1:GND - - - -X1:2:VCC -     2:RD     -X2:2:VCC - - - -X1:3:RX -     3:OG     -X2:4:TX - - - -X1:4:TX -     4:YE     -X2:3:RX - - - -  -X1:1:GND -Shield - -  + + +W1 + +Serial + +4x + +0.25 mm² (24 AWG) + ++ S + +0.2 m +  +X1:1:GND +     1:BN     +X2:1:GND + + + +X1:2:VCC +     2:RD     +X2:2:VCC + + + +X1:3:RX +     3:OG     +X2:4:TX + + + +X1:4:TX +     4:YE     +X2:3:RX + + + +  +X1:1:GND +Shield + +  X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - + X2 - - -X2 - -Molex KK 254 - -female - -7-pin - - - -SH1 - -SH2 - -1 - -GND - - - - -2 - -VCC - - - - -3 - -RX - - - -4 - -TX - - - -5 - -GND - - - - -6 - -VCC - - - - -7 - -GND - - - + + +X2 + +Molex KK 254 + +female + +7-pin + + + +SH1 + +SH2 + +1 + +GND + + + + +2 + +VCC + + + + +3 + +RX + + + +4 + +TX + + + +5 + +GND + + + + +6 + +VCC + + + + +7 + +GND + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + X2:c--X2:c - + X2:c--X2:c - + X2:c--X2:c - + @@ -355,20 +326,53 @@ Qty Unit Designators + Manufacturer + MPN
1 + + 2 + + X2/SH1, X2/SH2 + + +
+
+ 2 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 + +
- 2 + 3 Connector, Molex KK 254, female, 7 pins 2 X1, X2 + + +
+
+ 4 + shortPart + 1 + + X1/SH1 + WireViz + 42XCD42A5 +
+
+ 5 + shortPart + 42 + mm + X1/SH2 + WireViz + 42XCD42A5
diff --git a/examples/ex15.png b/examples/ex15.png index 0462c09..45a20e9 100644 Binary files a/examples/ex15.png and b/examples/ex15.png differ diff --git a/examples/ex15.svg b/examples/ex15.svg index 4335e40..b0bca2b 100644 --- a/examples/ex15.svg +++ b/examples/ex15.svg @@ -4,308 +4,279 @@ - - - + + + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - - -SH1 - -SH2 - - -GND - - - - -1 - -VCC - - - - -2 - -RX - - - -3 - -TX - - - -4 - -GND - - - - -5 - -VCC - - - - -6 - -GND - - - - -7 - -Short - -Manufacturer - -M.P.N. - -Length - -Description - -SH1 - -WireViz - -42XCD42A5 - - -shortPart - -SH2 - -WireViz - -42XCD42A5 - -42mm - -shortPart + + +X1 + +Molex KK 254 + +female + +7-pin + + +SH1 + +SH2 + + +GND + + + + +1 + +VCC + + + + +2 + +RX + + + +3 + +TX + + + +4 + +GND + + + + +5 + +VCC + + + + +6 + +GND + + + + +7 X1:c--X1:c - + X1:c--X1:c - + X1:c--X1:c - + W1 - - -W1 - -Serial - -4x - -0.25 mm² (24 AWG) - -+ S - -0.2 m -  -X1:1:GND -     1:BN     -X2:1:GND - - - -X1:2:VCC -     2:RD     -X2:2:VCC - - - -X1:3:RX -     3:OG     -X2:4:TX - - - -X1:4:TX -     4:YE     -X2:3:RX - - - -  -X1:1:GND -Shield - -  + + +W1 + +Serial + +4x + +0.25 mm² (24 AWG) + ++ S + +0.2 m +  +X1:1:GND +     1:BN     +X2:1:GND + + + +X1:2:VCC +     2:RD     +X2:2:VCC + + + +X1:3:RX +     3:OG     +X2:4:TX + + + +X1:4:TX +     4:YE     +X2:3:RX + + + +  +X1:1:GND +Shield + +  X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - - - + + + X1:e--W1:w - + X2 - - -X2 - -Molex KK 254 - -female - -7-pin - - - -SH1 - -SH2 - -1 - -GND - - - - -2 - -VCC - - - - -3 - -RX - - - -4 - -TX - - - -5 - -GND - - - - -6 - -VCC - - - - -7 - -GND - - - + + +X2 + +Molex KK 254 + +female + +7-pin + + + +SH1 + +SH2 + +1 + +GND + + + + +2 + +VCC + + + + +3 + +RX + + + +4 + +TX + + + +5 + +GND + + + + +6 + +VCC + + + + +7 + +GND + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + X2:c--X2:c - + X2:c--X2:c - + X2:c--X2:c - + diff --git a/examples/ex15.yml b/examples/ex15.yml index f2c9b1a..bd7314c 100644 --- a/examples/ex15.yml +++ b/examples/ex15.yml @@ -17,7 +17,6 @@ connectors: mpn: 42XCD42A5 description: shortPart length: 42 - shorts_graph_bom: true X2: type: Molex KK 254 subtype: female diff --git a/examples/ex16.bom.tsv b/examples/ex16.bom.tsv index dd1dfe8..1c86629 100644 --- a/examples/ex16.bom.tsv +++ b/examples/ex16.bom.tsv @@ -1,3 +1,5 @@ Id Description Qty Unit Designators -1 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 -2 Connector, Molex KK 254, female, 7 pins 2 X1, X2 +1 2 X2/SH1, X2/SH2 +2 84.3 mm X1/SH1, X1/SH2 +3 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 +4 Connector, Molex KK 254, female, 7 pins 2 X1, X2 diff --git a/examples/ex16.html b/examples/ex16.html index 53e776b..7bb39a3 100644 --- a/examples/ex16.html +++ b/examples/ex16.html @@ -302,13 +302,27 @@
1 + + 2 + + X2/SH1, X2/SH2 +
+
+ 2 + + 84.3 + mm + X1/SH1, X1/SH2 +
+
+ 3 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1
- 2 + 4 Connector, Molex KK 254, female, 7 pins 2 diff --git a/examples/ex16.yml b/examples/ex16.yml index c831cb2..33e4034 100644 --- a/examples/ex16.yml +++ b/examples/ex16.yml @@ -1,3 +1,6 @@ +options: + mini_bom_mode: false + connectors: X1: type: Molex KK 254 # more information @@ -8,9 +11,11 @@ connectors: pins: [1, 5, 7] color: PK type: loop + length: 42 SH2: pins: [2, 6] color: RD + length: 42.3 X2: type: Molex KK 254 subtype: female diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index f62bfa2..6ec0b30 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -177,7 +177,6 @@ class Connector: ignore_in_bom: bool = False#ß additional_components: List[AdditionalComponent] = field(default_factory=list) shorts: List[Short] = field(default_factory=list) - shorts_graph_bom: Optional[bool] = False def __post_init__(self) -> None: @@ -236,7 +235,10 @@ class Connector: if isinstance(item, dict): self.additional_components[i] = AdditionalComponent(**item) - # self.shorts = {} + + for i, item in enumerate(self.shorts): + if isinstance(item, dict): + self.additional_components[i] = Short(**item) for i, item in enumerate(self.shorts): if isinstance(item, dict): diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 48dd42e..ae47130 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -206,7 +206,6 @@ class Harness: translate_color(connector.color, self.options.color_mode) if connector.color else None, html_colorbar(connector.color)], '' if connector.style != 'simple' else None, - '' if connector.shorts_graph_bom else None, [html_image(connector.image)], [html_caption(connector.image)]] # fmt: on @@ -305,64 +304,6 @@ class Harness: for row in html ] - if connector.shorts_graph_bom: - shorthtml = [] - shorthtml.append( - '
' - ) - - - shorthtml.append(" ") - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(" ") - - # print(connector.shorts) - - #shorts = connector.shorts - #for shortI in shorts.values(): - # print(shortI) - # print(shortI.name) - - for shortName in connector.shorts: - short = connector.shorts[shortName] - shPins = short.get('pins') - shColor = short.get('color') - shType = short.get('type') - shManufacturer = short.get('manufacturer') if short.get('manufacturer') != None else "" - shMpn = short.get('mpn') if short.get('mpn') != None else "" - shDescription = short.get('description') if short.get('description') != None else "" - length = short.get('length') if short.get('length') != None else "" - if short.get('length_unit') != None and short.get('length') != None: - length_unit = short.get('length_unit') - elif short.get('length') == None: - length_unit = "" - else: - length_unit = "mm" - - if shColor == None: - shColor = "BK" - - shorthtml.append(" ") - - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(f' ') - shorthtml.append(f' ') - - shorthtml.append(" ") - - shorthtml.append("
ShortManufacturerM.P.N.LengthDescription
{shortName}{shManufacturer}{shMpn}{length}{length_unit}{shDescription}
") - - html = [ - row.replace("", "\n".join(shorthtml)) - for row in html - ] - for shortName in connector.shorts: short = connector.shorts[shortName] shPins = short.get('pins'); diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 27ee59b..c8e1584 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -4,7 +4,7 @@ from dataclasses import asdict from itertools import groupby from typing import Any, Dict, List, Optional, Tuple, Union -from wireviz.DataClasses import AdditionalComponent, Cable, Color, Connector +from wireviz.DataClasses import AdditionalComponent, Cable, Color, Connector, Short from wireviz.wv_colors import translate_color from wireviz.wv_gv_html import html_bgcolor_attr, html_line_breaks from wireviz.wv_helper import clean_whitespace @@ -22,7 +22,7 @@ BOMColumn = str # = Literal[*BOM_COLUMNS_ALWAYS, *BOM_COLUMNS_OPTIONAL] BOMEntry = Dict[BOMColumn, Union[str, int, float, List[str], None]] -def optional_fields(part: Union[Connector, Cable, AdditionalComponent]) -> BOMEntry: +def optional_fields(part: Union[Connector, Cable, AdditionalComponent, Short]) -> BOMEntry: """Return part field values for the optional BOM columns as a dict.""" part = asdict(part) return {field: part.get(field) for field in BOM_COLUMNS_OPTIONAL} @@ -85,6 +85,38 @@ def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOM ) return bom_entries +def get_shorts_bom(connector: Union[Connector]) -> List[BOMEntry]: + """Return a list of BOM entries with additional components.""" + bom_entries = [] + # Ignore components that have qty 0 + for shortName in connector.shorts: + short = connector.shorts[shortName] + shPins = short.get('pins') + shColor = short.get('color') + shType = short.get('type') + shManufacturer = short.get('manufacturer') if short.get('manufacturer') != None else "" + shMpn = short.get('mpn') if short.get('mpn') != None else "" + shDescription = short.get('description') if short.get('description') != None else "" + length = short.get('length') if short.get('length') != None else 1 + if short.get('length_unit') != None and short.get('length') != None: + length_unit = short.get('length_unit') + elif short.get('length') == None: + length_unit = "" + else: + length_unit = "mm" + + bom_entries.append( + { + "description": str(shDescription), + "qty": length, + "unit": str(length_unit), + "designators": str(connector.name + "/" + shortName), + "manufacturer": shManufacturer, + "mpn": shMpn, + # **optional_fields(short), + } + ) + return bom_entries def bom_entry_key(entry: BOMEntry) -> BOMKey: """Return a tuple of string values from the dict that must be equal to join BOM entries.""" @@ -124,6 +156,7 @@ def generate_bom(harness: "Harness") -> List[BOMEntry]: # add connectors aditional components to bom bom_entries.extend(get_additional_component_bom(connector)) + bom_entries.extend(get_shorts_bom(connector)) # cables # TODO: If category can have other non-empty values than 'bundle', maybe it should be part of description?