diff --git a/.gitignore b/.gitignore index 454ad24..583c4a1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.pyc \.idea/ + +pcbdevice/resources/output/ +pcbdevice/tests/resources/output/ diff --git a/pcbdevice/gcode/GcodeBuilder.py b/pcbdevice/gcode/GcodeBuilder.py index 4042389..ce28059 100644 --- a/pcbdevice/gcode/GcodeBuilder.py +++ b/pcbdevice/gcode/GcodeBuilder.py @@ -14,7 +14,7 @@ def listToGCode(listIndex, pHeight, pWidth): gcodeCommand.append('G0 Z0') toolUp = True else: - gcodeCommand.append('G0 X' + str(coord.getX()*pWidth) + ' Y' + str(coord.getY()*pHeight)) + gcodeCommand.append('G0 X' + str(round(coord.getX()*pWidth, 2)) + ' Y' + str(round(coord.getY()*pHeight, 2))) if toolUp: gcodeCommand.append('G0 Z3') toolUp = False diff --git a/pcbdevice/main.py b/pcbdevice/main.py index 637ac52..637e385 100644 --- a/pcbdevice/main.py +++ b/pcbdevice/main.py @@ -1,13 +1,19 @@ -from pcbdevice.utils.path import path -from pcbdevice.utils.plotimg import plotPath +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() @@ -17,13 +23,9 @@ if __name__ == "__main__": pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi, unit = args.u) else: pxHeight, pxWidth = FileUtils.getPixelSize(height, width, args.he, args.wi) - - - resourcesRawPath = 'tests/resources/raw/' - resourcesFormattedPath = 'tests/resources/formatted/' - resourcesPathOutput = 'resources/pathoutput/' - resourcesExpectedPath = 'tests/resources/expected/' - - #FileUtils.saveMatrixToFile(FileUtils.pbmToMatrix(resourcesRawPath + 'test1ascii.pbm'), resourcesFormattedPath + 'test1.csv') - - #plotPath(path(FileUtils.pbmToMatrix(resourcesRawPath + 'test100x100.pbm'), 5)) \ No newline at end of file + + 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) \ No newline at end of file diff --git a/pcbdevice/tests/utils/test_fileUtils.py b/pcbdevice/tests/utils/test_fileUtils.py index f87f846..c3bc4f3 100644 --- a/pcbdevice/tests/utils/test_fileUtils.py +++ b/pcbdevice/tests/utils/test_fileUtils.py @@ -41,4 +41,5 @@ class TestFileUtils(TestCase): self.assertEqual((10, 10), FileUtils.getPixelSize(10, 10, 10, 10, unit = 'cm')) self.assertEqual((10, 10), FileUtils.getPixelSize(10, 10, 1, 1, unit = 'm')) self.assertEqual((25.4, 25.4), FileUtils.getPixelSize(10, 10, 10, 10, unit = 'in')) - self.assertEqual((1, 2), FileUtils.getPixelSize(10, 10, 10, 20)) \ No newline at end of file + self.assertEqual((1, 2), FileUtils.getPixelSize(10, 10, 10, 20)) + self.assertRaises(RuntimeError, lambda: FileUtils.getPixelSize(10, 10, 10, 10, 'ft')) \ No newline at end of file