Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

modules/StarWrapper.hpp

00001 /*
00002  * The big star catalogue extension to Stellarium:
00003  * Author and Copyright: Johannes Gajdosik, 2006, 2007
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019 
00020 #ifndef _STARWRAPPER_HPP_
00021 #define _STARWRAPPER_HPP_
00022 
00023 #include <QString>
00024 #include "StelObject.hpp"
00025 #include "StelApp.hpp"
00026 #include "StelNavigator.hpp"
00027 #include "StarMgr.hpp"
00028 #include "Star.hpp"
00029 #include "StelSkyDrawer.hpp"
00030 
00031 namespace BigStarCatalogExtension {
00032 
00033 template <class Star> struct SpecialZoneArray;
00034 template <class Star> struct SpecialZoneData;
00035 
00036 
00037 // A Star (Star1,Star2,Star3,...) cannot be a StelObject. The additional
00038 // overhead of having a dynamic type would simply be too much.
00039 // Therefore the StarWrapper is needed when returning Stars as StelObjects,
00040 // e.g. for searching, and for constellations.
00041 // The StarWrapper is destroyed when it is not needed anymore, by utilizing
00042 // reference counting and boost::intrusive_ptr. So there is no chance that
00043 // more than a few hundreds of StarWrappers are alive simultanousely.
00044 // Another reason for having the StarWrapper is to encapsulate the differences
00045 // between the different kinds of Stars (Star1,Star2,Star3).
00046 
00047 
00048 class StarWrapperBase : public StelObject {
00049 protected:
00050   StarWrapperBase(void) : ref_count(0) {}
00051   virtual ~StarWrapperBase(void) {}
00052   QString getType(void) const {return "Star";}
00053 
00054   QString getEnglishName(void) const {return "";}
00055   QString getNameI18n(void) const = 0;
00056 
00057 
00069   QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
00070   virtual float getBV(void) const = 0;
00071 private:
00072   int ref_count;
00073   void retain(void) {Q_ASSERT(ref_count>=0);ref_count++;}
00074   void release(void) {Q_ASSERT(ref_count>0);if (--ref_count==0) delete this;}
00075 };
00076 
00077 template <class Star>
00078 class StarWrapper : public StarWrapperBase {
00079 protected:
00080   StarWrapper(const SpecialZoneArray<Star> *a,
00081               const SpecialZoneData<Star> *z,
00082               const Star *s) : a(a),z(z),s(s) {}
00083   Vec3d getJ2000EquatorialPos(const StelNavigator*) const {
00084     const double d2000 = 2451545.0;
00085     return s->getJ2000Pos(z,
00086                   (M_PI/180)*(0.0001/3600)
00087                    * ((StarMgr::getCurrentJDay()-d2000)/365.25)
00088                    / a->star_position_scale
00089                  );
00090   }
00091   Vec3f getInfoColor(void) const {return StelApp::getInstance().getVisionModeNight() ? Vec3f(0.8, 0.2, 0.2) : StelSkyDrawer::indexToColor(s->bV);}
00092   float getVMagnitude(const StelNavigator *nav) const
00093     {return 0.001f*a->mag_min + s->mag*(0.001f*a->mag_range)/a->mag_steps;}
00094   float getSelectPriority(const StelNavigator *nav) const
00095   {
00096     return getVMagnitude(nav);
00097   }
00098   float getBV(void) const {return s->getBV();}
00099   QString getEnglishName(void) const {
00100     return "";
00101   }
00102   QString getNameI18n(void) const {
00103     return s->getNameI18n();
00104   }
00105   virtual double getAngularSize(const StelCore* core) const {return 0.;}
00106 protected:
00107   const SpecialZoneArray<Star> *const a;
00108   const SpecialZoneData<Star> *const z;
00109   const Star *const s;
00110 };
00111 
00112 
00113 class StarWrapper1 : public StarWrapper<Star1> {
00114 public:
00115   StarWrapper1(const SpecialZoneArray<Star1> *a,
00116                const SpecialZoneData<Star1> *z,
00117                const Star1 *s) : StarWrapper<Star1>(a,z,s) {}
00132   QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
00133   QString getEnglishName(void) const;
00134 };
00135 
00136 class StarWrapper2 : public StarWrapper<Star2> {
00137 public:
00138   StarWrapper2(const SpecialZoneArray<Star2> *a,
00139                const SpecialZoneData<Star2> *z,
00140                const Star2 *s) : StarWrapper<Star2>(a,z,s) {}
00141 };
00142 
00143 class StarWrapper3 : public StarWrapper<Star3> {
00144 public:
00145   StarWrapper3(const SpecialZoneArray<Star3> *a,
00146                const SpecialZoneData<Star3> *z,
00147                const Star3 *s) : StarWrapper<Star3>(a,z,s) {}
00148 };
00149 
00150 } // namespace BigStarCatalogExtension
00151 
00152 #endif // _STARWRAPPER_HPP_

Generated on Mon Feb 2 17:23:47 2009 for Stellarium by  doxygen 1.5.5