Skip to content

Commit

Permalink
axis: optionally use a blend mode for preview plot
Browse files Browse the repository at this point in the history
Depending on the part program, the preview plot may be more useful when
it is drawn in a blended mode.  However, for other programs the old
style view might be preferable.  Add a blended drawing mode and make it
selectable at runtime.
  • Loading branch information
jepler committed Oct 27, 2010
1 parent df3f360 commit 6f29079
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
41 changes: 33 additions & 8 deletions lib/python/rs274/glcanon.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ def next_line(self, st):
def draw_lines(self, lines, for_selection, j=0):
return emc.draw_lines(self.geometry, lines, for_selection)

def draw_dwells(self, dwells, for_selection, j0=0):
return emc.draw_dwells(self.geometry, dwells, for_selection, self.is_lathe())

def draw_dwells(self, dwells, alpha, for_selection, j0=0):
return emc.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)
Expand Down Expand Up @@ -208,7 +207,7 @@ def highlight(self, lineno, geometry):
coords.append(line[2][:3])
for line in self.dwells:
if line[0] != lineno: continue
self.draw_dwells([(line[0], c) + line[2:]], 2)
self.draw_dwells([(line[0], c) + line[2:]], 2, 0)
coords.append(line[2:5])
glEnd()
glLineWidth(1)
Expand All @@ -222,21 +221,35 @@ def highlight(self, lineno, geometry):
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)
glColor3f(*self.colors['traverse'])
if for_selection:
self.color('traverse')
else:
self.color_with_alpha('traverse')
self.draw_lines(self.traverse, for_selection)
glDisable(GL_LINE_STIPPLE)
else:
glColor3f(*self.colors['straight_feed'])
if for_selection:
self.color('straight_feed')
else:
self.color_with_alpha('straight_feed')
self.draw_lines(self.feed, for_selection, len(self.traverse))

glColor3f(*self.colors['arc_feed'])
if for_selection:
self.color('arc_feed')
else:
self.color_with_alpha('arc_feed')
self.draw_lines(self.arcfeed, for_selection, len(self.traverse) + len(self.feed))

glLineWidth(2)
self.draw_dwells(self.dwells, for_selection, len(self.traverse) + len(self.feed) + len(self.arcfeed))
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)

def with_context(f):
Expand All @@ -262,6 +275,7 @@ def inner(self, *args, **kw):
class GlCanonDraw:
colors = {
'traverse': (0.30, 0.50, 0.50),
'traverse_alpha': 1/3.,
'backplotprobing_alpha': 0.75,
'backplotprobing': (0.63, 0.13, 0.94),
'backplottraverse': (0.30, 0.50, 0.50),
Expand All @@ -282,6 +296,7 @@ class GlCanonDraw:
'overlay_foreground': (1.00, 1.00, 1.00),
'overlay_background': (0.00, 0.00, 0.00),
'straight_feed': (1.00, 1.00, 1.00),
'straight_feed_alpha': 1/3.,
'small_origin': (0.00, 1.00, 1.00),
'backplottoolchange_alpha': 0.25,
'backplottraverse_alpha': 0.25,
Expand All @@ -294,6 +309,7 @@ class GlCanonDraw:
'backplotfeed_alpha': 0.75,
'backplotarc_alpha': 0.75,
'arc_feed': (1.00, 1.00, 1.00),
'arc_feed_alpha': .5,
'axis_y': (1.00, 0.20, 0.20),
}
def __init__(self, s, lp, g=None):
Expand Down Expand Up @@ -702,11 +718,20 @@ def redraw(self):
glMatrixMode(GL_MODELVIEW)

if self.get_show_program():
if self.get_program_alpha():
glDisable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

if self.get_show_rapids():
glCallList(self.dlist('program_rapids', gen=self.make_main_list))
glCallList(self.dlist('program_norapids', gen=self.make_main_list))
glCallList(self.dlist('highlight'))

if self.get_program_alpha():
glDisable(GL_BLEND)
glEnable(GL_DEPTH_TEST)

if self.get_show_extents():
self.show_extents()

