Skip to content

Commit

Permalink
Autopep8 format, author & version update
Browse files Browse the repository at this point in the history
Ran Autopep8 on all files in repo, they are otherwise untouched with one exception:
In the __init__ file, I had to manually rearrange the import statements to avoid triggering a circular import error.
This will be addressed in a future commit.

Updated authors in bl_info to: 'Vilem Novak & Contributors' - this can be changed as required
Updated version to: 1.0.5
  • Loading branch information
SpectralVectors authored Mar 21, 2024
1 parent 343d064 commit 9e9cd34
Show file tree
Hide file tree
Showing 67 changed files with 5,218 additions and 4,614 deletions.
43 changes: 23 additions & 20 deletions scripts/addons/cam/nc/anilam_crusader_m.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import nc
from . import iso


class Creator(iso.Creator):
def __init__(self):
iso.Creator.__init__(self)
Expand All @@ -16,10 +17,10 @@ def SPACE_STR(self): return(' ')
# This version of COMMENT removes comments from the resultant GCode
# Note: The Anilam hates comments when importing code.

def COMMENT(self,comment): return('')
def COMMENT(self, comment): return('')

def program_begin(self, id, comment):
self.write('%\n'); # Start of file token that Anilam Crusader M likes
self.write('%\n') # Start of file token that Anilam Crusader M likes
# No Comments for the Anilam crusaher M, please......
#self.write( ('(' + comment + ')' + '\n') )

Expand All @@ -28,41 +29,41 @@ def program_end(self):
self.write('%\n') # EOF signal for Anilam Crusader M

############################################################################
## Settings
# Settings

def imperial(self):
self.write( self.IMPERIAL() + '\n')
self.write(self.IMPERIAL() + '\n')
self.fmt.number_of_decimal_places = 4

def metric(self):
self.write( self.METRIC() + '\n' )
self.write(self.METRIC() + '\n')
self.fmt.number_of_decimal_places = 3

def absolute(self):
self.write( self.ABSOLUTE() + '\n')
self.write(self.ABSOLUTE() + '\n')

def incremental(self):
self.write( self.INCREMENTAL() + '\n' )
self.write(self.INCREMENTAL() + '\n')

def polar(self, on=True):
if (on) :
self.write(self.POLAR_ON() + '\n' )
else :
self.write(self.POLAR_OFF() + '\n' )
if (on):
self.write(self.POLAR_ON() + '\n')
else:
self.write(self.POLAR_OFF() + '\n')

def set_plane(self, plane):
if (plane == 0) :
if (plane == 0):
self.write('G17\n')
elif (plane == 1) :
elif (plane == 1):
self.write('G18\n')
elif (plane == 2) :
elif (plane == 2):
self.write('G19\n')

def comment(self, text):
pass
pass

############################################################################
## Tools
# Tools

