コード例 #1
0
def playForward(event=None):
    if CTK.t == []: return
    walls = VARS[3].get()
    t0 = CTK.varsFromWidget(VARS[0].get(), type=1)[0]
    time = CTK.varsFromWidget(VARS[1].get(), type=1)[0]
    tf = CTK.varsFromWidget(VARS[2].get(), type=1)[0]
    step = (tf - t0) / 100.

    if CTK.__MAINTREE__ == 1:
        CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()

    if (walls == '1' and CTK.dt == []):
        zones = Internal.getNodesFromType(CTK.t, 'Zone_t')
        Z = buildWalls(zones)
        CTK.dt = C.newPyTree(['Base'])
        CTK.dt[2][1][2] += Z

    CTK.__BUSY__ = True
    CPlot.setState(cursor=2)
    while (time < tf and CTK.__BUSY__):
        if (walls == '1'): temp = RM.evalPosition(CTK.dt, time)
        else: temp = RM.evalPosition(CTK.t, time)
        CTK.display(temp, mainTree=CTK.TIME)
        time += step
        VARS[1].set(str(time))
        WIDGETS['slider'].set((time - t0) / step)
        WIDGETS['time'].update()
        WIDGETS['slider'].update()
    CTK.__BUSY__ = False
    CPlot.setState(cursor=0)
コード例 #2
0
def setSelectionStyle(event=None):
    v = VARS[7].get()
    style = 0
    if v == 'Blue': style = 0
    elif v == 'Alpha': style = 1
    CPlot.setState(selectionStyle=style)
    CTK.PREFS['selectionStyle'] = v
コード例 #3
0
def setDisplayInfo(event=None):
    v = VARS[2].get()
    va = 0
    if v == 'Active': va = 1
    elif v == 'Inactive': va = 0
    CPlot.setState(displayInfo=va)
    CPlot.setState(displayBB=va)
    CTK.PREFS['displayInfo'] = str(va)
