- updated the UI in Geometry UI

- optimized the order of the defaults storage declaration and the update of the Preferences GUI from the defaults
This commit is contained in:
Marius Stanciu
2019-11-05 01:01:52 +02:00
committed by Marius
parent cd7620c801
commit 849bcded4c
12 changed files with 761 additions and 758 deletions

View File

@@ -3306,104 +3306,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
optionChanged = QtCore.pyqtSignal(str)
ui_type = GeometryObjectUI
def merge(self, geo_list, geo_final, multigeo=None):
"""
Merges the geometry of objects in grb_list into
the geometry of geo_final.
:param geo_list: List of FlatCAMGerber Objects to join.
:param geo_final: Destination FlatCAMGerber object.
:return: None
"""
if geo_final.solid_geometry is None:
geo_final.solid_geometry = []
if type(geo_final.solid_geometry) is not list:
geo_final.solid_geometry = [geo_final.solid_geometry]
for geo in geo_list:
for option in geo.options:
if option is not 'name':
try:
geo_final.options[option] = geo.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 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(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)
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:
max_uid += 1
geo_final.tools[max_uid] = deepcopy(geo.tools[tool_uid])
@staticmethod
def get_pts(o):
"""
Returns a list of all points in the object, where
the object can be a MultiPolygon, Polygon, Not a polygon, or a list
of such. Search is done recursively.
:param: geometric object
:return: List of points
:rtype: list
"""
pts = []
# Iterable: descend into each item.
try:
for subo in o:
pts += FlatCAMGeometry.get_pts(subo)
# Non-iterable
except TypeError:
if o is not None:
if type(o) == MultiPolygon:
for poly in o:
pts += FlatCAMGeometry.get_pts(poly)
# ## Descend into .exerior and .interiors
elif type(o) == Polygon:
pts += FlatCAMGeometry.get_pts(o.exterior)
for i in o.interiors:
pts += FlatCAMGeometry.get_pts(i)
elif type(o) == MultiLineString:
for line in o:
pts += FlatCAMGeometry.get_pts(line)
# ## Has .coords: list them.
else:
pts += list(o.coords)
else:
return
return pts
def __init__(self, name):
FlatCAMObj.__init__(self, name)
Geometry.__init__(self, geo_steps_per_circle=int(self.app.defaults["geometry_circle_steps"]))
@@ -3477,7 +3379,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# flag to store if the geometry is part of a special group of geometries that can't be processed by the default
# engine of FlatCAM. Most likely are generated by some of tools and are special cases of geometries.
self. special_group = None
self.special_group = None
self.old_pp_state = self.app.defaults["geometry_multidepth"]
self.old_toolchangeg_state = self.app.defaults["geometry_toolchange"]
@@ -3506,9 +3408,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
tool_idx += 1
row_no = tool_idx - 1
id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.geo_tools_table.setItem(row_no, 0, id) # Tool name/id
tool_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
tool_id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.geo_tools_table.setItem(row_no, 0, tool_id) # Tool name/id
# Make sure that the tool diameter when in MM is with no more than 2 decimals.
# There are no tool bits in MM with more than 3 decimals diameter.
@@ -3754,7 +3656,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# again float type; dict's don't like having keys changed when iterated through therefore the need for the
# following convoluted way of changing the keys from string to float type
temp_tools = {}
new_key = 0.0
for tooluid_key in self.tools:
val = deepcopy(self.tools[tooluid_key])
new_key = deepcopy(int(tooluid_key))
@@ -3775,6 +3676,8 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
return
self.ui.geo_tools_table.setupContextMenu()
self.ui.geo_tools_table.addContextMenu(
_("Add from Tool DB"), self.on_tool_add_from_db, icon=QtGui.QIcon("share/plus16.png"))
self.ui.geo_tools_table.addContextMenu(
_("Copy"), self.on_tool_copy, icon=QtGui.QIcon("share/copy16.png"))
self.ui.geo_tools_table.addContextMenu(
@@ -4076,6 +3979,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
if self.ui.geo_tools_table.rowCount() != 0:
self.ui.geo_param_frame.setDisabled(False)
def on_tool_add_from_db(self):
pass
def on_tool_copy(self, all=None):
self.ui_disconnect()
@@ -4670,16 +4576,16 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# test to see if we have tools available in the tool table
if self.ui.geo_tools_table.selectedItems():
for x in self.ui.geo_tools_table.selectedItems():
try:
tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text())
except ValueError:
# try to convert comma to decimal point. if it's still not working error message and return
try:
tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text().replace(',', '.'))
except ValueError:
self.app.inform.emit('[ERROR_NOTCL] %s' %
_("Wrong value format entered, use a number."))
return
# try:
# tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text())
# except ValueError:
# # try to convert comma to decimal point. if it's still not working error message and return
# try:
# tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text().replace(',', '.'))
# except ValueError:
# self.app.inform.emit('[ERROR_NOTCL] %s' %
# _("Wrong value format entered, use a number."))
# return
tooluid = int(self.ui.geo_tools_table.item(x.row(), 5).text())
for tooluid_key, tooluid_value in self.tools.items():
@@ -5630,6 +5536,105 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.ui.plot_cb.setChecked(True)
self.ui_connect()
def merge(self, geo_list, geo_final, multigeo=None):
"""
Merges the geometry of objects in grb_list into
the geometry of geo_final.
:param geo_list: List of FlatCAMGerber Objects to join.
:param geo_final: Destination FlatCAMGerber object.
:param multigeo: if the merged geometry objects are of type MultiGeo
:return: None
"""
if geo_final.solid_geometry is None:
geo_final.solid_geometry = []
if type(geo_final.solid_geometry) is not list:
geo_final.solid_geometry = [geo_final.solid_geometry]
for geo in geo_list:
for option in geo.options:
if option is not 'name':
try:
geo_final.options[option] = geo.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 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(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)
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:
max_uid += 1
geo_final.tools[max_uid] = deepcopy(geo.tools[tool_uid])
@staticmethod
def get_pts(o):
"""
Returns a list of all points in the object, where
the object can be a MultiPolygon, Polygon, Not a polygon, or a list
of such. Search is done recursively.
:param: geometric object
:return: List of points
:rtype: list
"""
pts = []
# Iterable: descend into each item.
try:
for subo in o:
pts += FlatCAMGeometry.get_pts(subo)
# Non-iterable
except TypeError:
if o is not None:
if type(o) == MultiPolygon:
for poly in o:
pts += FlatCAMGeometry.get_pts(poly)
# ## Descend into .exerior and .interiors
elif type(o) == Polygon:
pts += FlatCAMGeometry.get_pts(o.exterior)
for i in o.interiors:
pts += FlatCAMGeometry.get_pts(i)
elif type(o) == MultiLineString:
for line in o:
pts += FlatCAMGeometry.get_pts(line)
# ## Has .coords: list them.
else:
pts += list(o.coords)
else:
return
return pts
class FlatCAMCNCjob(FlatCAMObj, CNCjob):
"""