From f68cffcfb243f2a85fcd792b296e9e3b5a562ca7 Mon Sep 17 00:00:00 2001 From: Juan Pablo Caram Date: Tue, 9 Dec 2014 21:30:01 -0500 Subject: [PATCH] Hole milling is functional. Solves issue #74. --- FlatCAMApp.py | 2 ++ FlatCAMObj.py | 17 +++++++++++++---- camlib.py | 13 +++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 57a6b1ce..94036187 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -84,9 +84,11 @@ class App(QtCore.QObject): App.log.debug("Win32!") self.data_path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, None, 0) + \ '/FlatCAM' + self.os = 'windows' else: # Linux/Unix/MacOS self.data_path = os.path.expanduser('~') + \ '/.FlatCAM' + self.os = 'unix' ############################### ### Setup folders and files ### diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 3f88c178..9fa6a90f 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -635,13 +635,19 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): self.app.report_usage("excellon_on_create_milling_button") self.read_form() - # Get the tools from the list + # Get the tools from the list. These are keys + # to self.tools tools = self.get_selected_tools_list() if len(tools) == 0: self.app.inform.emit("Please select one or more tools from the list and try again.") return + for tool in tools: + if self.tools[tool]["C"] < self.options["tooldia"]: + self.app.inform.emit("[warning] Milling tool is larger than hole size. Cancelled.") + return + geo_name = self.options["name"] + "_mill" def geo_init(geo_obj, app_obj): @@ -653,7 +659,8 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): for hole in self.drills: if hole['tool'] in tools: geo_obj.solid_geometry.append( - Point(hole['point']).buffer(self.tools[hole['tool']]["C"]/2 - self.options["tooldia"]/2).exterior + Point(hole['point']).buffer(self.tools[hole['tool']]["C"] / 2 - + self.options["tooldia"] / 2).exterior ) def geo_thread(app_obj): @@ -1121,7 +1128,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): try: for sub_el in element: self.plot_element(sub_el) - except TypeError: + + except TypeError: # Element is not iterable... + if type(element) == Polygon: x, y = element.exterior.coords.xy self.axes.plot(x, y, 'r-') @@ -1135,7 +1144,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry): self.axes.plot(x, y, 'r-') return - FlatCAMApp.App.log.warning("Did not plot:", str(type(element))) + FlatCAMApp.App.log.warning("Did not plot:" + str(type(element))) def plot(self): """ diff --git a/camlib.py b/camlib.py index f329d11a..d2dddbc3 100644 --- a/camlib.py +++ b/camlib.py @@ -190,7 +190,16 @@ class Geometry(object): :rtype: Shapely.MultiPolygon or Shapely.Polygon """ return self.solid_geometry.buffer(offset) - + + def is_empty(self): + if self.solid_geometry is None: + return True + + if type(self.solid_geometry) is list and len(self.solid_geometry) == 0: + return True + + return False + def size(self): """ Returns (width, height) of rectangular @@ -200,7 +209,7 @@ class Geometry(object): log.warning("Solid_geometry not computed yet.") return 0 bounds = self.bounds() - return bounds[2]-bounds[0], bounds[3]-bounds[1] + return bounds[2] - bounds[0], bounds[3] - bounds[1] def get_empty_area(self, boundary=None): """