コード例 #4
0
def find(event=None):
    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
    nzs = CPlot.getSelectedZones()
    if nzs == []:
        CTK.TXT.insert('START', 'Selection is empty.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    if len(nzs) != 1:
        CTK.TXT.insert('START', 'Only one block must be selected.\n')
        CTK.TXT.insert('START', 'Error: ', 'Error')
        return
    nz = nzs[0]
    nob = CTK.Nb[nz] + 1
    noz = CTK.Nz[nz]
    z = CTK.t[2][nob][2][noz]
    type = VARS[0].get()
    if type == 'Node index':
        inds = CTK.varsFromWidget(VARS[1].get(), type=3)
        if len(inds) == 0:
            CTK.TXT.insert('START', 'Invalid index.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        [px, py, pz] = C.getValue(z, Internal.__GridCoordinates__, inds[0])
        CTK.TXT.insert('START', 'Node %s found.\n' % VARS[1].get())
    elif type == 'Coordinates':
        vars = CTK.varsFromWidget(VARS[1].get(), type=1)
        if len(vars) != 3:
            CTK.TXT.insert('START', 'Invalid coordinates.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        [px, py, pz] = vars
        CTK.TXT.insert('START', 'Coordinates %s found.\n' % VARS[1].get())
    else:  # type = element index
        inds = CTK.varsFromWidget(VARS[1].get(), type=3)
        if len(inds) == 0:
            CTK.TXT.insert('START', 'Invalid index.\n')
            CTK.TXT.insert('START', 'Error: ', 'Error')
            return
        zp = Internal.copyRef(z)
        C._deleteAllBCAndSolutions__(zp)
        zp = C.node2Center(z)
        [px, py, pz] = C.getValue(zp, Internal.__GridCoordinates__, inds[0])
        CTK.TXT.insert('START', 'Element %s found.\n' % VARS[1].get())

    (xeye, yeye, zeye) = CPlot.getState('posEye')
    (xcam, ycam, zcam) = CPlot.getState('posCam')
    dx = xcam - xeye
    dy = ycam - yeye
    dz = zcam - zeye
    CPlot.setState(posEye=(px, py, pz))
    CPlot.setState(posCam=(px + dx, py + dy, pz + dz))
    CPlot.setActivePoint(px, py, pz)
コード例 #5
0
def rotate():
    if CTK.t == []: return
    if not CTK.__BUSY__:
        bb = G.bbox(CTK.t)
        xc = 0.5 * (bb[3] + bb[0])
        yc = 0.5 * (bb[4] + bb[1])
        zc = 0.5 * (bb[5] + bb[2])
        pos = CPlot.getState('posCam')
        posCam = [pos[0], pos[1], pos[2]]
        posEye = [xc, yc, zc]
        dirCam = [0, 0, 1]
        CTK.__BUSY__ = True
        TTK.sunkButton(WIDGETS['rotate'])
        CPlot.setState(cursor=2)
        i = 0
        while CTK.__BUSY__:
            speed = WIDGETS['speed'].get() * 0.0006 / 100.
            cs = math.cos(speed * i * math.pi / 180)
            ss = math.sin(speed * i * math.pi / 180)
            px = cs * (posCam[0] - xc) + ss * (posCam[1] - yc) + xc
            py = -ss * (posCam[0] - xc) + cs * (posCam[1] - yc) + yc
            posCam[0] = px
            posCam[1] = py
            CPlot.setState(posCam=posCam)
            time.sleep(CPlot.__timeStep__)
            WIDGETS['rotate'].update()
            i += 1
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['rotate'])
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['rotate'])
        CPlot.setState(cursor=0)
コード例 #6
0
def setBgColor(event=None):
    v = VARS[3].get()
    va = 0
    if v == 'Black': va = 0
    elif v == 'White': va = 1
    elif v == 'Grey': va = 2
    elif v == 'Yellow': va = 3
    elif v == 'Blue': va = 4
    elif v == 'Red': va = 5
    elif v == 'Paper1': va = 6
    elif v == 'Paper2': va = 7
    elif v == 'Arch': va = 8
    elif v == 'Jarvis': va = 9
    elif v == 'Onera': va = 10
    CPlot.setState(bgColor=va)
    CTK.PREFS['bgColor'] = str(va)
コード例 #7
0
def orbite():
    if CTK.t == []: return
    if not CTK.__BUSY__:
        name = VARS[0].get()
        names = name.split(';')
        # Get paths
        paths = []
        for v in names:
            v = v.lstrip()
            v = v.rstrip()
            sname = v.split('/', 1)
            bases = Internal.getNodesFromName1(CTK.t, sname[0])
            if bases != []:
                nodes = Internal.getNodesFromType1(bases[0], 'Zone_t')
                for z in nodes:
                    if z[0] == sname[1]: paths.append(z)
        # Keep only 1D arrays
        path = []
        for p in paths:
            dim = Internal.getZoneDim(p)
            if (dim[0] == 'Unstructured' and dim[3] == 'BAR'): path.append(p)
            if (dim[0] == 'Structured' and dim[2] == 1 and dim[3] == 1):
                path.append(C.convertArray2Tetra(p))
        if path == []: return
        path = T.join(path)
        path = G.close(path)
        path = C.convertBAR2Struct(path)
        dim = Internal.getZoneDim(path)
        N = dim[1]

        CTK.__BUSY__ = True
        TTK.sunkButton(WIDGETS['orbite'])
        CPlot.setState(cursor=2)
        i = 0
        while CTK.__BUSY__:
            speed = 100. - WIDGETS['speed'].get()
            time.sleep(CPlot.__timeStep__ * speed * 0.06)
            if i > N - 1: i = 0
            if i + N / 10 > N - 1: inc = 1
            else: inc = N / 10
            posCam = C.getValue(path, Internal.__GridCoordinates__, i)
            posEye = C.getValue(path, Internal.__GridCoordinates__, i + inc)
            CPlot.setState(posCam=posCam, posEye=posEye)
            WIDGETS['orbite'].update()
            i += 1
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['orbite'])
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['orbite'])
        CPlot.setState(cursor=0)
