jpcgt/flatcam/Beta слито с Beta

This commit is contained in:
Camellan 2020-05-10 19:35:17 +04:00
commit 6070d22353
16 changed files with 632 additions and 253 deletions

View File

@ -7,10 +7,24 @@ CHANGELOG for FlatCAM beta
=================================================
9.05.2020
- modified the GUI for Exclusion areas; now the shapes are displayed in a Table where they can be selected and deleted. Modification applied for Geometry Objects only (for now).
- fixed an error when converting units, error that acted when in those fields that accept lists of tools only one tool was added
- finished the GUI for exclusion areas both in the Excellon and Geometry Objects. Need to think if to make it visible only in Advanced Mode
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)
- removed the Apply theme button in the Preferences; it is now replaced by the more general buttons (either Save or Apply)
- added a confirmation/warning message when applying a new theme
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,62 @@ class App(QtCore.QObject):
def scale_defaults(sfactor):
for dim in dimensions:
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"] == '':
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
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])
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))
elif dim == 'geometry_cnctooldia':
if self.defaults["geometry_cnctooldia"] is None or self.defaults["geometry_cnctooldia"] == '':
elif dim in [
'geometry_cnctooldia', 'tools_ncctools', 'tools_solderpaste_tools'
]:
if self.defaults[dim] is None or self.defaults[dim] == '':
continue
if type(self.defaults["geometry_cnctooldia"]) is float:
tools_diameters = [self.defaults["geometry_cnctooldia"]]
else:
try:
self.defaults[dim] = float(self.defaults[dim])
tools_diameters = [self.defaults[dim]]
except ValueError:
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'] = ''
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"]]
self.defaults[dim] = ''
td_len = len(tools_diameters)
if td_len > 1:
for t in range(td_len):
tools_diameters[t] *= sfactor
self.defaults[dim] += "%.*f," % (self.decimals, tools_diameters[t])
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
tools_diameters[0] *= sfactor
self.defaults[dim] += "%.*f" % (self.decimals, tools_diameters[0])
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 +4439,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

@ -10,6 +10,7 @@
# File Modified (major mod): Marius Adrian Stanciu #
# Date: 11/4/2019 #
# ##########################################################
from PyQt5 import QtCore
from shapely.geometry import Polygon, MultiPolygon
@ -17,7 +18,6 @@ from flatcamGUI.VisPyVisuals import ShapeCollection
from FlatCAMTool import FlatCAMTool
import numpy as np
import re
import gettext
import FlatCAMTranslation as fcTranslate
@ -129,9 +129,13 @@ def color_variant(hex_color, bright_factor=1):
return "#" + "".join([i for i in new_rgb])
class ExclusionAreas:
class ExclusionAreas(QtCore.QObject):
e_shape_modified = QtCore.pyqtSignal()
def __init__(self, app):
super().__init__()
self.app = app
# Storage for shapes, storage that can be used by FlatCAm tools for utility geometry
@ -280,7 +284,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 +345,7 @@ class ExclusionAreas:
face_color = "#FF7400BF"
else:
color = "#098a8f"
face_color = "#098a8fBF"
face_color = "#FF7400BF"
FlatCAMTool.draw_selection_shape_polygon(
self, points=self.points,
@ -401,6 +405,7 @@ class ExclusionAreas:
'%s %s' % (_("Generate the CNC Job object."), _("With Exclusion areas."))
)
self.e_shape_modified.emit()
for k in self.exclusion_areas_storage:
print(k)
@ -476,7 +481,7 @@ class ExclusionAreas:
face_color = "#FF7400BF"
else:
color = "#098a8f"
face_color = "#098a8fBF"
face_color = "#FF7400BF"
# draw the utility geometry
if shape_type == "square":
@ -514,3 +519,52 @@ class ExclusionAreas:
FlatCAMTool.delete_moving_selection_shape(self)
self.app.delete_selection_shape()
FlatCAMTool.delete_tool_selection_shape(self, shapes_storage=self.exclusion_shapes)
self.app.inform.emit('[success] %s' % _("All exclusion zones deleted."))
def delete_sel_shapes(self, idxs):
"""
:param idxs: list of indexes in self.exclusion_areas_storage list to be deleted
:return:
"""
# delete all plotted shapes
FlatCAMTool.delete_tool_selection_shape(self, shapes_storage=self.exclusion_shapes)
# delete shapes
for idx in sorted(idxs, reverse=True):
del self.exclusion_areas_storage[idx]
# re-add what's left after deletion in first step
if self.obj_type == 'excellon':
color = "#FF7400"
face_color = "#FF7400BF"
else:
color = "#098a8f"
face_color = "#FF7400BF"
face_alpha = 0.3
color_t = face_color[:-2] + str(hex(int(face_alpha * 255)))[2:]
for geo_el in self.exclusion_areas_storage:
if isinstance(geo_el['shape'], Polygon):
self.exclusion_shapes.add(
geo_el['shape'], color=color, face_color=color_t, update=True, layer=0, tolerance=None)
if self.app.is_legacy is True:
self.exclusion_shapes.redraw()
if self.exclusion_areas_storage:
self.app.inform.emit('[success] %s' % _("Selected exclusion zones deleted."))
else:
# restore the default StyleSheet
self.cnc_button.setStyleSheet("")
# update the StyleSheet
self.cnc_button.setStyleSheet("""
QPushButton
{
font-weight: bold;
}
""")
self.cnc_button.setToolTip('%s' % _("Generate the CNC Job object."))
self.app.inform.emit('[success] %s' % _("All exclusion zones deleted."))

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

