def _drawtext(self, text, color):
     # use atom positions to compute center, where text should go
     if self.picked:
         # move the text to the lower left corner, and make it big
         drawtext(text, color, self.assy.o.selectedJigTextPosition(),
                  3 * self.font_size, self.assy.o)
     else:
         pos1 = self.atoms[0].posn()
         pos2 = self.atoms[-1].posn()
         pos = (pos1 + pos2) / 2
         drawtext(text, color, pos, self.font_size, self.assy.o)
Beispiel #2
0
 def _drawtext(self, text, color):
     # use atom positions to compute center, where text should go
     if self.picked:
         # move the text to the lower left corner, and make it big
         drawtext(text, color, self.assy.o.selectedJigTextPosition(),
                  3 * self.font_size, self.assy.o)
     else:
         pos1 = self.atoms[0].posn()
         pos2 = self.atoms[-1].posn()
         pos = (pos1 + pos2) / 2
         drawtext(text, color, pos, self.font_size, self.assy.o)
def displayLabelsAlongPlaneEdgesLowerLeft(h, w ,hh, hw, uh, uw,
                     text_offset, text_color, font_size, glpane):
    """
    Display labels when origin is on the lower left corner.
    
    along all the plane edges
    @param h: height of the plane
    @type h: float
    @param w: width of the plane
    @type w: float
    @param hh: half the height of the plane
    @type hh: float
    @param hw: half the width of the plane
    @type hw: float
    @param uh: spacing along height of the plane
    @type uh: float
    @param uw: spacing along width of the plane
    @type uw: float
    @param text_offset: offset for label 
    @type text_offset: float
    @param text_color: color of the text
    @type: text_colot: tuple
    @param font_size: size of the text font
    @type: font_size: float
    @param glpane: The 3D graphics area to draw it in.
    @type  glpane: L{GLPane}
    """
    #Along the origin edges
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 >= -h:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(-hw - 3 * text_offset, y1 + hh, 0.0), font_size, glpane)
        y1 -= uh  
    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 <= w:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1 - hw, hh + 2 * text_offset, 0.0), font_size, glpane)
        x1 += uw 
    #Along the non origin edges
    
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 >= -h:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + 2 * text_offset, y1 + hh, 0.0), font_size, glpane)
        y1 -= uh  
    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 <= w:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1 - hw, -hh - text_offset, 0.0), font_size, glpane)
        x1 += uw    
    return
Beispiel #4
0
def displayLabelsAlongPlaneEdgesLowerLeft(h, w, hh, hw, uh, uw, text_offset,
                                          text_color, font_size, glpane):
    """
    Display labels when origin is on the lower left corner.

    along all the plane edges
    @param h: height of the plane
    @type h: float
    @param w: width of the plane
    @type w: float
    @param hh: half the height of the plane
    @type hh: float
    @param hw: half the width of the plane
    @type hw: float
    @param uh: spacing along height of the plane
    @type uh: float
    @param uw: spacing along width of the plane
    @type uw: float
    @param text_offset: offset for label
    @type text_offset: float
    @param text_color: color of the text
    @type: text_colot: tuple
    @param font_size: size of the text font
    @type: font_size: float
    @param glpane: The 3D graphics area to draw it in.
    @type  glpane: L{GLPane}
    """
    #Along the origin edges
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 >= -h:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(-hw - 3 * text_offset, y1 + hh, 0.0), font_size, glpane)
        y1 -= uh
    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 <= w:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1 - hw, hh + 2 * text_offset, 0.0), font_size, glpane)
        x1 += uw
    #Along the non origin edges

    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 >= -h:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + 2 * text_offset, y1 + hh, 0.0), font_size, glpane)
        y1 -= uh
    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 <= w:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1 - hw, -hh - text_offset, 0.0), font_size, glpane)
        x1 += uw
    return
def draw_debug_text(glpane, point, text): #bruce 080422, should refile
    """
    """
    from geometry.VQT import V
    from utilities.constants import white, red
    
    if point is None:
        point = - glpane.pov
    # todo: randomize offset using hash of text
    offset = glpane.right * glpane.scale / 2.0 + \
             glpane.up    * glpane.scale / 2.0
               # todo: correct for aspect ratio, use min scale in each dimension
    offset2 = V( - offset[0], offset[1], 0.0 ) / 3.0
    drawline( white, point, point + offset, width = 2)
    drawline( white, point - offset2, point + offset2 )
    point_size = 12
    drawtext( text, red, point + offset, point_size, glpane )
    return
