- working on fixing a bug in FlatCAMGeometry.merge()

This commit is contained in:
Marius Stanciu 2020-02-12 16:43:13 +02:00
parent 67a2350a59
commit c2373da17a
4 changed files with 44 additions and 28 deletions

View File

@ -5689,11 +5689,12 @@ class App(QtCore.QObject):
if True in geo_type_set:
def initialize(geo_obj, app):
FlatCAMGeometry.merge(self, geo_list=objs, geo_final=geo_obj, multigeo=True)
app.inform.emit('[success] %s.' % _("Multigeo. Geometry merging finished"))
app.inform.emit('[success] %s.' % _("Geometry merging finished"))
# rename all the ['name] key in obj.tools[tooluid]['data'] to the obj_name_multi
for v in obj.tools.values():
for v in geo_obj.tools.values():
v['data']['name'] = obj_name_multi
self.new_object("geometry", obj_name_multi, initialize)
else:
def initialize(geo_obj, app):
@ -5701,7 +5702,7 @@ class App(QtCore.QObject):
app.inform.emit('[success] %s.' % _("Geometry merging finished"))
# rename all the ['name] key in obj.tools[tooluid]['data'] to the obj_name_multi
for v in obj.tools.values():
for v in geo_obj.tools.values():
v['data']['name'] = obj_name_single
self.new_object("geometry", obj_name_single, initialize)

View File

@ -6268,53 +6268,58 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
"""
if geo_final.solid_geometry is None:
geo_final.solid_geometry = []
geo_final.solid_geometry = list()
if type(geo_final.solid_geometry) is not list:
try:
__ = iter(geo_final.solid_geometry)
except TypeError:
geo_final.solid_geometry = [geo_final.solid_geometry]
for geo in geo_list:
for option in geo.options:
new_solid_geometry = list()
new_options = dict()
new_tools = dict()
for geo_obj in geo_list:
for option in geo_obj.options:
if option is not 'name':
try:
geo_final.options[option] = deepcopy(geo.options[option])
new_options[option] = geo_obj.options[option]
except Exception as e:
log.warning("Failed to copy option %s. Error: %s" % (str(option), str(e)))
# Expand lists
if type(geo) is list:
FlatCAMGeometry.merge(self, geo_list=geo, geo_final=geo_final)
if type(geo_obj) is list:
FlatCAMGeometry.merge(self, geo_list=geo_obj, geo_final=geo_final)
# If not list, just append
else:
# merge solid_geometry, useful for singletool geometry, for multitool each is empty
if multigeo is None or multigeo is False:
geo_final.multigeo = False
try:
geo_final.solid_geometry.append(deepcopy(geo.solid_geometry))
except Exception as e:
log.debug("FlatCAMGeometry.merge() --> %s" % str(e))
else:
geo_final.multigeo = True
# if multigeo the solid_geometry is empty in the object attributes because it now lives in the
# tools object attribute, as a key value
geo_final.solid_geometry = []
# find the tool_uid maximum value in the geo_final
geo_final_uid_list = []
for key in geo_final.tools:
geo_final_uid_list.append(int(key))
try:
max_uid = max(geo_final_uid_list, key=int)
new_solid_geometry.append(geo_obj.solid_geometry)
except Exception as e:
log.debug("FlatCAMGeometry.merge() --> %s" % str(e))
# find the tool_uid maximum value in the geo_final
try:
max_uid = max([int(i) for i in new_tools.keys()])
except ValueError:
max_uid = 0
# add and merge tools. If what we try to merge as Geometry is Excellon's and/or Gerber's then don't try
# to merge the obj.tools as it is likely there is none to merge.
if not isinstance(geo, FlatCAMGerber) and not isinstance(geo, FlatCAMExcellon):
for tool_uid in geo.tools:
if not isinstance(geo_obj, FlatCAMGerber) and not isinstance(geo_obj, FlatCAMExcellon):
for tool_uid in geo_obj.tools:
max_uid += 1
geo_final.tools[max_uid] = deepcopy(geo.tools[tool_uid])
new_tools[max_uid] = geo_obj.tools[tool_uid]
geo_final.options.update(deepcopy(new_options))
geo_final.solid_geometry = deepcopy(list(geo_final.flatten_list(new_solid_geometry)))
geo_final.tools = deepcopy(new_tools)
for td in geo_final.tools:
print(td, geo_final.tools[td])
@staticmethod
def get_pts(o):

View File

@ -9,6 +9,12 @@ CAD program, and create G-Code for Isolation routing.
=================================================
12.02.2020
- working on fixing a bug in FlatCAMGeometry.merge()
11.02.2020
- working on Tool Punch; finished the geometry update with the clear geometry for the case of Excellon method

View File

@ -425,7 +425,11 @@ class Properties(FlatCAMTool):
tools, str(tool), expanded=True, color=QtGui.QColor("#000000"), font=font)
for k, v in value.items():
if k == 'solid_geometry':
printed_value = _('Present') if v else _('None')
# printed_value = _('Present') if v else _('None')
try:
printed_value = str(len(v))
except (TypeError, AttributeError):
printed_value = '1'
self.treeWidget.addChild(geo_tool, [str(k), printed_value], True)
elif k == 'data':
tool_data = self.treeWidget.addParent(