Beispiel #1
0
def drawAngleDimension(color,
                       right,
                       up,
                       bpos,
                       p0,
                       p1,
                       p2,
                       text,
                       minR1=0.0,
                       minR2=0.0,
                       highlighted=False):
    z = cross(p0 - p1, p2 - p1)
    try:
        csys = CylindricalCoordinates(p1, z, up, right)
    except ZeroLengthCylinder:
        len0 = vlen(p1 - p0)
        len2 = vlen(p1 - p2)
        # make sure it's really a zero-degree angle
        assert len0 > 1.0e-6
        assert len2 > 1.0e-6
        assert vlen(cross(p1 - p2, p1 - p0)) < 1.0e-6
        # For an angle of zero degrees, there is no correct way to
        # orient the text, so just draw a line segment
        if len0 > len2:
            L = len0
            end = p0
        else:
            L = len2
            end = p2
        Lb = vlen(bpos - p1)
        if Lb > L:
            L = Lb
            end = p1 + (Lb / L) * (end - p1)
        drawline(color, p1, end)
        return
    br, bt, bz = csys.rtz(bpos)
    theta1 = csys.rtz(p0)[1]
    theta2 = csys.rtz(p2)[1]
    if theta2 < theta1 - math.pi:
        theta2 += 2 * math.pi
    elif theta2 > theta1 + math.pi:
        theta2 -= 2 * math.pi
    if theta2 < theta1:
        theta1, theta2 = theta2, theta1
    e0 = csys.xyz((max(vlen(p0 - p1), br, minR1) + 0.5, theta1, 0))
    e1 = csys.xyz((max(vlen(p2 - p1), br, minR2) + 0.5, theta2, 0))
    drawline(color, p1, e0)
    drawline(color, p1, e1)
    if highlighted:
        csys.drawArc(color, br, theta1, theta2, 0, width=THICKLINEWIDTH)
    else:
        csys.drawArc(color, br, theta1, theta2, 0)
    # draw some arrowheads
    e00 = csys.xyz((br, theta1, 0))
    e10 = csys.xyz((br, theta2, 0))
    dr = 0.25
    dtheta = 1 / br
    e0a = csys.xyz((br + dr, theta1 + dtheta, 0))
    e0b = csys.xyz((br - dr, theta1 + dtheta, 0))
    e1a = csys.xyz((br + dr, theta2 - dtheta, 0))
    e1b = csys.xyz((br - dr, theta2 - dtheta, 0))
    drawline(color, e00, e0a)
    drawline(color, e00, e0b)
    drawline(color, e10, e1a)
    drawline(color, e10, e1b)
    midangle = (theta1 + theta2) / 2
    tmidpoint = csys.xyz((br + 0.5, midangle, 0))
    h = 1.0e-3
    textx = norm(csys.xyz((br + 0.5, midangle + h, 0)) - tmidpoint)
    texty = norm(csys.xyz((br + 0.5 + h, midangle, 0)) - tmidpoint)

    # make sure the text runs from left to right
    if dot(textx, right) < 0:
        textx = -textx

    # make sure the text isn't upside-down
    outOfScreen = cross(right, up)
    textForward = cross(textx, texty)
    if dot(outOfScreen, textForward) < 0:
        tmidpoint = csys.xyz((br + 1.5, midangle, 0))
        texty = -texty

    textxyz = tmidpoint - (0.5 * len(text)) * textx

    def tfm(x, y):
        x = (x / (1. * WIDTH)) * textx
        y = (y / (1. * HEIGHT)) * texty
        return textxyz + x + y

    f3d = Font3D()
    f3d.drawString(text, tfm=tfm, color=color)
