From 7f85e028935c38f98a9a9d117100ac54cea55c5d Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lafreniere Date: Wed, 20 Mar 2019 13:48:58 -0400 Subject: [PATCH] #55-UI frame Refactor main the ease usage in the UI --- pcbdevice/main.py | 51 ++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/pcbdevice/main.py b/pcbdevice/main.py index 38eaa16..608ec35 100644 --- a/pcbdevice/main.py +++ b/pcbdevice/main.py @@ -8,6 +8,33 @@ from pcbdevice.utils.FileUtils import FileUtils import argparse import subprocess +def main(inputPath, outputPath, isAscii, heightReal, widthReal, tool, unit): + converterPath = '.\\pcbdevice\\utils\\convertiseur.exe' + + if outputPath.rfind('\\') != -1: + asciiPbmPath = outputPath[0:outputPath.rfind('\\')] + '\\pcbImageAscii.pbm' + elif outputPath.rfind('/') != -1: + asciiPbmPath = outputPath[0:outputPath.rfind('/')] + '/pcbImageAscii.pbm' + else: + asciiPbmPath = '.\\pcbdevice\\resources\\output\\pcbImageAscii.pbm' + + if not isAscii: + subprocess.check_call([converterPath, inputPath, asciiPbmPath]) + + matrix, height, width = FileUtils.pbmToMatrix(asciiPbmPath) + + pxHeight, pxWidth = FileUtils.getPixelSize(height, width, heightReal, widthReal, unit = unit) + + if pxHeight > pxWidth: + rTool = int(math.ceil(tool * pxHeight)) + else: + rTool = int(math.ceil(tool * pxWidth)) + + matrixUpdated = path(matrix, rTool) + listIndexes = createSequence(matrixUpdated) + gcode = listToGCode(listIndexes, pxHeight, pxWidth) + FileUtils.saveStringListToFile(gcode, outputPath) + if __name__ == "__main__": parser = argparse.ArgumentParser(prog = 'main.py') parser.add_argument('-i', required = True, help = 'PCB image path') @@ -19,31 +46,13 @@ if __name__ == "__main__": parser.add_argument('-u', required = False, help = 'PCB dimension unit') args = parser.parse_args() - converterPath = '.\\pcbdevice\\utils\\convertiseur.exe' - asciiPbmPath = '.\\pcbdevice\\resources\\output\\pcbImageAscii.pbm' - unitValue = 'mm' isAscii = args.imgTypeisAscii - if isAscii: - asciiPbmPath = args.i - - if not isAscii: - subprocess.check_call([converterPath, args.i, asciiPbmPath]) - - matrix, height, width = FileUtils.pbmToMatrix(asciiPbmPath) - if args.u: unitValue = args.u - pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi, unit = unitValue) + if isAscii: + asciiPbmPath = args.i - if pxHeight > pxWidth: - rTool = int(math.ceil(args.t * pxHeight)) - else: - rTool = int(math.ceil(args.t * pxWidth)) - - matrixUpdated = path(matrix, rTool) - listIndexes = createSequence(matrixUpdated) - gcode = listToGCode(listIndexes, pxHeight, pxWidth) - FileUtils.saveStringListToFile(gcode, args.o) \ No newline at end of file + main(args.i, args.o, isAscii, args.wi, args.he, args.t, unitValue) \ No newline at end of file