Add functions description
Add python documentation
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user