- PEP8 cleanup in FlatCAMGui

- finished adding the Excellon Editor parameters into the app logic and added a selection limit within Excellon Editor just like in the other editors
This commit is contained in:
Marius Stanciu 2019-06-04 22:19:45 +03:00
parent dc51f6d833
commit 150bb9e999
4 changed files with 533 additions and 439 deletions

View File

@ -58,9 +58,9 @@ fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
# ##################################### ##
# ########################################
# # App ###
# ##################################### ##
# ########################################
class App(QtCore.QObject):
@ -428,6 +428,17 @@ class App(QtCore.QObject):
"excellon_exp_decimals": self.ui.excellon_defaults_form.excellon_exp_group.format_dec_entry,
"excellon_exp_zeros": self.ui.excellon_defaults_form.excellon_exp_group.zeros_radio,
# Excellon Editor
"excellon_editor_sel_limit": self.ui.excellon_defaults_form.excellon_editor_group.sel_limit_entry,
"excellon_editor_newdia": self.ui.excellon_defaults_form.excellon_editor_group.addtool_entry,
"excellon_editor_array_size": self.ui.excellon_defaults_form.excellon_editor_group.drill_array_size_entry,
"excellon_editor_lin_dir": self.ui.excellon_defaults_form.excellon_editor_group.drill_axis_radio,
"excellon_editor_lin_pitch": self.ui.excellon_defaults_form.excellon_editor_group.drill_pitch_entry,
"excellon_editor_lin_angle": self.ui.excellon_defaults_form.excellon_editor_group.drill_angle_entry,
"excellon_editor_circ_dir": self.ui.excellon_defaults_form.excellon_editor_group.drill_circular_dir_radio,
"excellon_editor_circ_angle":
self.ui.excellon_defaults_form.excellon_editor_group.drill_circular_angle_entry,
# Geometry General
"geometry_plot": self.ui.geometry_defaults_form.geometry_gen_group.plot_cb,
"geometry_circle_steps": self.ui.geometry_defaults_form.geometry_gen_group.circle_steps_entry,
@ -756,6 +767,16 @@ class App(QtCore.QObject):
"excellon_exp_decimals": 4,
"excellon_exp_zeros": 'LZ',
# Excellon Editor
"excellon_editor_sel_limit": 30,
"excellon_editor_newdia": 0.039,
"excellon_editor_array_size": 5,
"excellon_editor_lin_dir": 'X',
"excellon_editor_lin_pitch": 0.1,
"excellon_editor_lin_angle": 0.0,
"excellon_editor_circ_dir": 'CW',
"excellon_editor_circ_angle": 12,
# Geometry General
"geometry_plot": True,
"geometry_circle_steps": 128,

View File

@ -12,8 +12,10 @@ CAD program, and create G-Code for Isolation routing.
4.06.2019
- PEP8 updates in FlatCAMExcEditor.py
- added the Excellon Editor parameters to the Edit -> Preferences -> Excellon
- added the Excellon Editor parameters to the Edit -> Preferences -> Excellon GUI
- fixed a small bug in Excellon Editor
- PEP8 cleanup in FlatCAMGui
- finished adding the Excellon Editor parameters into the app logic and added a selection limit within Excellon Editor just like in the other editors
3.06.2019

View File

