SolarSystem.cpp   SolarSystem.cpp 
skipping to change at line 61 skipping to change at line 61
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QMap> #include <QMap>
#include <QMapIterator> #include <QMapIterator>
#include <QMultiMap> #include <QMultiMap>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
#include <QVariant> #include <QVariant>
#include <QDir>
SolarSystem::SolarSystem() SolarSystem::SolarSystem()
: moonScale(1.) : moonScale(1.)
, flagOrbits(false) , flagOrbits(false)
, flagLightTravelTime(false) , flagLightTravelTime(false)
, texPointer(NULL) , texPointer(NULL)
, allTrails(NULL) , allTrails(NULL)
{ {
planetNameFont.setPixelSize(StelApp::getInstance().getSettings()->va lue("gui/base_font_size", 13).toInt()); planetNameFont.setPixelSize(StelApp::getInstance().getSettings()->va lue("gui/base_font_size", 13).toInt());
setObjectName("SolarSystem"); setObjectName("SolarSystem");
skipping to change at line 256 skipping to change at line 257
p.clear(); p.clear();
} }
systemPlanets.clear(); systemPlanets.clear();
//Memory leak? What's the proper way of cleaning sha red pointers? //Memory leak? What's the proper way of cleaning sha red pointers?
//If the file is in the user data directory, rename it: //If the file is in the user data directory, rename it:
if (solarSystemFile.contains(StelFileMgr::getUserDir ())) if (solarSystemFile.contains(StelFileMgr::getUserDir ()))
{ {
QString newName = QString("%1/data/ssystem-% 2.ini").arg(StelFileMgr::getUserDir()).arg(QDateTime::currentDateTime().toS tring("yyyyMMddThhmmss")); QString newName = QString("%1/data/ssystem-% 2.ini").arg(StelFileMgr::getUserDir()).arg(QDateTime::currentDateTime().toS tring("yyyyMMddThhmmss"));
if (QFile::rename(solarSystemFile, newName)) if (QFile::rename(solarSystemFile, newName))
qWarning() << "Invalid Solar System file" << solarSystemFile << "has been renamed to" << newName; qWarning() << "Invalid Solar System file" << QDir::toNativeSeparators(solarSystemFile) << "has been renamed to" << QDir::toNativeSeparators(newName);
else else
{ {
qWarning() << "Invalid Solar System file" << solarSystemFile << "cannot be removed!"; qWarning() << "Invalid Solar System file" << QDir::toNativeSeparators(solarSystemFile) << "cannot be removed!";
qWarning() << "Please either delete it, rename it or move it elsewhere."; qWarning() << "Please either delete it, rename it or move it elsewhere.";
} }
} }
} }
} }
shadowPlanetCount = 0; shadowPlanetCount = 0;
foreach (const PlanetP& planet, systemPlanets) foreach (const PlanetP& planet, systemPlanets)
if(planet->parent != sun || !planet->satellites.isEmpty()) if(planet->parent != sun || !planet->satellites.isEmpty())
shadowPlanetCount++; shadowPlanetCount++;
} }
bool SolarSystem::loadPlanets(const QString& filePath) bool SolarSystem::loadPlanets(const QString& filePath)
{ {
QSettings pd(filePath, StelIniFormat); QSettings pd(filePath, StelIniFormat);
if (pd.status() != QSettings::NoError) if (pd.status() != QSettings::NoError)
{ {
qWarning() << "ERROR while parsing" << filePath; qWarning() << "ERROR while parsing" << QDir::toNativeSeparat ors(filePath);
return false; return false;
} }
// QSettings does not allow us to say that the sections of the file // QSettings does not allow us to say that the sections of the file
// will be listed in the same order as in the file like the old // will be listed in the same order as in the file like the old
// InitParser used to so we can no longer assume that. // InitParser used to so we can no longer assume that.
// //
// This means we must first decide what order to read the sections // This means we must first decide what order to read the sections
// of the file in (each section contains one planet) to avoid settin g // of the file in (each section contains one planet) to avoid settin g
// the parent Planet* to one which has not yet been created. // the parent Planet* to one which has not yet been created.
skipping to change at line 423 skipping to change at line 424
semi_major_axis = (eccentricity == 1.0) semi_major_axis = (eccentricity == 1.0)
? 0.0 // par abolic orbits have no semi_major_axis ? 0.0 // par abolic orbits have no semi_major_axis
: pericenter Distance / (1.0-eccentricity); : pericenter Distance / (1.0-eccentricity);
} }
double meanMotion = pd.value(secname+"/orbit_MeanMot ion",-1e100).toDouble(); double meanMotion = pd.value(secname+"/orbit_MeanMot ion",-1e100).toDouble();
double period; double period;
if (meanMotion <= -1e100) { if (meanMotion <= -1e100) {
period = pd.value(secname+"/orbit_Period",-1 e100).toDouble(); period = pd.value(secname+"/orbit_Period",-1 e100).toDouble();
if (period <= -1e100) { if (period <= -1e100) {
meanMotion = (eccentricity == 1.0) meanMotion = (eccentricity == 1.0)
? 0.01720209 ? 0.01720209
895 * (1.5/pericenterDistance) 895 * (1.5/pericenterDistance) * sqrt(0.5/pericenterDistance)
* sqrt(0.5/pericenterDistance)
: (semi_majo r_axis > 0.0) : (semi_majo r_axis > 0.0)
? 0.01720209 895 / (semi_major_axis*sqrt(semi_major_axis)) ? 0.01720209 895 / (semi_major_axis*sqrt(semi_major_axis))
: 0.01720209 895 / (-semi_major_axis*sqrt(-semi_major_axis)); : 0.01720209 895 / (-semi_major_axis*sqrt(-semi_major_axis));
period = 2.0*M_PI/meanMotion; period = 2.0*M_PI/meanMotion;
} else { } else {
meanMotion = 2.0*M_PI/period; meanMotion = 2.0*M_PI/period;
} }
} else { } else {
period = 2.0*M_PI/meanMotion; period = 2.0*M_PI/meanMotion;
} }
skipping to change at line 480 skipping to change at line 480
const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c _obl,s_obl); const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c _obl,s_obl);
const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s _obl,c_obl); const Vec3d OrbitPole( s_nod*s_obl,-c_nod*s _obl,c_obl);
const Vec3d J2000Pole(StelCore::matJ2000ToVs op87.multiplyWithoutTranslation(Vec3d(0,0,1))); const Vec3d J2000Pole(StelCore::matJ2000ToVs op87.multiplyWithoutTranslation(Vec3d(0,0,1)));
Vec3d J2000NodeOrigin(J2000Pole^OrbitPole); Vec3d J2000NodeOrigin(J2000Pole^OrbitPole);
J2000NodeOrigin.normalize(); J2000NodeOrigin.normalize();
parent_rot_j2000_longitude = atan2(J2000Node Origin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0); parent_rot_j2000_longitude = atan2(J2000Node Origin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
} }
// Create an elliptical orbit // Create an elliptical orbit
EllipticalOrbit *orb = new EllipticalOrbit(pericente rDistance, EllipticalOrbit *orb = new EllipticalOrbit(pericente rDistance,
eccentric
eccentricity, ity,
inclinati
inclination, on,
ascending
ascending_node, _node,
arg_of_pe
arg_of_pericenter, ricenter,
mean_anom
mean_anomaly, aly,
period,
period, epoch,
parentRot
epoch, Obliquity,
parent_ro
parentRotObliquity, t_asc_node,
parent_ro
parent_rot_asc_node, t_j2000_longitude);
parent_rot_j2000_longitude);
orbits.push_back(orb); orbits.push_back(orb);
userDataPtr = orb; userDataPtr = orb;
posfunc = &ellipticalOrbitPosFunc; posfunc = &ellipticalOrbitPosFunc;
} }
else if (funcName=="comet_orbit") else if (funcName=="comet_orbit")
{ {
// Read the orbital elements // Read the orbital elements
// orbit_PericenterDistance,orbit_SemiMajorAxis: giv en in AU // orbit_PericenterDistance,orbit_SemiMajorAxis: giv en in AU
// orbit_MeanMotion: given in degrees/day // orbit_MeanMotion: given in degrees/day
skipping to change at line 535 skipping to change at line 535
const double period = pd.value(secname+"/orb it_Period",-1e100).toDouble(); const double period = pd.value(secname+"/orb it_Period",-1e100).toDouble();
if (period <= -1e100) { if (period <= -1e100) {
if (parent->getParent()) { if (parent->getParent()) {
qWarning() << "ERROR: " << e nglishName qWarning() << "ERROR: " << e nglishName
<< ": when the paren t body is not the sun, you must provide " << ": when the paren t body is not the sun, you must provide "
<< "either orbit_Mea nMotion or orbit_Period"; << "either orbit_Mea nMotion or orbit_Period";
} else { } else {
// in case of parent=sun: us e Gaussian gravitational constant // in case of parent=sun: us e Gaussian gravitational constant
// for calculating meanMotio n: // for calculating meanMotio n:
meanMotion = (eccentricity = = 1.0) meanMotion = (eccentricity = = 1.0)
? 0. ? 0.
01720209895 * (1.5/pericenterDistance) 01720209895 * (1.5/pericenterDistance) * sqrt(0.5/pericenterDistance)
* sqrt(0.5/pericenterDistance)
: (s emi_major_axis > 0.0) : (s emi_major_axis > 0.0)
? 0. 01720209895 / (semi_major_axis*sqrt(semi_major_axis)) ? 0. 01720209895 / (semi_major_axis*sqrt(semi_major_axis))
: 0. 01720209895 / (-semi_major_axis*sqrt(-semi_major_axis)); : 0. 01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
} }
} else { } else {
meanMotion = 2.0*M_PI/period; meanMotion = 2.0*M_PI/period;
} }
} else { } else {
meanMotion *= (M_PI/180.0); meanMotion *= (M_PI/180.0);
} }
skipping to change at line 565 skipping to change at line 564
//abort(); //abort();
continue; continue;
} else { } else {
mean_anomaly *= (M_PI/180.0); mean_anomaly *= (M_PI/180.0);
time_at_pericenter = epoch - mean_an omaly / meanMotion; time_at_pericenter = epoch - mean_an omaly / meanMotion;
} }
} }
const double inclination = pd.value(secname+"/orbit_ Inclination").toDouble()*(M_PI/180.0); const double inclination = pd.value(secname+"/orbit_ Inclination").toDouble()*(M_PI/180.0);
const double arg_of_pericenter = pd.value(secname+"/ orbit_ArgOfPericenter").toDouble()*(M_PI/180.0); const double arg_of_pericenter = pd.value(secname+"/ orbit_ArgOfPericenter").toDouble()*(M_PI/180.0);
const double ascending_node = pd.value(secname+"/orb it_AscendingNode").toDouble()*(M_PI/180.0); const double ascending_node = pd.value(secname+"/orb it_AscendingNode").toDouble()*(M_PI/180.0);
const double parentRotObliquity = parent->getParent( const double parentRotObliquity = parent->getParent(
) ) ? parent->getRotObliquity() : 0.0;
const double parent_rot_asc_node = parent->getParent
? parent->getRotObliquity() () ? parent->getRotAscendingnode() : 0.0;
: 0.0;
const double parent_rot_asc_node = parent->getParent
()
? parent->getRotAscendingnode()
: 0.0;
double parent_rot_j2000_longitude = 0.0; double parent_rot_j2000_longitude = 0.0;
if (parent->getParent()) { if (parent->getParent()) {
const double c_obl = cos( const double c_obl =
parentRotObliquity); cos(parentRotObliquity);
const double s_obl = sin( const double s_obl =
parentRotObliquity); sin(parentRotObliquity);
const double c_nod = cos( const double c_nod =
parent_rot_asc_node); cos(parent_rot_asc_node);
const double s_nod = sin( const double s_nod =
parent_rot_asc_node); sin(parent_rot_asc_node);
const Vec3d OrbitAxis0( c const Vec3d OrbitAxi
_nod, s_nod, 0.0); s0( c_nod, s_nod, 0.0);
const Vec3d OrbitAxis1(-s const Vec3d OrbitAxi
_nod*c_obl, c_nod*c_obl,s_obl); s1(-s_nod*c_obl, c_nod*c_obl,s_obl);
const Vec3d OrbitPole( s const Vec3d OrbitPol
_nod*s_obl,-c_nod*s_obl,c_obl); e( s_nod*s_obl,-c_nod*s_obl,c_obl);
const Vec3d J2000Pole(Ste const Vec3d J2000Pol
lCore::matJ2000ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1))); e(StelCore::matJ2000ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1)));
Vec3d J2000NodeOrigin(J20 Vec3d J2000NodeOrigi
00Pole^OrbitPole); n(J2000Pole^OrbitPole);
J2000NodeOrigin.normalize J2000NodeOrigin.norm
(); alize();
parent_rot_j2000_longitud parent_rot_j2000_lon
e = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0); gitude = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
} }
CometOrbit *orb = new CometOrbit(pericenterDistance, CometOrbit *orb = new CometOrbit(pericenterDistance,
eccentricity,
eccentricity, inclination,
ascending_node,
inclination, arg_of_pericenter,
time_at_pericenter,
ascending_node, meanMotion,
parentRotObliquity,
arg_of_pericenter, parent_rot_asc_node
,
time_at_pericenter, parent_rot_j2000_lo
ngitude);
meanMotion,
parentRotObliquity,
parent_rot_asc_node,
parent_rot_j2000_longitude);
orbits.push_back(orb); orbits.push_back(orb);
userDataPtr = orb; userDataPtr = orb;
posfunc = &cometOrbitPosFunc; posfunc = &cometOrbitPosFunc;
} }
if (funcName=="sun_special") if (funcName=="sun_special")
posfunc = &get_sun_helio_coordsv; posfunc = &get_sun_helio_coordsv;
if (funcName=="mercury_special") { if (funcName=="mercury_special") {
posfunc = &get_mercury_helio_coordsv; posfunc = &get_mercury_helio_coordsv;
skipping to change at line 880 skipping to change at line 875
Ring *r = new Ring(rMin,rMax,pd.value(secname+"/tex_ ring").toString()); Ring *r = new Ring(rMin,rMax,pd.value(secname+"/tex_ ring").toString());
p->setRings(r); p->setRings(r);
} }
systemPlanets.push_back(p); systemPlanets.push_back(p);
readOk++; readOk++;
} }
if (systemPlanets.isEmpty()) if (systemPlanets.isEmpty())
{ {
qWarning() << "No Solar System objects loaded from" << fileP ath; qWarning() << "No Solar System objects loaded from" << QDir: :toNativeSeparators(filePath);
return false; return false;
} }
qDebug() << "Loaded" << readOk << "/" << totalPlanets << "planet orb its from" << filePath; qDebug() << "Loaded" << readOk << "/" << totalPlanets << "planet orb its from" << QDir::toNativeSeparators(filePath);
return true; return true;
} }
// Compute the position for every elements of the solar system. // Compute the position for every elements of the solar system.
// The order is not important since the position is computed relatively to the mother body // The order is not important since the position is computed relatively to the mother body
void SolarSystem::computePositions(double date, const Vec3d& observerPos) void SolarSystem::computePositions(double date, const Vec3d& observerPos)
{ {
if (flagLightTravelTime) if (flagLightTravelTime)
{ {
foreach (PlanetP p, systemPlanets) foreach (PlanetP p, systemPlanets)
skipping to change at line 1372 skipping to change at line 1367
return 1; return 1;
} }
//! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name //! Find and return the list of at most maxNbItem objects auto-completing t he passed object I18n name
QStringList SolarSystem::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const QStringList SolarSystem::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) if (maxNbItem==0)
return result; return result;
QString objw = objPrefix.toUpper();
QString sson;
foreach (const PlanetP& p, systemPlanets) foreach (const PlanetP& p, systemPlanets)
{ {
QString constw = p->getNameI18n().mid(0, objw.size()).toUppe sson = p->getNameI18n();
r(); if (sson.contains(objPrefix, Qt::CaseInsensitive))
if (constw==objw)
{ {
result << p->getNameI18n(); result << sson;
if (result.size()==maxNbItem) if (result.size()==maxNbItem)
return result; return result;
} }
} }
return result; return result;
} }
//! Find and return the list of at most maxNbItem objects auto-completing t he passed object English name //! Find and return the list of at most maxNbItem objects auto-completing t he passed object English name
QStringList SolarSystem::listMatchingObjects(const QString& objPrefix, int maxNbItem) const QStringList SolarSystem::listMatchingObjects(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) if (maxNbItem==0)
return result; return result;
QString objw = objPrefix.toUpper();
QString sson;
foreach (const PlanetP& p, systemPlanets) foreach (const PlanetP& p, systemPlanets)
{ {
QString constw = p->getEnglishName().mid(0, objw.size()).toU sson = p->getEnglishName();
pper(); if (sson.contains(objPrefix, Qt::CaseInsensitive))
if (constw==objw)
{ {
result << p->getEnglishName(); result << sson;
if (result.size()==maxNbItem) if (result.size()==maxNbItem)
return result; return result;
} }
} }
return result; return result;
} }
QStringList SolarSystem::listAllObjects(bool inEnglish) const QStringList SolarSystem::listAllObjects(bool inEnglish) const
{ {
QStringList result; QStringList result;
 End of changes. 18 change blocks. 
95 lines changed or deleted 75 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/