@ -2232,6 +2232,7 @@ class OptionalHideInputSection:
class FCTable(QtWidgets.QTableWidget):
drag_drop_sig = QtCore.pyqtSignal()
lost_focus = QtCore.pyqtSignal()
def __init__(self, drag_drop=False, protected_rows=None, parent=None):
super(FCTable, self).__init__(parent)
@ -2295,6 +2296,10 @@ class FCTable(QtWidgets.QTableWidget):
else:
QtWidgets.QTableWidget.mousePressEvent(self, event)
def focusOutEvent(self, event):
self.lost_focus.emit()
super().focusOutEvent(event)
def setupContextMenu(self):
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)

View File

@ -1292,8 +1292,12 @@ class ExcellonObjectUI(ObjectUI):
self.grid5.addWidget(pp_geo_label, 16, 0)
self.grid5.addWidget(self.pp_geo_name_cb, 16, 1)
# ------------------------------------------------------------------------------------------------------------
# ------------------------- EXCLUSION AREAS ------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------
# 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"
@ -1301,48 +1305,39 @@ class ExcellonObjectUI(ObjectUI):
"is forbidden."
)
)
self.grid5.addWidget(self.exclusion_cb, 17, 0, 1, 2)
self.grid5.addWidget(self.exclusion_cb, 20, 0, 1, 2)
# ------------------------------------------------------------------------------------------------------------
# ------------------------- EXCLUSION AREAS ------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------
self.exclusion_frame = QtWidgets.QFrame()
self.exclusion_frame.setContentsMargins(0, 0, 0, 0)
self.grid5.addWidget(self.exclusion_frame, 18, 0, 1, 2)
self.grid5.addWidget(self.exclusion_frame, 22, 0, 1, 2)
self.exclusion_box = QtWidgets.QVBoxLayout()
self.exclusion_box.setContentsMargins(0, 0, 0, 0)
self.exclusion_frame.setLayout(self.exclusion_box)
h_lay = QtWidgets.QHBoxLayout()
self.exclusion_box.addLayout(h_lay)
self.exclusion_table = FCTable()
self.exclusion_box.addWidget(self.exclusion_table)
self.exclusion_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
# Button Add Area
self.add_area_button = QtWidgets.QPushButton(_('Add area'))
self.add_area_button.setToolTip(_("Add an Exclusion Area."))
h_lay.addWidget(self.add_area_button)
self.exclusion_table.setColumnCount(4)
self.exclusion_table.setColumnWidth(0, 20)
self.exclusion_table.setHorizontalHeaderLabels(['#', _('Object'), _('Strategy'), _('Over Z')])
# Button Delete Area
self.delete_area_button = QtWidgets.QPushButton(_('Clear areas'))
self.delete_area_button.setToolTip(_("Delete all exclusion areas."))
h_lay.addWidget(self.delete_area_button)
self.exclusion_table.horizontalHeaderItem(0).setToolTip(_("This is the Area ID."))
self.exclusion_table.horizontalHeaderItem(1).setToolTip(
_("Type of the object where the exclusion area was added."))
self.exclusion_table.horizontalHeaderItem(2).setToolTip(
_("The strategy used for exclusion area. Go around the exclusion areas or over it."))
self.exclusion_table.horizontalHeaderItem(3).setToolTip(
_("If the strategy is to go over the area then this is the height at which the tool will go to avoid the "
"exclusion area."))
grid_l = QtWidgets.QGridLayout()
grid_l.setColumnStretch(0, 0)
grid_l.setColumnStretch(1, 1)
self.exclusion_box.addLayout(grid_l)
self.exclusion_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
# Area Selection shape
self.area_shape_label = QtWidgets.QLabel('%s:' % _("Shape"))
self.area_shape_label.setToolTip(
_("The kind of selection shape used for area selection.")
)
self.area_shape_radio = RadioSet([{'label': _("Square"), 'value': 'square'},
{'label': _("Polygon"), 'value': 'polygon'}])
grid_l.addWidget(self.area_shape_label, 0, 0)
grid_l.addWidget(self.area_shape_radio, 0, 1)
grid_a1 = QtWidgets.QGridLayout()
grid_a1.setColumnStretch(0, 0)
grid_a1.setColumnStretch(1, 1)
self.exclusion_box.addLayout(grid_a1)
# Chose Strategy
self.strategy_label = FCLabel('%s:' % _("Strategy"))
@ -1353,8 +1348,8 @@ class ExcellonObjectUI(ObjectUI):
self.strategy_radio = RadioSet([{'label': _('Over'), 'value': 'over'},
{'label': _('Around'), 'value': 'around'}])
grid_l.addWidget(self.strategy_label, 1, 0)
grid_l.addWidget(self.strategy_radio, 1, 1)
grid_a1.addWidget(self.strategy_label, 1, 0)
grid_a1.addWidget(self.strategy_radio, 1, 1)
# Over Z
self.over_z_label = FCLabel('%s:' % _("Over Z"))
@ -1364,17 +1359,45 @@ class ExcellonObjectUI(ObjectUI):
self.over_z_entry.set_range(0.000, 9999.9999)
self.over_z_entry.set_precision(self.decimals)
grid_l.addWidget(self.over_z_label, 2, 0)
grid_l.addWidget(self.over_z_entry, 2, 1)
grid_a1.addWidget(self.over_z_label, 2, 0)
grid_a1.addWidget(self.over_z_entry, 2, 1)
# Button Add Area
self.add_area_button = QtWidgets.QPushButton(_('Add area:'))
self.add_area_button.setToolTip(_("Add an Exclusion Area."))
# Area Selection shape
self.area_shape_radio = RadioSet([{'label': _("Square"), 'value': 'square'},
{'label': _("Polygon"), 'value': 'polygon'}])
self.area_shape_radio.setToolTip(
_("The kind of selection shape used for area selection.")
)
grid_a1.addWidget(self.add_area_button, 4, 0)
grid_a1.addWidget(self.area_shape_radio, 4, 1)
h_lay_1 = QtWidgets.QHBoxLayout()
self.exclusion_box.addLayout(h_lay_1)
# Button Delete All Areas
self.delete_area_button = QtWidgets.QPushButton(_('Delete All'))
self.delete_area_button.setToolTip(_("Delete all exclusion areas."))
# Button Delete Selected Areas
self.delete_sel_area_button = QtWidgets.QPushButton(_('Delete Selected'))
self.delete_sel_area_button.setToolTip(_("Delete all exclusion areas that are selected in the table."))
h_lay_1.addWidget(self.delete_area_button)
h_lay_1.addWidget(self.delete_sel_area_button)
self.ois_exclusion_exc = OptionalHideInputSection(self.exclusion_cb, [self.exclusion_frame])
# -------------------------- EXCLUSION AREAS END -------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------
self.ois_exclusion_geo = OptionalHideInputSection(self.exclusion_cb, [self.exclusion_frame])
separator_line = QtWidgets.QFrame()
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.grid5.addWidget(separator_line, 19, 0, 1, 2)
self.grid5.addWidget(separator_line, 25, 0, 1, 2)
# #################################################################
# ################# GRID LAYOUT 6 ###############################
@ -1391,7 +1414,7 @@ class ExcellonObjectUI(ObjectUI):
"for custom selection of tools."
))
self.grid6.addWidget(QtWidgets.QLabel(''), 1, 0, 1, 3)
# self.grid6.addWidget(QtWidgets.QLabel(''), 1, 0, 1, 3)
self.grid6.addWidget(warning_lbl, 2, 0, 1, 3)
self.generate_cnc_button = QtWidgets.QPushButton(_('Generate CNCJob object'))
@ -2103,8 +2126,12 @@ class GeometryObjectUI(ObjectUI):
# grid4.addWidget(QtWidgets.QLabel(''), 12, 0, 1, 2)
# ------------------------------------------------------------------------------------------------------------
# ------------------------- EXCLUSION AREAS ------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------
# 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"
@ -2114,9 +2141,6 @@ class GeometryObjectUI(ObjectUI):
)
grid4.addWidget(self.exclusion_cb, 12, 0, 1, 2)
# ------------------------------------------------------------------------------------------------------------
# ------------------------- EXCLUSION AREAS ------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------
self.exclusion_frame = QtWidgets.QFrame()
self.exclusion_frame.setContentsMargins(0, 0, 0, 0)
grid4.addWidget(self.exclusion_frame, 14, 0, 1, 2)
@ -2125,35 +2149,29 @@ class GeometryObjectUI(ObjectUI):
self.exclusion_box.setContentsMargins(0, 0, 0, 0)
self.exclusion_frame.setLayout(self.exclusion_box)
h_lay = QtWidgets.QHBoxLayout()
self.exclusion_box.addLayout(h_lay)
self.exclusion_table = FCTable()
self.exclusion_box.addWidget(self.exclusion_table)
self.exclusion_table.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
# Button Add Area
self.add_area_button = QtWidgets.QPushButton(_('Add area'))
self.add_area_button.setToolTip(_("Add an Exclusion Area."))
h_lay.addWidget(self.add_area_button)
self.exclusion_table.setColumnCount(4)
self.exclusion_table.setColumnWidth(0, 20)
self.exclusion_table.setHorizontalHeaderLabels(['#', _('Object'), _('Strategy'), _('Over Z')])
# Button Delete Area
self.delete_area_button = QtWidgets.QPushButton(_('Clear areas'))
self.delete_area_button.setToolTip(_("Delete all exclusion areas."))
h_lay.addWidget(self.delete_area_button)
self.exclusion_table.horizontalHeaderItem(0).setToolTip(_("This is the Area ID."))
self.exclusion_table.horizontalHeaderItem(1).setToolTip(
_("Type of the object where the exclusion area was added."))
self.exclusion_table.horizontalHeaderItem(2).setToolTip(
_("The strategy used for exclusion area. Go around the exclusion areas or over it."))
self.exclusion_table.horizontalHeaderItem(3).setToolTip(
_("If the strategy is to go over the area then this is the height at which the tool will go to avoid the "
"exclusion area."))
grid_l = QtWidgets.QGridLayout()
grid_l.setColumnStretch(0, 0)
grid_l.setColumnStretch(1, 1)
self.exclusion_box.addLayout(grid_l)
self.exclusion_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
# Area Selection shape
self.area_shape_label = QtWidgets.QLabel('%s:' % _("Shape"))
self.area_shape_label.setToolTip(
_("The kind of selection shape used for area selection.")
)
self.area_shape_radio = RadioSet([{'label': _("Square"), 'value': 'square'},
{'label': _("Polygon"), 'value': 'polygon'}])
grid_l.addWidget(self.area_shape_label, 0, 0)
grid_l.addWidget(self.area_shape_radio, 0, 1)
grid_a1 = QtWidgets.QGridLayout()
grid_a1.setColumnStretch(0, 0)
grid_a1.setColumnStretch(1, 1)
self.exclusion_box.addLayout(grid_a1)
# Chose Strategy
self.strategy_label = FCLabel('%s:' % _("Strategy"))
@ -2164,8 +2182,8 @@ class GeometryObjectUI(ObjectUI):
self.strategy_radio = RadioSet([{'label': _('Over'), 'value': 'over'},
{'label': _('Around'), 'value': 'around'}])
grid_l.addWidget(self.strategy_label, 1, 0)
grid_l.addWidget(self.strategy_radio, 1, 1)
grid_a1.addWidget(self.strategy_label, 1, 0)
grid_a1.addWidget(self.strategy_radio, 1, 1)
# Over Z
self.over_z_label = FCLabel('%s:' % _("Over Z"))
@ -2175,12 +2193,45 @@ class GeometryObjectUI(ObjectUI):
self.over_z_entry.set_range(0.000, 9999.9999)
self.over_z_entry.set_precision(self.decimals)
grid_l.addWidget(self.over_z_label, 2, 0)
grid_l.addWidget(self.over_z_entry, 2, 1)
grid_a1.addWidget(self.over_z_label, 2, 0)
grid_a1.addWidget(self.over_z_entry, 2, 1)
# Button Add Area
self.add_area_button = QtWidgets.QPushButton(_('Add area:'))
self.add_area_button.setToolTip(_("Add an Exclusion Area."))
# Area Selection shape
self.area_shape_radio = RadioSet([{'label': _("Square"), 'value': 'square'},
{'label': _("Polygon"), 'value': 'polygon'}])
self.area_shape_radio.setToolTip(
_("The kind of selection shape used for area selection.")
)
grid_a1.addWidget(self.add_area_button, 4, 0)
grid_a1.addWidget(self.area_shape_radio, 4, 1)
h_lay_1 = QtWidgets.QHBoxLayout()
self.exclusion_box.addLayout(h_lay_1)
# Button Delete All Areas
self.delete_area_button = QtWidgets.QPushButton(_('Delete All'))
self.delete_area_button.setToolTip(_("Delete all exclusion areas."))
# Button Delete Selected Areas
self.delete_sel_area_button = QtWidgets.QPushButton(_('Delete Selected'))
self.delete_sel_area_button.setToolTip(_("Delete all exclusion areas that are selected in the table."))
h_lay_1.addWidget(self.delete_area_button)
h_lay_1.addWidget(self.delete_sel_area_button)
self.ois_exclusion_geo = OptionalHideInputSection(self.exclusion_cb, [self.exclusion_frame])
# -------------------------- EXCLUSION AREAS END -------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------
self.ois_exclusion_geo = OptionalHideInputSection(self.exclusion_cb, [self.exclusion_frame])
separator_line2 = QtWidgets.QFrame()
separator_line2.setFrameShape(QtWidgets.QFrame.HLine)
separator_line2.setFrameShadow(QtWidgets.QFrame.Sunken)
grid4.addWidget(separator_line2, 15, 0, 1, 2)
warning_lbl = QtWidgets.QLabel(
_(
@ -2188,7 +2239,7 @@ class GeometryObjectUI(ObjectUI):
"Click the # header to select all, or Ctrl + LMB\n"
"for custom selection of tools."
))
grid4.addWidget(warning_lbl, 15, 0, 1, 2)
grid4.addWidget(warning_lbl, 16, 0, 1, 2)
# Button
self.generate_cnc_button = QtWidgets.QPushButton(_('Generate CNCJob object'))

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