def tool_change(self, id):
self.write(('T%i' % id) + '\n')
Expand All @@ -83,11 +84,13 @@ def tool_defn(self, id, name='', params=None):
# These are selected by values from 1 to 9 inclusive.
def workplane(self, id):
if ((id >= 1) and (id <= 6)):
self.write( (self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\n')
self.write((self.WORKPLANE() % (id + self.WORKPLANE_BASE())) + '\n')
if ((id >= 7) and (id <= 9)):
self.write( ((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\n')
self.write(((self.WORKPLANE() % (6 + self.WORKPLANE_BASE())) + ('.%i' % (id - 6))) + '\n')

def drill(self, x=None, y=None, dwell=None, depthparams=None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance=None):
self.write(
'(Canned drill cycle ops are not yet supported here on this Anilam Crusader M postprocessor)')

def drill(self, x=None, y=None, dwell=None, depthparams = None, retract_mode=None, spindle_mode=None, internal_coolant_on=None, rapid_to_clearance = None):
self.write('(Canned drill cycle ops are not yet supported here on this Anilam Crusader M postprocessor)')

nc.creator = Creator()
1 change: 1 addition & 0 deletions scripts/addons/cam/nc/anilam_crusader_m_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Override some iso parser methods to interpret arc centers as relative to origin, not relative to start of arc.


class Parser(iso.Parser):
def __init__(self, writer):
iso.Parser.__init__(self, writer)
Expand Down
36 changes: 23 additions & 13 deletions scripts/addons/cam/nc/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
units = 1.0

################################################################################


class Creator(recreator.Redirector):

def __init__(self, original):
Expand Down Expand Up @@ -44,32 +46,35 @@ def z2(self, z):
# use a line with no length
path.append(ocl.Line(ocl.Point(self.x, self.y, self.z), ocl.Point(self.x, self.y, self.z)))
self.setPdcfIfNotSet()
if (self.z>self.minz):
self.pdcf.setZ(self.z) # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
if (self.z > self.minz):
# Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
self.pdcf.setZ(self.z)
else:
self.pdcf.setZ(self.minz/units) # Else use minz
self.pdcf.setZ(self.minz/units) # Else use minz
self.pdcf.setPath(path)
self.pdcf.run()
plist = self.pdcf.getCLPoints()
p = plist[0]
return p.z + self.material_allowance/units

def cut_path(self):
if self.path == None: return
if self.path == None:
return
self.setPdcfIfNotSet()

if (self.z>self.minz):
self.pdcf.setZ(self.z) # Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
if (self.z > self.minz):
# Adjust Z if we have gotten a higher limit (Fix pocketing loosing steps when using attach?)
self.pdcf.setZ(self.z)
else:
self.pdcf.setZ(self.minz/units) # Else use minz
self.pdcf.setZ(self.minz/units) # Else use minz

# get the points on the surface
self.pdcf.setPath(self.path)

self.pdcf.run()
plist = self.pdcf.getCLPoints()

#refine the points
# refine the points
f = ocl.LineCLFilter()
f.setTolerance(0.005)
for p in plist:
Expand All @@ -85,7 +90,7 @@ def cut_path(self):

self.path = ocl.Path()

def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None ):
def rapid(self, x=None, y=None, z=None, a=None, b=None, c=None):
if z != None:
if z < self.z:
return
Expand All @@ -102,24 +107,28 @@ def feed(self, x=None, y=None, z=None, a=None, b=None, c=None):
return

# add a line to the path
if self.path == None: self.path = ocl.Path()
if self.path == None:
self.path = ocl.Path()
self.path.append(ocl.Line(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z)))

def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw = True):
def arc(self, x=None, y=None, z=None, i=None, j=None, k=None, r=None, ccw=True):
px = self.x
py = self.y
pz = self.z
recreator.Redirector.arc(self, x, y, z, i, j, k, r, ccw)

# add an arc to the path
if self.path == None: self.path = ocl.Path()
self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point(self.x, self.y, self.z), ocl.Point(i, j, pz), ccw))
if self.path == None:
self.path = ocl.Path()
self.path.append(ocl.Arc(ocl.Point(px, py, pz), ocl.Point(
self.x, self.y, self.z), ocl.Point(i, j, pz), ccw))

def set_ocl_cutter(self, cutter):
self.cutter = cutter

################################################################################


def attach_begin():
global attached
if attached == True:
Expand All @@ -130,6 +139,7 @@ def attach_begin():
nc.creator.pdcf = None
nc.creator.path = None


def attach_end():
global attached
nc.creator.cut_path()
Expand Down
95 changes: 55 additions & 40 deletions scripts/addons/cam/nc/cad_iso_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import sys

################################################################################
class Parser(nc.Parser):


class Parser(nc.Parser):

def __init__(self, writer):
nc.Parser.__init__(self, writer)

self.pattern_main = re.compile('([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)')
self.pattern_main = re.compile(
'([(!;].*|\s+|[a-zA-Z0-9_:](?:[+-])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)|\#\d+\=(?:[+-])?\d*(?:\.\d*)?)')

#if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point
# followed by a possible deimcal, or a letter followed by # with a decimal . deimcal
# if ( or ! or ; at least one space or a letter followed by some character or not followed by a +/- followed by decimal, with a possible decimal point
# followed by a possible deimcal, or a letter followed by # with a decimal . deimcal
# add your character here > [(!;] for comments char
# then look for the 'comment' function towards the end of the file and add another elif