Beispiel #2
0
def drawLinearDimension(
        color,  # what color are we drawing this in
        right,
        up,  # screen directions mapped to xyz coords
        bpos,  # position of the handle for moving the text
        p0,
        p1,  # positions of the ends of the dimension
        text,
        highlighted=False):
    outOfScreen = cross(right, up)
    bdiff = bpos - 0.5 * (p0 + p1)
    csys = CylindricalCoordinates(p0, p1 - p0, bdiff, right)
    # This works OK until we want to keep the text right side up, then the
    # criterion for right-side-up-ness changes because we've changed 'up'.
    br, bt, bz = csys.rtz(bpos)
    e0 = csys.xyz((br + 0.5, 0, 0))
    e1 = csys.xyz((br + 0.5, 0, 1))
    drawline(color, p0, e0)
    drawline(color, p1, e1)
    v0 = csys.xyz((br, 0, 0))
    v1 = csys.xyz((br, 0, 1))
    if highlighted:
        drawline(color, v0, v1, width=THICKLINEWIDTH)
    else:
        drawline(color, v0, v1)
    # draw arrowheads at the ends
    a1, a2 = 0.25, 1.0 * csys.zinv
    arrow00 = csys.xyz((br + a1, 0, a2))
    arrow01 = csys.xyz((br - a1, 0, a2))
    drawline(color, v0, arrow00)
    drawline(color, v0, arrow01)
    arrow10 = csys.xyz((br + a1, 0, 1 - a2))
    arrow11 = csys.xyz((br - a1, 0, 1 - a2))
    drawline(color, v1, arrow10)
    drawline(color, v1, arrow11)
    # draw the text for the numerical measurement, make
    # sure it goes from left to right
    xflip = dot(csys.z, right) < 0
    # then make sure it's right side up
    theoreticalRight = (xflip and -csys.z) or csys.z
    theoreticalOutOfScreen = cross(theoreticalRight, bdiff)
    yflip = dot(theoreticalOutOfScreen, outOfScreen) < 0
    if debug_flags.atom_debug:
        print "DEBUG INFO FROM drawLinearDimension"
        print csys
        print theoreticalRight, theoreticalOutOfScreen
        print xflip, yflip
    if yflip:

        def fx(y):
            return br + 1.5 - y / (1. * HEIGHT)
    else:

        def fx(y):
            return br + 0.5 + y / (1. * HEIGHT)

    if xflip:

        def fz(x):
            return 0.9 - csys.zinv * x / (1. * WIDTH)
    else:

        def fz(x):
            return 0.1 + csys.zinv * x / (1. * WIDTH)

    def tfm(x, y, fx=fx, fz=fz):
        return csys.xyz((fx(y), 0, fz(x)))

    f3d = Font3D()
    f3d.drawString(text, tfm=tfm, color=color)
Beispiel #3
0
def drawSiCGrid(color, line_type, w, h, up, right):
    """
    Draw SiC grid.
    """

    if line_type == NO_LINE:
        return

    XLen = sic_uLen * 3.0
    YLen = sic_yU * 2.0
    hw = w / 2.0
    hh = h / 2.0
    i1 = int(floor(-hw / XLen))
    i2 = int(ceil(hw / XLen))
    j1 = int(floor(-hh / YLen))
    j2 = int(ceil(hh / YLen))

    glDisable(GL_LIGHTING)
    glColor3fv(color)

    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 "drawer.drawSiCGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple(1, 0x00FF)  #  dashed

    glClipPlane(GL_CLIP_PLANE0, (1.0, 0.0, 0.0, hw))
    glClipPlane(GL_CLIP_PLANE1, (-1.0, 0.0, 0.0, hw))
    glClipPlane(GL_CLIP_PLANE2, (0.0, 1.0, 0.0, hh))
    glClipPlane(GL_CLIP_PLANE3, (0.0, -1.0, 0.0, hh))
    glEnable(GL_CLIP_PLANE0)
    glEnable(GL_CLIP_PLANE1)
    glEnable(GL_CLIP_PLANE2)
    glEnable(GL_CLIP_PLANE3)

    glPushMatrix()
    glTranslate(i1 * XLen, j1 * YLen, 0.0)
    for i in range(i1, i2):
        glPushMatrix()
        for j in range(j1, j2):
            glCallList(SiCGridList)
            glTranslate(0.0, YLen, 0.0)
        glPopMatrix()
        glTranslate(XLen, 0.0, 0.0)
    glPopMatrix()

    glDisable(GL_CLIP_PLANE0)
    glDisable(GL_CLIP_PLANE1)
    glDisable(GL_CLIP_PLANE2)
    glDisable(GL_CLIP_PLANE3)

    if line_type > 1:
        glDisable(GL_LINE_STIPPLE)

    xpos, ypos = hw, 0.0
    f3d = Font3D(xpos=xpos,
                 ypos=ypos,
                 right=right,
                 up=up,
                 rot90=False,
                 glBegin=False)
    for j in range(j1, j2):
        yoff = j * YLen
        if -hh < yoff + ypos < hh:
            f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff)

    xpos, ypos = 0.0, hh
    f3d = Font3D(xpos=xpos,
                 ypos=ypos,
                 right=right,
                 up=up,
                 rot90=True,
                 glBegin=False)
    for i in range(2 * i1, 2 * i2):
        yoff = i * (XLen / 2)
        if -hw < yoff + xpos < hw:
            f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff)

    glEnable(GL_LIGHTING)
    return