@ -441,6 +441,8 @@ class FCDrillMove(FCShapeTool):
# self.shape_buffer = self.draw_app.shape_buffer
self.origin = None
self.destination = None
self.sel_limit = self.draw_app.app.defaults["excellon_editor_sel_limit"]
self.selection_shape = self.selection_bbox()
self.selected_dia_list = []
if self.draw_app.launched_from_shortcuts is True:
@ -504,6 +506,25 @@ class FCDrillMove(FCShapeTool):
self.draw_app.build_ui()
self.draw_app.app.inform.emit(_("[success] Done. Drill(s) Move completed."))
def selection_bbox(self):
geo_list = []
for select_shape in self.draw_app.get_selected():
geometric_data = select_shape.geo
try:
for g in geometric_data:
geo_list.append(g)
except TypeError:
geo_list.append(geometric_data)
xmin, ymin, xmax, ymax = get_shapely_list_bounds(geo_list)
pt1 = (xmin, ymin)
pt2 = (xmax, ymin)
pt3 = (xmax, ymax)
pt4 = (xmin, ymax)
return Polygon([pt1, pt2, pt3, pt4])
def utility_geometry(self, data=None):
"""
Temporary geometry on screen while using this tool.
@ -521,9 +542,22 @@ class FCDrillMove(FCShapeTool):
dx = data[0] - self.origin[0]
dy = data[1] - self.origin[1]
if len(self.draw_app.get_selected()) <= self.sel_limit:
try:
for geom in self.draw_app.get_selected():
geo_list.append(affinity.translate(geom.geo, xoff=dx, yoff=dy))
except AttributeError:
self.draw_app.select_tool('drill_select')
self.draw_app.selected = []
return
return DrawToolUtilityShape(geo_list)
else:
try:
ss_el = affinity.translate(self.selection_shape, xoff=dx, yoff=dy)
except ValueError:
ss_el = None
return DrawToolUtilityShape(ss_el)
class FCDrillCopy(FCDrillMove):
@ -985,7 +1019,6 @@ class FlatCAMExcEditor(QtCore.QObject):
self.drill_direction_radio = RadioSet([{'label': 'CW', 'value': 'CW'},
{'label': 'CCW.', 'value': 'CCW'}])
self.drill_direction_radio.set_value('CW')
self.circular_form.addRow(self.drill_direction_label, self.drill_direction_radio)
self.drill_angle_label = QtWidgets.QLabel(_('Angle:'))
@ -1077,13 +1110,6 @@ class FlatCAMExcEditor(QtCore.QObject):
self.app.ui.exc_move_drill_menuitem.triggered.connect(self.exc_move_drills)
# Init GUI
self.drill_array_size_entry.set_value(5)
self.drill_pitch_entry.set_value(2.54)
self.drill_angle_entry.set_value(12)
self.drill_direction_radio.set_value('CW')
self.drill_axis_radio.set_value('X')
self.exc_obj = None
# VisPy Visuals
@ -1166,7 +1192,6 @@ class FlatCAMExcEditor(QtCore.QObject):
@staticmethod
def make_storage():
# ## Shape storage.
storage = FlatCAMRTreeStorage()
storage.get_points = DrawToolShape.get_pts
@ -1174,7 +1199,6 @@ class FlatCAMExcEditor(QtCore.QObject):
return storage
def set_ui(self):
# updated units
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
@ -1193,6 +1217,7 @@ class FlatCAMExcEditor(QtCore.QObject):
self.points_edit[tool_dia].append(drill['point'])
except KeyError:
self.points_edit[tool_dia] = [drill['point']]
# update the olddia_newdia dict to make sure we have an updated state of the tool_table
for key in self.points_edit:
self.olddia_newdia[key] = key
@ -1218,6 +1243,15 @@ class FlatCAMExcEditor(QtCore.QObject):
tool_dia = float('%.2f' % v['C'])
self.tool2tooldia[int(k)] = tool_dia
# Init GUI
self.addtool_entry.set_value(float(self.app.defaults['excellon_editor_newdia']))
self.drill_array_size_entry.set_value(int(self.app.defaults['excellon_editor_array_size']))
self.drill_axis_radio.set_value(self.app.defaults['excellon_editor_lin_dir'])
self.drill_pitch_entry.set_value(float(self.app.defaults['excellon_editor_lin_pitch']))
self.linear_angle_spinner.set_value(float(self.app.defaults['excellon_editor_lin_angle']))
self.drill_direction_radio.set_value(self.app.defaults['excellon_editor_circ_dir'])
self.drill_angle_entry.set_value(float(self.app.defaults['excellon_editor_circ_angle']))
def build_ui(self, first_run=None):
try:
@ -1238,11 +1272,6 @@ class FlatCAMExcEditor(QtCore.QObject):
self.edited_obj_name = self.exc_obj.options['name']
self.name_entry.set_value(self.edited_obj_name)
if self.units == "IN":
self.addtool_entry.set_value(0.039)
else:
self.addtool_entry.set_value(1.00)
sort_temp = []
for diam in self.olddia_newdia:
@ -1886,7 +1915,7 @@ class FlatCAMExcEditor(QtCore.QObject):
# add a first tool in the Tool Table but only if the Excellon Object is empty
if not self.tool2tooldia:
self.on_tool_add(tooldia=1.00)
self.on_tool_add(tooldia=float(self.app.defaults['excellon_editor_newdia']))
def update_fcexcellon(self, exc_obj):
"""
@ -2324,13 +2353,15 @@ class FlatCAMExcEditor(QtCore.QObject):
log.warning("Error: %s" % str(e))
raise
def draw_selection_area_handler(self, start_pos, end_pos, sel_type):
def draw_selection_area_handler(self, start, end, sel_type):
"""
:param start_pos: mouse position when the selection LMB click was done
:param end_pos: mouse position when the left mouse button is released
:param sel_type: if True it's a left to right selection (enclosure), if False it's a 'touch' selection
:return:
"""
start_pos = (start[0], start[1])
end_pos = (end[0], end[1])
poly_selection = Polygon([start_pos, (end_pos[0], start_pos[1]), end_pos, (start_pos[0], end_pos[1])])
self.app.delete_selection_shape()
@ -2702,4 +2733,23 @@ class FlatCAMExcEditor(QtCore.QObject):
self.select_tool('drill_move')
return
def get_shapely_list_bounds(geometry_list):
xmin = Inf
ymin = Inf
xmax = -Inf
ymax = -Inf
for gs in geometry_list:
try:
gxmin, gymin, gxmax, gymax = gs.bounds
xmin = min([xmin, gxmin])
ymin = min([ymin, gymin])
xmax = max([xmax, gxmax])
ymax = max([ymax, gymax])
except Exception as e:
log.warning("DEVELOPMENT: Tried to get bounds of empty geometry. --> %s" % str(e))
return [xmin, ymin, xmax, ymax]
# EOF