Expand Down Expand Up @@ -81,7 +82,7 @@ def ParseWord(self, word):
self.path_col = "feed"
self.col = "feed"
elif (word == 'G82' or word == 'g82'):
self.drill = True;
self.drill = True
self.no_move = True
self.path_col = "feed"
self.col = "feed"
Expand All @@ -94,7 +95,8 @@ def ParseWord(self, word):
self.absolute()
elif (word == 'G91' or word == 'g91'):
self.incremental()
elif (word[0] == 'G') : col = "prep"
elif (word[0] == 'G'):
col = "prep"
elif (word[0] == 'I' or word[0] == 'i'):
self.col = "axis"
self.i = eval(word[1:])
Expand All @@ -107,19 +109,22 @@ def ParseWord(self, word):
self.col = "axis"
self.k = eval(word[1:])
self.move = True
elif (word[0] == 'M') : self.col = "misc"
elif (word[0] == 'N') : self.col = "blocknum"
elif (word[0] == 'O') : self.col = "program"
elif (word[0] == 'M'):
self.col = "misc"
elif (word[0] == 'N'):
self.col = "blocknum"
elif (word[0] == 'O'):
self.col = "program"
elif (word[0] == 'P' or word[0] == 'p'):
if (self.no_move != True):
self.col = "axis"
self.p = eval(word[1:])
self.move = True
if (self.no_move != True):
self.col = "axis"
self.p = eval(word[1:])
self.move = True
elif (word[0] == 'Q' or word[0] == 'q'):
if (self.no_move != True):
self.col = "axis"
self.q = eval(word[1:])
self.move = True
if (self.no_move != True):
self.col = "axis"
self.q = eval(word[1:])
self.move = True
elif (word[0] == 'R' or word[0] == 'r'):
self.col = "axis"
self.r = eval(word[1:])
Expand All @@ -128,9 +133,9 @@ def ParseWord(self, word):
self.col = "axis"
self.s = eval(word[1:])
self.move = True
elif (word[0] == 'T') :
elif (word[0] == 'T'):
self.col = "tool"
self.set_tool( eval(word[1:]) )
self.set_tool(eval(word[1:]))
elif (word[0] == 'X' or word[0] == 'x'):
self.col = "axis"
self.x = eval(word[1:])
Expand All @@ -143,21 +148,27 @@ def ParseWord(self, word):
self.col = "axis"
self.z = eval(word[1:])
self.move = True
elif (word[0] == '(') : (self.col, self.cdata) = ("comment", True)
elif (word[0] == '!') : (self.col, self.cdata) = ("comment", True)
elif (word[0] == ';') : (self.col, self.cdata) = ("comment", True)
elif (word[0] == '#') : self.col = "variable"
elif (word[0] == ':') : self.col = "blocknum"
elif (ord(word[0]) <= 32) : self.cdata = True
elif (word[0] == '('):
(self.col, self.cdata) = ("comment", True)
elif (word[0] == '!'):
(self.col, self.cdata) = ("comment", True)
elif (word[0] == ';'):
(self.col, self.cdata) = ("comment", True)
elif (word[0] == '#'):
self.col = "variable"
elif (word[0] == ':'):
self.col = "blocknum"
elif (ord(word[0]) <= 32):
self.cdata = True

def Parse(self, name, oname=None):
self.files_open(name,oname)
self.files_open(name, oname)

#self.begin_ncblock()
#self.begin_path(None)
#self.add_line(z=500)
#self.end_path()
#self.end_ncblock()
# self.begin_ncblock()
# self.begin_path(None)
# self.add_line(z=500)
# self.end_path()
# self.end_ncblock()

self.path_col = None
self.f = None
Expand All @@ -179,7 +190,7 @@ def Parse(self, name, oname=None):
self.y = None
self.z = None

#self.begin_ncblock()
# self.begin_ncblock()

self.move = False
self.drill = False
Expand Down Expand Up @@ -207,12 +218,15 @@ def Parse(self, name, oname=None):
else:
if (self.move and not self.no_move):
self.begin_path(self.path_col)
if (self.arc==-1):
self.add_arc(self.x, self.y, self.z, self.i, self.j, self.k, self.r, self.arc)
elif (self.arc==1):
#self.add_arc(x, y, z, i, j, k, -r, arc) #if you want to use arcs with R values uncomment the first part of this line and comment the next one
self.add_arc(self.x, self.y, self.z, self.i, self.j, self.k, self.r, self.arc)
else : self.add_line(self.x, self.y, self.z, self.a, self.b, self.c)
if (self.arc == -1):
self.add_arc(self.x, self.y, self.z, self.i,
self.j, self.k, self.r, self.arc)
elif (self.arc == 1):
# self.add_arc(x, y, z, i, j, k, -r, arc) #if you want to use arcs with R values uncomment the first part of this line and comment the next one
self.add_arc(self.x, self.y, self.z, self.i,
self.j, self.k, self.r, self.arc)
else:
self.add_line(self.x, self.y, self.z, self.a, self.b, self.c)
self.end_path()

self.end_ncblock()
Expand All @@ -221,9 +235,10 @@ def Parse(self, name, oname=None):

################################################################################


if __name__ == '__main__':
parser = ParserIso()
if len(sys.argv)>2:
parser.Parse(sys.argv[1],sys.argv[2])
if len(sys.argv) > 2:
parser.Parse(sys.argv[1], sys.argv[2])
else:
parser.Parse(sys.argv[1])
Loading

0 comments on commit 9e9cd34

Please sign in to comment.