diff --git a/pcbdevice/gcode/GcodeBuilder.py b/pcbdevice/gcode/GcodeBuilder.py index ce28059..603bc16 100644 --- a/pcbdevice/gcode/GcodeBuilder.py +++ b/pcbdevice/gcode/GcodeBuilder.py @@ -1,4 +1,12 @@ def listToGCode(listIndex, pHeight, pWidth): + """ + Convert a list of matrix coordinate in a list of GCode commands + + :param listIndex: List of coordinate + :param pHeight: Pixel height in mm + :param pWidth: Pixel width in mm + :return: List of all the GCode commands + """ gcodeCommand = [] toolUp = True diff --git a/pcbdevice/utils/FileUtils.py b/pcbdevice/utils/FileUtils.py index 3014aa9..80648fb 100644 --- a/pcbdevice/utils/FileUtils.py +++ b/pcbdevice/utils/FileUtils.py @@ -3,6 +3,16 @@ import math class FileUtils: @staticmethod def pbmToMatrix(pbmFilePath, dimensionLineIndex = 2): + """ + Read a pbm file and convert in an int matrix + + :param str pbmFilePath: Path of the ascii pbm file to convert in a matrix + :param int dimensionLineIndex: Line index containing the dimension of the image + :return matrix: Matrix with image value + :return height: Height of the matrix + :return width: Width of the matrix + """ + completeFile = [] file = open(pbmFilePath, 'r') @@ -22,6 +32,13 @@ class FileUtils: @staticmethod def saveMatrixToFile(matrix, filePath): + """ + Save a matrix in a plain text file + + :param matrix: Matrix to save + :param filePath: Path of the output file + :return: None + """ with open(filePath, 'w') as f: for x in matrix: for y in x: @@ -31,6 +48,13 @@ class FileUtils: @staticmethod def saveStringListToFile(stringList, filePath): + """ + Save a string list into a plain text file with a carriage return after each entry + + :param stringList: List of string to write + :param filePath: File path to write the text + :return: None + """ with open(filePath, 'w') as f: for line in stringList: f.write('%s\n' % line) @@ -38,6 +62,18 @@ class FileUtils: @staticmethod def getPixelSize(matHeight, matWidth, pcbHeight, pcbWidth, unit = 'mm'): + """ + Get pixel width and height with the real image size + + :param matHeight: Height of the image matrix (Nb pixels) + :param matWidth: Width of the image matrix (Nb pixels) + :param pcbHeight: True height of the image (PCB) + :param pcbWidth: True width of the image (PCB) + :param unit: Unit of the size of the image, default in mm + :return pixelHeight: Pixel height in mm + :return pixelWidth: Pixel width in mm + + """ if unit == 'mm': return pcbHeight / matHeight, pcbWidth / matWidth elif unit == 'cm': diff --git a/pcbdevice/utils/TestUtils.py b/pcbdevice/utils/TestUtils.py index 384e50d..a8f1dce 100644 --- a/pcbdevice/utils/TestUtils.py +++ b/pcbdevice/utils/TestUtils.py @@ -1,4 +1,10 @@ def readIntFile(filePath): + """ + Read a matrix file + + :param filePath: File path to read from + :return: The matrix in int + """ completeFile = [] file = open(filePath, 'r') lines = file.readlines() @@ -14,6 +20,12 @@ def readIntFile(filePath): return completeFile def readStringFile(filePath): + """ + Read all lines of a file + + :param filePath: File path to read from + :return: Array of all lines in the file + """ file = open(filePath, 'r') lines = file.readlines() file.close()