| 1 | package Tk::AstroCatalog; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Tk::SourceCatalog - creates a self-standing sources catalog widget | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use Tk::AstroCatalog; | ||
| 10 | |||
| 11 | $cat = new Tk::AstroCatalog($MW, $addCmd, $upDate, $onDestroy); | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | Tk::AstroCatalog creates a non-editable text widget, displaying | ||
| 16 | sources from a default catalog or user-selected catalog file. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 1 | ▶ | use Math::Trig qw/pi/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 1 | ▶ | use Astro::Catalog; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | 1 | ▶ | use Astro::Catalog::Item; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 1 | ▶ | use Astro::Coords 0.12; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 0 | ▶ | use Tk; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 27 | use Tk::FileSelect; | ||
| 28 | |||
| 29 | my $locateBug = 0; | ||
| 30 | my $BUSY = 0; | ||
| 31 | my @COLOR_LIST = ( | ||
| 32 | '#ffAAAA', '#00ff00', '#ff55ff', '#ffff00', '#00ffff', | ||
| 33 | '#ff00ff', '#ffffff', '#ff5555', '#55ff55', '#55ffff', '#ffff55'); | ||
| 34 | my $COLOR_INDEX = 0; | ||
| 35 | |||
| 36 | our $VERSION = '4.38'; | ||
| 37 | |||
| 38 | # Kluge - this is the format of the catalog to be read | ||
| 39 | # Needs to be given as an option on the FileSelect widget. | ||
| 40 | our $FORMAT = 'JCMT'; | ||
| 41 | our $FORMAT_OPT = {incplanets => 0}; | ||
| 42 | |||
| 43 | =head1 PUBLIC METHODS | ||
| 44 | |||
| 45 | Methods available in this class: | ||
| 46 | |||
| 47 | =head2 Constructor | ||
| 48 | |||
| 49 | =over 4 | ||
| 50 | |||
| 51 | =item new | ||
| 52 | |||
| 53 | Create a new Tk::AstroCatalog object. A new catalog object will be | ||
| 54 | created. Callbacks must be specified for -addCmd and -upDate; a | ||
| 55 | warning is issued for -onDestroy when it is missing. | ||
| 56 | |||
| 57 | $cat = new Tk::AstroCatalog($MW, | ||
| 58 | -addCmd => $addCmd, | ||
| 59 | -upDate => $upDate, | ||
| 60 | -onDestroy => $onDestroy); | ||
| 61 | |||
| 62 | Additionally a pre-existing Astro::Catalog object can be supplied | ||
| 63 | using the "-catalog" option. | ||
| 64 | |||
| 65 | $cat = new Tk::AstroCatalog($MW, | ||
| 66 | -addCmd => $addCmd, | ||
| 67 | -upDate => $upDate | ||
| 68 | -catalog => $cat); | ||
| 69 | |||
| 70 | The "-transient" option can be used if only a single value is required | ||
| 71 | from the widget. Default behaviour is for the widget to be | ||
| 72 | permanent. The "-transient" button does not have a "Done" button on | ||
| 73 | the screen (ie no button to close the window without a selection) | ||
| 74 | |||
| 75 | The "-addCmd" callback is triggered whenever a source is selected | ||
| 76 | from the widget. If the widget is transient the widget will be | ||
| 77 | closed after the first add is triggered. | ||
| 78 | |||
| 79 | The "-onDestroy" callback is triggered when the "Done" button is | ||
| 80 | pressed. | ||
| 81 | |||
| 82 | The "-upDate" method is triggered whenever the contents of the | ||
| 83 | catalog widget are refreshed/updated. | ||
| 84 | |||
| 85 | It makes more sense for this widget to work like Tk::FileSelect | ||
| 86 | when used in transient mode since we want to get the answer back | ||
| 87 | rather than enter an event loop. | ||
| 88 | |||
| 89 | The "-customColumns" method can be used to add additional columns | ||
| 90 | to the display. This is an array of hashes specifying the | ||
| 91 | title, width and generator function for each column. This generating | ||
| 92 | function will be called with an Astro::Catalog::Item and must | ||
| 93 | return a string of the given width. | ||
| 94 | |||
| 95 | -customColumns => [{ | ||
| 96 | title => 'Example', | ||
| 97 | width => 7, | ||
| 98 | generator => sub { | ||
| 99 | my $item = shift; | ||
| 100 | return sprintf('%7s', 'test'); | ||
| 101 | }}, | ||
| 102 | ] | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | sub new { | ||
| 107 | my $class = shift; | ||
| 108 | croak "CatWin usage: Missing args \n" unless (@_); | ||
| 109 | my $MW = shift; | ||
| 110 | my %defaults = ( | ||
| 111 | -default => 'defaults', | ||
| 112 | -transient => 0, | ||
| 113 | @_); | ||
| 114 | |||
| 115 | croak "Tk::AstroCatalog -addCmd option missing \n" unless exists $defaults{'-addCmd'}; | ||
| 116 | croak "Tk::AstroCatalog -upDate option missing \n" unless exists $defaults{'-upDate'}; | ||
| 117 | warn "Tk::AstroCatalog -onDestroy option missing \n" unless exists $defaults{'-onDestroy'}; | ||
| 118 | |||
| 119 | my $self = {}; | ||
| 120 | |||
| 121 | if (exists $defaults{'-catalog'}) { | ||
| 122 | $self->{CatClass} = ref($defaults{'-catalog'}); | ||
| 123 | $self->{Catalog} = $defaults{'-catalog'}; | ||
| 124 | } | ||
| 125 | else { | ||
| 126 | # use default settings | ||
| 127 | $self->{CatClass} = 'Astro::Catalog'; | ||
| 128 | $self->{Catalog} = $self->{CatClass}->new(); | ||
| 129 | } | ||
| 130 | |||
| 131 | $self->{UpDate} = undef; | ||
| 132 | $self->{Reset} = undef; | ||
| 133 | $self->{AddCommand} = undef; | ||
| 134 | $self->{Toplevel} = $MW->Toplevel; | ||
| 135 | $self->{Selected} = []; | ||
| 136 | $self->{Text} = undef; | ||
| 137 | $self->{File} = 'default'; | ||
| 138 | $self->{Transient} = $defaults{'-transient'}; | ||
| 139 | $self->{RefLabel} = ''; | ||
| 140 | |||
| 141 | if (exists $defaults{'-customColumns'}) { | ||
| 142 | # Store whole hash rather than just generator function | ||
| 143 | # in case we want to add other ways of specifying custom columns. | ||
| 144 | my $cols = $self->{CustomColumns} = $defaults{'-customColumns'}; | ||
| 145 | croak "Tk::AstroCatalog -customColumns must be an array ref" | ||
| 146 | unless 'ARRAY' eq ref $cols; | ||
| 147 | |||
| 148 | my $headings = ''; | ||
| 149 | foreach my $col (@$cols) { | ||
| 150 | $headings .= sprintf('%-' . $col->{'width'} . 's ', $col->{'title'}); | ||
| 151 | } | ||
| 152 | |||
| 153 | $self->{CustomHeadings} = $headings; | ||
| 154 | $self->{CustomWidth} = length($headings); | ||
| 155 | } | ||
| 156 | else { | ||
| 157 | $self->{CustomColumns} = undef; | ||
| 158 | $self->{CustomHeadings} = ''; | ||
| 159 | $self->{CustomWidth} = 0; | ||
| 160 | } | ||
| 161 | |||
| 162 | bless $self, $class; | ||
| 163 | $self->Reset($defaults{'-onDestroy'}) if exists $defaults{'-onDestroy'}; | ||
| 164 | $self->AddCommand($defaults{'-addCmd'}); | ||
| 165 | $self->UpDate($defaults{'-upDate'}); | ||
| 166 | |||
| 167 | $self->makeCatalog(); | ||
| 168 | return $self; | ||
| 169 | } | ||
| 170 | |||
| 171 | =back | ||
| 172 | |||
| 173 | =head2 Data manipulation functions | ||
| 174 | |||
| 175 | =over 4 | ||
| 176 | |||
| 177 | =item Catalog | ||
| 178 | |||
| 179 | Returns and sets the Astro::Catalog object. | ||
| 180 | |||
| 181 | $catalog = $cat->Catalog(); | ||
| 182 | $cat->Catalog(new Astro::Catalog(...)); | ||
| 183 | |||
| 184 | =cut | ||
| 185 | |||
| 186 | sub Catalog { | ||
| 187 | my $self = shift; | ||
| 188 | if (@_) { | ||
| 189 | my $cat = shift; | ||
| 190 | if (UNIVERSAL::isa($cat,'Astro::Catalog')) { | ||
| 191 | $self->{Catalog} = $cat; | ||
| 192 | } | ||
| 193 | else { | ||
| 194 | croak "Tk::AstroCatalog: Catalog must be of type Astro::Catalog \n"; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | return $self->{Catalog}; | ||
| 198 | } | ||
| 199 | |||
| 200 | =item AddCommand | ||
| 201 | |||
| 202 | Returns and sets the AddCommand callback code for the catalog | ||
| 203 | |||
| 204 | $addCommand = $cat->AddCommand(); | ||
| 205 | $cat->AddCommand($addCommand); | ||
| 206 | |||
| 207 | =cut | ||
| 208 | |||
| 209 | sub AddCommand { | ||
| 210 | my $self = shift; | ||
| 211 | if (@_) { | ||
| 212 | my $cmd = shift; | ||
| 213 | if (ref($cmd) eq 'CODE') { | ||
| 214 | $self->{AddCommand} = $cmd; | ||
| 215 | } | ||
| 216 | else { | ||
| 217 | croak "CatWin: AddCommand must be of type Code Ref \n"; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | return $self->{AddCommand}; | ||
| 221 | } | ||
| 222 | |||
| 223 | =item UpDate | ||
| 224 | |||
| 225 | Returns and sets the UpDate callback code for the catalog | ||
| 226 | |||
| 227 | $update = $cat->UpDate(); | ||
| 228 | $cat->UpDate($update); | ||
| 229 | |||
| 230 | Called whenever the contents of the text widget are redisplayed. | ||
| 231 | The first argument will be the current object. | ||
| 232 | |||
| 233 | =cut | ||
| 234 | |||
| 235 | sub UpDate { | ||
| 236 | my $self = shift; | ||
| 237 | if (@_) { | ||
| 238 | my $cmd = shift; | ||
| 239 | if (ref($cmd) eq 'CODE') { | ||
| 240 | $self->{upDate} = $cmd; | ||
| 241 | } | ||
| 242 | else { | ||
| 243 | croak "CatWin: upDate must be of type Code Ref \n"; | ||
| 244 | } | ||
| 245 | } | ||
| 246 | return $self->{upDate}; | ||
| 247 | } | ||
| 248 | |||
| 249 | =item Reset | ||
| 250 | |||
| 251 | Returns and sets the onDestroy callback code for the catalog | ||
| 252 | |||
| 253 | $reset = $cat->Reset(); | ||
| 254 | $cat->Reset($reset); | ||
| 255 | |||
| 256 | =cut | ||
| 257 | |||
| 258 | sub Reset { | ||
| 259 | my $self = shift; | ||
| 260 | if (@_) { | ||
| 261 | my $cmd = shift; | ||
| 262 | if (ref($cmd) eq 'CODE') { | ||
| 263 | $self->{Reset} = $cmd; | ||
| 264 | } | ||
| 265 | else { | ||
| 266 | croak "CatWin: Reset must be of type Code Ref \n"; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | return $self->{Reset}; | ||
| 270 | } | ||
| 271 | |||
| 272 | =item Toplevel | ||
| 273 | |||
| 274 | Returns and sets the name of the Toplevel | ||
| 275 | |||
| 276 | $toplevel = $cat->Toplevel(); | ||
| 277 | $cat->Toplevel($top); | ||
| 278 | |||
| 279 | =cut | ||
| 280 | |||
| 281 | sub Toplevel { | ||
| 282 | my $self = shift; | ||
| 283 | if (@_) { | ||
| 284 | $self->{Toplevel} = shift; | ||
| 285 | } | ||
| 286 | return $self->{Toplevel}; | ||
| 287 | } | ||
| 288 | |||
| 289 | =item Transient | ||
| 290 | |||
| 291 | Returns and sets whether the widget should be destroyed after the | ||
| 292 | next Add. | ||
| 293 | |||
| 294 | $toplevel = $cat->Transient(); | ||
| 295 | $cat->Transient($top); | ||
| 296 | |||
| 297 | =cut | ||
| 298 | |||
| 299 | sub Transient { | ||
| 300 | my $self = shift; | ||
| 301 | if (@_) { | ||
| 302 | $self->{Transient} = shift; | ||
| 303 | } | ||
| 304 | return $self->{Transient}; | ||
| 305 | } | ||
| 306 | |||
| 307 | =item Text | ||
| 308 | |||
| 309 | Returns and sets the name of the Text | ||
| 310 | |||
| 311 | $text = $cat->Text(); | ||
| 312 | $cat->Text($text); | ||
| 313 | |||
| 314 | =cut | ||
| 315 | |||
| 316 | sub Text { | ||
| 317 | my $self = shift; | ||
| 318 | if (@_) { | ||
| 319 | my $cat = shift; | ||
| 320 | if (UNIVERSAL::isa($cat,'Tk::Frame')) { | ||
| 321 | $self->{Text} = $cat; | ||
| 322 | } | ||
| 323 | else { | ||
| 324 | croak "CatWin: Text widget must be of type Tk::Frame \n"; | ||
| 325 | } | ||
| 326 | } | ||
| 327 | return $self->{Text}; | ||
| 328 | } | ||
| 329 | |||
| 330 | =item RefLabel | ||
| 331 | |||
| 332 | Configure the text displayed in the reference label widget. | ||
| 333 | Usually a summary of the reference position. | ||
| 334 | |||
| 335 | $self->RefLabel | ||
| 336 | |||
| 337 | Returns a reference to a scalar that can be used to associate | ||
| 338 | the value with a widget. | ||
| 339 | |||
| 340 | =cut | ||
| 341 | |||
| 342 | sub RefLabel { | ||
| 343 | my $self = shift; | ||
| 344 | if (@_) { | ||
| 345 | $self->{RefLabel} = shift; | ||
| 346 | } | ||
| 347 | return \$self->{RefLabel}; | ||
| 348 | } | ||
| 349 | |||
| 350 | =item CatClass | ||
| 351 | |||
| 352 | Returns and sets the name of the CatClass | ||
| 353 | |||
| 354 | $class = $cat->CatClass(); | ||
| 355 | $cat->CatClass($class); | ||
| 356 | |||
| 357 | =cut | ||
| 358 | |||
| 359 | sub CatClass { | ||
| 360 | my $self = shift; | ||
| 361 | if (@_) { | ||
| 362 | $self->{CatClass} = shift; | ||
| 363 | } | ||
| 364 | return $self->{CatClass}; | ||
| 365 | } | ||
| 366 | |||
| 367 | =item Selected | ||
| 368 | |||
| 369 | Returns the Selected array or the indexed value of this array | ||
| 370 | |||
| 371 | @selected = $cat->Selected(); | ||
| 372 | $value = $cat->Selected($index); | ||
| 373 | |||
| 374 | =cut | ||
| 375 | |||
| 376 | sub Selected { | ||
| 377 | my $self = shift; | ||
| 378 | if (@_) { | ||
| 379 | my $index = shift; | ||
| 380 | if (@_) { | ||
| 381 | $self->{Selected}->[$index] = shift; | ||
| 382 | } | ||
| 383 | return $self->{Selected}->[$index]; | ||
| 384 | } | ||
| 385 | return $self->{Selected}; | ||
| 386 | } | ||
| 387 | |||
| 388 | =item file | ||
| 389 | |||
| 390 | Returns and sets the File name | ||
| 391 | |||
| 392 | $file = $cat->file(); | ||
| 393 | $cat->file($filename); | ||
| 394 | |||
| 395 | =cut | ||
| 396 | |||
| 397 | sub file { | ||
| 398 | my $self = shift; | ||
| 399 | if (@_) { | ||
| 400 | $self->{File} = shift; | ||
| 401 | } | ||
| 402 | return $self->{File}; | ||
| 403 | } | ||
| 404 | |||
| 405 | =item makeCatalog | ||
| 406 | |||
| 407 | makeCatalog creates a window that displays the | ||
| 408 | contents of a catalog and allows the user to select as | ||
| 409 | many entries as the user wishes. | ||
| 410 | |||
| 411 | $catalog = $cat->makeCatalog(); | ||
| 412 | $catalog = $cat->makeCatalog($selected); | ||
| 413 | |||
| 414 | =cut | ||
| 415 | |||
| 416 | sub makeCatalog { | ||
| 417 | my $self = shift; | ||
| 418 | my $selected = $self->{Selected}; | ||
| 419 | my $Top = $self->Toplevel; | ||
| 420 | $Top->geometry('+600+437'); | ||
| 421 | $Top->title('Source Plot: Catalog Window'); | ||
| 422 | $Top->resizable(1, 1); | ||
| 423 | |||
| 424 | print "made the catalog window\n" if $locateBug; | ||
| 425 | |||
| 426 | my @Sources; | ||
| 427 | my $topFrame = $Top->Frame( | ||
| 428 | -relief => 'groove', | ||
| 429 | -borderwidth => 2, | ||
| 430 | -width => 50 | ||
| 431 | )->grid(-column => 0, -row => 0, -padx => 3, -pady => 3, -sticky => 'nsew'); | ||
| 432 | |||
| 433 | # create the header | ||
| 434 | my $headFrame = $topFrame->Frame( | ||
| 435 | -relief => 'flat', | ||
| 436 | -borderwidth => 2 | ||
| 437 | )->grid(-row => 0, -sticky => 'nsew'); | ||
| 438 | my $head = $topFrame->Text( | ||
| 439 | -wrap => 'none', | ||
| 440 | -relief => 'flat', | ||
| 441 | -foreground => 'midnightblue', | ||
| 442 | -width => 90 + $self->{'CustomWidth'}, | ||
| 443 | -height => 1, | ||
| 444 | -font => '-*-Courier-Medium-R-Normal--*-120-*-*-*-*-*-*', | ||
| 445 | -takefocus => 0 | ||
| 446 | )->grid(-sticky => 'nsew', -row => 0); | ||
| 447 | my $title = sprintf "%5s %-16s %-12s %-13s %-4s %-3s %-3s %-5s %s%s", | ||
| 448 | 'Index', 'Name', 'Ra', 'Dec', 'Epoc', 'Az', 'El', 'Dist', | ||
| 449 | $self->{'CustomHeadings'}, "Comment"; | ||
| 450 | $head->insert('end', $title); | ||
| 451 | $head->configure(-state => 'disabled'); | ||
| 452 | |||
| 453 | print "just about to make the scrollable text\n" if $locateBug; | ||
| 454 | |||
| 455 | # create the text scrollable window | ||
| 456 | my $T = $topFrame->Scrolled('Text', | ||
| 457 | -scrollbars => 'e', | ||
| 458 | -wrap => 'none', | ||
| 459 | -width => 100 + $self->{'CustomWidth'}, | ||
| 460 | -height => 15, | ||
| 461 | -font => '-*-Courier-Medium-R-Normal--*-120-*-*-*-*-*-*', | ||
| 462 | -setgrid => 1, | ||
| 463 | )->grid(-sticky => 'nsew'); | ||
| 464 | $T->bindtags(qw/widget_demo/); # remove all bindings but dummy "widget_demo" | ||
| 465 | $self->Text($T); | ||
| 466 | print "just before creating the done button\n" if $locateBug; | ||
| 467 | |||
| 468 | # KLUGE with a global reference label for now | ||
| 469 | my $RefLabel = $topFrame->Label( | ||
| 470 | -textvariable => $self->RefLabel, -width => 64, | ||
| 471 | )->grid(-sticky=>'nsew',-row=>2); | ||
| 472 | |||
| 473 | $topFrame->gridRowconfigure(1, -weight => 1); | ||
| 474 | $topFrame->gridColumnconfigure(0, -weight => 1); | ||
| 475 | |||
| 476 | # Create button frame | ||
| 477 | my $buttonF2 = $Top->Frame->grid(-column => 0, -row => 1, -pady => 3); | ||
| 478 | my $buttonF = $Top->Frame->grid(-column => 0, -row => 2, -pady => 3); | ||
| 479 | |||
| 480 | # create the Done button if we are not transient | ||
| 481 | unless ($self->Transient) { | ||
| 482 | my $dBut = $buttonF->Button( | ||
| 483 | -text => 'Done', | ||
| 484 | -command => sub{ $self->destroy } | ||
| 485 | )->pack(-side=>'right'); | ||
| 486 | } | ||
| 487 | |||
| 488 | # create the Add button | ||
| 489 | my $addBut = $buttonF->Button( | ||
| 490 | -text=>'Add', | ||
| 491 | -relief => 'raised', | ||
| 492 | -width => 7, | ||
| 493 | -command => sub { | ||
| 494 | my $callback = $self->AddCommand; | ||
| 495 | my $selected = $self->Selected; | ||
| 496 | # turn off tags | ||
| 497 | foreach my $one (@$selected) { | ||
| 498 | # KLUGE source does not have index attribute | ||
| 499 | $T->tag('configure', 'd' . $one->{index}, -foreground => 'blue'); | ||
| 500 | } | ||
| 501 | $callback->($selected); | ||
| 502 | |||
| 503 | if ($self->Transient) { | ||
| 504 | # game over (should be a sub) | ||
| 505 | $self->destroy; | ||
| 506 | } | ||
| 507 | })->pack(-side => 'right', -padx => 20); | ||
| 508 | |||
| 509 | # create the Search button | ||
| 510 | my $searchBut; | ||
| 511 | $searchBut = $buttonF->Button( | ||
| 512 | -text => 'Search', | ||
| 513 | -relief => 'raised', | ||
| 514 | -width => 7, | ||
| 515 | -command => sub { | ||
| 516 | $searchBut->configure(-state => 'disabled'); | ||
| 517 | $self->getSource($self->Toplevel->Toplevel,$searchBut); | ||
| 518 | })->pack(-side => 'right'); | ||
| 519 | |||
| 520 | # declared for the catalog file | ||
| 521 | my $catEnt; | ||
| 522 | |||
| 523 | # create the Rescan button | ||
| 524 | my $rescanBut = $buttonF->Button( | ||
| 525 | -text=>'Rescan', | ||
| 526 | -relief => 'raised', | ||
| 527 | -width => 7, | ||
| 528 | -command => sub { | ||
| 529 | $self->file($catEnt->get); | ||
| 530 | # reset current array to original list | ||
| 531 | $self->Catalog->reset_list; | ||
| 532 | $self->fillWithSourceList ('full'); | ||
| 533 | })->pack(-side => 'right', -padx => '20'); | ||
| 534 | |||
| 535 | # create the Sort menu | ||
| 536 | my $sortmenu = $buttonF->Menubutton(-text => 'Sort by', -relief => 'raised', -width => 7); | ||
| 537 | $sortmenu->command(-label => 'Unsorted', -command => sub { | ||
| 538 | $self->Catalog->sort_catalog('unsorted'); | ||
| 539 | $self->fillWithSourceList('full'); | ||
| 540 | }); | ||
| 541 | $sortmenu->command(-label => 'Id', -command => sub { | ||
| 542 | $self->Catalog->sort_catalog('id'); | ||
| 543 | $self->fillWithSourceList('full'); | ||
| 544 | }); | ||
| 545 | $sortmenu->command(-label => 'Ra', -command => sub { | ||
| 546 | $self->Catalog->sort_catalog('ra'); | ||
| 547 | $self->fillWithSourceList('full'); | ||
| 548 | }); | ||
| 549 | $sortmenu->command(-label => 'Dec', -command => sub { | ||
| 550 | $self->Catalog->sort_catalog('dec'); | ||
| 551 | $self->fillWithSourceList('full'); | ||
| 552 | }); | ||
| 553 | $sortmenu->command(-label => 'Az', -command => sub { | ||
| 554 | $self->Catalog->sort_catalog('az'); | ||
| 555 | $self->fillWithSourceList('full'); | ||
| 556 | }); | ||
| 557 | $sortmenu->command(-label => 'El', -command => sub { | ||
| 558 | $self->Catalog->sort_catalog('el'); | ||
| 559 | $self->fillWithSourceList('full'); | ||
| 560 | }); | ||
| 561 | # add sort by distance if we have a reference position | ||
| 562 | if ($self->Catalog->reference) { | ||
| 563 | $sortmenu->command(-label => 'Distance', -command => sub { | ||
| 564 | $self->Catalog->sort_catalog('distance'); | ||
| 565 | $self->fillWithSourceList('full'); | ||
| 566 | }); | ||
| 567 | $sortmenu->command(-label => 'Distance in Az', -command => sub { | ||
| 568 | $self->Catalog->sort_catalog('distance_az'); | ||
| 569 | $self->fillWithSourceList('full'); | ||
| 570 | }); | ||
| 571 | } | ||
| 572 | |||
| 573 | $sortmenu->pack(-side => 'right', -padx => '20'); | ||
| 574 | |||
| 575 | # create the catalog menu button | ||
| 576 | my $catB = $buttonF2->Menubutton(-text => 'Catalogs', -relief => 'raised', -width => 8); | ||
| 577 | $catB->command(-label => 'Default Catalog', -command => sub { | ||
| 578 | $self->file('default'); | ||
| 579 | $catEnt->delete('0', 'end'); | ||
| 580 | $catEnt->insert(0, $self->file); | ||
| 581 | # No filename for default | ||
| 582 | $self->Catalog($self->CatClass->new( | ||
| 583 | Format => $FORMAT, | ||
| 584 | ReadOpt => $FORMAT_OPT, | ||
| 585 | )); | ||
| 586 | $self->fillWithSourceList('full'); | ||
| 587 | }); | ||
| 588 | $catB->command(-label => 'File Catalog', -command => sub { | ||
| 589 | my $dir; | ||
| 590 | chomp($dir = `pwd`); | ||
| 591 | my $win = $Top->FileSelect(-directory => $dir);; | ||
| 592 | my $file = $win->Show; | ||
| 593 | if (defined $file && $file ne '') { | ||
| 594 | $catEnt->delete('0', 'end'); | ||
| 595 | $catEnt->insert('0', $file); | ||
| 596 | |||
| 597 | # Get the current catalog properties [should be a sub] | ||
| 598 | my $oldcat = $self->Catalog; | ||
| 599 | my ($refc, $canobs); | ||
| 600 | if (defined $oldcat) { | ||
| 601 | $refc = $oldcat->reference; | ||
| 602 | $canobs = $oldcat->auto_filter_observability; | ||
| 603 | } | ||
| 604 | |||
| 605 | $self->file($file); | ||
| 606 | $self->Catalog($self->CatClass->new( | ||
| 607 | File =>$self->file, | ||
| 608 | Format => $FORMAT, | ||
| 609 | ReadOpt => $FORMAT_OPT, | ||
| 610 | )); | ||
| 611 | |||
| 612 | # Propagate previous info | ||
| 613 | $self->Catalog->reference($refc) if defined $refc; | ||
| 614 | $self->Catalog->auto_filter_observability($canobs); | ||
| 615 | $self->Catalog->reset_list; | ||
| 616 | |||
| 617 | $self->fillWithSourceList('full'); | ||
| 618 | } | ||
| 619 | }); | ||
| 620 | $catB->pack(-side => 'left', -padx => 10); | ||
| 621 | |||
| 622 | # Create the catalog file label | ||
| 623 | $buttonF2->Label( | ||
| 624 | -text => "Catalog file:", | ||
| 625 | )->pack(-side => 'left'); | ||
| 626 | $catEnt = $buttonF2->Entry( | ||
| 627 | -relief => 'sunken', | ||
| 628 | -width => 37 | ||
| 629 | )->pack(-side => 'left', -padx => 10); | ||
| 630 | $catEnt->bind('<KeyPress-Return>' => sub { | ||
| 631 | # Get the current catalog properties [should be a sub] | ||
| 632 | my $oldcat = $self->Catalog; | ||
| 633 | my ($refc, $canobs); | ||
| 634 | if (defined $oldcat) { | ||
| 635 | $refc = $oldcat->reference; | ||
| 636 | $canobs = $oldcat->auto_filter_observability; | ||
| 637 | } | ||
| 638 | |||
| 639 | $self->file($catEnt->get); | ||
| 640 | if ($catEnt->get eq 'default') { | ||
| 641 | $self->Catalog($self->CatClass->new( | ||
| 642 | Format => $FORMAT, | ||
| 643 | ReadOpt => $FORMAT_OPT, | ||
| 644 | )); | ||
| 645 | } | ||
| 646 | else { | ||
| 647 | $self->Catalog($self->CatClass->new( | ||
| 648 | File => $self->file, | ||
| 649 | Format => $FORMAT, | ||
| 650 | ReadOpt => $FORMAT_OPT, | ||
| 651 | )); | ||
| 652 | } | ||
| 653 | # Propagate previous info | ||
| 654 | $self->Catalog->reference($refc) if defined $refc; | ||
| 655 | $self->Catalog->auto_filter_observability($canobs); | ||
| 656 | $self->Catalog->reset_list; | ||
| 657 | |||
| 658 | $self->fillWithSourceList('full'); | ||
| 659 | }); | ||
| 660 | $catEnt->insert(0, $self->file); | ||
| 661 | |||
| 662 | $Top->gridRowconfigure(0, -weight => 1); | ||
| 663 | $Top->gridColumnconfigure(0, -weight => 1); | ||
| 664 | |||
| 665 | print "made it past all the buttons and just about to fill...\n" if $locateBug; | ||
| 666 | # if we do not have a catalog yet create one | ||
| 667 | unless ($self->Catalog) { | ||
| 668 | $self->file($catEnt->get); | ||
| 669 | $self->Catalog($self->CatClass->new( | ||
| 670 | File => $self->file, | ||
| 671 | Format => $FORMAT, | ||
| 672 | ReadOpt => $FORMAT_OPT, | ||
| 673 | )); | ||
| 674 | } | ||
| 675 | $self->fillWithSourceList('full'); | ||
| 676 | |||
| 677 | return $self; | ||
| 678 | } | ||
| 679 | |||
| 680 | =item destroy | ||
| 681 | |||
| 682 | Remove the widget from display. Leaves calling the | ||
| 683 | Reset handler to the DESTROY method. | ||
| 684 | |||
| 685 | =cut | ||
| 686 | |||
| 687 | sub destroy { | ||
| 688 | my $self = shift; | ||
| 689 | my $Top = $self->Toplevel; | ||
| 690 | $Top->destroy() if defined $Top && Exists($Top); | ||
| 691 | } | ||
| 692 | |||
| 693 | =item DESTROY | ||
| 694 | |||
| 695 | Object destructor. Triggers when the object is destroyed. | ||
| 696 | Guarantees to destroy the Toplevel widget and does trigger | ||
| 697 | the onDestroy callback. | ||
| 698 | |||
| 699 | =cut | ||
| 700 | |||
| 701 | sub DESTROY { | ||
| 702 | my $self = shift; | ||
| 703 | my $callback = $self->Reset; | ||
| 704 | $callback->() if defined $callback; | ||
| 705 | my $Top = $self->Toplevel; | ||
| 706 | $Top->destroy() if defined $Top && Exists($Top); | ||
| 707 | } | ||
| 708 | |||
| 709 | =item fillWithSourceList | ||
| 710 | |||
| 711 | Fills a text widget with the list of current sources | ||
| 712 | |||
| 713 | $cat->fillWithSourceList(); | ||
| 714 | $cat->fillWithSourceList($text, $selected, $task, $index); | ||
| 715 | $cat->fillWithSourceList($text, $selected, $task); | ||
| 716 | $cat->fillWithSourceList($text, $selected); | ||
| 717 | |||
| 718 | Also triggers the UpDate method. | ||
| 719 | |||
| 720 | =cut | ||
| 721 | |||
| 722 | sub fillWithSourceList { | ||
| 723 | my (@bold, @normal); | ||
| 724 | my $self = shift; | ||
| 725 | my $T = $self->Text; | ||
| 726 | my $selected = $self->Selected; | ||
| 727 | my $task = shift; | ||
| 728 | my $index = shift; | ||
| 729 | my @entered = (); | ||
| 730 | my ($line, $itag); | ||
| 731 | |||
| 732 | # Retrieve the objects | ||
| 733 | # forcing the reference time | ||
| 734 | $self->Catalog->force_ref_time; | ||
| 735 | my @stars = $self->Catalog->stars; | ||
| 736 | my @sources = map {$_->coords} @stars; | ||
| 737 | |||
| 738 | # Enable infobox for access | ||
| 739 | $T->configure(-state => 'normal'); | ||
| 740 | |||
| 741 | # Clear the existing widgets | ||
| 742 | if (defined $task && $task eq 'full') { | ||
| 743 | $T->delete('1.0', 'end'); | ||
| 744 | foreach my $source (@sources) { | ||
| 745 | # KLUGE source does not have index attribute | ||
| 746 | if (exists $source->{index} && defined $source->{index}) { | ||
| 747 | $T->tagDelete('d' . $source->{index}); | ||
| 748 | } | ||
| 749 | } | ||
| 750 | |||
| 751 | # And clear the current selection | ||
| 752 | @$selected = (); | ||
| 753 | } | ||
| 754 | |||
| 755 | # Set up display styles | ||
| 756 | if ($T->depth > 1) { | ||
| 757 | @bold = (-background => "#eeeeee", -relief => 'raised', -borderwidth => 1); | ||
| 758 | @normal = (-background => undef, -relief => 'flat'); | ||
| 759 | } | ||
| 760 | else { | ||
| 761 | @bold = (-foreground => 'white', -background => 'black'); | ||
| 762 | @normal = (-foreground => undef, -background => undef); | ||
| 763 | } | ||
| 764 | $T->tag(qw/configure normal -foreground blue/); | ||
| 765 | $T->tag(qw/configure inactive -foreground black/); | ||
| 766 | $T->tag(qw/configure selected -foreground red/); | ||
| 767 | foreach (@COLOR_LIST) { | ||
| 768 | $T->tag('configure', $_, -foreground => $_); | ||
| 769 | } | ||
| 770 | |||
| 771 | # Get a reference coordinate from the object | ||
| 772 | my $ref = $self->Catalog->reference; | ||
| 773 | |||
| 774 | # write the label | ||
| 775 | if ($ref) { | ||
| 776 | my ($az, $el) = $ref->azel(); | ||
| 777 | my $summary = sprintf("%-15s Az: %3.0f El: %3.0f", | ||
| 778 | $ref->name, $az->degrees, $el->degrees); | ||
| 779 | $self->RefLabel("Reference position: $summary"); | ||
| 780 | } | ||
| 781 | else { | ||
| 782 | # blank it | ||
| 783 | $self->RefLabel(''); | ||
| 784 | } | ||
| 785 | |||
| 786 | # Insert the current values | ||
| 787 | if (defined $task && $task eq 'full') { | ||
| 788 | my $len = @sources; | ||
| 789 | for ($index = 0; $index < $len; $index ++) { | ||
| 790 | my $source = $sources[$index]; | ||
| 791 | # KLUGE source does not have index attribute | ||
| 792 | $source->{index} = $index; | ||
| 793 | # KLUGE - source summary should add az, el and we should | ||
| 794 | # add distance | ||
| 795 | my $distance = " --- "; | ||
| 796 | if ($ref) { | ||
| 797 | my $d = $ref->distance($source); | ||
| 798 | if (defined $d) { | ||
| 799 | $distance = sprintf("%5.0f", $d->degrees); | ||
| 800 | } | ||
| 801 | else { | ||
| 802 | $distance = " Inf"; | ||
| 803 | } | ||
| 804 | } | ||
| 805 | my $custom = ''; | ||
| 806 | if ($self->{'CustomColumns'}) { | ||
| 807 | $custom = join(' ', map {$_->{'generator'}->($stars[$index])} | ||
| 808 | @{$self->{'CustomColumns'}}) . ' '; | ||
| 809 | } | ||
| 810 | $line = sprintf("%-4d %s %3.0f %3.0f %s %s%s", | ||
| 811 | $index, | ||
| 812 | $source->summary(), | ||
| 813 | $source->az(format=>'d'), | ||
| 814 | $source->el(format=>'d'), | ||
| 815 | $distance, | ||
| 816 | $custom, | ||
| 817 | $source->comment | ||
| 818 | ); | ||
| 819 | if ($self->isWithin ($source, @$selected)) { | ||
| 820 | $self->inswt("$line\n","d$index",'selected'); | ||
| 821 | } | ||
| 822 | else { | ||
| 823 | # KLUGE - source does not really have active or color attributes | ||
| 824 | # KLUGE2 - "active" is never set! | ||
| 825 | if ($source->{active}) { | ||
| 826 | if ($source->{color} ne '') { | ||
| 827 | $self->inswt("$line\n", "d$index", $source->{color}); | ||
| 828 | } | ||
| 829 | else { | ||
| 830 | $self->inswt("$line\n", "d$index", 'normal'); | ||
| 831 | } | ||
| 832 | } | ||
| 833 | else { | ||
| 834 | $self->inswt("$line\n", "d$index", 'inactive'); | ||
| 835 | } | ||
| 836 | } | ||
| 837 | } | ||
| 838 | |||
| 839 | $len = @sources; | ||
| 840 | for ($itag = 0; $itag < $len; $itag ++) { | ||
| 841 | my $dtag = "d$itag"; | ||
| 842 | $T->tag('bind', $dtag, '<Any-Enter>' => sub { | ||
| 843 | shift->tag('configure', $dtag, @bold); | ||
| 844 | }); | ||
| 845 | $T->tag('bind', $dtag, '<Any-Leave>' => sub { | ||
| 846 | shift->tag('configure', $dtag, @normal); | ||
| 847 | }); | ||
| 848 | $T->tag('bind', $dtag, '<ButtonRelease-1>' => sub { | ||
| 849 | unless ($BUSY) { | ||
| 850 | unless ($self->isWithin($sources[substr($dtag, 1, 99)], @$selected) ) { | ||
| 851 | shift->tag('configure', $dtag, -foreground => 'red'); | ||
| 852 | push (@$selected, $sources[substr($dtag, 1, 99)]); | ||
| 853 | } | ||
| 854 | else { | ||
| 855 | # KLUGE - no color support in class | ||
| 856 | if ($sources[substr($dtag, 1, 99)]->{color} ne '') { | ||
| 857 | shift->tag('configure', $dtag, -foreground => $sources[substr($dtag, 1, 99)]->color()); | ||
| 858 | } | ||
| 859 | else { | ||
| 860 | shift->tag('configure', $dtag, -foreground => 'blue'); | ||
| 861 | } | ||
| 862 | $self->remove($sources[substr($dtag, 1, 99)], $selected); | ||
| 863 | } | ||
| 864 | } | ||
| 865 | }); | ||
| 866 | $T->tag('bind', $dtag, '<Double-1>' => sub { | ||
| 867 | $BUSY = 1; | ||
| 868 | my $source = $sources[substr($dtag, 1, 99)]; | ||
| 869 | push (@$selected, $source); | ||
| 870 | my $T = shift; | ||
| 871 | my $callback = $self->AddCommand; | ||
| 872 | # turn off tags | ||
| 873 | foreach $source (@$selected) { | ||
| 874 | # KLUGE source does not have index attribute | ||
| 875 | $T->tag('configure', 'd' . $source->{index}, -foreground => 'blue'); | ||
| 876 | } | ||
| 877 | print " ref(@$selected) is selected \n" if $locateBug; | ||
| 878 | my @array = [1..2]; | ||
| 879 | $callback->($selected); | ||
| 880 | $BUSY = 0; | ||
| 881 | @$selected = (); | ||
| 882 | |||
| 883 | $self->destroy if $self->Transient; | ||
| 884 | }); | ||
| 885 | } | ||
| 886 | } | ||
| 887 | |||
| 888 | $T->mark(qw/set insert 1.0/); | ||
| 889 | |||
| 890 | # Disable access to infobox | ||
| 891 | $T->configure(-state => 'disabled'); | ||
| 892 | |||
| 893 | # Trigger an update callback | ||
| 894 | $self->UpDate->($self); | ||
| 895 | } | ||
| 896 | |||
| 897 | =item color | ||
| 898 | |||
| 899 | Returns a color from @COLOR_LIST and increments the latter's index | ||
| 900 | |||
| 901 | $color = $cat->color(); | ||
| 902 | |||
| 903 | =cut | ||
| 904 | |||
| 905 | sub getColor { | ||
| 906 | my $color = $COLOR_LIST[$COLOR_INDEX]; | ||
| 907 | my $len = @COLOR_LIST; | ||
| 908 | $COLOR_INDEX++; | ||
| 909 | $COLOR_INDEX = $COLOR_INDEX % $len; | ||
| 910 | return $color; | ||
| 911 | } | ||
| 912 | |||
| 913 | =item error | ||
| 914 | |||
| 915 | Displays an error message in Tk | ||
| 916 | |||
| 917 | $cat->error('Error message'); | ||
| 918 | |||
| 919 | =cut | ||
| 920 | |||
| 921 | sub error { | ||
| 922 | my $MW = shift; | ||
| 923 | my $errWin = $MW->Toplevel(-borderwidth => 10); | ||
| 924 | $errWin->title('Observation Log Error!'); | ||
| 925 | $errWin->resizable(0,0); | ||
| 926 | $errWin->Button( | ||
| 927 | -text => 'Ok', | ||
| 928 | -command => sub { | ||
| 929 | destroy $errWin; | ||
| 930 | })->pack(-side=>'bottom'); | ||
| 931 | my $message = shift; | ||
| 932 | $errWin->Label ( | ||
| 933 | -text => "\nError!\n\n " . $message . " \n", | ||
| 934 | -relief => 'sunken' | ||
| 935 | )->pack(-side => 'bottom', -pady => 10); | ||
| 936 | $errWin->title(shift) if @_; | ||
| 937 | $MW->update; | ||
| 938 | $errWin->grab; | ||
| 939 | } | ||
| 940 | |||
| 941 | =item inswt | ||
| 942 | |||
| 943 | inswt inserts text into a given text widget and applies | ||
| 944 | one or more tags to that text. | ||
| 945 | |||
| 946 | Parameters: | ||
| 947 | $text - Text to insert (it's inserted at the "insert" mark) | ||
| 948 | $args - One or more tags to apply to text. If this is empty | ||
| 949 | then all tags are removed from the text. | ||
| 950 | |||
| 951 | $cat->inswt($text, $args); | ||
| 952 | |||
| 953 | =cut | ||
| 954 | |||
| 955 | sub inswt { | ||
| 956 | my $self = shift; | ||
| 957 | my $w = $self->Text; | ||
| 958 | my ($text, @args) = @_; | ||
| 959 | my $start = $w->index('insert'); | ||
| 960 | |||
| 961 | $w->insert('insert', $text); | ||
| 962 | foreach my $tag ($w->tag('names', $start)) { | ||
| 963 | $w->tag('remove', $tag, $start, 'insert'); | ||
| 964 | } | ||
| 965 | foreach my $i (@args) { | ||
| 966 | $w->tag('add', $i, $start, 'insert'); | ||
| 967 | } | ||
| 968 | } | ||
| 969 | |||
| 970 | =item getSource | ||
| 971 | |||
| 972 | getSource prompts the user to enter source coords and name | ||
| 973 | and filters the catalog based on the input provided. | ||
| 974 | |||
| 975 | Takes the new top level widget to use, and the search button | ||
| 976 | to be re-activated when this window closes. | ||
| 977 | |||
| 978 | $obj = $cat->getSource($toplevel, $search_button); | ||
| 979 | |||
| 980 | =cut | ||
| 981 | |||
| 982 | sub getSource { | ||
| 983 | my $self = shift; | ||
| 984 | my $Top = shift; | ||
| 985 | my $searchButton = shift; | ||
| 986 | my @Epocs = ('RJ', 'RB'); | ||
| 987 | my %distances = ( | ||
| 988 | '15 degrees' => 15.0, | ||
| 989 | '5 degrees' => 5.0, | ||
| 990 | '1 degree' => 1.0, | ||
| 991 | '30\'' => 0.5, | ||
| 992 | '15\'' => 0.25, | ||
| 993 | '5\'' => 1.0 / 12, | ||
| 994 | '1\'' => 1.0 / 60, | ||
| 995 | '30\'\'' => 0.5 / 60, | ||
| 996 | '15\'\'' => 0.25 / 60, | ||
| 997 | '5\'\'' => 1.0 / 12 / 60, | ||
| 998 | '1\'\'' => 1.0 / 3600, | ||
| 999 | ); | ||
| 1000 | my $name; | ||
| 1001 | |||
| 1002 | $Top->title('Source Plot'); | ||
| 1003 | $Top->resizable(0,0); | ||
| 1004 | my $topFrame = $Top->Frame( | ||
| 1005 | -relief => 'groove', -borderwidth => 2, -width => 50 | ||
| 1006 | )->pack(-padx => 10, -fill => 'x', -ipady => 10, -pady => 10); | ||
| 1007 | |||
| 1008 | $topFrame->Label ( | ||
| 1009 | -text => "Name:" | ||
| 1010 | )->grid(-column=>0, -row=>0); | ||
| 1011 | my $nameEnt = $topFrame->Entry( | ||
| 1012 | -relief=>'sunken', -width=>15 | ||
| 1013 | )->grid(-column => 1, -row => 0, -padx => 10, -pady => 3); | ||
| 1014 | |||
| 1015 | $topFrame->Label ( | ||
| 1016 | -text => "Ra:" | ||
| 1017 | )->grid(-column => 0, -row => 1); | ||
| 1018 | my $raEnt = $topFrame->Entry( | ||
| 1019 | -relief => 'sunken', -width => 15 | ||
| 1020 | )->grid(-column => 1, -row => 1, -padx => 10, -pady => 3); | ||
| 1021 | |||
| 1022 | $topFrame->Label ( | ||
| 1023 | -text => "Dec:" | ||
| 1024 | )->grid(-column => 0, -row => 2); | ||
| 1025 | my $decEnt = $topFrame->Entry( | ||
| 1026 | -relief => 'sunken', -width => 15 | ||
| 1027 | )->grid(-column => 1, -row => 2, -padx => 10, -pady => 3); | ||
| 1028 | |||
| 1029 | $topFrame->Label( | ||
| 1030 | -text => 'Distance:' | ||
| 1031 | )->grid(-column => 0, -row => 3); | ||
| 1032 | my $distEnt = '1\''; | ||
| 1033 | my $distB = $topFrame->Menubutton( | ||
| 1034 | -text => $distEnt, -relief => 'raised', -width => 15); | ||
| 1035 | foreach my $dist (sort {$distances{$b} <=> $distances{$a}} keys %distances) { | ||
| 1036 | $distB->command(-label => $dist, -command => sub { | ||
| 1037 | $distB->configure(-text => $dist); | ||
| 1038 | $distEnt = $dist; | ||
| 1039 | }); | ||
| 1040 | } | ||
| 1041 | $distB->grid(-column => 1, -row => 3, -padx => 10, -pady => 5, -sticky => 'w'); | ||
| 1042 | |||
| 1043 | $topFrame->Label ( | ||
| 1044 | -text => "Epoc:" | ||
| 1045 | )->grid(-column => 0, -row => 4, -padx => 5, -pady => 5); | ||
| 1046 | my $epocEnt = 'RJ'; | ||
| 1047 | my $epocB = $topFrame->Menubutton( | ||
| 1048 | -text => $epocEnt, -relief => 'raised', -width => 15); | ||
| 1049 | foreach $name (@Epocs) { | ||
| 1050 | $epocB->command(-label => $name, -command => sub { | ||
| 1051 | $epocB->configure(-text => $name); | ||
| 1052 | $epocEnt = $name; | ||
| 1053 | }); | ||
| 1054 | } | ||
| 1055 | $epocB->grid(-column => 1, -row => 4, -padx => 10, -pady => 5, -sticky => 'w'); | ||
| 1056 | |||
| 1057 | my $buttonF = $Top->Frame->pack(-padx => 10, -pady => 10); | ||
| 1058 | $buttonF->Button( | ||
| 1059 | -text => 'Ok', | ||
| 1060 | -command => sub { | ||
| 1061 | my $name = $nameEnt->get(); undef $name if $name eq ''; | ||
| 1062 | my $ra = $raEnt->get(); undef $ra if $ra eq ''; | ||
| 1063 | my $dec = $decEnt->get(); undef $dec if $dec eq ''; | ||
| 1064 | |||
| 1065 | my $dec_tol = pi * $distances{$distEnt} / 180; | ||
| 1066 | my $ra_tol = $dec_tol * 15; | ||
| 1067 | |||
| 1068 | # Filter by name if a name was specified. | ||
| 1069 | |||
| 1070 | $self->Catalog()->filter_by_id($name) if defined $name; | ||
| 1071 | |||
| 1072 | # Use Astro::Catalog's coordinate filter by distance | ||
| 1073 | # if possible. | ||
| 1074 | |||
| 1075 | if (defined $ra and defined $dec) { | ||
| 1076 | my $coord = new Astro::Coords(ra => $ra, dec => $dec, | ||
| 1077 | type => $epocEnt eq 'RB' ? 'B1950' : 'J2000'); | ||
| 1078 | |||
| 1079 | $self->Catalog()->filter_by_distance( | ||
| 1080 | $dec_tol, $coord); | ||
| 1081 | } | ||
| 1082 | elsif (defined $ra or defined $dec) { | ||
| 1083 | # Searching by RA or Dec alone isn't implemented | ||
| 1084 | # by Astro::Catalog, so use a callback filter. | ||
| 1085 | |||
| 1086 | $ra = Astro::Coords::Angle::Hour->new( | ||
| 1087 | $ra, range => '2PI')->radians() | ||
| 1088 | if defined $ra; | ||
| 1089 | $dec = Astro::Coords::Angle->new($dec)->radians() | ||
| 1090 | if defined $dec; | ||
| 1091 | |||
| 1092 | $self->Catalog()->filter_by_cb(sub { | ||
| 1093 | my $item = shift; | ||
| 1094 | my $coord = $item->coords(); | ||
| 1095 | my ($item_ra, $item_dec) = map {$_->radians()} | ||
| 1096 | $epocEnt eq 'RB' | ||
| 1097 | ? $coord->radec1950() | ||
| 1098 | : $coord->radec(); | ||
| 1099 | |||
| 1100 | return ((! defined $ra or | ||
| 1101 | abs($item_ra - $ra) <= $ra_tol) | ||
| 1102 | and (! defined $dec or | ||
| 1103 | abs($item_dec - $dec) <= $dec_tol)); | ||
| 1104 | }); | ||
| 1105 | } | ||
| 1106 | |||
| 1107 | $self->fillWithSourceList('full'); | ||
| 1108 | $Top->destroy(); | ||
| 1109 | })->pack(-side=>'right'); | ||
| 1110 | $buttonF->Button( | ||
| 1111 | -text => 'Cancel', | ||
| 1112 | -command => sub { | ||
| 1113 | $Top->destroy(); | ||
| 1114 | })->pack(-side=>'right'); | ||
| 1115 | |||
| 1116 | $Top->bind('<Destroy>', sub { | ||
| 1117 | my $widget = shift; | ||
| 1118 | return unless $widget == $Top; | ||
| 1119 | $searchButton->configure(-state => 'normal'); | ||
| 1120 | }); | ||
| 1121 | |||
| 1122 | $Top->update; | ||
| 1123 | $Top->grab; | ||
| 1124 | return; | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | =item isWithin | ||
| 1128 | |||
| 1129 | isWithin returns a boolean value as to whether an element is | ||
| 1130 | within the array specified. | ||
| 1131 | |||
| 1132 | $obj = $cat->isWithin($element, @array); | ||
| 1133 | |||
| 1134 | =cut | ||
| 1135 | |||
| 1136 | sub isWithin { | ||
| 1137 | my $self = shift; | ||
| 1138 | my $element = shift; | ||
| 1139 | my @array = @_; | ||
| 1140 | my $len = @array; | ||
| 1141 | foreach (@array) { | ||
| 1142 | # KLUGE - need an isEqual method rather than this. Will break | ||
| 1143 | # for none RA/Dec coordinates. Had to remove epoch check | ||
| 1144 | if ($element->name() eq $_->name() | ||
| 1145 | && $element->ra() eq $_->ra() | ||
| 1146 | && $element->dec() eq $_->dec()) { | ||
| 1147 | return 1; | ||
| 1148 | } | ||
| 1149 | } | ||
| 1150 | return 0; | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | =item remove | ||
| 1154 | |||
| 1155 | Removes the item passed from the array specified. | ||
| 1156 | |||
| 1157 | $obj = $cat->remove($element, @array); | ||
| 1158 | |||
| 1159 | =cut | ||
| 1160 | |||
| 1161 | sub remove { | ||
| 1162 | my $self = shift; | ||
| 1163 | my $element = shift; | ||
| 1164 | my $array = shift; | ||
| 1165 | my $len = @$array; | ||
| 1166 | my @temp; | ||
| 1167 | my $flag = 0; | ||
| 1168 | |||
| 1169 | # KLUGE - epcc no longer required | ||
| 1170 | for (my $index = 0; $index < $len; $index++) { | ||
| 1171 | if ($element->name() eq $$array[$index]->name() | ||
| 1172 | && $element->ra() eq $$array[$index]->ra() | ||
| 1173 | && $element->dec() eq $$array[$index]->dec()) { | ||
| 1174 | $flag = -1; | ||
| 1175 | } | ||
| 1176 | else { | ||
| 1177 | $temp[$index+$flag] = $$array[$index]; | ||
| 1178 | } | ||
| 1179 | } | ||
| 1180 | @$array = @temp; | ||
| 1181 | } | ||
| 1182 | |||
| 1183 | 1; | ||
| 1184 | |||
| 1185 | __END__ | ||