Astro-Catalog
view release on metacpan or search on metacpan
lib/Tk/AstroCatalog.pm view on Meta::CPAN
# Create button frame
my $buttonF2 = $Top->Frame->grid(-column => 0, -row => 1, -pady => 3);
my $buttonF = $Top->Frame->grid(-column => 0, -row => 2, -pady => 3);
# create the Done button if we are not transient
unless ($self->Transient) {
my $dBut = $buttonF->Button(
-text => 'Done',
-command => sub{ $self->destroy }
)->pack(-side=>'right');
}
# create the Add button
my $addBut = $buttonF->Button(
-text=>'Add',
-relief => 'raised',
-width => 7,
-command => sub {
my $callback = $self->AddCommand;
my $selected = $self->Selected;
# turn off tags
foreach my $one (@$selected) {
# KLUGE source does not have index attribute
$T->tag('configure', 'd' . $one->{index}, -foreground => 'blue');
}
$callback->($selected);
if ($self->Transient) {
# game over (should be a sub)
$self->destroy;
}
})->pack(-side => 'right', -padx => 20);
# create the Search button
my $searchBut;
$searchBut = $buttonF->Button(
-text => 'Search',
-relief => 'raised',
-width => 7,
-command => sub {
$searchBut->configure(-state => 'disabled');
$self->getSource($self->Toplevel->Toplevel,$searchBut);
})->pack(-side => 'right');
# declared for the catalog file
my $catEnt;
# create the Rescan button
my $rescanBut = $buttonF->Button(
-text=>'Rescan',
-relief => 'raised',
-width => 7,
-command => sub {
$self->file($catEnt->get);
# reset current array to original list
$self->Catalog->reset_list;
$self->fillWithSourceList ('full');
})->pack(-side => 'right', -padx => '20');
# create the Sort menu
my $sortmenu = $buttonF->Menubutton(-text => 'Sort by', -relief => 'raised', -width => 7);
$sortmenu->command(-label => 'Unsorted', -command => sub {
$self->Catalog->sort_catalog('unsorted');
$self->fillWithSourceList('full');
});
$sortmenu->command(-label => 'Id', -command => sub {
$self->Catalog->sort_catalog('id');
$self->fillWithSourceList('full');
});
$sortmenu->command(-label => 'Ra', -command => sub {
$self->Catalog->sort_catalog('ra');
$self->fillWithSourceList('full');
});
$sortmenu->command(-label => 'Dec', -command => sub {
$self->Catalog->sort_catalog('dec');
$self->fillWithSourceList('full');
});
$sortmenu->command(-label => 'Az', -command => sub {
$self->Catalog->sort_catalog('az');
$self->fillWithSourceList('full');
});
$sortmenu->command(-label => 'El', -command => sub {
$self->Catalog->sort_catalog('el');
$self->fillWithSourceList('full');
});
# add sort by distance if we have a reference position
if ($self->Catalog->reference) {
$sortmenu->command(-label => 'Distance', -command => sub {
$self->Catalog->sort_catalog('distance');
$self->fillWithSourceList('full');
});
$sortmenu->command(-label => 'Distance in Az', -command => sub {
$self->Catalog->sort_catalog('distance_az');
$self->fillWithSourceList('full');
});
}
$sortmenu->pack(-side => 'right', -padx => '20');
# create the catalog menu button
my $catB = $buttonF2->Menubutton(-text => 'Catalogs', -relief => 'raised', -width => 8);
$catB->command(-label => 'Default Catalog', -command => sub {
$self->file('default');
$catEnt->delete('0', 'end');
$catEnt->insert(0, $self->file);
# No filename for default
$self->Catalog($self->CatClass->new(
Format => $FORMAT,
ReadOpt => $FORMAT_OPT,
));
$self->fillWithSourceList('full');
});
$catB->command(-label => 'File Catalog', -command => sub {
my $dir;
chomp($dir = `pwd`);
my $win = $Top->FileSelect(-directory => $dir);;
my $file = $win->Show;
if (defined $file && $file ne '') {
$catEnt->delete('0', 'end');
$catEnt->insert('0', $file);
# Get the current catalog properties [should be a sub]
my $oldcat = $self->Catalog;
my ($refc, $canobs);
if (defined $oldcat) {
$refc = $oldcat->reference;
$canobs = $oldcat->auto_filter_observability;
}
$self->file($file);
$self->Catalog($self->CatClass->new(
File =>$self->file,
Format => $FORMAT,
ReadOpt => $FORMAT_OPT,
));
# Propagate previous info
$self->Catalog->reference($refc) if defined $refc;
$self->Catalog->auto_filter_observability($canobs);
$self->Catalog->reset_list;
$self->fillWithSourceList('full');
}
});
$catB->pack(-side => 'left', -padx => 10);
# Create the catalog file label
$buttonF2->Label(
-text => "Catalog file:",
)->pack(-side => 'left');
$catEnt = $buttonF2->Entry(
-relief => 'sunken',
-width => 37
)->pack(-side => 'left', -padx => 10);
$catEnt->bind('<KeyPress-Return>' => sub {
# Get the current catalog properties [should be a sub]
my $oldcat = $self->Catalog;
my ($refc, $canobs);
if (defined $oldcat) {
$refc = $oldcat->reference;
$canobs = $oldcat->auto_filter_observability;
lib/Tk/AstroCatalog.pm view on Meta::CPAN
and filters the catalog based on the input provided.
Takes the new top level widget to use, and the search button
to be re-activated when this window closes.
$obj = $cat->getSource($toplevel, $search_button);
=cut
sub getSource {
my $self = shift;
my $Top = shift;
my $searchButton = shift;
my @Epocs = ('RJ', 'RB');
my %distances = (
'15 degrees' => 15.0,
'5 degrees' => 5.0,
'1 degree' => 1.0,
'30\'' => 0.5,
'15\'' => 0.25,
'5\'' => 1.0 / 12,
'1\'' => 1.0 / 60,
'30\'\'' => 0.5 / 60,
'15\'\'' => 0.25 / 60,
'5\'\'' => 1.0 / 12 / 60,
'1\'\'' => 1.0 / 3600,
);
my $name;
$Top->title('Source Plot');
$Top->resizable(0,0);
my $topFrame = $Top->Frame(
-relief => 'groove', -borderwidth => 2, -width => 50
)->pack(-padx => 10, -fill => 'x', -ipady => 10, -pady => 10);
$topFrame->Label (
-text => "Name:"
)->grid(-column=>0, -row=>0);
my $nameEnt = $topFrame->Entry(
-relief=>'sunken', -width=>15
)->grid(-column => 1, -row => 0, -padx => 10, -pady => 3);
$topFrame->Label (
-text => "Ra:"
)->grid(-column => 0, -row => 1);
my $raEnt = $topFrame->Entry(
-relief => 'sunken', -width => 15
)->grid(-column => 1, -row => 1, -padx => 10, -pady => 3);
$topFrame->Label (
-text => "Dec:"
)->grid(-column => 0, -row => 2);
my $decEnt = $topFrame->Entry(
-relief => 'sunken', -width => 15
)->grid(-column => 1, -row => 2, -padx => 10, -pady => 3);
$topFrame->Label(
-text => 'Distance:'
)->grid(-column => 0, -row => 3);
my $distEnt = '1\'';
my $distB = $topFrame->Menubutton(
-text => $distEnt, -relief => 'raised', -width => 15);
foreach my $dist (sort {$distances{$b} <=> $distances{$a}} keys %distances) {
$distB->command(-label => $dist, -command => sub {
$distB->configure(-text => $dist);
$distEnt = $dist;
});
}
$distB->grid(-column => 1, -row => 3, -padx => 10, -pady => 5, -sticky => 'w');
$topFrame->Label (
-text => "Epoc:"
)->grid(-column => 0, -row => 4, -padx => 5, -pady => 5);
my $epocEnt = 'RJ';
my $epocB = $topFrame->Menubutton(
-text => $epocEnt, -relief => 'raised', -width => 15);
foreach $name (@Epocs) {
$epocB->command(-label => $name, -command => sub {
$epocB->configure(-text => $name);
$epocEnt = $name;
});
}
$epocB->grid(-column => 1, -row => 4, -padx => 10, -pady => 5, -sticky => 'w');
my $buttonF = $Top->Frame->pack(-padx => 10, -pady => 10);
$buttonF->Button(
-text => 'Ok',
-command => sub {
my $name = $nameEnt->get(); undef $name if $name eq '';
my $ra = $raEnt->get(); undef $ra if $ra eq '';
my $dec = $decEnt->get(); undef $dec if $dec eq '';
my $dec_tol = pi * $distances{$distEnt} / 180;
my $ra_tol = $dec_tol * 15;
# Filter by name if a name was specified.
$self->Catalog()->filter_by_id($name) if defined $name;
# Use Astro::Catalog's coordinate filter by distance
# if possible.
if (defined $ra and defined $dec) {
my $coord = new Astro::Coords(ra => $ra, dec => $dec,
type => $epocEnt eq 'RB' ? 'B1950' : 'J2000');
$self->Catalog()->filter_by_distance(
$dec_tol, $coord);
}
elsif (defined $ra or defined $dec) {
# Searching by RA or Dec alone isn't implemented
# by Astro::Catalog, so use a callback filter.
$ra = Astro::Coords::Angle::Hour->new(
$ra, range => '2PI')->radians()
if defined $ra;
$dec = Astro::Coords::Angle->new($dec)->radians()
if defined $dec;
$self->Catalog()->filter_by_cb(sub {
my $item = shift;
my $coord = $item->coords();
my ($item_ra, $item_dec) = map {$_->radians()}
$epocEnt eq 'RB'
? $coord->radec1950()
: $coord->radec();
return ((! defined $ra or
abs($item_ra - $ra) <= $ra_tol)
and (! defined $dec or
abs($item_dec - $dec) <= $dec_tol));
});
}
$self->fillWithSourceList('full');
( run in 0.851 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )