Changeset 408


Ignore:
Timestamp:
Nov 7, 2011 3:13:29 PM (12 years ago)
Author:
vondreele
Message:

add copy to limits menu
more constraint GUI stuff

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIgrid.py

    r407 r408  
    5858] = [wx.NewId() for _init_coll_Back_Items in range(1)]
    5959
     60[ wxID_LIMITCOPY,
     61] = [wx.NewId() for _init_coll_Limit_Items in range(1)]
     62
    6063[ wxID_SAMPLECOPY,
    6164] = [wx.NewId() for _init_coll_Sample_Items in range(1)]
    6265
    63 [ wxID_CONSTRAINTADD,wxID_EQUIVADD,wxID_HOLDADD,
    64 ] = [wx.NewId() for _init_coll_Constraint_Items in range(3)]
     66[ wxID_CONSTRAINTADD,wxID_EQUIVADD,wxID_HOLDADD,wxID_FUNCTADD,
     67] = [wx.NewId() for _init_coll_Constraint_Items in range(4)]
    6568
    6669[ wxID_RESTRAINTADD,
     
    109112    def _init_coll_BackMenu(self,parent):
    110113        parent.Append(menu=self.BackEdit, title='File')
     114       
     115    def _init_coll_LimitMenu(self,parent):
     116        parent.Append(menu=self.LimitEdit, title='File')
    111117       
    112118    def _init_coll_InstMenu(self,parent):
     
    155161           
    156162    def _init_coll_Constraint_Items(self,parent):
     163        parent.Append(id=wxID_HOLDADD, kind=wx.ITEM_NORMAL,text='Add hold',
     164            help='Add hold on a parameter value')
     165        parent.Append(id=wxID_EQUIVADD, kind=wx.ITEM_NORMAL,text='Add equivalence',
     166            help='Add equivalence between parameter values')
    157167        parent.Append(id=wxID_CONSTRAINTADD, kind=wx.ITEM_NORMAL,text='Add constraint',
    158168            help='Add constraint on parameter values')
    159         parent.Append(id=wxID_EQUIVADD, kind=wx.ITEM_NORMAL,text='Add equivalence',
    160             help='Add equivalence between parameter values')
    161         parent.Append(id=wxID_HOLDADD, kind=wx.ITEM_NORMAL,text='Add hold',
    162             help='Add hold on a parameter value')
     169        parent.Append(id=wxID_FUNCTADD, kind=wx.ITEM_NORMAL,text='Add function',
     170            help='Add function of parameter values')
    163171       
    164172    def _init_coll_Restraint_Items(self,parent):
     
    173181        parent.Append(id=wxID_BACKCOPY, kind=wx.ITEM_NORMAL,text='Copy',
    174182            help='Copy background parameters to other histograms')
     183                   
     184    def _init_coll_Limit_Items(self,parent):
     185        parent.Append(id=wxID_LIMITCOPY, kind=wx.ITEM_NORMAL,text='Copy',
     186            help='Copy limits to other histograms')
    175187                   
    176188    def _init_coll_Data_Items(self,parent):
     
    243255        parent.Append(help='Load image controls from file',
    244256            id=wxID_IMLOADCONTROLS, kind=wx.ITEM_NORMAL,text='Load Controls')
    245 
    246257                   
    247258    def _init_coll_Mask_Items(self,parent):
     
    313324        self.MaskMenu = wx.MenuBar()
    314325        self.BackMenu = wx.MenuBar()
     326        self.LimitMenu = wx.MenuBar()
    315327        self.InstMenu = wx.MenuBar()
    316328        self.SampleMenu = wx.MenuBar()
     
    330342        self.MaskEdit = wx.Menu(title='')
    331343        self.BackEdit = wx.Menu(title='')
     344        self.LimitEdit = wx.Menu(title='')
    332345        self.InstEdit = wx.Menu(title='')
    333346        self.SampleEdit = wx.Menu(title='')
     
    357370        self._init_coll_BackMenu(self.BackMenu)
    358371        self._init_coll_Back_Items(self.BackEdit)
     372        self._init_coll_LimitMenu(self.LimitMenu)
     373        self._init_coll_Limit_Items(self.LimitEdit)
    359374        self._init_coll_InstMenu(self.InstMenu)
    360375        self._init_coll_Inst_Items(self.InstEdit)
     
    767782        data.update({'Hist':[],'HAP':[],'Phase':[]})       #empty dict - fill it
    768783    Histograms,Phases = self.GetUsedHistogramsAndPhasesfromTree()
     784    AtomDict = dict([Phases[phase]['pId'],Phases[phase]['Atoms']] for phase in Phases)
    769785    Natoms,phaseVary,phaseDict,pawleyLookup,FFtable = G2str.GetPhaseData(Phases,Print=False)
    770786    phaseList = []
     
    773789            phaseList.append(item)
    774790    phaseList.sort()
     791    phaseAtNames = {}
     792    for item in phaseList:
     793        Split = item.split(':')
     794        if Split[2][:2] in ['AU','Af','dA']:
     795            phaseAtNames[item] = AtomDict[int(Split[0])][int(Split[3])][0]
     796        else:
     797            phaseAtNames[item] = ''
     798           
    775799    hapVary,hapDict,controlDict = G2str.GetHistogramPhaseData(Phases,Histograms,Print=False)
    776800    hapList = hapDict.keys()
     
    811835        return outList
    812836       
    813     def SelectVarbs(FrstVarb,varList,legend,constType):
     837    def SelectVarbs(page,FrstVarb,varList,legend,constType):
    814838        #future -  add 'all:all:name', '0:all:name', etc. to the varList
    815         dlg = wx.MultiChoiceDialog(self,'Select more variables:'+legend,FrstVarb+' and:',varList)
     839        if page[1] == 'phs':
     840            atchoice = [item+' for '+phaseAtNames[item] for item in varList]
     841            dlg = wx.MultiChoiceDialog(self,'Select more variables:'+legend,FrstVarb+' and:',atchoice)
     842        else:
     843            dlg = wx.MultiChoiceDialog(self,'Select more variables:'+legend,FrstVarb+' and:',varList)
    816844        varbs = [FrstVarb,]
    817845        if dlg.ShowModal() == wx.ID_OK:
     
    821849        dlg.Destroy()
    822850        if len(varbs) > 1:
    823             if 'equivalents' in constType:
     851            if 'equivalence' in constType:
    824852                constr = []
    825853                for item in varbs[1:]:
    826 #                    constr += [[{FrstVarb:1.0},{item:-1.0},0.0,False],]
     854#                    constr += [[{FrstVarb:1.0},{item:-1.0},None,None],]
    827855                    constr += [[[1.0,FrstVarb],[-1.0,item],None,None],]
    828                 return constr
    829             else:
     856                return constr           #multiple constraints
     857            elif 'function' in constType:
     858#                constr = map(dict,zip(varbs,[1.0 for i in range(len(varbs))]))
     859                constr = map(list,zip([1.0 for i in range(len(varbs))],varbs))
     860                return [constr+[0.0,False]]         #just one constraint
     861            else:       #'constraint'
    830862                constr = map(list,zip([1.0 for i in range(len(varbs))],varbs))
    831863#                constr = map(dict,zip(varbs,[1.0 for i in range(len(varbs))]))
    832                 return [constr+[0.0,False]]
     864                return [constr+[0.0,None]]          #just one constraint
    833865        return []
    834866             
    835     def OnAddEquivalence(event):
    836         constr = []
    837         page = self.Page
    838         choice = scope[page[1]]
    839         dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
    840         if dlg.ShowModal() == wx.ID_OK:
    841             sel = dlg.GetSelection()
    842             FrstVarb = choice[2][sel]
    843             moreVarb = FindEquivVarb(FrstVarb,choice[2])
    844             constr = SelectVarbs(FrstVarb,moreVarb,choice[1],'equivalents')
    845             if len(constr) > 0:
    846                 data[choice[3]] += constr
    847         dlg.Destroy()
    848         choice[4]()
    849    
    850867    def OnAddHold(event):
    851868        for phase in Phases:
     
    855872        page = self.Page
    856873        choice = scope[page[1]]
    857         dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
     874        if page[1] == 'phs':
     875            atchoice = [item+' for '+phaseAtNames[item] for item in choice[2]]
     876            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],atchoice)
     877        else:   
     878            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
    858879        if dlg.ShowModal() == wx.ID_OK:
    859880            sel = dlg.GetSelection()
    860881            FrstVarb = choice[2][sel]
    861             data[choice[3]] += [[[0.0,FrstVarb],0.0,False],]
     882            data[choice[3]] += [[[0.0,FrstVarb],None,None],]
    862883        dlg.Destroy()
    863884        choice[4]()
    864885       
     886    def OnAddEquivalence(event):
     887        constr = []
     888        page = self.Page
     889        choice = scope[page[1]]
     890        if page[1] == 'phs':
     891            atchoice = [item+' for '+phaseAtNames[item] for item in choice[2]]
     892            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],atchoice)
     893        else:   
     894            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
     895        if dlg.ShowModal() == wx.ID_OK:
     896            sel = dlg.GetSelection()
     897            FrstVarb = choice[2][sel]
     898            moreVarb = FindEquivVarb(FrstVarb,choice[2])
     899            constr = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'equivalence')
     900            if len(constr) > 0:
     901                data[choice[3]] += constr
     902        dlg.Destroy()
     903        choice[4]()
     904   
     905    def OnAddFunction(event):
     906        constr = []
     907        page = self.Page
     908        choice = scope[page[1]]
     909        if page[1] == 'phs':
     910            atchoice = [item+' for '+phaseAtNames[item] for item in choice[2]]
     911            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],atchoice)
     912        else:   
     913            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
     914        if dlg.ShowModal() == wx.ID_OK:
     915            sel = dlg.GetSelection()
     916            FrstVarb = choice[2][sel]
     917            moreVarb = FindEquivVarb(FrstVarb,choice[2])
     918            constr = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'function')
     919            if len(constr) > 0:
     920                data[choice[3]] += constr
     921        dlg.Destroy()
     922        choice[4]()
     923                       
    865924    def OnAddConstraint(event):
    866925        constr = []
    867926        page = self.Page
    868927        choice = scope[page[1]]
    869         dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
     928        if page[1] == 'phs':
     929            atchoice = [item+' for '+phaseAtNames[item] for item in choice[2]]
     930            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],atchoice)
     931        else:   
     932            dlg = wx.SingleChoiceDialog(self,'Select 1st variable:'+choice[1],choice[0],choice[2])
    870933        if dlg.ShowModal() == wx.ID_OK:
    871934            sel = dlg.GetSelection()
    872935            FrstVarb = choice[2][sel]
    873936            moreVarb = FindEquivVarb(FrstVarb,choice[2])
    874             constr = SelectVarbs(FrstVarb,moreVarb,choice[1],'')
     937            constr = SelectVarbs(page,FrstVarb,moreVarb,choice[1],'constraint')
    875938            if len(constr) > 0:
    876939                data[choice[3]] += constr
     
    888951                constSizer.Add(constDel)
    889952                eqString = ' FIXED   '+item[0][1]+'   '
    890                 constSizer.Add((5,0),0)
     953                constSizer.Add((5,0),0)               
    891954            else:
    892955                constEdit = wx.Button(pageDisplay,-1,'Edit',style=wx.BU_EXACTFIT)
     
    901964                    Indx[constRef.GetId()] = item
    902965                    constSizer.Add(constRef,0,wx.ALIGN_CENTER_VERTICAL)
     966                    eqString = ' FUNCT   '
     967                elif isinstance(item[-2],float):
     968                    constSizer.Add((5,5),0)
    903969                    eqString = ' CONSTR  '
    904970                else:
     
    927993        Obj = event.GetEventObject()
    928994        Id,name = Indx[Obj.GetId()]
    929         const = data[name][Id][-2]
    930         if isinstance(data[name][Id][-2],float):
    931             items = data[name][Id][:-2]+[[const,'= constant'],[]]
     995        const = data[name][Id][-2]       
     996        if isinstance(data[name][Id][-1],bool):
     997            items = data[name][Id][:-2]+[[],]
     998            constType = 'Function'
     999            extra = '; sum = new variable'
     1000        elif isinstance(data[name][Id][-2],float):
     1001            items = data[name][Id][:-2]+[[const,'= fixed value'],[]]
     1002            constType = 'Constraint'
     1003            extra = ' sum = constant'
    9321004        else:
    9331005            items = data[name][Id][:-2]+[[],]
    934         dlg = self.SumDialog(self,'Constraint','Enter value for each term in constraint','',items)
     1006            constType = 'Equivalence'
     1007            extra = '; sum = 0'
     1008        dlg = self.SumDialog(self,constType,'Enter value for each term in constraint'+extra,'',items)
    9351009        try:
    9361010            if dlg.ShowModal() == wx.ID_OK:
     
    9511025        HAPSizer.Add((5,5),0)
    9521026        HAPSizer.Add(ConstSizer('HAP',HAPDisplay))
    953         HAPSizer.Layout()
    954         HAPDisplay.SetSizer(HAPSizer)
    955         Size = HAPSizer.Fit(self.dataFrame)
    956         Size[0] = max(450,Size[0])
    957         Size[1] += 26                           #compensate for status bar
     1027        HAPDisplay.SetSizer(HAPSizer,True)
     1028        Size = HAPSizer.GetMinSize()
     1029        Size[0] += 40
     1030        Size[1] = max(Size[1],250) + 20
    9581031        HAPDisplay.SetSize(Size)
     1032        HAPConstr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1)
     1033        Size[1] = min(Size[1],250)
    9591034        self.dataFrame.setSizePosLeft(Size)
    9601035       
     
    9651040        HistSizer.Add((5,5),0)       
    9661041        HistSizer.Add(ConstSizer('Hist',HistDisplay))
    967         HistSizer.Layout()
    968         HistDisplay.SetSizer(HistSizer)
    969         Size = HistSizer.Fit(self.dataFrame)
    970         Size[0] = max(450,Size[0])
    971         Size[1] += 26                           #compensate for status bar
     1042        HistDisplay.SetSizer(HistSizer,True)
     1043        Size = HistSizer.GetMinSize()
     1044        Size[0] += 40
     1045        Size[1] = max(Size[1],250) + 20
    9721046        HistDisplay.SetSize(Size)
     1047        HistConstr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1)
     1048        Size[1] = min(Size[1],250)
    9731049        self.dataFrame.setSizePosLeft(Size)
    9741050       
     
    9791055        PhaseSizer.Add((5,5),0)       
    9801056        PhaseSizer.Add(ConstSizer('Phase',PhaseDisplay))
    981         PhaseSizer.Layout()
    982         PhaseDisplay.SetSizer(PhaseSizer)
    983         Size = PhaseSizer.Fit(self.dataFrame)
    984         Size[1] += 26                           #compensate for status bar
    985         Size[0] = max(450,Size[0])
     1057        PhaseDisplay.SetSizer(PhaseSizer,True)
     1058        Size = PhaseSizer.GetMinSize()
     1059        Size[0] += 40
     1060        Size[1] = max(Size[1],250) + 20
    9861061        PhaseDisplay.SetSize(Size)
     1062        PhaseConstr.SetScrollbars(10,10,Size[0]/10-4,Size[1]/10-1)
     1063        Size[1] = min(Size[1],250)
    9871064        self.dataFrame.setSizePosLeft(Size)
    9881065   
     
    10171094    if not self.dataFrame.GetStatusBar():
    10181095        Status = self.dataFrame.CreateStatusBar()
    1019     SetStatusLine('NB: Set parameters to be varied first')
     1096    SetStatusLine('')
    10201097   
    10211098    self.dataFrame.SetMenuBar(self.dataFrame.ConstraintMenu)
    10221099    self.dataFrame.Bind(wx.EVT_MENU, OnAddConstraint, id=wxID_CONSTRAINTADD)
     1100    self.dataFrame.Bind(wx.EVT_MENU, OnAddFunction, id=wxID_FUNCTADD)
    10231101    self.dataFrame.Bind(wx.EVT_MENU, OnAddEquivalence, id=wxID_EQUIVADD)
    10241102    self.dataFrame.Bind(wx.EVT_MENU, OnAddHold, id=wxID_HOLDADD)
  • trunk/GSASIIpwdGUI.py

    r406 r408  
    366366        G2plt.PlotPatterns(self)
    367367       
     368    def OnLimitCopy(event):
     369        histList = ['All',]+G2gd.GetPatternTreeDataNames(self,['PWDR',])
     370        copyList = []
     371        dlg = wx.MultiChoiceDialog(self,
     372            'Copy limits to which histograms?', 'Copy limits',
     373            histList, wx.CHOICEDLG_STYLE)
     374        try:
     375            if dlg.ShowModal() == wx.ID_OK:
     376                result = dlg.GetSelections()
     377                for i in result:
     378                    copyList.append(histList[i])
     379                if 'All' in copyList:
     380                    copyList = histList[1:]
     381            for item in copyList:
     382                Id = G2gd.GetPatternTreeItemId(self,self.root,item)
     383                self.PatternTree.SetItemPyData(G2gd.GetPatternTreeItemId(self,Id,'Limits'),
     384                    copy.copy(data))
     385        finally:
     386            dlg.Destroy()
     387       
    368388    self.LimitsTable = []
    369389    colLabels = ['Tmin','Tmax']
     
    372392    self.LimitsTable = G2gd.Table(data,rowLabels=rowLabels,colLabels=colLabels,types=Types)
    373393    self.dataFrame.SetLabel('Limits')
    374     self.dataFrame.SetMenuBar(self.dataFrame.BlankMenu)
     394    self.dataFrame.SetMenuBar(self.dataFrame.LimitMenu)
     395    if not self.dataFrame.GetStatusBar():
     396        Status = self.dataFrame.CreateStatusBar()
     397    self.Bind(wx.EVT_MENU,OnLimitCopy,id=G2gd.wxID_LIMITCOPY)
    375398    self.dataDisplay = G2gd.GSGrid(parent=self.dataFrame)
    376399    self.dataDisplay.SetTable(self.LimitsTable, True)
     
    378401    self.dataDisplay.SetMargins(0,0)
    379402    self.dataDisplay.AutoSizeColumns(False)
    380     self.dataFrame.setSizePosLeft([230,120])
     403    self.dataFrame.setSizePosLeft([230,160])
    381404   
    382405def UpdateInstrumentGrid(self,data):
  • trunk/GSASIIstruct.py

    r407 r408  
    791791        Atoms = Phase['Atoms']
    792792        cell = General['Cell']
    793         textureData = General['SH Texture']
    794793        pId = Phase['pId']
    795794        pfx = str(pId)+'::'
     
    866865                                atomsSig[str(i)+':'+str(ind)] = sigDict[names[ind]]
    867866            PrintAtomsAndSig(General,Atoms,atomsSig)
    868            
    869         if textureData['Order']:
    870             SHtextureSig = {}
    871             for name in ['omega','chi','phi']:
    872                 aname = pfx+'SH '+name
    873                 textureData['Sample '+name][1] = parmDict[aname]
    874                 if aname in sigDict:
    875                     SHtextureSig['Sample '+name] = sigDict[aname]
    876             for name in textureData['SH Coeff'][1]:
    877                 aname = pfx+name
    878                 textureData['SH Coeff'][1][name] = parmDict[aname]
    879                 if aname in sigDict:
    880                     SHtextureSig[name] = sigDict[aname]
    881             PrintSHtextureAndSig(textureData,SHtextureSig)
     867       
     868        if 'SH Texture' in General:
     869            textureData = General['SH Texture']   
     870            if textureData['Order']:
     871                SHtextureSig = {}
     872                for name in ['omega','chi','phi']:
     873                    aname = pfx+'SH '+name
     874                    textureData['Sample '+name][1] = parmDict[aname]
     875                    if aname in sigDict:
     876                        SHtextureSig['Sample '+name] = sigDict[aname]
     877                for name in textureData['SH Coeff'][1]:
     878                    aname = pfx+name
     879                    textureData['SH Coeff'][1][name] = parmDict[aname]
     880                    if aname in sigDict:
     881                        SHtextureSig[name] = sigDict[aname]
     882                PrintSHtextureAndSig(textureData,SHtextureSig)
    882883
    883884def GetHistogramPhaseData(Phases,Histograms,Print=True):
Note: See TracChangeset for help on using the changeset viewer.