From dc2143f4c9cd892564ee689b1cd910a211690227 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 11 Nov 2020 01:39:56 +0200 Subject: [PATCH] - Drilling cut in Cutout Tool now works for geometry with multiple segments --- CHANGELOG.md | 1 + appTools/ToolCutOut.py | 45 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f5facb5..b2224d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ CHANGELOG for FlatCAM beta - fixed Paint Tcl command; fixes issue #437 - updated the setup_ubuntu.sh script - finished adding new feature in Cutout Tool: cut a geometry by drilling along its path +- Drilling cut in Cutout Tool now works for geometry with multiple segments 9.11.2020 diff --git a/appTools/ToolCutOut.py b/appTools/ToolCutOut.py index dd8e86e6..68ea8db8 100644 --- a/appTools/ToolCutOut.py +++ b/appTools/ToolCutOut.py @@ -1347,17 +1347,46 @@ class CutOut(AppTool): _("There is no object selected for Cutout.\nSelect one and try again.")) return - cut_geo = unary_union(obj.solid_geometry).buffer(margin, join_style=2).exterior - geo_length = cut_geo.length + cut_geo_solid = unary_union(obj.solid_geometry) drill_list = [] - dist = 0 - while dist <= geo_length: - drill_list.append(cut_geo.interpolate(dist)) - dist += pitch + try: + for geo in cut_geo_solid: + if isinstance(geo, LineString): + cut_geo = geo.parallel_offset(margin, side='left') + elif isinstance(geo, Polygon): + cut_geo = geo.buffer(margin).exterior + else: + self.app.inform.emit('[WARNING_NOTCL] %s %s' % (_("Failed."), _("Could not add drills."))) + return - if dist < geo_length: - drill_list.append(Point(list(cut_geo.coords)[-1])) + geo_length = cut_geo.length + + dist = 0 + while dist <= geo_length: + drill_list.append(cut_geo.interpolate(dist)) + dist += pitch + + if dist < geo_length: + drill_list.append(Point(list(cut_geo.coords)[-1])) + except TypeError: + if isinstance(cut_geo_solid, LineString): + cut_geo = cut_geo_solid.parallel_offset(margin, side='left') + elif isinstance(cut_geo_solid, Polygon): + cut_geo = cut_geo_solid.buffer(margin).exterior + else: + self.app.inform.emit('[WARNING_NOTCL] %s %s' % (_("Failed."), _("Could not add drills."))) + return + + geo_length = cut_geo.length + + dist = 0 + while dist <= geo_length: + drill_list.append(cut_geo.interpolate(dist)) + dist += pitch + + if dist < geo_length: + drill_list.append(Point(list(cut_geo.coords)[-1])) if not drill_list: self.app.inform.emit('[WARNING_NOTCL] %s %s' % (_("Failed."), _("Could not add drills.")))