Merged master into consolidate
This commit is contained in:
commit
5bd10f7489
134
FlatCAMApp.py
134
FlatCAMApp.py
|
@ -644,6 +644,15 @@ class App(QtCore.QObject):
|
|||
else:
|
||||
self.defaults['stats'][resource] = 1
|
||||
|
||||
def raiseTclError(self, text):
|
||||
"""
|
||||
this method pass exception from python into TCL as error, so we get stacktrace and reason
|
||||
:param text: text of error
|
||||
:return: raise exception
|
||||
"""
|
||||
self.tcl.eval('return -code error "%s"' % text)
|
||||
raise Exception(text)
|
||||
|
||||
def exec_command(self, text):
|
||||
"""
|
||||
Handles input from the shell. See FlatCAMApp.setup_shell for shell commands.
|
||||
|
@ -659,7 +668,11 @@ class App(QtCore.QObject):
|
|||
result = self.tcl.eval(str(text))
|
||||
self.shell.append_output(result + '\n')
|
||||
except Tkinter.TclError, e:
|
||||
self.shell.append_error('ERROR: ' + str(e) + '\n')
|
||||
#this will display more precise answer if something in TCL shell fail
|
||||
result = self.tcl.eval("set errorInfo")
|
||||
self.log.error("Exec command Exception: %s" % (result + '\n'))
|
||||
self.shell.append_error('ERROR: ' + result + '\n')
|
||||
#show error in console and just return
|
||||
return
|
||||
|
||||
"""
|
||||
|
@ -2137,7 +2150,7 @@ class App(QtCore.QObject):
|
|||
|
||||
def geocutout(name, *args):
|
||||
"""
|
||||
subtract gaps from geometry, this will not create new object
|
||||
Subtract gaps from geometry, this will not create new object
|
||||
|
||||
:param name:
|
||||
:param args:
|
||||
|
@ -2148,7 +2161,7 @@ class App(QtCore.QObject):
|
|||
'gapsize': float,
|
||||
'gaps': str}
|
||||
|
||||
#way gaps wil be rendered:
|
||||
# How gaps wil be rendered:
|
||||
# lr - left + right
|
||||
# tb - top + bottom
|
||||
# 4 - left + right +top + bottom
|
||||
|
@ -2166,24 +2179,53 @@ class App(QtCore.QObject):
|
|||
except:
|
||||
return "Could not retrieve object: %s" % name
|
||||
|
||||
|
||||
#get min and max data for each object as we just cut rectangles across X or Y
|
||||
# Get min and max data for each object as we just cut rectangles across X or Y
|
||||
xmin, ymin, xmax, ymax = obj.bounds()
|
||||
px = 0.5 * (xmin + xmax)
|
||||
py = 0.5 * (ymin + ymax)
|
||||
lenghtx = (xmax - xmin)
|
||||
lenghty = (ymax - ymin)
|
||||
gapsize = kwa['gapsize']+kwa['dia']/2
|
||||
gapsize = kwa['gapsize'] + kwa['dia'] / 2
|
||||
|
||||
if kwa['gaps'] == '8' or kwa['gaps']=='2lr':
|
||||
subtract_rectangle(name,xmin-gapsize,py-gapsize+lenghty/4,xmax+gapsize,py+gapsize+lenghty/4)
|
||||
subtract_rectangle(name,xmin-gapsize,py-gapsize-lenghty/4,xmax+gapsize,py+gapsize-lenghty/4)
|
||||
|
||||
subtract_rectangle(name,
|
||||
xmin - gapsize,
|
||||
py - gapsize + lenghty / 4,
|
||||
xmax + gapsize,
|
||||
py + gapsize + lenghty / 4)
|
||||
subtract_rectangle(name,
|
||||
xmin-gapsize,
|
||||
py - gapsize - lenghty / 4,
|
||||
xmax + gapsize,
|
||||
py + gapsize - lenghty / 4)
|
||||
|
||||
if kwa['gaps'] == '8' or kwa['gaps']=='2tb':
|
||||
subtract_rectangle(name,px-gapsize+lenghtx/4,ymin-gapsize,px+gapsize+lenghtx/4,ymax+gapsize)
|
||||
subtract_rectangle(name,px-gapsize-lenghtx/4,ymin-gapsize,px+gapsize-lenghtx/4,ymax+gapsize)
|
||||
subtract_rectangle(name,
|
||||
px - gapsize + lenghtx / 4,
|
||||
ymin-gapsize,
|
||||
px + gapsize + lenghtx / 4,
|
||||
ymax + gapsize)
|
||||
subtract_rectangle(name,
|
||||
px - gapsize - lenghtx / 4,
|
||||
ymin - gapsize,
|
||||
px + gapsize - lenghtx / 4,
|
||||
ymax + gapsize)
|
||||
|
||||
if kwa['gaps'] == '4' or kwa['gaps']=='lr':
|
||||
subtract_rectangle(name,xmin-gapsize,py-gapsize,xmax+gapsize,py+gapsize)
|
||||
subtract_rectangle(name,
|
||||
xmin - gapsize,
|
||||
py - gapsize,
|
||||
xmax + gapsize,
|
||||
py + gapsize)
|
||||
|
||||
if kwa['gaps'] == '4' or kwa['gaps']=='tb':
|
||||
subtract_rectangle(name,px-gapsize,ymin-gapsize,px+gapsize,ymax+gapsize)
|
||||
subtract_rectangle(name,
|
||||
px - gapsize,
|
||||
ymin - gapsize,
|
||||
px + gapsize,
|
||||
ymax + gapsize)
|
||||
|
||||
return 'Ok'
|
||||
|
||||
def mirror(name, *args):
|
||||
|
@ -2209,14 +2251,12 @@ class App(QtCore.QObject):
|
|||
if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMExcellon):
|
||||
return "ERROR: Only Gerber and Excellon objects can be mirrored."
|
||||
|
||||
|
||||
# Axis
|
||||
try:
|
||||
axis = kwa['axis'].upper()
|
||||
except KeyError:
|
||||
return "ERROR: Specify -axis X or -axis Y"
|
||||
|
||||
|
||||
# Box
|
||||
if 'box' in kwa:
|
||||
try:
|
||||
|
@ -2289,20 +2329,23 @@ class App(QtCore.QObject):
|
|||
else:
|
||||
gridoffsety=kwa['gridoffsety']
|
||||
|
||||
|
||||
# Tools
|
||||
tools = {"1": {"C": kwa['dia']}}
|
||||
|
||||
def aligndrillgrid_init_me(init_obj, app_obj):
|
||||
drills = []
|
||||
currenty=0
|
||||
|
||||
for row in range(kwa['rows']):
|
||||
currentx=0
|
||||
|
||||
for col in range(kwa['columns']):
|
||||
point = Point(currentx+gridoffsetx,currenty+gridoffsety)
|
||||
point = Point(currentx + gridoffsetx, currenty + gridoffsety)
|
||||
drills.append({"point": point, "tool": "1"})
|
||||
currentx=currentx+kwa['gridx']
|
||||
currenty=currenty+kwa['gridy']
|
||||
currentx = currentx + kwa['gridx']
|
||||
|
||||
currenty = currenty + kwa['gridy']
|
||||
|
||||
init_obj.tools = tools
|
||||
init_obj.drills = drills
|
||||
init_obj.create_geometry()
|
||||
|
@ -2376,23 +2419,32 @@ class App(QtCore.QObject):
|
|||
else:
|
||||
axisoffset=0
|
||||
|
||||
#this will align hole to given aligngridoffset and minimal offset from pcb, based on selected axis
|
||||
# This will align hole to given aligngridoffset and minimal offset from pcb, based on selected axis
|
||||
if axis == "X":
|
||||
firstpoint=kwa['gridoffset']
|
||||
while (xmin-kwa['minoffset'])<firstpoint:
|
||||
firstpoint=firstpoint-kwa['grid']
|
||||
lastpoint=kwa['gridoffset']
|
||||
while (xmax+kwa['minoffset'])>lastpoint:
|
||||
lastpoint=lastpoint+kwa['grid']
|
||||
localHoles=(firstpoint,axisoffset),(lastpoint,axisoffset)
|
||||
firstpoint = kwa['gridoffset']
|
||||
|
||||
while (xmin - kwa['minoffset']) < firstpoint:
|
||||
firstpoint = firstpoint - kwa['grid']
|
||||
|
||||
lastpoint = kwa['gridoffset']
|
||||
|
||||
while (xmax + kwa['minoffset']) > lastpoint:
|
||||
lastpoint = lastpoint + kwa['grid']
|
||||
|
||||
localHoles = (firstpoint, axisoffset), (lastpoint, axisoffset)
|
||||
|
||||
else:
|
||||
firstpoint=kwa['gridoffset']
|
||||
while (ymin-kwa['minoffset'])<firstpoint:
|
||||
firstpoint=firstpoint-kwa['grid']
|
||||
lastpoint=kwa['gridoffset']
|
||||
while (ymax+kwa['minoffset'])>lastpoint:
|
||||
firstpoint = kwa['gridoffset']
|
||||
|
||||
while (ymin - kwa['minoffset']) < firstpoint:
|
||||
firstpoint = firstpoint - kwa['grid']
|
||||
|
||||
lastpoint = kwa['gridoffset']
|
||||
|
||||
while (ymax + kwa['minoffset']) > lastpoint:
|
||||
lastpoint=lastpoint+kwa['grid']
|
||||
localHoles=(axisoffset,firstpoint),(axisoffset,lastpoint)
|
||||
|
||||
localHoles = (axisoffset, firstpoint), (axisoffset, lastpoint)
|
||||
|
||||
for hole in localHoles:
|
||||
point = Point(hole)
|
||||
|
@ -2441,8 +2493,9 @@ class App(QtCore.QObject):
|
|||
|
||||
return 'Ok'
|
||||
|
||||
|
||||
def drillcncjob(name, *args):
|
||||
def drillcncjob(name=None, *args):
|
||||
# name should not be none, but we set it to default, because TCL return error without reason if argument is missing
|
||||
# we should check it inside shell commamnd instead
|
||||
a, kwa = h(*args)
|
||||
types = {'tools': str,
|
||||
'outname': str,
|
||||
|
@ -2453,21 +2506,24 @@ class App(QtCore.QObject):
|
|||
'toolchange': int
|
||||
}
|
||||
|
||||
if name is None:
|
||||
self.raiseTclError('Argument name is missing.')
|
||||
|
||||
for key in kwa:
|
||||
if key not in types:
|
||||
return 'Unknown parameter: %s' % key
|
||||
self.raiseTclError('Unknown parameter: %s' % key)
|
||||
kwa[key] = types[key](kwa[key])
|
||||
|
||||
try:
|
||||
obj = self.collection.get_by_name(str(name))
|
||||
except:
|
||||
return "Could not retrieve object: %s" % name
|
||||
self.raiseTclError("Could not retrieve object: %s" % name)
|
||||
|
||||
if obj is None:
|
||||
return "Object not found: %s" % name
|
||||
self.raiseTclError('Object not found: %s' % name)
|
||||
|
||||
if not isinstance(obj, FlatCAMExcellon):
|
||||
return "ERROR: Only Excellon objects can be drilled."
|
||||
self.raiseTclError('Only Excellon objects can be drilled: %s' % name)
|
||||
|
||||
try:
|
||||
|
||||
|
@ -2493,7 +2549,7 @@ class App(QtCore.QObject):
|
|||
obj.app.new_object("cncjob", job_name, job_init)
|
||||
|
||||
except Exception, e:
|
||||
return "Operation failed: %s" % str(e)
|
||||
self.raiseTclError("Operation failed: %s" % str(e))
|
||||
|
||||
return 'Ok'
|
||||
|
||||
|
|
Loading…
Reference in New Issue