コード例 #8
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)
コード例 #9
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)
コード例 #10
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
コード例 #11
0
def fly():
    if CTK.t == []: return
    if not CTK.__BUSY__:
        bb = G.bbox(CTK.t)
        xc = 0.5 * (bb[3] + bb[0])
        yc = 0.5 * (bb[4] + bb[1])
        zc = 0.5 * (bb[5] + bb[2])
        pos = CPlot.getState('posCam')
        posCam = [pos[0], pos[1], pos[2]]
        step = 0.0001
        sigma = 10
        beta = 8 / 3
        ro = 28
        CTK.__BUSY__ = True
        TTK.sunkButton(WIDGETS['fly'])
        CPlot.setState(cursor=2)
        i = 0
        while CTK.__BUSY__:
            speed = WIDGETS['speed'].get() / 50.
            CPlot.setState(posCam=posCam)
            time.sleep(CPlot.__timeStep__)
            x = posCam[0] - xc
            y = posCam[2] - yc
            z = posCam[1] - zc
            x = 10 * x / max((bb[3] - bb[0]), 1.e-10)
            y = 10 * y / max((bb[4] - bb[1]), 1.e-10)
            z = 30 * z / max((bb[5] - bb[2]), 1.e-10)
            xp = x + step * speed * sigma * (y - x)
            yp = y + step * speed * (ro * x - y - x * z)
            zp = z + step * speed * (x * y - beta * z)
            xp = xp * (bb[3] - bb[0]) * 0.1 + xc
            yp = yp * (bb[4] - bb[1]) * 0.1 + yc
            zp = zp * (bb[5] - bb[2]) / 30. + zc
            posCam[0] = xp
            posCam[1] = zp
            posCam[2] = yp
            WIDGETS['fly'].update()
            i += 1
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['fly'])
        CPlot.setState(cursor=0)
    else:
        CTK.__BUSY__ = False
        TTK.raiseButton(WIDGETS['fly'])
        CPlot.setState(cursor=0)
コード例 #12
0
def setInfo(event=None):
    posCam = VARS[0].get()
    posCam = CTK.varsFromWidget(posCam, 1)
    if posCam != [] and len(posCam) == 3:
        CPlot.setState(posCam=posCam)
    posEye = VARS[1].get()
    posEye = CTK.varsFromWidget(posEye, 1)
    if posEye != [] and len(posEye) == 3:
        CPlot.setState(posEye=posEye)
    dirCam = VARS[2].get()
    dirCam = CTK.varsFromWidget(dirCam, 1)
    if dirCam != [] and len(dirCam) == 3:
        CPlot.setState(dirCam=dirCam)
コード例 #13
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)
コード例 #14
0
def setViewAngle(event=None):
    angle = VARS[0].get()
    angle = float(angle)
    CPlot.setState(viewAngle=angle)
コード例 #15
0
def setGammaCorrection(event=None):
    off = WIDGETS['gammaCorrection'].get() * 2.5 / 100.
    VARS[6].set('Gamma correction [%.2f].' % off)
    CPlot.setState(gamma=off)
コード例 #16
0
def setLightOffsetX(event=None):
    off = WIDGETS['lightOffsetX'].get() / 50. - 1.
    VARS[3].set('Light offset in x [%.2f %%].' % off)
    CPlot.setState(lightOffset=(off, -999))
コード例 #17
0
def setLightOffsetY(event=None):
    off = WIDGETS['lightOffsetY'].get() / 50.
    VARS[4].set('Light offset in y [%.2f %%].' % off)
    CPlot.setState(lightOffset=(-999, off))
コード例 #18
0
def setDOF(event=None):
    if VARS[2].get() == '1': CPlot.setState(dof=1)
    else: CPlot.setState(dof=0)
コード例 #19
0
def setDofPower(event=None):
    off = WIDGETS['dofPower'].get() * 4. / 100.
    VARS[5].set('Depth of field power [%.2f].' % off)
    CPlot.setState(dofPower=off)
