- the application now uses only the default values from the app.options dict, the app.defaults dict holds the definitive default values

- fixed some outstanding issues from the PyQt6 port
- PEP8 fixes
- minor fixes
- updated the saving of Preferences to update the self.options too: the `Apply` action will update the self.options but the `Save` action will save the updated preferences to the file on disk
This commit is contained in:
Marius Stanciu
2022-02-18 23:06:58 +02:00
committed by Marius
parent 14d9ea5470
commit 65d8dcc0b2
92 changed files with 1881 additions and 1882 deletions

View File

@@ -47,7 +47,7 @@ class GeometryObject(FlatCAMObj, Geometry):
def __init__(self, name):
self.decimals = self.app.decimals
self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
self.circle_steps = int(self.app.options["geometry_circle_steps"])
FlatCAMObj.__init__(self, name)
Geometry.__init__(self, geo_steps_per_circle=self.circle_steps)
@@ -89,17 +89,17 @@ class GeometryObject(FlatCAMObj, Geometry):
})
if "tools_mill_tooldia" not in self.obj_options:
if type(self.app.defaults["tools_mill_tooldia"]) == float:
self.obj_options["tools_mill_tooldia"] = self.app.defaults["tools_mill_tooldia"]
if type(self.app.options["tools_mill_tooldia"]) == float:
self.obj_options["tools_mill_tooldia"] = self.app.options["tools_mill_tooldia"]
else:
try:
tools_string = self.app.defaults["tools_mill_tooldia"].split(",")
tools_string = self.app.options["tools_mill_tooldia"].split(",")
tools_diameters = [eval(a) for a in tools_string if a != '']
self.obj_options["tools_mill_tooldia"] = tools_diameters[0] if tools_diameters else 0.0
except Exception as e:
self.app.log.error("FlatCAMObj.GeometryObject.init() --> %s" % str(e))
self.obj_options["tools_mill_startz"] = self.app.defaults["tools_mill_startz"]
self.obj_options["tools_mill_startz"] = self.app.options["tools_mill_startz"]
# this will hold the tool unique ID that is useful when having multiple tools with same diameter
self.tooluid = 0
@@ -136,24 +136,24 @@ class GeometryObject(FlatCAMObj, Geometry):
# engine of FlatCAM. Most likely are generated by some tools and are special cases of geometries.
self.special_group = None
# self.old_pp_state = self.app.defaults["tools_mill_multidepth"]
# self.old_toolchangeg_state = self.app.defaults["tools_mill_toolchange"]
# self.old_pp_state = self.app.options["tools_mill_multidepth"]
# self.old_toolchangeg_state = self.app.options["tools_mill_toolchange"]
self.units_found = self.app.app_units
# this variable can be updated by the Object that generates the geometry
self.tool_type = 'C1'
# save here the old value for the Cut Z before it is changed by selecting a V-shape type tool in the tool table
self.old_cutz = self.app.defaults["tools_mill_cutz"]
self.old_cutz = self.app.options["tools_mill_cutz"]
self.fill_color = self.app.defaults['geometry_plot_line']
self.outline_color = self.app.defaults['geometry_plot_line']
self.fill_color = self.app.options['geometry_plot_line']
self.outline_color = self.app.options['geometry_plot_line']
self.alpha_level = 'FF'
self.param_fields = {}
# store here the state of the exclusion checkbox state to be restored after building the UI
self.exclusion_area_cb_is_checked = self.app.defaults["tools_mill_area_exclusion"]
self.exclusion_area_cb_is_checked = self.app.options["tools_mill_area_exclusion"]
# Attributes to be included in serialization
# Always append to it because it carries contents
@@ -397,7 +397,7 @@ class GeometryObject(FlatCAMObj, Geometry):
self.ui.geo_tools_table.itemSelectionChanged.connect(self.on_row_changed)
self.ui.geo_tools_table.horizontalHeader().sectionClicked.connect(self.table_toggle_all)
# Show/Hide Advanced Options
app_mode = self.app.defaults["global_app_level"]
app_mode = self.app.options["global_app_level"]
self.change_level(app_mode)
def on_row_changed(self):
@@ -563,7 +563,7 @@ class GeometryObject(FlatCAMObj, Geometry):
def export_dxf(self):
dwg = None
dxf_format = self.app.defaults['geometry_dxf_format']
dxf_format = self.app.options['geometry_dxf_format']
try:
dwg = ezdxf.new(dxf_format)
@@ -638,8 +638,8 @@ class GeometryObject(FlatCAMObj, Geometry):
outname = "%s_%s" % (self.obj_options["name"], 'cnc') if outname is None else outname
tools_dict = self.sel_tools if tools_dict is None else tools_dict
segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
segx = segx if segx is not None else float(self.app.options['geometry_segx'])
segy = segy if segy is not None else float(self.app.options['geometry_segy'])
try:
xmin = self.obj_options['xmin']
@@ -679,11 +679,11 @@ class GeometryObject(FlatCAMObj, Geometry):
job_obj.multigeo = False
job_obj.tools.clear()
job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
job_obj.segx = segx if segx else float(self.app.options["geometry_segx"])
job_obj.segy = segy if segy else float(self.app.options["geometry_segy"])
job_obj.z_pdepth = float(self.app.defaults["tools_mill_z_pdepth"])
job_obj.feedrate_probe = float(self.app.defaults["tools_mill_feedrate_probe"])
job_obj.z_pdepth = float(self.app.options["tools_mill_z_pdepth"])
job_obj.feedrate_probe = float(self.app.options["tools_mill_feedrate_probe"])
total_gcode = ''
for tooluid_key in list(tools_dict.keys()):
@@ -742,11 +742,11 @@ class GeometryObject(FlatCAMObj, Geometry):
dwelltime = tools_dict[tooluid_key]['data']["tools_mill_dwelltime"]
pp_geometry_name = tools_dict[tooluid_key]['data']["tools_mill_ppname_g"]
spindledir = self.app.defaults['tools_mill_spindledir']
spindledir = self.app.options['tools_mill_spindledir']
tool_solid_geometry = self.solid_geometry
job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
job_obj.coords_decimals = self.app.options["cncjob_coords_decimals"]
job_obj.fr_decimals = self.app.options["cncjob_fr_decimals"]
# Propagate options
job_obj.obj_options["tooldia"] = tooldia_val
@@ -758,7 +758,7 @@ class GeometryObject(FlatCAMObj, Geometry):
# it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
# to a value of 0.0005 which is 20 times less than 0.01
tol = float(self.app.defaults['global_tolerance']) / 20
tol = float(self.app.options['global_tolerance']) / 20
res, start_gcode = job_obj.generate_from_geometry_2(
self, tooldia=tooldia_val, offset=tool_offset, tolerance=tol,
z_cut=z_cut, z_move=z_move,
@@ -821,11 +821,11 @@ class GeometryObject(FlatCAMObj, Geometry):
job_obj.multigeo = True
job_obj.tools.clear()
job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
job_obj.segx = segx if segx else float(self.app.options["geometry_segx"])
job_obj.segy = segy if segy else float(self.app.options["geometry_segy"])
job_obj.z_pdepth = float(self.app.defaults["tools_mill_z_pdepth"])
job_obj.feedrate_probe = float(self.app.defaults["tools_mill_feedrate_probe"])
job_obj.z_pdepth = float(self.app.options["tools_mill_z_pdepth"])
job_obj.feedrate_probe = float(self.app.options["tools_mill_feedrate_probe"])
# make sure that trying to make a CNCJob from an empty file is not creating an app crash
if not self.solid_geometry:
@@ -847,7 +847,7 @@ class GeometryObject(FlatCAMObj, Geometry):
})
if "optimization_type" not in tools_dict[tooluid_key]['data']:
tools_dict[tooluid_key]['data']["tools_mill_optimization_type"] = \
self.app.defaults["tools_mill_optimization_type"]
self.app.options["tools_mill_optimization_type"]
# find the tool_dia associated with the tooluid_key
# search in the self.tools for the sel_tool_dia and when found see what tooluid has
@@ -896,11 +896,11 @@ class GeometryObject(FlatCAMObj, Geometry):
# dwelltime = tools_dict[tooluid_key]['data']["dwelltime"]
# pp_geometry_name = tools_dict[tooluid_key]['data']["ppname_g"]
#
# spindledir = self.app.defaults['geometry_spindledir']
# spindledir = self.app.options['geometry_spindledir']
tool_solid_geometry = self.tools[tooluid_key]['solid_geometry']
job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
job_obj.coords_decimals = self.app.options["cncjob_coords_decimals"]
job_obj.fr_decimals = self.app.options["cncjob_fr_decimals"]
# Propagate options
job_obj.obj_options["tooldia"] = tooldia_val
@@ -909,7 +909,7 @@ class GeometryObject(FlatCAMObj, Geometry):
# it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
# to a value of 0.0005 which is 20 times less than 0.01
tol = float(self.app.defaults['global_tolerance']) / 20
tol = float(self.app.options['global_tolerance']) / 20
tool_lst = list(tools_dict.keys())
is_first = True if tooluid_key == tool_lst[0] else False
@@ -1034,8 +1034,8 @@ class GeometryObject(FlatCAMObj, Geometry):
multidepth = multidepth if multidepth is not None else self.obj_options["tools_mill_multidepth"]
depthperpass = dpp if dpp is not None else float(self.obj_options["tools_mill_depthperpass"])
segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
segx = segx if segx is not None else float(self.app.options['geometry_segx'])
segy = segy if segy is not None else float(self.app.options['geometry_segy'])
extracut = extracut if extracut is not None else float(self.obj_options["tools_mill_extracut"])
extracut_length = extracut_length if extracut_length is not None else float(self.obj_options[
@@ -1079,8 +1079,8 @@ class GeometryObject(FlatCAMObj, Geometry):
job_obj.obj_options["tooldia"] = tooldia
job_obj.obj_options["tools_mill_tooldia"] = tooldia
job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
job_obj.coords_decimals = self.app.options["cncjob_coords_decimals"]
job_obj.fr_decimals = self.app.options["cncjob_fr_decimals"]
job_obj.obj_options['type'] = 'Geometry'
job_obj.obj_options['tool_dia'] = tooldia
@@ -1098,7 +1098,7 @@ class GeometryObject(FlatCAMObj, Geometry):
# it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
# to a value of 0.0005 which is 20 times less than 0.01
tol = float(self.app.defaults['global_tolerance']) / 20
tol = float(self.app.options['global_tolerance']) / 20
res, start_gcode = job_obj.generate_from_geometry_2(
self, tooldia=tooldia, offset=offset, tolerance=tol, z_cut=z_cut, z_move=z_move, feedrate=feedrate,
feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid, spindlespeed=spindlespeed, dwell=dwell,
@@ -1319,10 +1319,10 @@ class GeometryObject(FlatCAMObj, Geometry):
self.obj_options["toolchangez"] = float(self.obj_options["toolchangez"]) * factor
if self.app.defaults["tools_mill_toolchangexy"] == '':
if self.app.options["tools_mill_toolchangexy"] == '':
self.obj_options['toolchangexy'] = "0.0, 0.0"
else:
coords_xy = [float(eval(coord)) for coord in self.app.defaults["tools_mill_toolchangexy"].split(",")]
coords_xy = [float(eval(coord)) for coord in self.app.options["tools_mill_toolchangexy"].split(",")]
if len(coords_xy) < 2:
self.app.inform.emit('[ERROR] %s' %
_("The Toolchange X,Y field in Edit -> Preferences "
@@ -1465,7 +1465,7 @@ class GeometryObject(FlatCAMObj, Geometry):
color = self.tools[tooluid_key]['data']['override_color']
else:
color = random_color() if self.obj_options['multicolored'] else \
self.app.defaults["geometry_plot_line"]
self.app.options["geometry_plot_line"]
self.plot_element(solid_geometry, visible=visible, color=color)
else:
@@ -1474,7 +1474,7 @@ class GeometryObject(FlatCAMObj, Geometry):
color = self.tools[plot_tool]['data']['override_color']
else:
color = random_color() if self.obj_options['multicolored'] else \
self.app.defaults["geometry_plot_line"]
self.app.options["geometry_plot_line"]
self.plot_element(solid_geometry, visible=visible, color=color)
else:
@@ -1482,7 +1482,7 @@ class GeometryObject(FlatCAMObj, Geometry):
# for SingleGeo
if self.solid_geometry:
solid_geometry = self.solid_geometry
color = self.app.defaults["geometry_plot_line"]
color = self.app.options["geometry_plot_line"]
self.plot_element(solid_geometry, visible=visible, color=color)