[BACK]Return to task.pl CVS log [TXT][DIR] Up to [tkperl]

File: [tkperl] / task.pl (download)

Revision 1.1, Mon Jan 28 19:10:09 2008 UTC (16 years, 2 months ago) by philip
Branch: MAIN
CVS Tags: HEAD


Remove dots from lat/lng

#! /usr/bin/perl -w

# Philip Plane
# philip@xinqu.net
# EW Task Tool Version 1.0

use Tk;
use Tk::widgets qw/Dialog ErrorDialog ROText/;
use strict;

# Generate task declaration suitable to EW.
# example supplied looks like this:

#FLIGHT DECLARATION
#-------------------
#
#Description:      To Heaven and Back
#Take Off LatLong: 0000000N00000000E TAKE OFF
#Start LatLon:     0000000N00000000E START
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#TP LatLon:        0000000N00000000E TURN POINT
#Finish LatLon:    0000000N00000000E FINISH
#Land LatLon:      0000000N00000000E LAND

my $mw = MainWindow->new;
$mw->CmdLine;
$mw->title("Turnpoints");
$mw->minsize(175,50);
$mw->configure(-menu => my $menubar = $mw->Menu);

my $file = $menubar->cascade(qw/-label File -underline 0 -menuitems/ =>
    [
     [command    => 'Open', -command => [\&load_dat]],
     [command    => 'Exit', -command => [\&exit]],
    ]);

my $igc = $menubar->cascade(qw/-label Task -underline 0 -menuitems/ =>
    [
     [command    => 'Add', -command => [\&add_to_task]],
     [command    => 'Delete', -command => [\&del_from_task]],
     [command    => 'Write', -command => [\&write_task]],
    ]);

my $help = $menubar->cascade(qw/-label Help -underline 0 -menuitems/ =>
    [
      [command => 'About'],
      [command => 'Add'],
      [command => 'Delete'],
      [command => 'Write'],
      [command => 'Open'],
    ]);

my $DIALOG_ABOUT = $mw->Dialog(
    -title          => 'About Task tool',
    -bitmap         => 'info',
    -default_button => 'OK',
    -buttons        => ['OK'],
    -text           => "EW Task tool\nPhilip Plane\n" .
    		       "9 March 2007\n\nPerl Version $]" .
                       "\nTk Version $Tk::VERSION\n\n" .
                       "Creates task definitions for the EW MicroRecorder",
);

$help->cget(-menu)->entryconfigure('About',
    -command => [$DIALOG_ABOUT => 'Show'],
);

my $DIALOG_ADD = $mw->Dialog(
    -title          => 'Adding to Task',
    -bitmap         => 'info',
    -default_button => 'OK',
    -buttons        => ['OK'],
    -text           => "To add a turnpoint from the turnpoint list " .
    		       "to the task, select the turnpoint from the " .
                       "turnpoint list, then select Add from the Task " .
                       "menu. The turnpoint will be added to the bottom " .
                       "of the task.",
);

$help->cget(-menu)->entryconfigure('Add',
    -command => [$DIALOG_ADD => 'Show'],
);


my $DIALOG_DELETE = $mw->Dialog(
    -title          => 'Delete from task',
    -bitmap         => 'info',
    -default_button => 'OK',
    -buttons        => ['OK'],
    -text           => "To delete a turnpoint from the task, select " .
    		       "the turnpoint from the task list, then " .
                       "select Delete from the task menu. The turnpoint " .
                       "will be deleted from the task.",
);

$help->cget(-menu)->entryconfigure('Delete',
    -command => [$DIALOG_DELETE => 'Show'],
);

my $DIALOG_WRITE = $mw->Dialog(
    -title          => 'Write task',
    -bitmap         => 'info',
    -default_button => 'OK',
    -buttons        => ['OK'],
    -text           => "Opens a window with the task presented in the " .
    		       "format used by the EW MicroRecorder. " .
                       "This is intended to be cut and pasted into the " .
                       "configuration file on the MicroRecorder. " ,
);

$help->cget(-menu)->entryconfigure('Write',
    -command => [$DIALOG_WRITE => 'Show'],
);