コード例 #20
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)
コード例 #21
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)
コード例 #22
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)
コード例 #23
0
def view(event=None):
    if CTK.t == []: return

    BCTypes = []
    selection = WIDGETS['BCLB'].curselection()
    for s in selection:
        t = WIDGETS['BCLB'].get(s)
        if t not in Internal.KNOWNBCS: t = 'FamilySpecified:' + t
        BCTypes.append(t)
    if 'FamilySpecified:-All BC-' in BCTypes: BCTypes = ['*']

    if CTK.__MAINTREE__ == 1:
        CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()

    tp = Internal.appendBaseName2ZoneName(CTK.t,
                                          updateRef=False,
                                          separator=Internal.SEP1)
    CTK.dt = C.newPyTree(['Base', 'Edges'])
    active = []
    for z in CTK.__MAINACTIVEZONES__:
        active.append(tp[2][CTK.Nb[z] + 1][2][CTK.Nz[z]])

    Z = []
    for t in BCTypes:
        Z += C.extractBCOfType(active, t, topTree=tp)
        if t == 'BCWall':  # Dans ce cas, affiche tous les types de BCWall
            Z += C.extractBCOfType(active, 'BCWallInviscid')
            Z += C.extractBCOfType(active, 'BCWallViscous')
            Z += C.extractBCOfType(active, 'BCWallViscousIsoThermal')
    CTK.dt[2][1][2] += Z

    if VARS[7].get() == '1':  # display les edges des zones en +
        exts = []
        for z in active:
            ztype = Internal.getZoneType(z)
            if ztype == 1:
                zp = P.exteriorFacesStructured(z)
                exts += zp
            else:
                #zp = P.exteriorFaces(z)
                #zp = P.sharpEdges(zp)
                zp = []
                exts += zp

        CTK.dt[2][2][2] += exts
        C._fillMissingVariables(CTK.dt)  # bug exteriorFaces

        # Activate
        lenZ = len(CTK.dt[2][1][2])
        lenExts = len(CTK.dt[2][2][2])
        active = [(i, 1) for i in range(lenZ + lenExts)]
        for i in range(lenZ):
            active[i] = (i, 1)
        for i in range(lenExts):
            active[i + lenZ] = (i + lenZ, 0)

        CTK.display(CTK.dt, mainTree=CTK.DEFINEDBC)
        CPlot.setActiveZones(active)
        CPlot.setState(edgifyDeactivatedZones=1)
    else:
        lenZ = len(CTK.dt[2][1][2])
        active = [(i, 1) for i in range(lenZ)]
        C._fillMissingVariables(CTK.dt)  # si BCDataSet != fields
        CTK.display(CTK.dt, mainTree=CTK.DEFINEDBC)
        CPlot.setActiveZones(active)
        CPlot.setState(edgifyDeactivatedZones=0)
