Bsoft  2.1.0
Bernard's software package
bshow_diffraction.tcl
Go to the documentation of this file.
1 ##
2 # @file bshow_diffraction.tcl
3 #
4 # @brief Procedures to analyze diffraction patterns
5 #
6 # @author Bernard Heymann
7 # @date Created: 20050203
8 # @date Modified: 20050204
9 
10 ## @brief Dialog box to analyze diffraction patterns
11 #
12 
13 proc Diffraction { } {
14  global helv12 theimg
15  global orix oriy width height
16  global diffplot
17 
18  if ![Bimage exists $theimg] {
19  tk_dialog .dialog "No image in memory!" \
20  {Please read in an appropriate image first.} \
21  info 0 {OK}
22  return
23  }
24 
25  if { [info exists diffplot] } { unset diffplot }
26  if ![winfo exists .wdif] {
27  toplevel .wdif
28  set width 500
29  set height 350
30  set orix 100
31  set oriy 400
32  set xmin 0
33  set xmax [expr [Bimage get $theimg width]/2]
34  set ymin 0
35  set ymax 10
36  set xscale 1.0
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]
40 # }
41 
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
54 
55  set g .wdif.plot
56  canvas $g -relief raised -width [expr $orix + $width + 50] \
57  -height [expr $oriy + 100]
58  pack $g -side top -fill x
59 
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
69 
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
80 
81  updateLimits .wdif $xmin $xmax $ymin $ymax
82  plotGraph .wdif $g diffplot "line" "Frequency" "Intensity"
83  } else {
84  wm deiconify .wdif
85  raise .wdif
86  }
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 }
91  bind $g <Button-1> {
92  set x1 [.wdif.plot canvasx %x]
93  set y1 [.wdif.plot canvasy %y]
94  }
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 }
101  destroy .wdif
102  }
103 }
104