/usr/share/skycat/rtd3.2.1/RtdImage.tcl is in skycat 3.1.2+starlink1~b-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | # E.S.O. - VLT project
# "@(#) $Id: RtdImage.tcl,v 1.1.1.1 2009/03/31 14:11:52 cguirao Exp $"
#
# RtdImage.tcl - itcl widget wrapper for the rtdimage type extension
#
# This widget is based on the Tk rtdimage extension, which is implemented
# in C++. It simplifies things by creating its own frame, canvas and
# scrollbars.
#
# See man page RtdImage(n) for a complete description.
#
# who when what
# -------------- --------- ----------------------------------------
# Allan Brighton 01/06/98 Created
# P.Biereichel 05/08/96 Added itk_option(-with_warp)
# Allan Brighton 22/03/98 Added focus_ method to fix focus problems
# and conflicts between menu traversal and
# mouse cursor warp code (from Peter Draper,
# Starlink).
# pbiereic 11/10/99 Added 'wm colormapwindows' if private colormaps are used
# pbiereic 04/11/03 Workaround bug in tcl 8.4.3 (SourceForge Request ID 835020)
# Peter W. Draper 21/07/12 Make cmap_dir a PATH-like list.
itk::usual RtdImage {}
# The RtdImage widget is an [incr Tk] interface to the rtdimage extended
# Tk image type. The widget creates a canvas window with optional
# scrollbars and a canvas image item to hold the image. An optional
# canvas line graphics editor is also created by default, to manage
# drawing on the image. The RtdImage widget can be treated pretty much
# like any standard Tk widget and can be inserted in a Tk frame with the
# pack(n) command. Applications using the RtdImage widget, can access
# the underlying image object and the canvas window to overlay graphics
# on the image.
#
# In addition to the methods below, this class also forwards methods
# implemented in the C++ rtdimage code. It is, however, usually more
# efficient to use the "get_image" method to get a handle for the
# internal rtdimage object and use it directly.
itcl::class rtd::RtdImage {
inherit util::FrameWidget
# create a new RtdImage widget
constructor {args} {
global ::rtd_library
# frame to hold image and scrollbars
itk_component add imagef {
frame $w_.imagef -background black
} {
keep -borderwidth -relief
}
pack $itk_component(imagef) -fill both -expand 1
# vertical scrollbar frame
itk_component add vscrollf {
frame $itk_component(imagef).vscrollf -background black
}
pack $itk_component(vscrollf) -side right -fill y
# horizontal scrollbar frame
itk_component add hscrollf {
frame $itk_component(imagef).hscrollf -background black
}
pack $itk_component(hscrollf) -side bottom -fill x
# canvas
# note: create canvas in global namespace, to avoid problems in C++ side
set cmd \
[list canvas $itk_component(imagef).canvas \
-xscrollincr 1 \
-yscrollincr 1 \
-background black \
-insertofftime 0]
# Tk canvas containing the image
itk_component add canvas {
set canvas_ [uplevel "#0" $cmd]
} {
rename -relief -canvasrelief canvasRelief CanvasRelief
rename -borderwidth -canvasborderwidth canvasBorderwidth CanvasBorderwidth
rename -background -canvasbackground canvasBackground CanvasBackground
rename -width -canvaswidth canvasWidth CanvasWidth
rename -height -canvasheight canvasHeight CanvasHeight
}
pack $canvas_ -fill both -expand 1
# create the image
# note: create (for now) in global namespace to avoid problems in C++ interface
set cmd [list image create rtdimage]
set image_ [uplevel "#0" $cmd]
# put the image in the canvas
set imageId_ [$canvas_ create image 0 0 \
-image $image_ \
-anchor nw \
-tags $image_]
bind $canvas_ <Configure> [code $this maybe_center]
if {[$image_ cmap isprivate]} {
# set the WM_COLORMAP_WINDOWS property
wm colormapwindows [winfo toplevel $w_] $canvas_
}
eval itk_initialize $args
}
# destructor - clean up when deleted
destructor {
catch {$itk_component(draw) deselect_objects}
catch {$canvas_ delete $image_}
catch {image delete $image_}
}
# this method is called from the base class (TopLevelWidget or FrameWidget)
# after all the options have been evaluated
protected method init {} {
if {$itk_option(-with_warp)} {
# make arrow keys move mouse pointer by one pixel
bind $canvas_ <Left> "+$image_ warp -1 0"
bind $canvas_ <Right> "+$image_ warp 1 0"
bind $canvas_ <Up> "+$image_ warp 0 -1"
bind $canvas_ <Down> "+$image_ warp 0 1"
global ::$w_.focus
set $w_.focus {}
bind $canvas_ <Enter> "+[code $this focus_ in]"
bind $canvas_ <Leave> "+[code $this focus_ out]"
}
# create a blank image and set default scaling factors
if {[$image_ isclear]} { $image_ clear }
$image_ scale $xscale_ $yscale_
$image_ config -newimagecmd [code $this new_image_cmd]
}
# Control the focussing of the canvas. Only take focus if the
# top-level window associated with this canvas has the focus
# (i.e. it's not in another toplevel somewhere). If this isn't
# done then mysterious raises of the main image window can occur
# with some window managers (mainly CDE, with click-to-focus).
#
# allan: 19.6.98: disabled the above behavior, since it causes
# problems with mouse warping and confuses people. Can't verify
# the CDE behavior...
protected method focus_ {way} {
global ::$w_.focus
set top [winfo toplevel $w_]
set focus [focus -displayof $top]
if { $focus != {} } {
#if {[winfo toplevel $focus] == "$top" } {
# This toplevel has the focus (or at least a child of it
# has), so it's ok to proceed.
if { $way == "in" } {
set $w_.focus [focus -displayof .]
catch {focus $canvas_}
} else {
catch {focus [set $w_.focus]}
}
#}
}
}
# utility to update an option in the image
# Note: this works automatically with "widgets", but itk doesn't work
# with "images"...
protected method imageconfig_ {option} {
$image_ config $option $itk_option($option)
}
# return the name of the underlying rtdimage object
public method get_image {} {
return $image_
}
# return the name of the underlying canvas widget
public method get_canvas {} {
return $canvas_
}
# return the canvas Id for the image
public method get_imageId {} {
return $imageId_
}
# return name of global variable which contains the statistics
# of the pick window. This allows applications to trace on this variable.
public method get_pickVar {} {
if {[winfo exists $w_.pick]} {
return [$w_.pick get_pickVar]
}
return ""
}
# update the allowed interactive drawing area in the canvas
protected method set_drawing_area {} {
if {[info exists itk_component(draw)] && ! [$image_ isclear]} {
$image_ convert coords 1 1 image x0 y0 canvas
$image_ convert coords \
[expr {[$image_ width]-1}] \
[expr {[$image_ height]-1}] \
image x1 y1 canvas
set cx0 [expr {int([min $x0 $x1])}]
set cy0 [expr {int([min $y0 $y1])}]
set cx1 [expr {int([max $x0 $x1])}]
set cy1 [expr {int([max $y0 $y1])}]
$itk_component(draw) configure -bbox "$cx0 $cy0 $cx1 $cy1"
}
}
# make the graphics toolbox and menu
protected method make_toolbox {} {
# CanvasDraw(n) object, used to manage the canvas graphics
itk_component add draw {
util::CanvasDraw $w_.draw \
-canvas $canvas_ \
-transient 1 \
-withdraw 1 \
-center 0 \
-shorthelpwin $itk_option(-shorthelpwin) \
-withtoolbox $itk_option(-withtoolbox) \
-defaultcursor $itk_option(-cursor) \
-show_object_menu $itk_option(-show_object_menu) \
-regioncommand $itk_option(-regioncommand)
}
set_drawing_area
# clicking on the image or image background deselects other objects
$canvas_ bind $image_ <1> [code $itk_component(draw) deselect_objects]
}
# display the toolbox window
public method show_toolbox {} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
if {! [info exists itk_component(draw)]} {
# user must have deleted window...
make_toolbox
} else {
# $itk_component(draw) center_window
wm deiconify $itk_component(draw)
wm transient $itk_component(draw) $w_
}
}
# resize the image and the canvas graphics by the given integer factors
# (1 is no scale, -2 = 50%, 2 = 200% etc...)
# - deselect canvas graphics (so handles don't get scaled)
public method scale {x y} {
# don't resize selection grips
if {$itk_option(-graphics)} {
$itk_component(draw) deselect_objects
}
save_scroll_pos_
set xscale_ $x
set yscale_ $y
# note previous scale and position
lassign [$image_ scale] xs ys
if {"$xs" == ""} {
set xs [set ys 1]
} else {
# scale the image
if {[catch {$image_ scale $x $y} msg]} {
error_dialog $msg $w_
return
}
# if we passed the max scale factor, it will be ignored
if {"[$image_ scale]" == "$xs $ys"} {
return
}
}
# scale the canvas items (need relative floating point factor)
if {$xs < 0} {
set xs [expr {-1.0/$xs}]
set ys [expr {-1.0/$ys}]
}
if {$x < 0} {
set x [expr {-1.0/$x}]
set y [expr {-1.0/$y}]
}
# carefull in case scale factor is zero
set fx [expr {double($x)/$xs}]
set fy [expr {double($y)/$ys}]
$canvas_ scale all 0 0 $fx $fy
# set new scrollregion to include all of image
set w [$image_ dispwidth]
set h [$image_ dispheight]
set_scrollregion 0 0 $w $h
# notify rapid frame to change size if necessary
if {[winfo exists $w_.rapid]} {
$w_.rapid notify_cmd scale
}
restore_scroll_pos_
maybe_center
# update interactive drawing area
set_drawing_area
# update pick window, if needed
if {[winfo exists $w_.pick]} {
$w_.pick update_scale $fx $fy
}
}
# save the current scrolling positions
protected method save_scroll_pos_ {} {
lassign [$canvas_ xview] xScroll0_ xScroll1_
lassign [$canvas_ yview] yScroll0_ yScroll1_
# XXX needed for bug in tcl 8.4.3
set bug "$xScroll0_ $xScroll1_ $yScroll0_ $yScroll1_"
}
# restore the relative scrolling positions
protected method restore_scroll_pos_ {} {
$canvas_ xview moveto $xScroll0_
$canvas_ yview moveto $yScroll0_
lassign [$canvas_ xview] x0 x1
lassign [$canvas_ yview] y0 y1
$canvas_ xview moveto [expr {$x0-($x1-$xScroll1_)/2.0}]
$canvas_ yview moveto [expr {$y0-($y1-$yScroll1_)/2.0}]
}
# toggle rotation of the image and canvas items
public method rotate {bool} {
if {$bool != [$image_ rotate]} {
$image_ rotate $bool
if {[info exists itk_component(draw)]} {
$itk_component(draw) rotate all
}
if {[$image_ dispwidth] != [$image_ dispheight]} {
center
}
# notify rapid frame to move if necessary
if {[winfo exists $w_.rapid]} {
$w_.rapid notify_cmd rotate $bool
}
# update interactive drawing area
set_drawing_area
}
}
# flip or unflip the image and canvas items about the
# x or y axis, as given by $xy
public method flip {xy bool} {
if {$bool != [$image_ flip $xy]} {
set coords [$canvas_ coords $image_]
$image_ flip $xy $bool
if {[info exists itk_component(draw)]} {
if {"$xy" == "x"} {
$itk_component(draw) flipx all [expr {[$image_ dispwidth]-1}]
} else {
$itk_component(draw) flipy all [expr {[$image_ dispheight]-1}]
}
}
eval "$canvas_ coords $image_ $coords"
# notify rapid frame to move if necessary
if {[winfo exists $w_.rapid]} {
$w_.rapid notify_cmd flip $xy $bool
}
# update interactive drawing area
set_drawing_area
}
}
# if the image is smaller than the canvas window, center it
public method maybe_center {} {
set cw [winfo width $canvas_]
set ch [winfo height $canvas_]
set dw [$image_ dispwidth]
set dh [$image_ dispheight]
if {$cw != 1} {
if {$dw < $cw && $dw} {
set x [expr {(($dw-$cw)/2.0)/$dw}]
$canvas_ xview moveto $x
}
if {$dh < $ch && $dh} {
set y [expr {(($dh-$ch)/2.0)/$dh}]
$canvas_ yview moveto $y
}
} else {
update
maybe_center
return
}
set_scrollregion 0 0 $dw $dh
}
# set the canvas scrollregion
protected method set_scrollregion {x0 y0 x1 y1} {
$canvas_ config -scrollregion "$x0 $y0 $x1 $y1"
}
# center the image in the canvas window
public method center {} {
set dw [$image_ dispwidth]
set dh [$image_ dispheight]
set_scrollregion 0 0 $dw $dh
set cw [winfo width $canvas_]
set ch [winfo height $canvas_]
if {$cw != 1 && $dw && $dh} {
$canvas_ xview moveto [expr {(($dw-$cw)/2.0)/$dw}]
$canvas_ yview moveto [expr {(($dh-$ch)/2.0)/$dh}]
}
}
# arrange to interactively create a rapid frame to display
# a section of the image.
# If popup is 1, the frame is displayed in a popup window,
# otherwise at the selected position in the canvas
public method rapid_frame {popup} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
if {[winfo exists $w_.rapid]} {
destroy $w_.rapid
}
if {[action_dialog \
"Please select and drag out a region of the image with mouse button 1" \
$w_]} {
$itk_component(draw) set_drawing_mode region [code $this make_rapid_frame $popup]
}
}
# delete the rapid frame
public method delete_rapid_frame {} {
if {[winfo exists $w_.rapid]} {
destroy $w_.rapid
}
}
# Create a rapid frame to display a section of the image.
# If popup is 1, the frame is displayed in a popup window,
# otherwise at the selected position in the canvas
# "region_id" is the canvas id of the object used to position
# and resize the image.
protected method make_rapid_frame {popup region_id x0 y0 x1 y1} {
set xoffset [expr {int($x0)}]
set yoffset [expr {int($y0)}]
set width [expr {int($x1-$x0+1)}]
set height [expr {int($y1-$y0+1)}]
if {$popup} {
rtd::RtdImagePopup $w_.rapid \
-target_image $this \
-xoffset $xoffset \
-yoffset $yoffset \
-width $width \
-height $height \
-zoomwin $itk_option(-zoomwin) \
-subsample $itk_option(-subsample) \
-usexshm $itk_option(-usexshm) \
-usexsync $itk_option(-usexsync) \
-withdraw [expr {!$popup}] \
-region_id $region_id \
-verbose $itk_option(-verbose) \
-shorthelpwin $itk_option(-shorthelpwin) \
-transient 1 \
-min_scale $itk_option(-min_scale) \
-max_scale $itk_option(-max_scale) \
-command $itk_option(-rapid_frame_command) \
} else {
rtd::RtdImageFrame $w_.rapid \
-target_image $this \
-xoffset $xoffset \
-yoffset $yoffset \
-width $width \
-height $height \
-subsample $itk_option(-subsample) \
-usexshm $itk_option(-usexshm) \
-usexsync $itk_option(-usexsync) \
-region_id $region_id \
-verbose $itk_option(-verbose) \
-command $itk_option(-rapid_frame_command)
}
}
# attach the named camera.
public method attach_camera {camera} {
# these commands are evaluated before/after real-time events
set preCmd [code $this camera_pre_command]
set postCmd [code $this camera_post_command]
if {[catch {$image_ camera attach $camera $preCmd $postCmd} msg]} {
# try again. Maybe rtdServer wasn't started yet.
catch {exec rtdServer &}
after 2000
}
if {[catch {$image_ camera attach $camera $preCmd $postCmd} msg]} {
error_dialog $msg
}
update idletasks
}
# stop the camera.
# note: race conditions might cause display to lag behind the socket data.
# force an update here.
public method detach_camera {} {
$image_ camera detach
$image_ update
}
# This method is called when a new image has been received from
# the camera and before it is displayed.
# The frameid will be 0 for the main image and non-zero for a rapid frame.
public method camera_pre_command {frameid} {
if {$frameid != 0} { return }
if {"$cameraPreCmd_" != ""} {
catch {eval $cameraPreCmd_}
}
}
# This method is called whenever a new image has been received from
# the camera and displayed.
# Update the widgets that need to display new values
# The frameid will be 0 for the main image and non-zero for a rapid frame.
public method camera_post_command {frameid} {
if {$frameid != 0} { return }
if {[winfo exists $w_.spectrum]} {
$w_.spectrum notify_cmd
}
if {"$preview_var_" != ""} {
global ::$preview_var_
if {[info exists $preview_var_]} {
set $preview_var_ 0
}
}
# update picked object
if {[winfo exists $w_.pick] && $updatePick_ != 0} {
$w_.pick update_now
}
# set up world coordinate info, if needed
set_rtd_wcs_info $frameid
if {"$cameraPostCmd_" != ""} {
catch {eval $cameraPostCmd_}
}
}
# Set up world coordinate info for an image received from the rtdServer.
public method set_rtd_wcs_info {frameid} {
}
# popup a window to display a table of nrows x ncols pixel values
# from the image
public method pixel_table {nrows ncols} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
if {[winfo exists $w_.pixtable]} {
destroy $w_.pixtable
}
rtd::RtdImagePixTable $w_.pixtable \
-image $this \
-nrows $nrows \
-ncols $ncols \
-shorthelpwin $itk_option(-shorthelpwin) \
-transient 1
}
# arrange to interactively create a spectrum line to display
# a graph of the image values along a given line.
public method spectrum {} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
if {[winfo exists $w_.spectrum]} {
$w_.spectrum quit
}
if {[action_dialog \
"Press OK and then drag out a line over the image with button 1" \
$w_]} {
$itk_component(draw) set_drawing_mode line [code $this make_spectrum]
}
}
# display a dialog for selecting objects in the image and displaying information
# about the selected area of the image
public method pick_dialog {{command ""}} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
utilReUseWidget rtd::RtdImagePick $w_.pick \
-target_image $this \
-command $command \
-verbose $itk_option(-verbose) \
-orient $itk_option(-pickobjectorient) \
-debug $itk_option(-debug) \
-shorthelpwin $itk_option(-shorthelpwin)
$w_.pick pick_object
}
# this method can be used in bindings to cause a selection in the
# image (to pick an object/star) to return the given position rather than the
# calculated center pos. If the optional args are not specified, they are
# calculated.
protected method picked_wcs_object {x y ra dec {equinox J2000} {fwhmX ""} {fwhmY ""} \
{angle ""} {object ""} {background ""}} {
if {[winfo exists $w_.pick]} {
if {"$angle" == ""} {
$w_.pick picked_special_object $x $y $ra $dec $equinox
} else {
$w_.pick picked_wcs_object \
[list $x $y $ra $dec $equinox $fwhmX $fwhmY $angle $object $background]
}
}
}
# make a hard copy of the image display
public method print {} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
set object [$image_ object]
set file [file tail $itk_option(-file)]
set center [$image_ wcscenter]
set user [id user]
set app [lindex [winfo name .] 0]
set date [clock format [clock seconds] -format {%b %d, %Y at %H:%M:%S}]
utilReUseWidget rtd::RtdImagePrint $w_.print \
-image $this \
-show_footer 1 \
-whole_canvas 0 \
-transient 1 \
-top_left "ESO\n$object" \
-top_right "$file\n$center" \
-bot_left "$user/$app" \
-bot_right "$date"
}
# Save the current image or a section of the current image to a file in
# FITS format chosen from a file name dialog. If dir and pattern are specified,
# they are used as defaults for the file selection dialog.
# If x0, y0, x1 and y1 are specified (canvas coordinates), then a section
# of the image is saved.
#
# The return value is the name of the new file, if any, or an empty string.
public method save_as {{dir "."} {pattern "*"} {x0 ""} {y0 ""} {x1 ""} {y1 ""}} {
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
set file [filename_dialog $dir $pattern $w_]
if {"$file" != ""} {
if {[file isfile $file]} {
if {![confirm_dialog \
"[file tail $file] exists - Do you want to overwrite it ?" $w_]} {
return
}
if {[file isdir $file]} {
error_dialog "$file is a directory" $w_
return
}
}
if {"$x0" == ""} {
$image_ dump $file
} else {
if {[catch {
$image_ convert coords $x0 $y0 canvas x0 y0 image
$image_ convert coords $x1 $y1 canvas x1 y1 image
$image_ dump $file $x0 $y0 $x1 $y1
} msg]} {
error_dialog $msg
return
}
}
return $file
}
}
# save a section of the current image to a file in FITS format
# chosen from a file name dialog.
public method save_region_as {} {
# check if we have an image
if {[$image_ isclear]} {
warning_dialog "No image is currently loaded" $w_
return
}
# can't convert DSS plate cooeficients correctly
if {"[$image_ fits get PLTRAH]" != ""} {
if { ! [confirm_dialog "Can't convert DSS plate coefficients.\
Please get the image from the DSS image server.\n\n\
\tContinue anyway?" $w_] } {
return
}
}
# first get the region to save
if {[action_dialog \
"Please select and drag out a region of the image with mouse button 1" \
$w_]} {
$itk_component(draw) set_drawing_mode region [code $this save_region]
}
}
# save the given section of the current image to a file in FITS format
# chosen from a file name dialog. The canvas_id is the id if the canvas
# object used to select the region . The canvas coordinates of the region
# are also passed as arguments.
protected method save_region {canvas_id x0 y0 x1 y1} {
save_as . * $x0 $y0 $x1 $y1
$itk_component(draw) delete_object $canvas_id
}
# Create a graph to display the image data values along the line
# just created.
# "line_id" is the canvas id of the line.
protected method make_spectrum {line_id x0 y0 x1 y1} {
if {[winfo exists $w_.spectrum]} {
$w_.spectrum quit
}
rtd::RtdImageSpectrum $w_.spectrum \
-x0 [expr {int($x0)}] \
-y0 [expr {int($y0)}] \
-x1 [expr {int($x1)}] \
-y1 [expr {int($y1)}] \
-image $this \
-transient 1 \
-shorthelpwin $itk_option(-shorthelpwin) \
-line_id $line_id
}
# toggle the visibility of the line graphics
# (The trace variable name is passed here, if 1, hide the graphics...)
public method hide_graphics {variable} {
global ::$variable
if {[set $variable]} {
$canvas_ raise $image_
} else {
$canvas_ lower $image_
}
}
# this method is called by the image code whenever a new image is loaded
# (for updates, see camera command)
protected method new_image_cmd {} {
# only runs the first time, if the user chose a different color scale
if {"$itk_option(-color_scale)" != "linear"} {
if {[catch {$image_ colorscale $itk_option(-color_scale)} msg]} {
error_dialog $msg
}
set itk_option(-color_scale) linear
}
if {[winfo exists $w_.rapid]} {
destroy $w_.rapid
}
if {[info exists itk_component(draw)]} {
$itk_component(draw) clear
set_drawing_area
}
# update biasimage status
$image_ biasimage update
if {"$itk_option(-newimagecmd)" != ""} {
eval $itk_option(-newimagecmd)
}
center
}
# set preview mode on or off in the image. In this case, the
# arg is the "name" of a global variable controlling the preview
# mode. It will be kept up to date by this class.
public method preview {var} {
global ::$var
$image_ preview [set [set preview_var_ $var]]
}
# set the performance test mode on or off.
public method perftest {} {
if {[catch {$image_ perftest on} msg]} {
error_dialog $msg
return
}
utilReUseWidget rtd::RtdImagePerf $w_.perf \
-target_image $this \
-shorthelpwin $itk_option(-shorthelpwin)
}
# Methods for the playing and recording of images.
public method record {camera} {
utilReUseWidget RtdRecorderTool $w_.rec \
-target_image $this \
-server_camera $camera \
-shorthelpwin $itk_option(-shorthelpwin)
}
# clear the current image display and remove any windows that
# access it
public method clear {} {
$image_ config -file ""
set itk_option(-file) ""
set w [$image_ dispwidth]
set h [$image_ dispheight]
set_scrollregion 0 0 $w $h
if {[info exists itk_component(draw)]} {
$itk_component(draw) clear
}
$canvas_ delete objects
if {[winfo exists $w_.rapid]} {
destroy $w_.rapid
}
if {[winfo exists $w_.spectrum]} {
destroy $w_.spectrum
}
if {[winfo exists $w_.pixtable]} {
destroy $w_.pixtable
}
if {[winfo exists $w_.pick]} {
$w_.pick close
}
}
# reload the image file, if there is one
public method reopen {} {
$image_ update
}
# load a FITS file (internal version: use -file option/public variable)
protected method load_fits_ {} {
if {[file exists $itk_option(-file)] || "$itk_option(-file)" == "-"} {
if {[catch {$image_ config -file $itk_option(-file)} msg]} {
error_dialog $msg $w_
clear
}
set w [$image_ dispwidth]
set h [$image_ dispheight]
set_scrollregion 0 0 $w $h
} else {
error_dialog "'$itk_option(-file)' does not exist" $w_
set file ""
clear
}
}
# pass these methods on to the image widget unchanged
# (this just generates methods on the fly...)
::foreach i {view cut cmap itt colorscale alloccolors zoom zoomview object convert
wcscenter wcsradius isclear dispwidth dispheight freq} {
method $i {args} [::format {return [eval "$image_ %s $args"]} $i]
}
# -- public vars --
# fits image file to display
itk_option define -file file File {} {
if {"$itk_option(-file)" != ""} {
# this code makes it easier to center the image on startup
if {[winfo width $w_] <= 1 || [$image_ isclear]} {
after 0 [code $this load_fits_]
} else {
load_fits_
}
}
}
# for compatibility with saoimage
itk_option define -fits fits Fits {} {
if {"$itk_option(-fits)" != ""} {
config -file $itk_option(-fits)
}
}
# set displaymode flag 0 to optimize for smooth scrolling,
# 1 for faster updates and less memory (works best for main image)
itk_option define -displaymode displayMode DisplayMode {1} {
imageconfig_ -displaymode
}
# X shared memory option.
# DISABLED: pbi 01/03/05
# Dynamic re-configuration crashes rtd but has never been used
# by any application or by rtd itself.
itk_option define -usexshm useXshm UseXshm 1 {
###imageconfig_ -usexshm
}
# X synchronisation option
itk_option define -usexsync useXsync UseXsync 1 {
imageconfig_ -usexsync
}
# -name option
itk_option define -name name Name {MainImage} {
imageconfig_ -name
}
# minimum allowed scale value
itk_option define -min_scale min_scale Min_scale -10
# maximum allowed scale value
itk_option define -max_scale max_scale Max_scale 20
# This flag controls whether the FITS image header is kept in
# SysV shared memory (see the rtdRemote interface for use of this)
itk_option define -shm_header shm_header Shm_header 0 {
imageconfig_ -shm_header
}
# This flag controls whether the FITS image data is kept in
# SysV shared memory (see the rtdRemote interface for use of this)
itk_option define -shm_data shm_data Shm_data 0 {
imageconfig_ -shm_data
}
# Specify the min number of colors to allocate before using
# a private colormap. Note: this option is currently ignored.
itk_option define -min_colors min_colors Min_colors 30 {
imageconfig_ -min_colors
}
# Specify the max number of colors to allocate before using
# a private colormap. Note: this option is currently ignored.
itk_option define -max_colors max_colors Max_colors 60 {
imageconfig_ -max_colors
}
# if non-zero, shrink image to fit width
itk_option define -fitwidth fitWidth FitWidth {0} {
if {$itk_option(-fitwidth)} {
config -canvaswidth $itk_option(-fitwidth)
imageconfig_ -fitwidth
}
}
# if non-zero, shrink image to fit height
itk_option define -fitheight fitHeight FitHeight {0} {
if {$itk_option(-fitheight)} {
config -canvasheight $itk_option(-fitheight)
imageconfig_ -fitheight
}
}
# if non-zero, fill image to fit width
itk_option define -fillwidth fillWidth FillWidth {0} {
if {$itk_option(-fillwidth)} {
config -canvaswidth $itk_option(-fillwidth)
imageconfig_ -fillwidth
}
}
# if non-zero, fill image to fit height
itk_option define -fillheight fillHeight FillHeight {0} {
if {$itk_option(-fillheight)} {
config -canvasheight $itk_option(-fillheight)
imageconfig_ -fillheight
}
}
# flag: if true, print diagnostic messages
itk_option define -verbose verbose Verbose {0} {
imageconfig_ -verbose
}
# flag: if true, use quick and dirty algorithm to shrink images
itk_option define -subsample subsample Subsample {1} {
imageconfig_ -subsample
}
# sampling method to used when option -subsample is 0
itk_option define -sampmethod sampmethod Sampmethod {0} {
imageconfig_ -sampmethod
}
# flag: if true, display horizontal and vertical scrollbars
itk_option define -scrollbars scrollbars Scrollbars 0 {
if {$itk_option(-scrollbars)} {
# optional vertical scrollbar
if {![info exists itk_component(vscroll)]} {
itk_component add vscroll {
scrollbar $itk_component(vscrollf).vscroll \
-relief sunken \
-command [code $canvas_ yview]
}
pack $itk_component(vscroll) -side right -fill y
$canvas_ config -yscrollcommand "$itk_component(vscroll) set"
}
if {![info exists itk_component(hscroll)]} {
# optional horizontal scrollbar
itk_component add hscroll {
scrollbar $itk_component(hscrollf).hscroll \
-relief sunken \
-orient horiz \
-command [code $canvas_ xview]
}
pack $itk_component(hscroll) -side bottom -fill x
$canvas_ config -xscrollcommand "$itk_component(hscroll) set"
}
} else {
$canvas_ config -xscrollcommand "" -yscrollcommand ""
if {[info exists itk_component(vscroll)]} {
destroy $itk_component(vscroll)
destroy $itk_component(hscroll)
unset itk_component(vscroll)
unset itk_component(hscroll)
}
}
}
# flag: if true, set bindings to scroll with the middle mouse button
itk_option define -drag_scroll drag_scroll Drag_scroll 0 {
global EDITING ; # panel editor
set pe 0
if {[info exists EDITING]} {
set pe $EDITING
}
if { ! $pe } {
if {$itk_option(-drag_scroll)} {
bind $canvas_ <2> [code $canvas_ scan mark %x %y]
bind $canvas_ <B2-Motion> [code "$canvas_ scan dragto %x %y; $this maybe_center"]
} else {
bind $canvas_ <2> { }
bind $canvas_ <B2-Motion> { }
}
}
}
# flag: if true, create a CanvasDraw object to manage the canvas graphics
itk_option define -graphics graphics Graphics 1 {
if {$itk_option(-graphics) && ![info exists itk_component(draw)]} {
# create an object to manage the canvas graphics
make_toolbox
} else {
$canvas_ config -cursor $itk_option(-cursor)
}
}
# if true (default) create the GUI interface (toolbox), otherwise don't
itk_option define -withtoolbox withToolbox WithToolbox {1}
# default cursor
itk_option define -cursor cursor Cursor {target}
# Tcl command to evaluate whenever a "region" of the image is selected
# via the graphic toolbox "region" selection item. Can be used to
# select graphic items or a section of the image for an operation.
itk_option define -regioncommand regionCommand RegionCommand {}
# optional tcl command to be evaluated when a rapid frame is created, moved,
# resized or deleted: 6 args will be appended:
#
# name = unique name for the frame
# op = {move,resize or delete},
# x, y = coords of upper left corner of frame in image
# width, height = dimensions of frame.
itk_option define -rapid_frame_command rapid_frame_command Rapid_frame_command {}
# default cmap file
itk_option define -default_cmap default_cmap Default_cmap {real}
# default ITT file
itk_option define -default_itt default_itt Default_itt {ramp}
# Set the default color scale algorithm to one of: {linear log sqrt histeq}
itk_option define -color_scale color_scale Color_scale linear
# Colormap initialization and directory search path for colormap
# and ITT files
itk_option define -cmap_dir cmap_dir Cmap_dir {} {
if {!$colormap_initialized_} {
global ::rtd_library
if {"$itk_option(-cmap_dir)" == ""} {
set itk_option(-cmap_dir) $rtd_library/colormaps
}
# find default cmap and itt, could be on the search path
set basename $itk_option(-default_cmap).$itk_option(-cmap_suffix)
set cmap {}
set dirlist [split $itk_option(-cmap_dir) {;}]
foreach dir $dirlist {
set offered_cmap ${dir}/${basename}
if { [::file exists $offered_cmap] } {
set cmap $offered_cmap
break
}
}
if { $cmap == {} } {
set cmap [lindex $dirlist 0]/$basename
}
$image_ cmap file $cmap
set basename $itk_option(-default_itt).$itk_option(-itt_suffix)
set itt {}
foreach dir $dirlist {
set offered_itt ${dir}/${basename}
if { [::file exists $offered_itt] } {
set itt $offered_itt
break
}
}
if { $itt == {} } {
set itt [lindex $dirlist 0]/$basename
}
$image_ itt file $itt
set colormap_initialized_ 1
}
}
# suffix for colormap files
itk_option define -cmap_suffix cmap_suffix Cmap_suffix {lasc}
# suffix for ITT files
itk_option define -itt_suffix itt_suffix Itt_suffix {iasc}
# flag: if true, display menus over graphic objects when selected with <3>
itk_option define -show_object_menu show_object_menu Show_object_menu 0
# name of zoom window to update when mouse enters this window
itk_option define -zoomwin zoomWin ZoomWin {} {
if {"$itk_option(-zoomwin)" != ""} {
bind $canvas_ <Any-Enter> "+$itk_option(-zoomwin) enter_image $image_"
bind $canvas_ <Any-Leave> "+$itk_option(-zoomwin) leave_image $image_"
}
}
# short help text
itk_option define -shelp shelp Shelp "image window" {
if {"$itk_option(-shelp)" != ""} {
catch {add_short_help $w_ $itk_option(-shelp)} msg
catch {add_short_help $canvas_ $itk_option(-shelp)} msg
}
}
# -orient option for Pick Object window
itk_option define -pickobjectorient pickObjectOrient PickObjectOrient {vertical}
# option to update RtdImagePick after a real-time image event
itk_option define -updatePick updatePick UpdatePick {1} {
set updatePick_ $itk_option(-updatePick)
}
# command to eval when a new image is loaded
itk_option define -newimagecmd newImageCmd NewImageCmd ""
# optionally specify TopLevelWidget to display short help messages
itk_option define -shorthelpwin shortHelpWin ShortHelpWin {}
# debugging flag
itk_option define -debug debug Debug {0} {
imageconfig_ -debug
}
# option to warp the mouse pointer
itk_option define -with_warp with_warp With_warp 0
# default scaling factors
itk_option define -xscale xscale Xscale {1} {
set xscale_ $itk_option(-xscale)
if {[winfo width $w_] > 1} {
scale $xscale_ $yscale_
}
}
itk_option define -yscale yscale Yscale {1} {
set yscale_ $itk_option(-yscale)
if {[winfo width $w_] > 1} {
scale $xscale_ $yscale_
}
}
# commands to be evaluated before/after image events
itk_option define -cameraPreCmd cameraPreCmd CameraPreCmd {} {
set cameraPreCmd_ $itk_option(-cameraPreCmd)
}
itk_option define -cameraPostCmd cameraPostCmd CameraPostCmd {} {
set cameraPostCmd_ $itk_option(-cameraPostCmd)
}
# -- protected vars --
# internal rtd image
protected variable image_
# canvas widget
protected variable canvas_
# canvas Id for image
protected variable imageId_
# name of a global variable controlling preview mode
protected variable preview_var_ {}
# saved x0 relative scrolling position
protected variable xScroll0_ 0
# saved x1 relative scrolling position
protected variable xScroll1_ 0
# saved y0 relative scrolling position
protected variable yScroll0_ 0
# saved y1 relative scrolling position
protected variable yScroll1_ 0
# camera pre/post commands
protected variable cameraPreCmd_ ""
protected variable cameraPostCmd_ ""
# values for xscale, yscale
protected variable xscale_ 1
protected variable yscale_ 1
# update RtdImagePick after a real-time event
protected variable updatePick_ 1
# --- common to all instances --
# flag: true if the colormap has been initialized
common colormap_initialized_ 0
}
|