Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2066735c authored by Bernhard Beschow's avatar Bernhard Beschow

move sunPosition() calculation to Planet to have planet logic in one place

parent 5c353657
......@@ -10,13 +10,16 @@
//
#include "Planet.h"
#include <QString>
#include "PlanetFactory.h"
#include "MarbleDebug.h"
#include "MarbleGlobal.h"
#include "MarbleColors.h"
#include "src/lib/astro/solarsystem.h"
#include <QDateTime>
#include <QString>
namespace Marble
{
......@@ -158,6 +161,28 @@ QString Planet::id() const
return d->id;
}
void Planet::sunPosition(qreal &lon, qreal &lat, const QDateTime &dateTime) const
{
SolarSystem sys;
sys.setCurrentMJD(
dateTime.date().year(), dateTime.date().month(), dateTime.date().day(),
dateTime.time().hour(), dateTime.time().minute(),
(double)dateTime.time().second());
const QString pname = d->id.at(0).toUpper() + d->id.right(d->id.size() - 1);
QByteArray name = pname.toLatin1();
sys.setCentralBody( name.data() );
double ra = 0.0;
double decl = 0.0;
sys.getSun(ra, decl);
double _lon = 0.0;
double _lat = 0.0;
sys.getPlanetographic(ra, decl, _lon, _lat);
lon = _lon * DEG2RAD;
lat = _lat * DEG2RAD;
}
/* Setter functions */
void Planet::setM_0( qreal M_0 )
......
......@@ -16,6 +16,7 @@
#include <QtGlobal>
class QDateTime;
class QStringList;
class QColor;
......@@ -78,6 +79,15 @@ public:
/** The internal, nonlocalized name of the planet */
QString id() const;
/**
* Fills the longitude and latitude with the planet's sun position.
*
* @param lon the latitude of the sun, in radian
* @param lat the longitude of the sun, in radian
* @param dateTime the time for which the sun position is to be calculated
*/
void sunPosition(qreal &lon, qreal &lat, const QDateTime &dateTime) const;
/* Setter functions */
void setM_0( qreal M_0 );
void setM_1( qreal M_1 );
......
......@@ -22,8 +22,6 @@
#include "MarbleDebug.h"
#include "src/lib/astro/solarsystem.h"
#include <QDateTime>
#include <cmath>
......@@ -47,6 +45,7 @@ public:
m_clock( clock ),
m_planet( planet )
{
planet->sunPosition(m_lon, m_lat, clock->dateTime());
}
qreal m_lon;
......@@ -70,30 +69,6 @@ SunLocator::~SunLocator()
delete d;
}
void SunLocator::updatePosition()
{
QString planetId = d->m_planet->id();
SolarSystem sys;
QDateTime dateTime = d->m_clock->dateTime();
sys.setCurrentMJD(
dateTime.date().year(), dateTime.date().month(), dateTime.date().day(),
dateTime.time().hour(), dateTime.time().minute(),
(double)dateTime.time().second());
QString const pname = planetId.at(0).toUpper() + planetId.right(planetId.size() - 1);
QByteArray name = pname.toLatin1();
sys.setCentralBody( name.data() );
double ra = 0.0;
double decl = 0.0;
sys.getSun( ra, decl );
double lon = 0.0;
double lat = 0.0;
sys.getPlanetographic (ra, decl, lon, lat);
d->m_lon = lon * DEG2RAD;
d->m_lat = lat * DEG2RAD;
}
qreal SunLocator::shading(qreal lon, qreal a, qreal c) const
{
// haversine formula
......@@ -172,7 +147,7 @@ void SunLocator::shadePixelComposite(QRgb &pixcol, const QRgb &dpixcol,
void SunLocator::update()
{
updatePosition();
d->m_planet->sunPosition(d->m_lon, d->m_lat, d->m_clock->dateTime());
emit positionChanged( getLon(), getLat() );
}
......@@ -192,7 +167,7 @@ void SunLocator::setPlanet( const Planet *planet )
mDebug() << "SunLocator::setPlanet(Planet*)";
d->m_planet = planet;
d->m_twilightZone = planet->twilightZone();
updatePosition();
planet->sunPosition(d->m_lon, d->m_lat, d->m_clock->dateTime());
// Initially there might be no planet set.
// In that case we don't want an update.
......
......@@ -53,8 +53,6 @@ class MARBLE_EXPORT SunLocator : public QObject
void positionChanged( qreal lon, qreal lat );
private:
void updatePosition();
SunLocatorPrivate * const d;
Q_DISABLE_COPY( SunLocator )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment