- 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:
parent
9696e8faad
commit
a823de9f98
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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.
|
||||||
|
|
147
camlib.py
147
camlib.py
|
@ -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,70 +6651,66 @@ 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)
|
|
||||||
else:
|
|
||||||
# plot the geometry of any objects other than Excellon
|
|
||||||
poly = geo['geom'].buffer(distance=(tooldia / 1.99999999), resolution=self.steps_per_circle)
|
|
||||||
poly = poly.simplify(tool_tolerance)
|
|
||||||
|
|
||||||
if kind == 'all':
|
if not obj.annotations_dict:
|
||||||
obj.add_shape(shape=poly, color=color[geo['kind'][0]][1], face_color=color[geo['kind'][0]][0],
|
return
|
||||||
visible=visible, layer=1 if geo['kind'][0] == 'C' else 2)
|
|
||||||
elif kind == 'travel':
|
|
||||||
if geo['kind'][0] == 'T':
|
|
||||||
obj.add_shape(shape=poly, color=color['T'][1], face_color=color['T'][0],
|
|
||||||
visible=visible, layer=2)
|
|
||||||
elif kind == 'cut':
|
|
||||||
if geo['kind'][0] == 'C':
|
|
||||||
obj.add_shape(shape=poly, color=color['C'][1], face_color=color['C'][0],
|
|
||||||
visible=visible, layer=1)
|
|
||||||
|
|
||||||
try:
|
if visible is True:
|
||||||
if self.app.defaults['global_theme'] == 'white':
|
obj.text_col.enabled = True
|
||||||
obj.annotation.set(text=text, pos=pos, visible=obj.options['plot'],
|
else:
|
||||||
font_size=self.app.defaults["cncjob_annotation_fontsize"],
|
obj.text_col.enabled = False
|
||||||
color=self.app.defaults["cncjob_annotation_fontcolor"])
|
return
|
||||||
else:
|
|
||||||
# invert the color
|
|
||||||
old_color = self.app.defaults["cncjob_annotation_fontcolor"].lower()
|
|
||||||
new_color = ''
|
|
||||||
code = {}
|
|
||||||
l1 = "#;0123456789abcdef"
|
|
||||||
l2 = "#;fedcba9876543210"
|
|
||||||
for i in range(len(l1)):
|
|
||||||
code[l1[i]] = l2[i]
|
|
||||||
|
|
||||||
for x in range(len(old_color)):
|
text = []
|
||||||
new_color += code[old_color[x]]
|
pos = []
|
||||||
|
for tooldia in obj.annotations_dict:
|
||||||
|
pos += obj.annotations_dict[tooldia]['pos']
|
||||||
|
text += obj.annotations_dict[tooldia]['text']
|
||||||
|
|
||||||
obj.annotation.set(text=text, pos=pos, visible=obj.options['plot'],
|
if not text or not pos:
|
||||||
font_size=self.app.defaults["cncjob_annotation_fontsize"],
|
return
|
||||||
color=new_color)
|
|
||||||
except Exception as e:
|
try:
|
||||||
log.debug("CNCJob.plot2() --> annotations --> %s" % str(e))
|
if self.app.defaults['global_theme'] == 'white':
|
||||||
|
obj.annotation.set(text=text, pos=pos, visible=obj.options['plot'],
|
||||||
|
font_size=self.app.defaults["cncjob_annotation_fontsize"],
|
||||||
|
color=self.app.defaults["cncjob_annotation_fontcolor"])
|
||||||
|
else:
|
||||||
|
# invert the color
|
||||||
|
old_color = self.app.defaults["cncjob_annotation_fontcolor"].lower()
|
||||||
|
new_color = ''
|
||||||
|
code = {}
|
||||||
|
l1 = "#;0123456789abcdef"
|
||||||
|
l2 = "#;fedcba9876543210"
|
||||||
|
for i in range(len(l1)):
|
||||||
|
code[l1[i]] = l2[i]
|
||||||
|
|
||||||
|
for x in range(len(old_color)):
|
||||||
|
new_color += code[old_color[x]]
|
||||||
|
|
||||||
|
obj.annotation.set(text=text, pos=pos, visible=obj.options['plot'],
|
||||||
|
font_size=self.app.defaults["cncjob_annotation_fontsize"],
|
||||||
|
color=new_color)
|
||||||
|
except Exception as 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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue