Merge lp:~georg-zotti/stellarium/gz-planet-type-enum into lp:stellarium

Proposed by gzotti
Status: Merged
Merged at revision: 6995
Proposed branch: lp:~georg-zotti/stellarium/gz-planet-type-enum
Merge into: lp:stellarium
Diff against target: 983 lines (+58/-382)
7 files modified
src/core/modules/Comet.cpp (+3/-4)
src/core/modules/Comet.hpp (+16/-16)
src/core/modules/MinorPlanet.cpp (+3/-4)
src/core/modules/MinorPlanet.hpp (+1/-1)
src/core/modules/Planet.cpp (+31/-8)
src/core/modules/Planet.hpp (+0/-346)
src/core/modules/SolarSystem.cpp (+4/-3)
To merge this branch: bzr merge lp:~georg-zotti/stellarium/gz-planet-type-enum
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
gzotti Needs Resubmitting
Review via email: mp+232802@code.launchpad.net

Description of the change

Changed Planet's pType from string to enum. Give a slight speed gain in case of many (thousands) asteroids, and makes the code somewhat cleaner.

To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) wrote :

Need cleanup the code and extend the comments

review: Needs Fixing
6973. By gzotti

pre-merge cleanup

Revision history for this message
gzotti (georg-zotti) wrote :

Don't know which level of commenting should be added? QMaps are used in many classes already, usually sparsely documented.

review: Needs Resubmitting
Revision history for this message
Alexander Wolf (alexwolf) wrote :

It's OK now.

About tStar, tPlanet, etc.... Maybe better use isStar, isPlanet, etc.?

review: Approve
6974. By gzotti

