1 /* 2 * The big star catalogue extension to Stellarium: 3 * Author and Copyright: Johannes Gajdosik, 2006, 2007 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 */ 19 20 #ifndef STARWRAPPER_HPP 21 #define STARWRAPPER_HPP 22 23 #include "StelObject.hpp" 24 #include "StelApp.hpp" 25 #include "StelCore.hpp" 26 #include "StarMgr.hpp" 27 #include "Star.hpp" 28 #include "StelSkyDrawer.hpp" 29 #include "Planet.hpp" 30 #include "StelUtils.hpp" 31 32 #include <QString> 33 34 template <class Star> class SpecialZoneArray; 35 template <class Star> struct SpecialZoneData; 36 37 38 //! @class StarWrapperBase 39 //! A Star (Star1,Star2,Star3,...) cannot be a StelObject. The additional 40 //! overhead of having a dynamic type would simply be too much. 41 //! Therefore the StarWrapper is needed when returning Stars as StelObjects, e.g. for searching, and for constellations. 42 //! The StarWrapper is destroyed when it is not needed anymore, by utilizing reference counting. 43 //! So there is no chance that more than a few hundreds of StarWrappers are alive simultanousely. 44 //! Another reason for having the StarWrapper is to encapsulate the differences between the different kinds of Stars (Star1,Star2,Star3). 45 class StarWrapperBase : public StelObject 46 { 47 protected: StarWrapperBase(void)48 StarWrapperBase(void) : ref_count(0) {;} ~StarWrapperBase(void)49 virtual ~StarWrapperBase(void) {;} getType(void) const50 virtual QString getType(void) const Q_DECL_OVERRIDE {return STAR_TYPE;} 51 getEnglishName(void) const52 virtual QString getEnglishName(void) const Q_DECL_OVERRIDE {return QString();} 53 virtual QString getNameI18n(void) const Q_DECL_OVERRIDE = 0; 54 55 //! StarWrapperBase supports the following InfoStringGroup flags <ul> 56 //! <li> Name 57 //! <li> Magnitude 58 //! <li> RaDecJ2000 59 //! <li> RaDec 60 //! <li> AltAzi 61 //! <li> PlainText </ul> 62 //! @param core the StelCore object 63 //! @param flags a set of InfoStringGroup items to include in the return value. 64 //! @return a QString containing an HTML encoded description of the StarWrapperBase. 65 virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const Q_DECL_OVERRIDE; 66 virtual float getBV(void) const = 0; 67 68 private: 69 int ref_count; 70 }; 71 72 template <class Star> class StarWrapper : public StarWrapperBase 73 { 74 protected: StarWrapper(const SpecialZoneArray<Star> * a,const SpecialZoneData<Star> * z,const Star * s)75 StarWrapper(const SpecialZoneArray<Star> *a, 76 const SpecialZoneData<Star> *z, 77 const Star *s) : a(a), z(z), s(s) {;} getJ2000EquatorialPos(const StelCore * core) const78 virtual Vec3d getJ2000EquatorialPos(const StelCore* core) const Q_DECL_OVERRIDE 79 { 80 static const double d2000 = 2451545.0; 81 Vec3f v; 82 s->getJ2000Pos(z, (M_PI/180.)*(0.0001/3600.) * ((core->getJDE()-d2000)/365.25) / a->star_position_scale, v); 83 84 // Aberration: Explanatory Supplement 2013, (7.38). We must get the observer planet speed vector in Equatorial J2000 coordinates. 85 if (core->getUseAberration()) 86 { 87 Vec3d vel=core->getCurrentPlanet()->getHeliocentricEclipticVelocity(); 88 vel=StelCore::matVsop87ToJ2000*vel*core->getAberrationFactor()*(AU/(86400.0*SPEED_OF_LIGHT)); 89 //Q_ASSERT_X(fabs(v.lengthSquared()-1.0f)<0.0001f, "StarWrapper aberration", "vertex length not unity"); 90 v.normalize(); // Required? YES! 91 Vec3d pos=v.toVec3d()+vel; 92 pos.normalize(); 93 return pos; 94 } 95 else 96 { 97 return v.toVec3d(); 98 } 99 } getInfoColor(void) const100 virtual Vec3f getInfoColor(void) const Q_DECL_OVERRIDE 101 { 102 return StelSkyDrawer::indexToColor(s->getBVIndex()); 103 } getVMagnitude(const StelCore * core) const104 virtual float getVMagnitude(const StelCore* core) const Q_DECL_OVERRIDE 105 { 106 Q_UNUSED(core); 107 return 0.001f*a->mag_min + s->getMag()*(0.001f*a->mag_range)/a->mag_steps; 108 } getBV(void) const109 virtual float getBV(void) const Q_DECL_OVERRIDE {return s->getBV();} getEnglishName(void) const110 virtual QString getEnglishName(void) const Q_DECL_OVERRIDE {return QString();} getNameI18n(void) const111 virtual QString getNameI18n(void) const Q_DECL_OVERRIDE {return s->getNameI18n();} getAngularSize(const StelCore *) const112 virtual double getAngularSize(const StelCore*) const Q_DECL_OVERRIDE {return 0.;} 113 protected: 114 const SpecialZoneArray<Star> *const a; 115 const SpecialZoneData<Star> *const z; 116 const Star *const s; 117 }; 118 119 120 class StarWrapper1 : public StarWrapper<Star1> 121 { 122 public: StarWrapper1(const SpecialZoneArray<Star1> * a,const SpecialZoneData<Star1> * z,const Star1 * s)123 StarWrapper1(const SpecialZoneArray<Star1> *a, 124 const SpecialZoneData<Star1> *z, 125 const Star1 *s) : StarWrapper<Star1>(a,z,s) {;} 126 127 //! StarWrapper1 supports the following InfoStringGroup flags: <ul> 128 //! <li> Name 129 //! <li> CatalogNumber 130 //! <li> Magnitude 131 //! <li> RaDecJ2000 132 //! <li> RaDec 133 //! <li> AltAzi 134 //! <li> Extra (spectral type, parallax) 135 //! <li> Distance 136 //! <li> PlainText </ul> 137 //! @param core the StelCore object. 138 //! @param flags a set of InfoStringGroup items to include in the return value. 139 //! @return a QString containing an HMTL encoded description of the StarWrapper1. 140 virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const Q_DECL_OVERRIDE; 141 //! In addition to the entries from StelObject::getInfoMap(), StarWrapper1 objects provide 142 //! - variable-star (no|eruptive|pulsating|rotating|cataclysmic|eclipsing-binary) 143 //! - star-type (star|double-star) 144 //! - bV : B-V Color Index 145 //! A few tags are only present if data known, or for variable or double stars from the WDS catalog 146 //! - absolute-mag 147 //! - distance-ly 148 //! - parallax 149 //! - spectral-class 150 //! - period (days) 151 //! - wds-year (year of validity of wds... fields) 152 //! - wds-position-angle 153 //! - wds-separation (arcseconds; 0 for spectroscopic binaries) 154 virtual QVariantMap getInfoMap(const StelCore *core) const Q_DECL_OVERRIDE; 155 virtual QString getEnglishName(void) const Q_DECL_OVERRIDE; 156 virtual QString getID(void) const Q_DECL_OVERRIDE; 157 }; 158 159 class StarWrapper2 : public StarWrapper<Star2> 160 { 161 public: StarWrapper2(const SpecialZoneArray<Star2> * a,const SpecialZoneData<Star2> * z,const Star2 * s)162 StarWrapper2(const SpecialZoneArray<Star2> *a, 163 const SpecialZoneData<Star2> *z, 164 const Star2 *s) : StarWrapper<Star2>(a,z,s) {;} getID(void) const165 virtual QString getID(void) const Q_DECL_OVERRIDE { return QString(); } 166 }; 167 168 class StarWrapper3 : public StarWrapper<Star3> 169 { 170 public: StarWrapper3(const SpecialZoneArray<Star3> * a,const SpecialZoneData<Star3> * z,const Star3 * s)171 StarWrapper3(const SpecialZoneArray<Star3> *a, 172 const SpecialZoneData<Star3> *z, 173 const Star3 *s) : StarWrapper<Star3>(a,z,s) {;} getID(void) const174 virtual QString getID(void) const Q_DECL_OVERRIDE { return QString(); } 175 }; 176 177 178 #endif // STARWRAPPER_HPP 179