From 2a30101bb01b10fd7327676a9312103ddfd4e52a Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 3 Jun 2019 04:47:29 +0300 Subject: [PATCH] - TclCommand Geocutout is now creating a new geometry object when working on a geometry, preserving also the origin object --- FlatCAMApp.py | 25 +++--- FlatCAMObj.py | 18 ++--- README.md | 4 + camlib.py | 6 +- flatcamTools/ToolCutOut.py | 4 +- tclCommands/TclCommandGeoCutout.py | 125 ++++++++++++++++++++--------- 6 files changed, 110 insertions(+), 72 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index c94f0052..819a6faa 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -8278,11 +8278,14 @@ The normal flow when working in FlatCAM is the following:

self.inform.emit(_("[success] All plots enabled.")) def on_enable_sel_plots(self): + log.debug("App.on_enable_sel_plot()") object_list = self.collection.get_selected() self.enable_plots(objects=object_list) self.inform.emit(_("[success] Selected plots enabled...")) def on_disable_sel_plots(self): + log.debug("App.on_disable_sel_plot()") + # self.inform.emit(_("Disabling plots ...")) object_list = self.collection.get_selected() self.disable_plots(objects=object_list) @@ -8297,14 +8300,9 @@ The normal flow when working in FlatCAM is the following:

log.debug("Enabling plots ...") - def worker_task(app_obj): - # app_obj.inform.emit(_("Enabling plots ...")) - for obj in objects: - obj.options['plot'] = True - self.plots_updated.emit() - - # Send to worker - self.worker_task.emit({'fcn': worker_task, 'params': [self]}) + for obj in objects: + obj.options['plot'] = True + self.plots_updated.emit() def disable_plots(self, objects): """ @@ -8315,14 +8313,9 @@ The normal flow when working in FlatCAM is the following:

