GotoWindowController.m
上传用户:center1979
上传日期:2022-07-26
资源大小:50633k
文件大小:4k
源码类别:

OpenGL

开发平台:

Visual C++

  1. //
  2. //  GotoWindowController.m
  3. //  celestia
  4. //
  5. //  Created by Bob Ippolito on Tue May 28 2002.
  6. //  Copyright (c) 2002 Chris Laurel. All rights reserved.
  7. //
  8. #import "GotoWindowController.h"
  9. #import "CelestiaAppCore.h"
  10. #import "CelestiaSimulation.h"
  11. #import "CelestiaBody.h"
  12. #import "Astro.h"
  13. #import "CelestiaVector.h"
  14. #include <math.h>
  15. #define UNITS_KM 0
  16. #define UNITS_RADII 1
  17. #define UNITS_AU 2
  18. @implementation GotoWindowController
  19. - (IBAction)showWindow:(id)sender
  20. {
  21.     CelestiaSimulation *sim;
  22.     CelestiaSelection *csel;
  23.     CelestiaBody *body;
  24.     NSArray *distLongLat;
  25.     double distance;
  26.     //NSLog(@"-[GotoWindowController showWindow:%@]",sender);
  27.     sim = [[CelestiaAppCore sharedAppCore] simulation];
  28.     distLongLat = [sim getSelectionLongLat];
  29.     //NSLog(@"distLongLat = %@",distLongLat);
  30.     csel = [sim selection];
  31.     body = [csel body];
  32.     if (body != nil) {
  33.         //NSLog(@"Body is NOT nil");
  34.         distance = [[distLongLat objectAtIndex:0] doubleValue] - [[body radius] doubleValue];
  35.         [distanceField setDoubleValue:distance];
  36.         [longitudeField setDoubleValue:[[distLongLat objectAtIndex:1] doubleValue]];
  37.         [latitudeField setDoubleValue:[[distLongLat objectAtIndex:2] doubleValue]];
  38.         [objectField setStringValue:[body name]];
  39.         [unitsButton selectItemAtIndex:UNITS_KM];
  40.     }
  41.     [super showWindow:sender];
  42. }
  43. - (IBAction)gotoObject:(id)sender
  44. {
  45.     CelestiaSimulation *sim;
  46.     CelestiaSelection *csel;
  47.     CelestiaVector *up;
  48.     double distance;
  49.     csel = nil;
  50.     //NSLog(@"-[GotoWindowController gotoObject:%@]",sender);
  51.     sim = [[CelestiaAppCore sharedAppCore] simulation];
  52.     //NSLog(@"[objectField stringValue] = '%@'",[objectField stringValue]);
  53.     if (![[objectField stringValue] length])
  54.     {
  55. NSRunAlertPanel(NSLocalizedString(@"No Object Name Entered",@""),
  56.                     NSLocalizedString(@"Please enter an object name.",@""),
  57.                     nil,nil,nil);
  58.         return;
  59.     }
  60.     csel = [sim findObjectFromPath:[objectField stringValue]];
  61.     if ((csel == nil) || [csel isEmpty])
  62.     {
  63.        NSRunAlertPanel(NSLocalizedString(@"Object Not Found",@""),
  64.                        NSLocalizedString(@"Please check that the object name is correct.",@""),
  65.                        nil,nil,nil);
  66.         return;
  67.     }
  68.     [sim setSelection:csel];
  69.     [sim geosynchronousFollow];
  70.     distance = [[csel radius] doubleValue]*5.0;
  71.     if ([[distanceField stringValue] length])
  72.     {
  73.         //NSLog(@"distanceField is filled in");
  74.         // convert to km if necessary 
  75.         switch ([unitsButton indexOfSelectedItem]) {
  76.             case UNITS_RADII:
  77.                 //NSLog(@"Converting from radii");
  78.                 distance = [distanceField doubleValue]*[[csel radius] doubleValue];
  79.                 break;
  80.             case UNITS_AU:
  81.                 //NSLog(@"Converting from AU");
  82.                 distance = [[Astro AUtoKilometers:[NSNumber numberWithDouble:[distanceField doubleValue]]] doubleValue];
  83.                 break;
  84.             case UNITS_KM:
  85.                 //NSLog(@"don't have to convert from km");
  86.                 distance = [distanceField doubleValue];
  87.                 break;
  88.             default:
  89.                 //NSLog(@"I don't know what button has been selected?");
  90.                 break;
  91.         }
  92.     }
  93.     distance = [[Astro kilometersToLightYears:[NSNumber numberWithDouble:distance]] doubleValue];
  94.     up = [CelestiaVector vectorWithx:[NSNumber numberWithFloat:0.0] y:[NSNumber numberWithFloat:1.0] z:[NSNumber numberWithFloat:0.0]];
  95.     if ([[latitudeField stringValue] length] && [[longitudeField stringValue] length])
  96.     {
  97.         //NSLog(@"lat/lon provided");
  98.         [sim 
  99.             gotoSelection:[NSNumber numberWithFloat:5.0]
  100.             distance:[NSNumber numberWithDouble:distance]
  101.             longitude:[NSNumber numberWithDouble:[longitudeField doubleValue]*(M_PI/180.0)]
  102.             latitude:[NSNumber numberWithDouble:[latitudeField doubleValue]*(M_PI/180.0)]
  103.             up:up
  104.         ];
  105.     } else {
  106.         //NSLog(@"No lat/lon");
  107.         [sim
  108.             gotoSelection:[NSNumber numberWithFloat:5.0]
  109.             distance:[NSNumber numberWithDouble:distance]
  110.             up:up
  111.             coordinateSystem:@"ObserverLocal"
  112.         ];
  113.     }
  114. }
  115. @end