Expand Down
5 changes: 5 additions & 0 deletions share/axis/tcl/axis.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ setup_menu_accel .menu.view end [_ "S_how program"]
-command toggle_show_rapids
setup_menu_accel .menu.view end [_ "Show program r_apids"]

.menu.view add checkbutton \
-variable program_alpha \
-command toggle_program_alpha
setup_menu_accel .menu.view end [_ "Alpha-_blend program"]

.menu.view add checkbutton \
-variable show_live_plot \
-command toggle_show_live_plot
Expand Down
6 changes: 4 additions & 2 deletions src/emc/usr_intf/axis/extensions/emcmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1707,10 +1707,11 @@ static PyObject *pydraw_lines(PyObject *s, PyObject *o) {
static PyObject *pydraw_dwells(PyObject *s, PyObject *o) {
PyListObject *li;
int for_selection = 0, is_lathe = 0, i, n;
double alpha;
char *geometry;
double delta = 0.015625;

if(!PyArg_ParseTuple(o, "sO!ii:draw_dwells", &geometry, &PyList_Type, &li, &for_selection, &is_lathe))
if(!PyArg_ParseTuple(o, "sO!dii:draw_dwells", &geometry, &PyList_Type, &li, &alpha, &for_selection, &is_lathe))
return NULL;

if (for_selection == 0)
Expand All @@ -1723,7 +1724,8 @@ static PyObject *pydraw_dwells(PyObject *s, PyObject *o) {
if(!PyArg_ParseTuple(it, "i(ddd)dddi", &n, &red, &green, &blue, &x, &y, &z, &axis)) {
return NULL;
}
glColor3f(red, green, blue);
if (for_selection != 1)
glColor4d(red, green, blue, alpha);
if (for_selection == 1) {
glLoadName(n);
glBegin(GL_LINES);
Expand Down
8 changes: 7 additions & 1 deletion src/emc/usr_intf/axis/scripts/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def get_show_commanded(self): return vars.display_type.get()
def get_show_rapids(self): return vars.show_rapids.get()
def get_geometry(self): return geometry
def get_num_joints(self): return num_joints
def get_program_alpha(self): return vars.program_alpha.get()

def get_a_axis_wrapped(self): return a_axis_wrapped
def get_b_axis_wrapped(self): return b_axis_wrapped
Expand Down Expand Up @@ -514,7 +515,6 @@ def actual_tkRedraw(self, *dummy):
self.tkRedraw_ortho()

def get_show_program(self): return vars.show_program.get()
def get_show_rapids(self): return vars.show_rapids.get()
def get_show_offsets(self): return vars.show_offsets.get()
def get_show_extents(self): return vars.show_extents.get()
def get_show_metric(self): return vars.metric.get()
Expand Down Expand Up @@ -2143,6 +2143,10 @@ def toggle_show_program(*event):
ap.putpref("show_program", vars.show_program.get())
o.tkRedraw()

def toggle_program_alpha(*event):
ap.putpref("program_alpha", vars.program_alpha.get())
o.tkRedraw()

def toggle_show_live_plot(*event):
ap.putpref("show_live_plot", vars.show_live_plot.get())
o.tkRedraw()
Expand Down Expand Up @@ -2462,6 +2466,7 @@ def goto_sensible_line():
("running_line", IntVar),
("highlight_line", IntVar),
("show_program", IntVar),
("program_alpha", IntVar),
("show_live_plot", IntVar),
("show_tool", IntVar),
("show_extents", IntVar),
Expand Down Expand Up @@ -2502,6 +2507,7 @@ def goto_sensible_line():
vars.tto_g11.set(ap.getpref("tto_g11", False))
vars.show_program.set(ap.getpref("show_program", True))
vars.show_rapids.set(ap.getpref("show_rapids", True))
vars.program_alpha.set(ap.getpref("program_alpha", False))
vars.show_live_plot.set(ap.getpref("show_live_plot", True))
vars.show_tool.set(ap.getpref("show_tool", True))
vars.show_extents.set(ap.getpref("show_extents", True))
Expand Down

0 comments on commit 6f29079

Please sign in to comment.