00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <cstdio>
00011 #include "astro.h"
00012 #include "selection.h"
00013
00014 using namespace std;
00015
00016
00017 double Selection::radius() const
00018 {
00019 switch (type)
00020 {
00021 case Type_Star:
00022 return star()->getRadius();
00023 case Type_Body:
00024 return body()->getRadius();
00025 case Type_DeepSky:
00026 return astro::lightYearsToKilometers(deepsky()->getRadius());
00027 case Type_Location:
00028
00029 return location()->getSize() / 2.0f;
00030 default:
00031 return 0.0;
00032 }
00033 }
00034
00035
00036 UniversalCoord Selection::getPosition(double t) const
00037 {
00038 switch (type)
00039 {
00040 case Type_Body:
00041 {
00042 PlanetarySystem* system = body()->getSystem();
00043 const Star* sun = NULL;
00044 if (system != NULL)
00045 sun = system->getStar();
00046
00047 Point3d hpos = body()->getHeliocentricPosition(t);
00048 if (sun != NULL)
00049 return astro::universalPosition(hpos, sun->getPosition(t));
00050 else
00051 return astro::universalPosition(hpos, Point3f(0.0f, 0.0f, 0.0f));
00052
00053 }
00054
00055 case Type_Star:
00056 return star()->getPosition(t);
00057
00058 case Type_DeepSky:
00059 {
00060 Point3d p = deepsky()->getPosition();
00061 return astro::universalPosition(Point3d(0.0, 0.0, 0.0),
00062 Point3f((float) p.x, (float) p.y, (float) p.z));
00063 }
00064
00065 case Type_Location:
00066 {
00067 Point3f sunPos(0.0f, 0.0f, 0.0f);
00068 Body* body = location()->getParentBody();
00069 if (body != NULL && body->getSystem() != NULL)
00070 {
00071 const Star* sun = body->getSystem()->getStar();
00072 if (sun != NULL)
00073 sunPos = sun->getPosition();
00074 }
00075
00076 return astro::universalPosition(location()->getHeliocentricPosition(t),
00077 sunPos);
00078 }
00079
00080 default:
00081 return UniversalCoord(Point3d(0.0, 0.0, 0.0));
00082 }
00083 }
00084
00085
00086 string Selection::getName() const
00087 {
00088 switch (type)
00089 {
00090 case Type_Star:
00091 {
00092 char buf[20];
00093 sprintf(buf, "#%d", star()->getCatalogNumber());
00094 return string(buf);
00095 }
00096
00097 case Type_DeepSky:
00098 {
00099 char buf[20];
00100 sprintf(buf, "#%d", deepsky()->getCatalogNumber());
00101 return string(buf);
00102 }
00103
00104 case Type_Body:
00105 {
00106 string name = body()->getName();
00107 PlanetarySystem* system = body()->getSystem();
00108 while (system != NULL)
00109 {
00110 Body* parent = system->getPrimaryBody();
00111 if (parent != NULL)
00112 {
00113 name = parent->getName() + '/' + name;
00114 system = parent->getSystem();
00115 }
00116 else
00117 {
00118 const Star* parentStar = system->getStar();
00119 if (parentStar != NULL)
00120 {
00121 char buf[20];
00122 sprintf(buf, "#%d", parentStar->getCatalogNumber());
00123 name = string(buf) + '/' + name;
00124 }
00125 system = NULL;
00126 }
00127 }
00128 return name;
00129 }
00130
00131 case Type_Location:
00132 if (location()->getParentBody() == NULL)
00133 {
00134 return location()->getName();
00135 }
00136 else
00137 {
00138 return Selection(location()->getParentBody()).getName() + '/' +
00139 location()->getName();
00140 }
00141
00142 default:
00143 return "";
00144 }
00145 }
00146
00147
00148 Selection Selection::parent() const
00149 {
00150 switch (type)
00151 {
00152 case Type_Location:
00153 return Selection(location()->getParentBody());
00154
00155 case Type_Body:
00156 if (body()->getSystem())
00157 {
00158 if (body()->getSystem()->getPrimaryBody() != NULL)
00159 return Selection(body()->getSystem()->getPrimaryBody());
00160 else
00161 return Selection(body()->getSystem()->getStar());
00162 }
00163 else
00164 {
00165 return Selection();
00166 }
00167 break;
00168
00169 case Type_Star:
00170 case Type_DeepSky:
00171
00172 return Selection();
00173
00174 default:
00175 return Selection();
00176 }
00177 }