-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.py
200 lines (164 loc) · 7 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from csv import reader
from array import array
from shapely.geometry import Polygon
from shapely.geometry import Point
from shapely.ops import cascaded_union
import locale
import re
import sys
import getopt
coordinates_mcu = {}
coordinates_mem = {}
connect = {}
decimal_point = locale.localeconv()['decimal_point']
route_table = []
jumps_list = []
solution = ''
jumps_count = 0
current_line = 0
def serve_route_table(newpoly):
global route_table
first_route = None
first_poly = None
#Serving new poly to route table, concatenating routes according to polys interlaces
for route in route_table:
for poly in route:
if (poly["layer"] == newpoly["layer"] and poly["poly"].intersects(newpoly["poly"])):
poly["poly"] = cascaded_union( [poly["poly"], newpoly["poly"]] )
if first_route == None:
first_route = route
first_poly = poly
else:
first_poly["poly"] = cascaded_union( [first_poly["poly"], poly["poly"]] )
route.remove( poly )
first_route += route
route_table.remove( route )
if first_route == None:
route_table.append( [ newpoly, ] )
def serve_route_table_jump():
global jumps_list
first_route = None
for jump in jumps_list:
for route in route_table:
for poly in route:
if (poly["poly"].contains( jump )):
if first_route == None:
first_route = route
else:
first_route += route
route_table.remove( route )
def parse_poly(command, solution):
global current_line
poly_object = {}
try:
#Get number of points and layer
edges_count = re.findall( "(?<=POLY)[^,]+(?=,)", command )
if len(edges_count) != 1:
print "Syntax error while getting points count in POLY, line #%d" % current_line
exit()
layer_number = re.findall( "(?<=,)[^\n\r]+(?=)", command )
if len(layer_number) != 1:
print "Syntax error while getting layer in POLY, line #%d" % current_line
exit()
poly_object["layer"] = int(layer_number[0])
if poly_object["layer"] > 10 or poly_object["layer"] < 1 :
print "Error on line %d - layer number should be in range [1, 10], found %d" % (current_line,
poly_object["layer"])
exit()
points_list = []
#Get all points
for iter in range(0, int(edges_count[0])):
points_line = solution.readline()
current_line += 1
points = points_line.split(';')
if len(points) != 2:
print "Syntax error extracting POLY point, line #%d" % current_line
exit()
points_list.append( (float(points[0].replace(',', decimal_point)),
float(points[1].replace(',', decimal_point))) )
except:
print "Syntax error, line #%d" % current_line
exit()
#Create shapely polygon
poly_object["poly"] = Polygon( points_list )
serve_route_table( poly_object )
def main():
global current_line
global route_table
global jumps_count
global jumps_list
inputfile = sys.argv[1]
#Load connect & coordinates files
with open('coordinates.csv', 'rU') as fcoords:
csvreader = reader( fcoords, delimiter=';' )
for row in csvreader:
if (int(row[1]) == 1):
coordinates_mcu[int(row[0])] = Point(
float(row[2].replace(',', decimal_point)),
float(row[3].replace(',', decimal_point)) )
else:
coordinates_mem[int(row[0])] = Point(
float(row[2].replace(',', decimal_point)),
float(row[3].replace(',', decimal_point)) )
with open('connect.csv', 'rU') as fcoords:
csvreader = reader( fcoords, delimiter=';' )
for row in csvreader:
connect[int(row[0])] = int(row[1])
#Load the solution file, create route table
solution = open(inputfile, 'rU')
while True:
current_line += 1
command = solution.readline()
if command.startswith( 'POLY' ):
parse_poly(command, solution)
elif command.startswith( 'JUMP' ):
jumps_count += 1
try:
point_x = re.findall("(?<=JUMP)[^;]+(?=;)", command)
if len(point_x) != 1:
print "Syntax error extracting JUMP point X coordinate, line #%d" % current_line
exit()
point_x = float(point_x[0].replace(',', decimal_point))
point_y = re.findall("(?<=;)[^;]+(?=)", command)
if len(point_y) != 1:
print "Syntax error extracting JUMP point Y coordinate, line #%d" % current_line
exit()
point_y = float(point_y[0].replace(',', decimal_point))
jumps_list.append( Point( point_x, point_y ) )
except:
print "Syntax error, line #%d" % current_line
exit()
if command == '':
break
serve_route_table_jump()
correct_connections = {}
#OK, checking connections are correct
for pin_mcu, point_mcu in coordinates_mcu.iteritems():
for route in route_table:
for poly in route:
if poly["poly"].intersects(point_mcu.buffer(0.1)) and poly["layer"] == 1:
for pin_mem, point_mem in coordinates_mem.iteritems():
if poly["poly"].intersects(point_mem.buffer(0.1)) and connect[pin_mcu] != pin_mem:
print "MCU pin %d and Memory pin %d are connected, though shouldn't" % (pin_mcu, pin_mem)
elif poly["poly"].contains(point_mem):
correct_connections[pin_mcu] = pin_mem
break
#Printing points that are not connected, but should be
for pin_mcu in range(1, 41):
if not(correct_connections.has_key( pin_mcu )):
print "MCU pin %d is NOT connected with Memory pin %d, though should" % (pin_mcu, connect[pin_mcu])
#Printing estimation of electrical length
el_length = 0.0
for route in route_table:
for poly in route:
el_length += poly["poly"].length / 2.0
print "S = %d" % el_length
print "Vias %d" % len(jumps_list)
#calculate layers used
layers = 1
for route in route_table:
for poly in route:
if poly["layer"] > layers:
layers = poly["layer"]
print "Layers used %d" % layers
main()