View File

@ -203,6 +203,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.menufile.addSeparator()
self.menufile_save = self.menufile.addMenu(QtGui.QIcon('share/save_as.png'), _('Save'))
# Save Project
self.menufilesaveproject = QtWidgets.QAction(QtGui.QIcon('share/floppy16.png'), _('&Save Project ...'), self)
self.menufile_save.addAction(self.menufilesaveproject)
@ -377,7 +378,6 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
_("Toggle Workspace\tSHIFT+W"))
# ## Tool ###
# self.menutool = self.menu.addMenu('&Tool')
self.menutool = QtWidgets.QMenu(_('&Tool'))
self.menutoolaction = self.menu.addMenu(self.menutool)
self.menutoolshell = self.menutool.addAction(QtGui.QIcon('share/shell16.png'), _('&Command Line\tS'))
@ -393,14 +393,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
)
self.menuhelp_about = self.menuhelp.addAction(QtGui.QIcon('share/about32.png'), _('About'))
# ## FlatCAM Editor menu ###
# self.editor_menu = QtWidgets.QMenu("Editor")
# self.menu.addMenu(self.editor_menu)
self.geo_editor_menu = QtWidgets.QMenu(">Geo Editor<")
self.menu.addMenu(self.geo_editor_menu)
# self.select_menuitem = self.menu.addAction(QtGui.QIcon('share/pointer16.png'), "Select 'Esc'")
self.geo_add_circle_menuitem = self.geo_editor_menu.addAction(
QtGui.QIcon('share/circle32.png'), _('Add Circle\tO')
)
@ -469,7 +465,6 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
QtGui.QIcon('share/move32.png'),_( 'Move Drill(s)\tM'))
# ## APPLICATION GERBER EDITOR MENU ###
self.grb_editor_menu = QtWidgets.QMenu(_(">Gerber Editor<"))
self.menu.addMenu(self.grb_editor_menu)
@ -516,9 +511,9 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.exc_editor_menu.menuAction().setVisible(False)
self.exc_editor_menu.setDisabled(True)
# ############################# ##
# ################################
# ### Project Tab Context menu ###
# ############################# ##
# ################################
self.menuproject = QtWidgets.QMenu()
self.menuprojectenable = self.menuproject.addAction(QtGui.QIcon('share/replot32.png'), _('Enable Plot'))
@ -535,9 +530,9 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.menuprojectproperties = self.menuproject.addAction(QtGui.QIcon('share/properties32.png'), _('Properties'))
# ############# ##
# ################
# ### Splitter ###
# ############# ##
# ################
# IMPORTANT #
# The order: SPITTER -> NOTEBOOK -> SNAP TOOLBAR is important and without it the GUI will not be initialized as
@ -638,10 +633,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
# self.toolbarview.setVisible(False)
# ## Shell Toolbar # ##
# ## Shell Toolbar ##
self.shell_btn = self.toolbarshell.addAction(QtGui.QIcon('share/shell32.png'), _("&Command Line"))
# ## Tools Toolbar # ##
# ## Tools Toolbar ##
self.dblsided_btn = self.toolbartools.addAction(QtGui.QIcon('share/doubleside32.png'), _("2Sided Tool"))
self.cutout_btn = self.toolbartools.addAction(QtGui.QIcon('share/cut16_bis.png'), _("&Cutout Tool"))
self.ncc_btn = self.toolbartools.addAction(QtGui.QIcon('share/ncc16.png'), _("NCC Tool"))
@ -960,9 +955,9 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
"which is the file storing the working default preferences."))
self.pref_tab_bottom_layout_2.addWidget(self.pref_save_button)
###################################### ##
# #################################################
# ## HERE WE BUILD THE SHORTCUTS LIST. TAB AREA ###
###################################### ##
# #################################################
self.shortcuts_tab = QtWidgets.QWidget()
self.sh_tab_layout = QtWidgets.QVBoxLayout()
self.sh_tab_layout.setContentsMargins(2, 2, 2, 2)
@ -1733,6 +1728,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.show()
self.filename = ""
self.units = ""
self.setAcceptDrops(True)
# # restore the Toolbar State from file
@ -2038,9 +2034,6 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
else:
key = event.key
# Propagate to tool
response = None
if self.app.call_source == 'app':
if modifiers == QtCore.Qt.ControlModifier:
if key == QtCore.Qt.Key_A:
@ -3001,7 +2994,8 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
if ok:
self.app.exc_editor.on_tool_add(tooldia=val)
self.app.inform.emit(
_("[success] Added new tool with dia: {dia} {units}").format(dia='%.4f' % float(val), units=str(self.units)))
_("[success] Added new tool with dia: {dia} {units}").format(dia='%.4f' % float(val),
units=str(self.units)))
else:
self.app.inform.emit(
_("[WARNING_NOTCL] Adding Tool cancelled ..."))
@ -3161,7 +3155,6 @@ class GerberPreferencesUI(QtWidgets.QWidget):
self.gerber_editor_group = GerberEditorPrefGroupUI()
self.gerber_editor_group.setFixedWidth(200)
self.vlay = QtWidgets.QVBoxLayout()
self.vlay.addWidget(self.gerber_opt_group)
self.vlay.addWidget(self.gerber_exp_group)
@ -3620,7 +3613,6 @@ class GeneralGUISetGroupUI(OptionsGroupUI):
# Create a form layout for the Application general settings
self.form_box = QtWidgets.QFormLayout()
# Layout selection
self.layout_label = QtWidgets.QLabel(_('Layout:'))
self.layout_label.setToolTip(
@ -4047,7 +4039,6 @@ class GerberOptPrefGroupUI(OptionsGroupUI):
self.setTitle(str(_("Gerber Options")))
# ## Isolation Routing
self.isolation_routing_label = QtWidgets.QLabel(_("<b>Isolation Routing:</b>"))
self.isolation_routing_label.setToolTip(
@ -4172,7 +4163,6 @@ class GerberAdvOptPrefGroupUI(OptionsGroupUI):
self.setTitle(str(_("Gerber Adv. Options")))
# ## Advanced Gerber Parameters
self.adv_param_label = QtWidgets.QLabel(_("<b>Advanced Param.:</b>"))
self.adv_param_label.setToolTip(
@ -4191,7 +4181,6 @@ class GerberAdvOptPrefGroupUI(OptionsGroupUI):
_("Generate a 'Follow' geometry.\n"
"This means that it will cut through\n"
"the middle of the trace.")
)
grid0.addWidget(self.follow_cb, 0, 0)
@ -4732,7 +4721,6 @@ class ExcellonOptPrefGroupUI(OptionsGroupUI):
self.pp_excellon_name_cb.setFocusPolicy(Qt.StrongFocus)
grid2.addWidget(self.pp_excellon_name_cb, 9, 1)
# ### Choose what to use for Gcode creation: Drills, Slots or Both
excellon_gcode_type_label = QtWidgets.QLabel(_('<b>Gcode: </b>'))
excellon_gcode_type_label.setToolTip(
@ -4796,9 +4784,9 @@ class ExcellonAdvOptPrefGroupUI(OptionsGroupUI):
self.setTitle(str(_("Excellon Adv. Options")))
#################### ##
# #######################
# ## ADVANCED OPTIONS ###
#################### ##
# #######################
self.cncjob_label = QtWidgets.QLabel(_('<b>Advanced Options:</b>'))
self.cncjob_label.setToolTip(
@ -5089,7 +5077,7 @@ class ExcellonEditorPrefGroupUI(OptionsGroupUI):
grid0.addWidget(self.drill_array_linear_label, 3, 0, 1, 2)
# Linear Drill Array direction
self.drill_axis_label = QtWidgets.QLabel(_('Direction:'))
self.drill_axis_label = QtWidgets.QLabel(_('Linear Dir.:'))
self.drill_axis_label.setToolTip(
_("Direction on which the linear array is oriented:\n"
"- 'X' - horizontal axis \n"
@ -5115,9 +5103,42 @@ class ExcellonEditorPrefGroupUI(OptionsGroupUI):
grid0.addWidget(self.drill_pitch_label, 5, 0)
grid0.addWidget(self.drill_pitch_entry, 5, 1)
# Linear Drill Array custom angle
self.drill_angle_label = QtWidgets.QLabel(_('Angle:'))
self.drill_angle_label.setToolTip(
_("Angle at which each element in circular array is placed.")
)
self.drill_angle_entry = LengthEntry()
grid0.addWidget(self.drill_angle_label, 6, 0)
grid0.addWidget(self.drill_angle_entry, 6, 1)
self.drill_array_circ_label = QtWidgets.QLabel(_('<b>Circular Drill Array:</b>'))
grid0.addWidget(self.drill_array_circ_label, 7, 0, 1, 2)
# Circular Drill Array direction
self.drill_circular_direction_label = QtWidgets.QLabel(_('Circular Dir.:'))
self.drill_circular_direction_label.setToolTip(
_("Direction for circular array."
"Can be CW = clockwise or CCW = counter clockwise.")
)
self.drill_circular_dir_radio = RadioSet([{'label': 'CW', 'value': 'CW'},
{'label': 'CCW.', 'value': 'CCW'}])
grid0.addWidget(self.drill_circular_direction_label, 8, 0)
grid0.addWidget(self.drill_circular_dir_radio, 8, 1)
# Circular Drill Array Angle
self.drill_circular_angle_label = QtWidgets.QLabel(_('Circ. Angle:'))
self.drill_circular_angle_label.setToolTip(
_("Angle at which each element in circular array is placed.")
)
self.drill_circular_angle_entry = LengthEntry()
grid0.addWidget(self.drill_circular_angle_label, 9, 0)
grid0.addWidget(self.drill_circular_angle_entry, 9, 1)
self.layout.addStretch()
@ -5539,8 +5560,7 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI):
# Display Annotation
self.annotation_label = QtWidgets.QLabel(_("Display Annotation:"))
self.annotation_label.setToolTip(
_(
"This selects if to display text annotation on the plot.\n"
_("This selects if to display text annotation on the plot.\n"
"When checked it will display numbers in order for each end\n"
"of a travel line."
)
@ -5735,7 +5755,8 @@ class CNCJobAdvOptPrefGroupUI(OptionsGroupUI):
self.tc_variable_combo.setItemData(8, _("z_move = Z height for travel"), Qt.ToolTipRole)
self.tc_variable_combo.setItemData(9, _("z_depthpercut = the step value for multidepth cut"), Qt.ToolTipRole)
self.tc_variable_combo.setItemData(10, _("spindlesspeed = the value for the spindle speed"), Qt.ToolTipRole)
self.tc_variable_combo.setItemData(11, _("dwelltime = time to dwell to allow the spindle to reach it's set RPM"),
self.tc_variable_combo.setItemData(11,
_("dwelltime = time to dwell to allow the spindle to reach it's set RPM"),
Qt.ToolTipRole)
hlay1.addStretch()