source: trunk/profcons.tcl @ 490

Last change on this file since 490 was 414, checked in by toby, 13 years ago

# on 2001/09/04 22:03:57, toby did:
adjustable fonts

  • Property rcs:author set to toby
  • Property rcs:date set to 2001/09/04 22:03:57
  • Property rcs:lines set to +3 -5
  • Property rcs:rev set to 1.4
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 23.2 KB
Line 
1# Implement profile constraints
2# $Revision: 414 $ $Date: 2009-12-04 23:05:46 +0000 (Fri, 04 Dec 2009) $
3
4
5# make the profile constraints pane
6proc MakeProfileConstraintsPane {} {
7    global expgui expcons
8
9    grid [button $expcons(profilemaster).del -text "Delete" \
10            -command "DeleteProfileConstraints"] \
11            -column 1 -sticky se -row 1 -columnspan 2
12    grid [button $expcons(profilemaster).add -text "Add Constraint" \
13                    -command "NewProfileConstraint"] \
14                    -column 0 -row 1 -sticky sw
15    grid [canvas $expcons(profilemaster).canvas \
16            -scrollregion {0 0 5000 1000} -width 400 -height 250 \
17            -yscrollcommand "$expcons(profilemaster).scroll set"] \
18            -column 0 -row 0 -columnspan 2 -sticky nsew \
19           
20    grid columnconfigure $expcons(profilemaster) 0 -weight 0
21    grid rowconfigure $expcons(profilemaster) 0 -weight 1
22    grid rowconfigure $expcons(profilemaster) 1 -pad 5
23    grid [scrollbar $expcons(profilemaster).scroll \
24            -command "$expcons(profilemaster).canvas yview"] \
25            -row 0 -column 2 -sticky ns
26}
27
28# read and display the profile constraints
29proc DisplayProfileConstraints {} {
30    global expgui expcons expmap
31
32    pleasewait "Processing constraints" 
33    catch {destroy $expcons(profilemaster).canvas.fr}
34    set top [frame $expcons(profilemaster).canvas.fr]
35    $expcons(profilemaster).canvas create window 0 0 -anchor nw -window $top
36    set col -1
37    set row -1
38
39    # column headings
40    incr row
41    set col 0
42    grid [label $top.h$col -text profile\nterm] \
43            -column $col -row $row -columnspan 3
44    incr col 4
45    grid [label $top.h$col -text "#"] \
46            -column $col -row $row 
47    grid columnconfigure $top $col -pad 8
48    incr col 3
49    grid [label $top.h$col -text "  Phase"] -column $col -row $row
50    grid columnconfigure $top $col -pad 8
51    incr col
52    grid [label $top.h$col -text Histograms] -column $col -row $row
53    grid columnconfigure $top $col -pad 8
54    incr col
55    grid [label $top.h$col -text Multiplier] -column $col -row $row
56    grid columnconfigure $top $col -pad 8
57    incr col 2
58    grid [label $top.h$col -text delete\nflag] -column $col -row $row
59    grid columnconfigure $top $col -pad 8
60
61    incr row
62    # vertical spacers
63    foreach col {3 10} {
64        grid [frame $top.vs$col -bd 8 -bg white] \
65                -column $col -row $row -rowspan 999 -sticky nsew
66        grid columnconfig $top $col -minsize 2 -pad 2
67    }
68
69    # loop over used profile terms
70    set msg {}
71    for {set i 1} {$i <= 36} {incr i} {
72        set ncons [constrinfo profile$i get 0]
73        if {$ncons == 0} continue
74        # loop over constraints to look for duplicate phase/hist entries
75        catch {unset varlist}
76        for {set j 1} {$j <= $ncons} {incr j} {
77            # get the constraint list
78            set conslist [constrinfo profile$i get $j]
79            foreach item $conslist {
80                set phaselist [lindex $item 0]
81                set histlist [lindex $item 1]
82                if {$phaselist == "ALL"} {set phaselist $expmap(phaselist)}
83                if {$histlist == "ALL"} {set histlist $expmap(powderlist)}
84                # tabulate phase/parameters used
85                foreach p $phaselist {
86                    foreach h $histlist {
87                        lappend varlist(${h}_$p) $j
88                    }
89                }
90            }
91        }
92        # scan for repeated references to phase/histogram combinations
93        catch {unset errarr errarr1}
94        set errlist {}
95        foreach n [array names varlist] {
96            if {[llength $varlist($n)] > 1} {
97                regexp {(.*)_(.*)} $n dummy h p
98                if [catch {set errarr($p)}] {
99                    set errarr($p) {}
100                    set errarr1($p) {}
101                }
102                # tabulate histograms by phase
103                lappend errarr($p) $h
104                # make a list of constraints
105                foreach c $varlist($n) {
106                    if {[lsearch $errarr1($p) $c] == -1} {
107                        lappend errarr1($p) $c
108                    }
109                }
110                eval lappend errlist $varlist($n)
111            }
112        }
113        catch {
114            foreach p [array names errarr] {
115                if {[llength $errarr($p)] >0} {
116                    append msg " Term #$i: phase $p, histogram(s) [CompressList $errarr($p)]"
117                    append msg " in constraints [CompressList $errarr1($p)]\n"
118                }
119            }
120        }
121        incr row
122        # put a spacer between each term
123        grid [frame $top.spa$row -bd 8 -bg white] \
124                -columnspan 16 -column 0 -row $row -sticky nsew
125        grid rowconfig $top $row -minsize 2 -pad 2
126        incr row
127        set row1 $row
128        # loop over the defined constraints
129        for {set j 1} {$j <= $ncons} {incr j} {
130            set row0 $row
131            # get the constraint list
132            set conslist [constrinfo profile$i get $j]
133
134            # reformat the constraint info
135            set conslist [SortProfileConstraints $conslist]
136            # set the phase & histogram type from the first entry in the list
137            set item [lindex $conslist 0]
138            set h [lindex [lindex $item 1] 0]
139            # trap a bad histogram code -- don't know how this happens, though
140            if {$h == ""} continue
141            if {$h == "ALL"} {set h [lindex $expmap(powderlist) 0]}
142            set p [lindex [lindex $item 0] 0]
143            if {$p == "ALL"} {set p [lindex $expmap(phaselist_$h) 0]}
144            # profile type
145            set ptype [string trim [hapinfo $h $p proftype]]
146            # histogram type
147            set htype [string range $expmap(htype_$h) 2 2]   
148            # get the profile term labels
149            set lbl [lindex "dummy [GetProfileTerms $p $h $ptype]" $i]
150            if {$lbl == ""} {set lbl ?}
151
152            foreach item $conslist {
153                set col 6
154                incr row
155                grid [label $top.tn${row}-$col \
156                        -text [CompressList [lindex $item 0]]] \
157                        -column [incr col] -row $row
158                grid [label $top.tn${row}-$col \
159                        -text [CompressList [lindex $item 1]]] \
160                        -column [incr col] -row $row
161                grid [label $top.tn${row}-$col -text [lindex $item 2]] \
162                        -column [incr col] -row $row
163                incr col
164            }
165            incr row
166            grid [label $top.ts$row0 -text $j] -column 4 \
167                    -row $row0 -rowspan [expr $row - $row0]
168            if {[lsearch $errlist $j] != -1} {$top.ts$row0 config -fg red}
169            grid [label $top.tu$row0 -text "($lbl)"] -column 2 \
170                -row $row0 -rowspan [expr $row - $row0]
171            grid [button $top.edit$row0 -text edit \
172                    -command "EditProfileConstraint $i $j [list $conslist]" \
173                    ] -column 5 -row $row0 -rowspan [expr $row - $row0]
174            set expcons(delete${i}_$j) 0
175            grid [checkbutton $top.del$row0 \
176                    -variable expcons(delete${i}_$j)] -column 11 \
177                    -row $row0 -rowspan [expr $row - $row0]
178            if {$j < $ncons} {
179                # put a spacer between each term
180                grid [frame $top.spb$row -bd 1 -bg white] \
181                        -columnspan 11 -column 3 -row $row -sticky nsew
182                grid rowconfig $top $row -minsize 1 -pad 1
183                incr row
184            }
185        }
186        grid [label $top.tt$row -text "#$i  "] -column 0 \
187                -row $row1 -rowspan [expr $row - $row1]
188    }
189    # resize the canvas & scrollbar
190    update idletasks
191    set sizes [grid bbox $top]
192    $expcons(profilemaster).canvas config -scrollregion $sizes
193    set hgt [lindex $sizes 3]
194    # set the maximum height for the canvas from the frame
195    set maxheight [expr \
196            [winfo height [winfo parent $expgui(consFrame)]] - 130]
197
198    # use the scroll for BIG constraint lists
199    if {$hgt > $maxheight} {
200        grid $expcons(profilemaster).scroll -sticky ns -column 2 -row 0
201    } else {
202        grid forget $expcons(profilemaster).scroll
203    }
204    $expcons(profilemaster).canvas config \
205            -height $maxheight \
206            -width [lindex $sizes 2]
207    $expgui(consFrame).n compute_size
208    donewait
209    if {$msg != ""} {
210        set msg "Error: a phase/histogram profile can appear in only one constraint. Here is a list of parameters that are referenced in more than one constraint:\n\n$msg"
211        MyMessageBox -icon error -message $msg \
212                -helplink "expgui6.html ProfileConstraintErr" \
213                -parent [winfo toplevel $expgui(consFrame)] 
214    }
215}
216
217
218# summarize profile constraints:
219# group histograms that have the same phase & mult
220proc SortProfileConstraints {conslist} {
221    # grouped list
222    set glist {}
223    # previous phase
224    set pp 0
225    # phase list
226    set pplist {}
227    # sort list on phase (add a dummy element)
228    foreach item "[lsort -index 0 $conslist] {0 0 0}" {
229        set p [lindex $item 0]
230        if {$p != $pp} {
231            # ok have a list containing only 1 phase
232            if {$pp != 0} {
233                set mp 0
234                set hl {}
235                foreach item2 "[lsort -index 2 -decreasing -real $pplist] {0 0 0}" {
236                    set m [lindex $item2 2]
237                    if {$m != $mp} {
238                        # have a list containing 1 phase and the same multiplier
239                        if {$mp != 0} {
240                            # do we another entry with the same multiplier
241                            set hl [lsort $hl]
242                            set i 0
243                            foreach item3 $glist {
244                                if {[lindex $item3 1] == $hl && \
245                                        [lindex $item3 2] == $mp} {
246                                    # got one that matches
247                                    # add the phase & replace it
248                                    set pp "[lindex $item3 0] $pp"
249                                    set glist [lreplace \
250                                            $glist $i $i \
251                                            "[list $pp] [list $hl] $mp"]
252                                    break
253                                }
254                                incr i
255                            }
256                            # we have looped all the way through
257                            # not matched, so add it to the list
258                            if {$i == [llength $glist]} {
259                                lappend glist "$pp [list $hl] $mp"
260                            }
261                        }
262                        set mp $m
263                        set hl [lindex $item2 1]
264                    } else {
265                        lappend hl [lindex $item2 1]
266                    }
267                }
268            }
269            set pp $p
270            set pplist [list $item]
271        } else {
272            lappend pplist $item
273        }
274    }
275    return $glist
276}
277
278# called to edit a single profile constraint set
279proc EditProfileConstraint {term num conslist} {
280    global expcons expmap expgui
281
282    set top {.editcons}
283    catch {toplevel $top}
284    eval destroy [grid slaves $top]
285    bind $top <Key-F1> "MakeWWWHelp expgui6.html EditProfileConstraints"
286
287    if {$num != "add"} {
288        # set the phase & histogram type from the first entry in the list
289        set item [lindex $conslist 0]
290        set h [lindex [lindex $item 1] 0]
291        if {$h == "ALL"} {set h [lindex $expmap(powderlist) 0]}
292        set p [lindex [lindex $item 0] 0]
293        if {$p == "ALL"} {set p [lindex $expmap(phaselist_$h) 0]}
294        # profile type
295        set ptype [string trim [hapinfo $h $p proftype]]
296        # histogram type
297        set htype [string range $expmap(htype_$h) 2 2]   
298        set expcons(ProfileHistType) [string range $expmap(htype_$h) 2 2]   
299    } else {
300        set p $expcons(ProfilePhase)
301        set ptype $expcons(ProfileFunction)
302        set htype $expcons(ProfileHistType)
303    }
304    set lbls "dummy [GetProfileTerms $p $htype $ptype]"
305    # get the cached copy of the profile term labels, when possible
306    if {$num != "add"} {
307        wm title $top "Constraint #$num for term $term"
308        set lbl [lindex $lbls $term]
309        if {$lbl == ""} {set lbl ?}
310        set txt "Editing constraint #$num for term $term ($lbl)"
311    } else {
312        wm title $top "New constraint for term(s) [CompressList $term]"
313        set txt "Editing new constraint for term(s) "
314        set i 0
315        foreach t $term {
316            set lbl [lindex $lbls $t]
317            if {$lbl == ""} {set lbl ?}
318            if {$i == 3 || $i == 10 || $i == 16 || $i == 22} {
319                append txt ",\n"
320            } elseif {$i != 0} {
321                append txt ", "
322            }
323            append txt "$t ($lbl)"
324            incr i
325        }
326    }
327    grid [label $top.top -text $txt -anchor w] -column 0 -row 0 -columnspan 20
328
329    if {$expcons(ProfileHistType) == "T"} {
330        set type "TOF"
331    } elseif {$expcons(ProfileHistType) == "C"} {
332        set type "Constant Wavelength"
333    } elseif {$expcons(ProfileHistType) == "E"} {
334        set type "Energy Dispersive X-ray"
335    }
336    grid [label $top.typ -text "Histogram type: $type"] \
337            -column 0 -row 1 -columnspan 20
338    grid [canvas $top.canvas \
339            -scrollregion {0 0 5000 500} -width 100 -height 50 \
340            -xscrollcommand "$top.scroll set"] \
341            -column 0 -row 2 -columnspan 4 -sticky nsew
342    grid columnconfigure $top 3 -weight 1
343    grid rowconfigure $top 2 -weight 1
344    catch {destroy $top.scroll}
345    scrollbar $top.scroll -orient horizontal \
346            -command "$top.canvas xview"
347    #    grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4
348    # create a scrollable frame inside the canvas
349    set cfr [frame $top.canvas.fr -class HistList]
350    $top.canvas create window 0 0 -anchor nw  -window $cfr
351
352    grid [button $top.add -text "New Column" \
353            -command "NewProfileConstraintColumn $top $cfr" \
354            ] -column 0 -row 4  -columnspan 2 -sticky ew
355    grid [button $top.done -text "Save" \
356            -command "SaveProfileConstraint $num [list $term] $top" \
357            ] -column 0 -row 5 -sticky ns
358    grid [button $top.quit -text "Cancel\nChanges" \
359            -command "CancelEditConstraint $top" \
360            ]  -column 1 -row 5
361    grid [button $top.help -text Help -bg yellow \
362            -command "MakeWWWHelp expgui6.html EditProfileConstraints"] \
363            -column 2 -row 4 -columnspan 99 -rowspan 2 -sticky e
364
365    set col 0
366    set row 2
367    # row headings
368    grid rowconfigure $cfr 6 -weight 1
369    foreach lbl {Phase(s) Histogram(s) Multiplier} {
370        # row separator
371        grid [frame $cfr.spd$row -bd 8 -bg white] \
372                -columnspan 60 -column 0 -row [incr row] -sticky nsew
373        grid rowconfig $cfr $row -minsize 2 -pad 2
374        grid [label $cfr.t$row -text $lbl] -column $col -row [incr row]
375    }
376
377    # row separator
378    grid [frame $cfr.spe$row -bd 8 -bg white] \
379            -columnspan 60 -column 0 -row [incr row] -sticky nsew
380    grid rowconfig $cfr $row -minsize 2 -pad 2
381
382    set ic 0
383    set col 1
384    foreach constr $conslist {
385        incr ic
386        MakeProfileConstraintColumn $cfr $ic $col
387        FillProfileConstraintColumn $cfr $ic $col
388        incr col 3
389    }
390    if {$conslist == ""} {NewProfileConstraintColumn $top $cfr}
391    # resize the canvas & scrollbar
392    update idletasks
393    set sizes [grid bbox $cfr]
394    $top.canvas config -scrollregion $sizes
395    set width [lindex $sizes 2]
396    # use the scroll for BIG constraints
397    if {$width > 600} {
398        set width 600
399        grid $top.scroll -sticky ew -column 0 -row 3 -columnspan 4
400    }
401    $top.canvas config -height [lindex $sizes 3] -width $width
402    set ic 0
403    set col 1
404    foreach constr $conslist {
405        incr ic
406        SelectProfileConstraintColumn $cfr $ic $col $constr
407        incr col 3
408        set expcons(mult$ic) [lindex $constr 2]
409    }
410    # force the window to stay on top
411    putontop $top
412    tkwait window $top
413    afterputontop
414}
415
416# called to make each column in the atom parameter dialog
417proc MakeProfileConstraintColumn {cfr ic col} {
418    global expmap expcons expgui
419    set row 2
420    # make column separator
421    grid [frame $cfr.spc$col -bd 8 -bg white] \
422            -rowspan 7 -column $col -row $row -sticky nsew
423    grid columnconfig $cfr $col -minsize 2 -pad 2
424    set col1 [incr col]
425    set col2 [incr col]
426    # make the phase listbox
427    set expcons(phaselistbox$ic) $cfr.lbp$ic
428    grid [listbox $cfr.lbp$ic \
429            -height [llength $expmap(phaselist)] -width 12 \
430            -exportselection 0 -selectmode extended] \
431            -column $col1 -columnspan 2 -row [incr row 2] -sticky nsew
432    bind $expcons(phaselistbox$ic) <Button-3> \
433            "$expcons(phaselistbox$ic) selection set 0 end"
434    # make the histogram listbox
435    set expcons(histlistbox$ic) $cfr.lbh$ic
436    grid [listbox $cfr.lbh$ic -height 10 -width 12 \
437            -exportselection 0 -selectmode extended \
438            -yscrollcommand " $cfr.sbh$ic set"] \
439            -column $col1 -row [incr row 2] -sticky nse
440    bind $expcons(histlistbox$ic) <Button-3> \
441            "$expcons(histlistbox$ic) selection set 0 end"
442    grid [scrollbar $cfr.sbh$ic -command "$cfr.lbh$ic yview"] \
443            -column $col2 -row $row -sticky wns
444    # multiplier
445    grid [entry $cfr.c${col}$ic -width 10 \
446            -textvariable expcons(mult$ic)] \
447            -column $col1 -row [incr row 2] -columnspan 2
448}
449
450
451# called to fill the contents of each column in the atom parameter dialog
452proc FillProfileConstraintColumn {cfr ic col "constr {}"} {
453    global expmap expcons expgui
454    # now insert the phases into the list
455    set i 0
456    foreach phase $expmap(phaselist) {
457        $expcons(phaselistbox$ic) insert end "$phase  [phaseinfo $phase name]"
458        incr i
459    }
460    # now insert the histograms into the list
461    set i 0
462    foreach h $expmap(powderlist) {
463        if {[string range $expmap(htype_$h) 2 2] == $expcons(ProfileHistType)} {
464            $expcons(histlistbox$ic) insert end [format "%2d %-67s" \
465                    $h [string range [histinfo $h title] 0 66]]
466            incr i
467        }
468    }
469}
470
471# called to select the default values for each column in the atom parameter dialog
472proc SelectProfileConstraintColumn {cfr ic col "constr {}"} {
473    global expmap expcons expgui
474    # now insert the phases into the list
475    set i 0
476    set selphase [lindex $constr 0]
477    foreach phase $expmap(phaselist) {
478        if {[lsearch $selphase $phase] != -1} {
479            $expcons(phaselistbox$ic) select set $i $i
480        }
481        incr i
482    }
483    if {[lsearch $selphase "ALL"] != -1} {
484        $expcons(phaselistbox$ic) select set 0 end
485    }
486    # now insert the histograms into the list
487    set i 0
488    set selhist [lindex $constr 1]
489    foreach h $expmap(powderlist) {
490        if {[string range $expmap(htype_$h) 2 2] == $expcons(ProfileHistType)} {
491            if {[lsearch $selhist $h] != -1} {
492                $expcons(histlistbox$ic) select set $i $i
493                $expcons(histlistbox$ic) see $i
494            }
495            incr i
496        }
497    }
498    if {[lsearch $selhist "ALL"] != -1} {
499        $expcons(histlistbox$ic) select set 0 end
500    }
501}
502
503# called when the "New column" button is pressed to add a new constraint
504proc NewProfileConstraintColumn {top cfr} {
505    global expcons
506    set col -2
507    set row 1
508    for {set ic 1} {$ic < 27} {incr ic} {
509        incr col 3
510        if [winfo exists $cfr.lbp$ic] continue
511        MakeProfileConstraintColumn $cfr $ic $col
512        FillProfileConstraintColumn $cfr $ic $col
513        # set the various variables to initial values
514        set expcons(mult$ic) 1.0
515        break
516    }
517    # resize the canvas & scrollbar
518    update idletasks
519    set sizes [grid bbox $cfr]
520    $top.canvas config -scrollregion $sizes
521    set width [lindex $sizes 2]
522    # use the scroll for BIG constraints
523    if {$width > 600} {
524        set width 600
525        grid $top.scroll -sticky ew -column 0 -row 3 -columnspan 4
526    }
527    $top.canvas config -height [lindex $sizes 3] -width $width
528}
529
530# called to delete profile constraints
531proc DeleteProfileConstraints {} {
532    global expgui expcons
533    # get the constraints to delete
534    set dellist {}
535    # loop over used profile terms
536    for {set i 1} {$i <= 36} {incr i} {
537        set ncons [constrinfo profile$i get 0]
538        # loop over the defined constraints
539        for {set j 1} {$j <= $ncons} {incr j} {
540            if {$expcons(delete${i}_$j)} {lappend dellist [list $i $j]}
541        }
542    }
543    # nothing to delete?
544    if {$dellist == ""} return
545    if {[MyMessageBox -message \
546            "Do you want to delete [llength $dellist] constraint(s)?" \
547            -parent [winfo toplevel $expcons(profilemaster)] \
548            -type {No Delete} -default no] == "no"} return
549    foreach item [lsort -decreasing -integer -index 1 $dellist] {
550        set i [lindex $item 0]
551        constrinfo profile$i delete [lindex $item 1]
552        incr expgui(changed)
553    }
554    DisplayProfileConstraints
555}
556
557
558# take the info in the Edit Profile Constraint page and save it in
559# the .EXP array
560proc SaveProfileConstraint {num term top} {
561    global expcons expmap expgui
562    set conslist {}
563    for {set ic 1} {$ic < 27} {incr ic} {
564        if ![info exists expcons(phaselistbox$ic)] break
565        if ![info exists expcons(histlistbox$ic)] break
566        if ![winfo exists $expcons(phaselistbox$ic)] break
567        if ![winfo exists $expcons(histlistbox$ic)] break
568        set phases [$expcons(phaselistbox$ic) curselection]
569        set hists [$expcons(histlistbox$ic) curselection]
570        if {[llength $phases] == [llength $expmap(phaselist)]} {
571            set phases "ALL"
572        }
573        if {[llength $hists] == [llength $expmap(powderlist)]} {
574            set hists "ALL"
575        }
576        foreach h $hists {
577            if {$h == "ALL"} {
578                set hist "ALL"
579            } else {
580                set hist [lindex [$expcons(histlistbox$ic) get $h] 0]
581            }
582            foreach p $phases {
583                if {$p == "ALL"} {
584                    set phase "ALL"
585                } else {
586                    set phase [lindex $expmap(phaselist) $p]
587                }
588                lappend conslist [list $phase $hist $expcons(mult$ic)]
589            }
590        }
591    }
592    if {[llength $conslist] > 27} {
593        MyMessageBox -icon warning \
594                -message "Note: you have entered [llength $conslist] terms, only 27 can be used" \
595                -helplink "expgui6.html ProfileConstraintsMax" \
596                -parent [winfo toplevel $expgui(consFrame)] 
597        return
598    }
599    foreach t $term {
600        if {$num != "add"} {
601            constrinfo profile$t set $num $conslist
602        } else {
603            constrinfo profile$t add $num $conslist
604        }
605        incr expgui(changed)
606    }
607    destroy $top
608    DisplayProfileConstraints
609}
610
611# Called to create a new profile constraint. Works in two steps,
612# 1st the profile type and terms are selected and
613# 2nd the constraint is defined using EditProfileConstraint
614proc NewProfileConstraint {} {
615    global expcons expmap expgui
616
617    set top {.editcons}
618    catch {toplevel $top}
619    bind $top <Key-F1> "MakeWWWHelp expgui6.html NewProfileConstraints"
620    eval destroy [grid slaves $top]
621
622    wm title $top "New Profile Constraint"
623    grid [label $top.top -text "Editing new profile constraint"] \
624            -column 0 -row 0 -columnspan 4
625    grid [frame $top.fr1] -column 1 -row 1 -columnspan 3 -sticky w
626    grid [frame $top.fr2] -column 1 -row 2 -columnspan 3 -sticky w
627    grid [frame $top.fr3] -column 1 -row 3 -columnspan 3 -sticky w
628    grid [frame $top.fr4 -relief groove -bd 2] \
629            -column 0 -row 4 -columnspan 4 -sticky w
630    # need to get histogram type
631    grid [label $top.fr1a -text "Choose histogram type:"] \
632            -column 0 -row 1 
633    grid [radiobutton $top.fr1.b -value T -variable expcons(ProfileHistType) \
634            -command "ResetProfileHistogram $top.fr4"\
635            -text "TOF"] -column 1 -row 1
636    grid [radiobutton $top.fr1.c -value C -variable expcons(ProfileHistType) \
637            -command "ResetProfileHistogram $top.fr4"\
638            -text "Constant Wavelength"] -column 2 -row 1
639    grid [radiobutton $top.fr1.d -value E -variable expcons(ProfileHistType) \
640            -command "ResetProfileHistogram $top.fr4"\
641            -text "Energy Disp. X-ray"] -column 3 -row 1
642    #
643    # need to get histogram type
644    grid [label $top.fr2a -text "Choose profile function:"] \
645            -column 0 -row 2 
646    foreach i {1 2 3 4} {
647        grid [radiobutton $top.fr2.$i -value $i \
648                -variable expcons(ProfileFunction) \
649                -command "ResetProfileHistogram $top.fr4"\
650                -text $i] -column $i -row 2
651    }
652    # and need to get phase # (for type 4 profile)
653    grid [label $top.fr3a -text "Choose phase:"] \
654            -column 0 -row 3
655    foreach i $expmap(phaselist) {
656        grid [radiobutton $top.fr3.$i -value $i \
657                -variable expcons(ProfilePhase) \
658                -command "ResetProfileHistogram $top.fr4"\
659                -text $i] -column $i -row 3
660    }
661    grid [button $top.b1 -text Continue \
662            -command "set expcons(createflag) 1"] -column 0 -row 5
663    grid [button $top.b2 -text Cancel \
664            -command "set expcons(createflag) 0"] -sticky w -column 1 -row 5
665    grid [button $top.help -text Help -bg yellow \
666            -command "MakeWWWHelp expgui6.html NewProfileConstraints"] \
667            -column 2 -row 5 -columnspan 99 -sticky e
668
669    # default values by 1st histogram
670    set h [lindex $expmap(powderlist) 0]
671    # histogram type
672    set expcons(ProfileHistType) [string range $expmap(htype_$h) 2 2]
673    set p [lindex $expmap(phaselist_$h) 0]
674    set expcons(ProfilePhase) $p
675    # profile type
676    set expcons(ProfileFunction) [string trim [hapinfo $h $p proftype]]
677    ResetProfileHistogram $top.fr4
678
679    # wait for a response
680    putontop $top
681    tkwait variable expcons(createflag)
682    if $expcons(createflag) {
683        eval destroy [winfo children $top]
684    } else {
685        destroy $top
686        return
687    }
688    set p $expcons(ProfilePhase)
689    set ptype $expcons(ProfileFunction)
690    set htype $expcons(ProfileHistType)
691    set termlist {}
692    set i 0
693    foreach lbl [GetProfileTerms $p $htype $ptype] {
694        incr i
695        if {$expcons(newcons$i)} {lappend termlist $i}
696    }
697    EditProfileConstraint $termlist add {}
698    afterputontop
699}
700
701# setup a box with the defined profile constraint terms
702proc ResetProfileHistogram {top} {
703    global expcons
704    set p $expcons(ProfilePhase)
705    set ptype $expcons(ProfileFunction)
706    set htype $expcons(ProfileHistType)
707    eval destroy [winfo children $top]
708    grid [label $top.0 -text "Choose profile terms to constrain:"] \
709            -column 0 -columnspan 4 -row 0 -sticky w
710    # loop over profile term labels
711    set i 0
712    set row 0
713    set col 0
714    foreach lbl [GetProfileTerms $p $htype $ptype] {
715        incr i
716        incr row
717        if {$row > 10} {
718            set row 1
719            incr col
720        }
721        grid [checkbutton $top.$i -text "#$i ($lbl)" \
722                -variable expcons(newcons$i) \
723                ] -column $col -row $row -sticky w
724    }
725}
Note: See TracBrowser for help on using the repository browser.