Ejemplo n.º 1
0
def measure():
    if CTK.t == []: return
    prev = []
    w = WIDGETS['button']
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__ == True:
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif prev != l:
                    dist = (l[0]-prev[0])*(l[0]-prev[0])+\
                    (l[1]-prev[1])*(l[1]-prev[1])+\
                    (l[2]-prev[2])*(l[2]-prev[2])
                    dist = math.sqrt(dist)
                    CTK.TXT.insert('START', 'dist= ' + str(dist) + '\n')
                    time.sleep(CPlot.__timeStep__)
                    prev = []
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
Ejemplo n.º 2
0
def drawCubic(npts):
    global CURRENTZONE; global CURRENTPOLYLINE
    if (CTK.t == []): return
    w = WIDGETS['draw']
    if (CTK.__BUSY__ == False):
        CPlot.unselectAllZones()
        CTK.saveTree()
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while (CTK.__BUSY__ == True):
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                CPlot.unselectAllZones()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                CURRENTPOLYLINE.append((l[0],l[1],l[2]))
                if (CURRENTZONE == None):
                    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
                    base = Internal.getNodeFromName1(CTK.t, 'CONTOURS')
                    nob = C.getNobOfBase(base, CTK.t)
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.add(CTK.t, nob, -1, a)
                    ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
                    noz = ret[1]
                else:
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.replace(CTK.t, nob, noz, a)
                (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                CTK.TKTREE.updateApp()
                CPlot.render()
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
       a = D.polyline(CURRENTPOLYLINE)
       d = G.cart( (0,0,0), (1./(npts-1),1,1), (npts,1,1) )
       a = G.map(a, d)
       surfaces = getSurfaces()
       if (surfaces != []): a = T.projectOrthoSmooth(a, surfaces)
       nob = C.getNobOfBase(ret[0], CTK.t)
       CTK.replace(CTK.t, nob, ret[1], a)
       #C._fillMissingVariables(CTK.t)
       (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
       CTK.TKTREE.updateApp()
       CPlot.render()
       CURRENTZONE = None
       CURRENTPOLYLINE = []
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
Ejemplo n.º 3
0
def translateClick():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    prev = []
    w = WIDGETS['translate']
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        nzs = CPlot.getSelectedZones()
        CTK.TXT.insert('START', 'Click start point...\n')
        TTK.sunkButton(w)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            l = []
            while l == []:
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__:
                if prev == []:
                    prev = l
                    if nzs == []: nzs = CPlot.getSelectedZones()
                    CTK.TXT.insert('START', 'Click end point...\n')
                elif prev != l:
                    CTK.saveTree()
                    vx = l[0] - prev[0]
                    vy = l[1] - prev[1]
                    vz = l[2] - prev[2]
                    for nz in nzs:
                        nob = CTK.Nb[nz] + 1
                        noz = CTK.Nz[nz]
                        z = CTK.t[2][nob][2][noz]
                        a = T.translate(z, (vx, vy, vz))
                        CTK.replace(CTK.t, nob, noz, a)
                    CTK.TKTREE.updateApp()
                    CTK.TXT.insert('START', 'Zones translated.\n')
                    CPlot.render()
                    prev = []
                    break
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
Ejemplo n.º 4
0
def drawLine(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    prev = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(WIDGETS['draw'])
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while l == []:
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                WIDGETS['draw'].update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__:
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (prev != l):
                    line = D.line(prev, l, npts)
                    if surfaces != []: line = T.projectOrthoSmooth(line, surfaces)
                    CTK.add(CTK.t, nob, -1, line)
                    CTK.TXT.insert('START', 'Line created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(WIDGETS['draw'])
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['draw'])
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(WIDGETS['draw'])
       CPlot.setState(cursor=0)
    return
Ejemplo n.º 5
0
def refineCells():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    W = WIDGETS['refine']
    if CTK.__BUSY__ == False:
        CPlot.unselectAllZones()
        CTK.__BUSY__ = True
        TTK.sunkButton(W)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            l = []
            while l == []:
                nz = CPlot.getSelectedZone()
                l = CPlot.getActivePointIndex()
                CPlot.unselectAllZones()
                time.sleep(CPlot.__timeStep__)
                W.update()
                if CTK.__BUSY__ == False: break
            if CTK.__BUSY__:
                nob = CTK.Nb[nz] + 1
                noz = CTK.Nz[nz]
                CTK.saveTree()
                z = CTK.t[2][nob][2][noz]
                C._initVars(z, 'centers:__tag__', 0)
                C.setValue(z, 'centers:__tag__', l[1], 1)
                try:
                    z = P.refine(z, '__tag__')
                    CTK.replace(CTK.t, nob, noz, z)
                except:
                    pass
                CTK.TKTREE.updateApp()
                CPlot.render()
        CTK.__BUSY__ = False
        TTK.raiseButton(W)
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(W)
        CPlot.setState(cursor=0)
Ejemplo n.º 6
0
def drawFreeHand():
    global CURRENTZONE; global CURRENTPOLYLINE; global ALLZONES
    w = WIDGETS['draw']
    prev = []; first = []
    if CTK.__BUSY__ == False:
        CPlot.unselectAllZones()
        CTK.saveTree()
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        buttonState = 0
        while CTK.__BUSY__ == True:
            if prev == []: # first point
                l = []
                while l == []:
                    l = CPlot.getActivePoint()
                    if l != []: prev = l; first = l
                    time.sleep(CPlot.__timeStep__)
                    w.update()
                    if CTK.__BUSY__ == False: break
            else: # next points
                diff = -1.
                while (diff < 1.e-10):
                    (buttonState,x,y,z) = CPlot.getMouseState()
                    l = (x,y,z)
                    diff = Vector.norm2(Vector.sub(l,prev))
                    diff1 = Vector.norm2(Vector.sub(l,first))
                    if (diff1 < 1.e-10): l = first
                    if (buttonState == 5): break
                    time.sleep(CPlot.__timeStep__)
                    w.update()
                    if (CTK.__BUSY__ == False): break
                    
            prev = l
            CPlot.unselectAllZones()
            if (buttonState == 5): # button released
                ALLZONES.append(CURRENTZONE)
                CURRENTZONE = None; prev = []; first = []
                CURRENTPOLYLINE = []
                CTK.TKTREE.updateApp()
                
            if (CTK.__BUSY__ == True and buttonState != 5):
                CURRENTPOLYLINE.append((l[0],l[1],l[2]))
                if (CURRENTZONE == None):
                    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
                    base = Internal.getNodeFromName1(CTK.t, 'CONTOURS')
                    nob = C.getNobOfBase(base, CTK.t)
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.add(CTK.t, nob, -1, a)
                    ret = Internal.getParentOfNode(CTK.t, CURRENTZONE)
                    noz = ret[1]
                else:
                    a = D.polyline(CURRENTPOLYLINE)
                    CURRENTZONE = a
                    CTK.replace(CTK.t, nob, noz, a)
                (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                CPlot.render()
            buttonState = 0
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       surfaces = getSurfaces()
       if (surfaces != []):
           if (CURRENTZONE != None): ALLZONES += [CURRENTZONE]
           for s in ALLZONES:
               ret = Internal.getParentOfNode(CTK.t, s)
               nob = C.getNobOfBase(ret[0], CTK.t)
               a = T.projectOrthoSmooth(s, surfaces)
               noz = ret[1]
               CTK.replace(CTK.t, nob, noz, a)
       #C._fillMissingVariables(CTK.t)
       (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
       CTK.TKTREE.updateApp()
       CPlot.render()
       CURRENTZONE = None; ALLZONES = []
       CURRENTPOLYLINE = []
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
Ejemplo n.º 7
0
def drawRectangle(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click left/lower corner...\n')
    w = WIDGETS['draw']
    prev = []; second = []
    if (CTK.__BUSY__ == False):
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while (CTK.__BUSY__ == True):
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if (prev == []):
                    prev = l
                    CTK.TXT.insert('START', 'Click right/up corner...\n')
                elif (prev != l):
                    e1,e2 = getVectorsFromCanvas()
                    e1n = Vector.norm(e1)
                    e2n = Vector.norm(e2)
                    if (e2n > e1n): e1 = e2
                    P1 = l; P2 = prev
                    P1P2 = Vector.sub(P2, P1)
                    P1P2n = Vector.norm(P1P2)
                    Q = Vector.norm(Vector.cross(e1, P1P2))
                    L = math.sqrt( P1P2n*P1P2n - Q*Q )
                    sign = Vector.dot(e1, P1P2)
                    if (sign > 0): e1 = Vector.mul(L, e1)
                    else: e1 = Vector.mul(-L, e1)
                    P3 = Vector.add(P1, e1)
                    P4 = Vector.sub(P2, e1)
                    l1 = D.line(P1, P3, npts)
                    l2 = D.line(P3, P2, npts)
                    l3 = D.line(P2, P4, npts)
                    l4 = D.line(P4, P1, npts)
                    rect = T.join([l1,l2,l3,l4])
                    if (surfaces != []):
                        rect = T.projectOrthoSmooth(rect, surfaces)
                    CTK.add(CTK.t, nob, -1, rect)
                    CTK.TXT.insert('START', 'Rectangle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
Ejemplo n.º 8
0
def drawArc(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    w = WIDGETS['draw']
    prev = []; second = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if (prev == []):
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (second == [] and prev != l):
                    second = l
                    CTK.TXT.insert('START', 'Click third point...\n')
                elif (prev != l and second != l):
                    x1 = l[0]; y1 = l[1]; z1 = l[2]
                    x2 = prev[0]; y2 = prev[1]; z2 = prev[2]
                    x3 = second[0]; y3 = second[1]; z3 = second[2]
                    xa = x2 - x1; ya = y2 - y1; za = z2 - z1
                    xb = x3 - x1; yb = y3 - y1; zb = z3 - z1
                    xc = x3 - x2; yc = y3 - y2; zc = z3 - z2
                    a2 = xa*xa + ya*ya + za*za
                    b2 = xb*xb + yb*yb + zb*zb
                    c2 = xc*xc + yc*yc + zc*zc
                    A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2
                    R = math.sqrt( a2*b2*c2 / A )
                    
                    nx = ya*zb - za*yb
                    ny = za*xb - xa*zb
                    nz = xa*yb - ya*xb
                    tx = ya*nz - za*ny
                    ty = za*nx - xa*nz
                    tz = xa*ny - ya*nx
                    norm = tx*tx + ty*ty + tz*tz
                    normi = 1./math.sqrt(norm)
                    tx = tx*normi; ty = ty*normi; tz = tz*normi;
                    alpha = R*R - (xa*xa+ya*ya+za*za)*0.25
                    alpha = math.sqrt(alpha)
                    center = [0,0,0]
                    center[0] = 0.5*(x1+x2) + alpha*tx
                    center[1] = 0.5*(y1+y2) + alpha*ty
                    center[2] = 0.5*(z1+z2) + alpha*tz
                    dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3
                    l = dx3*dx3 + dy3*dy3 + dz3*dz3
                    if (abs(l - R*R) > 1.e-10):
                        center[0] = 0.5*(x1+x2) - alpha*tx
                        center[1] = 0.5*(y1+y2) - alpha*ty
                        center[2] = 0.5*(z1+z2) - alpha*tz
                        dx3 = center[0]-x3; dy3 = center[1]-y3; dz3 = center[2]-z3
                        l = dx3*dx3 + dy3*dy3 + dz3*dz3
                    
                    e1 = [x1-center[0], y1-center[1], z1-center[2]]
                    e2 = [x2-center[0], y2-center[1], z2-center[2]]
                    e3 = Vector.cross(e1, e2)
                    e4 = Vector.cross(e1, e3)

                    # Images des pts dans le plan xyz 
                    pt1 = D.point((x1,y1,z1))
                    pt2 = D.point((x2,y2,z2))
                    pt3 = D.point((x3,y3,z3))
                    pt1 = T.rotate(pt1,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)) )
                    pt2 = T.rotate(pt2,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)))
                    pt3 = T.rotate(pt3,
                                   (center[0], center[1], center[2]),
                                   (e1, e4, e3),
                                   ((1,0,0), (0,1,0), (0,0,1)))
                    xp1 = C.getValue(pt1, 'CoordinateX', 0)
                    yp1 = C.getValue(pt1, 'CoordinateY', 0)
                    zp1 = C.getValue(pt1, 'CoordinateZ', 0)
                    xp2 = C.getValue(pt2, 'CoordinateX', 0)
                    yp2 = C.getValue(pt2, 'CoordinateY', 0)
                    zp2 = C.getValue(pt2, 'CoordinateZ', 0)
                    xp3 = C.getValue(pt3, 'CoordinateX', 0)
                    yp3 = C.getValue(pt3, 'CoordinateY', 0)
                    zp3 = C.getValue(pt3, 'CoordinateZ', 0)
                    
                    dx1 = (xp1-center[0])/R; dy1 = (yp1-center[1])/R
                    if dx1 > 1.: dx1 = 1.
                    if dx1 < -1.: dx1 = -1.
                    if dy1 > 0: teta1 = math.acos(dx1)
                    else: teta1 = 2*math.pi - math.acos(dx1)
                    teta1 = teta1*180./math.pi; teta1 = 360.

                    dx2 = (xp2-center[0])/R; dy2 = (yp2-center[1])/R
                    if dx2 > 1.: dx2 = 1.
                    if dx2 < -1.: dx2 = -1.
                    if dy2 > 0: teta2 = math.acos(dx2)
                    else: teta2 = 2*math.pi - math.acos(dx2)
                    teta2 = teta2*180./math.pi

                    dx3 = (xp3-center[0])/R; dy3 = (yp3-center[1])/R
                    if dx3 > 1.: dx3 = 1.
                    if dx3 < -1.: dx3 = -1.
                    if dy3 > 0: teta3 = math.acos(dx3)
                    else: teta3 = 2*math.pi - math.acos(dx3)
                    teta3 = teta3*180./math.pi

                    if teta3 > teta2: teta1 = 360.
                    else: teta1 = 0.

                    circle = D.circle((center[0],center[1],center[2]), R, 
                                      tetas=teta2, tetae=teta1, N=npts)
                    circle = T.rotate(circle,
                                      (center[0], center[1], center[2]),
                                      ((1,0,0), (0,1,0), (0,0,1)),
                                      (e1, e4, e3))
                    if surfaces != []:
                        circle = T.projectOrthoSmooth(circle, surfaces)
                    CTK.add(CTK.t, nob, -1, circle)
                    CTK.TXT.insert('START', 'Circle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
Ejemplo n.º 9
0
def drawCircle(npts):
    CTK.t = C.addBase2PyTree(CTK.t, 'CONTOURS', 1)
    nodes = Internal.getNodesFromName1(CTK.t, 'CONTOURS')
    nob = C.getNobOfBase(nodes[0], CTK.t)
    CTK.TXT.insert('START', 'Click first point...\n')
    w = WIDGETS['draw']
    prev = []; second = []
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            CPlot.unselectAllZones()
            CTK.saveTree()
            surfaces = getSurfaces()
            l = []
            while (l == []):
                l = CPlot.getActivePoint()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if (CTK.__BUSY__ == True):
                if prev == []:
                    prev = l
                    CTK.TXT.insert('START', 'Click second point...\n')
                elif (second == [] and prev != l):
                    second = l
                    CTK.TXT.insert('START', 'Click third point...\n')
                elif (prev != l and second != l):
                    x1 = l[0]; y1 = l[1]; z1 = l[2]
                    x2 = prev[0]; y2 = prev[1]; z2 = prev[2]
                    x3 = second[0]; y3 = second[1]; z3 = second[2]
                    xa = x2 - x1; ya = y2 - y1; za = z2 - z1
                    xb = x3 - x1; yb = y3 - y1; zb = z3 - z1
                    xc = x3 - x2; yc = y3 - y2; zc = z3 - z2
                    a2 = xa*xa + ya*ya + za*za
                    b2 = xb*xb + yb*yb + zb*zb
                    c2 = xc*xc + yc*yc + zc*zc
                    A = 2*b2*c2 + 2*c2*a2 + 2*a2*b2 - a2*a2 - b2*b2 - c2*c2
                    R = math.sqrt( a2*b2*c2 / A )
                    
                    nx = ya*zb - za*yb
                    ny = za*xb - xa*zb
                    nz = xa*yb - ya*xb
                    tx = ya*nz - za*ny
                    ty = za*nx - xa*nz
                    tz = xa*ny - ya*nx
                    norm = tx*tx + ty*ty + tz*tz
                    normi = 1./math.sqrt(norm)
                    tx = tx*normi; ty = ty*normi; tz = tz*normi;
                    alpha = R*R - (xa*xa+ya*ya+za*za)*0.25
                    alpha = math.sqrt(alpha)
                    center = [0,0,0]
                    center[0] = 0.5*(x1+x2) + alpha*tx
                    center[1] = 0.5*(y1+y2) + alpha*ty
                    center[2] = 0.5*(z1+z2) + alpha*tz
                    l = (center[0]-x3)*(center[0]-x3) + \
                        (center[1]-y3)*(center[1]-y3) + \
                        (center[2]-z3)*(center[2]-z3)
                    if (abs(l - R*R) > 1.e-10):
                        center[0] = 0.5*(x1+x2) - alpha*tx
                        center[1] = 0.5*(y1+y2) - alpha*ty
                        center[2] = 0.5*(z1+z2) - alpha*tz
                        l = (center[0]-x3)*(center[0]-x3) + \
                        (center[1]-y3)*(center[1]-y3) + \
                        (center[2]-z3)*(center[2]-z3)
                    circle = D.circle( (center[0],center[1],center[2]), R, N=npts)
                    e1 = [x1-center[0], y1-center[1], z1-center[2]]
                    e2 = [x2-center[0], y2-center[1], z2-center[2]]
                    e3 = Vector.cross(e1, e2)
                    e4 = Vector.cross(e1, e3)
                    circle = T.rotate(circle,
                                      (center[0], center[1], center[2]),
                                      ((1,0,0), (0,1,0), (0,0,1)),
                                      (e1, e4, e3))
                    if (surfaces != []):
                        circle = T.projectOrthoSmooth(circle, surfaces)
                    CTK.add(CTK.t, nob, -1, circle)
                    CTK.TXT.insert('START', 'Circle created.\n')
                    CTK.__BUSY__ = False
                    TTK.raiseButton(w)
                    CPlot.setState(cursor=0)
                    #C._fillMissingVariables(CTK.t)
                    (CTK.Nb, CTK.Nz) = CPlot.updateCPlotNumbering(CTK.t)
                    CTK.TKTREE.updateApp()
                    CPlot.render()
                    CPlot.setState(cursor=0)
                    prev = []
                    return
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
       CTK.__BUSY__ = False
       TTK.raiseButton(w)
       CPlot.setState(cursor=0)
Ejemplo n.º 10
0
def paint():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    # get patined var
    field = CPlot.getState('scalarField')
    if field == -1:
        CTK.TXT.insert('START', 'Scalar field is not set.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    CPlot.unselectAllZones()

    CTK.saveTree()
    w = WIDGETS['paint']
    if not CTK.__BUSY__:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)

        while CTK.__BUSY__ == True:
            l = []
            while l == []:
                nz = CPlot.getSelectedZone()
                l = CPlot.getActivePointIndex()
                #time.sleep(CPlot.__timeStep__)
                w.update()
                if not CTK.__BUSY__: break
            if CTK.__BUSY__:
                nob = CTK.Nb[nz] + 1
                noz = CTK.Nz[nz]
                CTK.saveTree()
                value = float(WIDGETS['value'].get())
                #width = float(WIDGETS['width'].get())
                #brushType = VARS[2].get()
                z = CTK.t[2][nob][2][noz]
                posCam = CPlot.getState('posCam')
                posEye = CPlot.getState('posEye')
                vect = (posEye[0] - posCam[0], posEye[1] - posCam[1],
                        posEye[2] - posCam[2])

                click = CPlot.getActivePoint()
                point = (click[0], click[1], click[2])
                ind = CPlot.getActivePointIndex()
                #hook = C.createHook
                varNames = C.getVarNames(z)[0]
                if len(varNames) > field + 3:
                    var = varNames[field + 3]
                    C.setValue(z, var, ind[0], value)
                else:
                    CTK.TXT.insert(
                        'START',
                        'Field %d not found. Use scalar mode.\n' % field)
                    CTK.TXT.insert('START', 'Error: ', 'Error')
                CTK.replace(CTK.t, nob, noz, z)

                CTK.TKTREE.updateApp()
                CPlot.unselectAllZones()
                CPlot.render()
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
Ejemplo n.º 11
0
def sculpt():
    if CTK.t == []: return
    if CTK.__MAINTREE__ <= 0:
        CTK.TXT.insert('START', 'Fail on a temporary tree.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return

    TOOLS = createTools()
    #CTK.display(TOOLS)

    bbox = G.bbox(CTK.t)
    size = max(bbox[3] - bbox[0], bbox[4] - bbox[1], bbox[5] - bbox[2])
    CPlot.unselectAllZones()

    w = WIDGETS['sculpt']
    if CTK.__BUSY__ == False:
        CTK.__BUSY__ = True
        TTK.sunkButton(w)
        CPlot.setState(cursor=1)
        while CTK.__BUSY__:
            l = []
            while l == []:
                nz = CPlot.getSelectedZone()
                l = CPlot.getActivePointIndex()
                time.sleep(CPlot.__timeStep__)
                w.update()
                if (CTK.__BUSY__ == False): break
            if CTK.__BUSY__:
                nob = CTK.Nb[nz] + 1
                noz = CTK.Nz[nz]
                CTK.saveTree()
                depth = 0.5 * WIDGETS['depth'].get() / 100.
                depth = size * depth
                width = 0.5 * WIDGETS['width'].get() / 100.
                width = size * width
                brushType = VARS[2].get()
                z = CTK.t[2][nob][2][noz]
                posCam = CPlot.getState('posCam')
                posEye = CPlot.getState('posEye')
                vect = (posEye[0] - posCam[0], posEye[1] - posCam[1],
                        posEye[2] - posCam[2])
                if brushType == 'Deform':
                    click = CPlot.getActivePoint()
                    point = (click[0], click[1], click[2])
                    z = T.deformPoint(z, point, vect, depth, width)
                    CTK.replace(CTK.t, nob, noz, z)
                elif brushType == 'Sphere':
                    click = CPlot.getActivePoint()
                    center = (click[0], click[1], click[2])
                    s = D.sphere(center, depth, N=10)
                    s = C.convertArray2Tetra(s)
                    s = G.close(s)
                    z = C.convertArray2Tetra(z)
                    z = G.close(z)
                    z = XOR.booleanMinus(z, s)
                    CTK.replace(CTK.t, nob, noz, z)
                elif brushType == 'Cube':
                    click = CPlot.getActivePoint()
                    center = (click[0], click[1], click[2])
                    s = D.sphere(center, depth, N=20)
                    s = C.convertArray2Tetra(s)
                    s = G.close(s)
                    z = C.convertArray2Tetra(z)
                    z = G.close(z)
                    z = XOR.booleanMinus(z, s)
                    CTK.replace(CTK.t, nob, noz, z)
                CTK.TKTREE.updateApp()
                CPlot.unselectAllZones()
                CPlot.render()
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(w)
        CPlot.setState(cursor=0)
Ejemplo n.º 12
0
def unselect(event=None):
    CPlot.unselectAllZones()