Beispiel #6
0
def draw_debug_text(glpane, point, text): #bruce 080422, should refile
    """
    """
    from geometry.VQT import V
    from utilities.constants import white, red
    
    if point is None:
        point = - glpane.pov
    # todo: randomize offset using hash of text
    offset = glpane.right * glpane.scale / 2.0 + \
             glpane.up    * glpane.scale / 2.0
               # todo: correct for aspect ratio, use min scale in each dimension
    offset2 = V( - offset[0], offset[1], 0.0 ) / 3.0
    drawline( white, point, point + offset, width = 2)
    drawline( white, point - offset2, point + offset2 )
    point_size = 12
    drawtext( text, red, point + offset, point_size, glpane )
    return
def displayLabelsAlongOriginUpperRight(h, w, hh, hw, uh, uw,
                  text_offset, text_color, font_size, glpane):
    """
    Display Labels when origin is on the upper right corner.
    
    @param h: height of the plane
    @type h: float
    @param w: width of the plane
    @type w: float
    @param hh: half the height of the plane
    @type hh: float
    @param hw: half the width of the plane
    @type hw: float
    @param uh: spacing along height of the plane
    @type uh: float
    @param uw: spacing along width of the plane
    @type uw: float
    @param text_offset: offset for label 
    @type text_offset: float
    @param text_color: color of the text
    @type: text_colot: tuple
    @param font_size: size of the text font
    @type: font_size: float
    @param glpane: The 3D graphics area to draw it in.
    @type  glpane: L{GLPane}
    """
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 <= h:
        drawtext("%g" % (y1 / 10.0), text_color,
                 V(hw + text_offset, y1 - hh, 0.0), font_size, glpane)
        y1 += uh  
    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 >= -w:
        drawtext("%g" % (-x1 / 10.0), text_color,
                 V(x1 + hw, - hh - text_offset, 0.0), font_size, glpane)
        x1 -= uw
    return
Beispiel #8
0
def displayLabelsAlongOriginUpperRight(h, w, hh, hw, uh, uw, text_offset,
                                       text_color, font_size, glpane):
    """
    Display Labels when origin is on the upper right corner.

    @param h: height of the plane
    @type h: float
    @param w: width of the plane
    @type w: float
    @param hh: half the height of the plane
    @type hh: float
    @param hw: half the width of the plane
    @type hw: float
    @param uh: spacing along height of the plane
    @type uh: float
    @param uw: spacing along width of the plane
    @type uw: float
    @param text_offset: offset for label
    @type text_offset: float
    @param text_color: color of the text
    @type: text_colot: tuple
    @param font_size: size of the text font
    @type: font_size: float
    @param glpane: The 3D graphics area to draw it in.
    @type  glpane: L{GLPane}
    """
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 <= h:
        drawtext("%g" % (y1 / 10.0), text_color,
                 V(hw + text_offset, y1 - hh, 0.0), font_size, glpane)
        y1 += uh
    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 >= -w:
        drawtext("%g" % (-x1 / 10.0), text_color,
                 V(x1 + hw, -hh - text_offset, 0.0), font_size, glpane)
        x1 -= uw
    return
