Attempting to write a parsing algorithm that's simple and works

master
Aaron Goldstein 2020-04-15 22:05:09 -07:00
parent a9bd5b1a86
commit 233a67edf1
1 changed files with 52 additions and 1 deletions

View File

@ -75,7 +75,58 @@ def determine_parts_list(schematic):
return parts_list
def determine_net_list(schematic):
print('NOT IMPLEMENTED')
wires = [ record for record in schematic["records"] if record["RECORD"] == "27" ]
contacts = [ record for record in schematic["records"] if record["RECORD"] == "2" ]
wire_groups = []
p = re.compile('^(?P<prefix>X)(?P<index>\d+)$')
for wire in wires:
coord_name_matches = [x for x in [p.match(key) for key in wire.keys()] if x]
wire['coords'] = [ ( int(wire['X' + match.group('index')]) , int(wire['Y' + match.group('index')]) )
for match in coord_name_matches ]
group_counter = 0
for wire_a in wires:
other_wires = [wire for wire in wires if wire["index"] != wire_a["index"]]
wire_a_vertex_pairs = [(wire_a['coords'][i], wire_a['coords'][i + 1]) for i in
range(len(wire_a['coords']) - 1)]
for wire_b in other_wires:
wire_b_vertex_pairs = [(wire_b['coords'][i], wire_b['coords'][i + 1]) for i in
range(len(wire_b['coords']) - 1)]
for vertex_a_pair in wire_a_vertex_pairs:
for vertex_b_pair in wire_b_vertex_pairs:
if ( (( vertex_a_pair[0][0] <= vertex_b_pair[0][0] <= vertex_a_pair[1][0] )
and ( vertex_a_pair[0][1] <= vertex_b_pair[0][1] <= vertex_a_pair[1][1] ))
or (( vertex_a_pair[0][0] >= vertex_b_pair[0][0] >= vertex_a_pair[1][0] )
and ( vertex_a_pair[0][1] >= vertex_b_pair[0][1] >= vertex_a_pair[1][1] ))
or (( vertex_a_pair[0][0] <= vertex_b_pair[1][0] <= vertex_a_pair[1][0] )
and ( vertex_a_pair[0][1] <= vertex_b_pair[1][1] <= vertex_a_pair[1][1] ))
or (( vertex_a_pair[0][0] >= vertex_b_pair[1][0] >= vertex_a_pair[1][0] )
and ( vertex_a_pair[0][1] >= vertex_b_pair[1][1] >= vertex_a_pair[1][1] )) )\
or ( (( vertex_b_pair[0][0] <= vertex_a_pair[0][0] <= vertex_b_pair[1][0] )
and ( vertex_b_pair[0][1] <= vertex_a_pair[0][1] <= vertex_b_pair[1][1] ))
or (( vertex_b_pair[0][0] >= vertex_a_pair[0][0] >= vertex_b_pair[1][0] )
and ( vertex_b_pair[0][1] >= vertex_a_pair[0][1] >= vertex_b_pair[1][1] ))
or (( vertex_b_pair[0][0] <= vertex_a_pair[1][0] <= vertex_b_pair[1][0] )
and ( vertex_b_pair[0][1] <= vertex_a_pair[1][1] <= vertex_b_pair[1][1] ))
or (( vertex_b_pair[0][0] >= vertex_a_pair[1][0] >= vertex_b_pair[1][0] )
and ( vertex_b_pair[0][1] >= vertex_a_pair[1][1] >= vertex_b_pair[1][1] )) ):
print("line {0} intersects with line {1}".format(vertex_a_pair, vertex_b_pair))
if ( wire_a.get('group', None) != None ) and ( wire_b.get('group', None) == None ):
wire_b['group'] = wire_a['group']
elif (wire_a.get('group', None) == None) and (wire_b.get('group', None) != None):
wire_a['group'] = wire_b['group']
else:
wire_a['group'] = group_counter
wire_b['group'] = group_counter
group_counter += 1
return schematic
def main(args):