コード例 #24
0
def check():
    if CTK.t == []: return

    node = Internal.getNodeFromName(CTK.t, 'EquationDimension')
    if node is not None: ndim = Internal.getValue(node)
    else:
        CTK.TXT.insert('START',
                       'EquationDimension not found (tkState). Using 3D.\n')
        CTK.TXT.insert('START', 'Warning: ', 'Warning')
        ndim = 3

    # Varie de 0 a 180 degres
    global __SPLITFACTOR__
    splitFactor = 180. - WIDGETS['splitFactor'].get() * 180. / 100.
    __SPLITFACTOR__ = splitFactor

    wins = C.getEmptyBC(CTK.t, ndim, splitFactor)
    if CTK.__MAINTREE__ == 1:
        CTK.__MAINACTIVEZONES__ = CPlot.getActiveZones()
    CTK.dt = C.newPyTree(['Base', 'Edges'])
    tp = Internal.appendBaseName2ZoneName(CTK.t,
                                          updateRef=False,
                                          separator=Internal.SEP1,
                                          trailing=Internal.SEP1)
    bases = Internal.getBases(tp)
    nb = 0
    for b in bases:
        nodes = Internal.getNodesFromType1(b, 'Zone_t')
        nz = 0
        for z in nodes:
            ztype = Internal.getZoneType(z)
            winz = wins[nb][nz]
            if ztype == 1:  # structure
                for w in winz:
                    imin = w[0]
                    imax = w[1]
                    jmin = w[2]
                    jmax = w[3]
                    kmin = w[4]
                    kmax = w[5]
                    zp = T.subzone(z, (imin, jmin, kmin), (imax, jmax, kmax))
                    CTK.dt[2][1][2].append(zp)
            else:  # non structure
                for w in winz:
                    zp = T.subzone(z, w, type='faces')
                    CTK.dt[2][1][2].append(zp)
            nz += 1
        nb += 1

    if VARS[7].get() == '1':  # display les edges des zones en +
        exts = []
        zones = Internal.getZones(tp)
        for z in zones:
            ztype = Internal.getZoneType(z)
            if ztype == 1:
                zp = P.exteriorFacesStructured(z)
                exts += zp
            else:
                #zp = P.exteriorFaces(z); zp = P.sharpEdges(zp)
                zp = []
                exts += zp
        CTK.dt[2][2][2] += exts
        #C._fillMissingVariables(CTK.dt) # bug exteriorFacesStruct

        # Activate
        lenZ = len(CTK.dt[2][1][2])
        lenExts = len(exts)
        active = [(i, 1) for i in range(lenZ + lenExts)]
        for i in range(lenZ):
            active[i] = (i, 1)
        for i in range(lenExts):
            active[i + lenZ] = (i + lenZ, 0)

        CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC)
        CPlot.setActiveZones(active)
        CPlot.setState(edgifyDeactivatedZones=1)
    else:
        lenZ = len(CTK.dt[2][1][2])
        active = [(i, 1) for i in range(lenZ)]
        CTK.display(CTK.dt, mainTree=CTK.UNDEFINEDBC)
        CPlot.setActiveZones(active)

    # modifie la couleur du bouton
    l = len(Internal.getZones(CTK.dt))
    if l == 0: TTK.setButtonGreen(WIDGETS['undefinedBC'])
    else: TTK.setButtonRed(WIDGETS['undefinedBC'])
    WIDGETS['undefinedBC'].update()
コード例 #25
0
def setStereo(event=None):
    if CTK.t == []: return
    mode = VARS[0].get()
    if mode == 'None': CPlot.setState(stereo=0)
    elif mode == 'Anaglyph (b&w)': CPlot.setState(stereo=1)
    elif mode == 'Anaglyph (color)': CPlot.setState(stereo=2)
コード例 #26
0
def setDist(event=None):
    if CTK.t == []: return
    dist = WIDGETS['dist'].get() / 100.
    VARS[1].set('Stereo distance [%.2f].' % dist)
    CPlot.setState(stereoDist=dist)
コード例 #27
0
# - display1D (pyTree) -
import Generator.PyTree as G
import CPlot.PyTree as CPlot
import Converter.PyTree as C
import numpy

# 1D data defined in zones
b = G.cart((0,0,0), (0.1,1,1), (50,1,1))
c = G.cart((5,0,0), (0.1,1,1), (50,1,1))
B = [b, c]
CPlot.setState(gridSize=(1,2))
for i in xrange(100):
    C._initVars(B, 'f=sin({CoordinateX}+0.01*%d)'%i)
    C._initVars(B, 'g={CoordinateX}')
    CPlot.display1D(B, slot=0, bgBlend=1., gridPos=(0,0), var1='CoordinateX', var2='f')

# 1D data defined in numpys
import numpy
x = numpy.linspace(0, 2*numpy.pi)
y = numpy.sin(x)
CPlot.display1D([x,y], slot=1, var1='x', var2='y', gridPos=(0,1), bgBlend=0.8)
コード例 #28
0
def setShadow(event=None):
    if VARS[1].get() == '1': CPlot.setState(shadow=1)
    else: CPlot.setState(shadow=0)
コード例 #29
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)
コード例 #30
0
# - setState (pyTree) -
import Generator.PyTree as G
import CPlot.PyTree as CPlot
import time

a = G.cart((0, 0, 0), (1, 1, 1), (5, 5, 5))
CPlot.display([a], mode='solid')
time.sleep(0.2)
CPlot.setState(posCam=(8, 8, 8), posEye=(5, 5, 5))