- fixed issue when plotting a CNCJob object with multiple tools and annotations on by plotting annotations after all the tools geometries are plotted

This commit is contained in:
Marius Stanciu 2020-08-26 22:58:40 +03:00
parent 9696e8faad
commit a823de9f98
3 changed files with 95 additions and 77 deletions

View File

@ -19,6 +19,7 @@ CHANGELOG for FlatCAM beta
- Isolation Tool - modified the add new tool method to search first in Tools Database for a suitable tool - Isolation Tool - modified the add new tool method to search first in Tools Database for a suitable tool
- Isolation Tool - added ability to find the tool diameter that will guarantee total isolation of the currently selected Gerber object - Isolation Tool - added ability to find the tool diameter that will guarantee total isolation of the currently selected Gerber object
- NCC Tool - UI change: if the operation is Isolation then some of the tool parameters are disabled - NCC Tool - UI change: if the operation is Isolation then some of the tool parameters are disabled
- fixed issue when plotting a CNCJob object with multiple tools and annotations on by plotting annotations after all the tools geometries are plotted
25.08.2020 25.08.2020

View File

@ -142,6 +142,8 @@ class CNCJobObject(FlatCAMObj, CNCjob):
self.coords_decimals = 4 self.coords_decimals = 4
self.fr_decimals = 2 self.fr_decimals = 2
self.annotations_dict = {}
# used for parsing the GCode lines to adjust the GCode when the GCode is offseted or scaled # used for parsing the GCode lines to adjust the GCode when the GCode is offseted or scaled
gcodex_re_string = r'(?=.*(X[-\+]?\d*\.\d*))' gcodex_re_string = r'(?=.*(X[-\+]?\d*\.\d*))'
self.g_x_re = re.compile(gcodex_re_string) self.g_x_re = re.compile(gcodex_re_string)
@ -2244,13 +2246,7 @@ class CNCJobObject(FlatCAMObj, CNCjob):
visible = visible if visible else self.options['plot'] visible = visible if visible else self.options['plot']
if self.app.is_legacy is False: # Geometry shapes plotting
if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
self.text_col.enabled = True
else:
self.text_col.enabled = False
self.annotation.redraw()
try: try:
if self.multitool is False: # single tool usage if self.multitool is False: # single tool usage
try: try:
@ -2286,6 +2282,20 @@ class CNCJobObject(FlatCAMObj, CNCjob):
if self.app.is_legacy is False: if self.app.is_legacy is False:
self.annotation.clear(update=True) self.annotation.clear(update=True)
# Annotaions shapes plotting
try:
if self.app.is_legacy is False:
if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
self.plot_annotations(obj=self, visible=True)
else:
self.plot_annotations(obj=self, visible=False)
except (ObjectDeleted, AttributeError):
if self.app.is_legacy is False:
self.annotation.clear(update=True)
def on_annotation_change(self): def on_annotation_change(self):
""" """
Handler for toggling the annotation display by clicking a checkbox. Handler for toggling the annotation display by clicking a checkbox.

103
camlib.py
View File