@ -913,7 +913,39 @@ class PreferencesUIManager:
# make sure we update the self.current_defaults dict used to undo changes to self.defaults
self.defaults.current_defaults.update(self.defaults)
if save_to_file:
# deal with theme change
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
theme = theme_settings.value('theme', type=str)
else:
theme = 'white'
should_restart = False
val = self.ui.general_defaults_form.general_gui_group.theme_radio.get_value()
if val != theme:
msgbox = QtWidgets.QMessageBox()
msgbox.setText(_("Are you sure you want to continue?"))
msgbox.setWindowTitle(_("Application restart"))
msgbox.setWindowIcon(QtGui.QIcon(self.ui.app.resource_location + '/warning.png'))
bt_yes = msgbox.addButton(_('Yes'), QtWidgets.QMessageBox.YesRole)
msgbox.addButton(_('Cancel'), QtWidgets.QMessageBox.NoRole)
msgbox.setDefaultButton(bt_yes)
msgbox.exec_()
response = msgbox.clickedButton()
if response == bt_yes:
theme_settings.setValue('theme', val)
# This will write the setting to the platform specific storage.
del theme_settings
should_restart = True
else:
self.ui.general_defaults_form.general_gui_group.theme_radio.set_value(theme)
if save_to_file or should_restart is True:
self.save_defaults(silent=False)
# load the defaults so they are updated into the app
self.defaults.load(filename=os.path.join(self.data_path, 'current_defaults.FlatConfig'))
@ -951,6 +983,9 @@ class PreferencesUIManager:
self.ui.plot_tab_area.closeTab(idx)
break
if should_restart is True:
self.ui.app.on_app_restart()
def on_pref_close_button(self):
# Preferences saved, update flag
self.preferences_changed_flag = False

