|
@@ -23,6 +23,8 @@ if '_' not in builtins.__dict__:
|
|
|
|
|
|
|
|
class ToolSub(FlatCAMTool):
|
|
class ToolSub(FlatCAMTool):
|
|
|
|
|
|
|
|
|
|
+ job_finished = QtCore.pyqtSignal(bool)
|
|
|
|
|
+
|
|
|
toolName = _("Substract Tool")
|
|
toolName = _("Substract Tool")
|
|
|
|
|
|
|
|
def __init__(self, app):
|
|
def __init__(self, app):
|
|
@@ -188,6 +190,7 @@ class ToolSub(FlatCAMTool):
|
|
|
except (TypeError, AttributeError):
|
|
except (TypeError, AttributeError):
|
|
|
pass
|
|
pass
|
|
|
self.intersect_geo_btn.clicked.connect(self.on_geo_intersection_click)
|
|
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):
|
|
def install(self, icon=None, separator=None, **kwargs):
|
|
|
FlatCAMTool.install(self, icon, separator, shortcut='ALT+W', **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:
|
|
for apid in self.target_grb_obj.apertures:
|
|
|
self.promises.append(apid)
|
|
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)
|
|
self.periodic_check(500, reset=True)
|
|
|
|
|
|
|
|
for apid in self.target_grb_obj.apertures:
|
|
for apid in self.target_grb_obj.apertures:
|
|
@@ -455,14 +458,14 @@ class ToolSub(FlatCAMTool):
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
# create the target_options obj
|
|
# create the target_options obj
|
|
|
- self.target_options = {}
|
|
|
|
|
|
|
+ self.target_options = dict()
|
|
|
for opt in self.target_geo_obj.options:
|
|
for opt in self.target_geo_obj.options:
|
|
|
if opt != 'name':
|
|
if opt != 'name':
|
|
|
self.target_options[opt] = deepcopy(self.target_geo_obj.options[opt])
|
|
self.target_options[opt] = deepcopy(self.target_geo_obj.options[opt])
|
|
|
|
|
|
|
|
# crate the new_tools dict structure
|
|
# crate the new_tools dict structure
|
|
|
for tool in self.target_geo_obj.tools:
|
|
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]:
|
|
for key in self.target_geo_obj.tools[tool]:
|
|
|
if key == 'solid_geometry':
|
|
if key == 'solid_geometry':
|
|
|
self.new_tools[tool][key] = []
|
|
self.new_tools[tool][key] = []
|
|
@@ -514,16 +517,14 @@ class ToolSub(FlatCAMTool):
|
|
|
if isinstance(geo_elem, Polygon):
|
|
if isinstance(geo_elem, Polygon):
|
|
|
for ring in self.poly2rings(geo_elem):
|
|
for ring in self.poly2rings(geo_elem):
|
|
|
new_geo = ring.difference(self.sub_union)
|
|
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):
|
|
elif isinstance(geo_elem, MultiPolygon):
|
|
|
for poly in geo_elem:
|
|
for poly in geo_elem:
|
|
|
for ring in self.poly2rings(poly):
|
|
for ring in self.poly2rings(poly):
|
|
|
new_geo = ring.difference(self.sub_union)
|
|
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):
|
|
elif isinstance(geo_elem, LineString):
|
|
|
new_geo = geo_elem.difference(self.sub_union)
|
|
new_geo = geo_elem.difference(self.sub_union)
|
|
|
if new_geo:
|
|
if new_geo:
|
|
@@ -532,9 +533,8 @@ class ToolSub(FlatCAMTool):
|
|
|
elif isinstance(geo_elem, MultiLineString):
|
|
elif isinstance(geo_elem, MultiLineString):
|
|
|
for line_elem in geo_elem:
|
|
for line_elem in geo_elem:
|
|
|
new_geo = line_elem.difference(self.sub_union)
|
|
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:
|
|
except TypeError:
|
|
|
if isinstance(geo, Polygon):
|
|
if isinstance(geo, Polygon):
|
|
|
for ring in self.poly2rings(geo):
|
|
for ring in self.poly2rings(geo):
|
|
@@ -544,15 +544,13 @@ class ToolSub(FlatCAMTool):
|
|
|
new_geometry.append(new_geo)
|
|
new_geometry.append(new_geo)
|
|
|
elif isinstance(geo, LineString):
|
|
elif isinstance(geo, LineString):
|
|
|
new_geo = geo.difference(self.sub_union)
|
|
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):
|
|
elif isinstance(geo, MultiLineString):
|
|
|
for line_elem in geo:
|
|
for line_elem in geo:
|
|
|
new_geo = line_elem.difference(self.sub_union)
|
|
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 new_geometry:
|
|
|
if tool == "single":
|
|
if tool == "single":
|
|
@@ -575,10 +573,11 @@ class ToolSub(FlatCAMTool):
|
|
|
log.debug("Promise fulfilled: %s" % str(tool))
|
|
log.debug("Promise fulfilled: %s" % str(tool))
|
|
|
|
|
|
|
|
def new_geo_object(self, outname):
|
|
def new_geo_object(self, outname):
|
|
|
|
|
+ geo_name = outname
|
|
|
def obj_init(geo_obj, app_obj):
|
|
def obj_init(geo_obj, app_obj):
|
|
|
|
|
|
|
|
geo_obj.options = deepcopy(self.target_options)
|
|
geo_obj.options = deepcopy(self.target_options)
|
|
|
- geo_obj.options['name'] = outname
|
|
|
|
|
|
|
+ geo_obj.options['name'] = geo_name
|
|
|
|
|
|
|
|
if self.target_geo_obj.multigeo:
|
|
if self.target_geo_obj.multigeo:
|
|
|
geo_obj.tools = deepcopy(self.new_tools)
|
|
geo_obj.tools = deepcopy(self.new_tools)
|
|
@@ -645,27 +644,39 @@ class ToolSub(FlatCAMTool):
|
|
|
try:
|
|
try:
|
|
|
if not self.promises:
|
|
if not self.promises:
|
|
|
self.check_thread.stop()
|
|
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
|
|
# reset the type of substraction for next time
|
|
|
self.sub_type = None
|
|
self.sub_type = None
|
|
|
|
|
|
|
|
log.debug("ToolSub --> Periodic check finished.")
|
|
log.debug("ToolSub --> Periodic check finished.")
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
|
+ self.job_finished.emit(False)
|
|
|
log.debug("ToolSub().periodic_check_handler() --> %s" % str(e))
|
|
log.debug("ToolSub().periodic_check_handler() --> %s" % str(e))
|
|
|
traceback.print_exc()
|
|
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):
|
|
def reset_fields(self):
|
|
|
self.target_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
|
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()))
|
|
self.sub_gerber_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|