Files
S4-P3-Projet/pcbdevice/main.py
Marc-Antoine Lafreniere f5599ce4b7 Create gcode file from image with arguments
#38-Create GCode from image
closes #38
2019-02-21 13:41:48 -05:00

31 lines
1.3 KiB
Python

import math
from pcbdevice.gcode.GcodeBuilder import listToGCode
from pcbdevice.gcode.GcodeCreator import createSequence
from pcbdevice.gcode.path import path
from pcbdevice.utils.FileUtils import FileUtils
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog = 'main.py')
parser.add_argument('-i', required = True, help = 'PCB image path')
parser.add_argument('-o', required = True, help = 'Gcode output path')
parser.add_argument('-wi', required = True, type = int, help = 'Width of the PCB')
parser.add_argument('-he', required = True, type = int, help = 'Height of the PCB')
parser.add_argument('-t', required = True, type = int, help = 'Tool\'s radius in mm')
parser.add_argument('-u', required = False, help = 'PCB dimension unit')
args = parser.parse_args()
matrix, height, width = FileUtils.pbmToMatrix(args.i)
if args.u:
pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi, unit = args.u)
else:
pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi)
rTool = int(math.ceil(args.t * pxHeight if pxHeight > pxWidth else pxWidth))
matrixUpdated = path(matrix, rTool)
listIndexes = createSequence(matrixUpdated)
gcode = listToGCode(listIndexes, pxHeight, pxWidth)
FileUtils.saveStringListToFile(gcode, args.o)