• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

planetcatalog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           planetcatalog.cpp  -  description
00003                              -------------------
00004     begin                : Mon Feb 18 2002
00005     copyright          : (C) 2002 by Mark Hollomon
00006     email                : mhh@mindspring.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <qstring.h>
00019 
00020 #include "planetcatalog.h"
00021 #include "dms.h"
00022 #include "kstarsdata.h"
00023 #include "ksnumbers.h"
00024 #include "ksplanetbase.h"
00025 #include "ksplanet.h"
00026 #include "kssun.h"
00027 #include "kspluto.h"
00028 #include "skypoint.h"
00029 #include "skyobject.h"
00030 #include "objectnamelist.h"
00031 
00032 PlanetCatalog::PlanetCatalog(KStarsData *dat) : Earth(0), Sun(0), kd(dat) {
00033     planets.setAutoDelete(true);
00034 }
00035 
00036 PlanetCatalog::~PlanetCatalog() {
00037     //
00038     // do NOT delete Sun. It is also in the QList
00039     // and will be deleted automatically.
00040     //
00041     delete Earth;
00042 }
00043 
00044 
00045 
00046 bool PlanetCatalog::initialize() {
00047     KSPlanetBase *ksp;
00048 
00049     Earth = new KSPlanet( kd, I18N_NOOP( "Earth" ), "", 12756.28 /*diameter in km*/ );
00050     if (!Earth->loadData())
00051         return false;
00052 
00053     Sun = new KSSun( kd, "sun.png", 1392000. /*diameter in km*/ );
00054     if (Sun->loadData()) {
00055         planets.append(Sun);
00056     }
00057 
00058     ksp = new KSPluto( kd, "pluto.png", 2320. /*diameter in km*/ );
00059     planets.append(ksp);
00060 
00061     ksp = new KSPlanet( kd, I18N_NOOP( "Mercury" ), "mercury.png", 4879.4 /*diameter in km*/ );
00062     if (ksp->loadData()) {
00063         planets.append(ksp);
00064     }
00065 
00066     ksp = new KSPlanet( kd, I18N_NOOP( "Venus" ), "venus.png", 12103.6 /*diameter in km*/ );
00067     if (ksp->loadData()) {
00068         planets.append(ksp);
00069     }
00070 
00071     ksp = new KSPlanet( kd, I18N_NOOP( "Mars" ), "mars.png", 6792.4 /*diameter in km*/ );
00072     if (ksp->loadData()) {
00073         planets.append(ksp);
00074     }
00075 
00076     ksp = new KSPlanet( kd, I18N_NOOP( "Jupiter" ), "jupiter.png", 142984. /*diameter in km*/ );
00077     if (ksp->loadData()) {
00078         planets.append(ksp);
00079     }
00080 
00081     ksp = new KSPlanet( kd, I18N_NOOP( "Saturn" ), "saturn.png", 120536. /*diameter in km*/ );
00082     if (ksp->loadData()) {
00083         planets.append(ksp);
00084     }
00085 
00086     ksp = new KSPlanet( kd, I18N_NOOP( "Uranus" ), "uranus.png", 51118. /*diameter in km*/ );
00087     if (ksp->loadData()) {
00088         planets.append(ksp);
00089     }
00090 
00091     ksp = new KSPlanet( kd, I18N_NOOP( "Neptune" ), "neptune.png", 49572. /*diameter in km*/ );
00092     if (ksp->loadData()) {
00093         planets.append(ksp);
00094     }
00095 
00096     return true;
00097 }
00098 
00099 void PlanetCatalog::addObject( ObjectNameList &ObjNames ) const {
00100     QPtrListIterator<KSPlanetBase> it(planets);
00101 
00102     for (KSPlanetBase *ksp = it.toFirst(); ksp != 0; ksp = ++it) {
00103         ObjNames.append( ksp );
00104     }
00105 }
00106 
00107 void PlanetCatalog::findPosition( const KSNumbers *num, const dms *lat, const dms *LST ) {
00108     Earth->findPosition(num);
00109     for (KSPlanetBase * ksp = planets.first(); ksp != 0; ksp = planets.next()) {
00110         ksp->findPosition(num, lat, LST, Earth);
00111     }
00112 }
00113 
00114 void PlanetCatalog::EquatorialToHorizontal( dms *LST, const dms *lat ) {
00115     for (KSPlanetBase * ksp = planets.first(); ksp != 0; ksp = planets.next()) {
00116         ksp->EquatorialToHorizontal( LST, lat);
00117         if ( ksp->hasTrail() ) ksp->updateTrail( LST, lat );
00118     }
00119 }
00120 
00121 bool PlanetCatalog::isPlanet(SkyObject *so) const {
00122     if (so == Earth)
00123         return true;
00124 
00125     QPtrListIterator<KSPlanetBase> it(planets);
00126 
00127     for (KSPlanetBase *ksp = it.toFirst(); ksp != 0; ksp = ++it) {
00128         if (so == ksp)
00129             return true;
00130     }
00131 
00132     return false;
00133 }
00134 
00135 KSPlanetBase *PlanetCatalog::findByName( const QString n) const {
00136     if (n == "Earth")
00137         return Earth;
00138 
00139     QPtrListIterator<KSPlanetBase> it(planets);
00140 
00141     for (KSPlanetBase *ksp = it.toFirst(); ksp != 0; ksp = ++it) {
00142         if (ksp->name() == n)
00143             return ksp;
00144     }
00145 
00146     kdDebug() << k_funcinfo << "could not find planet named " << n << endl;
00147 
00148     return 0;
00149 }
00150 
00151 static double dist_squared(const SkyPoint *a, const SkyPoint *b) {
00152     double dRA = a->ra()->Hours() - b->ra()->Hours();
00153     double dDec = a->dec()->Degrees() - b->dec()->Degrees();
00154     double f = 15.0*cos( a->dec()->radians() );
00155 
00156     return f*f*dRA*dRA + dDec*dDec;
00157 }
00158 
00159 SkyObject *PlanetCatalog::findClosest(const SkyPoint *p, double &r) const {
00160     QPtrListIterator<KSPlanetBase> it(planets);
00161     SkyObject *found = 0;
00162     double trialr = 0.0;
00163     double rmin = 100000.0;
00164 
00165     for (KSPlanetBase *ksp = it.toFirst(); ksp != 0; ksp = ++it) {
00166         trialr = dist_squared(ksp, p);
00167         if (trialr < rmin) {
00168             rmin = trialr;
00169             found = ksp;
00170         }
00171     }
00172 
00173     r = rmin;
00174     return found;
00175 
00176 }
00177 
00178 #include "planetcatalog.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal