From 3c16630df46d2f15d36efe00b7387707064e2beb Mon Sep 17 00:00:00 2001 From: Aaron Goldstein Date: Thu, 21 May 2020 19:54:15 -0700 Subject: [PATCH] Store complete wire information within netlist object, Begin implementing a generic record search function --- parse.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/parse.py b/parse.py index 3797ce9..cff8870 100644 --- a/parse.py +++ b/parse.py @@ -76,6 +76,7 @@ def determine_parts_list(schematic): def determine_net_list(schematic): wires = [ record for record in schematic["records"] if record["RECORD"] == "27" ] + pins = [ record for record in schematic["records"] if record["RECORD"] == 2 ] p = re.compile('^(?PX)(?P\d+)$') for wire in wires: @@ -88,24 +89,50 @@ def determine_net_list(schematic): if wire["index"] not in [id for net in nets for id in net]: nets.append(find_connected_wires(wire, [], schematic)) + visited, found = find_record(schematic, key="RECORD", value="2") + schematic["nets"] = nets return schematic +def find_record(schematic, key, value, record=None, visited=None, found=None): + print("finding records where: {0} = {1}".format(key, value)) + + if visited == None: + visited = [] + if found == None: + found = [] + if record == None: + for record in schematic['records']: + visited, found = find_record(schematic, key, value, record=record, visited=visited, found=found) + else: + if record['index'] not in [r['index'] for r in visited]: + visited.append(record) + + if key in record.keys(): + if record[key] == value: + found.append(record) + + if "children" in record.keys(): + for child_record in record["children"]: + visited, found = find_record(schematic, key, value, record=child_record, visited=visited, found=found) + + return visited, found + def find_connected_wires(wire, visited, schematic): neighbors = find_neighbors(wire, schematic) print('entering: {0}'.format(wire['index'])) - if wire['index'] not in visited: - print('adding: {0} to {1}'.format(wire['index'], visited)) - visited.append(wire['index']) + if wire['index'] not in [w['index'] for w in visited]: + print('adding: {0} to {1}'.format(wire['index'], [w['index'] for w in visited])) + visited.append(wire) for neighbor in neighbors: print('trying: {0} of {1}'.format(neighbor['index'], [x['index'] for x in neighbors])) visited = find_connected_wires(neighbor, visited, schematic) - print('visited = {0}'.format(visited)) + print('visited = {0}'.format([w['index'] for w in visited])) else: - print('skipping: {0} already in list {1}'.format(wire['index'], visited)) + print('skipping: {0} already in list {1}'.format(wire['index'], [w['index'] for w in visited])) print('returning: {0}'.format(wire['index'])) return visited