- added a parameter to the FlatCAMDefaults class, whenever a value in the self.defaults dict change it will call a callback function and send to it the modified key
- optimized and fixed some issues in the self.on_toggle_units() method - the Exclusion areas will have all the orange color but the color of the outline will differ according to the type of the object from where it was added (cosmetic use only as the Exclusion areas will be applied globally)
This commit is contained in:
162
FlatCAMApp.py
162
FlatCAMApp.py
@@ -4244,10 +4244,10 @@ class App(QtCore.QObject):
|
||||
|
||||
# If option is the same, then ignore
|
||||
if new_units == self.defaults["units"].upper():
|
||||
self.log.debug("on_toggle_units(): Same as defaults, so ignoring.")
|
||||
self.log.debug("on_toggle_units(): Same as previous, ignoring.")
|
||||
return
|
||||
|
||||
# Options to scale
|
||||
# Keys in self.defaults for which to scale their values
|
||||
dimensions = ['gerber_isotooldia', 'gerber_noncoppermargin', 'gerber_bboxmargin',
|
||||
"gerber_editor_newsize", "gerber_editor_lin_pitch", "gerber_editor_buff_f", "gerber_vtipdia",
|
||||
"gerber_vcutz", "gerber_editor_newdim", "gerber_editor_ma_low",
|
||||
@@ -4321,149 +4321,54 @@ class App(QtCore.QObject):
|
||||
|
||||
def scale_defaults(sfactor):
|
||||
for dim in dimensions:
|
||||
if dim in [
|
||||
'gerber_editor_newdim', 'excellon_toolchangexy', 'geometry_toolchangexy', 'excellon_endxy',
|
||||
'geometry_endxy', 'tools_solderpaste_xy_toolchange', 'tools_cal_toolchange_xy',
|
||||
'tools_transform_mirror_point'
|
||||
]:
|
||||
if self.defaults[dim] is None or self.defaults[dim] == '':
|
||||
continue
|
||||
try:
|
||||
coordinates = self.defaults[dim].split(",")
|
||||
coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
coords_xy[0] *= sfactor
|
||||
coords_xy[1] *= sfactor
|
||||
self.defaults[dim] = "%.*f, %.*f" % (self.decimals, coords_xy[0], self.decimals, coords_xy[1])
|
||||
except Exception as e:
|
||||
log.debug("App.on_toggle_units.scale_defaults() --> 'string tuples': %s" % str(e))
|
||||
|
||||
if dim == 'gerber_editor_newdim':
|
||||
if self.defaults["gerber_editor_newdim"] is None or self.defaults["gerber_editor_newdim"] == '':
|
||||
continue
|
||||
coordinates = self.defaults["gerber_editor_newdim"].split(",")
|
||||
coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
coords_xy[0] *= sfactor
|
||||
coords_xy[1] *= sfactor
|
||||
self.defaults['gerber_editor_newdim'] = "%.*f, %.*f" % (self.decimals, coords_xy[0],
|
||||
self.decimals, coords_xy[1])
|
||||
if dim == 'excellon_toolchangexy':
|
||||
if self.defaults["excellon_toolchangexy"] is None or self.defaults["excellon_toolchangexy"] == '':
|
||||
continue
|
||||
coordinates = self.defaults["excellon_toolchangexy"].split(",")
|
||||
coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
coords_xy[0] *= sfactor
|
||||
coords_xy[1] *= sfactor
|
||||
self.defaults['excellon_toolchangexy'] = "%.*f, %.*f" % (self.decimals, coords_xy[0],
|
||||
self.decimals, coords_xy[1])
|
||||
elif dim == 'geometry_toolchangexy':
|
||||
if self.defaults["geometry_toolchangexy"] is None or self.defaults["geometry_toolchangexy"] == '':
|
||||
continue
|
||||
coordinates = self.defaults["geometry_toolchangexy"].split(",")
|
||||
coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
coords_xy[0] *= sfactor
|
||||
coords_xy[1] *= sfactor
|
||||
self.defaults['geometry_toolchangexy'] = "%.*f, %.*f" % (self.decimals, coords_xy[0],
|
||||
self.decimals, coords_xy[1])
|
||||
elif dim == 'excellon_endxy':
|
||||
if self.defaults["excellon_endxy"] is None or self.defaults["excellon_endxy"] == '':
|
||||
elif dim in [
|
||||
'geometry_cnctooldia', 'tools_ncctools', 'tools_solderpaste_tools'
|
||||
]:
|
||||
if self.defaults[dim] is None or self.defaults[dim] == '':
|
||||
continue
|
||||
|
||||
coordinates = self.defaults["excellon_endxy"].split(",")
|
||||
end_coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
end_coords_xy[0] *= sfactor
|
||||
end_coords_xy[1] *= sfactor
|
||||
self.defaults['excellon_endxy'] = "%.*f, %.*f" % (self.decimals, end_coords_xy[0],
|
||||
self.decimals, end_coords_xy[1])
|
||||
elif dim == 'geometry_endxy':
|
||||
if self.defaults["geometry_endxy"] is None or self.defaults["geometry_endxy"] == '':
|
||||
continue
|
||||
coordinates = self.defaults["geometry_endxy"].split(",")
|
||||
end_coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
end_coords_xy[0] *= sfactor
|
||||
end_coords_xy[1] *= sfactor
|
||||
self.defaults['geometry_endxy'] = "%.*f, %.*f" % (self.decimals, end_coords_xy[0],
|
||||
self.decimals, end_coords_xy[1])
|
||||
|
||||
elif dim == 'geometry_cnctooldia':
|
||||
if self.defaults["geometry_cnctooldia"] is None or self.defaults["geometry_cnctooldia"] == '':
|
||||
continue
|
||||
if type(self.defaults["geometry_cnctooldia"]) is float:
|
||||
tools_diameters = [self.defaults["geometry_cnctooldia"]]
|
||||
if isinstance(self.defaults[dim], float):
|
||||
tools_diameters = [self.defaults[dim]]
|
||||
else:
|
||||
try:
|
||||
tools_string = self.defaults["geometry_cnctooldia"].split(",")
|
||||
tools_string = self.defaults[dim].split(",")
|
||||
tools_diameters = [eval(a) for a in tools_string if a != '']
|
||||
except Exception as e:
|
||||
log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
|
||||
continue
|
||||
|
||||
self.defaults['geometry_cnctooldia'] = ''
|
||||
self.defaults[dim] = ''
|
||||
for t in range(len(tools_diameters)):
|
||||
tools_diameters[t] *= sfactor
|
||||
self.defaults['geometry_cnctooldia'] += "%.*f," % (self.decimals, tools_diameters[t])
|
||||
elif dim == 'tools_ncctools':
|
||||
if self.defaults["tools_ncctools"] is None or self.defaults["tools_ncctools"] == '':
|
||||
continue
|
||||
if type(self.defaults["tools_ncctools"]) == float:
|
||||
ncctools = [self.defaults["tools_ncctools"]]
|
||||
else:
|
||||
try:
|
||||
tools_string = self.defaults["tools_ncctools"].split(",")
|
||||
ncctools = [eval(a) for a in tools_string if a != '']
|
||||
except Exception as e:
|
||||
log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
|
||||
continue
|
||||
self.defaults[dim] += "%.*f," % (self.decimals, tools_diameters[t])
|
||||
|
||||
self.defaults['tools_ncctools'] = ''
|
||||
for t in range(len(ncctools)):
|
||||
ncctools[t] *= sfactor
|
||||
self.defaults['tools_ncctools'] += "%.*f," % (self.decimals, ncctools[t])
|
||||
elif dim == 'tools_solderpaste_tools':
|
||||
if self.defaults["tools_solderpaste_tools"] is None or \
|
||||
self.defaults["tools_solderpaste_tools"] == '':
|
||||
continue
|
||||
if type(self.defaults["tools_solderpaste_tools"]) == float:
|
||||
sptools = [self.defaults["tools_solderpaste_tools"]]
|
||||
else:
|
||||
try:
|
||||
tools_string = self.defaults["tools_solderpaste_tools"].split(",")
|
||||
sptools = [eval(a) for a in tools_string if a != '']
|
||||
except Exception as e:
|
||||
log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
|
||||
continue
|
||||
|
||||
self.defaults['tools_solderpaste_tools'] = ""
|
||||
for t in range(len(sptools)):
|
||||
sptools[t] *= sfactor
|
||||
self.defaults['tools_solderpaste_tools'] += "%.*f," % (self.decimals, sptools[t])
|
||||
elif dim == 'tools_solderpaste_xy_toolchange':
|
||||
if self.defaults["tools_solderpaste_xy_toolchange"] is None or \
|
||||
self.defaults["tools_solderpaste_xy_toolchange"] == '':
|
||||
continue
|
||||
elif dim in ['global_gridx', 'global_gridy']:
|
||||
# format the number of decimals to the one specified in self.decimals
|
||||
try:
|
||||
coordinates = self.defaults["tools_solderpaste_xy_toolchange"].split(",")
|
||||
sp_coords = [float(eval(a)) for a in coordinates if a != '']
|
||||
sp_coords[0] *= sfactor
|
||||
sp_coords[1] *= sfactor
|
||||
self.defaults['tools_solderpaste_xy_toolchange'] = "%.*f, %.*f" % (self.decimals, sp_coords[0],
|
||||
self.decimals, sp_coords[1])
|
||||
val = float(self.defaults[dim]) * sfactor
|
||||
except Exception as e:
|
||||
log.debug("App.on_toggle_units().scale_options() --> %s" % str(e))
|
||||
log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e))
|
||||
continue
|
||||
elif dim == 'tools_cal_toolchange_xy':
|
||||
if self.defaults["tools_cal_toolchange_xy"] is None or \
|
||||
self.defaults["tools_cal_toolchange_xy"] == '':
|
||||
continue
|
||||
coordinates = self.defaults["tools_cal_toolchange_xy"].split(",")
|
||||
end_coords_xy = [float(eval(a)) for a in coordinates if a != '']
|
||||
end_coords_xy[0] *= sfactor
|
||||
end_coords_xy[1] *= sfactor
|
||||
self.defaults['tools_cal_toolchange_xy'] = "%.*f, %.*f" % (self.decimals, end_coords_xy[0],
|
||||
self.decimals, end_coords_xy[1])
|
||||
|
||||
elif dim == 'global_gridx' or dim == 'global_gridy':
|
||||
if new_units == 'IN':
|
||||
try:
|
||||
val = float(self.defaults[dim]) * sfactor
|
||||
except Exception as e:
|
||||
log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e))
|
||||
continue
|
||||
|
||||
self.defaults[dim] = float('%.*f' % (self.decimals, val))
|
||||
else:
|
||||
try:
|
||||
val = float(self.defaults[dim]) * sfactor
|
||||
except Exception as e:
|
||||
log.debug('App.on_toggle_units().scale_defaults() --> %s' % str(e))
|
||||
continue
|
||||
|
||||
self.defaults[dim] = float('%.*f' % (self.decimals, val))
|
||||
self.defaults[dim] = float('%.*f' % (self.decimals, val))
|
||||
else:
|
||||
# the number of decimals for the rest is kept unchanged
|
||||
if self.defaults[dim]:
|
||||
try:
|
||||
val = float(self.defaults[dim]) * sfactor
|
||||
@@ -4526,10 +4431,11 @@ class App(QtCore.QObject):
|
||||
|
||||
# replot all objects
|
||||
self.plot_all()
|
||||
|
||||
# set the status labels to reflect the current FlatCAM units
|
||||
self.set_screen_units(new_units)
|
||||
|
||||
# signal to the app that we changed the object properties and it shoud save the project
|
||||
# signal to the app that we changed the object properties and it should save the project
|
||||
self.should_we_save = True
|
||||
|
||||
self.inform.emit('[success] %s: %s' % (_("Converted units to"), new_units))
|
||||
|
||||
Reference in New Issue
Block a user