View File

@ -56,13 +56,13 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
)
grid0.addWidget(self.gray_icons_cb, 1, 0, 1, 3)
self.theme_button = FCButton(_("Apply Theme"))
self.theme_button.setToolTip(
_("Select a theme for FlatCAM.\n"
"It will theme the plot area.\n"
"The application will restart after change.")
)
grid0.addWidget(self.theme_button, 2, 0, 1, 3)
# self.theme_button = FCButton(_("Apply Theme"))
# self.theme_button.setToolTip(
# _("Select a theme for FlatCAM.\n"
# "It will theme the plot area.\n"
# "The application will restart after change.")
# )
# grid0.addWidget(self.theme_button, 2, 0, 1, 3)
separator_line = QtWidgets.QFrame()
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
@ -381,8 +381,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
self.layout.addStretch()
self.theme_button.clicked.connect(self.on_theme_change)
# #############################################################################
# ############################# GUI COLORS SIGNALS ############################
# #############################################################################
@ -418,23 +416,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI):
self.layout_combo.activated.connect(self.on_layout)
def on_theme_change(self):
val = self.theme_radio.get_value()
theme_settings = QtCore.QSettings("Open Source", "FlatCAM")
if theme_settings.contains("theme"):
theme = theme_settings.value('theme', type=str)
else:
theme = 'white'
if val != theme:
theme_settings.setValue('theme', val)
# This will write the setting to the platform specific storage.
del theme_settings
self.app.on_app_restart()
@staticmethod
def handle_style(style):
# set current style

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

