1 /*
2  * Stellarium: Meteor Showers Plug-in
3  * Copyright (C) 2013-2015 Marcos Cardinot
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 METEORSHOWER_HPP
21 #define METEORSHOWER_HPP
22 
23 #include "MeteorObj.hpp"
24 #include "MeteorShowersMgr.hpp"
25 #include "StelFader.hpp"
26 #include "StelObject.hpp"
27 #include "StelPainter.hpp"
28 #include "StelTextureTypes.hpp"
29 #include "StelTranslator.hpp"
30 
31 //! @class MeteorShower
32 //! A MeteorShower object represents one meteor shower on the sky.
33 //! Details about the meteor showers are passed using a QVariant which contains
34 //! a map of data from the json file.
35 //! @ingroup meteorShowers
36 
37 class MeteorShower : public StelObject
38 {
39 public:
40 	static const QString METEORSHOWER_TYPE;
41 
42 	//! @enum Meteor Shower status.
43 	enum Status {
44 		INVALID,          // not initialized properly
45 		UNDEFINED,        // it's loaded but with 'activity' undefined
46 		INACTIVE,         // inactive radiant
47 		ACTIVE_CONFIRMED, // active radiant - confirmed data
48 		ACTIVE_GENERIC    // active radiant - generic data
49 	};
50 
51 	//! @struct Activity
52 	struct Activity
53 	{
54 		int year;                  //! The catalog year (0 for generic)
55 		int zhr;                   //! The ZHR on peak
56 		QList<int> variable;       //! The ZHR range when it's variable
57 		QDate start;               //! Initial date of activity
58 		QDate finish;              //! Last date of activity
59 		QDate peak;                //! Peak activity
60 	};
61 
62 	//! Constructor
63 	//! @param map QVariantMap containing all the data about a Meteor Shower.
64 	MeteorShower(MeteorShowersMgr* mgr, const QVariantMap& map);
65 
66 	//! Destructor
67 	~MeteorShower() Q_DECL_OVERRIDE;
68 
69 	//! Update
70 	//! @param deltaTime the time increment in seconds since the last call.
71 	void update(StelCore *core, double deltaTime);
72 
73 	//! Draw
74 	void draw(StelCore *core);
75 
76 	//! Checks if we have generic data for a given date
77 	//! @param date QDate
78 	//! @return Activity
79 	Activity hasGenericShower(QDate date, bool &found) const;
80 
81 	//! Checks if we have confirmed data for a given date
82 	//! @param date QDate
83 	//! @return Activity
84 	Activity hasConfirmedShower(QDate date, bool &found) const;
85 
86 	//! Checks if this meteor shower is being displayed or not
87 	//! @return true if it's being displayed
88 	bool enabled() const;
89 
90 	//! Gets the meteor shower id
91 	//! //! @return designation
92 	QString getDesignation() const;
93 
94 	//! Gets the current meteor shower status
95 	//! @return status
getStatus()96 	Status getStatus() { return m_status; }
97 
98 	//! Gets the peak
99 	//! @return peak
getPeak()100 	QDate getPeak() { return m_activity.peak; }
101 
102 	//! Gets the current ZHR
103 	//! @return ZHR
getZHR()104 	int getZHR() { return m_activity.zhr; }
105 
106 	//
107 	// Methods defined in StelObject class
108 	//
109 	virtual QString getInfoString(const StelCore* core, const InfoStringGroup& flags) const Q_DECL_OVERRIDE;
110 
111 	//! Return a map like StelObject, but with a few extra tags:
112 	// TODO: Describe the fields!
113 	//! - status
114 	//! - id
115 	//! - type (translated string "meteor shower")
116 	//! - speed (km/s)
117 	//! - pop-idx (population index)
118 	//! - parent
119 	//! - zhr-max (information string)
120 	virtual QVariantMap getInfoMap(const StelCore *core) const Q_DECL_OVERRIDE;
getType(void) const121 	virtual QString getType(void) const Q_DECL_OVERRIDE { return METEORSHOWER_TYPE; }
getID(void) const122 	virtual QString getID(void) const Q_DECL_OVERRIDE { return m_showerID; }
getEnglishName(void) const123 	virtual QString getEnglishName(void) const Q_DECL_OVERRIDE { return m_designation.trimmed(); }
getNameI18n(void) const124 	virtual QString getNameI18n(void) const Q_DECL_OVERRIDE	{ return q_(m_designation.trimmed()); }
getJ2000EquatorialPos(const StelCore *) const125 	virtual Vec3d getJ2000EquatorialPos(const StelCore*) const Q_DECL_OVERRIDE { return m_position; }
getSelectPriority(const StelCore *) const126 	virtual float getSelectPriority(const StelCore*) const Q_DECL_OVERRIDE { return -4.0; }
127 	virtual Vec3f getInfoColor(void) const Q_DECL_OVERRIDE;
getAngularSize(const StelCore *) const128 	virtual double getAngularSize(const StelCore*) const Q_DECL_OVERRIDE { return 0.001; }
129 
130 private:
131 	MeteorShowersMgr* m_mgr;           //! MeteorShowersMgr instance
132 	Status m_status;                   //! Meteor shower status
133 
134 	// data from catalog
135 	QString m_showerID;                //! The ID of the meteor shower
136 	QString m_designation;             //! The designation of the meteor shower
137 	QList<Activity> m_activities;      //! Activity list
138 	int m_speed;                       //! Speed of meteors
139 	float m_rAlphaPeak;                //! R.A. for radiant of meteor shower on the peak day
140 	float m_rDeltaPeak;                //! Dec. for radiant of meteor shower on the peak day
141 	float m_driftAlpha;                //! Drift of R.A. for each day from peak
142 	float m_driftDelta;                //! Drift of Dec. for each day from peak
143 	QString m_parentObj;               //! Parent object for meteor shower
144 	float m_pidx;                      //! The population index
145 	QList<Meteor::ColorPair> m_colors; //! <colorName, 0-100>
146 
147 	//current information
148 	Vec3d m_position;                  //! Cartesian equatorial position
149 	double m_radiantAlpha;             //! Current R.A. for radiant of meteor shower
150 	double m_radiantDelta;             //! Current Dec. for radiant of meteor shower
151 	Activity m_activity;               //! Current activity
152 
153 	QList<MeteorObj*> m_activeMeteors; //! List with all the active meteors
154 
155 	//! Draws the radiant
156 	void drawRadiant(StelCore* core);
157 
158 	//! Draws all active meteors
159 	void drawMeteors(StelCore* core);
160 
161 	//! Calculates the ZHR using normal distribution
162 	//! @param current julian day
163 	int calculateZHR(const double& currentJD);
164 
165 	//! Gets the mean solar longitude for a specified date (approximate formula)
166 	//! @param date QDate
167 	//! @return solar longitude in degree
168 	static QString getSolarLongitude(QDate date);
169 };
170 
171 #endif /* METEORSHOWER_HPP */
172