From 233a67edf137857bd1de40990a423438d1d2a1d2 Mon Sep 17 00:00:00 2001 From: Aaron Goldstein Date: Wed, 15 Apr 2020 22:05:09 -0700 Subject: [PATCH] Attempting to write a parsing algorithm that's simple and works --- parse.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/parse.py b/parse.py index 2d44875..d3c771b 100644 --- a/parse.py +++ b/parse.py @@ -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('^(?PX)(?P\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):