- 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:
Marius Stanciu 2020-05-08 01:41:40 +03:00 committed by Marius
parent eea80aafc3
commit 484fb51bf0
10 changed files with 64 additions and 145 deletions

View File

@ -7,10 +7,16 @@ CHANGELOG for FlatCAM beta
=================================================
8.05.2020
- 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)
7.05.2020
- added a fix so the app close is now clean, with exit code 0 as set
- added the ability to add exclusion areas from the Excellon object too. Now there is a different in color to differentiate from which type of object the exclusion areas were added but they all serve the same purpose
- added the ability to add exclusion areas from the Excellon object too. Now there is a difference in color to differentiate from which type of object the exclusion areas were added but they all serve the same purpose
6.05.2020

View File

@ -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))

View File

@ -280,7 +280,7 @@ class ExclusionAreas:
face_color = "#FF7400BF"
else:
color = "#098a8f"
face_color = "#098a8fBF"
face_color = "#FF7400BF"
# add a temporary shape on canvas
FlatCAMTool.draw_tool_selection_shape(
@ -341,7 +341,7 @@ class ExclusionAreas:
face_color = "#FF7400BF"
else:
color = "#098a8f"
face_color = "#098a8fBF"
face_color = "#FF7400BF"
FlatCAMTool.draw_selection_shape_polygon(
self, points=self.points,
@ -476,7 +476,7 @@ class ExclusionAreas:
face_color = "#FF7400BF"
else:
color = "#098a8f"
face_color = "#098a8fBF"
face_color = "#FF7400BF"
# draw the utility geometry
if shape_type == "square":

View File

@ -495,7 +495,7 @@ class FlatCAMDefaults:
"tools_transform_offset_x": 0.0,
"tools_transform_offset_y": 0.0,
"tools_transform_mirror_reference": False,
"tools_transform_mirror_point": (0, 0),
"tools_transform_mirror_point": "0.0, 0.0",
"tools_transform_buffer_dis": 0.0,
"tools_transform_buffer_factor": 100.0,
"tools_transform_buffer_corner": True,
@ -697,13 +697,19 @@ class FlatCAMDefaults:
except Exception as e:
log.error("save_factory_defaults() -> %s" % str(e))
def __init__(self):
def __init__(self, callback=lambda x: None):
"""
:param callback: A method called each time that one of the values are changed in the self.defaults LouDict
"""
self.defaults = LoudDict()
self.defaults.update(self.factory_defaults)
self.current_defaults = {} # copy used for restoring after cancelled prefs changes
self.current_defaults.update(self.factory_defaults)
self.old_defaults_found = False
self.defaults.set_change_callback(callback)
# #### Pass-through to the defaults LoudDict #####
def __len__(self):
return self.defaults.__len__()

View File

@ -933,7 +933,7 @@ class TransformEditorTool(FlatCAMTool):
"the 'y' in (x, y) will be used when using Flip on Y.")
)
self.flip_ref_label.setFixedWidth(50)
self.flip_ref_entry = FCEntry("(0, 0)")
self.flip_ref_entry = FCEntry("0, 0")
self.flip_ref_button = FCButton()
self.flip_ref_button.set_value(_("Add"))
@ -1048,7 +1048,7 @@ class TransformEditorTool(FlatCAMTool):
if self.app.defaults["tools_transform_mirror_point"]:
self.flip_ref_entry.set_value(self.app.defaults["tools_transform_mirror_point"])
else:
self.flip_ref_entry.set_value((0, 0))
self.flip_ref_entry.set_value("0, 0")
def template(self):
if not self.draw_app.selected:

View File

@ -5633,7 +5633,7 @@ class TransformEditorTool(FlatCAMTool):
"the 'y' in (x, y) will be used when using Flip on Y.")
)
self.flip_ref_label.setMinimumWidth(50)
self.flip_ref_entry = EvalEntry2("(0, 0)")
self.flip_ref_entry = FCEntry()
self.flip_ref_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
# self.flip_ref_entry.setFixedWidth(60)
@ -5760,7 +5760,7 @@ class TransformEditorTool(FlatCAMTool):
if self.app.defaults["tools_transform_mirror_point"]:
self.flip_ref_entry.set_value(self.app.defaults["tools_transform_mirror_point"])
else:
self.flip_ref_entry.set_value((0, 0))
self.flip_ref_entry.set_value("0, 0")
def template(self):
if not self.draw_app.selected:

View File

@ -1293,7 +1293,7 @@ class ExcellonObjectUI(ObjectUI):
self.grid5.addWidget(self.pp_geo_name_cb, 16, 1)
# Exclusion Areas
self.exclusion_cb = FCCheckBox('%s' % _("Exclusion areas"))
self.exclusion_cb = FCCheckBox('%s' % _("Add exclusion areas"))
self.exclusion_cb.setToolTip(
_(
"Include exclusion areas.\n"
@ -2104,7 +2104,7 @@ class GeometryObjectUI(ObjectUI):
# grid4.addWidget(QtWidgets.QLabel(''), 12, 0, 1, 2)
# Exclusion Areas
self.exclusion_cb = FCCheckBox('%s' % _("Exclusion areas"))
self.exclusion_cb = FCCheckBox('%s' % _("Add exclusion areas"))
self.exclusion_cb.setToolTip(
_(
"Include exclusion areas.\n"

View File

@ -287,6 +287,7 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
def on_mouse_scroll(self, event):
# key modifiers
modifiers = event.modifiers
pan_delta_x = self.fcapp.defaults["global_gridx"]
pan_delta_y = self.fcapp.defaults["global_gridy"]
curr_pos = event.pos

View File

@ -1,7 +1,7 @@
from PyQt5 import QtWidgets
from PyQt5.QtCore import QSettings
from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, EvalEntry2
from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, FCEntry
from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI
import gettext
@ -191,7 +191,7 @@ class ToolsTransformPrefGroupUI(OptionsGroupUI):
"The 'x' in (x, y) will be used when using Flip on X and\n"
"the 'y' in (x, y) will be used when using Flip on Y and")
)
self.flip_ref_entry = EvalEntry2("(0, 0)")
self.flip_ref_entry = FCEntry()
grid0.addWidget(self.flip_ref_label, 14, 0, 1, 2)
grid0.addWidget(self.flip_ref_entry, 15, 0, 1, 2)

View File

@ -7,7 +7,7 @@
from PyQt5 import QtWidgets
from FlatCAMTool import FlatCAMTool
from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, FCButton, OptionalInputSection, EvalEntry2
from flatcamGUI.GUIElements import FCDoubleSpinner, FCCheckBox, FCButton, OptionalInputSection, FCEntry
import gettext
import FlatCAMTranslation as fcTranslate
@ -300,7 +300,7 @@ class ToolTransform(FlatCAMTool):
"The 'x' in (x, y) will be used when using Flip on X and\n"
"the 'y' in (x, y) will be used when using Flip on Y.")
)
self.flip_ref_entry = EvalEntry2("(0, 0)")
self.flip_ref_entry = FCEntry()
# self.flip_ref_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
# self.flip_ref_entry.setFixedWidth(70)
@ -533,7 +533,7 @@ class ToolTransform(FlatCAMTool):
if self.app.defaults["tools_transform_mirror_point"]:
self.flip_ref_entry.set_value(self.app.defaults["tools_transform_mirror_point"])
else:
self.flip_ref_entry.set_value((0, 0))
self.flip_ref_entry.set_value("0, 0")
if self.app.defaults["tools_transform_buffer_dis"]:
self.buffer_entry.set_value(self.app.defaults["tools_transform_buffer_dis"])