@ -6570,7 +6570,6 @@ class CNCjob(Geometry):
} }
gcode_parsed = gcode_parsed if gcode_parsed else self.gcode_parsed gcode_parsed = gcode_parsed if gcode_parsed else self.gcode_parsed
path_num = 0
if tooldia is None: if tooldia is None:
tooldia = self.tooldia tooldia = self.tooldia
@ -6590,24 +6589,36 @@ class CNCjob(Geometry):
if geo['kind'][0] == 'C': if geo['kind'][0] == 'C':
obj.add_shape(shape=geo['geom'], color=color['C'][1], visible=visible) obj.add_shape(shape=geo['geom'], color=color['C'][1], visible=visible)
else: else:
text = [] path_num = 0
pos = []
self.coordinates_type = self.app.defaults["cncjob_coords_type"] self.coordinates_type = self.app.defaults["cncjob_coords_type"]
if self.coordinates_type == "G90": if self.coordinates_type == "G90":
# For Absolute coordinates type G90 # For Absolute coordinates type G90
for geo in gcode_parsed: for geo in gcode_parsed:
if geo['kind'][0] == 'T': if geo['kind'][0] == 'T':
current_position = geo['geom'].coords[0] start_position = geo['geom'].coords[0]
if current_position not in pos:
pos.append(current_position)
path_num += 1
text.append(str(path_num))
current_position = geo['geom'].coords[-1] if tooldia not in obj.annotations_dict:
if current_position not in pos: obj.annotations_dict[tooldia] = {
pos.append(current_position) 'pos': [],
'text': []
}
if start_position not in obj.annotations_dict[tooldia]['pos']:
path_num += 1 path_num += 1
text.append(str(path_num)) obj.annotations_dict[tooldia]['pos'].append(start_position)
obj.annotations_dict[tooldia]['text'].append(str(path_num))
end_position = geo['geom'].coords[-1]
if tooldia not in obj.annotations_dict:
obj.annotations_dict[tooldia] = {
'pos': [],
'text': []
}
if end_position not in obj.annotations_dict[tooldia]['pos']:
path_num += 1
obj.annotations_dict[tooldia]['pos'].append(end_position)
obj.annotations_dict[tooldia]['text'].append(str(path_num))
# plot the geometry of Excellon objects # plot the geometry of Excellon objects
if self.origin_kind == 'excellon': if self.origin_kind == 'excellon':
@ -6640,46 +6651,38 @@ class CNCjob(Geometry):
obj.add_shape(shape=poly, color=color['C'][1], face_color=color['C'][0], obj.add_shape(shape=poly, color=color['C'][1], face_color=color['C'][0],
visible=visible, layer=1) visible=visible, layer=1)
else: else:
# For Incremental coordinates type G91 self.app.inform.emit('[ERROR_NOTCL] %s...' % _('G91 coordinates not implemented'))
self.app.inform.emit('[ERROR_NOTCL] %s' % _('G91 coordinates not implemented ...')) return 'fail'
for geo in gcode_parsed:
if geo['kind'][0] == 'T':
current_position = geo['geom'].coords[0]
if current_position not in pos:
pos.append(current_position)
path_num += 1
text.append(str(path_num))
current_position = geo['geom'].coords[-1] def plot_annotations(self, obj, visible=True):
if current_position not in pos: """
pos.append(current_position) Plot annotations.
path_num += 1
text.append(str(path_num))
# plot the geometry of Excellon objects :param obj: FlatCAM CNCJob object for which to plot the annotations
if self.origin_kind == 'excellon': :type obj:
try: :param visible: annotaions visibility
poly = Polygon(geo['geom']) :type visible: bool
except ValueError: :return: Nothing
# if the geos are travel lines it will enter into Exception :rtype:
poly = geo['geom'].buffer(distance=(tooldia / 1.99999999), resolution=self.steps_per_circle) """
poly = poly.simplify(tool_tolerance)
if not obj.annotations_dict:
return
if visible is True:
obj.text_col.enabled = True
else: else:
# plot the geometry of any objects other than Excellon obj.text_col.enabled = False
poly = geo['geom'].buffer(distance=(tooldia / 1.99999999), resolution=self.steps_per_circle) return
poly = poly.simplify(tool_tolerance)
if kind == 'all': text = []
obj.add_shape(shape=poly, color=color[geo['kind'][0]][1], face_color=color[geo['kind'][0]][0], pos = []
visible=visible, layer=1 if geo['kind'][0] == 'C' else 2) for tooldia in obj.annotations_dict:
elif kind == 'travel': pos += obj.annotations_dict[tooldia]['pos']
if geo['kind'][0] == 'T': text += obj.annotations_dict[tooldia]['text']
obj.add_shape(shape=poly, color=color['T'][1], face_color=color['T'][0],
visible=visible, layer=2) if not text or not pos:
elif kind == 'cut': return
if geo['kind'][0] == 'C':
obj.add_shape(shape=poly, color=color['C'][1], face_color=color['C'][0],
visible=visible, layer=1)
try: try:
if self.app.defaults['global_theme'] == 'white': if self.app.defaults['global_theme'] == 'white':
@ -6704,6 +6707,10 @@ class CNCjob(Geometry):
color=new_color) color=new_color)
except Exception as e: except Exception as e:
log.debug("CNCJob.plot2() --> annotations --> %s" % str(e)) log.debug("CNCJob.plot2() --> annotations --> %s" % str(e))
if self.app.is_legacy is False:
obj.annotation.clear(update=True)
obj.annotation.redraw()
def create_geometry(self): def create_geometry(self):
""" """