diff --git a/README.md b/README.md index 84d0b328..ba0d2dcc 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ CAD program, and create G-Code for Isolation routing. - updated the Edit -> Preferences to include also the Gerber Editor complete Preferences - started to update the app strings to make it easier for future translations - fixed the POT file and the German translation +- some mods in the Tool Sub 18.08.2019 diff --git a/flatcamTools/ToolSub.py b/flatcamTools/ToolSub.py index 486fc283..bdc78304 100644 --- a/flatcamTools/ToolSub.py +++ b/flatcamTools/ToolSub.py @@ -23,6 +23,8 @@ if '_' not in builtins.__dict__: class ToolSub(FlatCAMTool): + job_finished = QtCore.pyqtSignal(bool) + toolName = _("Substract Tool") def __init__(self, app): @@ -188,6 +190,7 @@ class ToolSub(FlatCAMTool): except (TypeError, AttributeError): pass self.intersect_geo_btn.clicked.connect(self.on_geo_intersection_click) + self.job_finished.connect(self.on_job_finished) def install(self, icon=None, separator=None, **kwargs): FlatCAMTool.install(self, icon, separator, shortcut='ALT+W', **kwargs) @@ -286,7 +289,7 @@ class ToolSub(FlatCAMTool): for apid in self.target_grb_obj.apertures: self.promises.append(apid) - # start the QTimer to check for promises with 1 second period check + # start the QTimer to check for promises with 0.5 second period check self.periodic_check(500, reset=True) for apid in self.target_grb_obj.apertures: @@ -455,14 +458,14 @@ class ToolSub(FlatCAMTool): return # create the target_options obj - self.target_options = {} + self.target_options = dict() for opt in self.target_geo_obj.options: if opt != 'name': self.target_options[opt] = deepcopy(self.target_geo_obj.options[opt]) # crate the new_tools dict structure for tool in self.target_geo_obj.tools: - self.new_tools[tool] = {} + self.new_tools[tool] = dict() for key in self.target_geo_obj.tools[tool]: if key == 'solid_geometry': self.new_tools[tool][key] = [] @@ -514,16 +517,14 @@ class ToolSub(FlatCAMTool): if isinstance(geo_elem, Polygon): for ring in self.poly2rings(geo_elem): new_geo = ring.difference(self.sub_union) - if new_geo: - if not new_geo.is_empty: - new_geometry.append(new_geo) + if new_geo and not new_geo.is_empty: + new_geometry.append(new_geo) elif isinstance(geo_elem, MultiPolygon): for poly in geo_elem: for ring in self.poly2rings(poly): new_geo = ring.difference(self.sub_union) - if new_geo: - if not new_geo.is_empty: - new_geometry.append(new_geo) + if new_geo and not new_geo.is_empty: + new_geometry.append(new_geo) elif isinstance(geo_elem, LineString): new_geo = geo_elem.difference(self.sub_union) if new_geo: @@ -532,9 +533,8 @@ class ToolSub(FlatCAMTool): elif isinstance(geo_elem, MultiLineString): for line_elem in geo_elem: new_geo = line_elem.difference(self.sub_union) - if new_geo: - if not new_geo.is_empty: - new_geometry.append(new_geo) + if new_geo and not new_geo.is_empty: + new_geometry.append(new_geo) except TypeError: if isinstance(geo, Polygon): for ring in self.poly2rings(geo): @@ -544,15 +544,13 @@ class ToolSub(FlatCAMTool): new_geometry.append(new_geo) elif isinstance(geo, LineString): new_geo = geo.difference(self.sub_union) - if new_geo: - if not new_geo.is_empty: - new_geometry.append(new_geo) + if new_geo and not new_geo.is_empty: + new_geometry.append(new_geo) elif isinstance(geo, MultiLineString): for line_elem in geo: new_geo = line_elem.difference(self.sub_union) - if new_geo: - if not new_geo.is_empty: - new_geometry.append(new_geo) + if new_geo and not new_geo.is_empty: + new_geometry.append(new_geo) if new_geometry: if tool == "single": @@ -575,10 +573,11 @@ class ToolSub(FlatCAMTool): log.debug("Promise fulfilled: %s" % str(tool)) def new_geo_object(self, outname): + geo_name = outname def obj_init(geo_obj, app_obj): geo_obj.options = deepcopy(self.target_options) - geo_obj.options['name'] = outname + geo_obj.options['name'] = geo_name if self.target_geo_obj.multigeo: geo_obj.tools = deepcopy(self.new_tools) @@ -645,27 +644,39 @@ class ToolSub(FlatCAMTool): try: if not self.promises: self.check_thread.stop() - if self.sub_type == "gerber": - outname = self.target_gerber_combo.currentText() + '_sub' - - # intersection jobs finished, start the creation of solid_geometry - self.app.worker_task.emit({'fcn': self.new_gerber_object, - 'params': [outname]}) - else: - outname = self.target_geo_combo.currentText() + '_sub' - - # intersection jobs finished, start the creation of solid_geometry - self.app.worker_task.emit({'fcn': self.new_geo_object, - 'params': [outname]}) + self.job_finished.emit(True) # reset the type of substraction for next time self.sub_type = None log.debug("ToolSub --> Periodic check finished.") except Exception as e: + self.job_finished.emit(False) log.debug("ToolSub().periodic_check_handler() --> %s" % str(e)) traceback.print_exc() + def on_job_finished(self, succcess): + """ + + :param succcess: boolean, this parameter signal if all the apertures were processed + :return: None + """ + if succcess is True: + if self.sub_type == "gerber": + outname = self.target_gerber_combo.currentText() + '_sub' + + # intersection jobs finished, start the creation of solid_geometry + self.app.worker_task.emit({'fcn': self.new_gerber_object, + 'params': [outname]}) + else: + outname = self.target_geo_combo.currentText() + '_sub' + + # intersection jobs finished, start the creation of solid_geometry + self.app.worker_task.emit({'fcn': self.new_geo_object, + 'params': [outname]}) + else: + self.app.inform.emit(_('[ERROR_NOTCL] Generating new object failed.')) + def reset_fields(self): self.target_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex())) self.sub_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))