- in Geometry Editor - fixed multiple plotting for the same selection
This commit is contained in:
committed by
Marius Stanciu
parent
ac145b283b
commit
4f46620e7e
@@ -612,13 +612,247 @@ class Panelize(AppTool):
|
||||
# app_obj.log.debug("Finished creating a unary_union for the panel.")
|
||||
app_obj.proc_container.update_view_text('')
|
||||
|
||||
def job_init_gerber(obj_fin, app_obj):
|
||||
currentx = 0.0
|
||||
currenty = 0.0
|
||||
|
||||
def translate_recursion(geom):
|
||||
if type(geom) == list:
|
||||
geoms = []
|
||||
for local_geom in geom:
|
||||
res_geo = translate_recursion(local_geom)
|
||||
try:
|
||||
geoms += res_geo
|
||||
except TypeError:
|
||||
geoms.append(res_geo)
|
||||
return geoms
|
||||
else:
|
||||
return affinity.translate(geom, xoff=currentx, yoff=currenty)
|
||||
|
||||
obj_fin.solid_geometry = []
|
||||
|
||||
# create the initial structure on which to create the panel
|
||||
if panel_source_obj.kind == 'geometry':
|
||||
obj_fin.multigeo = panel_source_obj.multigeo
|
||||
obj_fin.tools = copied_tools
|
||||
if panel_source_obj.multigeo is True:
|
||||
for tool in panel_source_obj.tools:
|
||||
obj_fin.tools[tool]['solid_geometry'] = []
|
||||
elif panel_source_obj.kind == 'gerber':
|
||||
obj_fin.apertures = copied_apertures
|
||||
for ap in obj_fin.apertures:
|
||||
obj_fin.apertures[ap]['geometry'] = []
|
||||
|
||||
# find the number of polygons in the source solid_geometry
|
||||
geo_len = 0
|
||||
if panel_source_obj.kind == 'geometry':
|
||||
if panel_source_obj.multigeo is True:
|
||||
for tool in panel_source_obj.tools:
|
||||
try:
|
||||
geo_len += len(panel_source_obj.tools[tool]['solid_geometry'])
|
||||
except TypeError:
|
||||
geo_len += 1
|
||||
elif panel_source_obj.kind == 'gerber':
|
||||
for ap in panel_source_obj.apertures:
|
||||
if 'geometry' in panel_source_obj.apertures[ap]:
|
||||
try:
|
||||
geo_len += len(panel_source_obj.apertures[ap]['geometry'])
|
||||
except TypeError:
|
||||
geo_len += 1
|
||||
|
||||
element = 0
|
||||
for row in range(rows):
|
||||
currentx = 0.0
|
||||
|
||||
for col in range(columns):
|
||||
element += 1
|
||||
old_disp_number = 0
|
||||
|
||||
# Will panelize a Geometry Object
|
||||
if panel_source_obj.kind == 'geometry':
|
||||
if panel_source_obj.multigeo is True:
|
||||
for tool in panel_source_obj.tools:
|
||||
# graceful abort requested by the user
|
||||
if app_obj.abort_flag:
|
||||
raise grace
|
||||
|
||||
# calculate the number of polygons
|
||||
try:
|
||||
geo_len = len(panel_source_obj.tools[tool]['solid_geometry'])
|
||||
except TypeError:
|
||||
geo_len = 1
|
||||
|
||||
# panelization
|
||||
pol_nr = 0
|
||||
for geo_el in panel_source_obj.tools[tool]['solid_geometry']:
|
||||
trans_geo = translate_recursion(geo_el)
|
||||
obj_fin.tools[tool]['solid_geometry'].append(trans_geo)
|
||||
|
||||
# update progress
|
||||
pol_nr += 1
|
||||
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
|
||||
if old_disp_number < disp_number <= 100:
|
||||
app_obj.proc_container.update_view_text(
|
||||
' %s: %d %d%%' % (_("Copy"), int(element), disp_number))
|
||||
old_disp_number = disp_number
|
||||
else:
|
||||
# graceful abort requested by the user
|
||||
if app_obj.abort_flag:
|
||||
raise grace
|
||||
|
||||
# calculate the number of polygons
|
||||
try:
|
||||
geo_len = len(panel_source_obj.solid_geometry)
|
||||
except TypeError:
|
||||
geo_len = 1
|
||||
|
||||
# panelization
|
||||
pol_nr = 0
|
||||
try:
|
||||
for geo_el in panel_source_obj.solid_geometry:
|
||||
if app_obj.abort_flag:
|
||||
# graceful abort requested by the user
|
||||
raise grace
|
||||
|
||||
trans_geo = translate_recursion(geo_el)
|
||||
obj_fin.solid_geometry.append(trans_geo)
|
||||
|
||||
# update progress
|
||||
pol_nr += 1
|
||||
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
|
||||
if old_disp_number < disp_number <= 100:
|
||||
app_obj.proc_container.update_view_text(
|
||||
' %s: %d %d%%' % (_("Copy"), int(element), disp_number))
|
||||
old_disp_number = disp_number
|
||||
|
||||
except TypeError:
|
||||
trans_geo = translate_recursion(panel_source_obj.solid_geometry)
|
||||
obj_fin.solid_geometry.append(trans_geo)
|
||||
# Will panelize a Gerber Object
|
||||
else:
|
||||
# graceful abort requested by the user
|
||||
if self.app.abort_flag:
|
||||
raise grace
|
||||
|
||||
# panelization solid_geometry
|
||||
try:
|
||||
for geo_el in panel_source_obj.solid_geometry:
|
||||
# graceful abort requested by the user
|
||||
if app_obj.abort_flag:
|
||||
raise grace
|
||||
|
||||
trans_geo = translate_recursion(geo_el)
|
||||
obj_fin.solid_geometry.append(trans_geo)
|
||||
except TypeError:
|
||||
trans_geo = translate_recursion(panel_source_obj.solid_geometry)
|
||||
obj_fin.solid_geometry.append(trans_geo)
|
||||
|
||||
for apid in panel_source_obj.apertures:
|
||||
# graceful abort requested by the user
|
||||
if app_obj.abort_flag:
|
||||
raise grace
|
||||
|
||||
if 'geometry' in panel_source_obj.apertures[apid]:
|
||||
# calculate the number of polygons
|
||||
try:
|
||||
geo_len = len(panel_source_obj.apertures[apid]['geometry'])
|
||||
except TypeError:
|
||||
geo_len = 1
|
||||
|
||||
# panelization -> apertures
|
||||
pol_nr = 0
|
||||
for el in panel_source_obj.apertures[apid]['geometry']:
|
||||
if app_obj.abort_flag:
|
||||
# graceful abort requested by the user
|
||||
raise grace
|
||||
|
||||
new_el = {}
|
||||
if 'solid' in el:
|
||||
geo_aper = translate_recursion(el['solid'])
|
||||
new_el['solid'] = geo_aper
|
||||
if 'clear' in el:
|
||||
geo_aper = translate_recursion(el['clear'])
|
||||
new_el['clear'] = geo_aper
|
||||
if 'follow' in el:
|
||||
geo_aper = translate_recursion(el['follow'])
|
||||
new_el['follow'] = geo_aper
|
||||
obj_fin.apertures[apid]['geometry'].append(deepcopy(new_el))
|
||||
|
||||
# update progress
|
||||
pol_nr += 1
|
||||
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
|
||||
if old_disp_number < disp_number <= 100:
|
||||
app_obj.proc_container.update_view_text(
|
||||
' %s: %d %d%%' % (_("Copy"), int(element), disp_number))
|
||||
old_disp_number = disp_number
|
||||
|
||||
currentx += lenghtx
|
||||
currenty += lenghty
|
||||
|
||||
# Lines optimization
|
||||
if panel_source_obj.kind == 'geometry' and panel_source_obj.multigeo is True:
|
||||
# I'm going to do this only here as a fix for panelizing cutouts
|
||||
# I'm going to separate linestrings out of the solid geometry from other
|
||||
# possible type of elements and apply unary_union on them to fuse them
|
||||
|
||||
if to_optimize is True:
|
||||
app_obj.inform.emit('%s' % _("Optimizing the overlapping paths."))
|
||||
|
||||
for tool in obj_fin.tools:
|
||||
lines = []
|
||||
other_geo = []
|
||||
for geo in obj_fin.tools[tool]['solid_geometry']:
|
||||
if isinstance(geo, LineString):
|
||||
lines.append(geo)
|
||||
elif isinstance(geo, MultiLineString):
|
||||
for line in geo:
|
||||
lines.append(line)
|
||||
else:
|
||||
other_geo.append(geo)
|
||||
|
||||
if to_optimize is True:
|
||||
for idx, line in enumerate(lines):
|
||||
for idx_s in range(idx+1, len(lines)):
|
||||
line_mod = lines[idx_s]
|
||||
dist = line.distance(line_mod)
|
||||
if dist < 1e-8:
|
||||
print("Disjoint %d: %d -> %s" % (idx, idx_s, str(dist)))
|
||||
print("Distance %f" % dist)
|
||||
res = snap(line_mod, line, tolerance=1e-7)
|
||||
if res and not res.is_empty:
|
||||
lines[idx_s] = res
|
||||
|
||||
fused_lines = linemerge(lines)
|
||||
fused_lines = [unary_union(fused_lines)]
|
||||
|
||||
obj_fin.tools[tool]['solid_geometry'] = fused_lines + other_geo
|
||||
|
||||
if to_optimize is True:
|
||||
app_obj.inform.emit('%s' % _("Optimization complete."))
|
||||
|
||||
app_obj.inform.emit('%s' % _("Generating panel ... Adding the source code."))
|
||||
if panel_type == 'gerber':
|
||||
obj_fin.source_file = self.app.f_handlers.export_gerber(obj_name=self.outname, filename=None,
|
||||
local_use=obj_fin, use_thread=False)
|
||||
if panel_type == 'geometry':
|
||||
obj_fin.source_file = self.app.f_handlers.export_dxf(obj_name=self.outname, filename=None,
|
||||
local_use=obj_fin, use_thread=False)
|
||||
|
||||
# obj_fin.solid_geometry = unary_union(obj_fin.solid_geometry)
|
||||
# app_obj.log.debug("Finished creating a unary_union for the panel.")
|
||||
app_obj.proc_container.update_view_text('')
|
||||
|
||||
self.app.inform.emit('%s: %d' % (_("Generating panel... Spawning copies"), (int(rows * columns))))
|
||||
if panel_source_obj.kind == 'excellon':
|
||||
self.app.app_obj.new_object(
|
||||
"excellon", self.outname, job_init_excellon, plot=True, autoselected=True)
|
||||
else:
|
||||
self.app.app_obj.new_object(
|
||||
panel_type, self.outname, job_init_geometry, plot=True, autoselected=True)
|
||||
if panel_type == 'geometry':
|
||||
self.app.app_obj.new_object(
|
||||
'geometry', self.outname, job_init_geometry, plot=True, autoselected=True)
|
||||
if panel_type == 'gerber':
|
||||
self.app.app_obj.new_object(
|
||||
'geometry', self.outname, job_init_gerber, plot=True, autoselected=True)
|
||||
|
||||
if self.constrain_flag is False:
|
||||
self.app.inform.emit('[success] %s' % _("Done."))
|
||||
|
||||
Reference in New Issue
Block a user