my $DIALOG_OPEN = $mw->Dialog(
    -title          => 'Open file',
    -bitmap         => 'info',
    -default_button => 'OK',
    -buttons        => ['OK'],
    -text           => "Opens a turnpoint file in Cambridge .DAT " .
    		       "format. This is loaded into the left pane " .
                       "to allow turnpoints the be selected and added " .
                       "to the task. " ,
);

$help->cget(-menu)->entryconfigure('Open',
    -command => [$DIALOG_OPEN => 'Show'],
);

$mw->Label(-text=>"Turnpoints")->grid( "x", $mw->Label(-text=>"Task"));

my $lb = $mw->Scrolled("Listbox",
        	-scrollbars => "e",
                -selectmode => "single")->grid(-row=> 0,
                                               -column=> 0,
                                               -rowspan=> 2,
                                               -sticky=> "nsew");

$mw->Button(-text=>"Add ->", -command=> \&add_to_task )->grid(-row=> 0,
                                                              -column=> 1,
                                                              -sticky=> "sew");


my $task = $mw->Scrolled("Listbox",
        	-scrollbars => "e",
                -selectmode => "single")->grid(-row=> 0,
                                               -column=> 2,
                                               -rowspan=> 2,
                                               -sticky=> "nsew");

$mw->Button(-text=>"Del <-", -command=> \&del_from_task )->grid(-row=> 1,
                                                                -column=> 1,
                                                                -sticky=> "new");


my @dat = ();
my %lat = ();
my %lng = ();

sub load_dat {
    my $types = [
		 ['DAT Files','.dat'],
		 ['DAT Files','.DAT'],
		 ];

    my $igc = $mw->getOpenFile(-initialdir=>'C:',
			       -filetypes=>$types);
    if ( defined $igc ){
	my @igc = split /\//,$igc;
	my $igcfile = pop @igc;
        open IGC, $igc or die "Can't open $igc : $!\n";
        my @log = <IGC>;
        close IGC;
        while ( $_ = shift @log ){
            if ( $_ =~ /^\d/ ){
            	@dat = split(/\,/,$_);
                if ( $dat[4] =~ /T|S|F/ ){
                        if ( $dat[5] eq "" ) { $dat[5] = $dat[0] }
                        $lat{$dat[5]} = $dat[1];
                        $lng{$dat[5]} = $dat[2];
                        $lb->insert('end',$dat[5]);
                }
            }
	}
    }
}

sub add_to_task {
	my @selection = $lb->curselection();
        foreach ( @selection ){
        	my $turnpoint =$lb->get($_);
                $task->insert('end',$turnpoint);
        }
}

sub del_from_task {
	my @selection = $task->curselection();
        foreach ( @selection ){
        	$task->delete($_);
        }
}

sub write_task {
	my $bwin = $mw->Toplevel();
	$bwin->title("Flight Declaration");
        my $text = $bwin->Scrolled("Text")->pack();
        $text->delete("1.0","end");
        $text->insert("end","FLIGHT DECLARATION\n");
        $text->insert("end","-------------------\n");
        $text->insert("end","\n");
        $text->insert("end","Description:      To Heaven and Back\n");
        my @elements = $task->get(0,'end');
        my $start = shift @elements;
        my $finish = pop @elements;
        my $lat = $lat{$start};
        my $lng = $lng{$start};
        $lat =~ s/://;
        $lng =~ s/://;
        $lat =~ s/\.//;
    	$lng =~ s/\.//;
        $text->insert("end","Start LatLon:     " . $lat . $lng . " " . $start . "\n");
        foreach ( @elements ){
        	my $lat = $lat{$start};
        	my $lng = $lng{$start};
        	$lat =~ s/://;
        	$lat =~ s/\.//;
        	$lng =~ s/://;
        	$lng =~ s/\.//;
        	$text->insert("end","TP LatLon:        " . $lat . $lng . " " . $_ . "\n");
        }
    	$lat = $lat{$finish};
        $lng = $lng{$finish};
        $lat =~ s/://;
        $lat =~ s/\.//;
        $lng =~ s/://;
        $lng =~ s/\.//;
        $text->insert("end","Finish LatLon:    " . $lat . $lng . " " . $finish . "\n");
}
MainLoop;