Updated neoden formatting script

This commit is contained in:
andrewc
2023-04-06 14:37:47 +10:00
parent d3090843ca
commit a72975187e

View File

@@ -17,19 +17,26 @@ YY1_FEEDER_IND = YY1_COMP_HEADER.index("FeederNo") - YY1_EXTRA_IND
YY1_DEF_EXTRA = [0, 0, 50, 0.0, 0.0, 1, 0] YY1_DEF_EXTRA = [0, 0, 50, 0.0, 0.0, 1, 0]
KI_POS_SUFFIX = "-all-pos" KI_POS_SUFFIX = "_cpl"
pcb_dir = sys.argv[1]
pcb_file = glob("*.kicad_pcb") pcb_file = glob(pcb_dir + "/*.kicad_pcb")
board = LoadBoard(pcb_file[0]) board = LoadBoard(pcb_file[0])
sourceArea = findBoardBoundingBox(board) sourceArea = findBoardBoundingBox(board)
bottomOrig = [(a - b)/10**6 for a,b in zip(*[list(getOriginCoord(o, sourceArea)) for o in [Origin.BottomRight, Origin.BottomLeft]])] bottomOrig = [(a - b)/10**6 for a,b in zip(*[list(getOriginCoord(o, sourceArea)) for o in [Origin.BottomRight, Origin.BottomLeft]])]
print("bottom Orig: ", bottomOrig) print("bottom Orig: ", bottomOrig)
csv_files = glob("*.csv")
output_dir = deepcopy(pcb_dir)
csv_files = glob(output_dir + "/*.csv")
if len(csv_files) < 1:
output_dir = "Fabrication/" + output_dir
csv_files = glob(output_dir + "/*.csv")
input = next(filter(lambda f: KI_POS_SUFFIX in f, csv_files)) input = next(filter(lambda f: KI_POS_SUFFIX in f, csv_files))
output = input.split(KI_POS_SUFFIX)[0] + "-neo-pos.csv" output = output_dir + "/" + input.split("/")[-1].split(KI_POS_SUFFIX)[0] + "-neo-pos.csv"
try: try:
feed_opt = next(filter(lambda f: "feed" in f, csv_files)) feed_opt = next(filter(lambda f: "feed" in f, csv_files))
except: except:
@@ -71,7 +78,7 @@ for f in fids:
# Components # Components
comps = rows_in[1:] comps = rows_in[1:]
comp_feed = {} comp_feed = {}
feeder = 0 feeder = 1
# Load in optional file # Load in optional file
if feed_opt is not None: if feed_opt is not None:
# Read in feeder options for components # Read in feeder options for components
@@ -140,7 +147,7 @@ for tag, origin in origins.items():
# Format output # Format output
rows_out = [YY1_HEADER, YY1_SEP, YY1_PANEL, YY1_SEP] rows_out = [YY1_HEADER, YY1_SEP, YY1_PANEL, YY1_SEP]
# y is still same dir, but x gets flipped, so the x calc is opposite sign # y is still same dir, but x gets flipped, so the x calc is opposite sign
rows_out.append(["Fiducial","1-X", "{:.2f}".format(origin[0] - fid_pos[0]) ,"1-Y","{:.2f}".format(fid_pos[1] - origin[1]) ,"OverallOffsetX",0,"OverallOffsetY",0,]) rows_out.append(["Fiducial","1-X", "{:.2f}".format(abs(fid_pos[0] - origin[0])) ,"1-Y","{:.2f}".format(fid_pos[1] - origin[1]) ,"OverallOffsetX",0,"OverallOffsetY",0,])
rows_out.append(YY1_SEP) rows_out.append(YY1_SEP)
for _ in range(4): for _ in range(4):
rows_out.append(YY1_NOZZLE_DEF) rows_out.append(YY1_NOZZLE_DEF)
@@ -154,3 +161,5 @@ for tag, origin in origins.items():
quotechar='|', quoting=csv.QUOTE_MINIMAL) quotechar='|', quoting=csv.QUOTE_MINIMAL)
for row in rows_out: for row in rows_out:
spamwriter.writerow(row) spamwriter.writerow(row)