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

OpenGL

开发平台:

Visual C++

  1. //
  2. //  CelestiaSelection.mm
  3. //  celestia
  4. //
  5. //  Created by Bob Ippolito on Fri Jun 07 2002.
  6. //  Copyright (c) 2002 Chris Laurel. All rights reserved.
  7. //
  8. #import "CelestiaSelection.h"
  9. #import "CelestiaSelection_PrivateAPI.h"
  10. #import "CelestiaBody_PrivateAPI.h"
  11. #import "CelestiaGalaxy_PrivateAPI.h"
  12. #import "CelestiaStar_PrivateAPI.h"
  13. #import "CelestiaLocation.h"
  14. #import "NSString_ObjCPlusPlus.h"
  15. #import "CelestiaUniversalCoord_PrivateAPI.h"
  16. #import "CelestiaAppCore.h"
  17. #import "CelestiaUniverse_PrivateAPI.h"
  18. @implementation CelestiaSelection(PrivateAPI)
  19. -(CelestiaSelection *)initWithSelection:(Selection)selection
  20. {
  21.     self=[super init];
  22.     _data = [[NSMutableData alloc] initWithBytes:(void *)&selection length:sizeof(Selection)];
  23.     return self;
  24. }
  25. -(Selection)selection
  26. {
  27.     return *reinterpret_cast<const Selection*>([_data mutableBytes]);
  28. }
  29. @end
  30. @implementation CelestiaSelection
  31. /*
  32.     Selection() : star(NULL), body(NULL), galaxy(NULL) {};
  33.     Selection(Star* _star) : star(_star), body(NULL), galaxy(NULL) {};
  34.     Selection(Body* _body) : star(NULL), body(_body), galaxy(NULL) {};
  35.     Selection(Galaxy* _galaxy) : star(NULL), body(NULL), galaxy(_galaxy) {};
  36. */
  37. -(void)dealloc
  38. {
  39.     if (_data != nil) {
  40.         [_data release];
  41.         _data = nil;
  42.     }
  43.     [super dealloc];
  44. }
  45. -(CelestiaSelection*)initWithCelestiaStar:(CelestiaStar*)s
  46. {
  47.     return [self initWithSelection:Selection([s star])];
  48. }
  49. -(CelestiaSelection*)initWithCelestiaBody:(CelestiaBody*)b
  50. {
  51.     return [self initWithSelection:Selection([b body])];
  52. }
  53. -(CelestiaSelection*)initWithCelestiaGalaxy:(CelestiaGalaxy*)g
  54. {
  55.     return [self initWithSelection:Selection([g galaxy])];
  56. }
  57. -(CelestiaSelection*)initWithCelestiaLocation:(CelestiaLocation*)g
  58. {
  59.     return [self initWithSelection:Selection([g location])];
  60. }
  61. -(CelestiaBody *)body
  62. {
  63.     if ([self selection].getType() != Selection::Type_Body) return nil;
  64.     return [[[CelestiaBody alloc] initWithBody:[self selection].body()] autorelease];
  65. }
  66. -(BOOL)isEmpty
  67. {
  68.     return (BOOL)([self selection].empty());
  69. }
  70. -(NSNumber*)radius
  71. {
  72.     return [NSNumber numberWithDouble:[self selection].radius()];
  73. }
  74. -(BOOL)isEqualToSelection:(CelestiaSelection*)csel
  75. {
  76.     return (BOOL)([self selection]==[csel selection]);
  77. }
  78. -(CelestiaStar*)star
  79. {
  80.     if ([self selection].getType() != Selection::Type_Star) return nil;
  81.     return [[[CelestiaStar alloc] initWithStar:[self selection].star()] autorelease];
  82. }
  83. -(CelestiaGalaxy*)galaxy
  84. {
  85.     if ([self selection].getType() != Selection::Type_DeepSky) return nil;
  86.     return [[[CelestiaGalaxy alloc] initWithGalaxy:((Galaxy*)[self selection].deepsky())] autorelease];
  87. }
  88. -(CelestiaLocation*)location
  89. {
  90.     if ([self selection].getType() != Selection::Type_Location) return nil;
  91.     return [[[CelestiaLocation alloc] initWithLocation:((Location*)[self selection].location())] autorelease];
  92. }
  93. -(NSString *)name
  94. {
  95.     return [NSString stringWithStdString:[self selection].getName()];
  96. }
  97. -(NSString *) briefName
  98. {
  99.     NSString* name;
  100.     if ([self star] != NULL)
  101.     {
  102.         CelestiaAppCore* appCore = [CelestiaAppCore sharedAppCore];
  103.         Universe* univ = [[[appCore simulation] universe] universe];
  104.         StarDatabase* stardb = univ->getStarCatalog();
  105.         string starname = stardb->getStarName(*[[self star]star]);
  106.         name = [NSString stringWithStdString:starname];
  107. /*
  108.         char buf[20];
  109.         sprintf(buf, "#%d", [[[self star] catalogNumber] intValue]);
  110. //        string tname = string(buf);
  111.         name = [NSString stringWithStdString:string(buf)];
  112. */
  113.     }
  114.     else if ([ self galaxy] != NULL)
  115.     {
  116.         name = [ [self galaxy] name ];
  117.     }
  118.     else if ([self body] != NULL)
  119.     {
  120.         name = [[self body] name];
  121.     }
  122.     else if ([self location] != NULL)
  123.     {
  124.         name = [[self location] name];
  125.     }
  126.     else
  127.     {
  128.         name = @"";
  129.     }
  130.     return name;
  131. }
  132. -(CelestiaUniversalCoord*)position:(NSNumber*)t
  133. {
  134.     return [[[CelestiaUniversalCoord alloc] initWithUniversalCoord:[self selection].getPosition([t doubleValue])] autorelease];
  135. }
  136. @end