- fixed MultiColor checkbox in Excellon Object to work in Legacy Mode (2D)

- modified the visibility change in Excellon UI to no longer do plot() when doing visibility toggle for one of the tools but only a visibility change in the shapes properties
This commit is contained in:
Marius Stanciu 2020-07-21 06:01:04 +03:00 committed by Marius
parent e99dd967fe
commit e57820f707
4 changed files with 84 additions and 82 deletions

View File

@ -11,6 +11,8 @@ CHANGELOG for FlatCAM beta
- updated the FCRadio class with a method that allow disabling certain options
- the Path optimization options for Excellon and Geometry objects are now available depending on the OS platform used (32bit vs 64bit)
- fixed MultiColor checkbox in Excellon Object to work in Legacy Mode (2D)
- modified the visibility change in Excellon UI to no longer do plot() when doing visibility toggle for one of the tools but only a visibility change in the shapes properties
20.07.2020

View File

@ -1272,6 +1272,7 @@ class ShapeCollectionLegacy:
'face_color': self._face_color,
'linewidth': line_width,
'alpha': self._alpha,
'visible': self._visible,
'shape': sh
})
@ -1285,6 +1286,7 @@ class ShapeCollectionLegacy:
'face_color': self._face_color,
'linewidth': line_width,
'alpha': self._alpha,
'visible': self._visible,
'shape': shape
})
@ -1336,19 +1338,20 @@ class ShapeCollectionLegacy:
except AttributeError:
obj_type = 'utility'
if self._visible:
# if we don't use this then when adding each new shape, the old ones will be added again, too
if obj_type == 'utility':
self.axes.patches.clear()
# if we don't use this then when adding each new shape, the old ones will be added again, too
# if obj_type == 'utility':
# self.axes.patches.clear()
self.axes.patches.clear()
for element in local_shapes:
for element in local_shapes:
if local_shapes[element]['visible'] is True:
if obj_type == 'excellon':
# Plot excellon (All polygons?)
if self.obj.options["solid"] and isinstance(local_shapes[element]['shape'], Polygon):
try:
patch = PolygonPatch(local_shapes[element]['shape'],
facecolor="#C40000",
edgecolor="#750000",
facecolor=local_shapes[element]['face_color'],
edgecolor=local_shapes[element]['color'],
alpha=local_shapes[element]['alpha'],
zorder=3,
linewidth=local_shapes[element]['linewidth']
@ -1546,6 +1549,17 @@ class ShapeCollectionLegacy:
self.redraw()
self._visible = value
def update_visibility(self, state, indexes=None):
if indexes:
for i in indexes:
if i in self._shapes:
self._shapes[i]['visible'] = state
else:
for i in self._shapes:
self._shapes[i]['visible'] = state
self.redraw()
@property
def enabled(self):
return self._visible

View File

@ -145,7 +145,9 @@ class ShapeGroup(object):
:param kwargs: keyword arguments
Arguments for ShapeCollection.add function
"""
self._indexes.append(self._collection.add(**kwargs))
key = self._collection.add(**kwargs)
self._indexes.append(key)
return key
def remove(self, idx, update=False):
self._indexes.remove(idx)
@ -196,6 +198,17 @@ class ShapeGroup(object):
self._collection.redraw([])
def update_visibility(self, state, indexes=None):
if indexes:
for i in indexes:
if i in self._indexes:
self._collection.data[i]['visible'] = state
else:
for i in self._indexes:
self._collection.data[i]['visible'] = state
self._collection.redraw([])
class ShapeCollectionVisual(CompoundVisual):
@ -326,6 +339,19 @@ class ShapeCollectionVisual(CompoundVisual):
if update:
self.__update()
def update_visibility(self, state:bool, indexes=None) -> None:
# Lock sub-visuals updates
self.update_lock.acquire(True)
if indexes is None:
for k, data in list(self.data.items()):
self.data[k]['visible'] = state
else:
for k, data in list(self.data.items()):
if k in indexes:
self.data[k]['visible'] = state
self.update_lock.release()
def update_color(self, new_mesh_color=None, new_line_color=None, indexes=None):
if new_mesh_color is None and new_line_color is None:
return
@ -533,7 +559,7 @@ class ShapeCollectionVisual(CompoundVisual):
self.results_lock.release()
if update_colors is None:
if update_colors is None or update_colors is False:
self.__update()
else:
try:

View File

@ -103,6 +103,9 @@ class ExcellonObject(FlatCAMObj, Excellon):
self.outline_color = self.app.defaults['excellon_plot_line']
self.alpha_level = 'bf'
# the key is the tool id and the value is a list of shapes keys (indexes)
self.shape_indexes_dict = {}
# Attributes to be included in serialization
# Always append to it because it carries contents
# from predecessors.
@ -1068,52 +1071,19 @@ class ExcellonObject(FlatCAMObj, Excellon):
self.ui_connect()
def on_plot_cb_click_table(self):
# self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
self.ui_disconnect()
# cw = self.sender()
# cw_index = self.ui.tools_table.indexAt(cw.pos())
# cw_row = cw_index.row()
check_row = 0
self.shapes.clear(update=True)
for tool_key in self.tools:
solid_geometry = self.tools[tool_key]['solid_geometry']
# find the geo_tool_table row associated with the tool_key
for row in range(self.ui.tools_table.rowCount()):
tool_item = int(self.ui.tools_table.item(row, 0).text())
if tool_item == int(tool_key):
check_row = row
break
if self.ui.tools_table.cellWidget(check_row, 5).isChecked():
self.options['plot'] = True
# self.plot_element(element=solid_geometry, visible=True)
# Plot excellon (All polygons?)
if self.options["solid"]:
for geo in solid_geometry:
self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
visible=self.options['plot'],
layer=2)
else:
for geo in solid_geometry:
self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
for ints in geo.interiors:
self.add_shape(shape=ints, color='green', visible=self.options['plot'])
state = self.ui.tools_table.cellWidget(check_row, 5).isChecked()
self.shapes.update_visibility(state, indexes=self.shape_indexes_dict[tool_key])
self.shapes.redraw()
# make sure that the general plot is disabled if one of the row plot's are disabled and
# if all the row plot's are enabled also enable the general plot checkbox
cb_cnt = 0
total_row = self.ui.tools_table.rowCount()
for row in range(total_row - 2):
if self.ui.tools_table.cellWidget(row, 5).isChecked():
cb_cnt += 1
else:
cb_cnt -= 1
if cb_cnt < total_row - 2:
self.ui.plot_cb.setChecked(False)
else:
self.ui.plot_cb.setChecked(True)
self.ui_connect()
def plot(self, visible=None, kind=None):
@ -1144,26 +1114,6 @@ class ExcellonObject(FlatCAMObj, Excellon):
break
return new_color
# try:
# # Plot Excellon (All polygons?)
# if self.options["solid"]:
# for tool in self.tools:
# for geo in self.tools[tool]['solid_geometry']:
# self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
# visible=self.options['plot'],
# layer=2)
# else:
# for tool in self.tools:
# for geo in self.tools[tool]['solid_geometry']:
# self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
# for ints in geo.interiors:
# self.add_shape(shape=ints, color='orange', visible=self.options['plot'])
#
# self.shapes.redraw()
# return
# except (ObjectDeleted, AttributeError, KeyError):
# self.shapes.clear(update=True)
# this stays for compatibility reasons, in case we try to open old projects
try:
__ = iter(self.solid_geometry)
@ -1175,13 +1125,6 @@ class ExcellonObject(FlatCAMObj, Excellon):
try:
# Plot Excellon (All polygons?)
if self.ui.solid_cb.get_value():
# for geo in self.solid_geometry:
# self.add_shape(shape=geo,
# color=self.outline_color,
# face_color=random_color() if self.options['multicolored'] else self.fill_color,
# visible=visible,
# layer=2)
# plot polygons for each tool separately
for tool in self.tools:
# set the color here so we have one color for each tool
@ -1190,20 +1133,37 @@ class ExcellonObject(FlatCAMObj, Excellon):
# tool is a dict also
for geo in self.tools[tool]["solid_geometry"]:
self.add_shape(shape=geo,
color=geo_color if multicolored else self.outline_color,
face_color=geo_color if multicolored else self.fill_color,
visible=visible,
layer=2)
idx = self.add_shape(shape=geo,
color=geo_color if multicolored else self.outline_color,
face_color=geo_color if multicolored else self.fill_color,
visible=visible,
layer=2)
try:
self.shape_indexes_dict[tool].append(idx)
except KeyError:
self.shape_indexes_dict[tool] = [idx]
else:
for geo in self.solid_geometry:
self.add_shape(shape=geo.exterior, color='red', visible=visible)
for ints in geo.interiors:
self.add_shape(shape=ints, color='orange', visible=visible)
for tool in self.tools:
for geo in self.tools[tool]['solid_geometry']:
idx = self.add_shape(shape=geo.exterior, color='red', visible=visible)
try:
self.shape_indexes_dict[tool].append(idx)
except KeyError:
self.shape_indexes_dict[tool] = [idx]
for ints in geo.interiors:
idx = self.add_shape(shape=ints, color='orange', visible=visible)
try:
self.shape_indexes_dict[tool].append(idx)
except KeyError:
self.shape_indexes_dict[tool] = [idx]
# for geo in self.solid_geometry:
# self.add_shape(shape=geo.exterior, color='red', visible=visible)
# for ints in geo.interiors:
# self.add_shape(shape=ints, color='orange', visible=visible)
self.shapes.redraw()
except (ObjectDeleted, AttributeError):
except (ObjectDeleted, AttributeError) as e:
log.debug("ExcellonObject.plot() -> %s" % str(e))
self.shapes.clear(update=True)
@staticmethod