22 #include <QMouseEvent>
23 #include <QVBoxLayout>
24 #include <QTextStream>
26 #include <QPaintEvent>
33 #include <KPlotObject>
36 #include "ui_planetviewer.h"
52 :
KDialog( parent ), scale(1.0), isClockRunning(false), tmr(this)
57 setCaption( i18n(
"Solar System Viewer") );
58 setButtons( KDialog::Close );
61 pw->map->setLimits( -48.0, 48.0, -48.0, 48.0 );
62 pw->map->axis( KPlotWidget::BottomAxis )->setLabel(
i18nc(
"axis label for x-coordinate of solar system viewer. AU means astronomical unit.",
"X-position (AU)" ) );
63 pw->map->axis( KPlotWidget::LeftAxis )->setLabel(
i18nc(
"axis label for y-coordinate of solar system viewer. AU means astronomical unit.",
"Y-position (AU)" ) );
65 pw->TimeStep->setDaysOnly(
true );
66 pw->TimeStep->tsbox()->setValue( 1 );
68 pw->RunButton->setIcon( KIcon(
"arrow-right") );
69 pw->ZoomInButton->setIcon( KIcon(
"zoom-in") );
70 pw->ZoomOutButton->setIcon( KIcon(
"zoom-out") );
71 pw->DateBox->setDate( data->
lt().date() );
74 pw->map->QWidget::setFocus();
80 PlanetList.append(
new KSPlanet(
"Earth" ) );
91 for ( uint i=0; i<9; ++i ) {
92 PlanetList[i]->findPosition( &num, 0, 0 );
93 LastUpdate[i] = int( ut.date().toJulianDay() );
97 UpdateInterval[0] = 0;
98 UpdateInterval[1] = 0;
99 UpdateInterval[2] = 0;
100 UpdateInterval[3] = 1;
101 UpdateInterval[4] = 5;
102 UpdateInterval[5] = 13;
103 UpdateInterval[6] = 38;
104 UpdateInterval[7] = 75;
105 UpdateInterval[8] = 113;
107 QTimer::singleShot( 0,
this, SLOT( initPlotObjects() ) );
109 connect( &tmr, SIGNAL( timeout() ), SLOT( tick() ) );
110 connect( pw->TimeStep, SIGNAL( scaleChanged(
float) ), SLOT( setTimeScale(
float) ) );
111 connect( pw->RunButton, SIGNAL( clicked() ), SLOT( slotRunClock() ) );
112 connect( pw->ZoomInButton, SIGNAL( clicked() ), pw->map, SLOT( slotZoomIn() ) );
113 connect( pw->ZoomOutButton, SIGNAL( clicked() ), pw->map, SLOT( slotZoomOut() ) );
114 connect( pw->DateBox, SIGNAL( dateChanged(
const QDate&) ), SLOT( slotChangeDate() ) );
115 connect( pw->TodayButton, SIGNAL( clicked() ), SLOT( slotToday() ) );
116 connect(
this, SIGNAL( closeClicked() ), SLOT( slotCloseWindow() ) );
124 return PlanetList[i]->name();
127 void PlanetViewer::tick() {
129 ut.setDJD( ut.djd() + scale*0.1 );
130 pw->DateBox->setDate( ut.date() );
135 void PlanetViewer::setTimeScale(
float f) {
139 void PlanetViewer::slotRunClock() {
140 isClockRunning = !isClockRunning;
142 if ( isClockRunning ) {
143 pw->RunButton->setIcon( KIcon(
"media-playback-pause") );
147 pw->RunButton->setIcon( KIcon(
"arrow-right") );
153 void PlanetViewer::slotChangeDate() {
154 ut.setDate( pw->DateBox->date() );
158 void PlanetViewer::slotCloseWindow() {
160 if ( isClockRunning ) {
162 isClockRunning =
false;
166 void PlanetViewer::updatePlanets() {
171 for (
unsigned int i=0; i<9; ++i ) {
172 if ( abs(
int(ut.date().toJulianDay()) - LastUpdate[i] ) > UpdateInterval[i] ) {
180 points.at(0)->setX( p->
rsun()*c*c2 );
181 points.at(0)->setY( p->
rsun()*s*c2 );
183 if ( centerPlanet() == p->
name() ) {
184 QRectF dataRect = pw->map->dataRect();
185 double xc = (dataRect.right() + dataRect.left())*0.5;
186 double yc = (dataRect.bottom() + dataRect.top())*0.5;
187 double dx = points.at(0)->x() - xc;
188 double dy = points.at(0)->y() - yc;
189 pw->map->setLimits( dataRect.x() + dx, dataRect.right() + dx,
190 dataRect.y() + dy, dataRect.bottom() + dy );
193 LastUpdate[i] = int(ut.date().toJulianDay());
198 if ( changed ) pw->map->update();
201 void PlanetViewer::slotToday() {
209 void PlanetViewer::initPlotObjects() {
211 ksun =
new KPlotObject( Qt::yellow, KPlotObject::Points, 12, KPlotObject::Circle );
212 ksun->addPoint( 0.0, 0.0 );
213 pw->map->addPlotObject( ksun );
216 KPlotObject *orbit[9];
217 for (
unsigned int i=0; i<9; ++i ) {
219 orbit[i] =
new KPlotObject( Qt::white, KPlotObject::Lines, 1.0 );
222 QString orbitFileName = ( p->
isMajorPlanet() ? ((
KSPlanet *)p)->untranslatedName().toLower() : p->
name().toLower() ) +
".orbit";
226 while ( fileReader.hasMoreLines() ) {
227 QString line = fileReader.readLine();
228 QStringList fields = line.split(
' ', QString::SkipEmptyParts );
229 if ( fields.size() == 3 ) {
230 x = fields[0].toDouble();
231 y = fields[1].toDouble();
232 orbit[i]->addPoint( x, y );
237 pw->map->addPlotObject( orbit[i] );
240 for (
unsigned int i=0; i<9; ++i ) {
242 planet[i] =
new KPlotObject( p->
color(), KPlotObject::Points, 6, KPlotObject::Circle );
248 pw->map->addPlotObject( planet[i] );
255 if( e->key() == Qt::Key_Escape )
261 #include "planetviewer.moc"
void findPosition(const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth=0)
Find position, including correction for Figure-of-the-Earth.
KStarsData is the backbone of KStars.
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
QString translatedName() const
const dms & helEcLat() const
static KStarsData * Instance()
QString planetName(uint i) const
bool openDataFile(QFile &file, const QString &filename)
Attempt to open the data file named filename, using the QFile object "file".
void setCenterPlanet(const QString &cp)
static KSPlanetBase * createPlanet(int n)
const KStarsDateTime & lt() const
i18nc("string from libindi, used in the config dialog","100x")
bool isMajorPlanet() const
PlanetViewer(QWidget *parent=0)
const dms & helEcLong() const
There are several time-dependent values used in position calculations, that are not specific to an ob...
virtual void paintEvent(QPaintEvent *)
PlanetViewerUI(QWidget *parent=0)
A subclass of TrailObject that provides additional information needed for most solar system objects...
const KStarsDateTime & ut() const
virtual QString name(void) const
virtual void keyPressEvent(QKeyEvent *e)