Satellite.cpp   Satellite.cpp 
skipping to change at line 54 skipping to change at line 54
float Satellite::showLabels = true; float Satellite::showLabels = true;
float Satellite::hintBrightness = 0.0; float Satellite::hintBrightness = 0.0;
float Satellite::hintScale = 1.f; float Satellite::hintScale = 1.f;
SphericalCap Satellite::viewportHalfspace = SphericalCap(); SphericalCap Satellite::viewportHalfspace = SphericalCap();
int Satellite::orbitLineSegments = 90; int Satellite::orbitLineSegments = 90;
int Satellite::orbitLineFadeSegments = 4; int Satellite::orbitLineFadeSegments = 4;
int Satellite::orbitLineSegmentDuration = 20; int Satellite::orbitLineSegmentDuration = 20;
bool Satellite::orbitLinesFlag = true; bool Satellite::orbitLinesFlag = true;
Satellite::Satellite(const QString& identifier, const QVariantMap& map) Satellite::Satellite(const QString& identifier, const QVariantMap& map)
: initialized(false), visible(true), newlyAdded(false), orbi : initialized(false),
tValid(false), hintColor(0.0,0.0,0.0), lastUpdated(), pSatWrapper(NULL) displayed(true),
orbitDisplayed(false),
userDefined(false),
newlyAdded(false),
orbitValid(false),
hintColor(0.0,0.0,0.0),
lastUpdated(),
pSatWrapper(NULL)
{ {
// return initialized if the mandatory fields are not present // return initialized if the mandatory fields are not present
if (identifier.isEmpty()) if (identifier.isEmpty())
return; return;
if (!map.contains("name") || !map.contains("tle1") || !map.contains( "tle2")) if (!map.contains("name") || !map.contains("tle1") || !map.contains( "tle2"))
return; return;
font.setPixelSize(16); font.setPixelSize(16);
id = identifier; id = identifier;
name = map.value("name").toString(); name = map.value("name").toString();
if (name.isEmpty()) if (name.isEmpty())
return; return;
if (map.contains("description")) description = map.value("descriptio // If there are no such keys, these will be initialized with the def
n").toString(); ault
if (map.contains("visible")) visible = map.value("visible").toBool() // values given them above.
; description = map.value("description", description).toString().trimm
if (map.contains("orbitVisible")) orbitVisible = map.value("orbitVis ed();
ible").toBool(); displayed = map.value("visible", displayed).toBool();
orbitDisplayed = map.value("orbitVisible", orbitDisplayed).toBool();
if (map.contains("hintColor")) userDefined = map.value("userDefined", userDefined).toBool();
{
if (map.value("hintColor").toList().count() == 3) // Satellite hint color
{ QVariantList list = map.value("hintColor", QVariantList()).toList();
hintColor[0] = map.value("hintColor").toList().at(0) if (list.count() == 3)
.toDouble(); {
hintColor[1] = map.value("hintColor").toList().at(1) hintColor[0] = list.at(0).toDouble();
.toDouble(); hintColor[1] = list.at(1).toDouble();
hintColor[2] = map.value("hintColor").toList().at(2) hintColor[2] = list.at(2).toDouble();
.toDouble(); }
}
} // Satellite orbit section color
list = map.value("orbitColor", QVariantList()).toList();
if (map.contains("orbitColor")) if (list.count() == 3)
{ {
if (map.value("orbitColor").toList().count() == 3) orbitColorNormal[0] = list.at(0).toDouble();
{ orbitColorNormal[1] = list.at(1).toDouble();
orbitColorNormal[0] = map.value("orbitColor").toList orbitColorNormal[2] = list.at(2).toDouble();
().at(0).toDouble();
orbitColorNormal[1] = map.value("orbitColor").toList
().at(1).toDouble();
orbitColorNormal[2] = map.value("orbitColor").toList
().at(2).toDouble();
}
} }
else else
{ {
orbitColorNormal = hintColor; orbitColorNormal = hintColor;
} }
// Set the night color of orbit lines to red with the // Set the night color of orbit lines to red with the
// intensity of the average of the RGB for the day color. // intensity of the average of the RGB for the day color.
float orbitColorBrightness = (orbitColorNormal[0] + orbitColorNormal [1] + orbitColorNormal[2])/3; float orbitColorBrightness = (orbitColorNormal[0] + orbitColorNormal [1] + orbitColorNormal[2])/3;
orbitColorNight[0] = orbitColorBrightness; orbitColorNight[0] = orbitColorBrightness;
skipping to change at line 114 skipping to change at line 123
if (StelApp::getInstance().getVisionModeNight()) if (StelApp::getInstance().getVisionModeNight())
orbitColor = &orbitColorNight; orbitColor = &orbitColorNight;
else else
orbitColor = &orbitColorNormal; orbitColor = &orbitColorNormal;
if (map.contains("comms")) if (map.contains("comms"))
{ {
foreach(const QVariant &comm, map.value("comms").toList()) foreach(const QVariant &comm, map.value("comms").toList())
{ {
QVariantMap commMap = comm.toMap(); QVariantMap commMap = comm.toMap();
commLink c; CommLink c;
if (commMap.contains("frequency")) c.frequency = com mMap.value("frequency").toDouble(); if (commMap.contains("frequency")) c.frequency = com mMap.value("frequency").toDouble();
if (commMap.contains("modulation")) c.modulation = c ommMap.value("modulation").toString(); if (commMap.contains("modulation")) c.modulation = c ommMap.value("modulation").toString();
if (commMap.contains("description")) c.description = commMap.value("description").toString(); if (commMap.contains("description")) c.description = commMap.value("description").toString();
comms.append(c); comms.append(c);
} }
} }
if (map.contains("groups")) QVariantList groupList = map.value("groups", QVariantList()).toList
();
if (!groupList.isEmpty())
{ {
foreach(const QVariant &group, map.value("groups").toList()) foreach(const QVariant& group, groupList)
{ groups.insert(group.toString());
if (!groupIDs.contains(group.toString()))
groupIDs << group.toString();
}
} }
// TODO: Somewhere here - some kind of TLE validation.
QString line1 = map.value("tle1").toString(); QString line1 = map.value("tle1").toString();
QString line2 = map.value("tle2").toString(); QString line2 = map.value("tle2").toString();
setNewTleElements(line1, line2); setNewTleElements(line1, line2);
internationalDesignator = extractInternationalDesignator(line1); // This also sets the international designator and launch year.
StelUtils::getJDFromDate(&jdLaunchYearJan1, extractLaunchYear(line1)
, 1, 1, 0, 0, 0); QString dateString = map.value("lastUpdated").toString();
if (!dateString.isEmpty())
lastUpdated = QDateTime::fromString(dateString, Qt::ISODate)
;
if (map.contains("lastUpdated"))
{
lastUpdated = QDateTime::fromString(map.value("lastUpdated")
.toString(),
Qt::ISODate);
}
orbitValid = true; orbitValid = true;
initialized = true; initialized = true;
update(0.); update(0.);
} }
Satellite::~Satellite() Satellite::~Satellite()
{ {
if (pSatWrapper != NULL) if (pSatWrapper != NULL)
{ {
skipping to change at line 171 skipping to change at line 177
return floor(n * pow(10., dp) + .5) / pow(10., dp); return floor(n * pow(10., dp) + .5) / pow(10., dp);
} }
QVariantMap Satellite::getMap(void) QVariantMap Satellite::getMap(void)
{ {
QVariantMap map; QVariantMap map;
map["name"] = name; map["name"] = name;
map["tle1"] = tleElements.first.data(); map["tle1"] = tleElements.first.data();
map["tle2"] = tleElements.second.data(); map["tle2"] = tleElements.second.data();
if (!description.isEmpty() && description!="") if (!description.isEmpty())
map["description"] = description; map["description"] = description;
map["visible"] = visible; map["visible"] = displayed;
map["orbitVisible"] = orbitVisible; map["orbitVisible"] = orbitDisplayed;
if (userDefined)
map.insert("userDefined", userDefined);
QVariantList col, orbitCol; QVariantList col, orbitCol;
col << roundToDp(hintColor[0],3) << roundToDp(hintColor[1], 3) << ro undToDp(hintColor[2], 3); col << roundToDp(hintColor[0],3) << roundToDp(hintColor[1], 3) << ro undToDp(hintColor[2], 3);
orbitCol << roundToDp(orbitColorNormal[0], 3) << roundToDp(orbitColo rNormal[1], 3) << roundToDp(orbitColorNormal[2],3); orbitCol << roundToDp(orbitColorNormal[0], 3) << roundToDp(orbitColo rNormal[1], 3) << roundToDp(orbitColorNormal[2],3);
map["hintColor"] = col; map["hintColor"] = col;
map["orbitColor"] = orbitCol; map["orbitColor"] = orbitCol;
QVariantList commList; QVariantList commList;
foreach(const commLink &c, comms) foreach(const CommLink &c, comms)
{ {
QVariantMap commMap; QVariantMap commMap;
commMap["frequency"] = c.frequency; commMap["frequency"] = c.frequency;
if (!c.modulation.isEmpty() && c.modulation != "") commMap[" modulation"] = c.modulation; if (!c.modulation.isEmpty() && c.modulation != "") commMap[" modulation"] = c.modulation;
if (!c.description.isEmpty() && c.description != "") commMap ["description"] = c.description; if (!c.description.isEmpty() && c.description != "") commMap ["description"] = c.description;
commList << commMap; commList << commMap;
} }
map["comms"] = commList; map["comms"] = commList;
QVariantList groupList; QVariantList groupList;
foreach(const QString &g, groupIDs) foreach(const QString &g, groups)
{ {
groupList << g; groupList << g;
} }
map["groups"] = groupList; map["groups"] = groupList;
if (!lastUpdated.isNull()) if (!lastUpdated.isNull())
{ {
// A raw QDateTime is not a recognised JSON data type. --BM // A raw QDateTime is not a recognised JSON data type. --BM
map["lastUpdated"] = lastUpdated.toString(Qt::ISODate); map["lastUpdated"] = lastUpdated.toString(Qt::ISODate);
} }
skipping to change at line 221 skipping to change at line 229
QString Satellite::getInfoString(const StelCore *core, const InfoStringGrou p& flags) const QString Satellite::getInfoString(const StelCore *core, const InfoStringGrou p& flags) const
{ {
QString str; QString str;
QTextStream oss(&str); QTextStream oss(&str);
if (flags & Name) if (flags & Name)
{ {
oss << "<h2>" << name << "</h2>"; oss << "<h2>" << name << "</h2>";
if (!description.isEmpty()) if (!description.isEmpty())
oss << description << "<br/>"; oss << q_(description) << "<br/>";
} }
if (flags & CatalogNumber) if (flags & CatalogNumber)
{ {
QString catalogNumbers; QString catalogNumbers;
if (internationalDesignator.isEmpty()) if (internationalDesignator.isEmpty())
catalogNumbers = QString("%1: %2") catalogNumbers = QString("%1: %2")
.arg(q_("Catalog #")) .arg(q_("Catalog #"))
.arg(id); .arg(id);
else else
skipping to change at line 309 skipping to change at line 317
case NOT_VISIBLE: case NOT_VISIBLE:
oss << q_("The satellite is not visible") << "<br/>" ; oss << q_("The satellite is not visible") << "<br/>" ;
break; break;
default: default:
break; break;
} }
} }
if (flags&Extra2 && comms.size() > 0) if (flags&Extra2 && comms.size() > 0)
{ {
foreach(const commLink &c, comms) foreach(const CommLink &c, comms)
{ {
double dop = getDoppler(c.frequency); double dop = getDoppler(c.frequency);
double ddop = dop; double ddop = dop;
char sign; char sign;
if (dop<0.) if (dop<0.)
{ {
sign='-'; sign='-';
ddop*=-1; ddop*=-1;
} }
else else
skipping to change at line 382 skipping to change at line 390
delete old; delete old;
} }
tleElements.first.clear(); tleElements.first.clear();
tleElements.first.append(tle1); tleElements.first.append(tle1);
tleElements.second.clear(); tleElements.second.clear();
tleElements.second.append(tle2); tleElements.second.append(tle2);
pSatWrapper = new gSatWrapper(id, tle1, tle2); pSatWrapper = new gSatWrapper(id, tle1, tle2);
orbitPoints.clear(); orbitPoints.clear();
parseInternationalDesignator(tle1);
} }
void Satellite::update(double) void Satellite::update(double)
{ {
if (pSatWrapper && orbitValid) if (pSatWrapper && orbitValid)
{ {
StelCore* core = StelApp::getInstance().getCore(); StelCore* core = StelApp::getInstance().getCore();
double JD = core->getJDay(); double JD = core->getJDay();
epochTime = JD - core->getDeltaT(JD)/86400; // Delta T anti- correction for artificial satellites epochTime = JD - core->getDeltaT(JD)/86400; // Delta T anti- correction for artificial satellites
skipping to change at line 417 skipping to change at line 427
return; return;
} }
elAzPosition = pSatWrapper->getAltAz(); elAzPosition = pSatWrapper->getAltAz();
elAzPosition.normalize(); elAzPosition.normalize();
pSatWrapper->getSlantRange(range, rangeRate); pSatWrapper->getSlantRange(range, rangeRate);
visibility = pSatWrapper->getVisibilityPredict(); visibility = pSatWrapper->getVisibilityPredict();
// Compute orbit points to draw orbit line. // Compute orbit points to draw orbit line.
if (orbitVisible) computeOrbitPoints(); if (orbitDisplayed) computeOrbitPoints();
} }
} }
double Satellite::getDoppler(double freq) const double Satellite::getDoppler(double freq) const
{ {
double result; double result;
double f = freq * 1000000; double f = freq * 1000000;
result = -f*((rangeRate*1000.0)/SPEED_OF_LIGHT); result = -f*((rangeRate*1000.0)/SPEED_OF_LIGHT);
return result/1000000; return result/1000000;
} }
void Satellite::recalculateOrbitLines(void) void Satellite::recalculateOrbitLines(void)
{ {
orbitPoints.clear(); orbitPoints.clear();
} }
QString Satellite::extractInternationalDesignator(const QString& tle1) SatFlags Satellite::getFlags()
{ {
QString result; // There's also a faster, but less readable way: treating them as ui
if (tle1.isEmpty()) nt.
return result; SatFlags flags;
if (displayed)
// The designator is encoded as the 3rd group on the first line flags |= SatDisplayed;
QString rawString = tle1.split(' ').at(2);
if (rawString.isEmpty())
return result;
//TODO: Use a regular expression?
bool ok;
int year = rawString.left(2).toInt(&ok);
if (!ok)
return result;
// Y2K bug :) I wonder what NORAD will do in 2057. :)
if (year < 57)
year += 2000;
else else
year += 1900; flags |= SatNotDisplayed;
if (orbitDisplayed)
result = QString::number(year) + "-" + rawString.right(4); flags |= SatOrbit;
return result; if (userDefined)
flags |= SatUser;
if (newlyAdded)
flags |= SatNew;
if (!orbitValid)
flags |= SatError;
return flags;
} }
int Satellite::extractLaunchYear(const QString& tle1) void Satellite::setFlags(const SatFlags& flags)
{ {
if (tle1.isEmpty()) displayed = flags.testFlag(SatDisplayed);
return 1957; orbitDisplayed = flags.testFlag(SatOrbit);
userDefined = flags.testFlag(SatUser);
}
// The designator is encoded as the 3rd group on the first line void Satellite::parseInternationalDesignator(const QString& tle1)
QString rawString = tle1.split(' ').at(2); {
if (rawString.isEmpty()) Q_ASSERT(!tle1.isEmpty());
return 1957;
// The designator is encoded as columns 10-17 on the first line.
QString rawString = tle1.mid(9, 8);
//TODO: Use a regular expression? //TODO: Use a regular expression?
bool ok; bool ok;
int year = rawString.left(2).toInt(&ok); int year = rawString.left(2).toInt(&ok);
if (!ok) if (!rawString.isEmpty() && ok)
return 1957; {
// Y2K bug :) I wonder what NORAD will do in 2057. :)
if (year < 57)
year += 2000;
else
year += 1900;
internationalDesignator = QString::number(year) + "-" + rawS
tring.right(4);
}
else
year = 1957;
StelUtils::getJDFromDate(&jdLaunchYearJan1, year, 1, 1, 0, 0, 0);
//qDebug() << rawString << internationalDesignator << year;
}
// Y2K bug :) I wonder what NORAD will do in 2057. :) bool Satellite::operator <(const Satellite& another) const
if (year < 57) {
return year + 2000; // If interface strings are used, you'll need QString::localeAwareCo
mpare()
int comp = name.compare(another.name);
if (comp < 0)
return true;
if (comp > 0)
return false;
// If the names are the same, compare IDs, i.e. NORAD numbers.
if (id < another.id)
return true;
else else
return year + 1900; return false;
} }
void Satellite::draw(const StelCore* core, StelRenderer* renderer, void Satellite::draw(const StelCore* core, StelRenderer* renderer,
StelProjectorP projector, StelTextureNew* hintTexture) StelProjectorP projector, StelTextureNew* hintTexture)
{ {
if (core->getJDay() < jdLaunchYearJan1) return; if (core->getJDay() < jdLaunchYearJan1) return;
XYZ = getJ2000EquatorialPos(core); XYZ = getJ2000EquatorialPos(core);
Vec3f drawColor; Vec3f drawColor;
(visibility==RADAR_NIGHT) ? drawColor = Vec3f(0.2f,0.2f,0.2f) : draw Color = hintColor; (visibility==RADAR_NIGHT) ? drawColor = Vec3f(0.2f,0.2f,0.2f) : draw Color = hintColor;
skipping to change at line 505 skipping to change at line 532
Vec3d xy; Vec3d xy;
if (core->getProjection(StelCore::FrameJ2000)->project(XYZ,xy)) if (core->getProjection(StelCore::FrameJ2000)->project(XYZ,xy))
{ {
if (Satellite::showLabels) if (Satellite::showLabels)
{ {
renderer->drawText(TextParams(xy[0], xy[1], name).sh ift(10, 10).useGravity()); renderer->drawText(TextParams(xy[0], xy[1], name).sh ift(10, 10).useGravity());
} }
renderer->drawTexturedRect(xy[0] - 11, xy[1] - 11, 22, 22); renderer->drawTexturedRect(xy[0] - 11, xy[1] - 11, 22, 22);
if (orbitVisible && Satellite::orbitLinesFlag) {drawOrbit(re nderer, projector);} if (orbitDisplayed && Satellite::orbitLinesFlag) {drawOrbit( renderer, projector);}
} }
} }
void Satellite::drawOrbit(StelRenderer* renderer, StelProjectorP projector) void Satellite::drawOrbit(StelRenderer* renderer, StelProjectorP projector)
{ {
Vec3d position,previousPosition; Vec3d position,previousPosition;
QList<Vec3d>::iterator it= orbitPoints.begin(); QList<Vec3d>::iterator it= orbitPoints.begin();
//First point projection calculation //First point projection calculation
skipping to change at line 654 skipping to change at line 681
pSatWrapper->setEpoch(epochTm.getGmtTm()); pSatWrapper->setEpoch(epochTm.getGmtTm());
elAzVector = pSatWrapper->getAltAz(); elAzVector = pSatWrapper->getAltAz();
orbitPoints.push_front(elAzVector); orbitPoints.push_front(elAzVector);
epochTm -= computeInterval; epochTm -= computeInterval;
} }
lastEpochCompForOrbit = epochTime; lastEpochCompForOrbit = epochTime;
} }
} }
} }
bool operator <(const SatelliteP& left, const SatelliteP& right)
{
if (left.isNull())
{
if (right.isNull())
return false;
else
return true;
}
if (right.isNull())
return false; // No sense to check the left one now
return ((*left) < (*right));
}
 End of changes. 28 change blocks. 
94 lines changed or deleted 116 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/