def drawGPGrid(glpane, color, line_type, w, h, uw, uh, up, right):
    """
    Draw grid lines for a Grid Plane.
    
    glpane = the glpane
    color = grid line and unit text color
    line_type is: 0=None, 1=Solid, 2=Dashed or 3=Dotted
    w = width
    h = height
    uw = width spacing between grid lines
    uh = height spacing between grid lines
    """
    
    if line_type == NO_LINE:
        return

    if uw > w: uw = w
    if uh > h: uh = h

    Z_OFF = 0.0 #0.001
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)
    
    hw = w/2.0; hh = h/2.0

    #glEnable(GL_LINE_SMOOTH)
    #glEnable(GL_BLEND)
    #glBlendFunc(GL_SRC_ALPHA, GL_ONE)#_MINUS_SRC_ALPHA)
    
    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawGPGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glBegin(GL_LINES)

    #Draw horizontal lines
    y1 = 0
    while y1 > -hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 -= uh

    y1 = 0
    while y1 < hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 += uh

    #Draw vertical lines
    x1 = 0
    while x1 < hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 += uw

    x1 = 0
    while x1 > -hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 -= uw

    glEnd()

    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)
    
    # Draw unit labels for gridlines (in nm).
    text_color = color
    
    import sys
    if sys.platform == "darwin":
        # WARNING: Anything smaller than 9 pt on Mac OS X results in 
        # un-rendered text. Not sure why. -- piotr 080616
        font_size = 9
    else:
        font_size = 8
        
    text_offset = 0.5 # Offset from edge of border, in Angstroms.
    
    
    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 > -hh:
        y1 -= uh
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + text_offset, y1, 0.0), font_size, glpane)
    drawtext("%g" % (-y1 / 10.0), text_color,
             V(hw + text_offset, y1, 0.0), font_size, glpane)

    y1 = 0
    while y1 < hh:
        drawtext("%g" % (-y1 / 10.0), text_color,
                 V(hw + text_offset, y1, 0.0), font_size, glpane)
        y1 += uh
    drawtext("%g" % (-y1 / 10.0), text_color,
             V(hw + text_offset, y1, 0.0), font_size, glpane)

    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 < hw:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1, hh + text_offset, 0.0), font_size, glpane)
        x1 += uw
    drawtext("%g" % (x1 / 10.0), text_color,
             V(x1, hh + text_offset, 0.0), font_size, glpane)

    x1 = 0
    while x1 > -hw:
        drawtext("%g" % (x1 / 10.0), text_color,
                 V(x1, hh + text_offset, 0.0), font_size, glpane)
        x1 -= uw
    drawtext("%g" % (x1 / 10.0), text_color,
             V(x1, hh + text_offset, 0.0), font_size, glpane)
    
    glEnable(GL_LIGHTING)
    return
Beispiel #10
0
def drawGPGrid(glpane, color, line_type, w, h, uw, uh, up, right):
    """
    Draw grid lines for a Grid Plane.

    glpane = the glpane
    color = grid line and unit text color
    line_type is: 0=None, 1=Solid, 2=Dashed or 3=Dotted
    w = width
    h = height
    uw = width spacing between grid lines
    uh = height spacing between grid lines
    """

    if line_type == NO_LINE:
        return

    if uw > w: uw = w
    if uh > h: uh = h

    Z_OFF = 0.0  #0.001

    glDisable(GL_LIGHTING)
    glColor3fv(color)

    hw = w / 2.0
    hh = h / 2.0

    #glEnable(GL_LINE_SMOOTH)
    #glEnable(GL_BLEND)
    #glBlendFunc(GL_SRC_ALPHA, GL_ONE)#_MINUS_SRC_ALPHA)

    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple(1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple(1, 0x0101)  #  dotted
        else:
            print "drawGPGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple(1, 0x00FF)  #  dashed

    glBegin(GL_LINES)

    #Draw horizontal lines
    y1 = 0
    while y1 > -hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 -= uh

    y1 = 0
    while y1 < hh:
        glVertex3f(-hw, y1, Z_OFF)
        glVertex3f(hw, y1, Z_OFF)
        y1 += uh

    #Draw vertical lines
    x1 = 0
    while x1 < hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 += uw

    x1 = 0
    while x1 > -hw:
        glVertex3f(x1, hh, Z_OFF)
        glVertex3f(x1, -hh, Z_OFF)
        x1 -= uw

    glEnd()

    if line_type > 1:
        glDisable(GL_LINE_STIPPLE)

    # Draw unit labels for gridlines (in nm).
    text_color = color

    import sys
    if sys.platform == "darwin":
        # WARNING: Anything smaller than 9 pt on Mac OS X results in
        # un-rendered text. Not sure why. -- piotr 080616
        font_size = 9
    else:
        font_size = 8

    text_offset = 0.5  # Offset from edge of border, in Angstroms.

    # Draw unit text labels for horizontal lines (nm)
    y1 = 0
    while y1 > -hh:
        y1 -= uh
        drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0),
                 font_size, glpane)
    drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0),
             font_size, glpane)

    y1 = 0
    while y1 < hh:
        drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0),
                 font_size, glpane)
        y1 += uh
    drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0),
             font_size, glpane)

    # Draw unit text labels for vertical lines (nm).
    x1 = 0
    while x1 < hw:
        drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0),
                 font_size, glpane)
        x1 += uw
    drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0),
             font_size, glpane)

    x1 = 0
    while x1 > -hw:
        drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0),
                 font_size, glpane)
        x1 -= uw
    drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0),
             font_size, glpane)

    glEnable(GL_LIGHTING)
    return