@ -125,6 +125,10 @@ class ExcellonObject(FlatCAMObj, Excellon):
self.outline_color = self.app.defaults['excellon_plot_line']
self.alpha_level = 'bf'
# store here the state of the exclusion checkbox state to be restored after building the UI
# TODO add this in the sel.app.defaults dict and in Preferences
self.exclusion_area_cb_is_checked = False
# Attributes to be included in serialization
# Always append to it because it carries contents
# from predecessors.
@ -314,6 +318,15 @@ class ExcellonObject(FlatCAMObj, Excellon):
def build_ui(self):
FlatCAMObj.build_ui(self)
# Area Exception - exclusion shape added signal
# first disconnect it from any other object
try:
self.app.exc_areas.e_shape_modified.disconnect()
except (TypeError, AttributeError):
pass
# then connect it to the current build_ui() method
self.app.exc_areas.e_shape_modified.connect(self.update_exclusion_table)
self.units = self.app.defaults['units'].upper()
for row in range(self.ui.tools_table.rowCount()):
@ -514,6 +527,58 @@ class ExcellonObject(FlatCAMObj, Excellon):
"<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
)
# Build Exclusion Areas section
e_len = len(self.app.exc_areas.exclusion_areas_storage)
self.ui.exclusion_table.setRowCount(e_len)
area_id = 0
for area in range(e_len):
area_id += 1
area_dict = self.app.exc_areas.exclusion_areas_storage[area]
area_id_item = QtWidgets.QTableWidgetItem('%d' % int(area_id))
area_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 0, area_id_item) # Area id
object_item = QtWidgets.QTableWidgetItem('%s' % area_dict["obj_type"])
object_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 1, object_item) # Origin Object
strategy_item = QtWidgets.QTableWidgetItem('%s' % area_dict["strategy"])
strategy_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 2, strategy_item) # Strategy
overz_item = QtWidgets.QTableWidgetItem('%s' % area_dict["overz"])
overz_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 3, overz_item) # Over Z
self.ui.exclusion_table.resizeColumnsToContents()
self.ui.exclusion_table.resizeRowsToContents()
area_vheader = self.ui.exclusion_table.verticalHeader()
area_vheader.hide()
self.ui.exclusion_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
area_hheader = self.ui.exclusion_table.horizontalHeader()
area_hheader.setMinimumSectionSize(10)
area_hheader.setDefaultSectionSize(70)
area_hheader.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
area_hheader.resizeSection(0, 20)
area_hheader.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
area_hheader.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
area_hheader.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
# area_hheader.setStretchLastSection(True)
self.ui.exclusion_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.ui.exclusion_table.setColumnWidth(0, 20)
self.ui.exclusion_table.setMinimumHeight(self.ui.exclusion_table.getHeight())
self.ui.exclusion_table.setMaximumHeight(self.ui.exclusion_table.getHeight())
self.ui_connect()
def set_ui(self, ui):
@ -632,14 +697,21 @@ class ExcellonObject(FlatCAMObj, Excellon):
assert isinstance(self.ui, ExcellonObjectUI), \
"Expected a ExcellonObjectUI, got %s" % type(self.ui)
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
self.ui.generate_cnc_button.clicked.connect(self.on_create_cncjob_button_click)
self.ui.generate_milling_button.clicked.connect(self.on_generate_milling_button_click)
self.ui.generate_milling_slots_button.clicked.connect(self.on_generate_milling_slots_button_click)
# Exclusion areas signals
self.ui.exclusion_table.horizontalHeader().sectionClicked.connect(self.exclusion_table_toggle_all)
self.ui.exclusion_table.lost_focus.connect(self.clear_selection)
self.ui.exclusion_table.itemClicked.connect(self.draw_sel_shape)
self.ui.add_area_button.clicked.connect(self.on_add_area_click)
self.ui.delete_area_button.clicked.connect(self.on_clear_area_click)
self.ui.delete_sel_area_button.clicked.connect(self.on_delete_sel_areas)
self.ui.strategy_radio.activated_custom.connect(self.on_strategy)
self.on_operation_type(val='drill')
self.ui.operation_radio.activated_custom.connect(self.on_operation_type)
@ -1487,7 +1559,96 @@ class ExcellonObject(FlatCAMObj, Excellon):
solid_geo=solid_geo, obj_type=obj_type)
def on_clear_area_click(self):
if not self.app.exc_areas.exclusion_areas_storage:
self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. There are no exclusion areas to delete."))
return
self.app.exc_areas.on_clear_area_click()
self.app.exc_areas.e_shape_modified.emit()
def on_delete_sel_areas(self):
sel_model = self.ui.exclusion_table.selectionModel()
sel_indexes = sel_model.selectedIndexes()
# it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
# so the duplicate rows will not be added
sel_rows = set()
for idx in sel_indexes:
sel_rows.add(idx.row())
if not sel_rows:
self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. Nothing is selected."))
return
self.app.exc_areas.delete_sel_shapes(idxs=list(sel_rows))
self.app.exc_areas.e_shape_modified.emit()
def draw_sel_shape(self):
sel_model = self.ui.exclusion_table.selectionModel()
sel_indexes = sel_model.selectedIndexes()
# it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
sel_rows = set()
for idx in sel_indexes:
sel_rows.add(idx.row())
self.delete_sel_shape()
if self.app.is_legacy is False:
face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.2 * 255)))[2:]
outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(0.8 * 255)))[2:]
else:
face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.4 * 255)))[2:]
outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(1.0 * 255)))[2:]
for row in sel_rows:
sel_rect = self.app.exc_areas.exclusion_areas_storage[row]['shape']
self.app.move_tool.sel_shapes.add(sel_rect, color=outline, face_color=face, update=True, layer=0,
tolerance=None)
if self.app.is_legacy is True:
self.app.move_tool.sel_shapes.redraw()
def clear_selection(self):
self.app.delete_selection_shape()
# self.ui.exclusion_table.clearSelection()
def delete_sel_shape(self):
self.app.delete_selection_shape()
def update_exclusion_table(self):
self.exclusion_area_cb_is_checked = True if self.ui.exclusion_cb.isChecked() else False
self.build_ui()
self.ui.exclusion_cb.set_value(self.exclusion_area_cb_is_checked)
def on_strategy(self, val):
if val == 'around':
self.ui.over_z_label.setDisabled(True)
self.ui.over_z_entry.setDisabled(True)
else:
self.ui.over_z_label.setDisabled(False)
self.ui.over_z_entry.setDisabled(False)
def exclusion_table_toggle_all(self):
"""
will toggle the selection of all rows in Exclusion Areas table
:return:
"""
sel_model = self.ui.exclusion_table.selectionModel()
sel_indexes = sel_model.selectedIndexes()
# it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
sel_rows = set()
for idx in sel_indexes:
sel_rows.add(idx.row())
if sel_rows:
self.ui.exclusion_table.clearSelection()
self.delete_sel_shape()
else:
self.ui.exclusion_table.selectAll()
self.draw_sel_shape()
def on_solid_cb_click(self, *args):
if self.muted_ui:

