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