Support for milling holes from the shell, command "millholes".
This commit is contained in:
parent
1942fe3bed
commit
a2ac2b12be
|
@ -2136,6 +2136,43 @@ class App(QtCore.QObject):
|
||||||
|
|
||||||
return 'Ok'
|
return 'Ok'
|
||||||
|
|
||||||
|
def drillmillgeometry(name, *args):
|
||||||
|
a, kwa = h(*args)
|
||||||
|
types = {'tooldia': float,
|
||||||
|
'tools': str,
|
||||||
|
'outname': str}
|
||||||
|
|
||||||
|
for key in kwa:
|
||||||
|
if key not in types:
|
||||||
|
return 'Unknown parameter: %s' % key
|
||||||
|
kwa[key] = types[key](kwa[key])
|
||||||
|
|
||||||
|
try:
|
||||||
|
if 'tools' in kwa:
|
||||||
|
kwa['tools'] = [x.strip() for x in kwa['tools'].split(",")]
|
||||||
|
except Exception as e:
|
||||||
|
return "Bad tools: %s" % str(e)
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = self.collection.get_by_name(str(name))
|
||||||
|
except:
|
||||||
|
return "Could not retrieve object: %s" % name
|
||||||
|
|
||||||
|
if obj is None:
|
||||||
|
return "Object not found: %s" % name
|
||||||
|
|
||||||
|
assert isinstance(obj, FlatCAMExcellon)
|
||||||
|
|
||||||
|
try:
|
||||||
|
success, msg = obj.generate_milling(**kwa)
|
||||||
|
except Exception as e:
|
||||||
|
return "Operation failed: %s" % str(e)
|
||||||
|
|
||||||
|
if not success:
|
||||||
|
return msg
|
||||||
|
|
||||||
|
return 'Ok'
|
||||||
|
|
||||||
def isolate(name, *args):
|
def isolate(name, *args):
|
||||||
a, kwa = h(*args)
|
a, kwa = h(*args)
|
||||||
types = {'dia': float,
|
types = {'dia': float,
|
||||||
|
@ -2157,6 +2194,8 @@ class App(QtCore.QObject):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return "Object not found: %s" % name
|
return "Object not found: %s" % name
|
||||||
|
|
||||||
|
assert isinstance(obj, FlatCAMGerber)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj.isolate(**kwa)
|
obj.isolate(**kwa)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -2290,16 +2329,14 @@ class App(QtCore.QObject):
|
||||||
|
|
||||||
obj.union()
|
obj.union()
|
||||||
|
|
||||||
|
def join_geometries(obj_name, *obj_names):
|
||||||
|
|
||||||
def join_geometries (obj_name, *obj_names):
|
|
||||||
objs = []
|
objs = []
|
||||||
for obj_n in obj_names:
|
for obj_n in obj_names:
|
||||||
obj = self.collection.get_by_name(str(obj_n))
|
obj = self.collection.get_by_name(str(obj_n))
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return "Object not found: %s" % obj_n
|
return "Object not found: %s" % obj_n
|
||||||
else:
|
else:
|
||||||
objs.append (obj)
|
objs.append(obj)
|
||||||
|
|
||||||
def initialize(obj, app):
|
def initialize(obj, app):
|
||||||
FlatCAMGeometry.merge(objs, obj)
|
FlatCAMGeometry.merge(objs, obj)
|
||||||
|
@ -2501,6 +2538,15 @@ class App(QtCore.QObject):
|
||||||
" spindlespeed: Speed of the spindle in rpm (example: 4000)\n" +
|
" spindlespeed: Speed of the spindle in rpm (example: 4000)\n" +
|
||||||
" toolchange: Enable tool changes (example: 1)\n"
|
" toolchange: Enable tool changes (example: 1)\n"
|
||||||
},
|
},
|
||||||
|
'millholes': {
|
||||||
|
'fcn': drillmillgeometry,
|
||||||
|
'help': "Create Geometry Object for milling holes from Excellon.\n" +
|
||||||
|
"> drillmillgeometry <name> -tools <str> -tooldia <float> -outname <str> \n" +
|
||||||
|
" name: Name of the Excellon Object\n" +
|
||||||
|
" tools: Comma separated indexes of tools (example: 1,3 or 2)\n" +
|
||||||
|
" tooldia: Diameter of the milling tool (example: 0.1)\n" +
|
||||||
|
" outname: Name of object to create\n"
|
||||||
|
},
|
||||||
'scale': {
|
'scale': {
|
||||||
'fcn': lambda name, factor: self.collection.get_by_name(str(name)).scale(float(factor)),
|
'fcn': lambda name, factor: self.collection.get_by_name(str(name)).scale(float(factor)),
|
||||||
'help': "Resizes the object by a factor.\n" +
|
'help': "Resizes the object by a factor.\n" +
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
from copy import copy
|
||||||
from ObjectUI import *
|
from ObjectUI import *
|
||||||
import FlatCAMApp
|
import FlatCAMApp
|
||||||
import inspect # TODO: For debugging only.
|
import inspect # TODO: For debugging only.
|
||||||
|
@ -679,27 +680,42 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||||
"""
|
"""
|
||||||
Returns the keys to the self.tools dictionary corresponding
|
Returns the keys to the self.tools dictionary corresponding
|
||||||
to the selections on the tool list in the GUI.
|
to the selections on the tool list in the GUI.
|
||||||
|
|
||||||
|
:return: List of tools.
|
||||||
|
:rtype: list
|
||||||
"""
|
"""
|
||||||
return [str(x.text()) for x in self.ui.tools_table.selectedItems()]
|
return [str(x.text()) for x in self.ui.tools_table.selectedItems()]
|
||||||
|
|
||||||
def on_generate_milling_button_click(self, *args):
|
def generate_milling(self, tools=None, outname=None, tooldia=None):
|
||||||
self.app.report_usage("excellon_on_create_milling_button")
|
"""
|
||||||
self.read_form()
|
Note: This method is a good template for generic operations as
|
||||||
|
it takes it's options from parameters or otherwise from the
|
||||||
|
object's options and returns a success, msg tuple as feedback
|
||||||
|
for shell operations.
|
||||||
|
|
||||||
|
:return: Success/failure condition tuple (bool, str).
|
||||||
|
:rtype: tuple
|
||||||
|
"""
|
||||||
|
|
||||||
# Get the tools from the list. These are keys
|
# Get the tools from the list. These are keys
|
||||||
# to self.tools
|
# to self.tools
|
||||||
|
if tools is None:
|
||||||
tools = self.get_selected_tools_list()
|
tools = self.get_selected_tools_list()
|
||||||
|
|
||||||
|
if outname is None:
|
||||||
|
outname = self.options["name"] + "_mill"
|
||||||
|
|
||||||
|
if tooldia is None:
|
||||||
|
tooldia = self.options["tooldia"]
|
||||||
|
|
||||||
if len(tools) == 0:
|
if len(tools) == 0:
|
||||||
self.app.inform.emit("Please select one or more tools from the list and try again.")
|
self.app.inform.emit("Please select one or more tools from the list and try again.")
|
||||||
return
|
return False, "Error: No tools."
|
||||||
|
|
||||||
for tool in tools:
|
for tool in tools:
|
||||||
if self.tools[tool]["C"] < self.options["tooldia"]:
|
if self.tools[tool]["C"] < tooldia:
|
||||||
self.app.inform.emit("[warning] Milling tool is larger than hole size. Cancelled.")
|
self.app.inform.emit("[warning] Milling tool is larger than hole size. Cancelled.")
|
||||||
return
|
return False, "Error: Milling tool is larger than hole."
|
||||||
|
|
||||||
geo_name = self.options["name"] + "_mill"
|
|
||||||
|
|
||||||
def geo_init(geo_obj, app_obj):
|
def geo_init(geo_obj, app_obj):
|
||||||
assert isinstance(geo_obj, FlatCAMGeometry)
|
assert isinstance(geo_obj, FlatCAMGeometry)
|
||||||
|
@ -711,19 +727,27 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||||
if hole['tool'] in tools:
|
if hole['tool'] in tools:
|
||||||
geo_obj.solid_geometry.append(
|
geo_obj.solid_geometry.append(
|
||||||
Point(hole['point']).buffer(self.tools[hole['tool']]["C"] / 2 -
|
Point(hole['point']).buffer(self.tools[hole['tool']]["C"] / 2 -
|
||||||
self.options["tooldia"] / 2).exterior
|
tooldia / 2).exterior
|
||||||
)
|
)
|
||||||
|
|
||||||
def geo_thread(app_obj):
|
def geo_thread(app_obj):
|
||||||
app_obj.new_object("geometry", geo_name, geo_init)
|
app_obj.new_object("geometry", outname, geo_init)
|
||||||
app_obj.progress.emit(100)
|
app_obj.progress.emit(100)
|
||||||
|
|
||||||
# Create a promise with the new name
|
# Create a promise with the new name
|
||||||
self.app.collection.promise(geo_name)
|
self.app.collection.promise(outname)
|
||||||
|
|
||||||
# Send to worker
|
# Send to worker
|
||||||
self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
|
self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
|
||||||
|
|
||||||
|
return True, ""
|
||||||
|
|
||||||
|
def on_generate_milling_button_click(self, *args):
|
||||||
|
self.app.report_usage("excellon_on_create_milling_button")
|
||||||
|
self.read_form()
|
||||||
|
|
||||||
|
self.generate_milling()
|
||||||
|
|
||||||
def on_create_cncjob_button_click(self, *args):
|
def on_create_cncjob_button_click(self, *args):
|
||||||
self.app.report_usage("excellon_on_create_cncjob_button")
|
self.app.report_usage("excellon_on_create_cncjob_button")
|
||||||
self.read_form()
|
self.read_form()
|
||||||
|
|
Loading…
Reference in New Issue