4 # @brief Miscellaneous procedures for Bshow and other scripts.
6 # @author Bernard Heymann
7 # @date Created: 20010516
8 # @date Modified: 20200625
28 set cursorName "crosshair"
33 set box_color "yellow"
34 set box_select_color "green"
36 set bad_select_color "purple"
37 set filament_color "yellow"
38 set filament_first_color "blue"
39 set filament_select_color "green"
40 set spot_color "yellow"
41 set spot_select_color "green"
43 set ll_select_color "green"
44 set marker_color "yellow"
45 set marker2_color "red"
46 set marker_select_color "green"
47 set error_color "orange"
48 set error_select_color "blue"
50 proc getControlWindow { theimg } {
52 if [string equal "theimg" $theimg] {
58 proc getImageCanvas { theimg } {
60 if { [string length $theimg] < 1 } {
61 puts "Error: image not selected!"
65 if [string equal "theimg" $theimg] {
72 ## @brief Creates the right-side controls for image display
74 # @param w Control window.
76 proc setupControls { w } {
80 label $w.img.tag -text "Image type"
81 tk_optionMenu $w.img.menu imgtype "" "mg" "frame" "part" "fil" "rec" "ft" "ps" "mod"
82 $w.img.menu configure -width 10
83 # trace add variable imgbigtype write imageType
86 checkbutton $w.mode.avg -text "Averaging mode" -variable mode \
88 button $w.mode.invert -text "Invert" -command { invertContrast }
91 label $w.pixel.xtag -font $helv12 -text "x"
92 label $w.pixel.x -text "0" -relief sunken -bd 1 -width 6 \
93 -font $helv12 -anchor w
94 label $w.pixel.ytag -font $helv12 -text "y"
95 label $w.pixel.y -text "0" -relief sunken -bd 1 -width 6 \
96 -font $helv12 -anchor w
97 label $w.pixel.vtag -font $helv12 -text "value"
98 label $w.pixel.value -text "0" -relief sunken -bd 1 -width 20 \
99 -font $helv12 -anchor w
101 set pixel_size "1 1 1"
102 setupVectorEntry $w.pixel_size "Pixel size" double $pixel_size "Image pixel size in Å/pixel"
103 bind $w.pixel_size.x <Return> { setPixelsize $theimg }
104 bind $w.pixel_size.y <Return> { setPixelsize $theimg }
105 bind $w.pixel_size.z <Return> { setPixelsize $theimg }
108 label $w.origin.tag -font $helv12 -text "Origin"
109 label $w.origin.x -text "0" -relief sunken -bd 1 -width 6 \
110 -font $helv12 -anchor w
111 label $w.origin.y -text "0" -relief sunken -bd 1 -width 6 \
112 -font $helv12 -anchor w
113 label $w.origin.z -text "0" -relief sunken -bd 1 -width 6 \
114 -font $helv12 -anchor w
115 checkbutton $w.origin.show -text "Show" -variable show_origin -command { drawOrigin }
116 $w.origin.show toggle
119 label $w.distance.tag -font $helv12 -text "Distance" -width 10
120 label $w.distance.value -text "" -relief sunken -bd 1 -width 16 \
121 -font $helv12 -anchor w
122 label $w.distance.unit -text "Å" -width 3 -font $helv12 -anchor w
126 pack $w.img $w.mode -side top -pady 2
127 pack $w.img.tag $w.img.menu -side left -pady 2 -anchor w
128 pack $w.mode.avg $w.mode.invert -side left -pady 2 -anchor w
130 pack $w.pixel.xtag $w.pixel.x $w.pixel.ytag $w.pixel.y $w.pixel.vtag \
131 $w.pixel.value -side left -pady 10 -padx 2
133 pack $w.origin.tag $w.origin.x $w.origin.y $w.origin.z $w.origin.show -side left -pady 10 -padx 2
134 pack $w.distance.tag $w.distance.value $w.distance.unit -side left -pady 10
136 pack $w.pixel $w.pixel_size $w.origin $w.distance $w.image $w.slice $w.scale \
137 $w.min $w.max $w.step $w.as $w.ani -side top -fill x -pady 2
140 ## @brief Flips the display y axis.
142 # @param y Canvas y value.
146 set h [Bimage get $theimg height]
147 return [expr $h - $y - 1]
150 ## @brief Returns the image coordinates given canvas coordinates.
153 # @param y Canvas coordinates.
155 proc imageCoordinatesFromCanvas { x y } {
158 set c [getImageCanvas $theimg]
159 set wc [getControlWindow $theimg]
160 set scale [$wc.scale.scale get]
161 set z [$wc.slice.scale get]
162 set px [expr floor( [$c canvasx $x] / $scale ) ]
163 set py [expr floor( [$c canvasy $y] / $scale ) ]
168 ## @brief Selects a color.
170 # @param w parent window
172 proc selectColor { w } {
173 global selected_color
174 set initialColor $selected_color
175 set color [tk_chooseColor -title "Choose a color" -parent $w \
176 -initialcolor $selected_color]
177 if { [string compare $color ""] } {
178 set selected_color $color
179 $w configure -background $color
182 return $selected_color
185 if {[tk windowingsystem] eq "aqua"} {
186 proc ::tk::mac::ShowPreferences { } { setPreferences }
189 proc setPreferences { } {
190 global helv12 rem_scale avg_check kernel
192 global box_color box_select_color bad_color bad_select_color
193 global filament_color filament_first_color filament_select_color
194 global ll_color ll_select_color
195 global spot_color spot_select_color
196 global marker_color marker_select_color error_color error_select_color
200 if ![winfo exists .wprf] {
203 checkbutton $w.rem_scale -text "Remember scale" -variable rem_scale
205 setupCheckEntry $w.avg "Kernel" list kernel avg_check "The size of the filter kernel"
207 labelframe $w.col -text "Colors"
208 label $w.col.lbl -text "Draw Select First" -anchor e
211 label $w.col.origins.label -text "Origins" -width 15 -anchor e
212 canvas $w.col.origins.well -width 30 -height 30 -relief sunken \
213 -borderwidth 2 -background $ori_color
216 label $w.col.box.label -text "Boxes" -width 15 -anchor e
217 canvas $w.col.box.well -width 30 -height 30 -relief sunken \
218 -borderwidth 2 -background $box_color
219 canvas $w.col.box.well2 -width 30 -height 30 -relief sunken \
220 -borderwidth 2 -background $box_select_color
223 label $w.col.bad.label -text "Bad areas" -width 15 -anchor e
224 canvas $w.col.bad.well -width 30 -height 30 -relief sunken \
225 -borderwidth 2 -background $bad_color
226 canvas $w.col.bad.well2 -width 30 -height 30 -relief sunken \
227 -borderwidth 2 -background $bad_select_color
229 frame $w.col.filament
230 label $w.col.filament.label -text "Filaments" -width 15 -anchor e
231 canvas $w.col.filament.well -width 30 -height 30 -relief sunken \
232 -borderwidth 2 -background $filament_color
233 canvas $w.col.filament.well2 -width 30 -height 30 -relief sunken \
234 -borderwidth 2 -background $filament_select_color
235 canvas $w.col.filament.well3 -width 30 -height 30 -relief sunken \
236 -borderwidth 2 -background $filament_first_color
239 label $w.col.spot.label -text "Diffraction spots" -width 15 -anchor e
240 canvas $w.col.spot.well -width 30 -height 30 -relief sunken \
241 -borderwidth 2 -background $spot_color
242 canvas $w.col.spot.well2 -width 30 -height 30 -relief sunken \
243 -borderwidth 2 -background $spot_select_color
246 label $w.col.ll.label -text "Layer lines" -width 15 -anchor e
247 canvas $w.col.ll.well -width 30 -height 30 -relief sunken \
248 -borderwidth 2 -background $ll_color
249 canvas $w.col.ll.well2 -width 30 -height 30 -relief sunken \
250 -borderwidth 2 -background $ll_select_color
253 label $w.col.marker.label -text "Markers" -width 15 -anchor e
254 canvas $w.col.marker.well -width 30 -height 30 -relief sunken \
255 -borderwidth 2 -background $marker_color
256 canvas $w.col.marker.well2 -width 30 -height 30 -relief sunken \
257 -borderwidth 2 -background $marker_select_color
260 label $w.col.error.label -text "Marker errors" -width 15 -anchor e
261 canvas $w.col.error.well -width 30 -height 30 -relief sunken \
262 -borderwidth 2 -background $error_color
263 canvas $w.col.error.well2 -width 30 -height 30 -relief sunken \
264 -borderwidth 2 -background $error_select_color
266 button $w.update -text "Update" -relief raised -command { Update 0 }
268 pack $w.col.origins.label $w.col.origins.well -side left
269 pack $w.col.box.label $w.col.box.well $w.col.box.well2 -side left
270 pack $w.col.bad.label $w.col.bad.well $w.col.bad.well2 -side left
271 pack $w.col.filament.label $w.col.filament.well $w.col.filament.well2 \
272 $w.col.filament.well3 -side left
273 pack $w.col.spot.label $w.col.spot.well $w.col.spot.well2 -side left
274 pack $w.col.ll.label $w.col.ll.well $w.col.ll.well2 -side left
275 pack $w.col.marker.label $w.col.marker.well $w.col.marker.well2 -side left
276 pack $w.col.error.label $w.col.error.well $w.col.error.well2 -side left
277 pack $w.col.lbl $w.col.origins $w.col.box $w.col.bad $w.col.filament \
278 $w.col.spot $w.col.ll $w.col.marker $w.col.error -side top -fill x -padx 5
279 pack $w.rem_scale $w.avg $w.col $w.update -side top -pady 5 -padx 5
284 wm title $w "Preferences"
285 wm iconname $w "Preferences"
286 bind $w.col.origins.well <1> { set ori_color [selectColor .wprf.col.origins.well] }
287 bind $w.col.box.well <1> { set box_color [selectColor .wprf.col.box.well] }
288 bind $w.col.box.well2 <1> { set box_select_color [selectColor .wprf.col.box.well2] }
289 bind $w.col.bad.well <1> { set bad_color [selectColor .wprf.col.bad.well] }
290 bind $w.col.bad.well2 <1> { set bad_select_color [selectColor .wprf.col.bad.well2] }
291 bind $w.col.filament.well <1> { set filament_color [selectColor .wprf.col.filament.well] }
292 bind $w.col.filament.well2 <1> { set filament_select_color \
293 [selectColor .wprf.col.filament.well2] }
294 bind $w.col.filament.well3 <1> { set filament_first_color \
295 [selectColor .wprf.col.filament.well3] }
296 bind $w.col.spot.well <1> { set spot_color [selectColor .wprf.col.spot.well] }
297 bind $w.col.spot.well2 <1> { set spot_select_color [selectColor .wprf.col.spot.well2] }
298 bind $w.col.ll.well <1> { set ll_color [selectColor .wprf.col.ll.well] }
299 bind $w.col.ll.well2 <1> { set ll_select_color [selectColor .wprf.col.ll.well2] }
300 bind $w.col.marker.well <1> { set marker_color [selectColor .wprf.col.marker.well] }
301 bind $w.col.marker.well2 <1> { set marker_select_color [selectColor .wprf.col.marker.well2] }
302 bind $w.col.error.well <1> { set error_color [selectColor .wprf.col.error.well] }
303 bind $w.col.error.well2 <1> { set error_select_color [selectColor .wprf.col.error.well2] }
306 ## @brief Saves the settings file .bshow
309 proc writeSettingsFile { } {
310 global theimg project_root
311 global window_width window_height window_scale
312 global autoscale std_scale imageonly
313 global rem_scale img_filter
314 global lg avgtileps avgframeps tiled
315 global tilex tiley tilez defocus
316 global tilt_axis tilt_angle tilt_offset show_tilt_axis
318 global volt Cs amp_fac
319 global focal_length obj_apert slit
320 global ctf_win_x ctf_win_y
321 global ctf_scale_x ctf_scale_y
322 global ctf_hires ctf_lores
323 global cont_update show_rings base_type env_type sub_base
324 global box_size bad_radius
325 global filament_width filament_node_radius boxing_interval helix_rise helix_angle
327 global shift_limit thickness
328 global spot_radius spot_resolution
329 global ll_length ll_width ll_resolution
330 global comp_radius link_radius selected_color line_width
331 global width height orix oriy color
332 global magnification magsize
334 global box_color box_select_color bad_color bad_select_color
335 global filament_color filament_first_color filament_select_color
336 global ll_color ll_select_color
337 global spot_color spot_select_color
338 global marker_color marker_select_color error_color error_select_color
340 set c [getImageCanvas $theimg]
341 set window_width [expr [winfo width $c] - 10]
342 set window_height [expr [winfo height $c] - 10]
343 # puts "Settings: $window_width $window_height $window_scale $autoscale"
345 if { [catch {open .bshow w} fset] } { return }
347 puts $fset "# .bshow: Bshow parameter file"
348 puts $fset "# ----------------------------"
349 puts $fset "# [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}]"
350 puts $fset "# This must be valid Tcl/Tk code."
352 puts $fset "# File access:"
353 puts $fset "set img_filter $img_filter"
355 puts $fset "# Image window parameters:"
356 puts $fset "set window_width $window_width"
357 puts $fset "set window_height $window_height"
358 puts $fset "set window_scale $window_scale"
359 puts $fset "set rem_scale $rem_scale"
360 puts $fset "set autoscale $autoscale"
361 puts $fset "set std_scale $std_scale"
362 puts $fset "set imageonly $imageonly"
363 puts $fset "set ori_color $ori_color"
365 puts $fset "# Micrograph parameters:"
366 puts $fset "set project_root $project_root"
367 puts $fset "set tilt_axis $tilt_axis"
368 puts $fset "set tilt_angle $tilt_angle"
369 puts $fset "set tilt_offset $tilt_offset"
370 puts $fset "set show_tilt_axis $show_tilt_axis"
371 puts $fset "set direct_beam $direct_beam"
373 puts $fset "# Powerspectrum parameters:"
374 puts $fset "set lg $lg"
375 puts $fset "set avgtileps $avgtileps"
376 puts $fset "set avgframeps $avgframeps"
377 puts $fset "set tiled $tiled"
378 puts $fset "set tilex $tilex"
379 puts $fset "set tiley $tiley"
380 puts $fset "set tilez $tilez"
381 puts $fset "set defocus $defocus"
383 puts $fset "# CTF parameters:"
384 puts $fset "set volt $volt"
385 puts $fset "set Cs $Cs"
386 puts $fset "set amp_fac $amp_fac"
387 puts $fset "set focal_length $focal_length"
388 puts $fset "set obj_apert $obj_apert"
389 puts $fset "set slit $slit"
390 puts $fset "set ctf_hires $ctf_hires"
391 puts $fset "set ctf_lores $ctf_lores"
392 puts $fset "set ctf_win_x $ctf_win_x"
393 puts $fset "set ctf_win_y $ctf_win_y"
394 puts $fset "set ctf_scale_x $ctf_scale_x"
395 puts $fset "set ctf_scale_y $ctf_scale_y"
396 puts $fset "set cont_update $cont_update"
397 puts $fset "set show_rings $show_rings"
398 puts $fset "set base_type $base_type"
399 puts $fset "set env_type $env_type"
400 puts $fset "set sub_base $sub_base"
402 puts $fset "# Boxing parameters:"
403 puts $fset "set box_size \"$box_size\""
404 puts $fset "set bad_radius $bad_radius"
405 puts $fset "set box_color $box_color"
406 puts $fset "set box_select_color $box_select_color"
407 puts $fset "set bad_color $bad_color"
408 puts $fset "set bad_select_color $bad_select_color"
410 puts $fset "# Filament parameters:"
411 puts $fset "set filament_width $filament_width"
412 puts $fset "set filament_node_radius $filament_node_radius"
413 puts $fset "set boxing_interval $boxing_interval"
414 puts $fset "set helix_rise $helix_rise"
415 puts $fset "set helix_angle $helix_angle"
416 puts $fset "set filament_color $filament_color"
417 puts $fset "set filament_first_color $filament_first_color"
418 puts $fset "set filament_select_color $filament_select_color"
420 puts $fset "# Tomography parameters:"
421 puts $fset "set marker_radius $marker_radius"
422 puts $fset "set marker_color $marker_color"
423 puts $fset "set marker_select_color $marker_select_color"
424 puts $fset "set error_color $error_color"
425 puts $fset "set error_select_color $error_select_color"
426 puts $fset "set shift_limit $shift_limit"
427 puts $fset "set thickness $thickness"
429 puts $fset "# Crystallography parameters:"
430 puts $fset "set spot_radius $spot_radius"
431 puts $fset "set spot_resolution $spot_resolution"
432 puts $fset "set spot_color $spot_color"
433 puts $fset "set spot_select_color $spot_select_color"
435 puts $fset "# Helix parameters:"
436 puts $fset "set ll_length $ll_length"
437 puts $fset "set ll_width $ll_width"
438 puts $fset "set ll_resolution $ll_resolution"
439 puts $fset "set ll_color $ll_color"
440 puts $fset "set ll_select_color $ll_select_color"
442 puts $fset "# Model parameters:"
443 puts $fset "set comp_radius $comp_radius"
444 puts $fset "set link_radius $link_radius"
445 puts $fset "set selected_color $selected_color"
446 puts $fset "set line_width $line_width"
448 puts $fset "# Graph parameters:"
449 puts $fset "set width $width"
450 puts $fset "set height $height"
451 puts $fset "set orix $orix"
452 puts $fset "set oriy $oriy"
453 puts $fset "set color { blue green red yellow black SkyBlue2 }"
455 puts $fset "# Magnification parameters:"
456 puts $fset "set magnification $magnification"
457 puts $fset "set magsize $magsize"
462 ## @brief getFileName
463 # Edits a file name entry
465 # @param w the entry window
467 proc getFileName { w } {
469 set name [tk_getOpenFile -initialdir $imgdir]
476 proc checkType {type val} {
477 if { [expr {[string match {[.-+]} $val] || [string is $type $val]}] } {
484 proc setupEntry { w name type var desc } {
486 label $w.l -text $name -width 20 -anchor w
487 entry $w.e -validate key -invcmd bell -width 10 \
488 -vcmd [list checkType $type %P]
490 button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
491 pack $w.l $w.e $w.b -side left -padx 1m
494 proc setupResolutionEntry { w } {
496 labelframe $w.res -text "Resolution limits"
497 setupEntry $w.res.hi "High" double $hires "High resolution limit in angstrom"
498 setupEntry $w.res.lo "Low" double $lores "Low resolution limit in angstrom"
499 pack $w.res.hi $w.res.lo -side top -fill x
502 proc setupCheckEntry { w name type var cvar desc } {
504 checkbutton $w.c -text $name -variable $cvar
505 entry $w.e -validate key -invcmd bell -width 10 \
506 -vcmd [list checkType $type %P] -textvariable $var
508 button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
509 pack $w.c $w.e $w.b -side left -padx 1m
512 proc setupScrollEntry { w name var desc } {
514 label $w.l -text $name -anchor w
515 entry $w.e -validate key -invcmd bell -width 40 \
516 -xscrollcommand "$w.s set"
518 scrollbar $w.s -relief sunken -orient horiz -command "$w.e xview"
519 button $w.b -text "Browse ..." -command "getFileName $w" -width 10
520 button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
521 pack $w.s $w.e -side bottom -fill x -expand 1 -padx 1m
522 pack $w.l $w.b $w.i -side left -fill x -padx 1m
525 proc setupVectorEntry { w name type var desc } {
527 label $w.l -text $name -anchor w
528 entry $w.x -width 6 -validate key -vcmd [list checkType $type %P]
529 entry $w.y -width 6 -validate key -vcmd [list checkType $type %P]
530 entry $w.z -width 6 -validate key -vcmd [list checkType $type %P]
531 $w.x insert 0 [lindex $var 0]
532 $w.y insert 0 [lindex $var 1]
533 $w.z insert 0 [lindex $var 2]
534 button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
535 pack $w.l $w.x $w.y $w.z $w.b -side left -padx 1m
538 proc setupCheckSizeEntry { w name type var cvar desc } {
540 checkbutton $w.c -text $name -variable $cvar -command [list updateCheckSizeEntry $w $var]
541 entry $w.x -width 6 -validate key -vcmd [list checkType $type %P]
542 entry $w.y -width 6 -validate key -vcmd [list checkType $type %P]
543 entry $w.z -width 6 -validate key -vcmd [list checkType $type %P]
544 $w.x insert 0 [lindex $var 0]
545 $w.y insert 0 [lindex $var 1]
546 $w.z insert 0 [lindex $var 2]
547 button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
548 pack $w.c $w.x $w.y $w.z $w.b -side left -padx 1m
551 proc updateCheckSizeEntry { w var } {
555 set kernel [list $ax $ay $az]
559 proc setupFileEntry { w name file desc } {
561 label $w.l -text $name -anchor w
564 button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
565 pack $w.l $w.e $w.i -side left -pady 5
568 proc setupNewFileEntry { w name newfile desc } {
570 label $w.l -text $name -anchor w
572 $w.e insert 0 $newfile
573 button $w.b -text "Load" \
574 -relief raised -command " loadParam \[$w.e get] "
575 button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
576 pack $w.l $w.e $w.b $w.i -side left -pady 5
579 proc setupPostscriptEntry { w name psfile desc } {
581 label $w.l -text $name -anchor w
583 $w.e insert 0 $psfile
584 button $w.b -text "Open" \
585 -relief raised -command "openPostscript \[$w.e get] "
586 button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
587 pack $w.l $w.e $w.b $w.i -side left -pady 5
590 proc openPostscript { file } {
592 if { $tcl_platform(os) == "Darwin" } {
594 } elseif { $tcl_platform(os) == "Linux" } {
599 ## @brief Opens a text documentation file
601 # @param helpfile File name.
603 proc showHelp { helpfile } {
605 if ![winfo exists .help] {
608 pack .help.frame -expand yes -fill both -padx 1 -pady 1
609 text .help.text -height 40 -wrap word -background white\
610 -xscrollcommand ".help.xscroll set" \
611 -yscrollcommand ".help.yscroll set" \
612 -setgrid 1 -highlightthickness 0 -pady 2 -padx 3
613 scrollbar .help.xscroll -command ".help.text xview" \
614 -highlightthickness 0 -orient horizontal
615 scrollbar .help.yscroll -command ".help.text yview" \
616 -highlightthickness 0 -orient vertical
618 grid .help.text -in .help.frame -padx 1 -pady 1 \
619 -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
620 grid .help.yscroll -in .help.frame -padx 1 -pady 1 \
621 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
622 grid rowconfig .help.frame 0 -weight 1 -minsize 0
623 grid columnconfig .help.frame 0 -weight 1 -minsize 0
628 wm title .help $helpfile
629 wm iconname .help $helpfile
630 readTextFile .help "$bshow_script/$helpfile"
633 ## @brief Opens a URL in a web browser.
637 proc showURL { url } {
640 switch $tcl_platform(os) {
651 foreach pot_exe {firefox mozilla netscape iexplorer opera lynx
652 w3m links epiphany galeon konqueror mosaic amaya
654 set executable [auto_execok $pot_exe]
657 if [string length $executable] {
658 exec $executable $url &
664 exec [auto_execok start] $url
668 tk_messageBox -icon error -message "Error: '$err' displaying '$url'"
672 proc toolTip { w t } {
673 # bind $w <Any-Enter> "after 1000 showTip %X %Y $t; after 3000 hideTip"
674 # bind $w <Any-Leave> "hideTip"
675 # bind $w <ButtonPress-3> "set btn3 1; showTip %X %Y $t"
676 # bind $w <ButtonRelease-3> "set btn3 0; hideTip"
677 bind $w <ButtonPress-3> "showTip %X %Y $t"
678 bind $w <ButtonRelease-3> "hideTip"
681 proc showTip { x y args } {
682 wm geometry .tooltip +$x+$y
683 .tooltip.message configure -text $args
689 wm geometry .tooltip +0+0
690 .tooltip.message configure -text ""
694 wm geometry .tooltip 1x1+0+0
695 wm overrideredirect .tooltip 1
696 label .tooltip.message -bd 1 -fg black -bg lightyellow -font fixed -text ""
697 pack .tooltip.message
700 ## @brief Updates the pixel size from parameter information
703 proc updatePixelsize { } {
704 global filename project_item theimg imgtype
708 # puts "in updatePixelsize: Item: $project_item"
709 if [regexp "Field" $project_item] {
710 set n [Bmg get $project_item number_of_mg]
711 if { $imgtype == "mg" || $imgtype == "frame" } {
712 set ps [Bmg get $project_item pixel_size]
714 set ps [Bimage get $theimg pixel_size]
716 } elseif [regexp "Micrograph" $project_item] {
717 if { $imgtype == "mg" || $imgtype == "frame" } {
718 set ps [Bmg get $project_item pixel_size]
719 } elseif { $imgtype == "part" } {
720 # set n [Bmg get $project_item number_of_part]
721 set ps [Bmg get $project_item part_pixel_size]
723 set ps [Bimage get $theimg pixel_size]
725 } elseif [regexp "Reconstruction" $project_item] {
726 if { $imgtype == "rec" } {
727 set ps [Bmg get $project_item pixel_size]
728 } elseif { $imgtype == "part" } {
729 # set n [Bmg get $project_item number_of_part]
730 set ps [Bmg get $project_item part_pixel_size $filename]
732 set ps [Bimage get $theimg pixel_size]
734 } elseif [regexp "Class" $project_item] {
735 if { $imgtype == "part" } {
736 set ps [Bmg get $project_item part_pixel_size $filename]
739 # puts "updatePixelsize: $ps"
741 foreach {x y z} $ps {
742 Bimage set $theimg pixel_size $i $x $y $z
749 ## @brief Updates the current pixel size entry displayed
752 proc updatePixelSizeEntry { } {
754 set wc [getControlWindow $theimg]
755 set img_num [$wc.image.scale get]
756 set ps [Bimage get $theimg pixel_size $img_num]
757 # puts "updatePixelSizeEntry: $ps"
759 $wc.pixel_size.x delete 0 end
760 $wc.pixel_size.x insert 0 [lindex $ps 0]
761 $wc.pixel_size.y delete 0 end
762 $wc.pixel_size.y insert 0 [lindex $ps 1]
763 $wc.pixel_size.z delete 0 end
764 $wc.pixel_size.z insert 0 [lindex $ps 2]
768 ## @brief Returns the current pixel size entry
771 proc getPixelSizeEntry { } {
772 global project_item theimg
773 set wc [getControlWindow $theimg]
774 set psx [$wc.pixel_size.x get]
775 set psy [$wc.pixel_size.y get]
776 set psz [$wc.pixel_size.z get]
777 set ps "$psx $psy $psz"
778 # puts "getPixelSizeEntry: $ps"
782 ## @brief Sets the pixel size of the image and micrograph
784 # theimg Image identifier.
786 proc setPixelsize { theimg } {
788 set wc [getControlWindow $theimg]
789 set img_num [$wc.image.scale get]
790 set ps [getPixelSizeEntry]
791 # puts "setPixelsize: $ps"
792 Bimage set $theimg pixel_size $img_num [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
794 Bmg set $project_item pixel_size [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
795 if [winfo exists .wctf] { updateCTF }
797 set ps [Bimage get $theimg pixel_size $img_num]
798 puts "setPixelsize: $ps"
801 ## @brief Sets the pixel size of the image and micrograph
803 # theimg Image identifier.
805 proc setAllPixelsizes { theimg } {
807 set wc [getControlWindow $theimg]
808 set ps [getPixelSizeEntry]
809 # puts "setPixelsize: $ps"
810 Bimage set $theimg pixel_size -1 [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
812 Bmg set all pixel_size [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
813 if [winfo exists .wctf] { updateCTF }
815 set ps [Bimage get $theimg pixel_size $img_num]
816 puts "setPixelsize: $ps"
819 ## @brief Updates the image origins from parameters
822 proc updateOrigins { } {
823 global theimg filename
824 global imgtype project_item
827 # puts "in updateOrigins: Item: $project_item"
828 if [regexp "Field" $project_item] {
829 set n [Bmg get $project_item number_of_mg]
830 if { $imgtype == "mg" || $imgtype == "frame" } {
831 set origin [Bmg get $project_item origin]
833 set origin [Bimage get $theimg origin]
835 } elseif [regexp "Micrograph" $project_item] {
836 if { $imgtype == "mg" || $imgtype == "frame" } {
837 set origin [Bmg get $project_item origin]
838 } elseif { $imgtype == "part" } {
839 # set n [Bmg get $project_item number_of_part]
840 set origin [Bmg get $project_item part_origin $filename]
842 set origin [Bimage get $theimg origin]
844 } elseif [regexp "Reconstruction" $project_item] {
845 if { $imgtype == "rec" } {
846 set origin [Bmg get $project_item origin]
847 } elseif { $imgtype == "part" } {
848 # set n [Bmg get $project_item number_of_part]
849 set origin [Bmg get $project_item part_origin $filename]
851 set origin [Bimage get $theimg origin]
853 } elseif [regexp "Class" $project_item] {
854 if { $imgtype == "part" } {
855 set origin [Bmg get $project_item part_origin $filename]
858 # puts "Origin: $origin"
860 foreach {x y z} $origin {
861 Bimage set $theimg origin $x $y $z $i
868 ## @brief Draws the current image origin
871 proc drawOrigin { } {
873 global show_origin ori_color
874 set c [getImageCanvas $theimg]
875 set wc [getControlWindow $theimg]
877 set img_num [$wc.image.scale get]
878 set slice_num [$wc.slice.scale get]
879 set scale [$wc.scale.scale get]
880 set origin [Bimage get $theimg origin $img_num]
881 set ox [lindex $origin 0]
882 set oy [lindex $origin 1]
883 set oz [lindex $origin 2]
884 if { $show_origin } {
885 if { [expr abs($oz - $slice_num)] < 1 } {
886 set h [lindex [$c cget -scrollregion] 3]
887 $c create oval [expr int(($ox - 4.5)*$scale)] \
888 [expr int($h - ($oy - 4.5)*$scale)] \
889 [expr int(($ox + 5.5)*$scale)] \
890 [expr int($h - ($oy + 5.5)*$scale)] \
891 -tags origin -outline $ori_color
894 $wc.origin.x config -text $ox
895 $wc.origin.y config -text $oy
896 $wc.origin.z config -text $oz
899 proc getPixelCoordinates { c x y } {
901 set wc [getControlWindow $theimg]
902 set scale [$wc.scale.scale get]
903 set h [lindex [$c cget -scrollregion] 3]
904 set cx [$c canvasx $x]
905 set cy [$c canvasy $y]
906 set px [expr int($cx / $scale) ]
907 set py [expr int(($h - $cy) / $scale) ]
912 ## @brief Update or grabs items closeby whenever the mouse is pressed
914 # @param c Canvas object.
916 # @param y Coordinates on the canvas.
918 proc mousePressed { c x y } {
920 global px py m0x m0y mx my
925 set p [getPixelCoordinates $c $x $y ]
929 updateMagnify $px $py default mouse
932 ## @brief Updates or moves grabbed items whenever the mouse is moved.
934 # @param c Canvas object.
936 # @param y Coordinates on the canvas.
937 # @param b button pressed.
939 proc mouseMoved { c x y b } {
940 global filename theimg
944 global selectiontype trace_line
945 if { [string length $filename] < 1 } { return }
946 set wc [getControlWindow $theimg]
947 set scale [$wc.scale.scale get]
948 set cx [$c canvasx $x]
949 set cy [$c canvasy $y]
950 set cmx [$c canvasx $mx]
951 set cmy [$c canvasy $my]
952 set p1 [getPixelCoordinates $c $mx $my ]
953 set p1x [lindex $p1 0]
954 set p1y [lindex $p1 1]
955 set p [getPixelCoordinates $c $x $y ]
960 if { [winfo exists $w] && $b == 1 && $tool == "select" } {
962 set xsize [expr abs($px - $p1x) + 1]
963 set ysize [expr abs($py - $p1y) + 1]
965 if { $selectiontype == "Square" || $selectiontype == "Cube" \
966 || $selectiontype == "Circle" || $selectiontype == "Sphere" } {
968 set cy [expr $cmy + abs($cx - $cmx) ]
970 set cy [expr $cmy - abs($cx - $cmx) ]
973 if { $selectiontype == "Cube" || $selectiontype == "Sphere" } {
977 if { $selectiontype == "Square" || $selectiontype == "Rectangle" || $selectiontype == "Cube" } {
978 $c create rectangle $cmx $cmy $cx $cy -tags selection -outline red
980 if { $selectiontype == "Circle" || $selectiontype == "Ellipse" || $selectiontype == "Sphere" } {
981 $c create oval $cmx $cmy $cx $cy -tags selection -outline red
983 $w.size.x config -text $xsize
984 $w.size.y config -text $ysize
985 $w.size.z config -text $zsize
987 if { $tool == "measure" || $trace_line } {
988 $c create line $cmx $cmy $cx $cy -fill yellow -width 1 -tags measure
991 updateMagnify $px $py default mouse
994 ## @brief Updates grabbed or nearby items whenever the mouse is released.
996 # @param c Canvas object.
998 proc mouseReleased { c } {
1003 global selectiontype calc_stats trace_line line_width
1004 global sx1 sx2 sy1 sy2 sz1 sz2
1005 set wc [getControlWindow $theimg]
1006 set slice_num [$wc.slice.scale get]
1007 set n [$wc.image.scale get]
1008 set scale [$wc.scale.scale get]
1009 # puts "m=$mx,$my p=$px,$py"
1010 set p0 [getPixelCoordinates $c $m0x $m0y ]
1011 set p1 [getPixelCoordinates $c $mx $my ]
1012 set sx0 [lindex $p0 0]
1013 set sx1 [lindex $p1 0]
1015 set sy0 [lindex $p0 1]
1016 set sy1 [lindex $p1 1]
1021 if { [winfo exists .wsel] && $tool == "select" } {
1022 # puts "Statistics for $mx $my $px $py"
1023 if { $selectiontype == "Square" || $selectiontype == "Cube" \
1024 || $selectiontype == "Circle" || $selectiontype == "Sphere" } {
1025 if { $sy2 > $sy1 } {
1026 set sy2 [expr $sy1 + abs($sx2 - $sx1) ]
1028 set sy2 [expr $sy1 - abs($sx2 - $sx1) ]
1030 if { $selectiontype == "Cube" || $selectiontype == "Sphere" } {
1031 set dz [expr abs($sx1 - $sx2)]
1032 set zrad [expr $dz/2]
1033 set sz1 [expr $slice_num - $zrad]
1034 set sz2 [expr $slice_num + $zrad]
1035 if { [expr 2*$zrad] != $dz } { set sz1 [expr $sz1 - 1] }
1036 # puts "$sx1 $sx2 $zrad $sz1 $sz2"
1039 if { $calc_stats } { updateSelectionStats }
1040 } elseif { $tool == "measure" } {
1041 set ps [getPixelSizeEntry]
1042 set dx [expr ($sx2 - $sx0) * [lindex $ps 0]]
1043 set dy [expr ($sy2 - $sy0) * [lindex $ps 1]]
1044 set d [expr sqrt($dx*$dx + $dy*$dy)]
1045 # puts "Distance = $d angstrom"
1046 # puts [expr 57.296 * atan2($dy, $dx)]
1047 $wc.distance.value config -text "$d"
1048 } elseif { $tool == "voxels" } {
1050 if ![winfo exists $w] { Voxels }
1051 if { $trace_line } {
1052 set line_width [$w.type.width.e get]
1053 set line [Bimage get $theimg line $sx0 $sy0 $sz0 $sx2 $sy2 $sz2 $n $line_width]
1054 foreach {n x y z v} $line {
1055 $w.text insert end "$n $x $y $z $v\n"
1059 set value [Bimage get $theimg pixel $sx2 $sy2 $sz2 $n]
1060 # puts "$sx2 $sy2 $value"
1061 $w.text insert end "$n $sx2 $sy2 $sz2 $value\n"
1067 ## @brief Displays updated coordinates whenever the mouse is moved.
1070 proc showCoords { } {
1072 global theimg imgtype
1075 if { [string length $filename] < 1 } { return }
1076 if ![Bimage exists $theimg] { return }
1077 # puts "px = $px py = $py"
1078 set wc [getControlWindow $theimg]
1079 set img_num [$wc.image.scale get]
1080 set slice_num [$wc.slice.scale get]
1081 set value [Bimage get $theimg pixel $px $py $slice_num $img_num]
1082 if { $value eq " " } { return }
1083 $wc.pixel.x config -text "$px"
1084 $wc.pixel.y config -text "$py"
1085 $wc.pixel.value config -text "$value"
1086 if { $tool != "measure" } {
1087 set ps [getPixelSizeEntry]
1088 # puts "pixel size = $ps"
1089 if { $imgtype == "ft" || $imgtype == "ps" } {
1090 set width [Bimage get $theimg width]
1091 set height [Bimage get $theimg height]
1092 set depth [Bimage get $theimg nslices]
1093 set dx [expr ($px*1.0/$width - 0.5) / [lindex $ps 0]]
1094 set dy [expr ($py*1.0/$height - 0.5) / [lindex $ps 1]]
1095 if { $slice_num > 1 } {
1096 set dz [expr ($slice_num*1.0/$depth - 0.5) / [lindex $ps 2]]
1100 # puts "$dx $dy $dz"
1101 set d [expr sqrt($dx*$dx + $dy*$dy + $dz*$dz)]
1102 if { $d < 0.0001 } { set d 0.0001 }
1106 set origin [Bimage get $theimg origin]
1107 set dx [expr [lindex $ps 0]*($px - [lindex $origin 0])]
1108 set dy [expr [lindex $ps 1]*($py - [lindex $origin 1])]
1109 set dz [expr [lindex $ps 2]*($slice_num - [lindex $origin 2])]
1110 set d [expr sqrt($dx*$dx + $dy*$dy + $dz*$dz)]
1113 $wc.distance.value config -text "$d"
1114 $wc.distance.unit config -text "$u"
1118 ## @brief Sets and updates the cutoff FOM.
1120 # @param cutoff FOM cutoff value.
1122 proc setFOMcutoff { cutoff } {
1124 set fom_cutoff $cutoff
1129 ## @brief Selects a cursor for the canvas window.
1132 proc selectCursor { } {
1137 set c [getImageCanvas $theimg]
1139 set pad 4; # extra space around buttons
1140 set cols 6; # number of button columns
1143 X_cursor arrow based_arrow_down based_arrow_up bottom_left_corner
1144 bottom_right_corner bottom_side bottom_tee box_spiral center_ptr circle
1145 cross cross_reverse crosshair diamond_cross dot dotbox double_arrow
1146 draft_large draft_small draped_box exchange fleur hand1 hand2
1147 icon iron_cross left_ptr left_side left_tee ll_angle lr_angle
1148 plus right_ptr right_side
1149 right_tee sb_down_arrow sb_h_double_arrow sb_left_arrow
1150 sb_right_arrow sb_up_arrow sb_v_double_arrow sizing
1151 target tcross top_left_arrow top_left_corner top_right_corner top_side
1152 top_tee ul_angle ur_angle
1155 if { $tcl_platform(platform) == "windows" } {
1156 lappend cursor_list no starting size_ne_sw size_ns size_nw_se size_we uparrow wait
1159 if { $tcl_platform(os) == "Darwin" } {
1160 lappend cursor_list text cross-hair
1165 wm title $w "Select a cursor"
1166 wm iconname $w "Cursors"
1168 foreach cursor $cursor_list {
1169 set cb [button $w.b_$cursor -text $cursor -cursor $cursor -command "configCursor_destroyWindow $c $w $cursor"]
1171 if { [llength $cblist] >= $cols } {
1172 # place whole row of buttons
1173 eval grid $cblist -ipadx $pad -ipady $pad -sticky nswe
1177 if { [llength $cblist] > 0 } {
1178 # place rest of buttons
1179 eval grid $cblist -ipadx $pad -ipady $pad -sticky nswe
1182 eval grid [button $w.cancel -text Cancel -relief flat -overrelief raised -command "destroy $w"] \
1183 -ipadx $pad -ipady $pad -sticky nswe
1187 proc configCursor_destroyWindow { c w name } {
1188 configCursor $c $name
1192 proc configCursor { c name } {
1193 global cursorName tcl_platform
1194 set cursorName $name
1195 # $c config -cursor $cursorName
1196 switch -- $tcl_platform(platform) {
1198 # $c config -cursor "$cursorName #ffffff #ffff00"
1199 $c config -cursor $cursorName
1202 $c config -cursor $cursorName
1207 if {[tk windowingsystem] eq "aqua"} {
1208 proc ::tk::mac::ShowHelp { } {
1210 showURL "file://$Bsoft/doc/bshow/bshow.html"
1214 proc canvas2Photo { canvId } {
1215 # The following line grabs the contents of the canvas canvId into photo image ph.
1216 set retVal [catch {image create photo -format window -data $canvId} ph]
1217 if { $retVal != 0 } {
1218 puts "\n\tFATAL ERROR: Cannot create photo from canvas window"
1224 proc capture {W format file} {
1225 if {[catch {package require Img}]} {
1226 # Error thrown - package not found.
1227 # Set up a dummy interface to work around the absence
1228 puts "package Img not found!"
1233 set image [image create photo -format window -data $W]
1234 $image write -format $format $file
1235 puts "capture -> '$file' ([file size $file] bytes)"