4
4
from .errors import DiagramSyntaxError , BOMError
5
5
6
6
7
- SMALL_COMPONENT_OR_BOM = re .compile (r' #*([A-Z]+)(\d*|\.\w+)(:[^\s]+)?#*' )
7
+ SMALL_COMPONENT_OR_BOM = re .compile (r" #*([A-Z]+)(\d*|\.\w+)(:[^\s]+)?#*" )
8
8
9
9
10
10
def find_small (grid : Grid ) -> tuple [list [Cbox ], list [BOMData ]]:
@@ -14,20 +14,24 @@ def find_small(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
14
14
boms : list [BOMData ] = []
15
15
for i , line in enumerate (grid .lines ):
16
16
for m in SMALL_COMPONENT_OR_BOM .finditer (line ):
17
- ident = m .group (2 ) or '0'
17
+ ident = m .group (2 ) or "0"
18
18
if m .group (3 ):
19
- boms .append (BOMData (m .group (1 ),
20
- ident , m .group (3 )[1 :]))
19
+ boms .append (BOMData (m .group (1 ), ident , m .group (3 )[1 :]))
21
20
else :
22
- components .append (Cbox (complex (m .start (), i ),
23
- complex (m .end () - 1 , i ),
24
- m .group (1 ), ident ))
21
+ components .append (
22
+ Cbox (
23
+ complex (m .start (), i ),
24
+ complex (m .end () - 1 , i ),
25
+ m .group (1 ),
26
+ ident ,
27
+ )
28
+ )
25
29
for z in range (* m .span (0 )):
26
30
grid .setmask (complex (z , i ))
27
31
return components , boms
28
32
29
33
30
- TOP_OF_BOX = re .compile (r' \.~+\.' )
34
+ TOP_OF_BOX = re .compile (r" \.~+\." )
31
35
32
36
33
37
def find_big (grid : Grid ) -> tuple [list [Cbox ], list [BOMData ]]:
@@ -49,35 +53,37 @@ def find_big(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
49
53
if cs == tb :
50
54
y2 = j
51
55
break
52
- if not cs [0 ] == cs [- 1 ] == ':' :
56
+ if not cs [0 ] == cs [- 1 ] == ":" :
53
57
raise DiagramSyntaxError (
54
- f'{ grid .filename } : Fragmented box '
55
- f'starting at line { y1 + 1 } , col { x1 + 1 } ' )
58
+ f"{ grid .filename } : Fragmented box "
59
+ f"starting at line { y1 + 1 } , col { x1 + 1 } "
60
+ )
56
61
else :
57
62
raise DiagramSyntaxError (
58
- f'{ grid .filename } : Unfinished box '
59
- f'starting at line { y1 + 1 } , col { x1 + 1 } ' )
63
+ f"{ grid .filename } : Unfinished box "
64
+ f"starting at line { y1 + 1 } , col { x1 + 1 } "
65
+ )
60
66
inside = grid .clip (complex (x1 , y1 ), complex (x2 , y2 ))
61
67
results , resb = find_small (inside )
62
68
if len (results ) == 0 and len (resb ) == 0 :
63
69
raise BOMError (
64
- f'{ grid .filename } : Box starting at '
65
- f'line { y1 + 1 } , col { x1 + 1 } is '
66
- f'missing reference designator' )
70
+ f"{ grid .filename } : Box starting at "
71
+ f"line { y1 + 1 } , col { x1 + 1 } is "
72
+ f"missing reference designator"
73
+ )
67
74
if len (results ) != 1 and len (resb ) != 1 :
68
75
raise BOMError (
69
- f'{ grid .filename } : Box starting at '
70
- f'line { y1 + 1 } , col { x1 + 1 } has '
71
- f'multiple reference designators' )
76
+ f"{ grid .filename } : Box starting at "
77
+ f"line { y1 + 1 } , col { x1 + 1 } has "
78
+ f"multiple reference designators"
79
+ )
72
80
if not results :
73
81
merd = resb [0 ]
74
82
else :
75
83
merd = results [0 ]
76
84
boxes .append (
77
- Cbox (complex (x1 , y1 ),
78
- complex (x2 - 1 , y2 ),
79
- merd .type ,
80
- merd .id ))
85
+ Cbox (complex (x1 , y1 ), complex (x2 - 1 , y2 ), merd .type , merd .id )
86
+ )
81
87
boms .extend (resb )
82
88
# mark everything
83
89
for i in range (x1 , x2 ):
@@ -94,10 +100,10 @@ def find_all(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
94
100
and masks off all of them, leaving only wires and extraneous text."""
95
101
b1 , l1 = find_big (grid )
96
102
b2 , l2 = find_small (grid )
97
- return b1 + b2 , l1 + l2
103
+ return b1 + b2 , l1 + l2
98
104
99
105
100
- if __name__ == ' __main__' :
106
+ if __name__ == " __main__" :
101
107
test_grid = Grid ("test_data/test_resistors.txt" )
102
108
bbb , _ = find_all (test_grid )
103
109
all_pts = []
0 commit comments