View File

@ -150,6 +150,10 @@ class GeometryObject(FlatCAMObj, Geometry):
self.param_fields = {}
# store here the state of the exclusion checkbox state to be restored after building the UI
# TODO add this in the sel.app.defaults dict and in Preferences
self.exclusion_area_cb_is_checked = False
# Attributes to be included in serialization
# Always append to it because it carries contents
# from predecessors.
@ -159,6 +163,15 @@ class GeometryObject(FlatCAMObj, Geometry):
self.ui_disconnect()
FlatCAMObj.build_ui(self)
# Area Exception - exclusion shape added signal
# first disconnect it from any other object
try:
self.app.exc_areas.e_shape_modified.disconnect()
except (TypeError, AttributeError):
pass
# then connect it to the current build_ui() method
self.app.exc_areas.e_shape_modified.connect(self.update_exclusion_table)
self.units = self.app.defaults['units']
tool_idx = 0
@ -179,7 +192,6 @@ class GeometryObject(FlatCAMObj, Geometry):
# For INCH the decimals should be no more than 3. There are no tools under 10mils.
dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooluid_value['tooldia'])))
dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
offset_item = FCComboBox()
@ -310,6 +322,58 @@ class GeometryObject(FlatCAMObj, Geometry):
"<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
)
# Build Exclusion Areas section
e_len = len(self.app.exc_areas.exclusion_areas_storage)
self.ui.exclusion_table.setRowCount(e_len)
area_id = 0
for area in range(e_len):
area_id += 1
area_dict = self.app.exc_areas.exclusion_areas_storage[area]
area_id_item = QtWidgets.QTableWidgetItem('%d' % int(area_id))
area_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 0, area_id_item) # Area id
object_item = QtWidgets.QTableWidgetItem('%s' % area_dict["obj_type"])
object_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 1, object_item) # Origin Object
strategy_item = QtWidgets.QTableWidgetItem('%s' % area_dict["strategy"])
strategy_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 2, strategy_item) # Strategy
overz_item = QtWidgets.QTableWidgetItem('%s' % area_dict["overz"])
overz_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.exclusion_table.setItem(area, 3, overz_item) # Over Z
self.ui.exclusion_table.resizeColumnsToContents()
self.ui.exclusion_table.resizeRowsToContents()
area_vheader = self.ui.exclusion_table.verticalHeader()
area_vheader.hide()
self.ui.exclusion_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
area_hheader = self.ui.exclusion_table.horizontalHeader()
area_hheader.setMinimumSectionSize(10)
area_hheader.setDefaultSectionSize(70)
area_hheader.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
area_hheader.resizeSection(0, 20)
area_hheader.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
area_hheader.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
area_hheader.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
# area_hheader.setStretchLastSection(True)
self.ui.exclusion_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.ui.exclusion_table.setColumnWidth(0, 20)
self.ui.exclusion_table.setMinimumHeight(self.ui.exclusion_table.getHeight())
self.ui.exclusion_table.setMaximumHeight(self.ui.exclusion_table.getHeight())
def set_ui(self, ui):
FlatCAMObj.set_ui(self, ui)
@ -534,8 +598,14 @@ class GeometryObject(FlatCAMObj, Geometry):
self.ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
self.ui.cutz_entry.returnPressed.connect(self.on_cut_z_changed)
# Exclusion areas signals
self.ui.exclusion_table.horizontalHeader().sectionClicked.connect(self.exclusion_table_toggle_all)
self.ui.exclusion_table.lost_focus.connect(self.clear_selection)
self.ui.exclusion_table.itemClicked.connect(self.draw_sel_shape)
self.ui.add_area_button.clicked.connect(self.on_add_area_click)
self.ui.delete_area_button.clicked.connect(self.on_clear_area_click)
self.ui.delete_sel_area_button.clicked.connect(self.on_delete_sel_areas)
self.ui.strategy_radio.activated_custom.connect(self.on_strategy)
def on_cut_z_changed(self):
self.old_cutz = self.ui.cutz_entry.get_value()
@ -2462,7 +2532,96 @@ class GeometryObject(FlatCAMObj, Geometry):
solid_geo=solid_geo, obj_type=obj_type)
def on_clear_area_click(self):
if not self.app.exc_areas.exclusion_areas_storage:
self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. There are no exclusion areas to delete."))
return
self.app.exc_areas.on_clear_area_click()
self.app.exc_areas.e_shape_modified.emit()
def on_delete_sel_areas(self):
sel_model = self.ui.exclusion_table.selectionModel()
sel_indexes = sel_model.selectedIndexes()
# it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
# so the duplicate rows will not be added
sel_rows = set()
for idx in sel_indexes:
sel_rows.add(idx.row())
if not sel_rows:
self.app.inform.emit("[WARNING_NOTCL] %s" % _("Delete failed. Nothing is selected."))
return
self.app.exc_areas.delete_sel_shapes(idxs=list(sel_rows))
self.app.exc_areas.e_shape_modified.emit()
def draw_sel_shape(self):
sel_model = self.ui.exclusion_table.selectionModel()
sel_indexes = sel_model.selectedIndexes()
# it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
sel_rows = set()
for idx in sel_indexes:
sel_rows.add(idx.row())
self.delete_sel_shape()
if self.app.is_legacy is False:
face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.2 * 255)))[2:]
outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(0.8 * 255)))[2:]
else:
face = self.app.defaults['global_sel_fill'][:-2] + str(hex(int(0.4 * 255)))[2:]
outline = self.app.defaults['global_sel_line'][:-2] + str(hex(int(1.0 * 255)))[2:]
for row in sel_rows:
sel_rect = self.app.exc_areas.exclusion_areas_storage[row]['shape']
self.app.move_tool.sel_shapes.add(sel_rect, color=outline, face_color=face, update=True, layer=0,
tolerance=None)
if self.app.is_legacy is True:
self.app.move_tool.sel_shapes.redraw()
def clear_selection(self):
self.app.delete_selection_shape()
# self.ui.exclusion_table.clearSelection()
def delete_sel_shape(self):
self.app.delete_selection_shape()
def update_exclusion_table(self):
self.exclusion_area_cb_is_checked = True if self.ui.exclusion_cb.isChecked() else False
self.build_ui()
self.ui.exclusion_cb.set_value(self.exclusion_area_cb_is_checked)
def on_strategy(self, val):
if val == 'around':
self.ui.over_z_label.setDisabled(True)
self.ui.over_z_entry.setDisabled(True)
else:
self.ui.over_z_label.setDisabled(False)
self.ui.over_z_entry.setDisabled(False)
def exclusion_table_toggle_all(self):
"""
will toggle the selection of all rows in Exclusion Areas table
:return:
"""
sel_model = self.ui.exclusion_table.selectionModel()
sel_indexes = sel_model.selectedIndexes()
# it will iterate over all indexes which means all items in all columns too but I'm interested only on rows
sel_rows = set()
for idx in sel_indexes:
sel_rows.add(idx.row())
if sel_rows:
self.ui.exclusion_table.clearSelection()
self.delete_sel_shape()
else:
self.ui.exclusion_table.selectAll()
self.draw_sel_shape()
def plot_element(self, element, color=None, visible=None):

View File

@ -186,11 +186,9 @@ class FlatCAMObj(QtCore.QObject):
def build_ui(self):
"""
Sets up the UI/form for this object. Show the UI
in the App.
Sets up the UI/form for this object. Show the UI in the App.
:return: None
:rtype: None
"""
self.muted_ui = True
@ -308,8 +306,8 @@ class FlatCAMObj(QtCore.QObject):
for option in self.options:
try:
self.set_form_item(option)
except Exception:
self.app.log.warning("Unexpected error:", sys.exc_info())
except Exception as err:
self.app.log.warning("Unexpected error: %s" % str(sys.exc_info()), str(err))
def read_form(self):
"""
@ -323,7 +321,7 @@ class FlatCAMObj(QtCore.QObject):
try:
self.read_form_item(option)
except Exception:
self.app.log.warning("Unexpected error:", sys.exc_info())
self.app.log.warning("Unexpected error: %s" % str(sys.exc_info()))
def set_form_item(self, option):
"""

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"])