added input defaulting and error alerts

ver1_5_1
Hank Ramsey 2003-11-29 23:18:50 +00:00
parent 7a14183696
commit 82ad8f8023
1 changed files with 12 additions and 68 deletions

View File

@ -50,13 +50,20 @@
- (IBAction)setTime:(id)sender
{
CelestiaSimulation *sim;
sim = [[CelestiaAppCore sharedAppCore] simulation];
// NSLog( [dateField stringValue] );
NSString* fmtString = @"%m/%d/%Y %H:%M:%S";
NSString* dateString = [dateField stringValue];
NSString* timeString = [timeField stringValue];
NSString* inputString = [ [ dateString stringByAppendingString: @" " ]
stringByAppendingString: timeString ];
NSString* fmtString = @"%m/%d/%Y %H:%M:%S";
NSCalendarDate* cdate = [NSCalendarDate dateWithString: inputString calendarFormat: fmtString ];
NSNumber* jd = [ Astro julianDate: cdate];
sim = [[CelestiaAppCore sharedAppCore] simulation];
if ( [dateString isEqualToString: @""] && [timeString isEqualToString: @""])
{
NSRunAlertPanel(@"No Date or Time Entered",@"Please enter a date and/or time.",nil,nil,nil);
return;
}
if ( [timeString isEqualToString: @""] )
{
NSLog(@"emptyTime");
@ -74,79 +81,16 @@
NSLog(timeString);
}
NSString* inputString = [ [ dateString stringByAppendingString: @" " ]
stringByAppendingString: timeString ];
NSCalendarDate* cdate = [NSCalendarDate dateWithString: inputString calendarFormat: fmtString ];
if ( cdate == NULL )
{
NSLog(@"bad date");
// NSLog(@"bad date");
NSRunAlertPanel(@"Improper Date or Time Format",@"Please enter the date as \"mm/dd/yyyy\" and the time as \"hh:mm:ss\".",nil,nil,nil);
return;
}
NSLog( [cdate description] );
NSNumber* jd = [ Astro julianDate: cdate];
// float fjd = [jd intValue];
// NSLog ( @"jdate = %", fjd);
[sim setDate: jd ];
/*
CelestiaSimulation *sim;
CelestiaSelection *csel;
CelestiaVector *up;
double distance;
csel = nil;
//NSLog(@"-[GotoWindowController gotoObject:%@]",sender);
sim = [[CelestiaAppCore sharedAppCore] simulation];
//NSLog(@"[objectField stringValue] = '%@'",[objectField stringValue]);
if ([[objectField stringValue] length])
csel = [sim findObjectFromPath:[objectField stringValue]];
if ((csel == nil) || [csel isEmpty])
return;
[sim setSelection:csel];
[sim geosynchronousFollow];
distance = [[csel radius] doubleValue]*5.0;
if ([[distanceField stringValue] length])
{
//NSLog(@"distanceField is filled in");
// convert to km if necessary
switch ([unitsButton indexOfSelectedItem]) {
case UNITS_RADII:
//NSLog(@"Converting from radii");
distance = [distanceField doubleValue]*[[csel radius] doubleValue];
break;
case UNITS_AU:
//NSLog(@"Converting from AU");
distance = [[Astro AUtoKilometers:[NSNumber numberWithDouble:[distanceField doubleValue]]] doubleValue];
break;
case UNITS_KM:
//NSLog(@"don't have to convert from km");
distance = [distanceField doubleValue];
break;
default:
//NSLog(@"I don't know what the fuck the button has selected?");
break;
}
}
distance = [[Astro kilometersToLightYears:[NSNumber numberWithDouble:distance]] doubleValue];
up = [CelestiaVector vectorWithx:[NSNumber numberWithFloat:0.0] y:[NSNumber numberWithFloat:1.0] z:[NSNumber numberWithFloat:0.0]];
if ([[latitudeField stringValue] length] && [[longitudeField stringValue] length])
{
//NSLog(@"lat/lon provided");
[sim
gotoSelection:[NSNumber numberWithFloat:5.0]
distance:[NSNumber numberWithDouble:distance]
longitude:[NSNumber numberWithDouble:[longitudeField doubleValue]*(M_PI/180.0)]
latitude:[NSNumber numberWithDouble:[latitudeField doubleValue]*(M_PI/180.0)]
up:up
];
} else {
//NSLog(@"No lat/lon");
[sim
gotoSelection:[NSNumber numberWithFloat:5.0]
distance:[NSNumber numberWithDouble:distance]
up:up
coordinateSystem:@"ObserverLocal"
];
}
*/
}
@end