Changeset 749 for trunk/GSASIIplot.py


Ignore:
Timestamp:
Sep 4, 2012 1:34:01 PM (10 years ago)
Author:
vondreele
Message:

fix crash on delete atoms
couple roll & peak shift on charge flip maps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r748 r749  
    23602360        Draw()                          #make sure plot is fresh!!
    23612361        mode = cb.GetValue()
    2362         Fname = os.path.joint(Mydir,generalData['Name']+'.'+mode)
    2363         size = Page.canvas.GetSize()
    2364         glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    2365         if mode in ['jpeg',]:
    2366             Pix = glReadPixels(0,0,size[0],size[1],GL_RGBA, GL_UNSIGNED_BYTE)
    2367             im = Image.new("RGBA", (size[0],size[1]))
     2362        if mode in ['jpeg','bmp','tiff',]:
     2363            Fname = os.path.joint(Mydir,generalData['Name']+'.'+mode)
     2364            size = Page.canvas.GetSize()
     2365            glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
     2366            if mode in ['jpeg',]:
     2367                Pix = glReadPixels(0,0,size[0],size[1],GL_RGBA, GL_UNSIGNED_BYTE)
     2368                im = Image.new("RGBA", (size[0],size[1]))
     2369            else:
     2370                Pix = glReadPixels(0,0,size[0],size[1],GL_RGB, GL_UNSIGNED_BYTE)
     2371                im = Image.new("RGB", (size[0],size[1]))
     2372            im.fromstring(Pix)
     2373            im.save(Fname,mode)
     2374            cb.SetValue(' save as/key:')
     2375            G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1)
    23682376        else:
    2369             Pix = glReadPixels(0,0,size[0],size[1],GL_RGB, GL_UNSIGNED_BYTE)
    2370             im = Image.new("RGB", (size[0],size[1]))
    2371         im.fromstring(Pix)
    2372         im.save(Fname,mode)
    2373         cb.SetValue(' Save as:')
    2374         G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1)
    2375    
     2377            event.key = cb.GetValue()[0]
     2378            cb.SetValue(' save as/key:')
     2379            wx.CallAfter(OnKey,event)
     2380
     2381    def OnKey(event):           #on key UP!!
     2382        Draw()                          #make sure plot is fresh!!
     2383        try:
     2384            keyCode = event.GetKeyCode()
     2385            if keyCode > 255:
     2386                keyCode = 0
     2387            key = chr(keyCode)
     2388        except AttributeError:       #if from OnKeyBox above
     2389            key = str(event.key).upper()
     2390        indx = drawingData['selectedAtoms']
     2391        if key in ['C']:
     2392            drawingData['viewPoint'] = [[.5,.5,.5],[0,0]]
     2393            drawingData['Rotation'] = [0.0,0.0,0.0,[]]
     2394            SetViewPointText(drawingData['viewPoint'][0])
     2395        elif key in ['N']:
     2396            drawAtoms = drawingData['Atoms']
     2397            pI = drawingData['viewPoint'][1]
     2398            if indx:
     2399                pI[0] = indx[pI[1]]
     2400                Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]
     2401                pI[1] += 1
     2402                if pI[1] >= len(indx):
     2403                    pI[1] = 0
     2404            else:
     2405                Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]               
     2406                pI[0] += 1
     2407                if pI[0] >= len(drawAtoms):
     2408                    pI[0] = 0
     2409            drawingData['viewPoint'] = [[Tx,Ty,Tz],pI]
     2410            SetViewPointText(drawingData['viewPoint'][0])
     2411            G2frame.G2plotNB.status.SetStatusText('View point at atom '+drawAtoms[pI[0]][ct-1]+str(pI),1)
     2412               
     2413        elif key in ['P']:
     2414            drawAtoms = drawingData['Atoms']
     2415            pI = drawingData['viewPoint'][1]
     2416            if indx:
     2417                pI[0] = indx[pI[1]]
     2418                Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]
     2419                pI[1] -= 1
     2420                if pI[1] < 0:
     2421                    pI[1] = len(indx)-1
     2422            else:
     2423                Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]               
     2424                pI[0] -= 1
     2425                if pI[0] < 0:
     2426                    pI[0] = len(drawAtoms)-1
     2427            drawingData['viewPoint'] = [[Tx,Ty,Tz],pI]
     2428            SetViewPointText(drawingData['viewPoint'][0])           
     2429            G2frame.G2plotNB.status.SetStatusText('View point at atom '+drawAtoms[pI[0]][ct-1]+str(pI),1)
     2430        elif key in ['U','D','L','R'] and mapData['Flip'] == True:
     2431            dirDict = {'U':[0,-1],'D':[0,1],'L':[-1,0],'R':[1,0]}
     2432            SetMapRoll(dirDict[key])
     2433            SetPeakRoll(dirDict[key])
     2434        Draw()
     2435           
    23762436    def GetTruePosition(xy,Add=False):
    23772437        View = glGetIntegerv(GL_VIEWPORT)
     
    25082568        return Ind
    25092569                                       
    2510     def OnKey(event):           #on key UP!!
    2511         keyCode = event.GetKeyCode()
    2512         if keyCode > 255:
    2513             keyCode = 0
    2514         key,xyz = chr(keyCode),event.GetPosition()
    2515         indx = drawingData['selectedAtoms']
    2516         if key in ['C']:
    2517             drawingData['viewPoint'] = [[.5,.5,.5],[0,0]]
    2518             drawingData['Rotation'] = [0.0,0.0,0.0,[]]
    2519             SetViewPointText(drawingData['viewPoint'][0])
    2520         elif key in ['N']:
    2521             drawAtoms = drawingData['Atoms']
    2522             pI = drawingData['viewPoint'][1]
    2523             if indx:
    2524                 pI[0] = indx[pI[1]]
    2525                 Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]
    2526                 pI[1] += 1
    2527                 if pI[1] >= len(indx):
    2528                     pI[1] = 0
    2529             else:
    2530                 Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]               
    2531                 pI[0] += 1
    2532                 if pI[0] >= len(drawAtoms):
    2533                     pI[0] = 0
    2534             drawingData['viewPoint'] = [[Tx,Ty,Tz],pI]
    2535             SetViewPointText(drawingData['viewPoint'][0])
    2536             G2frame.G2plotNB.status.SetStatusText('View point at atom '+drawAtoms[pI[0]][ct-1]+str(pI),1)
    2537                
    2538         elif key in ['P']:
    2539             drawAtoms = drawingData['Atoms']
    2540             pI = drawingData['viewPoint'][1]
    2541             if indx:
    2542                 pI[0] = indx[pI[1]]
    2543                 Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]
    2544                 pI[1] -= 1
    2545                 if pI[1] < 0:
    2546                     pI[1] = len(indx)-1
    2547             else:
    2548                 Tx,Ty,Tz = drawAtoms[pI[0]][cx:cx+3]               
    2549                 pI[0] -= 1
    2550                 if pI[0] < 0:
    2551                     pI[0] = len(drawAtoms)-1
    2552             drawingData['viewPoint'] = [[Tx,Ty,Tz],pI]
    2553             SetViewPointText(drawingData['viewPoint'][0])           
    2554             G2frame.G2plotNB.status.SetStatusText('View point at atom '+drawAtoms[pI[0]][ct-1]+str(pI),1)
    2555         elif key in ['U','D','L','R'] and mapData['Flip'] == True:
    2556             dirDict = {'U':[0,1],'D':[0,-1],'L':[-1,0],'R':[1,0]}
    2557             SetMapRoll(dirDict[key])
    2558         Draw()
    2559            
    25602570    def SetBackground():
    25612571        R,G,B,A = Page.camera['backColor']
     
    25722582        glLightfv(GL_LIGHT0,GL_DIFFUSE,[1,1,1,1])
    25732583       
    2574     def SetMapRoll(newxy):
    2575         global sumroll
     2584    def GetRoll(newxy,rho):
    25762585        anglex,angley,anglez,oldxy = drawingData['Rotation']
    25772586        Rx = G2lat.rotdMat(anglex,0)
     
    25802589        dxy = np.inner(Bmat,np.inner(Rz,np.inner(Ry,np.inner(Rx,newxy+[0,]))))
    25812590        dxy *= np.array([-1,-1,1])
    2582         rho = mapData['rho']
    25832591        dxy = np.array(dxy*rho.shape)
    25842592        roll = np.where(dxy>0.5,1,np.where(dxy<-.5,-1,0))
     2593        return roll
     2594               
     2595    def SetMapRoll(newxy):
     2596        global sumroll
     2597        rho = mapData['rho']
     2598        roll = GetRoll(newxy,rho)
    25852599        sumroll += roll
    25862600        mapData['rho'] = np.roll(np.roll(np.roll(rho,roll[0],axis=0),roll[1],axis=1),roll[2],axis=2)
     
    25882602        drawingData['Rotation'][3] = list(newxy)
    25892603       
     2604    def SetPeakRoll(newxy):
     2605        rho = mapData['rho']
     2606        roll = GetRoll(newxy,rho)
     2607        steps = 1./np.array(rho.shape)
     2608        dxy = roll*steps
     2609        for peak in mapPeaks:
     2610            peak[1:4] += dxy
     2611            peak[1:4] %= 1.
     2612               
    25902613    def SetTranslation(newxy):
    25912614        Tx,Ty,Tz = drawingData['viewPoint'][0]
     
    26482671        for line,color in zip(uEdges,uColors)[:3]:
    26492672            glColor3ubv(color)
    2650             glVertex3fv(line[0])
    2651             glVertex3fv(line[1])
     2673            glVertex3fv(-line[1]/2.)
     2674            glVertex3fv(line[1]/2.)
    26522675        glEnd()
    26532676        glPopMatrix()
     
    29813004        altDown = False
    29823005    Page.SetFocus()
    2983     cb = wx.ComboBox(G2frame.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,
    2984         choices=(' save as:','jpeg','tiff','bmp'))
     3006    if mapData['Flip']:
     3007        choice = [' save as/key:','jpeg','tiff','bmp','c: center on 1/2,1/2,1/2','n: next','p: previous']
     3008    else:
     3009        choice = [' save as/key:','jpeg','tiff','bmp','u: roll up','d: roll down','l: roll left','r: roll right']
     3010    cb = wx.ComboBox(G2frame.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,choices=choice)
    29853011    cb.Bind(wx.EVT_COMBOBOX, OnKeyBox)
    2986     cb.SetValue(' save as:')
     3012    cb.SetValue(' save as/key:')
    29873013    Page.canvas.Bind(wx.EVT_MOUSEWHEEL, OnMouseWheel)
    29883014    Page.canvas.Bind(wx.EVT_LEFT_DOWN, OnMouseDown)
Note: See TracChangeset for help on using the changeset viewer.