Код: Выделить всё
class GLCanon(Translated, ArcsToSegmentsMixin):
lineno = -1
def __init__(self, colors, geometry, is_foam=0):
# traverse list - [line number, [start position], [end position], [tlo x, tlo y, tlo z]]
self.traverse = []; self.traverse_append = self.traverse.append
# feed list - [line number, [start position], [end position], feedrate, [tlo x, tlo y, tlo z]]
self.feed = []; self.feed_append = self.feed.append
# arcfeed list - [line number, [start position], [end position], feedrate, [tlo x, tlo y, tlo z]]
self.arcfeed = []; self.arcfeed_append = self.arcfeed.append
# dwell list - [line number, color, pos x, pos y, pos z, plane]
self.dwells = []; self.dwells_append = self.dwells.append
self.choice = None
self.feedrate = 1
self.lo = (0,) * 9
self.first_move = True
self.geometry = geometry
self.min_extents = [9e99,9e99,9e99]
self.max_extents = [-9e99,-9e99,-9e99]
self.min_extents_notool = [9e99,9e99,9e99]
self.max_extents_notool = [-9e99,-9e99,-9e99]
self.colors = colors
self.in_arc = 0
self.xo = self.yo = self.zo = self.ao = self.bo = self.co = self.uo = self.vo = self.wo = 0
self.dwell_time = 0
self.suppress = 0
self.g92_offset_x = 0.0
self.g92_offset_y = 0.0
self.g92_offset_z = 0.0
self.g92_offset_a = 0.0
self.g92_offset_b = 0.0
self.g92_offset_c = 0.0
self.g92_offset_u = 0.0
self.g92_offset_v = 0.0
self.g92_offset_w = 0.0
self.g5x_index = 1
self.g5x_offset_x = 0.0
self.g5x_offset_y = 0.0
self.g5x_offset_z = 0.0
self.g5x_offset_a = 0.0
self.g5x_offset_b = 0.0
self.g5x_offset_c = 0.0
self.g5x_offset_u = 0.0
self.g5x_offset_v = 0.0
self.g5x_offset_w = 0.0
self.is_foam = is_foam
self.foam_z = 0
self.foam_w = 1.5
self.notify = 0
self.notify_message = ""
def comment(self, arg):
if arg.startswith("AXIS,"):
parts = arg.split(",")
command = parts[1]
if command == "stop": raise KeyboardInterrupt
if command == "hide": self.suppress += 1
if command == "show": self.suppress -= 1
if command == "XY_Z_POS":
if len(parts) > 2 :
try:
self.foam_z = float(parts[2])
if 210 in self.state.gcodes:
self.foam_z = self.foam_z / 25.4
except:
self.foam_z = 5.0/25.4
if command == "UV_Z_POS":
if len(parts) > 2 :
try:
self.foam_w = float(parts[2])
if 210 in self.state.gcodes:
self.foam_w = self.foam_w / 25.4
except:
self.foam_w = 30.0
if command == "notify":
self.notify = self.notify + 1
self.notify_message = "(AXIS,notify):" + str(self.notify)
if len(parts) > 2:
if len(parts[2]): self.notify_message = parts[2]
def message(self, message): pass
def check_abort(self): pass
def next_line(self, st):
self.state = st
self.lineno = self.state.sequence_number
def draw_lines(self, lines, for_selection, j=0, geometry=None):
return linuxcnc.draw_lines(geometry or self.geometry, lines, for_selection)
def colored_lines(self, color, lines, for_selection, j=0):
if self.is_foam:
if not for_selection:
self.color_with_alpha(color + "_xy")
glPushMatrix()
glTranslatef(0, 0, self.foam_z)
self.draw_lines(lines, for_selection, 2*j, 'XY')
glPopMatrix()
if not for_selection:
self.color_with_alpha(color + "_uv")
glPushMatrix()
glTranslatef(0, 0, self.foam_w)
self.draw_lines(lines, for_selection, 2*j+len(lines), 'UV')
glPopMatrix()
else:
if not for_selection:
self.color_with_alpha(color)
self.draw_lines(lines, for_selection, j)
def draw_dwells(self, dwells, alpha, for_selection, j0=0):
return linuxcnc.draw_dwells(self.geometry, dwells, alpha, for_selection, self.is_lathe())
def calc_extents(self):
self.min_extents, self.max_extents, self.min_extents_notool, self.max_extents_notool = gcode.calc_extents(self.arcfeed, self.feed, self.traverse)
if self.is_foam:
min_z = min(self.foam_z, self.foam_w)
max_z = max(self.foam_z, self.foam_w)
self.min_extents = self.min_extents[0], self.min_extents[1], min_z
self.max_extents = self.max_extents[0], self.max_extents[1], max_z
self.min_extents_notool = \
self.min_extents_notool[0], self.min_extents_notool[1], min_z
self.max_extents_notool = \
self.max_extents_notool[0], self.max_extents_notool[1], max_z
def tool_offset(self, xo, yo, zo, ao, bo, co, uo, vo, wo):
self.first_move = True
x, y, z, a, b, c, u, v, w = self.lo
self.lo = (x - xo + self.xo, y - yo + self.yo, z - zo + self.zo, a - ao + self.ao, b - bo + self.bo, c - bo + self.bo,
u - uo + self.uo, v - vo + self.vo, w - wo + self.wo)
self.xo = xo
self.yo = yo
self.zo = zo
self.so = ao
self.bo = bo
self.co = co
self.uo = uo
self.vo = vo
self.wo = wo
def set_spindle_rate(self, arg): pass
def set_feed_rate(self, arg): self.feedrate = arg / 60.
def select_plane(self, arg): pass
def change_tool(self, arg):
self.first_move = True
def straight_traverse(self, x,y,z, a,b,c, u, v, w):
if self.suppress > 0: return
l = self.rotate_and_translate(x,y,z,a,b,c,u,v,w)
if not self.first_move:
self.traverse_append((self.lineno, self.lo, l, [self.xo, self.yo, self.zo]))
self.lo = l
def rigid_tap(self, x, y, z):
if self.suppress > 0: return
self.first_move = False
l = self.rotate_and_translate(x,y,z,0,0,0,0,0,0)[:3]
l += [self.lo[3], self.lo[4], self.lo[5],
self.lo[6], self.lo[7], self.lo[8]]
self.feed_append((self.lineno, self.lo, l, self.feedrate, [self.xo, self.yo, self.zo]))
# self.dwells_append((self.lineno, self.colors['dwell'], x + self.offset_x, y + self.offset_y, z + self.offset_z, 0))
self.feed_append((self.lineno, l, self.lo, self.feedrate, [self.xo, self.yo, self.zo]))
def arc_feed(self, *args):
if self.suppress > 0: return
self.first_move = False
self.in_arc = True
try:
ArcsToSegmentsMixin.arc_feed(self, *args)
finally:
self.in_arc = False
def straight_arcsegments(self, segs):
self.first_move = False
lo = self.lo
lineno = self.lineno
feedrate = self.feedrate
to = [self.xo, self.yo, self.zo]
append = self.arcfeed_append
for l in segs:
append((lineno, lo, l, feedrate, to))
lo = l
self.lo = lo
def straight_feed(self, x,y,z, a,b,c, u, v, w):
if self.suppress > 0: return
self.first_move = False
l = self.rotate_and_translate(x,y,z,a,b,c,u,v,w)
self.feed_append((self.lineno, self.lo, l, self.feedrate, [self.xo, self.yo, self.zo]))
self.lo = l
straight_probe = straight_feed
def user_defined_function(self, i, p, q):
if self.suppress > 0: return
color = self.colors['m1xx']
self.dwells_append((self.lineno, color, self.lo[0], self.lo[1], self.lo[2], self.state.plane/10-17))
def dwell(self, arg):
if self.suppress > 0: return
self.dwell_time += arg
color = self.colors['dwell']
self.dwells_append((self.lineno, color, self.lo[0], self.lo[1], self.lo[2], self.state.plane/10-17))
def highlight(self, lineno, geometry):
glLineWidth(3)
c = self.colors['selected']
glColor3f(*c)
glBegin(GL_LINES)
coords = []
for line in self.traverse:
if line[0] != lineno: continue
linuxcnc.line9(geometry, line[1], line[2])
coords.append(line[1][:3])
coords.append(line[2][:3])
for line in self.arcfeed:
if line[0] != lineno: continue
linuxcnc.line9(geometry, line[1], line[2])
coords.append(line[1][:3])
coords.append(line[2][:3])
for line in self.feed:
if line[0] != lineno: continue
linuxcnc.line9(geometry, line[1], line[2])
coords.append(line[1][:3])
coords.append(line[2][:3])
glEnd()
for line in self.dwells:
if line[0] != lineno: continue
self.draw_dwells([(line[0], c) + line[2:]], 2, 0)
coords.append(line[2:5])
glLineWidth(1)
if coords:
x = reduce(lambda x,y:x+y, [c[0] for c in coords]) / len(coords)
y = reduce(lambda x,y:x+y, [c[1] for c in coords]) / len(coords)
z = reduce(lambda x,y:x+y, [c[2] for c in coords]) / len(coords)
else:
x = (self.min_extents[0] + self.max_extents[0])/2
y = (self.min_extents[1] + self.max_extents[1])/2
z = (self.min_extents[2] + self.max_extents[2])/2
return x, y, z
def color_with_alpha(self, name):
glColor4f(*(self.colors[name] + (self.colors.get(name+'_alpha', 1/3.),)))
def color(self, name):
glColor3f(*self.colors[name])
def draw(self, for_selection=0, no_traverse=True):
if not no_traverse:
glEnable(GL_LINE_STIPPLE)
self.colored_lines('traverse', self.traverse, for_selection)
glDisable(GL_LINE_STIPPLE)
else:
self.colored_lines('straight_feed', self.feed, for_selection, len(self.traverse))
self.colored_lines('arc_feed', self.arcfeed, for_selection, len(self.traverse) + len(self.feed))
glLineWidth(2)
self.draw_dwells(self.dwells, self.colors.get('dwell_alpha', 1/3.), for_selection, len(self.traverse) + len(self.feed) + len(self.arcfeed))
glLineWidth(1)