- restored Cutout freeform to previous state

This commit is contained in:
Marius Stanciu 2020-08-29 19:37:10 +03:00 committed by Marius
parent f73f6fb5da
commit 62f06f6472
1 changed files with 212 additions and 260 deletions

View File

@ -556,6 +556,7 @@ class CutOut(AppTool):
return
margin = float(self.ui.margin.get_value())
gapsize = float(self.ui.gapsize.get_value())
try:
gaps = self.ui.gaps.get_value()
@ -576,7 +577,30 @@ class CutOut(AppTool):
"and after that perform Cutout."))
return
def cutout_handler(geom, gapsize):
convex_box = self.ui.convex_box_cb.get_value()
gapsize = gapsize / 2 + (dia / 2)
def geo_init(geo_obj, app_obj):
solid_geo = []
gaps_solid_geo = None
if cutout_obj.kind == 'gerber':
if isinstance(cutout_obj.solid_geometry, list):
cutout_obj.solid_geometry = MultiPolygon(cutout_obj.solid_geometry)
try:
if convex_box:
object_geo = cutout_obj.solid_geometry.convex_hull
else:
object_geo = cutout_obj.solid_geometry
except Exception as err:
log.debug("CutOut.on_freeform_cutout().geo_init() --> %s" % str(err))
object_geo = cutout_obj.solid_geometry
else:
object_geo = cutout_obj.solid_geometry
def cutout_handler(geom):
proc_geometry = []
rest_geometry = []
r_temp_geo = []
@ -678,38 +702,6 @@ class CutOut(AppTool):
return proc_geometry, rest_geometry
with self.app.proc_container.new("Generating Cutout ..."):
outname = cutout_obj.options["name"] + "_cutout"
self.app.collection.promise(outname)
outname_exc = cutout_obj.options["name"] + "_mouse_bites"
if self.ui.gaptype_radio.get_value() == 'mb':
self.app.collection.promise(outname_exc)
def job_thread(app_obj):
solid_geo = []
gaps_solid_geo = []
mouse_bites_geo = []
convex_box = self.ui.convex_box_cb.get_value()
gapsize = self.ui.gapsize.get_value()
gapsize = gapsize / 2 + (dia / 2)
if cutout_obj.kind == 'gerber':
if isinstance(cutout_obj.solid_geometry, list):
cutout_obj.solid_geometry = MultiPolygon(cutout_obj.solid_geometry)
try:
if convex_box:
object_geo = cutout_obj.solid_geometry.convex_hull
else:
object_geo = cutout_obj.solid_geometry
except Exception as err:
log.debug("CutOut.on_freeform_cutout().geo_init() --> %s" % str(err))
object_geo = cutout_obj.solid_geometry
else:
object_geo = cutout_obj.solid_geometry
if kind == 'single':
object_geo = unary_union(object_geo)
@ -727,11 +719,9 @@ class CutOut(AppTool):
else:
geo = object_geo
solid_geo, rest_geo = cutout_handler(geom=geo, gapsize=gapsize)
solid_geo, rest_geo = cutout_handler(geom=geo)
if self.ui.gaptype_radio.get_value() == 'bt' and self.ui.thin_depth_entry.get_value() > 0:
gaps_solid_geo = rest_geo
if self.ui.gaptype_radio.get_value() == 'mb':
mouse_bites_geo = rest_geo
else:
try:
__ = iter(object_geo)
@ -746,23 +736,16 @@ class CutOut(AppTool):
geom_struct_buff = geom_struct.buffer(-margin + abs(dia / 2))
geom_struct = geom_struct_buff.interiors
c_geo, r_geo = cutout_handler(geom=geom_struct, gapsize=gapsize)
c_geo, r_geo = cutout_handler(geom=geom_struct)
solid_geo += c_geo
if self.ui.gaptype_radio.get_value() == 'bt' and self.ui.thin_depth_entry.get_value() > 0:
gaps_solid_geo += r_geo
if self.ui.gaptype_radio.get_value() == 'mb':
mouse_bites_geo += r_geo
if not solid_geo:
self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed."))
app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Failed."))
return "fail"
solid_geo = linemerge(solid_geo)
# list of Shapely Points to mark the drill points centers
holes = []
print(mouse_bites_geo)
def geo_init(geo_obj, app_object):
geo_obj.solid_geometry = deepcopy(solid_geo)
xmin, ymin, xmax, ymax = CutOut.recursive_bounds(geo_obj.solid_geometry)
@ -788,7 +771,7 @@ class CutOut(AppTool):
geo_obj.tools[1]['data']['multidepth'] = self.ui.mpass_cb.get_value()
geo_obj.tools[1]['data']['depthperpass'] = self.ui.maxdepth_entry.get_value()
if gaps_solid_geo:
if gaps_solid_geo is not None:
geo_obj.tools.update({
9999: self.cut_tool_dict
})
@ -802,48 +785,17 @@ class CutOut(AppTool):
# plot this tool in a different color
geo_obj.tools[9999]['data']['override_color'] = "#29a3a3fa"
def excellon_init(exc_obj, app_o):
if not holes:
return 'fail'
mb_dia = self.ui.mb_dia_entry.get_value()
outname = cutout_obj.options["name"] + "_cutout"
ret = self.app.app_obj.new_object('geometry', outname, geo_init)
tools = {}
tools[1] = {}
tools[1]["tooldia"] = mb_dia
tools[1]['drills'] = holes
tools[1]['solid_geometry'] = []
exc_obj.tools = tools
exc_obj.create_geometry()
exc_obj.source_file = app_o.export_excellon(obj_name=exc_obj.options['name'], local_use=exc_obj,
filename=None, use_thread=False)
# calculate the bounds
xmin, ymin, xmax, ymax = CutOut.recursive_bounds(exc_obj.solid_geometry)
exc_obj.options['xmin'] = xmin
exc_obj.options['ymin'] = ymin
exc_obj.options['xmax'] = xmax
exc_obj.options['ymax'] = ymax
try:
ret = app_obj.app_obj.new_object('geometry', outname, geo_init)
if ret == 'fail':
app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Failed."))
return
if self.ui.gaptype_radio.get_value() == 'mb':
ret = app_obj.app_obj.new_object('excellon', outname_exc, excellon_init)
if ret == 'fail':
app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Mouse bites failed."))
self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed."))
return
# cutout_obj.plot(plot_tool=1)
app_obj.inform.emit('[success] %s' % _("Any form CutOut operation finished."))
self.app.inform.emit('[success] %s' % _("Any form CutOut operation finished."))
# self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
app_obj.should_we_save = True
except Exception as ee:
log.debug(str(ee))
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
self.app.should_we_save = True
def on_rectangular_cutout(self):
log.debug("Cutout.on_rectangular_cutout() was launched ...")