1 | # initial constraint sort mode |
---|
2 | set expcons(sortmode) num |
---|
3 | # size of constraint box |
---|
4 | set expcons(height) 300 |
---|
5 | |
---|
6 | # this is used to create the contents of the constraint page |
---|
7 | proc MakeConstraintsPane {} { |
---|
8 | global expgui expcons |
---|
9 | # create the notebook |
---|
10 | grid [NoteBook $expgui(consFrame).n -bd 2 -side bottom] -sticky news |
---|
11 | # create pages for each of the constraint "subpages" |
---|
12 | set expcons(atommaster) [\ |
---|
13 | $expgui(consFrame).n insert end atomic -text Atomic \ |
---|
14 | -createcmd "MakeAtomsConstraintsPane" \ |
---|
15 | -raisecmd "DisplayAtomConstraints"] |
---|
16 | # a profile constraints page (someday) |
---|
17 | $expgui(consFrame).n insert end profile -text Profile -state disabled |
---|
18 | |
---|
19 | # open the atom constraints page |
---|
20 | $expgui(consFrame).n raise atomic |
---|
21 | } |
---|
22 | |
---|
23 | # fill the atom constraints pane |
---|
24 | proc MakeAtomsConstraintsPane {} { |
---|
25 | global expgui expcons |
---|
26 | |
---|
27 | grid [button $expcons(atommaster).new -text "New Constraint" \ |
---|
28 | -command "EditAtomConstraint new"] \ |
---|
29 | -column 0 -sticky sw -row 1 |
---|
30 | grid [button $expcons(atommaster).del -text "Delete" \ |
---|
31 | -command "DeleteAtomConstraints"] \ |
---|
32 | -column 1 -sticky se -row 1 |
---|
33 | grid [canvas $expcons(atommaster).canvas \ |
---|
34 | -scrollregion {0 0 5000 500} -width 0 -height 250 \ |
---|
35 | -yscrollcommand "$expcons(atommaster).scroll set"] \ |
---|
36 | -column 0 -row 0 -columnspan 2 -sticky nsew |
---|
37 | grid columnconfigure $expcons(atommaster) 0 -weight 1 |
---|
38 | grid rowconfigure $expcons(atommaster) 0 -weight 1 |
---|
39 | grid rowconfigure $expcons(atommaster) 1 -pad 5 |
---|
40 | scrollbar $expcons(atommaster).scroll \ |
---|
41 | -command "$expcons(atommaster).canvas yview" |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | # this is called to display the constraints on atomic parameters |
---|
46 | proc DisplayAtomConstraints {} { |
---|
47 | global expgui expcons expmap |
---|
48 | catch {destroy $expcons(atommaster).canvas.fr} |
---|
49 | set top [frame $expcons(atommaster).canvas.fr] |
---|
50 | $expcons(atommaster).canvas create window 0 0 -anchor nw -window $top |
---|
51 | |
---|
52 | # get a list of constraints |
---|
53 | set expcons(lastconstr) 0 |
---|
54 | set expcons(clist) {} |
---|
55 | set i 0 |
---|
56 | catch {unset varlist} |
---|
57 | while {[set clist [constrinfo atom get [incr i]]] != -1} { |
---|
58 | set clist [lsort -integer -index 1 $clist] |
---|
59 | if {$expcons(sortmode) == "num"} { |
---|
60 | set sortvar $i |
---|
61 | } elseif {$expcons(sortmode) == "var"} { |
---|
62 | set sortvar [lindex [lindex $clist 0] 2] |
---|
63 | } elseif {$expcons(sortmode) == "atom"} { |
---|
64 | set sortvar [lindex [lindex $clist 0] 1] |
---|
65 | if {$sortvar == "ALL"} {set sortvar 0} |
---|
66 | } elseif {$expcons(sortmode) == "phase"} { |
---|
67 | set sortvar [lindex [lindex $clist 0] 0] |
---|
68 | } |
---|
69 | # tabulate a list where each phase-atom-var is referenced |
---|
70 | foreach item $clist { |
---|
71 | set phase [lindex $item 0] |
---|
72 | set atom [lindex $item 1] |
---|
73 | if {$atom == "ALL"} {set atom $expmap(atomlist_$phase)} |
---|
74 | foreach a $atom { |
---|
75 | set key [lindex $item 2]_${phase}_${a} |
---|
76 | lappend varlist($key) $i |
---|
77 | } |
---|
78 | } |
---|
79 | lappend expcons(clist) [list $sortvar $i $clist] |
---|
80 | } |
---|
81 | # were any variables referenced more than once? |
---|
82 | |
---|
83 | set problems {} |
---|
84 | foreach key [array names varlist] { |
---|
85 | if {[llength $varlist($key)] > 1} { |
---|
86 | append problems " $varlist($key)" |
---|
87 | } |
---|
88 | } |
---|
89 | # column headings |
---|
90 | set row 0 |
---|
91 | set col -1 |
---|
92 | foreach lbl {# "" Phase \ |
---|
93 | "" Atom(s) Variable Multiplier \ |
---|
94 | "" Atom(s) Variable Multiplier \ |
---|
95 | "" Delete} { |
---|
96 | incr col |
---|
97 | if {$lbl != ""} { |
---|
98 | grid [label $top.t$col -text $lbl] -column $col -row $row |
---|
99 | } |
---|
100 | } |
---|
101 | # make some column headings into buttons |
---|
102 | foreach col {0 2 4 5} val {num phase atom var} { |
---|
103 | $top.t$col config -relief raised -bd 2 |
---|
104 | bind $top.t$col <1> "set expcons(sortmode) $val; DisplayAtomConstraints" |
---|
105 | } |
---|
106 | # extra column spacing |
---|
107 | foreach col {1 2 4 5 6 8 9 10} { |
---|
108 | grid columnconfig $top $col -pad 6 |
---|
109 | } |
---|
110 | set i 0 |
---|
111 | if {$expcons(sortmode) == "var"} { |
---|
112 | set sortlist [lsort -index 0 -ascii $expcons(clist)] |
---|
113 | } else { |
---|
114 | set sortlist [lsort -index 0 -integer $expcons(clist)] |
---|
115 | } |
---|
116 | foreach item $sortlist { |
---|
117 | set clist [lindex $item 2] |
---|
118 | set num [lindex $item 1] |
---|
119 | incr i |
---|
120 | # row separator |
---|
121 | grid [frame $top.sp$row -bd 8 -bg white] \ |
---|
122 | -columnspan 20 -column 0 -row [incr row] -sticky nsew |
---|
123 | grid rowconfig $top $row -minsize 2 -pad 2 |
---|
124 | set startrow [incr row] |
---|
125 | catch {unset atomlist} |
---|
126 | # make a list of unique phase #, variables & multipliers |
---|
127 | foreach item $clist { |
---|
128 | set key [lindex $item 0]_[lindex $item 2]_[lindex $item 3] |
---|
129 | lappend atomlist($key) [lindex $item 1] |
---|
130 | } |
---|
131 | set phprev 0 |
---|
132 | incr row -1 |
---|
133 | foreach key [lsort [array names atomlist]] { |
---|
134 | regexp {(.*)_(.*)_(.*)} $key dummy phase var mult |
---|
135 | if {$phase != $phprev} { |
---|
136 | set col 1 |
---|
137 | if {$phprev!= 0} { |
---|
138 | grid [frame $top.sp$row -bg white] \ |
---|
139 | -columnspan 14 -column 2 \ |
---|
140 | -row [incr row] -sticky nsew |
---|
141 | grid rowconfig $top $row -minsize 1 |
---|
142 | } |
---|
143 | grid [label $top.c${col}$row -text $phase] \ |
---|
144 | -column [incr col] -row [incr row] |
---|
145 | set phprev $phase |
---|
146 | } |
---|
147 | incr col |
---|
148 | if {$col > 8} { |
---|
149 | incr row |
---|
150 | set col 3 |
---|
151 | } |
---|
152 | grid [label $top.c${col}$row \ |
---|
153 | -text [CompressList $atomlist($key)]] \ |
---|
154 | -column [incr col] -row $row -sticky w |
---|
155 | grid [label $top.c${col}$row -text $var] \ |
---|
156 | -column [incr col] -row $row |
---|
157 | if {$mult > 0} { |
---|
158 | grid [label $top.c${col}$row -text "x $mult"] \ |
---|
159 | -column [incr col] -row $row |
---|
160 | } else { |
---|
161 | grid [label $top.c${col}$row -text "x $mult" -fg red] \ |
---|
162 | -column [incr col] -row $row |
---|
163 | } |
---|
164 | } |
---|
165 | grid [button $top.but$row -text "edit" \ |
---|
166 | -command "EditAtomConstraint $num"] \ |
---|
167 | -column 1 -row $startrow \ |
---|
168 | -rowspan [expr 1 + $row - $startrow] |
---|
169 | set expcons(delete$num) 0 |
---|
170 | grid [checkbutton $top.del$row \ |
---|
171 | -variable expcons(delete$num)] \ |
---|
172 | -column 12 -row $startrow \ |
---|
173 | -rowspan [expr 1 + $row - $startrow] |
---|
174 | if {[lsearch $problems $num] == -1} { |
---|
175 | grid [label $top.l$i -text $num] \ |
---|
176 | -column 0 -row $startrow \ |
---|
177 | -rowspan [expr 1 + $row - $startrow] |
---|
178 | } else { |
---|
179 | grid [label $top.l$i -text $num -fg red] \ |
---|
180 | -column 0 -row $startrow \ |
---|
181 | -rowspan [expr 1 + $row - $startrow] |
---|
182 | } |
---|
183 | set expcons(lastconstr) \ |
---|
184 | [expr $expcons(lastconstr) > $num ? \ |
---|
185 | $expcons(lastconstr) : $num ] |
---|
186 | } |
---|
187 | # row separator |
---|
188 | grid [frame $top.sp$row -bd 8 -bg white] \ |
---|
189 | -columnspan 16 -column 0 -row [incr row] -sticky nsew |
---|
190 | grid rowconfig $top $row -minsize 2 -pad 2 |
---|
191 | # column separators |
---|
192 | foreach col {3 7 11} { |
---|
193 | grid [frame $top.vs${col}$row -bd 8 -bg white] \ |
---|
194 | -column $col -row 0 -rowspan $row -sticky nsew |
---|
195 | grid columnconfig $top $col -minsize 2 -pad 2 |
---|
196 | } |
---|
197 | # resize the canvas & scrollbar |
---|
198 | update idletasks |
---|
199 | set sizes [grid bbox $top] |
---|
200 | $expcons(atommaster).canvas config -scrollregion $sizes |
---|
201 | set hgt [lindex $sizes 3] |
---|
202 | # set the maximum height for the canvas from the frame |
---|
203 | set maxheight [expr \ |
---|
204 | [winfo height [winfo parent $expgui(consFrame)]] - 130] |
---|
205 | |
---|
206 | # use the scroll for BIG constraint lists |
---|
207 | if {$hgt > $maxheight} { |
---|
208 | grid $expcons(atommaster).scroll -sticky ns -column 2 -row 0 |
---|
209 | } |
---|
210 | # report constraint errors |
---|
211 | $expcons(atommaster).canvas config \ |
---|
212 | -height $maxheight \ |
---|
213 | -width [lindex $sizes 2] |
---|
214 | set msg {} |
---|
215 | foreach key [lsort [array names varlist]] { |
---|
216 | if {[llength $varlist($key)] > 1} { |
---|
217 | regexp {(.*)_(.*)_(.*)} $key dummy var phase atom |
---|
218 | append msg " $var for atom $atom (phase $phase) is in" |
---|
219 | append msg " constraints [CompressList $varlist($key)]\n" |
---|
220 | } |
---|
221 | } |
---|
222 | $expgui(consFrame).n compute_size |
---|
223 | update idletasks |
---|
224 | if {$msg != ""} { |
---|
225 | set msg "Error: an atomic parameter can appear in only one constraint. Here is a list of parameters that are referenced in more than one constraint:\n\n$msg" |
---|
226 | MyMessageBox -icon error -message $msg -parent [winfo toplevel $expgui(consFrame)] |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | # this is called to delete an atomic constraint |
---|
231 | proc DeleteAtomConstraints {} { |
---|
232 | global expcons expgui |
---|
233 | # get the constraints to delete |
---|
234 | set dellist {} |
---|
235 | for {set i 1} {$i <= $expcons(lastconstr)} {incr i} { |
---|
236 | if $expcons(delete$i) {lappend dellist $i} |
---|
237 | } |
---|
238 | # nothing to delete? |
---|
239 | if {$dellist == ""} return |
---|
240 | if {[MyMessageBox -message \ |
---|
241 | "Do you want to delete constraint(s) [CompressList $dellist]?" \ |
---|
242 | -parent [winfo toplevel $expcons(atommaster)] \ |
---|
243 | -type {No Delete} -default no] == "no"} return |
---|
244 | # if {![tk_dialog .delete {Delete Constraints?} \ |
---|
245 | # "Do you want to delete constraint(s) [CompressList $dellist]?" \ |
---|
246 | # warning 0 {No} {Delete}] } return |
---|
247 | |
---|
248 | foreach num [lsort -decreasing -integer $dellist] { |
---|
249 | constrinfo atom delete $num |
---|
250 | incr expgui(changed) |
---|
251 | } |
---|
252 | DisplayAtomConstraints |
---|
253 | } |
---|
254 | |
---|
255 | # called to edit a single constraint set |
---|
256 | proc EditAtomConstraint {num args} { |
---|
257 | global expcons expmap expgui |
---|
258 | |
---|
259 | set top {.editcons} |
---|
260 | catch {toplevel $top} |
---|
261 | eval destroy [grid slaves $top] |
---|
262 | if {$num == "new"} { |
---|
263 | wm title $top "New Constraint" |
---|
264 | set clist {} |
---|
265 | grid [label $top.top -text "Editing new constraint"] \ |
---|
266 | -column 0 -row 0 -columnspan 4 |
---|
267 | |
---|
268 | } else { |
---|
269 | wm title $top "Constraint #$num" |
---|
270 | set clist [constrinfo atom get $num] |
---|
271 | grid [label $top.top -text "Editing constraint #$num"] \ |
---|
272 | -column 0 -row 0 -columnspan 4 |
---|
273 | } |
---|
274 | # column headings |
---|
275 | grid [canvas $top.canvas \ |
---|
276 | -scrollregion {0 0 5000 500} -width 100 -height 50 \ |
---|
277 | -xscrollcommand "$top.scroll set"] \ |
---|
278 | -column 0 -row 1 -columnspan 4 -sticky nsew |
---|
279 | grid columnconfigure $top 3 -weight 1 |
---|
280 | grid rowconfigure $top 1 -weight 1 |
---|
281 | catch {destroy $top.scroll} |
---|
282 | scrollbar $top.scroll -orient horizontal \ |
---|
283 | -command "$top.canvas xview" |
---|
284 | # grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4 |
---|
285 | # create a scrollable frame inside the canvas |
---|
286 | set cfr [frame $top.canvas.fr] |
---|
287 | $top.canvas create window 0 0 -anchor nw -window $cfr |
---|
288 | |
---|
289 | grid [button $top.add -text "New Column" \ |
---|
290 | -command "NewAtomConstraintColumn $top $cfr $num"] \ |
---|
291 | -column 0 -row 3 -columnspan 2 |
---|
292 | grid [button $top.done -text "Save" \ |
---|
293 | -command "SaveAtomConstraint $num $top"] \ |
---|
294 | -column 0 -row 4 |
---|
295 | # set cmd "if {!\[tk_dialog .changes {Abandon Changes} \ |
---|
296 | # {Do you want to lose any changes made to this constraint?} \ |
---|
297 | # warning 0 {Abandon\nChanges} {Continue\nEdit}\]} \ |
---|
298 | # {destroy $top}" |
---|
299 | grid [button $top.quit -text "Cancel Changes" \ |
---|
300 | -command "DeleteEditAtomConstraint $top"] -column 1 -row 4 |
---|
301 | |
---|
302 | set col 0 |
---|
303 | set row 1 |
---|
304 | foreach lbl {Phase Atom(s) Variable Multiplier} { |
---|
305 | # row separator |
---|
306 | grid [frame $cfr.spc$row -bd 8 -bg white] \ |
---|
307 | -columnspan 60 -column 0 -row [incr row] -sticky nsew |
---|
308 | grid rowconfig $cfr $row -minsize 2 -pad 2 |
---|
309 | if {$lbl == ""} { |
---|
310 | incr row |
---|
311 | } else { |
---|
312 | grid [label $cfr.t$row -text $lbl] -column $col -row [incr row] |
---|
313 | } |
---|
314 | } |
---|
315 | # row separator |
---|
316 | grid [frame $cfr.spc$row -bd 8 -bg white] \ |
---|
317 | -columnspan 60 -column 0 -row [incr row] -sticky nsew |
---|
318 | grid rowconfig $cfr $row -minsize 2 -pad 2 |
---|
319 | # make a list of unique phase #, variables & multipliers |
---|
320 | catch {unset atomlist} |
---|
321 | foreach item $clist { |
---|
322 | if {$item == -1} break |
---|
323 | set key [lindex $item 0]_[lindex $item 2]_[lindex $item 3] |
---|
324 | lappend atomlist($key) [lindex $item 1] |
---|
325 | } |
---|
326 | set ic 0 |
---|
327 | foreach key [lsort [array names atomlist]] { |
---|
328 | incr ic |
---|
329 | regexp {(.*)_(.*)_(.*)} $key dummy phase var mult |
---|
330 | } |
---|
331 | # delete traces on expcons(var1) |
---|
332 | foreach v [ trace vinfo expcons(var1)] { |
---|
333 | eval trace vdelete expcons(var1) $v |
---|
334 | } |
---|
335 | # fill the listbox & set the vars |
---|
336 | set ic 0 |
---|
337 | foreach key [lsort [array names atomlist]] { |
---|
338 | incr ic |
---|
339 | regexp {(.*)_(.*)_(.*)} $key dummy phase var mult |
---|
340 | # delete traces on expcons(phase$ic) |
---|
341 | foreach v [ trace vinfo expcons(phase$ic)] { |
---|
342 | eval trace vdelete expcons(phase$ic) $v |
---|
343 | } |
---|
344 | MakeAtomConstraintColumn $cfr $ic $col $num |
---|
345 | incr col 3 |
---|
346 | # set the various variables |
---|
347 | set expcons(phase$ic) $phase |
---|
348 | set expcons(mult$ic) $mult |
---|
349 | set expcons(var$ic) $var |
---|
350 | FillAtomsConstraintList $ic $atomlist($key) |
---|
351 | trace variable expcons(phase$ic) w "FillAtomsConstraintList $ic {}" |
---|
352 | } |
---|
353 | if {$num == "new"} {NewAtomConstraintColumn $top $cfr $num} |
---|
354 | trace variable expcons(var1) w SetVarConstraintMenu |
---|
355 | SetVarConstraintMenu |
---|
356 | # resize the canvas & scrollbar |
---|
357 | update idletasks |
---|
358 | set sizes [grid bbox $cfr] |
---|
359 | $top.canvas config -scrollregion $sizes |
---|
360 | set width [lindex $sizes 2] |
---|
361 | # use the scroll for BIG constraints |
---|
362 | if {$width > 600} { |
---|
363 | set width 600 |
---|
364 | grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4 |
---|
365 | } |
---|
366 | $top.canvas config -height [lindex $sizes 3] -width $width |
---|
367 | # force the window to stay on top |
---|
368 | putontop $top |
---|
369 | tkwait window $top |
---|
370 | afterputontop |
---|
371 | } |
---|
372 | |
---|
373 | # called when the "Cancel Changes" button is pressed |
---|
374 | proc DeleteEditAtomConstraint {top} { |
---|
375 | set ans [MyMessageBox -type "{Abandon Changes} {Continue Edit}" \ |
---|
376 | -parent [winfo toplevel $top] -default "abandon changes" \ |
---|
377 | -icon warning -message \ |
---|
378 | {Do you want to lose any changes made to this constraint?}] |
---|
379 | if {$ans == "abandon changes"} {destroy $top} |
---|
380 | } |
---|
381 | |
---|
382 | # called to make each column in the atom parameter dialog |
---|
383 | proc MakeAtomConstraintColumn {cfr ic col num} { |
---|
384 | global expmap expcons expgui |
---|
385 | set row 1 |
---|
386 | # make column separator |
---|
387 | incr col 2 |
---|
388 | grid [frame $cfr.sp$col -bd 8 -bg white] \ |
---|
389 | -rowspan 9 -column $col -row $row -sticky nsew |
---|
390 | grid columnconfig $cfr $col -minsize 2 -pad 2 |
---|
391 | |
---|
392 | eval tk_optionMenu $cfr.phase$ic expcons(phase$ic) $expmap(phaselist) |
---|
393 | grid $cfr.phase$ic -column [incr col] -row [incr row 2] -columnspan 2 |
---|
394 | # make the listbox |
---|
395 | set expcons(atomlistbox$ic) $cfr.lb$ic |
---|
396 | grid [listbox $cfr.lb$ic -height 10 -width 12 \ |
---|
397 | -font $expgui(coordfont) \ |
---|
398 | -exportselection 0 -selectmode extended \ |
---|
399 | -yscrollcommand " $cfr.sb$ic set"] \ |
---|
400 | -column $col -row [incr row 2] -sticky nse |
---|
401 | bind $expcons(atomlistbox$ic) <Button-3> \ |
---|
402 | "$expcons(atomlistbox$ic) selection set 0 end" |
---|
403 | grid [scrollbar $cfr.sb$ic -command "$cfr.lb$ic yview"] \ |
---|
404 | -column [expr 1+$col] -row $row -sticky wns |
---|
405 | if {$num == "new"} { |
---|
406 | set expcons(varmenu$ic) [tk_optionMenu $cfr.var$ic expcons(var$ic) \ |
---|
407 | FRAC X Y Z UISO U11 U22 U33 U12 U23 U13 MX MY MZ XYZU Uxx] |
---|
408 | $expcons(varmenu$ic) insert 14 separator |
---|
409 | } else { |
---|
410 | set expcons(varmenu$ic) [tk_optionMenu $cfr.var$ic expcons(var$ic) \ |
---|
411 | FRAC X Y Z UISO U11 U22 U33 U12 U23 U13 MX MY MZ] |
---|
412 | } |
---|
413 | grid $cfr.var$ic -column $col -row [incr row 2] -columnspan 2 |
---|
414 | grid [entry $cfr.c${col}$ic -width 10 \ |
---|
415 | -textvariable expcons(mult$ic)] \ |
---|
416 | -column $col -row [incr row 2] -columnspan 2 |
---|
417 | } |
---|
418 | |
---|
419 | # called when the "New column" button is pressed to add a new constraint |
---|
420 | proc NewAtomConstraintColumn {top cfr num} { |
---|
421 | global expcons expmap expgui |
---|
422 | set col -3 |
---|
423 | set row 1 |
---|
424 | for {set ic 1} {$ic < 500} {incr ic} { |
---|
425 | incr col 3 |
---|
426 | if [winfo exists $cfr.phase$ic] continue |
---|
427 | # delete traces on expcons(phase$ic) |
---|
428 | foreach v [ trace vinfo expcons(phase$ic)] { |
---|
429 | eval trace vdelete expcons(phase$ic) $v |
---|
430 | } |
---|
431 | MakeAtomConstraintColumn $cfr $ic $col $num |
---|
432 | # set the various variables to initial values |
---|
433 | set expcons(atmlst$ic) {} |
---|
434 | set expcons(phase$ic) {} |
---|
435 | set expcons(var$ic) {} |
---|
436 | set expcons(mult$ic) 1.0 |
---|
437 | trace variable expcons(phase$ic) w "FillAtomsConstraintList $ic {}" |
---|
438 | break |
---|
439 | } |
---|
440 | # set the allowed constraints |
---|
441 | SetVarConstraintMenu |
---|
442 | # resize the canvas & scrollbar |
---|
443 | update idletasks |
---|
444 | set sizes [grid bbox $cfr] |
---|
445 | $top.canvas config -scrollregion $sizes |
---|
446 | set width [lindex $sizes 2] |
---|
447 | # use the scroll for BIG constraints |
---|
448 | if {$width > 600} { |
---|
449 | set width 600 |
---|
450 | grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4 |
---|
451 | } |
---|
452 | $top.canvas config -height [lindex $sizes 3] -width $width |
---|
453 | } |
---|
454 | |
---|
455 | # called when the leftmost constraint variable is changed, so that |
---|
456 | # only allowed constraints are offered to the user. |
---|
457 | proc SetVarConstraintMenu {args} { |
---|
458 | global expcons |
---|
459 | set maxvar [$expcons(varmenu1) index end] |
---|
460 | set allowed {} |
---|
461 | switch $expcons(var1) { |
---|
462 | FRAC {set allowed FRAC} |
---|
463 | X - |
---|
464 | Y - |
---|
465 | Z {set allowed "X Y Z"} |
---|
466 | XYZU {set allowed XYZU} |
---|
467 | UISO {set allowed UISO} |
---|
468 | U11 - |
---|
469 | U22 - |
---|
470 | U33 - |
---|
471 | U12 - |
---|
472 | U23 - |
---|
473 | U13 {set allowed "U11 U22 U33 U12 U23 U13"} |
---|
474 | Uxx {set allowed Uxx} |
---|
475 | MX - |
---|
476 | MY - |
---|
477 | MZ {set allowed "MX MY MZ"} |
---|
478 | } |
---|
479 | for {set ic 2} {$ic < 500} {incr ic} { |
---|
480 | if [catch {set expcons(varmenu$ic)}] break |
---|
481 | if [winfo exists $expcons(varmenu$ic)] { |
---|
482 | # if only one variable choice is allowed select it, |
---|
483 | # if not and the current value is not allowed, blank it out |
---|
484 | if {[llength $allowed] == 1} { |
---|
485 | set expcons(var$ic) $allowed |
---|
486 | } elseif {[lsearch $allowed $expcons(var$ic)] == -1} { |
---|
487 | set expcons(var$ic) {} |
---|
488 | } |
---|
489 | set num 0 |
---|
490 | for {set num 0} {$num <= $maxvar} {incr num} { |
---|
491 | # ignore error on separators |
---|
492 | catch { |
---|
493 | set var [$expcons(varmenu$ic) entrycget $num -label] |
---|
494 | if {[lsearch $allowed $var] == -1} { |
---|
495 | $expcons(varmenu$ic) entryconfigure $num \ |
---|
496 | -state disabled |
---|
497 | } else { |
---|
498 | $expcons(varmenu$ic) entryconfigure $num \ |
---|
499 | -state normal |
---|
500 | } |
---|
501 | } |
---|
502 | } |
---|
503 | } else { |
---|
504 | break |
---|
505 | } |
---|
506 | } |
---|
507 | } |
---|
508 | |
---|
509 | # called to load the parameter values into the atom parameter dialog |
---|
510 | proc FillAtomsConstraintList {ic atomselectlist args} { |
---|
511 | global expcons expgui expmap |
---|
512 | # fill the atoms box |
---|
513 | set phase $expcons(phase$ic) |
---|
514 | $expcons(atomlistbox$ic) delete 0 end |
---|
515 | set atmlst {} |
---|
516 | if {$expgui(asorttype) == "type"} { |
---|
517 | # sort on atom type |
---|
518 | foreach atom $expmap(atomlist_$phase) { |
---|
519 | lappend atmlst "$atom [atominfo $phase $atom type]" |
---|
520 | } |
---|
521 | set atmlst [lsort -ascii -index 1 $atmlst] |
---|
522 | } elseif {$expgui(asorttype) == "number"} { |
---|
523 | # sort on atom number |
---|
524 | foreach atom $expmap(atomlist_$phase) { |
---|
525 | lappend atmlst "$atom $atom $phase" |
---|
526 | } |
---|
527 | set atmlst [lsort -integer -index 1 $atmlst] |
---|
528 | } elseif {$expgui(asorttype) == "x"} { |
---|
529 | # sort on x |
---|
530 | foreach atom $expmap(atomlist_$phase) { |
---|
531 | lappend atmlst "$atom [atominfo $phase $atom x]" |
---|
532 | } |
---|
533 | set atmlst [lsort -real -index 1 $atmlst] |
---|
534 | } elseif {$expgui(asorttype) == "y"} { |
---|
535 | # sort on y |
---|
536 | foreach atom $expmap(atomlist_$phase) { |
---|
537 | lappend atmlst "$atom [atominfo $phase $atom y]" |
---|
538 | } |
---|
539 | set atmlst [lsort -real -index 1 $atmlst] |
---|
540 | } elseif {$expgui(asorttype) == "z"} { |
---|
541 | # sort on z |
---|
542 | foreach atom $expmap(atomlist_$phase) { |
---|
543 | lappend atmlst "$atom [atominfo $phase $atom z]" |
---|
544 | } |
---|
545 | set atmlst [lsort -real -index 1 $atmlst] |
---|
546 | } else { |
---|
547 | error "Bad expgui(asorttype = $expgui(asorttype)" |
---|
548 | } |
---|
549 | # make a list of atoms in the box |
---|
550 | set expcons(atmlst$ic) {} |
---|
551 | foreach tuple $atmlst { |
---|
552 | set atom [lindex $tuple 0] |
---|
553 | lappend expcons(atmlst$ic) $atom |
---|
554 | $expcons(atomlistbox$ic) insert end [format "%-6s%3d %-6s" \ |
---|
555 | [atominfo $phase $atom label] \ |
---|
556 | $atom \ |
---|
557 | [atominfo $phase $atom type]] |
---|
558 | # select the atom if appropriate |
---|
559 | if {[lsearch $atomselectlist $atom] != -1} { |
---|
560 | $expcons(atomlistbox$ic) selection set end |
---|
561 | } |
---|
562 | } |
---|
563 | if {$atomselectlist == "ALL"} { |
---|
564 | $expcons(atomlistbox$ic) selection set 0 end |
---|
565 | } |
---|
566 | } |
---|
567 | |
---|
568 | # this is called to change an atomic consraint |
---|
569 | proc SaveAtomConstraint {num top} { |
---|
570 | global expcons expgui |
---|
571 | # special variables XYZU & Uxx should only occur with num == "new" |
---|
572 | # then add new constraints |
---|
573 | set varlist {{}} |
---|
574 | if {$expcons(var1) == "XYZU"} {set varlist "X Y Z U"} |
---|
575 | if {$expcons(var1) == "Uxx"} {set varlist "U11 U22 U33 U12 U23 U13"} |
---|
576 | foreach var $varlist { |
---|
577 | set clist {} |
---|
578 | for {set ic 1} {$ic < 500} {incr ic} { |
---|
579 | if [catch {set expcons(varmenu$ic)}] break |
---|
580 | if [winfo exists $expcons(varmenu$ic)] { |
---|
581 | set phase $expcons(phase$ic) |
---|
582 | if {$var == ""} { |
---|
583 | set v $expcons(var$ic) |
---|
584 | } else { |
---|
585 | set v $var |
---|
586 | } |
---|
587 | set mult $expcons(mult$ic) |
---|
588 | set atomlist {} |
---|
589 | foreach indx [$expcons(atomlistbox$ic) curselection] { |
---|
590 | lappend atomlist [lindex $expcons(atmlst$ic) $indx] |
---|
591 | } |
---|
592 | if {[llength $atomlist] == [llength $expcons(atmlst$ic)] \ |
---|
593 | && $v == "UISO"} { |
---|
594 | set atomlist ALL |
---|
595 | } else { |
---|
596 | set atomlist [lsort -integer $atomlist] |
---|
597 | } |
---|
598 | # ignore this column if phase is invalid or there are no atoms |
---|
599 | if {![catch {expr $phase}] && \ |
---|
600 | [llength $atomlist] > 0 && \ |
---|
601 | $v != ""} { |
---|
602 | # error if mult is invalid |
---|
603 | if [catch {expr $mult}] { |
---|
604 | tk_dialog .badmult "Bad Multiplier" \ |
---|
605 | "Multiplier value \"$mult\" in column $ic is invalid" \ |
---|
606 | error 0 Fix |
---|
607 | return |
---|
608 | } |
---|
609 | foreach atom $atomlist { |
---|
610 | lappend clist [list $phase $atom $v $mult] |
---|
611 | } |
---|
612 | } |
---|
613 | } |
---|
614 | } |
---|
615 | if {$num == "new"} { |
---|
616 | constrinfo atom add {} $clist |
---|
617 | } elseif {$clist != ""} { |
---|
618 | constrinfo atom set $num $clist |
---|
619 | } else { |
---|
620 | constrinfo atom delete $num |
---|
621 | } |
---|
622 | incr expgui(changed) |
---|
623 | } |
---|
624 | destroy $top |
---|
625 | DisplayAtomConstraints |
---|
626 | } |
---|