diff --git a/examples/.~lock.ex16.bom.tsv# b/examples/.~lock.ex16.bom.tsv# new file mode 100644 index 0000000..a4f8da2 --- /dev/null +++ b/examples/.~lock.ex16.bom.tsv# @@ -0,0 +1 @@ +,TIM/Tobias,tim,16.06.2024 13:54,file:///C:/Users/Tobias/AppData/Roaming/LibreOffice/4; \ No newline at end of file diff --git a/examples/ex15.bom.tsv b/examples/ex15.bom.tsv index ba432d7..a7210c5 100644 --- a/examples/ex15.bom.tsv +++ b/examples/ex15.bom.tsv @@ -1,5 +1,5 @@ Id Description Qty Unit Designators Manufacturer MPN 1 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 2 Connector, Molex KK 254, female, 7 pins 2 X1, X2 -3 shortPartA 42 mm X1 WireViz 42XCD42A5 -4 shortPartB 1 X1 WireViz 42XCD42A5 +3 shortPartA 42 mm X1-SH1 WireViz 42XCD42A5 +4 shortPartB 1 X1-SH2 WireViz 42XCD42A5 diff --git a/examples/ex15.gv b/examples/ex15.gv index 1d5f481..6ddf27f 100644 --- a/examples/ex15.gv +++ b/examples/ex15.gv @@ -83,12 +83,12 @@ graph { - +
126 mm x #3 (shortPartA)42 mm x SH1 x #3 (shortPartA)
- +
1 x #4 (shortPartB)1 x SH2 x #4 (shortPartB)
diff --git a/examples/ex15.html b/examples/ex15.html index 52c8d11..1851aec 100644 --- a/examples/ex15.html +++ b/examples/ex15.html @@ -33,285 +33,285 @@ - + - + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - - -SH1 - -SH2 - - -GND - - - - -1 - -VCC - - - - -2 - -RX - - - -3 - -TX - - - -4 - -GND - - - - -5 - -VCC - - - - -6 - -GND - - - - -7 - -Additional components - -126 mm x #3 (shortPartA) - -1 x #4 (shortPartB) + + +X1 + +Molex KK 254 + +female + +7-pin + + +SH1 + +SH2 + + +GND + + + + +1 + +VCC + + + + +2 + +RX + + + +3 + +TX + + + +4 + +GND + + + + +5 + +VCC + + + + +6 + +GND + + + + +7 + +Additional components + +42 mm x SH1 x #3 (shortPartA) + +1 x SH2 x #4 (shortPartB) 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 - + @@ -358,7 +358,7 @@ shortPartA 42 mm - X1 + X1-SH1 WireViz 42XCD42A5 @@ -367,7 +367,7 @@ shortPartB 1 - X1 + X1-SH2 WireViz 42XCD42A5 diff --git a/examples/ex15.png b/examples/ex15.png index 06ced7b..ade529e 100644 Binary files a/examples/ex15.png and b/examples/ex15.png differ diff --git a/examples/ex15.svg b/examples/ex15.svg index 4f64701..472e703 100644 --- a/examples/ex15.svg +++ b/examples/ex15.svg @@ -4,285 +4,285 @@ - + - + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - - -SH1 - -SH2 - - -GND - - - - -1 - -VCC - - - - -2 - -RX - - - -3 - -TX - - - -4 - -GND - - - - -5 - -VCC - - - - -6 - -GND - - - - -7 - -Additional components - -126 mm x #3 (shortPartA) - -1 x #4 (shortPartB) + + +X1 + +Molex KK 254 + +female + +7-pin + + +SH1 + +SH2 + + +GND + + + + +1 + +VCC + + + + +2 + +RX + + + +3 + +TX + + + +4 + +GND + + + + +5 + +VCC + + + + +6 + +GND + + + + +7 + +Additional components + +42 mm x SH1 x #3 (shortPartA) + +1 x SH2 x #4 (shortPartB) 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 8b4b8e1..f90fa23 100644 --- a/examples/ex15.yml +++ b/examples/ex15.yml @@ -7,14 +7,14 @@ connectors: - SH1: [1, 5, 7] - SH2: [2, 6] additional_components: - - shorts: [SH1, LO1, LO2] + - references: SH1 color: PK manufacturer: WireViz mpn: 42XCD42A5 type: shortPartA qty: 42 unit: mm - - shorts: SH2 + - references: SH2 color: RD manufacturer: WireViz mpn: 42XCD42A5 diff --git a/examples/ex16.bom.tsv b/examples/ex16.bom.tsv index ff9bd02..32b8aff 100644 --- a/examples/ex16.bom.tsv +++ b/examples/ex16.bom.tsv @@ -1,6 +1,6 @@ Id Description Qty Unit Designators Manufacturer MPN 1 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m W1 2 Connector, Molex KK 254, female, 7 pins 2 X1, X2 -3 shortPartA 42 mm X1 WireViz 42XCD42A5 -4 shortPartB 74 mm X1 WireViz 42XCD42A5 -5 shortPartC 21 mm X2 WireViz 42XCD42A5 +3 shortPartA 42 mm X1-LO1 WireViz 42XCD42A5 +4 shortPartB 74 mm X1-LO2 WireViz 42XCD42A5 +5 shortPartC 21 mm X2-LO1; X2-LO2 WireViz 42XCD42A5 diff --git a/examples/ex16.gv b/examples/ex16.gv index 0d46fb7..4ef5a47 100644 --- a/examples/ex16.gv +++ b/examples/ex16.gv @@ -58,12 +58,12 @@ graph {
- +
42 mm x shortPartA
WireViz: 42XCD42A5
42 mm x LO1 x shortPartA
WireViz: 42XCD42A5
- +
74 mm x shortPartB
WireViz: 42XCD42A5
74 mm x LO2 x shortPartB
WireViz: 42XCD42A5
@@ -127,7 +127,7 @@ graph { - +
42 mm x shortPartC
WireViz: 42XCD42A5
42 mm x LO1; LO2 x shortPartC
WireViz: 42XCD42A5
diff --git a/examples/ex16.html b/examples/ex16.html index 259901e..269a091 100644 --- a/examples/ex16.html +++ b/examples/ex16.html @@ -33,10 +33,10 @@ - + - + X1 @@ -80,10 +80,10 @@ Additional components -42 mm x shortPartA +42 mm x LO1 x shortPartA WireViz: 42XCD42A5 -74 mm x shortPartB +74 mm x LO2 x shortPartB WireViz: 42XCD42A5 @@ -190,47 +190,47 @@ X2 - - -X2 - -Molex KK 254 - -female - -7-pin - -1 - -GND - -2 - -VCC - -3 - -RX - -4 - -TX - -5 - -GND - -6 - -VCC - -7 - -GND - -Additional components - -42 mm x shortPartC + + +X2 + +Molex KK 254 + +female + +7-pin + +1 + +GND + +2 + +VCC + +3 + +RX + +4 + +TX + +5 + +GND + +6 + +VCC + +7 + +GND + +Additional components + +42 mm x LO1; LO2 x shortPartC WireViz: 42XCD42A5 @@ -264,23 +264,23 @@ X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + @@ -327,7 +327,7 @@ shortPartA 42 mm - X1 + X1-LO1 WireViz 42XCD42A5 @@ -336,7 +336,7 @@ shortPartB 74 mm - X1 + X1-LO2 WireViz 42XCD42A5 @@ -345,7 +345,7 @@ shortPartC 21 mm - X2 + X2-LO1; X2-LO2 WireViz 42XCD42A5 diff --git a/examples/ex16.png b/examples/ex16.png index 3fd356a..aa0d205 100644 Binary files a/examples/ex16.png and b/examples/ex16.png differ diff --git a/examples/ex16.svg b/examples/ex16.svg index 6d4dae2..ff89d33 100644 --- a/examples/ex16.svg +++ b/examples/ex16.svg @@ -4,10 +4,10 @@ - + - + X1 @@ -51,10 +51,10 @@ Additional components -42 mm x shortPartA +42 mm x LO1 x shortPartA WireViz: 42XCD42A5 -74 mm x shortPartB +74 mm x LO2 x shortPartB WireViz: 42XCD42A5 @@ -161,47 +161,47 @@ X2 - - -X2 - -Molex KK 254 - -female - -7-pin - -1 - -GND - -2 - -VCC - -3 - -RX - -4 - -TX - -5 - -GND - -6 - -VCC - -7 - -GND - -Additional components - -42 mm x shortPartC + + +X2 + +Molex KK 254 + +female + +7-pin + +1 + +GND + +2 + +VCC + +3 + +RX + +4 + +TX + +5 + +GND + +6 + +VCC + +7 + +GND + +Additional components + +42 mm x LO1; LO2 x shortPartC WireViz: 42XCD42A5 @@ -235,23 +235,23 @@ X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + diff --git a/examples/ex16.yml b/examples/ex16.yml index f1a790c..da42416 100644 --- a/examples/ex16.yml +++ b/examples/ex16.yml @@ -10,14 +10,14 @@ connectors: - LO1: [1, 5, 7] - LO2: [2, 6] additional_components: - - shorts: LO1 + - references: LO1 color: PK manufacturer: WireViz mpn: 42XCD42A5 type: shortPartA qty: 42 unit: mm - - shorts: LO2 + - references: LO2 color: RD manufacturer: WireViz mpn: 42XCD42A5 @@ -33,7 +33,7 @@ connectors: - LO1: [1, 5, 7] - LO2: [2, 6] additional_components: - - shorts: [LO1, LO2] + - references: [LO1, LO2] color: PK manufacturer: WireViz mpn: 42XCD42A5 diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 07681a2..600bc34 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -129,7 +129,7 @@ class AdditionalComponent: qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = None bgcolor: Optional[Color] = None color: Optional[Color] = None - shorts: Optional[List[str]] = field(default_factory=list) + references: Optional[List[str]] = field(default_factory=list) @property def description(self) -> str: diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 30ee473..e082e48 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -67,9 +67,9 @@ def check_old(node: str, old_attr: dict, args: dict) -> None: if attr in args: raise ValueError(f"'{attr}' in {node}: '{attr}' {descr}") -def getAddCompFromShort(short, part): +def getAddCompFromRef(reference, part): for comp in part.additional_components: - if short in comp.shorts: + if reference in comp.references: return comp; @dataclass @@ -273,7 +273,7 @@ class Harness: for short in connector.shorts: shortName = list(short.keys())[0] shortPins = list(short.values())[0] - shortComp = getAddCompFromShort(shortName, connector) + shortComp = getAddCompFromRef(shortName, connector) shColor = "BK" if shortComp != None and shortComp.color != None: @@ -300,7 +300,7 @@ class Harness: for short in connector.shorts: shortName = list(short.keys())[0] shortPins = list(short.values())[0] - shortComp = getAddCompFromShort(shortName, connector) + shortComp = getAddCompFromRef(shortName, connector) shColor = "BK" if shortComp != None and shortComp.color != None: @@ -326,10 +326,9 @@ class Harness: ) for loop in connector.loops: - # print(loop) loopName = list(loop.keys())[0] loopPins = list(loop.values())[0] - loopComp = getAddCompFromShort(loopName, connector) + loopComp = getAddCompFromRef(loopName, connector) loColor = "BK" if loopComp != None and loopComp.color != None: diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 218d3d6..41f01b4 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -40,18 +40,19 @@ def get_additional_component_table( part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier) - ]: + ]: - if type(part.shorts) == str: - numShorts = 1 + if type(part.references) == str: + numRef = 1 else: - numShorts = len(part.shorts) + numRef = len(part.references) - if numShorts > 0: + if numRef > 0: common_args = { - "qty": part.qty * numShorts, + "qty": part.qty * numRef, "unit": part.unit, "bgcolor": part.bgcolor, + "designators": part.references, } else: common_args = { @@ -91,11 +92,22 @@ def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOM "description": part.description, "qty": part.qty * component.get_qty_multiplier(part.qty_multiplier), "unit": part.unit, - "designators": component.name if component.show_name else None, + "designators": additional_component_bom_desig(component, part), # component.name if component.show_name else None, **optional_fields(part), } ) return bom_entries +# "designators": part.references, +def additional_component_bom_desig(component: Union[Connector, Cable], part) -> Union[str, None]: + if component.show_name and not part.references: + return component.name + elif component.show_name and part.references: + if type(part.references) == str: + return component.name + "-" + part.references + else: + return '; '.join([component.name + "-" + x for x in part.references]) + else: + return None def bom_entry_key(entry: BOMEntry) -> BOMKey: """Return a tuple of string values from the dict that must be equal to join BOM entries.""" @@ -263,6 +275,7 @@ def component_table_entry( mpn: Optional[str] = None, supplier: Optional[str] = None, spn: Optional[str] = None, + designators: Optional[str] = None, ) -> str: """Return a diagram node table row string with an additional component.""" part_number_list = [ @@ -273,6 +286,7 @@ def component_table_entry( output = ( f"{qty}" + (f" {unit}" if unit else "") + + (f" x {designators_info_string(designators)}" if designators else "") + f" x {type}" + ("
" if any(part_number_list) else "") + (", ".join([pn for pn in part_number_list if pn])) @@ -294,6 +308,11 @@ def pn_info_string( else: return None +def designators_info_string(designators: list) -> str: + if type(designators) == str: + return designators + else: + return '; '.join(designators) def index_if_list(value: Any, index: int) -> Any: """Return the value indexed if it is a list, or simply the value otherwise."""