- finished the new Substract Tool
This commit is contained in:
@@ -16,6 +16,7 @@ CAD program, and create G-Code for Isolation routing.
|
|||||||
- renamed SilkScreen Tool to Substract Tool and move it's menu location in Edit -> Conversion
|
- renamed SilkScreen Tool to Substract Tool and move it's menu location in Edit -> Conversion
|
||||||
- started to modify the Substract Tool to work on Geometry objects too
|
- started to modify the Substract Tool to work on Geometry objects too
|
||||||
- progress in the new Substract Tool for Geometry Objects
|
- progress in the new Substract Tool for Geometry Objects
|
||||||
|
- finished the new Substract Tool
|
||||||
|
|
||||||
29.04.2019
|
29.04.2019
|
||||||
|
|
||||||
|
|||||||
@@ -153,9 +153,6 @@ class ToolSub(FlatCAMTool):
|
|||||||
|
|
||||||
self.sub_union = None
|
self.sub_union = None
|
||||||
|
|
||||||
# object to hold a flattened geometry
|
|
||||||
self.flat_geometry = []
|
|
||||||
|
|
||||||
self.sub_grb_obj = None
|
self.sub_grb_obj = None
|
||||||
self.sub_grb_obj_name = None
|
self.sub_grb_obj_name = None
|
||||||
self.target_grb_obj = None
|
self.target_grb_obj = None
|
||||||
@@ -169,6 +166,9 @@ class ToolSub(FlatCAMTool):
|
|||||||
# signal which type of substraction to do: "geo" or "gerber"
|
# signal which type of substraction to do: "geo" or "gerber"
|
||||||
self.sub_type = None
|
self.sub_type = None
|
||||||
|
|
||||||
|
# store here the options from target_obj
|
||||||
|
self.target_options = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.intersect_btn.clicked.disconnect(self.on_grb_intersection_click)
|
self.intersect_btn.clicked.disconnect(self.on_grb_intersection_click)
|
||||||
except:
|
except:
|
||||||
@@ -207,6 +207,7 @@ class ToolSub(FlatCAMTool):
|
|||||||
self.new_apertures.clear()
|
self.new_apertures.clear()
|
||||||
self.new_tools.clear()
|
self.new_tools.clear()
|
||||||
self.new_solid_geometry = []
|
self.new_solid_geometry = []
|
||||||
|
self.target_options.clear()
|
||||||
|
|
||||||
self.app.ui.notebook.setTabText(2, _("Sub Tool"))
|
self.app.ui.notebook.setTabText(2, _("Sub Tool"))
|
||||||
|
|
||||||
@@ -345,6 +346,7 @@ class ToolSub(FlatCAMTool):
|
|||||||
def on_geo_intersection_click(self):
|
def on_geo_intersection_click(self):
|
||||||
# reset previous values
|
# reset previous values
|
||||||
self.new_tools.clear()
|
self.new_tools.clear()
|
||||||
|
self.target_options.clear()
|
||||||
self.new_solid_geometry = []
|
self.new_solid_geometry = []
|
||||||
self.sub_union = []
|
self.sub_union = []
|
||||||
|
|
||||||
@@ -378,17 +380,26 @@ class ToolSub(FlatCAMTool):
|
|||||||
self.app.inform.emit(_("[ERROR_NOTCL] Currently, the Substractor geometry cannot be of type Multigeo."))
|
self.app.inform.emit(_("[ERROR_NOTCL] Currently, the Substractor geometry cannot be of type Multigeo."))
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.target_geo_obj.multigeo:
|
# create the target_options obj
|
||||||
# crate the new_tools dict structure
|
self.target_options = {}
|
||||||
for tool in self.target_geo_obj.tools:
|
for opt in self.target_geo_obj.options:
|
||||||
self.new_tools[tool] = {}
|
if opt != 'name':
|
||||||
self.new_tools[tool]['solid_geometry'] = []
|
self.target_options[opt] = deepcopy(self.target_geo_obj.options[opt])
|
||||||
|
|
||||||
# add the promises
|
# crate the new_tools dict structure
|
||||||
|
for tool in self.target_geo_obj.tools:
|
||||||
|
self.new_tools[tool] = {}
|
||||||
|
for key in self.target_geo_obj.tools[tool]:
|
||||||
|
if key == 'solid_geometry':
|
||||||
|
self.new_tools[tool][key] = []
|
||||||
|
else:
|
||||||
|
self.new_tools[tool][key] = deepcopy(self.target_geo_obj.tools[tool][key])
|
||||||
|
|
||||||
|
# add the promises
|
||||||
|
if self.target_geo_obj.multigeo:
|
||||||
for tool in self.target_geo_obj.tools:
|
for tool in self.target_geo_obj.tools:
|
||||||
self.promises.append(tool)
|
self.promises.append(tool)
|
||||||
else:
|
else:
|
||||||
# add the promise
|
|
||||||
self.promises.append("single")
|
self.promises.append("single")
|
||||||
|
|
||||||
self.sub_union = cascaded_union(self.sub_geo_obj.solid_geometry)
|
self.sub_union = cascaded_union(self.sub_geo_obj.solid_geometry)
|
||||||
@@ -403,7 +414,6 @@ class ToolSub(FlatCAMTool):
|
|||||||
'params': [tool, geo]})
|
'params': [tool, geo]})
|
||||||
else:
|
else:
|
||||||
geo = self.target_geo_obj.solid_geometry
|
geo = self.target_geo_obj.solid_geometry
|
||||||
|
|
||||||
self.app.worker_task.emit({'fcn': self.toolgeo_intersection,
|
self.app.worker_task.emit({'fcn': self.toolgeo_intersection,
|
||||||
'params': ["single", geo]})
|
'params': ["single", geo]})
|
||||||
|
|
||||||
@@ -417,19 +427,11 @@ class ToolSub(FlatCAMTool):
|
|||||||
text = _("Parsing tool %s geometry ...") % str(tool)
|
text = _("Parsing tool %s geometry ...") % str(tool)
|
||||||
|
|
||||||
with self.app.proc_container.new(text):
|
with self.app.proc_container.new(text):
|
||||||
for t_geo in geo:
|
new_geo = (cascaded_union(geo)).difference(self.sub_union)
|
||||||
if t_geo.intersects(self.sub_union):
|
if new_geo:
|
||||||
new_geo = t_geo.difference(self.sub_union)
|
if not new_geo.is_empty:
|
||||||
new_geo = new_geo.buffer(0)
|
new_geometry.append(new_geo)
|
||||||
if new_geo:
|
|
||||||
if not new_geo.is_empty:
|
|
||||||
new_geometry.append(new_geo)
|
|
||||||
else:
|
|
||||||
new_geometry.append(t_geo)
|
|
||||||
else:
|
|
||||||
new_geometry.append(t_geo)
|
|
||||||
else:
|
|
||||||
new_geometry.append(t_geo)
|
|
||||||
if new_geometry:
|
if new_geometry:
|
||||||
if tool == "single":
|
if tool == "single":
|
||||||
while not self.new_solid_geometry:
|
while not self.new_solid_geometry:
|
||||||
@@ -453,29 +455,22 @@ class ToolSub(FlatCAMTool):
|
|||||||
def new_geo_object(self, outname):
|
def new_geo_object(self, outname):
|
||||||
def obj_init(geo_obj, app_obj):
|
def obj_init(geo_obj, app_obj):
|
||||||
|
|
||||||
geo_obj.solid_geometry = deepcopy(self.new_solid_geometry)
|
geo_obj.options = deepcopy(self.target_options)
|
||||||
try:
|
geo_obj.options['name'] = outname
|
||||||
geo_obj.tools = deepcopy(self.target_geo_obj.tools)
|
|
||||||
for tool in geo_obj.tools:
|
|
||||||
geo_obj.tools[tool]['solid_geometry'] = deepcopy(self.new_solid_geometry)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
poly_buff = []
|
if self.target_geo_obj.multigeo:
|
||||||
for poly in geo_obj.solid_geometry:
|
geo_obj.tools = deepcopy(self.new_tools)
|
||||||
poly_buff.append(poly)
|
# this turn on the FlatCAMCNCJob plot for multiple tools
|
||||||
|
geo_obj.multigeo = True
|
||||||
work_poly_buff = cascaded_union(poly_buff)
|
geo_obj.multitool = True
|
||||||
try:
|
else:
|
||||||
poly_buff = work_poly_buff.buffer(0.0000001)
|
geo_obj.solid_geometry = deepcopy(self.new_solid_geometry)
|
||||||
except ValueError:
|
try:
|
||||||
pass
|
geo_obj.tools = deepcopy(self.new_tools)
|
||||||
try:
|
for tool in geo_obj.tools:
|
||||||
poly_buff = poly_buff.buffer(-0.0000001)
|
geo_obj.tools[tool]['solid_geometry'] = deepcopy(self.new_solid_geometry)
|
||||||
except ValueError:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
geo_obj.solid_geometry = deepcopy(poly_buff)
|
|
||||||
|
|
||||||
with self.app.proc_container.new(_("Generating new object ...")):
|
with self.app.proc_container.new(_("Generating new object ...")):
|
||||||
ret = self.app.new_object('geometry', outname, obj_init, autoselected=False)
|
ret = self.app.new_object('geometry', outname, obj_init, autoselected=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user