|
@@ -644,6 +644,15 @@ class App(QtCore.QObject):
|
|
|
else:
|
|
else:
|
|
|
self.defaults['stats'][resource] = 1
|
|
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):
|
|
def exec_command(self, text):
|
|
|
"""
|
|
"""
|
|
|
Handles input from the shell. See FlatCAMApp.setup_shell for shell commands.
|
|
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))
|
|
result = self.tcl.eval(str(text))
|
|
|
self.shell.append_output(result + '\n')
|
|
self.shell.append_output(result + '\n')
|
|
|
except Tkinter.TclError, e:
|
|
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
|
|
return
|
|
|
|
|
|
|
|
"""
|
|
"""
|
|
@@ -2137,7 +2150,7 @@ class App(QtCore.QObject):
|
|
|
|
|
|
|
|
def geocutout(name, *args):
|
|
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 name:
|
|
|
:param args:
|
|
:param args:
|
|
@@ -2148,7 +2161,7 @@ class App(QtCore.QObject):
|
|
|
'gapsize': float,
|
|
'gapsize': float,
|
|
|
'gaps': str}
|
|
'gaps': str}
|
|
|
|
|
|
|
|
- #way gaps wil be rendered:
|
|
|
|
|
|
|
+ # How gaps wil be rendered:
|
|
|
# lr - left + right
|
|
# lr - left + right
|
|
|
# tb - top + bottom
|
|
# tb - top + bottom
|
|
|
# 4 - left + right +top + bottom
|
|
# 4 - left + right +top + bottom
|
|
@@ -2166,24 +2179,53 @@ class App(QtCore.QObject):
|
|
|
except:
|
|
except:
|
|
|
return "Could not retrieve object: %s" % name
|
|
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()
|
|
xmin, ymin, xmax, ymax = obj.bounds()
|
|
|
px = 0.5 * (xmin + xmax)
|
|
px = 0.5 * (xmin + xmax)
|
|
|
py = 0.5 * (ymin + ymax)
|
|
py = 0.5 * (ymin + ymax)
|
|
|
lenghtx = (xmax - xmin)
|
|
lenghtx = (xmax - xmin)
|
|
|
lenghty = (ymax - ymin)
|
|
lenghty = (ymax - ymin)
|
|
|
- gapsize = kwa['gapsize']+kwa['dia']/2
|
|
|
|
|
|
|
+ gapsize = kwa['gapsize'] + kwa['dia'] / 2
|
|
|
|
|
+
|
|
|
if kwa['gaps'] == '8' or kwa['gaps']=='2lr':
|
|
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':
|
|
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':
|
|
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':
|
|
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'
|
|
return 'Ok'
|
|
|
|
|
|
|
|
def mirror(name, *args):
|
|
def mirror(name, *args):
|
|
@@ -2209,14 +2251,12 @@ class App(QtCore.QObject):
|
|
|
if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMExcellon):
|
|
if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMExcellon):
|
|
|
return "ERROR: Only Gerber and Excellon objects can be mirrored."
|
|
return "ERROR: Only Gerber and Excellon objects can be mirrored."
|
|
|
|
|
|
|
|
-
|
|
|
|
|
# Axis
|
|
# Axis
|
|
|
try:
|
|
try:
|
|
|
axis = kwa['axis'].upper()
|
|
axis = kwa['axis'].upper()
|
|
|
except KeyError:
|
|
except KeyError:
|
|
|
return "ERROR: Specify -axis X or -axis Y"
|
|
return "ERROR: Specify -axis X or -axis Y"
|
|
|
|
|
|
|
|
-
|
|
|
|
|
# Box
|
|
# Box
|
|
|
if 'box' in kwa:
|
|
if 'box' in kwa:
|
|
|
try:
|
|
try:
|
|
@@ -2289,20 +2329,23 @@ class App(QtCore.QObject):
|
|
|
else:
|
|
else:
|
|
|
gridoffsety=kwa['gridoffsety']
|
|
gridoffsety=kwa['gridoffsety']
|
|
|
|
|
|
|
|
-
|
|
|
|
|
# Tools
|
|
# Tools
|
|
|
tools = {"1": {"C": kwa['dia']}}
|
|
tools = {"1": {"C": kwa['dia']}}
|
|
|
|
|
|
|
|
def aligndrillgrid_init_me(init_obj, app_obj):
|
|
def aligndrillgrid_init_me(init_obj, app_obj):
|
|
|
drills = []
|
|
drills = []
|
|
|
currenty=0
|
|
currenty=0
|
|
|
|
|
+
|
|
|
for row in range(kwa['rows']):
|
|
for row in range(kwa['rows']):
|
|
|
currentx=0
|
|
currentx=0
|
|
|
|
|
+
|
|
|
for col in range(kwa['columns']):
|
|
for col in range(kwa['columns']):
|
|
|
- point = Point(currentx+gridoffsetx,currenty+gridoffsety)
|
|
|
|
|
|
|
+ point = Point(currentx + gridoffsetx, currenty + gridoffsety)
|
|
|
drills.append({"point": point, "tool": "1"})
|
|
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.tools = tools
|
|
|
init_obj.drills = drills
|
|
init_obj.drills = drills
|
|
|
init_obj.create_geometry()
|
|
init_obj.create_geometry()
|
|
@@ -2376,23 +2419,32 @@ class App(QtCore.QObject):
|
|
|
else:
|
|
else:
|
|
|
axisoffset=0
|
|
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":
|
|
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:
|
|
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']
|
|
lastpoint=lastpoint+kwa['grid']
|
|
|
- localHoles=(axisoffset,firstpoint),(axisoffset,lastpoint)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ localHoles = (axisoffset, firstpoint), (axisoffset, lastpoint)
|
|
|
|
|
|
|
|
for hole in localHoles:
|
|
for hole in localHoles:
|
|
|
point = Point(hole)
|
|
point = Point(hole)
|
|
@@ -2441,8 +2493,9 @@ class App(QtCore.QObject):
|
|
|
|
|
|
|
|
return 'Ok'
|
|
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)
|
|
a, kwa = h(*args)
|
|
|
types = {'tools': str,
|
|
types = {'tools': str,
|
|
|
'outname': str,
|
|
'outname': str,
|
|
@@ -2453,21 +2506,24 @@ class App(QtCore.QObject):
|
|
|
'toolchange': int
|
|
'toolchange': int
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if name is None:
|
|
|
|
|
+ self.raiseTclError('Argument name is missing.')
|
|
|
|
|
+
|
|
|
for key in kwa:
|
|
for key in kwa:
|
|
|
if key not in types:
|
|
if key not in types:
|
|
|
- return 'Unknown parameter: %s' % key
|
|
|
|
|
|
|
+ self.raiseTclError('Unknown parameter: %s' % key)
|
|
|
kwa[key] = types[key](kwa[key])
|
|
kwa[key] = types[key](kwa[key])
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
obj = self.collection.get_by_name(str(name))
|
|
obj = self.collection.get_by_name(str(name))
|
|
|
except:
|
|
except:
|
|
|
- return "Could not retrieve object: %s" % name
|
|
|
|
|
|
|
+ self.raiseTclError("Could not retrieve object: %s" % name)
|
|
|
|
|
|
|
|
if obj is None:
|
|
if obj is None:
|
|
|
- return "Object not found: %s" % name
|
|
|
|
|
|
|
+ self.raiseTclError('Object not found: %s' % name)
|
|
|
|
|
|
|
|
if not isinstance(obj, FlatCAMExcellon):
|
|
if not isinstance(obj, FlatCAMExcellon):
|
|
|
- return "ERROR: Only Excellon objects can be drilled."
|
|
|
|
|
|
|
+ self.raiseTclError('Only Excellon objects can be drilled: %s' % name)
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
|
|
|
|
@@ -2493,7 +2549,7 @@ class App(QtCore.QObject):
|
|
|
obj.app.new_object("cncjob", job_name, job_init)
|
|
obj.app.new_object("cncjob", job_name, job_init)
|
|
|
|
|
|
|
|
except Exception, e:
|
|
except Exception, e:
|
|
|
- return "Operation failed: %s" % str(e)
|
|
|
|
|
|
|
+ self.raiseTclError("Operation failed: %s" % str(e))
|
|
|
|
|
|
|
|
return 'Ok'
|
|
return 'Ok'
|
|
|
|
|
|