renamed Planet::PlanetType enums

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/modules/Comet.cpp'
2--- src/core/modules/Comet.cpp 2014-08-17 09:28:31 +0000
3+++ src/core/modules/Comet.cpp 2014-08-31 09:14:13 +0000
4@@ -52,7 +52,7 @@
5 OsculatingFunctType *osculatingFunc,
6 bool acloseOrbit,
7 bool hidden,
8- const QString& pType,
9+ const QString& pTypeStr,
10 float dustTailWidthFact, float dustTailLengthFact, float dustTailBrightnessFact)
11 : Planet (englishName,
12 flagLighting,
13@@ -69,7 +69,7 @@
14 hidden,
15 false, //No atmosphere
16 true, //halo
17- pType),
18+ pTypeStr),
19 dustTailWidthFactor(dustTailWidthFact),
20 dustTailLengthFactor(dustTailLengthFact),
21 dustTailBrightnessFactor(dustTailBrightnessFact)
22@@ -142,8 +142,7 @@
23
24 if (flags&ObjectType)
25 {
26- if (pType.length()>0)
27- oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />";
28+ oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />";
29 }
30
31 if (flags&Magnitude)
32
33=== modified file 'src/core/modules/Comet.hpp'
34--- src/core/modules/Comet.hpp 2014-08-17 09:28:31 +0000
35+++ src/core/modules/Comet.hpp 2014-08-31 09:14:13 +0000
36@@ -38,22 +38,22 @@
37 public:
38 friend class SolarSystem; // Solar System initializes static constants.
39 Comet(const QString& englishName,
40- int flagLighting,
41- double radius,
42- double oblateness,
43- Vec3f color,
44- float albedo,
45- const QString& texMapName,
46- posFuncType _coordFunc,
47- void* userDataPtr,
48- OsculatingFunctType *osculatingFunc,
49- bool closeOrbit,
50- bool hidden,
51- const QString &pType,
52- float dustTailWidthFact=1.5f,
53- float dustTailLengthFact=0.4f,
54- float dustTailBrightnessFact=1.5f
55- );
56+ int flagLighting,
57+ double radius,
58+ double oblateness,
59+ Vec3f color,
60+ float albedo,
61+ const QString& texMapName,
62+ posFuncType _coordFunc,
63+ void* userDataPtr,
64+ OsculatingFunctType *osculatingFunc,
65+ bool closeOrbit,
66+ bool hidden,
67+ const QString &pTypeStr,
68+ float dustTailWidthFact=1.5f,
69+ float dustTailLengthFact=0.4f,
70+ float dustTailBrightnessFact=1.5f
71+ );
72
73 virtual ~Comet();
74
75
76=== modified file 'src/core/modules/MinorPlanet.cpp'
77--- src/core/modules/MinorPlanet.cpp 2014-08-16 17:40:45 +0000
78+++ src/core/modules/MinorPlanet.cpp 2014-08-31 09:14:13 +0000
79@@ -45,7 +45,7 @@
80 OsculatingFunctType *osculatingFunc,
81 bool acloseOrbit,
82 bool hidden,
83- const QString &pType)
84+ const QString &pTypeStr)
85 : Planet (englishName,
86 flagLighting,
87 radius,
88@@ -61,7 +61,7 @@
89 hidden,
90 false, //No atmosphere
91 true, //Halo
92- pType)
93+ pTypeStr)
94 {
95 texMapName = atexMapName;
96 lastOrbitJD =0;
97@@ -205,8 +205,7 @@
98
99 if (flags&ObjectType)
100 {
101- if (pType.length()>0)
102- oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />";
103+ oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />";
104 }
105
106 if (flags&Magnitude)
107
108=== modified file 'src/core/modules/MinorPlanet.hpp'
109--- src/core/modules/MinorPlanet.hpp 2014-08-16 17:40:45 +0000
110+++ src/core/modules/MinorPlanet.hpp 2014-08-31 09:14:13 +0000
111@@ -50,7 +50,7 @@
112 OsculatingFunctType *osculatingFunc,
113 bool closeOrbit,
114 bool hidden,
115- const QString &pType);
116+ const QString &pTypeStr);
117
118 ~MinorPlanet();
119
120
121=== modified file 'src/core/modules/Planet.cpp'
122--- src/core/modules/Planet.cpp 2014-08-17 19:41:04 +0000
123+++ src/core/modules/Planet.cpp 2014-08-31 09:14:13 +0000
124@@ -71,7 +71,7 @@
125 bool hidden,
126 bool hasAtmosphere,
127 bool hasHalo,
128- const QString& pType)
129+ const QString& pTypeStr)
130 : englishName(englishName),
131 flagLighting(flagLighting),
132 radius(radius),
133@@ -88,8 +88,7 @@
134 parent(NULL),
135 hidden(hidden),
136 atmosphere(hasAtmosphere),
137- halo(hasHalo),
138- pType(pType)
139+ halo(hasHalo)
140 {
141 texMapName = atexMapName;
142 normalMapName = anormalMapName;
143@@ -100,6 +99,10 @@
144 deltaOrbitJD = 0;
145 distance = 0;
146
147+ // Initialize pType with the key found in pTypeMap, or mark planet type as undefined.
148+ // The latter condition should obviously never happen.
149+ pType=pTypeMap.key(pTypeStr, Planet::isUNDEFINED);
150+
151 eclipticPos=Vec3d(0.,0.,0.);
152 rotLocalToParent = Mat4d::identity();
153 texMap = StelApp::getInstance().getTextureManager().createTextureThread(StelFileMgr::getInstallationDir()+"/textures/"+texMapName, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT));
154@@ -113,6 +116,26 @@
155 flagLabels = true;
156 }
157
158+QMap<Planet::PlanetType, QString> Planet::pTypeMap;
159+
160+// called in SolarSystem::init() before first planet is created. Loads pTypeMap.
161+void Planet::init()
162+{
163+ if (pTypeMap.count() > 0 )
164+ {
165+ // This should never happen. But it's uncritical.
166+ qDebug() << "Planet::init(): Non-empty static map. This is a programming error, but we can fix that.";
167+ pTypeMap.clear();
168+ }
169+ pTypeMap.insert(Planet::isStar, "star");
170+ pTypeMap.insert(Planet::isPlanet, "planet");
171+ pTypeMap.insert(Planet::isMoon, "moon");
172+ pTypeMap.insert(Planet::isAsteroid, "asteroid");
173+ pTypeMap.insert(Planet::isPlutoid, "plutoid");
174+ pTypeMap.insert(Planet::isComet, "comet");
175+ pTypeMap.insert(Planet::isUNDEFINED, "UNDEFINED"); // something must be broken before we ever see this!
176+}
177+
178 Planet::~Planet()
179 {
180 if (rings)
181@@ -142,8 +165,7 @@
182
183 if (flags&ObjectType)
184 {
185- if (pType.length()>0)
186- oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />";
187+ oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />";
188 }
189
190 if (flags&Magnitude)
191@@ -574,7 +596,7 @@
192 if (englishName=="Venus" || englishName=="Uranus" || englishName=="Pluto")
193 sign = -1;
194
195- if (pType.contains("moon"))
196+ if (pType==Planet::isMoon)
197 {
198 // duration of mean solar day on moon are same as synodic month on this moon
199 double a = parent->getSiderealPeriod()/sday;
200@@ -646,7 +668,7 @@
201 {
202 distance = (obsHelioPos-getHeliocentricEclipticPos()).length();
203 // GZ: improve fps by juggling updates for asteroids. They must be fast if close to observer, but can be slow if further away.
204- if (pType == "asteroid")
205+ if (pType == Planet::isAsteroid)
206 deltaJD=distance*StelCore::JD_SECOND;
207 return distance;
208 }
209@@ -870,7 +892,8 @@
210 // GZ: Try to improve speed for minor planets: test if visible at all.
211 // For a full catalog of NEAs (11000 objects), with this and resetting deltaJD according to distance, rendering time went 4.5fps->12fps.
212 // AW: Apply this rule to asteroids only
213- if (((getVMagnitude(core)-1.0f) > core->getSkyDrawer()->getLimitMagnitude()) && pType=="asteroid")
214+ // Note that taking away the asteroids at this stage breaks dim-asteroid occultation of stars!
215+ if (((getVMagnitude(core)-1.0f) > core->getSkyDrawer()->getLimitMagnitude()) && pType==Planet::isAsteroid)
216 {
217 return;
218 }
219
220=== added file 'src/core/modules/Planet.hpp'
221--- src/core/modules/Planet.hpp 1970-01-01 00:00:00 +0000
222+++ src/core/modules/Planet.hpp 2014-08-31 09:14:13 +0000
223@@ -0,0 +1,370 @@
224+/*
225+ * Stellarium
226+ * Copyright (C) 2002 Fabien Chereau
227+ *
228+ * This program is free software; you can redistribute it and/or
229+ * modify it under the terms of the GNU General Public License
230+ * as published by the Free Software Foundation; either version 2
231+ * of the License, or (at your option) any later version.
232+ *
233+ * This program is distributed in the hope that it will be useful,
234+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
235+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
236+ * GNU General Public License for more details.
237+ *
238+ * You should have received a copy of the GNU General Public License
239+ * along with this program; if not, write to the Free Software
240+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
241+ */
242+
243+#ifndef _PLANET_HPP_
244+#define _PLANET_HPP_
245+
246+#include "StelObject.hpp"
247+#include "StelProjector.hpp"
248+#include "VecMath.hpp"
249+#include "StelFader.hpp"
250+#include "StelTextureTypes.hpp"
251+#include "StelProjectorType.hpp"
252+
253+#include <QString>
254+
255+// The callback type for the external position computation function
256+// The last variable is the userData pointer.
257+typedef void (*posFuncType)(double, double*, void*);
258+
259+typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]);
260+
261+// epoch J2000: 12 UT on 1 Jan 2000
262+#define J2000 2451545.0
263+#define ORBIT_SEGMENTS 360
264+
265+class StelFont;
266+class StelPainter;
267+class StelTranslator;
268+class QOpenGLShaderProgram;
269+
270+// Class used to store orbital elements
271+class RotationElements
272+{
273+public:
274+ RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.), siderealPeriod(0.) {}
275+ float period; // rotation period
276+ float offset; // rotation at epoch
277+ double epoch;
278+ float obliquity; // tilt of rotation axis w.r.t. ecliptic
279+ float ascendingNode; // long. of ascending node of equator on the ecliptic
280+ float precessionRate; // rate of precession of rotation axis in rads/day
281+ double siderealPeriod; // sidereal period (Planet year in earth days)
282+};
283+
284+// Class to manage rings for planets like saturn
285+class Ring
286+{
287+public:
288+ Ring(float radiusMin, float radiusMax,const QString &texname);
289+ double getSize(void) const {return radiusMax;}
290+ const float radiusMin;
291+ const float radiusMax;
292+ StelTextureSP tex;
293+};
294+
295+
296+class Planet : public StelObject
297+{
298+public:
299+ friend class SolarSystem;
300+
301+ Q_ENUMS(PlanetType)
302+ //! numeric typecodes for the type descriptions in ssystem.ini
303+ // GZ: Until 0.13 QStrings were used for types.
304+ // GZ: Enums are slightly faster than string comparisons in time-critical comparisons.
305+ // GZ: If other types are introduced, add here and the string in init().
306+ enum PlanetType
307+ {
308+ isStar, // ssystem.ini: type="star"
309+ isPlanet, // ssystem.ini: type="planet"
310+ isMoon, // ssystem.ini: type="moon"
311+ isAsteroid, // ssystem.ini: type="asteroid"
312+ isPlutoid, // ssystem.ini: type="plutoid"
313+ isComet, // ssystem.ini: type="comet"
314+ isUNDEFINED // ssystem.ini: type=<anything else>
315+ };
316+
317+ Planet(const QString& englishName,
318+ int flagLighting,
319+ double radius,
320+ double oblateness,
321+ Vec3f color,
322+ float albedo,
323+ const QString& texMapName,
324+ const QString& normalMapName,
325+ posFuncType _coordFunc,
326+ void* userDataPtr,
327+ OsculatingFunctType *osculatingFunc,
328+ bool closeOrbit,
329+ bool hidden,
330+ bool hasAtmosphere,
331+ bool hasHalo,
332+ const QString &pTypeStr);
333+
334+ virtual ~Planet();
335+
336+ //! Initializes static vars. Must be called before creating first planet.
337+ // Currently ensured by SolarSystem::init()
338+ static void init();
339+
340+ ///////////////////////////////////////////////////////////////////////////
341+ // Methods inherited from StelObject
342+ //! Get a string with data about the Planet.
343+ //! Planets support the following InfoStringGroup flags:
344+ //! - Name
345+ //! - Magnitude
346+ //! - RaDec
347+ //! - AltAzi
348+ //! - Distance
349+ //! - Size
350+ //! - PlainText
351+ //! - Extra: Heliocentric Ecliptical Coordinates & Observer-planetocentric Ecliptical Coordinates, Phase, illumination, phase angle & elongation from the Sun
352+ //! @param core the StelCore object
353+ //! @param flags a set of InfoStringGroup items to include in the return value.
354+ //! @return a QString containing an HMTL encoded description of the Planet.
355+ virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
356+ virtual double getCloseViewFov(const StelCore* core) const;
357+ virtual double getSatellitesFov(const StelCore* core) const;
358+ virtual double getParentSatellitesFov(const StelCore* core) const;
359+ virtual float getVMagnitude(const StelCore* core) const;
360+ virtual float getSelectPriority(const StelCore* core) const;
361+ virtual Vec3f getInfoColor(void) const;
362+ virtual QString getType(void) const {return "Planet";}
363+ virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
364+ virtual QString getEnglishName(void) const {return englishName;}
365+ virtual QString getNameI18n(void) const {return nameI18;}
366+ virtual double getAngularSize(const StelCore* core) const;
367+ virtual bool hasAtmosphere(void) {return atmosphere;}
368+ virtual bool hasHalo(void) {return halo;}
369+
370+ ///////////////////////////////////////////////////////////////////////////
371+ // Methods of SolarSystem object
372+ //! Translate planet name using the passed translator
373+ virtual void translateName(const StelTranslator &trans);
374+
375+ // Draw the Planet
376+ // GZ Made that virtual to allow comets having their own draw().
377+ virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
378+
379+ ///////////////////////////////////////////////////////////////////////////
380+ // Methods specific to Planet
381+ //! Get the radius of the planet in AU.
382+ //! @return the radius of the planet in astronomical units.
383+ double getRadius(void) const {return radius;}
384+ //! Get duration of sidereal day
385+ double getSiderealDay(void) const {return re.period;}
386+ //! Get duration of sidereal year
387+ // GZ: made that virtual for Comets.
388+ virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
389+ //! Get duration of mean solar day
390+ double getMeanSolarDay(void) const;
391+
392+ const QString& getTextMapName() const {return texMapName;}
393+ //const QString getPlanetType() const {return pTypeStr;}
394+ const PlanetType getPlanetType() const {return pType;}
395+
396+ // Compute the z rotation to use from equatorial to geographic coordinates
397+ double getSiderealTime(double jd) const;
398+ Mat4d getRotEquatorialToVsop87(void) const;
399+ void setRotEquatorialToVsop87(const Mat4d &m);
400+
401+ const RotationElements &getRotationElements(void) const {return re;}
402+
403+ // Compute the position in the parent Planet coordinate system
404+ void computePositionWithoutOrbits(const double dateJD);
405+ virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet!
406+
407+ // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
408+ void computeTransMatrix(double date);
409+
410+ // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
411+ double getPhaseAngle(const Vec3d& obsPos) const;
412+ // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
413+ double getElongation(const Vec3d& obsPos) const;
414+ // Get the angular size of the spheroid of the planet (i.e. without the rings)
415+ double getSpheroidAngularSize(const StelCore* core) const;
416+ // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
417+ float getPhase(const Vec3d& obsPos) const;
418+
419+ // Set the orbital elements
420+ void setRotationElements(float _period, float _offset, double _epoch,
421+ float _obliquity, float _ascendingNode,
422+ float _precessionRate, double _siderealPeriod);
423+ double getRotAscendingnode(void) const {return re.ascendingNode;}
424+ double getRotObliquity(double JDay) const;
425+
426+ //! Get the Planet position in the parent Planet ecliptic coordinate in AU
427+ Vec3d getEclipticPos() const;
428+
429+ // Return the heliocentric ecliptical position
430+ Vec3d getHeliocentricEclipticPos() const;
431+
432+ // Return the heliocentric transformation for local coordinate
433+ Vec3d getHeliocentricPos(Vec3d) const;
434+ void setHeliocentricEclipticPos(const Vec3d &pos);
435+
436+ // Compute the distance to the given position in heliocentric coordinate (in AU)
437+ double computeDistance(const Vec3d& obsHelioPos);
438+ double getDistance(void) const {return distance;}
439+
440+ void setRings(Ring* r) {rings = r;}
441+
442+ void setSphereScale(float s) {sphereScale = s;}
443+ float getSphereScale(void) const {return sphereScale;}
444+
445+ const QSharedPointer<Planet> getParent(void) const {return parent;}
446+
447+ static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
448+ static const Vec3f& getLabelColor(void) {return labelColor;}
449+
450+ // update displayed elements. @param deltaTime: ms (?)
451+ void update(int deltaTime);
452+
453+ void setFlagHints(bool b){hintFader = b;}
454+ bool getFlagHints(void) const {return hintFader;}
455+
456+ void setFlagLabels(bool b){flagLabels = b;}
457+ bool getFlagLabels(void) const {return flagLabels;}
458+
459+ ///////////////////////////////////////////////////////////////////////////
460+ // DEPRECATED
461+ ///// Orbit related code
462+ // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
463+ void setFlagOrbits(bool b){orbitFader = b;}
464+ bool getFlagOrbits(void) const {return orbitFader;}
465+ LinearFader orbitFader;
466+ // draw orbital path of Planet
467+ void drawOrbit(const StelCore*);
468+ Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
469+ Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
470+ double lastOrbitJD;
471+ double deltaJD; // time difference between positional updates.
472+ double deltaOrbitJD;
473+ bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
474+ bool closeOrbit; // whether to connect the beginning of the orbit line to
475+ // the end: good for elliptical orbits, bad for parabolic
476+ // and hyperbolic orbits
477+
478+ static Vec3f orbitColor;
479+ static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
480+ static const Vec3f& getOrbitColor() {return orbitColor;}
481+
482+ //! Return the list of planets which project some shadow on this planet
483+ QVector<const Planet*> getCandidatesForShadow() const;
484+
485+protected:
486+ static StelTextureSP texEarthShadow; // for lunar eclipses
487+
488+ void computeModelMatrix(Mat4d &result) const;
489+
490+ // Return the information string "ready to print" :)
491+ QString getSkyLabel(const StelCore* core) const;
492+
493+ // Draw the 3d model. Call the proper functions if there are rings etc..
494+ void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false);
495+
496+ // Draw the 3D sphere
497+ void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false);
498+
499+ // Draw the circle and name of the Planet
500+ void drawHints(const StelCore* core, const QFont& planetNameFont);
501+
502+ QString englishName; // english planet name
503+ QString nameI18; // International translated name
504+ QString texMapName; // Texture file path
505+ QString normalMapName; // Texture file path
506+ int flagLighting; // Set whether light computation has to be proceed
507+ RotationElements re; // Rotation param
508+ double radius; // Planet radius in AU
509+ double oneMinusOblateness; // (polar radius)/(equatorial radius)
510+ Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
511+ // centered on the parent Planet
512+ Vec3d screenPos; // Used to store temporarily the 2D position on screen
513+ Vec3d previousScreenPos; // The position of this planet in the previous frame.
514+ Vec3f color; // exclusively used for drawing the planet halo
515+
516+ float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
517+ Mat4d rotLocalToParent;
518+ float axisRotation; // Rotation angle of the Planet on it's axis
519+ StelTextureSP texMap; // Planet map texture
520+ StelTextureSP normalMap; // Planet normal map texture
521+
522+ Ring* rings; // Planet rings
523+ double distance; // Temporary variable used to store the distance to a given point
524+ // it is used for sorting while drawing
525+ float sphereScale; // Artificial scaling for better viewing
526+ double lastJD; // caches JD of last positional computation
527+ // The callback for the calculation of the equatorial rect heliocentric position at time JD.
528+ posFuncType coordFunc;
529+ void* userDataPtr;
530+
531+ OsculatingFunctType *const osculatingFunc;
532+ QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
533+ QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
534+ LinearFader hintFader;
535+ LinearFader labelsFader; // Store the current state of the label for this planet
536+ bool flagLabels; // Define whether labels should be displayed
537+ bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
538+ bool atmosphere; // Does the planet have an atmosphere?
539+ bool halo; // Does the planet have a halo?
540+ // QString pTypeStr; // Type of body, old version just had a string here.
541+ PlanetType pType; // GZ this is now a proper type...
542+
543+ static Vec3f labelColor;
544+ static StelTextureSP hintCircleTex;
545+ static QMap<PlanetType, QString> pTypeMap; // GZ: maps fast type to english name.
546+
547+ // Shader-related variables
548+ struct PlanetShaderVars {
549+ int projectionMatrix;
550+ int texCoord;
551+ int unprojectedVertex;
552+ int vertex;
553+ int texture;
554+ int lightDirection;
555+ int eyeDirection;
556+ int diffuseLight;
557+ int ambientLight;
558+ int shadowCount;
559+ int shadowData;
560+ int sunInfo;
561+
562+ void initLocations(QOpenGLShaderProgram*);
563+ };
564+ static PlanetShaderVars planetShaderVars;
565+ static QOpenGLShaderProgram* planetShaderProgram;
566+
567+ // Shader-related variables
568+ struct RingPlanetShaderVars : public PlanetShaderVars {
569+ // Rings-specific variables
570+ int isRing;
571+ int ring;
572+ int outerRadius;
573+ int innerRadius;
574+ int ringS;
575+ };
576+ static RingPlanetShaderVars ringPlanetShaderVars;
577+ static QOpenGLShaderProgram* ringPlanetShaderProgram;
578+
579+ struct MoonShaderVars : public PlanetShaderVars {
580+ // Moon-specific variables
581+ int earthShadow;
582+ int normalMap;
583+ };
584+ static MoonShaderVars moonShaderVars;
585+ static QOpenGLShaderProgram* moonShaderProgram;
586+
587+ static void initShader();
588+ static void deinitShader();
589+
590+};
591+
592+#endif // _PLANET_HPP_
593+
594
595=== removed file 'src/core/modules/Planet.hpp'
596--- src/core/modules/Planet.hpp 2014-08-02 17:34:13 +0000
597+++ src/core/modules/Planet.hpp 1970-01-01 00:00:00 +0000
598@@ -1,346 +0,0 @@
599-/*
600- * Stellarium
601- * Copyright (C) 2002 Fabien Chereau
602- *
603- * This program is free software; you can redistribute it and/or
604- * modify it under the terms of the GNU General Public License
605- * as published by the Free Software Foundation; either version 2
606- * of the License, or (at your option) any later version.
607- *
608- * This program is distributed in the hope that it will be useful,
609- * but WITHOUT ANY WARRANTY; without even the implied warranty of
610- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
611- * GNU General Public License for more details.
612- *
613- * You should have received a copy of the GNU General Public License
614- * along with this program; if not, write to the Free Software
615- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
616- */
617-
618-#ifndef _PLANET_HPP_
619-#define _PLANET_HPP_
620-
621-#include "StelObject.hpp"
622-#include "StelProjector.hpp"
623-#include "VecMath.hpp"
624-#include "StelFader.hpp"
625-#include "StelTextureTypes.hpp"
626-#include "StelProjectorType.hpp"
627-
628-#include <QString>
629-
630-// The callback type for the external position computation function
631-// The last variable is the userData pointer.
632-typedef void (*posFuncType)(double, double*, void*);
633-
634-typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]);
635-
636-// epoch J2000: 12 UT on 1 Jan 2000
637-#define J2000 2451545.0
638-#define ORBIT_SEGMENTS 360
639-
640-class StelFont;
641-class StelPainter;
642-class StelTranslator;
643-class QOpenGLShaderProgram;
644-
645-// Class used to store orbital elements
646-class RotationElements
647-{
648-public:
649- RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.), siderealPeriod(0.) {}
650- float period; // rotation period
651- float offset; // rotation at epoch
652- double epoch;
653- float obliquity; // tilt of rotation axis w.r.t. ecliptic
654- float ascendingNode; // long. of ascending node of equator on the ecliptic
655- float precessionRate; // rate of precession of rotation axis in rads/day
656- double siderealPeriod; // sidereal period (Planet year in earth days)
657-};
658-
659-// Class to manage rings for planets like saturn
660-class Ring
661-{
662-public:
663- Ring(float radiusMin, float radiusMax,const QString &texname);
664- double getSize(void) const {return radiusMax;}
665- const float radiusMin;
666- const float radiusMax;
667- StelTextureSP tex;
668-};
669-
670-
671-class Planet : public StelObject
672-{
673-public:
674- friend class SolarSystem;
675- Planet(const QString& englishName,
676- int flagLighting,
677- double radius,
678- double oblateness,
679- Vec3f color,
680- float albedo,
681- const QString& texMapName,
682- const QString& normalMapName,
683- posFuncType _coordFunc,
684- void* userDataPtr,
685- OsculatingFunctType *osculatingFunc,
686- bool closeOrbit,
687- bool hidden,
688- bool hasAtmosphere,
689- bool hasHalo,
690- const QString &pType);
691-
692- virtual ~Planet();
693-
694- ///////////////////////////////////////////////////////////////////////////
695- // Methods inherited from StelObject
696- //! Get a string with data about the Planet.
697- //! Planets support the following InfoStringGroup flags:
698- //! - Name
699- //! - Magnitude
700- //! - RaDec
701- //! - AltAzi
702- //! - Distance
703- //! - Size
704- //! - PlainText
705- //! - Extra: Heliocentric Ecliptical Coordinates & Observer-planetocentric Ecliptical Coordinates, Phase, illumination, phase angle & elongation from the Sun
706- //! @param core the StelCore object
707- //! @param flags a set of InfoStringGroup items to include in the return value.
708- //! @return a QString containing an HMTL encoded description of the Planet.
709- virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
710- virtual double getCloseViewFov(const StelCore* core) const;
711- virtual double getSatellitesFov(const StelCore* core) const;
712- virtual double getParentSatellitesFov(const StelCore* core) const;
713- virtual float getVMagnitude(const StelCore* core) const;
714- virtual float getSelectPriority(const StelCore* core) const;
715- virtual Vec3f getInfoColor(void) const;
716- virtual QString getType(void) const {return "Planet";}
717- virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
718- virtual QString getEnglishName(void) const {return englishName;}
719- virtual QString getNameI18n(void) const {return nameI18;}
720- virtual double getAngularSize(const StelCore* core) const;
721- virtual bool hasAtmosphere(void) {return atmosphere;}
722- virtual bool hasHalo(void) {return halo;}
723-
724- ///////////////////////////////////////////////////////////////////////////
725- // Methods of SolarSystem object
726- //! Translate planet name using the passed translator
727- virtual void translateName(const StelTranslator &trans);
728-
729- // Draw the Planet
730- // GZ Made that virtual to allow comets having their own draw().
731- virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
732-
733- ///////////////////////////////////////////////////////////////////////////
734- // Methods specific to Planet
735- //! Get the radius of the planet in AU.
736- //! @return the radius of the planet in astronomical units.
737- double getRadius(void) const {return radius;}
738- //! Get duration of sidereal day
739- double getSiderealDay(void) const {return re.period;}
740- //! Get duration of sidereal year
741- // GZ: made that virtual for Comets.
742- virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
743- //! Get duration of mean solar day
744- double getMeanSolarDay(void) const;
745-
746- const QString& getTextMapName() const {return texMapName;}
747- const QString getPlanetType() const {return pType;}
748-
749- // Compute the z rotation to use from equatorial to geographic coordinates
750- double getSiderealTime(double jd) const;
751- Mat4d getRotEquatorialToVsop87(void) const;
752- void setRotEquatorialToVsop87(const Mat4d &m);
753-
754- const RotationElements &getRotationElements(void) const {return re;}
755-
756- // Compute the position in the parent Planet coordinate system
757- void computePositionWithoutOrbits(const double dateJD);
758- virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet!
759-
760- // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
761- void computeTransMatrix(double date);
762-
763- // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
764- double getPhaseAngle(const Vec3d& obsPos) const;
765- // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
766- double getElongation(const Vec3d& obsPos) const;
767- // Get the angular size of the spheroid of the planet (i.e. without the rings)
768- double getSpheroidAngularSize(const StelCore* core) const;
769- // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
770- float getPhase(const Vec3d& obsPos) const;
771-
772- // Set the orbital elements
773- void setRotationElements(float _period, float _offset, double _epoch,
774- float _obliquity, float _ascendingNode,
775- float _precessionRate, double _siderealPeriod);
776- double getRotAscendingnode(void) const {return re.ascendingNode;}
777- double getRotObliquity(double JDay) const;
778-
779- //! Get the Planet position in the parent Planet ecliptic coordinate in AU
780- Vec3d getEclipticPos() const;
781-
782- // Return the heliocentric ecliptical position
783- Vec3d getHeliocentricEclipticPos() const;
784-
785- // Return the heliocentric transformation for local coordinate
786- Vec3d getHeliocentricPos(Vec3d) const;
787- void setHeliocentricEclipticPos(const Vec3d &pos);
788-
789- // Compute the distance to the given position in heliocentric coordinate (in AU)
790- double computeDistance(const Vec3d& obsHelioPos);
791- double getDistance(void) const {return distance;}
792-
793- void setRings(Ring* r) {rings = r;}
794-
795- void setSphereScale(float s) {sphereScale = s;}
796- float getSphereScale(void) const {return sphereScale;}
797-
798- const QSharedPointer<Planet> getParent(void) const {return parent;}
799-
800- static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
801- static const Vec3f& getLabelColor(void) {return labelColor;}
802-
803- // update displayed elements. @param deltaTime: ms (?)
804- void update(int deltaTime);
805-
806- void setFlagHints(bool b){hintFader = b;}
807- bool getFlagHints(void) const {return hintFader;}
808-
809- void setFlagLabels(bool b){flagLabels = b;}
810- bool getFlagLabels(void) const {return flagLabels;}
811-
812- ///////////////////////////////////////////////////////////////////////////
813- // DEPRECATED
814- ///// Orbit related code
815- // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
816- void setFlagOrbits(bool b){orbitFader = b;}
817- bool getFlagOrbits(void) const {return orbitFader;}
818- LinearFader orbitFader;
819- // draw orbital path of Planet
820- void drawOrbit(const StelCore*);
821- Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
822- Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
823- double lastOrbitJD;
824- double deltaJD; // time difference between positional updates.
825- double deltaOrbitJD;
826- bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
827- bool closeOrbit; // whether to connect the beginning of the orbit line to
828- // the end: good for elliptical orbits, bad for parabolic
829- // and hyperbolic orbits
830-
831- static Vec3f orbitColor;
832- static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
833- static const Vec3f& getOrbitColor() {return orbitColor;}
834-
835- //! Return the list of planets which project some shadow on this planet
836- QVector<const Planet*> getCandidatesForShadow() const;
837-
838-protected:
839- static StelTextureSP texEarthShadow; // for lunar eclipses
840-
841- void computeModelMatrix(Mat4d &result) const;
842-
843- // Return the information string "ready to print" :)
844- QString getSkyLabel(const StelCore* core) const;
845-
846- // Draw the 3d model. Call the proper functions if there are rings etc..
847- void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false);
848-
849- // Draw the 3D sphere
850- void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false);
851-
852- // Draw the circle and name of the Planet
853- void drawHints(const StelCore* core, const QFont& planetNameFont);
854-
855- QString englishName; // english planet name
856- QString nameI18; // International translated name
857- QString texMapName; // Texture file path
858- QString normalMapName; // Texture file path
859- int flagLighting; // Set whether light computation has to be proceed
860- RotationElements re; // Rotation param
861- double radius; // Planet radius in AU
862- double oneMinusOblateness; // (polar radius)/(equatorial radius)
863- Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
864- // centered on the parent Planet
865- Vec3d screenPos; // Used to store temporarily the 2D position on screen
866- Vec3d previousScreenPos; // The position of this planet in the previous frame.
867- Vec3f color; // exclusively used for drawing the planet halo
868-
869- float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
870- Mat4d rotLocalToParent;
871- float axisRotation; // Rotation angle of the Planet on it's axis
872- StelTextureSP texMap; // Planet map texture
873- StelTextureSP normalMap; // Planet normal map texture
874-
875- Ring* rings; // Planet rings
876- double distance; // Temporary variable used to store the distance to a given point
877- // it is used for sorting while drawing
878- float sphereScale; // Artificial scaling for better viewing
879- double lastJD; // caches JD of last positional computation
880- // The callback for the calculation of the equatorial rect heliocentric position at time JD.
881- posFuncType coordFunc;
882- void* userDataPtr;
883-
884- OsculatingFunctType *const osculatingFunc;
885- QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
886- QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
887- LinearFader hintFader;
888- LinearFader labelsFader; // Store the current state of the label for this planet
889- bool flagLabels; // Define whether labels should be displayed
890- bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
891- bool atmosphere; // Does the planet have an atmosphere?
892- bool halo; // Does the planet have a halo?
893- QString pType; // Type of body
894-
895- static Vec3f labelColor;
896- static StelTextureSP hintCircleTex;
897-
898- // Shader-related variables
899- struct PlanetShaderVars {
900- int projectionMatrix;
901- int texCoord;
902- int unprojectedVertex;
903- int vertex;
904- int texture;
905- int lightDirection;
906- int eyeDirection;
907- int diffuseLight;
908- int ambientLight;
909- int shadowCount;
910- int shadowData;
911- int sunInfo;
912-
913- void initLocations(QOpenGLShaderProgram*);
914- };
915- static PlanetShaderVars planetShaderVars;
916- static QOpenGLShaderProgram* planetShaderProgram;
917-
918- // Shader-related variables
919- struct RingPlanetShaderVars : public PlanetShaderVars {
920- // Rings-specific variables
921- int isRing;
922- int ring;
923- int outerRadius;
924- int innerRadius;
925- int ringS;
926- };
927- static RingPlanetShaderVars ringPlanetShaderVars;
928- static QOpenGLShaderProgram* ringPlanetShaderProgram;
929-
930- struct MoonShaderVars : public PlanetShaderVars {
931- // Moon-specific variables
932- int earthShadow;
933- int normalMap;
934- };
935- static MoonShaderVars moonShaderVars;
936- static QOpenGLShaderProgram* moonShaderProgram;
937-
938- static void initShader();
939- static void deinitShader();
940-
941-};
942-
943-#endif // _PLANET_HPP_
944-
945
946=== modified file 'src/core/modules/SolarSystem.cpp'
947--- src/core/modules/SolarSystem.cpp 2014-08-30 16:58:25 +0000
948+++ src/core/modules/SolarSystem.cpp 2014-08-31 09:14:13 +0000
949@@ -119,6 +119,7 @@
950 QSettings* conf = StelApp::getInstance().getSettings();
951 Q_ASSERT(conf);
952
953+ Planet::init();
954 loadPlanets(); // Load planets data
955
956 // Compute position and matrix of sun and all the satellites (ie planets)
957@@ -1069,7 +1070,7 @@
958 QString SolarSystem::getPlanetType(QString planetName) const
959 {
960 PlanetP p = searchByEnglishName(planetName);
961- return p->getPlanetType();
962+ return Planet::pTypeMap.value(p->getPlanetType());
963 }
964
965 double SolarSystem::getDistanceToPlanet(QString planetName) const
966@@ -1382,7 +1383,7 @@
967 {
968 foreach(const PlanetP& p, systemPlanets)
969 {
970- if (p->getPlanetType()==objType)
971+ if (Planet::pTypeMap.value(p->getPlanetType())==objType)
972 result << p->getEnglishName();
973 }
974 }
975@@ -1390,7 +1391,7 @@
976 {
977 foreach(const PlanetP& p, systemPlanets)
978 {
979- if (p->getPlanetType()==objType)
980+ if (Planet::pTypeMap.value(p->getPlanetType())==objType)
981 result << p->getNameI18n();
982 }
983 }