1 | # Implement profile constraints |
---|
2 | # $Revision: 320 $ $Date: 2009-12-04 23:04:05 +0000 (Fri, 04 Dec 2009) $ |
---|
3 | |
---|
4 | |
---|
5 | # make the profile constraints pane |
---|
6 | proc 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 |
---|
29 | proc 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 | if {$h == "ALL"} {set h [lindex $expmap(powderlist) 0]} |
---|
140 | set p [lindex [lindex $item 0] 0] |
---|
141 | if {$p == "ALL"} {set p [lindex $expmap(phaselist_$h) 0]} |
---|
142 | # profile type |
---|
143 | set ptype [string trim [hapinfo $h $p proftype]] |
---|
144 | # histogram type |
---|
145 | set htype [string range $expmap(htype_$h) 2 2] |
---|
146 | # get the profile term labels |
---|
147 | set lbl [lindex "dummy [GetProfileTerms $p $h $ptype]" $i] |
---|
148 | if {$lbl == ""} {set lbl ?} |
---|
149 | |
---|
150 | foreach item $conslist { |
---|
151 | set col 6 |
---|
152 | incr row |
---|
153 | grid [label $top.tn${row}-$col \ |
---|
154 | -text [CompressList [lindex $item 0]]] \ |
---|
155 | -column [incr col] -row $row |
---|
156 | grid [label $top.tn${row}-$col \ |
---|
157 | -text [CompressList [lindex $item 1]]] \ |
---|
158 | -column [incr col] -row $row |
---|
159 | grid [label $top.tn${row}-$col -text [lindex $item 2]] \ |
---|
160 | -column [incr col] -row $row |
---|
161 | incr col |
---|
162 | } |
---|
163 | incr row |
---|
164 | grid [label $top.ts$row0 -text $j] -column 4 \ |
---|
165 | -row $row0 -rowspan [expr $row - $row0] |
---|
166 | if {[lsearch $errlist $j] != -1} {$top.ts$row0 config -fg red} |
---|
167 | grid [label $top.tu$row0 -text "($lbl)"] -column 2 \ |
---|
168 | -row $row0 -rowspan [expr $row - $row0] |
---|
169 | grid [button $top.edit$row0 -text edit \ |
---|
170 | -command "EditProfileConstraint $i $j [list $conslist]" \ |
---|
171 | ] -column 5 -row $row0 -rowspan [expr $row - $row0] |
---|
172 | set expcons(delete${i}_$j) 0 |
---|
173 | grid [checkbutton $top.del$row0 \ |
---|
174 | -variable expcons(delete${i}_$j)] -column 11 \ |
---|
175 | -row $row0 -rowspan [expr $row - $row0] |
---|
176 | if {$j < $ncons} { |
---|
177 | # put a spacer between each term |
---|
178 | grid [frame $top.spb$row -bd 1 -bg white] \ |
---|
179 | -columnspan 11 -column 3 -row $row -sticky nsew |
---|
180 | grid rowconfig $top $row -minsize 1 -pad 1 |
---|
181 | incr row |
---|
182 | } |
---|
183 | } |
---|
184 | grid [label $top.tt$row -text "#$i "] -column 0 \ |
---|
185 | -row $row1 -rowspan [expr $row - $row1] |
---|
186 | } |
---|
187 | # resize the canvas & scrollbar |
---|
188 | update idletasks |
---|
189 | set sizes [grid bbox $top] |
---|
190 | $expcons(profilemaster).canvas config -scrollregion $sizes |
---|
191 | set hgt [lindex $sizes 3] |
---|
192 | # set the maximum height for the canvas from the frame |
---|
193 | set maxheight [expr \ |
---|
194 | [winfo height [winfo parent $expgui(consFrame)]] - 130] |
---|
195 | |
---|
196 | # use the scroll for BIG constraint lists |
---|
197 | if {$hgt > $maxheight} { |
---|
198 | grid $expcons(profilemaster).scroll -sticky ns -column 2 -row 0 |
---|
199 | } else { |
---|
200 | grid forget $expcons(profilemaster).scroll |
---|
201 | } |
---|
202 | $expcons(profilemaster).canvas config \ |
---|
203 | -height $maxheight \ |
---|
204 | -width [lindex $sizes 2] |
---|
205 | $expgui(consFrame).n compute_size |
---|
206 | donewait |
---|
207 | if {$msg != ""} { |
---|
208 | 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" |
---|
209 | MyMessageBox -icon error -message $msg \ |
---|
210 | -helplink "expgui6.html ProfileConstraintErr" \ |
---|
211 | -parent [winfo toplevel $expgui(consFrame)] |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | |
---|
216 | # summarize profile constraints: |
---|
217 | # group histograms that have the same phase & mult |
---|
218 | proc SortProfileConstraints {conslist} { |
---|
219 | # grouped list |
---|
220 | set glist {} |
---|
221 | # previous phase |
---|
222 | set pp 0 |
---|
223 | # phase list |
---|
224 | set pplist {} |
---|
225 | # sort list on phase (add a dummy element) |
---|
226 | foreach item "[lsort -index 0 $conslist] {0 0 0}" { |
---|
227 | set p [lindex $item 0] |
---|
228 | if {$p != $pp} { |
---|
229 | # ok have a list containing only 1 phase |
---|
230 | if {$pp != 0} { |
---|
231 | set mp 0 |
---|
232 | set hl {} |
---|
233 | foreach item2 "[lsort -index 2 -decreasing -real $pplist] {0 0 0}" { |
---|
234 | set m [lindex $item2 2] |
---|
235 | if {$m != $mp} { |
---|
236 | # have a list containing 1 phase and the same multiplier |
---|
237 | if {$mp != 0} { |
---|
238 | # do we another entry with the same multiplier |
---|
239 | set hl [lsort $hl] |
---|
240 | set i 0 |
---|
241 | foreach item3 $glist { |
---|
242 | if {[lindex $item3 1] == $hl && \ |
---|
243 | [lindex $item3 2] == $mp} { |
---|
244 | # got one that matches |
---|
245 | # add the phase & replace it |
---|
246 | set pp "[lindex $item3 0] $pp" |
---|
247 | set glist [lreplace \ |
---|
248 | $glist $i $i \ |
---|
249 | "[list $pp] [list $hl] $mp"] |
---|
250 | break |
---|
251 | } |
---|
252 | incr i |
---|
253 | } |
---|
254 | # we have looped all the way through |
---|
255 | # not matched, so add it to the list |
---|
256 | if {$i == [llength $glist]} { |
---|
257 | lappend glist "$pp [list $hl] $mp" |
---|
258 | } |
---|
259 | } |
---|
260 | set mp $m |
---|
261 | set hl [lindex $item2 1] |
---|
262 | } else { |
---|
263 | lappend hl [lindex $item2 1] |
---|
264 | } |
---|
265 | } |
---|
266 | } |
---|
267 | set pp $p |
---|
268 | set pplist [list $item] |
---|
269 | } else { |
---|
270 | lappend pplist $item |
---|
271 | } |
---|
272 | } |
---|
273 | return $glist |
---|
274 | } |
---|
275 | |
---|
276 | # called to edit a single profile constraint set |
---|
277 | proc EditProfileConstraint {term num conslist} { |
---|
278 | global expcons expmap expgui |
---|
279 | |
---|
280 | set top {.editcons} |
---|
281 | catch {toplevel $top} |
---|
282 | eval destroy [grid slaves $top] |
---|
283 | bind $top <Key-F1> "MakeWWWHelp expgui6.html EditProfileConstraints" |
---|
284 | |
---|
285 | if {$num != "add"} { |
---|
286 | # set the phase & histogram type from the first entry in the list |
---|
287 | set item [lindex $conslist 0] |
---|
288 | set h [lindex [lindex $item 1] 0] |
---|
289 | if {$h == "ALL"} {set h [lindex $expmap(powderlist) 0]} |
---|
290 | set p [lindex [lindex $item 0] 0] |
---|
291 | if {$p == "ALL"} {set p [lindex $expmap(phaselist_$h) 0]} |
---|
292 | # profile type |
---|
293 | set ptype [string trim [hapinfo $h $p proftype]] |
---|
294 | # histogram type |
---|
295 | set htype [string range $expmap(htype_$h) 2 2] |
---|
296 | set expcons(ProfileHistType) [string range $expmap(htype_$h) 2 2] |
---|
297 | } else { |
---|
298 | set p $expcons(ProfilePhase) |
---|
299 | set ptype $expcons(ProfileFunction) |
---|
300 | set htype $expcons(ProfileHistType) |
---|
301 | } |
---|
302 | set lbls "dummy [GetProfileTerms $p $htype $ptype]" |
---|
303 | # get the cached copy of the profile term labels, when possible |
---|
304 | if {$num != "add"} { |
---|
305 | wm title $top "Constraint #$num for term $term" |
---|
306 | set lbl [lindex $lbls $term] |
---|
307 | if {$lbl == ""} {set lbl ?} |
---|
308 | set txt "Editing constraint #$num for term $term ($lbl)" |
---|
309 | } else { |
---|
310 | wm title $top "New constraint for term(s) [CompressList $term]" |
---|
311 | set txt "Editing new constraint for term(s) " |
---|
312 | set i 0 |
---|
313 | foreach t $term { |
---|
314 | set lbl [lindex $lbls $t] |
---|
315 | if {$lbl == ""} {set lbl ?} |
---|
316 | if {$i == 3 || $i == 10 || $i == 16 || $i == 22} { |
---|
317 | append txt ",\n" |
---|
318 | } elseif {$i != 0} { |
---|
319 | append txt ", " |
---|
320 | } |
---|
321 | append txt "$t ($lbl)" |
---|
322 | incr i |
---|
323 | } |
---|
324 | } |
---|
325 | grid [label $top.top -text $txt -anchor w] -column 0 -row 0 -columnspan 20 |
---|
326 | |
---|
327 | if {$expcons(ProfileHistType) == "T"} { |
---|
328 | set type "TOF" |
---|
329 | } elseif {$expcons(ProfileHistType) == "C"} { |
---|
330 | set type "Constant Wavelength" |
---|
331 | } elseif {$expcons(ProfileHistType) == "E"} { |
---|
332 | set type "Energy Dispersive X-ray" |
---|
333 | } |
---|
334 | grid [label $top.typ -text "Histogram type: $type"] \ |
---|
335 | -column 0 -row 1 -columnspan 20 |
---|
336 | grid [canvas $top.canvas \ |
---|
337 | -scrollregion {0 0 5000 500} -width 100 -height 50 \ |
---|
338 | -xscrollcommand "$top.scroll set"] \ |
---|
339 | -column 0 -row 2 -columnspan 4 -sticky nsew |
---|
340 | grid columnconfigure $top 3 -weight 1 |
---|
341 | grid rowconfigure $top 2 -weight 1 |
---|
342 | catch {destroy $top.scroll} |
---|
343 | scrollbar $top.scroll -orient horizontal \ |
---|
344 | -command "$top.canvas xview" |
---|
345 | # grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4 |
---|
346 | # create a scrollable frame inside the canvas |
---|
347 | set cfr [frame $top.canvas.fr] |
---|
348 | $top.canvas create window 0 0 -anchor nw -window $cfr |
---|
349 | |
---|
350 | grid [button $top.add -text "New Column" \ |
---|
351 | -command "NewProfileConstraintColumn $top $cfr" \ |
---|
352 | ] -column 0 -row 4 -columnspan 2 -sticky ew |
---|
353 | grid [button $top.done -text "Save" \ |
---|
354 | -command "SaveProfileConstraint $num [list $term] $top" \ |
---|
355 | ] -column 0 -row 5 -sticky ns |
---|
356 | grid [button $top.quit -text "Cancel\nChanges" \ |
---|
357 | -command "CancelEditConstraint $top" \ |
---|
358 | ] -column 1 -row 5 |
---|
359 | grid [button $top.help -text Help -bg yellow \ |
---|
360 | -command "MakeWWWHelp expgui6.html EditProfileConstraints"] \ |
---|
361 | -column 2 -row 4 -columnspan 99 -rowspan 2 -sticky e |
---|
362 | |
---|
363 | set col 0 |
---|
364 | set row 2 |
---|
365 | # row headings |
---|
366 | grid rowconfigure $cfr 6 -weight 1 |
---|
367 | foreach lbl {Phase(s) Histogram(s) Multiplier} { |
---|
368 | # row separator |
---|
369 | grid [frame $cfr.spd$row -bd 8 -bg white] \ |
---|
370 | -columnspan 60 -column 0 -row [incr row] -sticky nsew |
---|
371 | grid rowconfig $cfr $row -minsize 2 -pad 2 |
---|
372 | grid [label $cfr.t$row -text $lbl] -column $col -row [incr row] |
---|
373 | } |
---|
374 | |
---|
375 | # row separator |
---|
376 | grid [frame $cfr.spe$row -bd 8 -bg white] \ |
---|
377 | -columnspan 60 -column 0 -row [incr row] -sticky nsew |
---|
378 | grid rowconfig $cfr $row -minsize 2 -pad 2 |
---|
379 | |
---|
380 | set ic 0 |
---|
381 | set col 1 |
---|
382 | foreach constr $conslist { |
---|
383 | incr ic |
---|
384 | MakeProfileConstraintColumn $cfr $ic $col |
---|
385 | FillProfileConstraintColumn $cfr $ic $col |
---|
386 | incr col 3 |
---|
387 | } |
---|
388 | if {$conslist == ""} {NewProfileConstraintColumn $top $cfr} |
---|
389 | # resize the canvas & scrollbar |
---|
390 | update idletasks |
---|
391 | set sizes [grid bbox $cfr] |
---|
392 | $top.canvas config -scrollregion $sizes |
---|
393 | set width [lindex $sizes 2] |
---|
394 | # use the scroll for BIG constraints |
---|
395 | if {$width > 600} { |
---|
396 | set width 600 |
---|
397 | grid $top.scroll -sticky ew -column 0 -row 3 -columnspan 4 |
---|
398 | } |
---|
399 | $top.canvas config -height [lindex $sizes 3] -width $width |
---|
400 | set ic 0 |
---|
401 | set col 1 |
---|
402 | foreach constr $conslist { |
---|
403 | incr ic |
---|
404 | SelectProfileConstraintColumn $cfr $ic $col $constr |
---|
405 | incr col 3 |
---|
406 | set expcons(mult$ic) [lindex $constr 2] |
---|
407 | } |
---|
408 | # force the window to stay on top |
---|
409 | putontop $top |
---|
410 | tkwait window $top |
---|
411 | afterputontop |
---|
412 | } |
---|
413 | |
---|
414 | # called to make each column in the atom parameter dialog |
---|
415 | proc MakeProfileConstraintColumn {cfr ic col} { |
---|
416 | global expmap expcons expgui |
---|
417 | set row 2 |
---|
418 | # make column separator |
---|
419 | grid [frame $cfr.spc$col -bd 8 -bg white] \ |
---|
420 | -rowspan 7 -column $col -row $row -sticky nsew |
---|
421 | grid columnconfig $cfr $col -minsize 2 -pad 2 |
---|
422 | set col1 [incr col] |
---|
423 | set col2 [incr col] |
---|
424 | # make the phase listbox |
---|
425 | set expcons(phaselistbox$ic) $cfr.lbp$ic |
---|
426 | grid [listbox $cfr.lbp$ic \ |
---|
427 | -height [llength $expmap(phaselist)] -width 12 \ |
---|
428 | -font $expgui(coordfont) \ |
---|
429 | -exportselection 0 -selectmode extended] \ |
---|
430 | -column $col1 -columnspan 2 -row [incr row 2] -sticky nsew |
---|
431 | bind $expcons(phaselistbox$ic) <Button-3> \ |
---|
432 | "$expcons(phaselistbox$ic) selection set 0 end" |
---|
433 | # make the histogram listbox |
---|
434 | set expcons(histlistbox$ic) $cfr.lbh$ic |
---|
435 | grid [listbox $cfr.lbh$ic -height 10 -width 12 \ |
---|
436 | -font $expgui(coordfont) \ |
---|
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 |
---|
452 | proc 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 |
---|
472 | proc 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 |
---|
504 | proc 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 |
---|
531 | proc 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 |
---|
560 | proc 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 |
---|
614 | proc 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 |
---|
702 | proc 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 | } |
---|