log.debug("Disabling plots ...") - def worker_task(app_obj): - self.inform.emit(_("Disabling plots ...")) - for obj in objects: - obj.options['plot'] = False - self.plots_updated.emit() - - # Send to worker - self.worker_task.emit({'fcn': worker_task, 'params': [self]}) + for obj in objects: + obj.options['plot'] = False + self.plots_updated.emit() def clear_plots(self): diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 21c9705d..a2cb16f9 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -137,7 +137,7 @@ class FlatCAMObj(QtCore.QObject): if key == 'plot': self.visible = self.options['plot'] - self.optionChanged.emit(key) + # self.optionChanged.emit(key) def set_ui(self, ui): self.ui = ui @@ -297,8 +297,6 @@ class FlatCAMObj(QtCore.QObject): return False self.clear() - - return True def serialize(self): @@ -346,7 +344,7 @@ class FlatCAMObj(QtCore.QObject): # Not all object types has annotations try: self.annotation.visible = value - except AttributeError: + except Exception as e: pass @property @@ -366,12 +364,6 @@ class FlatCAMObj(QtCore.QObject): except AttributeError: pass - # Not all object types have mark_shapes - # try: - # self.mark_shapes.clear(update) - # except AttributeError: - # pass - def delete(self): # Free resources del self.ui @@ -1054,7 +1046,6 @@ class FlatCAMGerber(FlatCAMObj, Gerber): :param kwargs: color and face_color :return: """ - FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMGerber.plot()") # Does all the required setup and returns False @@ -1066,6 +1057,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber): color = kwargs['color'] else: color = self.app.defaults['global_plot_line'] + if 'face_color' in kwargs: face_color = kwargs['face_color'] else: @@ -1079,7 +1071,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber): # Make sure geometry is iterable. try: - _ = iter(geometry) + __ = iter(geometry) except TypeError: geometry = [geometry] @@ -2796,7 +2788,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): # this stays for compatibility reasons, in case we try to open old projects try: - _ = iter(self.solid_geometry) + __ = iter(self.solid_geometry) except TypeError: self.solid_geometry = [self.solid_geometry] diff --git a/README.md b/README.md index ceaf70b8..d17b2cc9 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing. ================================================= +3.06.2019 + +- TclCommand Geocutout is now creating a new geometry object when working on a geometry, preserving also the origin object + 2.06.2019 - fixed issue with geometry name not being updated immediately after change while doing geocutout TclCommand diff --git a/camlib.py b/camlib.py index 71eae17a..62a65b79 100644 --- a/camlib.py +++ b/camlib.py @@ -7294,7 +7294,7 @@ def dict2obj(d): # def plotg(geo, solid_poly=False, color="black"): # try: -# _ = iter(geo) +# __ = iter(geo) # except: # geo = [geo] # @@ -7327,7 +7327,7 @@ def dict2obj(d): # continue # # try: -# _ = iter(g) +# __ = iter(g) # plotg(g, color=color) # except: # log.error("Cannot plot: " + str(type(g))) @@ -7633,7 +7633,7 @@ def parse_gerber_number(strnumber, int_digits, frac_digits, zeros): def autolist(obj): try: - _ = iter(obj) + __ = iter(obj) return obj except TypeError: return [obj] diff --git a/flatcamTools/ToolCutOut.py b/flatcamTools/ToolCutOut.py index 19f5df24..20167ebd 100644 --- a/flatcamTools/ToolCutOut.py +++ b/flatcamTools/ToolCutOut.py @@ -415,7 +415,7 @@ class CutOut(FlatCAMTool): object_geo = cutout_obj.solid_geometry try: - _ = iter(object_geo) + __ = iter(object_geo) except TypeError: object_geo = [object_geo] @@ -565,7 +565,7 @@ class CutOut(FlatCAMTool): object_geo = cutout_obj.solid_geometry try: - _ = iter(object_geo) + __ = iter(object_geo) except TypeError: object_geo = [object_geo] diff --git a/tclCommands/TclCommandGeoCutout.py b/tclCommands/TclCommandGeoCutout.py index 076d037e..211af47e 100644 --- a/tclCommands/TclCommandGeoCutout.py +++ b/tclCommands/TclCommandGeoCutout.py @@ -179,49 +179,97 @@ class TclCommandGeoCutout(TclCommandSignaled): if isinstance(cutout_obj, FlatCAMGeometry): # rename the obj name so it can be identified as cutout - cutout_obj.options["name"] += "_cutout" + # cutout_obj.options["name"] += "_cutout" - if gaps_u == 8 or gaps_u == '2lr': - subtract_rectangle(cutout_obj, - xmin - gapsize, # botleft_x - py - gapsize + lenghty / 4, # botleft_y - xmax + gapsize, # topright_x - py + gapsize + lenghty / 4) # topright_y - subtract_rectangle(cutout_obj, - xmin - gapsize, - py - gapsize - lenghty / 4, - xmax + gapsize, - py + gapsize - lenghty / 4) + # if gaps_u == 8 or gaps_u == '2lr': + # subtract_rectangle(cutout_obj, + # xmin - gapsize, # botleft_x + # py - gapsize + lenghty / 4, # botleft_y + # xmax + gapsize, # topright_x + # py + gapsize + lenghty / 4) # topright_y + # subtract_rectangle(cutout_obj, + # xmin - gapsize, + # py - gapsize - lenghty / 4, + # xmax + gapsize, + # py + gapsize - lenghty / 4) + # + # if gaps_u == 8 or gaps_u == '2tb': + # subtract_rectangle(cutout_obj, + # px - gapsize + lenghtx / 4, + # ymin - gapsize, + # px + gapsize + lenghtx / 4, + # ymax + gapsize) + # subtract_rectangle(cutout_obj, + # px - gapsize - lenghtx / 4, + # ymin - gapsize, + # px + gapsize - lenghtx / 4, + # ymax + gapsize) + # + # if gaps_u == 4 or gaps_u == 'lr': + # subtract_rectangle(cutout_obj, + # xmin - gapsize, + # py - gapsize, + # xmax + gapsize, + # py + gapsize) + # + # if gaps_u == 4 or gaps_u == 'tb': + # subtract_rectangle(cutout_obj, + # px - gapsize, + # ymin - gapsize, + # px + gapsize, + # ymax + gapsize) - if gaps_u == 8 or gaps_u == '2tb': - subtract_rectangle(cutout_obj, - px - gapsize + lenghtx / 4, - ymin - gapsize, - px + gapsize + lenghtx / 4, - ymax + gapsize) - subtract_rectangle(cutout_obj, - px - gapsize - lenghtx / 4, - ymin - gapsize, - px + gapsize - lenghtx / 4, - ymax + gapsize) + def geo_init(geo_obj, app_obj): + geo = deepcopy(cutout_obj.solid_geometry) - if gaps_u == 4 or gaps_u == 'lr': - subtract_rectangle(cutout_obj, - xmin - gapsize, - py - gapsize, - xmax + gapsize, - py + gapsize) + if gaps_u == 8 or gaps_u == '2lr': + geo = substract_rectangle_geo(geo, + xmin - gapsize, # botleft_x + py - gapsize + lenghty / 4, # botleft_y + xmax + gapsize, # topright_x + py + gapsize + lenghty / 4) # topright_y + geo = substract_rectangle_geo(geo, + xmin - gapsize, + py - gapsize - lenghty / 4, + xmax + gapsize, + py + gapsize - lenghty / 4) - if gaps_u == 4 or gaps_u == 'tb': - subtract_rectangle(cutout_obj, - px - gapsize, - ymin - gapsize, - px + gapsize, - ymax + gapsize) + if gaps_u == 8 or gaps_u == '2tb': + geo = substract_rectangle_geo(geo, + px - gapsize + lenghtx / 4, + ymin - gapsize, + px + gapsize + lenghtx / 4, + ymax + gapsize) + geo = substract_rectangle_geo(geo, + px - gapsize - lenghtx / 4, + ymin - gapsize, + px + gapsize - lenghtx / 4, + ymax + gapsize) - cutout_obj.plot() - self.app.inform.emit("[success] Any-form Cutout operation finished.") - self.app.plots_updated.emit() + if gaps_u == 4 or gaps_u == 'lr': + geo = substract_rectangle_geo(geo, + xmin - gapsize, + py - gapsize, + xmax + gapsize, + py + gapsize) + + if gaps_u == 4 or gaps_u == 'tb': + geo = substract_rectangle_geo(geo, + px - gapsize, + ymin - gapsize, + px + gapsize, + ymax + gapsize) + geo_obj.solid_geometry = deepcopy(geo) + app_obj.disable_plots(objects=[cutout_obj]) + + app_obj.inform.emit("[success] Any-form Cutout operation finished.") + + outname = cutout_obj.options["name"] + "_cutout" + self.app.new_object('geometry', outname, geo_init) + + # cutout_obj.plot() + # self.app.inform.emit("[success] Any-form Cutout operation finished.") + # self.app.plots_updated.emit() elif isinstance(cutout_obj, FlatCAMGerber): def geo_init(geo_obj, app_obj): @@ -269,6 +317,7 @@ class TclCommandGeoCutout(TclCommandSignaled): px + gapsize, ymax + gapsize) geo_obj.solid_geometry = deepcopy(geo) + app_obj.inform.emit("[success] Any-form Cutout operation finished.") outname = cutout_obj.options["name"] + "_cutout" self.app.new_object('geometry', outname, geo_init)