class Hud(object): # head up display - draws a semi-transparent text box. def __init__(self): self.showme = 0 self.app = [] self.strs = [] self.fontbase = [] self.ident = [] self.strings1 = [] self.strings2 = [] self.string_lists = [] self.formats = [] self.messages = [] self.pins = [] def show(self, string): # only for legacy vismach models self.messages += [str(string)] def clear(self): # only for legacy vismach models self.messages = [] def show_txt(self, string): # displays a string self.ident += ["txt"] self.strings1 += [str(string)] self.strings2 += [None] self.string_lists += [None] self.pins += [None] self.formats += [None] def show_msg(self, string1, string_list, pin, string2=""): # displays the string 'string_list[val]' # where 'val' is a hal_pin with values 0,1,.... # example usage: # myhud.show_msg("Kinematics ", ["IDENTITY","TCP"], "motion.switchkins-type", " active") self.ident += ["msg"] self.strings1 += [str(string1)] self.strings2 += [str(string2)] self.string_lists += [string_list] self.pins += [pin] self.formats += [None] def show_pin(self, string1, pin, form, string2=""): # displays 'string1' followed by a hal_pin value 'val' and an optional 'string2' # the value 'val' is formatted by a python format string # example usage: # myhud.show_val("X : ", "joint.0.pos-fb", "{:8.3f}", "mm") self.showme = 1 self.ident += ["pin"] self.strings1 += [str(string1)] self.strings2 += [str(string2)] self.string_lists += [None] self.pins += [pin] self.formats += [form] def hide(self): self.showme = 0 def draw(self): # update the lines to be displayed in the hud using the respective lists strs = [] for n in range(len(self.ident)): if self.ident[n] == "msg": strs += [self.strings1[n] + self.string_lists[n][int(hal.get_value( self.pins[n]))] + self.strings2[n] ] elif self.ident[n] == "pin": strs += [self.strings1[n] + str(self.formats[n].format(hal.get_value( self.pins[n]))) + self.strings2[n] ] else: strs += [self.strings1[n]] drawtext = strs + self.messages self.lines = len(drawtext) #draw head-up-display #see axis.py for more font/color configurability if ((self.showme == 0) or (self.lines == 0)): return glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() if not self.fontbase: self.fontbase = int(self.app.loadbitmapfont("9x15")) char_width, char_height = 9, 15 xmargin,ymargin = 5,5 ypos = float(self.app.winfo_height()) glOrtho(0.0, self.app.winfo_width(), 0.0, ypos, -1.0, 1.0) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() #draw the text box maxlen = max([len(p) for p in drawtext]) box_width = maxlen * char_width glDepthFunc(GL_ALWAYS) glDepthMask(GL_FALSE) glDisable(GL_LIGHTING) glEnable(GL_BLEND) glEnable(GL_NORMALIZE) glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA) glColor3f(0,0.2,0) # sets the color of the hud overlay glBlendColor(0,0,0,0.5) #rgba, sets the transparency of the overlay using the 'a' value glBegin(GL_QUADS) glVertex3f(0, ypos, 1) #upper left glVertex3f(0, ypos - 2*ymargin - char_height*len(drawtext), 1) #lower left glVertex3f(box_width+2*xmargin, ypos - 2*ymargin - char_height*len(drawtext), 1) #lower right glVertex3f(box_width+2*xmargin, ypos , 1) #upper right glEnd() glDisable(GL_BLEND) glEnable(GL_LIGHTING) #fill the box with text maxlen = 0 ypos -= char_height+ymargin i=0 glDisable(GL_LIGHTING) glColor3f(1,0.8,0.4) # sets the color of the text in the hud for string in drawtext: maxlen = max(maxlen, len(string)) glRasterPos2i(xmargin, int(ypos)) for char in string: glCallList(self.fontbase + ord(char)) ypos -= char_height i = i + 1 glDepthFunc(GL_LESS) glDepthMask(GL_TRUE) glEnable(GL_LIGHTING) glPopMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW)