From 1edb049d86e8df994e4586f4f29e860bb52a650b Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 5 Jul 2019 12:13:53 +0300 Subject: [PATCH] - fixed bug in CutOut Tool --- README.md | 4 + flatcamTools/ToolCutOut.py | 200 +++++++++++++++++++------------------ 2 files changed, 106 insertions(+), 98 deletions(-) diff --git a/README.md b/README.md index 32965f16..0cfbf60a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing. ================================================= +5.07.2019 + +- fixed bug in CutOut Tool + 1.07.2019 - Spanish translation at 36% diff --git a/flatcamTools/ToolCutOut.py b/flatcamTools/ToolCutOut.py index 305e6f3c..c7136e39 100644 --- a/flatcamTools/ToolCutOut.py +++ b/flatcamTools/ToolCutOut.py @@ -419,61 +419,65 @@ class CutOut(FlatCAMTool): except TypeError: object_geo = [object_geo] - for geo in object_geo: - if isinstance(cutout_obj, FlatCAMGerber): - geo = (geo.buffer(margin + abs(dia / 2))).exterior + # for geo in object_geo: + if isinstance(cutout_obj, FlatCAMGerber): + geo = (object_geo.buffer(margin + abs(dia / 2))).exterior + else: + geo = object_geo - # Get min and max data for each object as we just cut rectangles across X or Y - xmin, ymin, xmax, ymax = recursive_bounds(geo) + geo = unary_union(geo) - px = 0.5 * (xmin + xmax) + margin - py = 0.5 * (ymin + ymax) + margin - lenx = (xmax - xmin) + (margin * 2) - leny = (ymax - ymin) + (margin * 2) + # Get min and max data for each object as we just cut rectangles across X or Y + xmin, ymin, xmax, ymax = recursive_bounds(geo) - if gaps == '8' or gaps == '2LR': - geo = self.subtract_poly_from_geo(geo, - xmin - gapsize, # botleft_x - py - gapsize + leny / 4, # botleft_y - xmax + gapsize, # topright_x - py + gapsize + leny / 4) # topright_y - geo = self.subtract_poly_from_geo(geo, - xmin - gapsize, - py - gapsize - leny / 4, - xmax + gapsize, - py + gapsize - leny / 4) + px = 0.5 * (xmin + xmax) + margin + py = 0.5 * (ymin + ymax) + margin + lenx = (xmax - xmin) + (margin * 2) + leny = (ymax - ymin) + (margin * 2) - if gaps == '8' or gaps == '2TB': - geo = self.subtract_poly_from_geo(geo, - px - gapsize + lenx / 4, - ymin - gapsize, - px + gapsize + lenx / 4, - ymax + gapsize) - geo = self.subtract_poly_from_geo(geo, - px - gapsize - lenx / 4, - ymin - gapsize, - px + gapsize - lenx / 4, - ymax + gapsize) + if gaps == '8' or gaps == '2LR': + geo = self.subtract_poly_from_geo(geo, + xmin - gapsize, # botleft_x + py - gapsize + leny / 4, # botleft_y + xmax + gapsize, # topright_x + py + gapsize + leny / 4) # topright_y + geo = self.subtract_poly_from_geo(geo, + xmin - gapsize, + py - gapsize - leny / 4, + xmax + gapsize, + py + gapsize - leny / 4) - if gaps == '4' or gaps == 'LR': - geo = self.subtract_poly_from_geo(geo, - xmin - gapsize, - py - gapsize, - xmax + gapsize, - py + gapsize) + if gaps == '8' or gaps == '2TB': + geo = self.subtract_poly_from_geo(geo, + px - gapsize + lenx / 4, + ymin - gapsize, + px + gapsize + lenx / 4, + ymax + gapsize) + geo = self.subtract_poly_from_geo(geo, + px - gapsize - lenx / 4, + ymin - gapsize, + px + gapsize - lenx / 4, + ymax + gapsize) - if gaps == '4' or gaps == 'TB': - geo = self.subtract_poly_from_geo(geo, - px - gapsize, - ymin - gapsize, - px + gapsize, - ymax + gapsize) + if gaps == '4' or gaps == 'LR': + geo = self.subtract_poly_from_geo(geo, + xmin - gapsize, + py - gapsize, + xmax + gapsize, + py + gapsize) - try: - for g in geo: - solid_geo.append(g) - except TypeError: - solid_geo.append(geo) + if gaps == '4' or gaps == 'TB': + geo = self.subtract_poly_from_geo(geo, + px - gapsize, + ymin - gapsize, + px + gapsize, + ymax + gapsize) + + try: + for g in geo: + solid_geo.append(g) + except TypeError: + solid_geo.append(geo) geo_obj.solid_geometry = deepcopy(solid_geo) xmin, ymin, xmax, ymax = recursive_bounds(geo_obj.solid_geometry) @@ -575,63 +579,63 @@ class CutOut(FlatCAMTool): except TypeError: object_geo = [object_geo] - for poly in object_geo: + object_geo = unary_union(object_geo) - xmin, ymin, xmax, ymax = poly.bounds - geo = box(xmin, ymin, xmax, ymax) + xmin, ymin, xmax, ymax = object_geo.bounds + geo = box(xmin, ymin, xmax, ymax) - # if Gerber create a buffer at a distance - # if Geometry then cut through the geometry - if isinstance(cutout_obj, FlatCAMGerber): - geo = geo.buffer(margin + abs(dia / 2)) + # if Gerber create a buffer at a distance + # if Geometry then cut through the geometry + if isinstance(cutout_obj, FlatCAMGerber): + geo = geo.buffer(margin + abs(dia / 2)) - px = 0.5 * (xmin + xmax) + margin - py = 0.5 * (ymin + ymax) + margin - lenx = (xmax - xmin) + (margin * 2) - leny = (ymax - ymin) + (margin * 2) + px = 0.5 * (xmin + xmax) + margin + py = 0.5 * (ymin + ymax) + margin + lenx = (xmax - xmin) + (margin * 2) + leny = (ymax - ymin) + (margin * 2) - if gaps == '8' or gaps == '2LR': - geo = self.subtract_poly_from_geo(geo, - xmin - gapsize, # botleft_x - py - gapsize + leny / 4, # botleft_y - xmax + gapsize, # topright_x - py + gapsize + leny / 4) # topright_y - geo = self.subtract_poly_from_geo(geo, - xmin - gapsize, - py - gapsize - leny / 4, - xmax + gapsize, - py + gapsize - leny / 4) + if gaps == '8' or gaps == '2LR': + geo = self.subtract_poly_from_geo(geo, + xmin - gapsize, # botleft_x + py - gapsize + leny / 4, # botleft_y + xmax + gapsize, # topright_x + py + gapsize + leny / 4) # topright_y + geo = self.subtract_poly_from_geo(geo, + xmin - gapsize, + py - gapsize - leny / 4, + xmax + gapsize, + py + gapsize - leny / 4) - if gaps == '8' or gaps == '2TB': - geo = self.subtract_poly_from_geo(geo, - px - gapsize + lenx / 4, - ymin - gapsize, - px + gapsize + lenx / 4, - ymax + gapsize) - geo = self.subtract_poly_from_geo(geo, - px - gapsize - lenx / 4, - ymin - gapsize, - px + gapsize - lenx / 4, - ymax + gapsize) + if gaps == '8' or gaps == '2TB': + geo = self.subtract_poly_from_geo(geo, + px - gapsize + lenx / 4, + ymin - gapsize, + px + gapsize + lenx / 4, + ymax + gapsize) + geo = self.subtract_poly_from_geo(geo, + px - gapsize - lenx / 4, + ymin - gapsize, + px + gapsize - lenx / 4, + ymax + gapsize) - if gaps == '4' or gaps == 'LR': - geo = self.subtract_poly_from_geo(geo, - xmin - gapsize, - py - gapsize, - xmax + gapsize, - py + gapsize) + if gaps == '4' or gaps == 'LR': + geo = self.subtract_poly_from_geo(geo, + xmin - gapsize, + py - gapsize, + xmax + gapsize, + py + gapsize) - if gaps == '4' or gaps == 'TB': - geo = self.subtract_poly_from_geo(geo, - px - gapsize, - ymin - gapsize, - px + gapsize, - ymax + gapsize) - try: - for g in geo: - solid_geo.append(g) - except TypeError: - solid_geo.append(geo) + if gaps == '4' or gaps == 'TB': + geo = self.subtract_poly_from_geo(geo, + px - gapsize, + ymin - gapsize, + px + gapsize, + ymax + gapsize) + try: + for g in geo: + solid_geo.append(g) + except TypeError: + solid_geo.append(geo) geo_obj.solid_geometry = deepcopy(solid_geo)