From 8f787fc61ac9c0c87ed4119b1419d5871e555e93 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 24 Jan 2019 12:31:42 +0200 Subject: [PATCH] - fixed the Copy Object function when the object is Gerber - added the Copy entry to the Project context menu - made the functions behind Disable and Enable project context menu entries, non-threaded to fix a possible issue --- FlatCAMApp.py | 100 ++++++++++++++++++++++++++++++-------------- FlatCAMGUI.py | 1 + ObjectCollection.py | 1 + README.md | 3 ++ 4 files changed, 73 insertions(+), 32 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 308d32a5..3a4bc7fe 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -956,6 +956,7 @@ class App(QtCore.QObject): self.ui.menuprojectenable.triggered.connect(lambda: self.enable_plots(self.collection.get_selected())) self.ui.menuprojectdisable.triggered.connect(lambda: self.disable_plots(self.collection.get_selected())) self.ui.menuprojectgeneratecnc.triggered.connect(lambda: self.generate_cnc_job(self.collection.get_selected())) + self.ui.menuprojectcopy.triggered.connect(self.on_copy_object) self.ui.menuprojectdelete.triggered.connect(self.on_delete) # Toolbar @@ -3090,8 +3091,11 @@ class App(QtCore.QObject): def initialize(obj_init, app): obj_init.solid_geometry = obj.solid_geometry - if obj.tools: - obj_init.tools = obj.tools + try: + if obj.tools: + obj_init.tools = obj.tools + except Exception as e: + log.debug("on_copy_object() --> %s" % str(e)) def initialize_excellon(obj_init, app): obj_init.tools = obj.tools @@ -3118,8 +3122,11 @@ class App(QtCore.QObject): def initialize_geometry(obj_init, app): obj_init.solid_geometry = obj.solid_geometry - if obj.tools: - obj_init.tools = obj.tools + try: + if obj.tools: + obj_init.tools = obj.tools + except Exception as e: + log.debug("on_copy_object2() --> %s" % str(e)) def initialize_gerber(obj_init, app): obj_init.solid_geometry = obj.solid_geometry @@ -5899,28 +5906,51 @@ class App(QtCore.QObject): "info" ) - def enable_plots(self, objects): - def worker_task(app_obj): - percentage = 0.1 - try: - delta = 0.9 / len(objects) - except ZeroDivisionError: + # TODO: FIX THIS + ''' + By default this is not threaded + If threaded the app give warnings like this: + + QObject::connect: Cannot queue arguments of type 'QVector' + (Make sure 'QVector' is registered using qRegisterMetaType(). + ''' + def enable_plots(self, objects, threaded=False): + if threaded is True: + def worker_task(app_obj): + percentage = 0.1 + try: + delta = 0.9 / len(objects) + except ZeroDivisionError: + self.progress.emit(0) + return + for obj in objects: + obj.options['plot'] = True + percentage += delta + self.progress.emit(int(percentage*100)) + self.progress.emit(0) - return + self.plots_updated.emit() + self.collection.update_view() + + # Send to worker + # self.worker.add_task(worker_task, [self]) + self.worker_task.emit({'fcn': worker_task, 'params': [self]}) + else: for obj in objects: obj.options['plot'] = True - percentage += delta - self.progress.emit(int(percentage*100)) - self.progress.emit(0) self.plots_updated.emit() self.collection.update_view() - # Send to worker - # self.worker.add_task(worker_task, [self]) - self.worker_task.emit({'fcn': worker_task, 'params': [self]}) + # TODO: FIX THIS + ''' + By default this is not threaded + If threaded the app give warnings like this: - def disable_plots(self, objects): + QObject::connect: Cannot queue arguments of type 'QVector' + (Make sure 'QVector' is registered using qRegisterMetaType(). + ''' + def disable_plots(self, objects, threaded=False): # TODO: This method is very similar to replot_all. Try to merge. """ Disables plots @@ -5928,28 +5958,34 @@ class App(QtCore.QObject): Objects to be disabled :return: """ - self.progress.emit(10) - def worker_task(app_obj): - percentage = 0.1 - try: - delta = 0.9 / len(objects) - except ZeroDivisionError: + if threaded is True: + self.progress.emit(10) + def worker_task(app_obj): + percentage = 0.1 + try: + delta = 0.9 / len(objects) + except ZeroDivisionError: + self.progress.emit(0) + return + + for obj in objects: + obj.options['plot'] = False + percentage += delta + self.progress.emit(int(percentage*100)) + self.progress.emit(0) - return + self.plots_updated.emit() + self.collection.update_view() + # Send to worker + self.worker_task.emit({'fcn': worker_task, 'params': [self]}) + else: for obj in objects: obj.options['plot'] = False - percentage += delta - self.progress.emit(int(percentage*100)) - - self.progress.emit(0) self.plots_updated.emit() self.collection.update_view() - # Send to worker - self.worker_task.emit({'fcn': worker_task, 'params': [self]}) - def clear_plots(self): objects = self.collection.get_list() diff --git a/FlatCAMGUI.py b/FlatCAMGUI.py index 80f1e2f9..5c999e93 100644 --- a/FlatCAMGUI.py +++ b/FlatCAMGUI.py @@ -323,6 +323,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow): self.menuproject.addSeparator() self.menuprojectgeneratecnc = self.menuproject.addAction('Generate CNC') self.menuproject.addSeparator() + self.menuprojectcopy = self.menuproject.addAction('Copy') self.menuprojectdelete = self.menuproject.addAction('Delete') ############### diff --git a/ObjectCollection.py b/ObjectCollection.py index 8ed49a95..2b08e8d6 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -388,6 +388,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): sel = len(self.view.selectedIndexes()) > 0 self.app.ui.menuprojectenable.setEnabled(sel) self.app.ui.menuprojectdisable.setEnabled(sel) + self.app.ui.menuprojectcopy.setEnabled(sel) self.app.ui.menuprojectdelete.setEnabled(sel) if sel: diff --git a/README.md b/README.md index 4db51f1a..dfaae2fa 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ CAD program, and create G-Code for Isolation routing. 24.01.2019 - trying to fix painting single when the actual painted object it's a MultiPolygon +- fixed the Copy Object function when the object is Gerber +- added the Copy entry to the Project context menu +- made the functions behind Disable and Enable project context menu entries, non-threaded to fix a possible issue 23.01.2019