1
1
#!/usr/bin/env python3
2
2
# -*- coding: utf-8 -*-
3
3
4
- from typing import Optional , List , Any , Union
4
+ from typing import Optional , List , Union
5
5
from dataclasses import dataclass , field , InitVar
6
6
from pathlib import Path
7
7
from wireviz .wv_helper import int2tuple , aspect_ratio
10
10
# Literal type aliases below are commented to avoid requiring python 3.8
11
11
ConnectorMultiplier = str # = Literal['pincount', 'populated']
12
12
CableMultiplier = str # = Literal['wirecount', 'terminations', 'length', 'total_length']
13
+ ImageScale = str # = Literal['false', 'true', 'width', 'height', 'both']
14
+
15
+ Designator = str # Case insensitive unique name of connector or cable
16
+ Pin = Union [int , str ] # Pin identifier
17
+ Wire = Union [int , str ] # Wire number or 's' for shield
18
+ MLstr = str # Multi-line string where any newline is properly handled
19
+ Color = str # Two-letter color name = Literal[wv_colors._color_hex.keys()]
20
+ Colors = str # One or more two-letter color names (Color) concatenated into one string
21
+ ColorScheme = str # Color scheme name = Literal[wv_colors.COLOR_CODES.keys()]
13
22
14
23
15
24
@dataclass
16
25
class Image :
17
26
gv_dir : InitVar [Path ] # Directory of .gv file injected as context during parsing
18
27
# Attributes of the image object <img>:
19
28
src : str
20
- scale : Optional [str ] = None # false | true | width | height | both
29
+ scale : Optional [ImageScale ] = None
21
30
# Attributes of the image cell <td> containing the image:
22
31
width : Optional [int ] = None
23
32
height : Optional [int ] = None
24
33
fixedsize : Optional [bool ] = None
25
34
# Contents of the text cell <td> just below the image cell:
26
- caption : Optional [str ] = None
35
+ caption : Optional [MLstr ] = None
27
36
# See also HTML doc at https://graphviz.org/doc/info/shapes.html#html
28
37
29
38
def __post_init__ (self , gv_dir ):
@@ -49,10 +58,10 @@ def __post_init__(self, gv_dir):
49
58
50
59
@dataclass
51
60
class AdditionalComponent :
52
- type : str
53
- subtype : Optional [str ] = None
54
- manufacturer : Optional [str ] = None
55
- mpn : Optional [str ] = None
61
+ type : MLstr
62
+ subtype : Optional [MLstr ] = None
63
+ manufacturer : Optional [MLstr ] = None
64
+ mpn : Optional [MLstr ] = None
56
65
pn : Optional [str ] = None
57
66
qty : float = 1
58
67
unit : Optional [str ] = None
@@ -65,25 +74,25 @@ def description(self) -> str:
65
74
66
75
@dataclass
67
76
class Connector :
68
- name : str
69
- manufacturer : Optional [str ] = None
70
- mpn : Optional [str ] = None
77
+ name : Designator
78
+ manufacturer : Optional [MLstr ] = None
79
+ mpn : Optional [MLstr ] = None
71
80
pn : Optional [str ] = None
72
81
style : Optional [str ] = None
73
82
category : Optional [str ] = None
74
- type : Optional [str ] = None
75
- subtype : Optional [str ] = None
83
+ type : Optional [MLstr ] = None
84
+ subtype : Optional [MLstr ] = None
76
85
pincount : Optional [int ] = None
77
86
image : Optional [Image ] = None
78
- notes : Optional [str ] = None
79
- pinlabels : List [Any ] = field (default_factory = list )
80
- pins : List [Any ] = field (default_factory = list )
81
- color : Optional [str ] = None
87
+ notes : Optional [MLstr ] = None
88
+ pinlabels : List [Pin ] = field (default_factory = list )
89
+ pins : List [Pin ] = field (default_factory = list )
90
+ color : Optional [Color ] = None
82
91
show_name : Optional [bool ] = None
83
92
show_pincount : Optional [bool ] = None
84
93
hide_disconnected_pins : bool = False
85
94
autogenerate : bool = False
86
- loops : List [Any ] = field (default_factory = list )
95
+ loops : List [List [ Pin ] ] = field (default_factory = list )
87
96
ignore_in_bom : bool = False
88
97
additional_components : List [AdditionalComponent ] = field (default_factory = list )
89
98
@@ -155,23 +164,23 @@ def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> i
155
164
156
165
@dataclass
157
166
class Cable :
158
- name : str
159
- manufacturer : Optional [ Union [str , List [str ]] ] = None
160
- mpn : Optional [ Union [str , List [str ]] ] = None
161
- pn : Optional [ Union [str , List [str ]] ] = None
167
+ name : Designator
168
+ manufacturer : Union [MLstr , List [MLstr ], None ] = None
169
+ mpn : Union [MLstr , List [MLstr ], None ] = None
170
+ pn : Union [str , List [str ], None ] = None
162
171
category : Optional [str ] = None
163
- type : Optional [str ] = None
172
+ type : Optional [MLstr ] = None
164
173
gauge : Optional [float ] = None
165
174
gauge_unit : Optional [str ] = None
166
175
show_equiv : bool = False
167
176
length : float = 0
168
- color : Optional [str ] = None
177
+ color : Optional [Color ] = None
169
178
wirecount : Optional [int ] = None
170
- shield : Union [bool , str ] = False # False | True | color
179
+ shield : Union [bool , Color ] = False
171
180
image : Optional [Image ] = None
172
- notes : Optional [str ] = None
173
- colors : List [Any ] = field (default_factory = list )
174
- color_code : Optional [str ] = None
181
+ notes : Optional [MLstr ] = None
182
+ colors : List [Colors ] = field (default_factory = list )
183
+ color_code : Optional [ColorScheme ] = None
175
184
show_name : bool = True
176
185
show_wirecount : bool = True
177
186
ignore_in_bom : bool = False
@@ -264,8 +273,8 @@ def get_qty_multiplier(self, qty_multiplier: Optional[CableMultiplier]) -> float
264
273
265
274
@dataclass
266
275
class Connection :
267
- from_name : Any
268
- from_port : Any
269
- via_port : Any
270
- to_name : Any
271
- to_port : Any
276
+ from_name : Optional [ Designator ]
277
+ from_port : Optional [ Pin ]
278
+ via_port : Wire
279
+ to_name : Optional [ Designator ]
280
+ to_port : Optional [ Pin ]
0 commit comments