diff --git a/examples/ex15.bom.tsv b/examples/ex15.bom.tsv index ed86637..ba432d7 100644 --- a/examples/ex15.bom.tsv +++ b/examples/ex15.bom.tsv @@ -1,6 +1,5 @@ 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 +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 diff --git a/examples/ex15.gv b/examples/ex15.gv index d998aab..1d5f481 100644 --- a/examples/ex15.gv +++ b/examples/ex15.gv @@ -76,6 +76,21 @@ graph { + + + +
Additional components
+ + + + +
126 mm x #3 (shortPartA)
+ + + + +
1 x #4 (shortPartB)
+ > 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 51c8492..52c8d11 100644 --- a/examples/ex15.html +++ b/examples/ex15.html @@ -33,279 +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 + + +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: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 - + @@ -331,15 +337,6 @@
1 - - 2 - - X2/SH1, X2/SH2 - - -
-
- 2 Cable, Serial, 4 x 0.25 mm² shielded 0.2 m @@ -348,7 +345,7 @@
- 3 + 2 Connector, Molex KK 254, female, 7 pins 2 @@ -357,20 +354,20 @@
- 4 - shortPart - 1 - - X1/SH1 + 3 + shortPartA + 42 + mm + X1 WireViz 42XCD42A5
- 5 - shortPart - 42 - mm - X1/SH2 + 4 + shortPartB + 1 + + X1 WireViz 42XCD42A5
diff --git a/examples/ex15.png b/examples/ex15.png index 45a20e9..06ced7b 100644 Binary files a/examples/ex15.png and b/examples/ex15.png differ diff --git a/examples/ex15.svg b/examples/ex15.svg index b0bca2b..4f64701 100644 --- a/examples/ex15.svg +++ b/examples/ex15.svg @@ -4,279 +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 + + +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: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 bd7314c..8b4b8e1 100644 --- a/examples/ex15.yml +++ b/examples/ex15.yml @@ -4,28 +4,28 @@ connectors: subtype: female pinlabels: [GND, VCC, RX, TX, GND, VCC, GND] # pincount is implicit in pinout shorts: - SH1: - pins: [1, 5, 7] + - SH1: [1, 5, 7] + - SH2: [2, 6] + additional_components: + - shorts: [SH1, LO1, LO2] color: PK manufacturer: WireViz mpn: 42XCD42A5 - description: shortPart - SH2: - pins: [2, 6] + type: shortPartA + qty: 42 + unit: mm + - shorts: SH2 color: RD manufacturer: WireViz mpn: 42XCD42A5 - description: shortPart - length: 42 + type: shortPartB X2: type: Molex KK 254 subtype: female pinlabels: [GND, VCC, RX, TX, GND, VCC, GND] shorts: - SH1: - pins: [1, 5, 7] - SH2: - pins: [2, 6] + - SH1: [1, 5, 7] + - SH2: [2, 6] cables: W1: diff --git a/examples/ex16.bom.tsv b/examples/ex16.bom.tsv index 1c86629..ff9bd02 100644 --- a/examples/ex16.bom.tsv +++ b/examples/ex16.bom.tsv @@ -1,5 +1,6 @@ -Id Description Qty Unit Designators -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 +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 diff --git a/examples/ex16.gv b/examples/ex16.gv index cfbaae9..0d46fb7 100644 --- a/examples/ex16.gv +++ b/examples/ex16.gv @@ -4,11 +4,6 @@ graph { graph [bgcolor="#FFFFFF" fontname=arial nodesep=0.33 rankdir=LR ranksep=2] node [fillcolor="#FFFFFF" fontname=arial height=0 margin=0 shape=none style=filled width=0] edge [fontname=arial style=bold] - edge [color="#000000:#FF66CC:#000000"] - X1:p1r:e -- X1:p5r:e - X1:p5r:e -- X1:p7r:e - edge [color="#FF0000" headclip=false style="solid,bold" tailclip=false] - X1:p2j:c -- X1:p6j:c [straight=straight] edge [headclip=true style=bold tailclip=true] X1 [label=<
@@ -26,55 +21,58 @@ graph { + + +
- - - - - - - - - - - -
SH2
GND 1
VCC 2
RX 3
TX 4
GND 5
VCC 6
GND 7
+ + +
Additional components
+
+ + +
42 mm x shortPartA
WireViz: 42XCD42A5
+
+ + +
74 mm x shortPartB
WireViz: 42XCD42A5
+
> fillcolor="#FFFFFF" shape=box style=filled] - edge [color="#000000:#000000:#000000"] - X2:p1l:w -- X2:p5l:w - X2:p5l:w -- X2:p7l:w - edge [color="#000000:#000000:#000000"] - X2:p2l:w -- X2:p6l:w + edge [color="#000000:#FF66CC:#000000"] + X1:p1r:e -- X1:p5r:e + X1:p5r:e -- X1:p7r:e + edge [color="#000000:#FF0000:#000000"] + X1:p2r:e -- X1:p6r:e edge [headclip=true style=bold tailclip=true] X2 [label=< @@ -122,8 +120,23 @@ graph {
+ + + +
Additional components
+ + + + +
42 mm x shortPartC
WireViz: 42XCD42A5
+ > fillcolor="#FFFFFF" shape=box style=filled] + edge [color="#000000:#FF66CC:#000000"] + X2:p1l:w -- X2:p5l:w + X2:p5l:w -- X2:p7l:w + edge [color="#000000:#FF66CC:#000000"] + X2:p2l:w -- X2:p6l:w edge [color="#000000:#895956:#000000"] X1:p1r:e -- W1:w1:w W1:w1:e -- X2:p1l:w diff --git a/examples/ex16.html b/examples/ex16.html index 7bb39a3..259901e 100644 --- a/examples/ex16.html +++ b/examples/ex16.html @@ -33,252 +33,254 @@ - - - + + + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - - -SH2 - - -GND - - -1 - -VCC - - - -2 - -RX - - -3 - -TX - - -4 - -GND - - -5 - -VCC - - - -6 - -GND - - -7 + + +X1 + +Molex KK 254 + +female + +7-pin + +GND + +1 + +VCC + +2 + +RX + +3 + +TX + +4 + +GND + +5 + +VCC + +6 + +GND + +7 + +Additional components + +42 mm x shortPartA +WireViz: 42XCD42A5 + +74 mm x shortPartB +WireViz: 42XCD42A5 X1:e--X1:e - - - + + + X1:e--X1:e - - - + + + -X1:c--X1:c - +X1:e--X1:e + + + 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 - -1 - -GND - -2 - -VCC - -3 - -RX - -4 - -TX - -5 - -GND - -6 - -VCC - -7 - -GND + + +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 +WireViz: 42XCD42A5 W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + @@ -299,34 +301,53 @@ Qty Unit Designators + Manufacturer + MPN
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 + 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
diff --git a/examples/ex16.png b/examples/ex16.png index 54f0441..3fd356a 100644 Binary files a/examples/ex16.png and b/examples/ex16.png differ diff --git a/examples/ex16.svg b/examples/ex16.svg index 17dbd81..6d4dae2 100644 --- a/examples/ex16.svg +++ b/examples/ex16.svg @@ -4,252 +4,254 @@ - - - + + + X1 - - -X1 - -Molex KK 254 - -female - -7-pin - - -SH2 - - -GND - - -1 - -VCC - - - -2 - -RX - - -3 - -TX - - -4 - -GND - - -5 - -VCC - - - -6 - -GND - - -7 + + +X1 + +Molex KK 254 + +female + +7-pin + +GND + +1 + +VCC + +2 + +RX + +3 + +TX + +4 + +GND + +5 + +VCC + +6 + +GND + +7 + +Additional components + +42 mm x shortPartA +WireViz: 42XCD42A5 + +74 mm x shortPartB +WireViz: 42XCD42A5 X1:e--X1:e - - - + + + X1:e--X1:e - - - + + + -X1:c--X1:c - +X1:e--X1:e + + + 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 - -1 - -GND - -2 - -VCC - -3 - -RX - -4 - -TX - -5 - -GND - -6 - -VCC - -7 - -GND + + +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 +WireViz: 42XCD42A5 W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + W1:e--X2:w - - - + + + X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + X2:w--X2:w - - - + + + diff --git a/examples/ex16.yml b/examples/ex16.yml index 33e4034..f1a790c 100644 --- a/examples/ex16.yml +++ b/examples/ex16.yml @@ -6,27 +6,40 @@ connectors: type: Molex KK 254 # more information subtype: female pinlabels: [GND, VCC, RX, TX, GND, VCC, GND] # pincount is implicit in pinout - shorts: - SH1: - pins: [1, 5, 7] + loops: + - LO1: [1, 5, 7] + - LO2: [2, 6] + additional_components: + - shorts: LO1 color: PK - type: loop - length: 42 - SH2: - pins: [2, 6] + manufacturer: WireViz + mpn: 42XCD42A5 + type: shortPartA + qty: 42 + unit: mm + - shorts: LO2 color: RD - length: 42.3 + manufacturer: WireViz + mpn: 42XCD42A5 + type: shortPartB + qty: 74 + unit: mm + X2: type: Molex KK 254 subtype: female pinlabels: [GND, VCC, RX, TX, GND, VCC, GND] - shorts: - SH1: - pins: [1, 5, 7] - type: loop - SH2: - pins: [2, 6] - type: loop + loops: + - LO1: [1, 5, 7] + - LO2: [2, 6] + additional_components: + - shorts: [LO1, LO2] + color: PK + manufacturer: WireViz + mpn: 42XCD42A5 + type: shortPartC + qty: 21 + unit: mm cables: W1: diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 6ec0b30..07681a2 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -18,7 +18,7 @@ MultilineHypertext = ( Designator = PlainText # Case insensitive unique name of connector or cable # Literal type aliases below are commented to avoid requiring python 3.8 -ConnectorMultiplier = PlainText # = Literal['pincount', 'populated', 'unpopulated'] +ConnectorMultiplier = PlainText # = Literal['pincount', 'populated', 'unpopulated', 'shorts'] CableMultiplier = ( PlainText # = Literal['wirecount', 'terminations', 'length', 'total_length'] ) @@ -128,6 +128,8 @@ class AdditionalComponent: unit: Optional[str] = None qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = None bgcolor: Optional[Color] = None + color: Optional[Color] = None + shorts: Optional[List[str]] = field(default_factory=list) @property def description(self) -> str: @@ -136,19 +138,6 @@ class AdditionalComponent: t = t + st return t -@dataclass -class Short: - name: Designator - pins: List[Pin] = field(default_factory=list) - color: Optional[Color] = None - manufacturer: Optional[MultilineHypertext] = None - mpn: Optional[MultilineHypertext] = None - description: Optional[str] = None - length: Optional[float] = None - length_unit: Optional[str] = None - type: Optional[MultilineHypertext] = None - - @dataclass class Connector: name: Designator @@ -173,10 +162,10 @@ class Connector: show_name: Optional[bool] = None show_pincount: Optional[bool] = None hide_disconnected_pins: bool = False - loops: List[List[Pin]] = field(default_factory=list) + loops: Dict = field(default_factory=list)# List[List[Pin]] = field(default_factory=list) ignore_in_bom: bool = False#ß additional_components: List[AdditionalComponent] = field(default_factory=list) - shorts: List[Short] = field(default_factory=list) + shorts: Dict = field(default_factory=list) def __post_init__(self) -> None: @@ -218,38 +207,31 @@ class Connector: # hide pincount for simple (1 pin) connectors by default self.show_pincount = self.style != "simple" - for loop in self.loops: - # TODO: allow using pin labels in addition to pin numbers, just like when defining regular connections - # TODO: include properties of wire used to create the loop - if len(loop) != 2: - raise Exception("Loops must be between exactly two pins!") - for pin in loop: - if pin not in self.pins: - raise Exception( - f'Unknown loop pin "{pin}" for connector "{self.name}"!' - ) - # Make sure loop connected pins are not hidden. - self.activate_pin(pin, None) + # for loop in self.loops: + # # TODO: allow using pin labels in addition to pin numbers, just like when defining regular connections + # # TODO: include properties of wire used to create the loop + # if len(loop) != 2: + # raise Exception("Loops must be between exactly two pins!") + # for pin in loop: + # if pin not in self.pins: + # raise Exception( + # f'Unknown loop pin "{pin}" for connector "{self.name}"!' + # ) + # # Make sure loop connected pins are not hidden. + # self.activate_pin(pin, None) for i, item in enumerate(self.additional_components): if isinstance(item, dict): self.additional_components[i] = AdditionalComponent(**item) - - 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): - self.shorts[i] = Short(**item) - def activate_pin(self, pin: Pin, side: Side) -> None: self.visible_pins[pin] = True if side == Side.LEFT: self.ports_left = True elif side == Side.RIGHT: self.ports_right = True + + # def get_qty_shorts_AddComp() def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> int: if not qty_multiplier: diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index ae47130..30ee473 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from itertools import zip_longest from pathlib import Path from typing import Any, List, Union +from dataclasses import asdict from graphviz import Graph @@ -20,7 +21,6 @@ from wireviz.DataClasses import ( Options, Tweak, Side, - Short, ) from wireviz.svgembed import embed_svg_images_file from wireviz.wv_bom import ( @@ -66,6 +66,11 @@ def check_old(node: str, old_attr: dict, args: dict) -> None: for attr, descr in old_attr.items(): if attr in args: raise ValueError(f"'{attr}' in {node}: '{attr}' {descr}") + +def getAddCompFromShort(short, part): + for comp in part.additional_components: + if short in comp.shorts: + return comp; @dataclass class Harness: @@ -219,23 +224,17 @@ class Harness: pinhtml.append( '
' ) - - intShorts = False - - for shortName in connector.shorts: - if connector.shorts[shortName].get("type") == None or connector.shorts[shortName].get("type") == "internal": - intShorts = True - if len(connector.shorts) > 0 and intShorts: + if len(connector.shorts) > 0: pinhtml.append(" ") if connector.ports_left: pinhtml.append(f' ') if connector.pinlabels: pinhtml.append(f" ") - for shortName in connector.shorts: - if connector.shorts[shortName].get("type") == None or connector.shorts[shortName].get("type") == "internal": - pinhtml.append(f' ') + for short in connector.shorts: + shortName = list(short.keys())[0] + pinhtml.append(f' ') if connector.ports_right: pinhtml.append(f' ') @@ -271,25 +270,19 @@ class Harness: else: pinhtml.append(' ') - 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'); - # shMpn = short.get('mpn'); - # shDescription = short.get('description'); + for short in connector.shorts: + shortName = list(short.keys())[0] + shortPins = list(short.values())[0] + shortComp = getAddCompFromShort(shortName, connector) - if shType == None or shType == "internal": - if shColor == None: - shColor = "BK" - - if pinindex+1 in shPins: - pinhtml.append(f' ') - else: - pinhtml.append(f' ') - elif shType == "loop": - pass + shColor = "BK" + if shortComp != None and shortComp.color != None: + shColor = shortComp.color + + if pinindex+1 in shortPins: + pinhtml.append(f' ') + else: + pinhtml.append(f' ') if connector.ports_right: @@ -304,43 +297,22 @@ class Harness: for row in html ] - 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'); - # shMpn = short.get('mpn'); - # shDescription = short.get('description'); + for short in connector.shorts: + shortName = list(short.keys())[0] + shortPins = list(short.values())[0] + shortComp = getAddCompFromShort(shortName, connector) - if shColor == None: - shColor = "BK" + shColor = "BK" + if shortComp != None and shortComp.color != None: + shColor = shortComp.color - - if shType == None or shType == "internal": - dot.attr("edge", color=str(wv_colors.translate_color(shColor, "HEX")), headclip="false", tailclip="false", style="solid,bold") - for i in range(1, len(shPins)): - dot.edge( - f"{connector.name}:p{shPins[i - 1]}j:c", - f"{connector.name}:p{shPins[i]}j:c", - straight="straight" - ) - elif shType == "loop": - dot.attr("edge", color=f'#000000:{wv_colors.translate_color(shColor, "HEX")}:#000000') - if connector.ports_left: - loop_side = "l" - loop_dir = "w" - elif connector.ports_right: - loop_side = "r" - loop_dir = "e" - else: - raise Exception("No side for loops") - - for i in range(1, len(shPins)): - dot.edge( - f"{connector.name}:p{shPins[i - 1]}{loop_side}:{loop_dir}", - f"{connector.name}:p{shPins[i]}{loop_side}:{loop_dir}", - ) + dot.attr("edge", color=str(wv_colors.translate_color(shColor, "HEX")), headclip="false", tailclip="false", style="solid,bold") + for i in range(1, len(shortPins)): + dot.edge( + f"{connector.name}:p{shortPins[i - 1]}j:c", + f"{connector.name}:p{shortPins[i]}j:c", + straight="straight" + ) dot.attr("edge", headclip="true", tailclip="true", style="bold") @@ -353,8 +325,17 @@ class Harness: fillcolor=translate_color(self.options.bgcolor_connector, "HEX"), ) - if len(connector.loops) > 0: - dot.attr("edge", color="#000000:#ffffff:#000000") + for loop in connector.loops: + # print(loop) + loopName = list(loop.keys())[0] + loopPins = list(loop.values())[0] + loopComp = getAddCompFromShort(loopName, connector) + + loColor = "BK" + if loopComp != None and loopComp.color != None: + loColor = loopComp.color + + dot.attr("edge", color=f"#000000:{wv_colors.translate_color(loColor, 'HEX')}:#000000") if connector.ports_left: loop_side = "l" loop_dir = "w" @@ -363,12 +344,28 @@ class Harness: loop_dir = "e" else: raise Exception("No side for loops") - for loop in connector.loops: + for i in range(1, len(loopPins)): dot.edge( - f"{connector.name}:p{loop[0]}{loop_side}:{loop_dir}", - f"{connector.name}:p{loop[1]}{loop_side}:{loop_dir}", + f"{connector.name}:p{loopPins[i - 1]}{loop_side}:{loop_dir}", + f"{connector.name}:p{loopPins[i]}{loop_side}:{loop_dir}", ) + # if len(connector.loops) > 0: + # dot.attr("edge", color="#000000:#ffffff:#000000") + # if connector.ports_left: + # loop_side = "l" + # loop_dir = "w" + # elif connector.ports_right: + # loop_side = "r" + # loop_dir = "e" + # else: + # raise Exception("No side for loops") + # for loop in connector.loops: + # dot.edge( + # f"{connector.name}:p{loop[0]}{loop_side}:{loop_dir}", + # f"{connector.name}:p{loop[1]}{loop_side}:{loop_dir}", + # ) + # determine if there are double- or triple-colored wires in the harness; # if so, pad single-color wires to make all wires of equal thickness pad = any( diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index c8e1584..218d3d6 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, Short +from wireviz.DataClasses import AdditionalComponent, Cable, Color, Connector 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, Short]) -> BOMEntry: +def optional_fields(part: Union[Connector, Cable, AdditionalComponent]) -> 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} @@ -41,11 +41,24 @@ def get_additional_component_table( for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier) ]: - common_args = { - "qty": part.qty * component.get_qty_multiplier(part.qty_multiplier), - "unit": part.unit, - "bgcolor": part.bgcolor, - } + + if type(part.shorts) == str: + numShorts = 1 + else: + numShorts = len(part.shorts) + + if numShorts > 0: + common_args = { + "qty": part.qty * numShorts, + "unit": part.unit, + "bgcolor": part.bgcolor, + } + else: + common_args = { + "qty": part.qty * component.get_qty_multiplier(part.qty_multiplier), + "unit": part.unit, + "bgcolor": part.bgcolor, + } if harness.options.mini_bom_mode: id = get_bom_index( harness.bom(), @@ -64,7 +77,6 @@ def get_additional_component_table( ) return rows - def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOMEntry]: """Return a list of BOM entries with additional components.""" bom_entries = [] @@ -85,39 +97,6 @@ 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.""" if "key" not in entry: @@ -156,7 +135,6 @@ 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?
{shortName}{shortName}