2 # @file bshow_diffraction.tcl
4 # @brief Procedures to analyze diffraction patterns
6 # @author Bernard Heymann
7 # @date Created: 20050203
8 # @date Modified: 20050204
10 ## @brief Dialog box to analyze diffraction patterns
13 proc Diffraction { } {
15 global orix oriy width height
18 if ![Bimage exists $theimg] {
19 tk_dialog .dialog "No image in memory!" \
20 {Please read in an appropriate image first.} \
25 if { [info exists diffplot] } { unset diffplot }
26 if ![winfo exists .wdif] {
33 set xmax [expr [Bimage get $theimg width]/2]
37 # for { set i 0 } { $i < $xmax } { incr i } {
38 # set diffplot(x,$i) [expr $i*$xscale + $xmin]
39 # set diffplot(y,$i) [lindex $raddiff $i]
42 menu .wdif.menuBar -tearoff 0
43 .wdif.menuBar add cascade -menu .wdif.menuBar.dif -label "Diffraction" -underline 0
44 menu .wdif.menuBar.dif -tearoff 0
45 .wdif configure -menu .wdif.menuBar
46 .wdif.menuBar.dif add command -label "Help" \
47 -command { showHelp bshow_diffraction.hlp } -underline 0
48 .whdif.menuBar.dif add command -label "Reset plot" -underline 0 \
49 -command { drawGraph .wdif diffplot "line" "Frequency" "Intensity" } -accelerator "Ctrl-r"
50 .wdif.menuBar.dif add command -label "Write data" \
51 -command { writePlotData } -underline 0
52 .wdif.menuBar.dif add command -label "Close" \
53 -command "destroy .wdif" -underline 0
56 canvas $g -relief raised -width [expr $orix + $width + 50] \
57 -height [expr $oriy + 100]
58 pack $g -side top -fill x
60 frame .wdif.point -bg green
61 label .wdif.point.xtag -font $helv12 -text "x" -bg green
62 label .wdif.point.x -text "0" -relief sunken -bd 1 -width 8 \
63 -font $helv12 -anchor w
64 label .wdif.point.ytag -font $helv12 -text "y" -bg green
65 label .wdif.point.y -text "0" -relief sunken -bd 1 -width 8 \
66 -font $helv12 -anchor w
67 pack .wdif.point.xtag .wdif.point.x .wdif.point.ytag .wdif.point.y \
68 -side left -pady 10 -padx 10
70 frame .wdif.lim -bg cyan
71 label .wdif.lim.x_tag -font $helv12 -text "X limits" -bg cyan
72 entry .wdif.lim.x_min -width 6 -validate key -vcmd { string is double %P }
73 entry .wdif.lim.x_max -width 6 -validate key -vcmd { string is double %P }
74 label .wdif.lim.y_tag -font $helv12 -text "Y limits" -bg cyan
75 entry .wdif.lim.y_min -width 6 -validate key -vcmd { string is double %P }
76 entry .wdif.lim.y_max -width 6 -validate key -vcmd { string is double %P }
77 pack .wdif.lim.x_tag .wdif.lim.x_min .wdif.lim.x_max .wdif.lim.y_tag \
78 .wdif.lim.y_min .wdif.lim.y_max -side left -pady 10 -padx 10
79 pack .wdif.point .wdif.lim -side left
81 updateLimits .wdif $xmin $xmax $ymin $ymax
82 plotGraph .wdif $g diffplot "line" "Frequency" "Intensity"
87 wm title .wdif "Diffraction"
88 wm iconname .wdif "Diffraction"
89 $g bind point <Any-Enter> { showPoint .wdif diffplot %x %y }
90 $g bind point <Any-Leave> { showPoint .wdif diffplot %x %y }
92 set x1 [.wdif.plot canvasx %x]
93 set y1 [.wdif.plot canvasy %y]
95 bind $g <B1-Motion> { drawRectangle .wdif.plot $x1 $y1 [.wdif.plot canvasx %x] [.wdif.plot canvasy %y] }
96 bind $g <B1-ButtonRelease> { drawSubGraph .wdif .wdif.plot diffplot $x1 $y1 \
97 [.wdif.plot canvasx %x] [.wdif.plot canvasy %y] "bar" "Frequency" "Intensity" }
98 bind .wdif <Return> { plotGraph .wdif .wdif.plot diffplot "bar" "Frequency" "Intensity" }
99 bind .wdif <Control-w> {
100 if { [info exists diffplot] } { unset diffplot }