~ubuntu-branches/ubuntu/precise/stellarium/precise

« back to all changes in this revision

Viewing changes to src/modules/SolarSystem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2010-02-15 20:48:39 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20100215204839-u3qgbv60rho997yk
Tags: 0.10.3-0ubuntu1
* New upstream release.
  - fixes intel rendering bug (LP: #480553)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
18
 */
19
19
 
20
 
 
21
 
#include <algorithm>
22
20
#include "SolarSystem.hpp"
23
21
#include "StelTexture.hpp"
24
22
#include "stellplanet.h"
29
27
#include "StelCore.hpp"
30
28
#include "StelTextureMgr.hpp"
31
29
#include "StelObjectMgr.hpp"
32
 
#include "StelFontMgr.hpp"
33
30
#include "StelLocaleMgr.hpp"
34
31
#include "StelSkyCultureMgr.hpp"
35
32
#include "StelFileMgr.hpp"
37
34
#include "StelIniParser.hpp"
38
35
#include "Planet.hpp"
39
36
#include "StelNavigator.hpp"
40
 
#include "StelFont.hpp"
41
37
#include "StelSkyDrawer.hpp"
42
38
#include "StelStyle.hpp"
43
39
#include "StelUtils.hpp"
44
40
#include "StelPainter.hpp"
45
41
 
 
42
#include <functional>
 
43
#include <algorithm>
 
44
 
46
45
#include <QTextStream>
47
46
#include <QSettings>
48
47
#include <QVariant>
53
52
#include <QMapIterator>
54
53
#include <QDebug>
55
54
 
56
 
using namespace std;
57
 
 
58
 
SolarSystem::SolarSystem() :sun(NULL),moon(NULL),earth(NULL),selected(NULL), moonScale(1.), fontSize(14.),
59
 
        planetNameFont(StelApp::getInstance().getFontManager().getStandardFont(StelApp::getInstance().getLocaleMgr().getAppLanguage(), fontSize)),
60
 
        flagOrbits(false),flagLightTravelTime(false), lastHomePlanet(NULL)
 
55
SolarSystem::SolarSystem() : moonScale(1.),     flagOrbits(false), flagLightTravelTime(false), lastHomePlanet(NULL)
61
56
{
 
57
        planetNameFont.setPixelSize(14.);
62
58
        setObjectName("SolarSystem");
63
59
}
64
60
 
65
61
void SolarSystem::setFontSize(float newFontSize)
66
62
{
67
 
        planetNameFont = StelApp::getInstance().getFontManager().getStandardFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize);
 
63
        planetNameFont.setPixelSize(newFontSize);
68
64
}
69
65
 
70
66
SolarSystem::~SolarSystem()
71
67
{
72
68
        // release selected:
73
 
        selected = NULL;
74
 
        for(std::vector<Planet*>::iterator iter = systemPlanets.begin(); iter != systemPlanets.end(); ++iter)
75
 
        {
76
 
                if (*iter) delete *iter;
77
 
                *iter = NULL;
78
 
        }
79
 
        for(std::vector<Orbit*>::iterator iter = orbits.begin(); iter != orbits.end(); ++iter)
80
 
        {
81
 
                if (*iter) delete *iter;
82
 
                *iter = NULL;
83
 
        }
84
 
        sun = NULL;
85
 
        moon = NULL;
86
 
        earth = NULL;
87
 
        Planet::hintCircleTex.reset();
88
 
        Planet::texEarthShadow.reset();
 
69
        selected.clear();
 
70
        foreach (Orbit* orb, orbits)
 
71
        {
 
72
                delete orb;
 
73
                orb = NULL;
 
74
        }
 
75
        sun.clear();
 
76
        moon.clear();
 
77
        earth.clear();
 
78
        Planet::hintCircleTex.clear();
 
79
        Planet::texEarthShadow.clear();
89
80
}
90
81
 
91
82
/*************************************************************************
119
110
        setFlagOrbits(conf->value("astro/flag_planets_orbits").toBool());
120
111
        setFlagLightTravelTime(conf->value("astro/flag_light_travel_time", false).toBool());
121
112
        setFlagTrails(conf->value("astro/flag_object_trails", false).toBool());
122
 
        startTrails(conf->value("astro/flag_object_trails", false).toBool());   
123
 
        
 
113
        startTrails(conf->value("astro/flag_object_trails", false).toBool());
 
114
 
124
115
        GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
125
 
        StelApp::getInstance().getTextureManager().setDefaultParams();
126
 
        StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
127
116
        texPointer = StelApp::getInstance().getTextureManager().createTexture("pointeur4.png");
128
117
        Planet::hintCircleTex = StelApp::getInstance().getTextureManager().createTexture("planet-indicator.png");
129
118
}
132
121
{
133
122
        const StelNavigator* nav = core->getNavigator();
134
123
        const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
135
 
        
 
124
 
136
125
        const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)->getSelectedObject("Planet");
137
126
        if (!newSelected.empty())
138
127
        {
142
131
                // Compute 2D pos and return if outside screen
143
132
                if (!prj->project(pos, screenpos))
144
133
                        return;
145
 
        
146
 
                
 
134
 
 
135
 
147
136
                StelPainter sPainter(prj);
148
 
                glColor3f(1.0f,0.3f,0.3f);
149
 
        
 
137
                sPainter.setColor(1.0f,0.3f,0.3f);
 
138
 
150
139
                float size = obj->getAngularSize(core)*M_PI/180.*prj->getPixelPerRadAtCenter()*2.;
151
 
                size+=26.f + 10.f*std::sin(2.f * StelApp::getInstance().getTotalRunTime());
 
140
                size+=40.f + 10.f*std::sin(2.f * StelApp::getInstance().getTotalRunTime());
152
141
 
153
142
                texPointer->bind();
154
143
 
155
 
        glEnable(GL_TEXTURE_2D);
156
 
        glEnable(GL_BLEND);
157
 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
158
 
        
159
 
        glPushMatrix();
160
 
        glTranslatef(screenpos[0], screenpos[1], 0.0f);
161
 
        glRotatef(StelApp::getInstance().getTotalRunTime()*10.,0,0,-1);
162
 
 
163
 
        glTranslatef(-size/2, -size/2,0.0f);
164
 
        glRotatef(90,0,0,1);
165
 
        glBegin(GL_QUADS );
166
 
            glTexCoord2f(0.0f,0.0f);    glVertex3f(-10,-10,0);      //Bas Gauche
167
 
            glTexCoord2f(1.0f,0.0f);    glVertex3f(10,-10,0);       //Bas Droite
168
 
            glTexCoord2f(1.0f,1.0f);    glVertex3f(10,10,0);        //Haut Droit
169
 
            glTexCoord2f(0.0f,1.0f);    glVertex3f(-10,10,0);       //Haut Gauche
170
 
        glEnd ();
171
 
 
172
 
        glRotatef(-90,0,0,1);
173
 
        glTranslatef(0,size,0.0f);
174
 
        glBegin(GL_QUADS );
175
 
            glTexCoord2f(0.0f,0.0f);    glVertex3f(-10,-10,0);      //Bas Gauche
176
 
            glTexCoord2f(1.0f,0.0f);    glVertex3f(10,-10,0);       //Bas Droite
177
 
            glTexCoord2f(1.0f,1.0f);    glVertex3f(10,10,0);        //Haut Droit
178
 
            glTexCoord2f(0.0f,1.0f);    glVertex3f(-10,10,0);       //Haut Gauche
179
 
        glEnd ();
180
 
 
181
 
        glRotatef(-90,0,0,1);
182
 
        glTranslatef(0, size,0.0f);
183
 
        glBegin(GL_QUADS );
184
 
            glTexCoord2f(0.0f,0.0f);    glVertex3f(-10,-10,0);      //Bas Gauche
185
 
            glTexCoord2f(1.0f,0.0f);    glVertex3f(10,-10,0);       //Bas Droite
186
 
            glTexCoord2f(1.0f,1.0f);    glVertex3f(10,10,0);        //Haut Droit
187
 
            glTexCoord2f(0.0f,1.0f);    glVertex3f(-10,10,0);       //Haut Gauche
188
 
        glEnd ();
189
 
 
190
 
        glRotatef(-90,0,0,1);
191
 
        glTranslatef(0,size,0);
192
 
        glBegin(GL_QUADS );
193
 
            glTexCoord2f(0.0f,0.0f);    glVertex3f(-10,-10,0);      //Bas Gauche
194
 
            glTexCoord2f(1.0f,0.0f);    glVertex3f(10,-10,0);       //Bas Droite
195
 
            glTexCoord2f(1.0f,1.0f);    glVertex3f(10,10,0);        //Haut Droit
196
 
            glTexCoord2f(0.0f,1.0f);    glVertex3f(-10,10,0);       //Haut Gauche
197
 
        glEnd ();
198
 
                glPopMatrix();
 
144
                sPainter.enableTexture2d(true);
 
145
                glEnable(GL_BLEND);
 
146
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
 
147
                
 
148
                size*=0.5;
 
149
                const float angleBase = StelApp::getInstance().getTotalRunTime() * 10;
 
150
                // We draw 4 instances of the sprite at the corners of the pointer
 
151
                for (int i = 0; i < 4; ++i)
 
152
                {
 
153
                        const float angle = angleBase + i * 90;
 
154
                        const double x = screenpos[0] + size * cos(angle / 180 * M_PI);
 
155
                        const double y = screenpos[1] + size * sin(angle / 180 * M_PI);
 
156
                        sPainter.drawSprite2dMode(x, y, 10, angle);
 
157
                }
199
158
        }
200
159
}
201
160
 
 
161
void ellipticalOrbitPosFunc(double jd,double xyz[3], void* userDataPtr)
 
162
{
 
163
        static_cast<EllipticalOrbit*>(userDataPtr)->positionAtTimevInVSOP87Coordinates(jd, xyz);
 
164
}
 
165
void cometOrbitPosFunc(double jd,double xyz[3], void* userDataPtr)
 
166
{
 
167
        static_cast<CometOrbit*>(userDataPtr)->positionAtTimevInVSOP87Coordinates(jd, xyz);
 
168
}
 
169
 
202
170
// Init and load the solar system data
203
171
void SolarSystem::loadPlanets()
204
172
{
206
174
        QString iniFile;
207
175
        try
208
176
        {
209
 
                iniFile = StelApp::getInstance().getFileMgr().findFile("data/ssystem.ini");
 
177
                iniFile = StelFileMgr::findFile("data/ssystem.ini");
210
178
        }
211
179
        catch(std::runtime_error& e)
212
180
        {
221
189
        }
222
190
 
223
191
        // QSettings does not allow us to say that the sections of the file
224
 
        // will be listed in the same order  as in the file like the old 
225
 
        // InitParser used to so we can no longer assume that.  
 
192
        // will be listed in the same order  as in the file like the old
 
193
        // InitParser used to so we can no longer assume that.
226
194
        //
227
195
        // This means we must first decide what order to read the sections
228
196
        // of the file in (each section contains one planet) to avoid setting
229
197
        // the parent Planet* to one which has not yet been created.
230
198
        //
231
 
        // Stage 1: Make a map of body names back to the section names 
232
 
        // which they come from. Also make a map of body name to parent body 
233
 
        // name. These two maps can be made in a single pass through the 
 
199
        // Stage 1: Make a map of body names back to the section names
 
200
        // which they come from. Also make a map of body name to parent body
 
201
        // name. These two maps can be made in a single pass through the
234
202
        // sections of the file.
235
203
        //
236
204
        // Stage 2: Make an ordered list of section names such that each
237
205
        // item is only ever dependent on items which appear earlier in the
238
206
        // list.
239
207
        // 2a: Make a QMultiMap relating the number of levels of dependency
240
 
        //     to the body name, i.e. 
 
208
        //     to the body name, i.e.
241
209
        //     0 -> Sun
242
210
        //     1 -> Mercury
243
211
        //     1 -> Venus
251
219
        //
252
220
        // Stage 3: iterate over the ordered sections decided in stage 2,
253
221
        // creating the planet objects from the QSettings data.
254
 
        
 
222
 
255
223
        // Stage 1 (as described above).
256
224
        QMap<QString, QString> secNameMap;
257
225
        QMap<QString, QString> parentMap;
272
240
        {
273
241
                const QString englishName = pd.value(sections.at(i)+"/name").toString();
274
242
 
275
 
                // follow dependencies, incrementing level when we have one 
 
243
                // follow dependencies, incrementing level when we have one
276
244
                // till we run out.
277
245
                QString p=englishName;
278
246
                int level = 0;
303
271
                const QString secname = orderedSections.at(i);
304
272
                const QString englishName = pd.value(secname+"/name").toString();
305
273
                const QString strParent = pd.value(secname+"/parent").toString();
306
 
                Planet *parent = NULL;
307
 
                if (strParent!="none")
 
274
                PlanetP parent;
 
275
                if (strParent!="none")
308
276
                {
309
277
                        // Look in the other planets the one named with strParent
310
 
                        vector<Planet*>::iterator iter = systemPlanets.begin();
311
 
                        while (iter != systemPlanets.end())
 
278
                        foreach (const PlanetP& p, systemPlanets)
312
279
                        {
313
 
                                if ((*iter)->getEnglishName()==strParent)
 
280
                                if (p->getEnglishName()==strParent)
314
281
                                {
315
 
                                        parent = (*iter);
 
282
                                        parent = p;
 
283
                                        break;
316
284
                                }
317
 
                                iter++;
318
285
                        }
319
 
                        if (parent == NULL)
 
286
                        if (parent.isNull())
320
287
                        {
321
288
                                qWarning() << "ERROR : can't find parent solar system body for " << englishName;
322
289
                                abort();
325
292
                }
326
293
 
327
294
                const QString funcName = pd.value(secname+"/coord_func").toString();
328
 
                posFuncType posfunc;
 
295
                posFuncType posfunc=NULL;
 
296
                void* userDataPtr=NULL;
329
297
                OsulatingFunctType *osculatingFunc = 0;
330
298
                bool closeOrbit = pd.value(secname+"/closeOrbit", true).toBool();
331
299
 
351
319
                        } else {
352
320
                                pericenterDistance /= AU;
353
321
                                semi_major_axis = (eccentricity == 1.0)
354
 
                                                ? 0.0 // parabolic orbits have no semi_major_axis
355
 
                                                : pericenterDistance / (1.0-eccentricity);
 
322
                                                                ? 0.0 // parabolic orbits have no semi_major_axis
 
323
                                                                : pericenterDistance / (1.0-eccentricity);
356
324
                        }
357
325
                        double meanMotion = pd.value(secname+"/orbit_MeanMotion",-1e100).toDouble();
358
326
                        double period;
360
328
                                period = pd.value(secname+"/orbit_Period",-1e100).toDouble();
361
329
                                if (period <= -1e100) {
362
330
                                        meanMotion = (eccentricity == 1.0)
363
 
                                                    ? 0.01720209895 * (1.5/pericenterDistance)
364
 
                                                                    * sqrt(0.5/pericenterDistance)
365
 
                                                    : (semi_major_axis > 0.0)
366
 
                                                    ? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
367
 
                                                    : 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
 
331
                                                                ? 0.01720209895 * (1.5/pericenterDistance)
 
332
                                                                                                * sqrt(0.5/pericenterDistance)
 
333
                                                                : (semi_major_axis > 0.0)
 
334
                                                                ? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
 
335
                                                                : 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
368
336
                                        period = 2.0*M_PI/meanMotion;
369
337
                                } else {
370
338
                                        meanMotion = 2.0*M_PI/period;
395
363
 
396
364
                        // when the parent is the sun use ecliptic rathe than sun equator:
397
365
                        const double parentRotObliquity = parent->getParent()
398
 
                                                          ? parent->getRotObliquity()
399
 
                                                          : 0.0;
 
366
                                                                                          ? parent->getRotObliquity()
 
367
                                                                                          : 0.0;
400
368
                        const double parent_rot_asc_node = parent->getParent()
401
 
                                                          ? parent->getRotAscendingnode()
402
 
                                                          : 0.0;
 
369
                                                                                          ? parent->getRotAscendingnode()
 
370
                                                                                          : 0.0;
403
371
                        double parent_rot_j2000_longitude = 0.0;
404
372
                        if (parent->getParent()) {
405
373
                                const double c_obl = cos(parentRotObliquity);
417
385
 
418
386
                        // Create an elliptical orbit
419
387
                        EllipticalOrbit *orb = new EllipticalOrbit(pericenterDistance,
420
 
                                                                   eccentricity,
421
 
                                                                   inclination,
422
 
                                                                   ascending_node,
423
 
                                                                   arg_of_pericenter,
424
 
                                                                   mean_anomaly,
425
 
                                                                   period,
426
 
                                                                   epoch,
427
 
                                                                   parentRotObliquity,
428
 
                                                                   parent_rot_asc_node,
 
388
                                                                                                           eccentricity,
 
389
                                                                                                           inclination,
 
390
                                                                                                           ascending_node,
 
391
                                                                                                           arg_of_pericenter,
 
392
                                                                                                           mean_anomaly,
 
393
                                                                                                           period,
 
394
                                                                                                           epoch,
 
395
                                                                                                           parentRotObliquity,
 
396
                                                                                                           parent_rot_asc_node,
429
397
                                                                                                           parent_rot_j2000_longitude);
430
398
                        orbits.push_back(orb);
431
399
 
432
 
                        posfunc = posFuncType(orb, &EllipticalOrbit::positionAtTimevInVSOP87Coordinates);
433
 
                } 
 
400
                        userDataPtr = orb;
 
401
                        posfunc = &ellipticalOrbitPosFunc;
 
402
                }
434
403
                else if (funcName=="comet_orbit")
435
404
                {
436
405
                        // Read the orbital elements
455
424
                                }
456
425
                        } else {
457
426
                                semi_major_axis = (eccentricity == 1.0)
458
 
                                                ? 0.0 // parabolic orbits have no semi_major_axis
459
 
                                                : pericenterDistance / (1.0-eccentricity);
 
427
                                                                ? 0.0 // parabolic orbits have no semi_major_axis
 
428
                                                                : pericenterDistance / (1.0-eccentricity);
460
429
                        }
461
430
                        double meanMotion = pd.value(secname+"/orbit_MeanMotion",-1e100).toDouble();
462
431
                        if (meanMotion <= -1e100) {
470
439
                                                // in case of parent=sun: use Gaussian gravitational constant
471
440
                                                // for calculating meanMotion:
472
441
                                                meanMotion = (eccentricity == 1.0)
473
 
                                                            ? 0.01720209895 * (1.5/pericenterDistance)
474
 
                                                                            * sqrt(0.5/pericenterDistance)
475
 
                                                            : (semi_major_axis > 0.0)
476
 
                                                            ? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
477
 
                                                            : 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
 
442
                                                                        ? 0.01720209895 * (1.5/pericenterDistance)
 
443
                                                                                                        * sqrt(0.5/pericenterDistance)
 
444
                                                                        : (semi_major_axis > 0.0)
 
445
                                                                        ? 0.01720209895 / (semi_major_axis*sqrt(semi_major_axis))
 
446
                                                                        : 0.01720209895 / (-semi_major_axis*sqrt(-semi_major_axis));
478
447
                                        }
479
448
                                } else {
480
449
                                        meanMotion = 2.0*M_PI/period;
500
469
                        const double arg_of_pericenter = pd.value(secname+"/orbit_ArgOfPericenter").toDouble()*(M_PI/180.0);
501
470
                        const double ascending_node = pd.value(secname+"/orbit_AscendingNode").toDouble()*(M_PI/180.0);
502
471
                        const double parentRotObliquity = parent->getParent()
503
 
                                                          ? parent->getRotObliquity()
504
 
                                                          : 0.0;
 
472
                                                                                          ? parent->getRotObliquity()
 
473
                                                                                          : 0.0;
505
474
                        const double parent_rot_asc_node = parent->getParent()
506
 
                                                          ? parent->getRotAscendingnode()
507
 
                                                          : 0.0;
 
475
                                                                                          ? parent->getRotAscendingnode()
 
476
                                                                                          : 0.0;
508
477
                        double parent_rot_j2000_longitude = 0.0;
509
 
                        if (parent->getParent()) {
510
 
                           const double c_obl = cos(parentRotObliquity);
511
 
                           const double s_obl = sin(parentRotObliquity);
512
 
                           const double c_nod = cos(parent_rot_asc_node);
513
 
                           const double s_nod = sin(parent_rot_asc_node);
514
 
                           const Vec3d OrbitAxis0( c_nod,       s_nod,        0.0);
515
 
                           const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c_obl,s_obl);
516
 
                           const Vec3d OrbitPole(  s_nod*s_obl,-c_nod*s_obl,c_obl);
 
478
                                                if (parent->getParent()) {
 
479
                                                   const double c_obl = cos(parentRotObliquity);
 
480
                                                   const double s_obl = sin(parentRotObliquity);
 
481
                                                   const double c_nod = cos(parent_rot_asc_node);
 
482
                                                   const double s_nod = sin(parent_rot_asc_node);
 
483
                                                   const Vec3d OrbitAxis0( c_nod,       s_nod,        0.0);
 
484
                                                   const Vec3d OrbitAxis1(-s_nod*c_obl, c_nod*c_obl,s_obl);
 
485
                                                   const Vec3d OrbitPole(  s_nod*s_obl,-c_nod*s_obl,c_obl);
517
486
                                                   const Vec3d J2000Pole(StelNavigator::matJ2000ToVsop87.multiplyWithoutTranslation(Vec3d(0,0,1)));
518
 
                           Vec3d J2000NodeOrigin(J2000Pole^OrbitPole);
519
 
                           J2000NodeOrigin.normalize();
520
 
                           parent_rot_j2000_longitude = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
521
 
                        }
 
487
                                                   Vec3d J2000NodeOrigin(J2000Pole^OrbitPole);
 
488
                                                   J2000NodeOrigin.normalize();
 
489
                                                   parent_rot_j2000_longitude = atan2(J2000NodeOrigin*OrbitAxis1,J2000NodeOrigin*OrbitAxis0);
 
490
                                                }
522
491
                        CometOrbit *orb = new CometOrbit(pericenterDistance,
523
 
                                                         eccentricity,
524
 
                                                         inclination,
525
 
                                                         ascending_node,
526
 
                                                         arg_of_pericenter,
527
 
                                                         time_at_pericenter,
528
 
                                                         meanMotion,
529
 
                                                         parentRotObliquity,
530
 
                                                         parent_rot_asc_node,
 
492
                                                                                         eccentricity,
 
493
                                                                                         inclination,
 
494
                                                                                         ascending_node,
 
495
                                                                                         arg_of_pericenter,
 
496
                                                                                         time_at_pericenter,
 
497
                                                                                         meanMotion,
 
498
                                                                                         parentRotObliquity,
 
499
                                                                                         parent_rot_asc_node,
531
500
                                                                                         parent_rot_j2000_longitude);
532
501
                        orbits.push_back(orb);
533
 
 
534
 
                        posfunc = posFuncType(orb,&CometOrbit::positionAtTimevInVSOP87Coordinates);
 
502
                        userDataPtr = orb;
 
503
                        posfunc = &cometOrbitPosFunc;
535
504
                }
536
505
 
537
506
                if (funcName=="sun_special")
538
 
                        posfunc = posFuncType(get_sun_helio_coordsv);
 
507
                        posfunc = &get_sun_helio_coordsv;
539
508
 
540
509
                if (funcName=="mercury_special") {
541
 
                        posfunc = posFuncType(get_mercury_helio_coordsv);
 
510
                        posfunc = &get_mercury_helio_coordsv;
542
511
                        osculatingFunc = &get_mercury_helio_osculating_coords;
543
512
                }
544
 
        
 
513
 
545
514
                if (funcName=="venus_special") {
546
 
                        posfunc = posFuncType(get_venus_helio_coordsv);
 
515
                        posfunc = &get_venus_helio_coordsv;
547
516
                        osculatingFunc = &get_venus_helio_osculating_coords;
548
517
                }
549
518
 
550
519
                if (funcName=="earth_special") {
551
 
                        posfunc = posFuncType(get_earth_helio_coordsv);
 
520
                        posfunc = &get_earth_helio_coordsv;
552
521
                        osculatingFunc = &get_earth_helio_osculating_coords;
553
522
                }
554
523
 
555
524
                if (funcName=="lunar_special")
556
 
                        posfunc = posFuncType(get_lunar_parent_coordsv);
 
525
                        posfunc = &get_lunar_parent_coordsv;
557
526
 
558
527
                if (funcName=="mars_special") {
559
 
                        posfunc = posFuncType(get_mars_helio_coordsv);
 
528
                        posfunc = &get_mars_helio_coordsv;
560
529
                        osculatingFunc = &get_mars_helio_osculating_coords;
561
530
                }
562
531
 
564
533
                        posfunc = posFuncType(get_phobos_parent_coordsv);
565
534
 
566
535
                if (funcName=="deimos_special")
567
 
                        posfunc = posFuncType(get_deimos_parent_coordsv);
 
536
                        posfunc = &get_deimos_parent_coordsv;
568
537
 
569
538
                if (funcName=="jupiter_special") {
570
 
                        posfunc = posFuncType(get_jupiter_helio_coordsv);
 
539
                        posfunc = &get_jupiter_helio_coordsv;
571
540
                        osculatingFunc = &get_jupiter_helio_osculating_coords;
572
541
                }
573
542
 
574
543
                if (funcName=="europa_special")
575
 
                        posfunc = posFuncType(get_europa_parent_coordsv);
 
544
                        posfunc = &get_europa_parent_coordsv;
576
545
 
577
546
                if (funcName=="calisto_special")
578
 
                        posfunc = posFuncType(get_callisto_parent_coordsv);
 
547
                        posfunc = &get_callisto_parent_coordsv;
579
548
 
580
549
                if (funcName=="io_special")
581
 
                        posfunc = posFuncType(get_io_parent_coordsv);
 
550
                        posfunc = &get_io_parent_coordsv;
582
551
 
583
552
                if (funcName=="ganymede_special")
584
 
                        posfunc = posFuncType(get_ganymede_parent_coordsv);
 
553
                        posfunc = &get_ganymede_parent_coordsv;
585
554
 
586
555
                if (funcName=="saturn_special") {
587
 
                        posfunc = posFuncType(get_saturn_helio_coordsv);
 
556
                        posfunc = &get_saturn_helio_coordsv;
588
557
                        osculatingFunc = &get_saturn_helio_osculating_coords;
589
558
                }
590
559
 
591
560
                if (funcName=="mimas_special")
592
 
                        posfunc = posFuncType(get_mimas_parent_coordsv);
 
561
                        posfunc = &get_mimas_parent_coordsv;
593
562
 
594
563
                if (funcName=="enceladus_special")
595
 
                        posfunc = posFuncType(get_enceladus_parent_coordsv);
 
564
                        posfunc = &get_enceladus_parent_coordsv;
596
565
 
597
566
                if (funcName=="tethys_special")
598
 
                        posfunc = posFuncType(get_tethys_parent_coordsv);
 
567
                        posfunc = &get_tethys_parent_coordsv;
599
568
 
600
569
                if (funcName=="dione_special")
601
 
                        posfunc = posFuncType(get_dione_parent_coordsv);
 
570
                        posfunc = &get_dione_parent_coordsv;
602
571
 
603
572
                if (funcName=="rhea_special")
604
 
                        posfunc = posFuncType(get_rhea_parent_coordsv);
 
573
                        posfunc = &get_rhea_parent_coordsv;
605
574
 
606
575
                if (funcName=="titan_special")
607
 
                        posfunc = posFuncType(get_titan_parent_coordsv);
 
576
                        posfunc = &get_titan_parent_coordsv;
608
577
 
609
578
                if (funcName=="iapetus_special")
610
 
                        posfunc = posFuncType(get_iapetus_parent_coordsv);
 
579
                        posfunc = &get_iapetus_parent_coordsv;
611
580
 
612
581
                if (funcName=="hyperion_special")
613
 
                        posfunc = posFuncType(get_hyperion_parent_coordsv);
 
582
                        posfunc = &get_hyperion_parent_coordsv;
614
583
 
615
584
                if (funcName=="uranus_special") {
616
 
                        posfunc = posFuncType(get_uranus_helio_coordsv);
 
585
                        posfunc = &get_uranus_helio_coordsv;
617
586
                        osculatingFunc = &get_uranus_helio_osculating_coords;
618
587
                }
619
588
 
620
589
                if (funcName=="miranda_special")
621
 
                        posfunc = posFuncType(get_miranda_parent_coordsv);
 
590
                        posfunc = &get_miranda_parent_coordsv;
622
591
 
623
592
                if (funcName=="ariel_special")
624
 
                        posfunc = posFuncType(get_ariel_parent_coordsv);
 
593
                        posfunc = &get_ariel_parent_coordsv;
625
594
 
626
595
                if (funcName=="umbriel_special")
627
 
                        posfunc = posFuncType(get_umbriel_parent_coordsv);
 
596
                        posfunc = &get_umbriel_parent_coordsv;
628
597
 
629
598
                if (funcName=="titania_special")
630
 
                        posfunc = posFuncType(get_titania_parent_coordsv);
 
599
                        posfunc = &get_titania_parent_coordsv;
631
600
 
632
601
                if (funcName=="oberon_special")
633
 
                        posfunc = posFuncType(get_oberon_parent_coordsv);
 
602
                        posfunc = &get_oberon_parent_coordsv;
634
603
 
635
604
                if (funcName=="neptune_special") {
636
605
                        posfunc = posFuncType(get_neptune_helio_coordsv);
638
607
                }
639
608
 
640
609
                if (funcName=="pluto_special")
641
 
                        posfunc = posFuncType(get_pluto_helio_coordsv);
642
 
 
643
 
 
644
 
                if (posfunc.empty())
 
610
                        posfunc = &get_pluto_helio_coordsv;
 
611
 
 
612
 
 
613
                if (posfunc==NULL)
645
614
                {
646
615
                        qWarning() << "ERROR : can't find posfunc " << funcName << " for " << englishName;
647
616
                        exit(-1);
648
617
                }
649
618
 
650
619
                // Create the Planet and add it to the list
651
 
                Planet* p = new Planet(englishName,
 
620
                PlanetP p(new Planet(englishName,
652
621
                                        pd.value(secname+"/lighting").toBool(),
653
622
                                        pd.value(secname+"/radius").toDouble()/AU,
654
623
                                        pd.value(secname+"/oblateness", 0.0).toDouble(),
657
626
                                        pd.value(secname+"/tex_map").toString(),
658
627
                                        pd.value(secname+"/tex_halo").toString(),
659
628
                                        posfunc,
 
629
                                    userDataPtr,
660
630
                                        osculatingFunc,
661
631
                                        closeOrbit,
662
632
                                        pd.value(secname+"/hidden", 0).toBool(),
663
 
                                        pd.value(secname+"/atmosphere", false).toBool());
664
 
                if (parent!=NULL)
665
 
                        p->setParent(parent);
 
633
                                        pd.value(secname+"/atmosphere", false).toBool()));
 
634
                if (!parent.isNull())
 
635
                {
 
636
                        parent->satellites.append(p);
 
637
                        p->parent = parent;
 
638
                }
666
639
                if (secname=="earth") earth = p;
667
640
                if (secname=="sun") sun = p;
668
641
                if (secname=="moon") moon = p;
680
653
                {
681
654
                        Vec3d J2000NPole;
682
655
                        StelUtils::spheToRect(J2000NPoleRA,J2000NPoleDE,J2000NPole);
683
 
                  
 
656
 
684
657
                        Vec3d vsop87Pole(StelNavigator::matJ2000ToVsop87.multiplyWithoutTranslation(J2000NPole));
685
 
                  
 
658
 
686
659
                        double ra, de;
687
660
                        StelUtils::rectToSphe(&ra, &de, vsop87Pole);
688
 
                  
 
661
 
689
662
                        rotObliquity = (M_PI_2 - de);
690
663
                        rotAscNode = (ra + M_PI_2);
691
 
                  
 
664
 
692
665
                        // qDebug() << "\tCalculated rotational obliquity: " << rotObliquity*180./M_PI << endl;
693
666
                        // qDebug() << "\tCalculated rotational ascending node: " << rotAscNode*180./M_PI << endl;
694
667
                }
695
668
 
696
669
                p->setRotationElements(
697
 
                    pd.value(secname+"/rot_periode", pd.value(secname+"/orbit_Period", 24.).toDouble()).toDouble()/24.,
698
 
                    pd.value(secname+"/rot_rotation_offset",0.).toDouble(),
699
 
                    pd.value(secname+"/rot_epoch", J2000).toDouble(),
700
 
                    rotObliquity,
701
 
                    rotAscNode,
702
 
                    pd.value(secname+"/rot_precession_rate",0.).toDouble()*M_PI/(180*36525),
703
 
                    pd.value(secname+"/orbit_visualization_period",0.).toDouble());
 
670
                        pd.value(secname+"/rot_periode", pd.value(secname+"/orbit_Period", 24.).toDouble()).toDouble()/24.,
 
671
                        pd.value(secname+"/rot_rotation_offset",0.).toDouble(),
 
672
                        pd.value(secname+"/rot_epoch", J2000).toDouble(),
 
673
                        rotObliquity,
 
674
                        rotAscNode,
 
675
                        pd.value(secname+"/rot_precession_rate",0.).toDouble()*M_PI/(180*36525),
 
676
                        pd.value(secname+"/orbit_visualization_period",0.).toDouble());
704
677
 
705
678
 
706
679
                if (pd.value(secname+"/rings", 0).toBool()) {
715
688
        }
716
689
 
717
690
        // special case: load earth shadow texture
718
 
        StelApp::getInstance().getTextureManager().setDefaultParams();
719
691
        Planet::texEarthShadow = StelApp::getInstance().getTextureManager().createTexture("earth-shadow.png");
720
 
        
 
692
 
721
693
        qDebug() << "Loaded" << readOk << "/" << totalPlanets << "planet orbits";
722
694
}
723
695
 
727
699
{
728
700
        if (flagLightTravelTime)
729
701
        {
730
 
                for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
 
702
                foreach (PlanetP p, systemPlanets)
731
703
                {
732
 
                        (*iter)->computePositionWithoutOrbits(date);
 
704
                        p->computePositionWithoutOrbits(date);
733
705
                }
734
 
                for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
 
706
                foreach (PlanetP p, systemPlanets)
735
707
                {
736
 
                        const double light_speed_correction = ((*iter)->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
737
 
                        (*iter)->computePosition(date-light_speed_correction);
 
708
                        const double light_speed_correction = (p->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
 
709
                        p->computePosition(date-light_speed_correction);
738
710
                }
739
711
        }
740
712
        else
741
713
        {
742
 
                for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
 
714
                foreach (PlanetP p, systemPlanets)
743
715
                {
744
 
                        (*iter)->computePosition(date);
 
716
                        p->computePosition(date);
745
717
                }
746
 
        }  
 
718
        }
747
719
        computeTransMatrices(date, observerPos);
748
720
}
749
721
 
753
725
{
754
726
        if (flagLightTravelTime)
755
727
        {
756
 
                for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
 
728
                foreach (PlanetP p, systemPlanets)
757
729
                {
758
 
                        const double light_speed_correction = ((*iter)->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
759
 
                        (*iter)->computeTransMatrix(date-light_speed_correction);
 
730
                        const double light_speed_correction = (p->getHeliocentricEclipticPos()-observerPos).length() * (AU / (SPEED_OF_LIGHT * 86400));
 
731
                        p->computeTransMatrix(date-light_speed_correction);
760
732
                }
761
 
        }
 
733
        }
762
734
        else
763
735
        {
764
 
                for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
 
736
                foreach (PlanetP p, systemPlanets)
765
737
                {
766
 
                        (*iter)->computeTransMatrix(date);
 
738
                        p->computeTransMatrix(date);
767
739
                }
768
740
        }
769
741
}
770
742
 
 
743
// And sort them from the furthest to the closest to the observer
 
744
struct biggerDistance : public std::binary_function<PlanetP, PlanetP, bool>
 
745
{
 
746
        bool operator()(PlanetP p1, PlanetP p2)
 
747
        {
 
748
                return p1->getDistance() > p2->getDistance();
 
749
        }
 
750
};
 
751
 
771
752
// Draw all the elements of the solar system
772
753
// We are supposed to be in heliocentric coordinate
773
754
void SolarSystem::draw(StelCore* core)
774
755
{
775
756
        if (!flagShow)
776
757
                return;
777
 
        
 
758
 
778
759
        StelNavigator* nav = core->getNavigator();
779
 
        Planet::setFont(&planetNameFont);
780
760
 
781
761
        // Compute each Planet distance to the observer
782
762
        Vec3d obsHelioPos = nav->getObserverHeliocentricEclipticPos();
783
 
        
784
 
        vector<Planet*>::iterator iter;
785
 
        iter = systemPlanets.begin();
786
 
        while (iter != systemPlanets.end())
 
763
 
 
764
        foreach (PlanetP p, systemPlanets)
787
765
        {
788
 
                (*iter)->computeDistance(obsHelioPos);
789
 
                ++iter;
 
766
                p->computeDistance(obsHelioPos);
790
767
        }
791
768
 
792
769
        // And sort them from the furthest to the closest
794
771
 
795
772
        // Draw the elements
796
773
        float maxMagLabel=core->getSkyDrawer()->getLimitMagnitude()*0.80+(labelsAmount*1.2f)-2.f;
797
 
        iter = systemPlanets.begin();
798
 
        while (iter != systemPlanets.end())
 
774
        foreach (const PlanetP& p, systemPlanets)
799
775
        {
800
 
                (*iter)->draw(core, maxMagLabel);
801
 
                ++iter;
 
776
                p->draw(core, maxMagLabel, planetNameFont);
802
777
        }
803
778
 
804
779
        if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
810
785
        // Load colors from config file
811
786
        QSettings* conf = StelApp::getInstance().getSettings();
812
787
        QString section = style.confSectionName;
813
 
        
 
788
 
814
789
        QString defaultColor = conf->value(section+"/default_color").toString();
815
790
        setLabelsColor(StelUtils::strToVec3f(conf->value(section+"/planet_names_color", defaultColor).toString()));
816
791
        setOrbitsColor(StelUtils::strToVec3f(conf->value(section+"/planet_orbits_color", defaultColor).toString()));
817
792
        setTrailsColor(StelUtils::strToVec3f(conf->value(section+"/object_trails_color", defaultColor).toString()));
818
793
}
819
794
 
820
 
Planet* SolarSystem::searchByEnglishName(QString planetEnglishName) const
 
795
PlanetP SolarSystem::searchByEnglishName(QString planetEnglishName) const
821
796
{
822
 
        vector<Planet*>::const_iterator iter = systemPlanets.begin();
823
 
        while (iter != systemPlanets.end())
 
797
        foreach (const PlanetP& p, systemPlanets)
824
798
        {
825
 
                if((*iter)->getEnglishName() == planetEnglishName) return (*iter);  // also check standard ini file names
826
 
                ++iter;
 
799
                if (p->getEnglishName() == planetEnglishName)
 
800
                        return p;
827
801
        }
828
 
 
829
 
        return NULL;
 
802
        return PlanetP();
830
803
}
831
804
 
832
805
StelObjectP SolarSystem::searchByNameI18n(const QString& planetNameI18) const
833
806
{
834
 
        vector<Planet*>::const_iterator iter = systemPlanets.begin();
835
 
        while (iter != systemPlanets.end())
 
807
        foreach (const PlanetP& p, systemPlanets)
836
808
        {
837
 
                if( (*iter)->getNameI18n() == planetNameI18 ) return (*iter);  // also check standard ini file names
838
 
                ++iter;
 
809
                if (p->getNameI18n() == planetNameI18)
 
810
                        return qSharedPointerCast<StelObject>(p);
839
811
        }
840
 
        return NULL;
 
812
        return StelObjectP();
841
813
}
842
814
 
843
815
 
844
816
StelObjectP SolarSystem::searchByName(const QString& name) const
845
817
{
846
 
        vector<Planet*>::const_iterator iter = systemPlanets.begin();
847
 
        while (iter != systemPlanets.end())
 
818
        foreach (const PlanetP& p, systemPlanets)
848
819
        {
849
 
                if( (*iter)->getEnglishName() == name ) return (*iter); 
850
 
                ++iter;
 
820
                if (p->getEnglishName() == name)
 
821
                        return qSharedPointerCast<StelObject>(p);
851
822
        }
852
 
        return NULL;
 
823
        return StelObjectP();
853
824
}
854
825
 
855
826
// Search if any Planet is close to position given in earth equatorial position and return the distance
856
 
StelObject* SolarSystem::search(Vec3d pos, const StelCore* core) const
 
827
StelObjectP SolarSystem::search(Vec3d pos, const StelCore* core) const
857
828
{
858
829
        pos.normalize();
859
 
        Planet * closest = NULL;
 
830
        PlanetP closest;
860
831
        double cos_angle_closest = 0.;
861
832
        Vec3d equPos;
862
833
 
863
 
        vector<Planet*>::const_iterator iter = systemPlanets.begin();
864
 
        while (iter != systemPlanets.end())
 
834
        foreach (const PlanetP& p, systemPlanets)
865
835
        {
866
 
                equPos = (*iter)->getEquinoxEquatorialPos(core->getNavigator());
 
836
                equPos = p->getEquinoxEquatorialPos(core->getNavigator());
867
837
                equPos.normalize();
868
 
                double cos_ang_dist = equPos[0]*pos[0] + equPos[1]*pos[1] + equPos[2]*pos[2];
 
838
                double cos_ang_dist = equPos*pos;
869
839
                if (cos_ang_dist>cos_angle_closest)
870
840
                {
871
 
                        closest = *iter;
 
841
                        closest = p;
872
842
                        cos_angle_closest = cos_ang_dist;
873
843
                }
874
 
                iter++;
875
844
        }
876
845
 
877
846
        if (cos_angle_closest>0.999)
878
847
        {
879
 
                return closest;
 
848
                return qSharedPointerCast<StelObject>(closest);
880
849
        }
881
 
        else return NULL;
 
850
        else return StelObjectP();
882
851
}
883
852
 
884
853
// Return a stl vector containing the planets located inside the limFov circle around position v
887
856
        QList<StelObjectP> result;
888
857
        if (!getFlagPlanets())
889
858
                return result;
890
 
                
 
859
 
891
860
        Vec3d v = core->getNavigator()->j2000ToEquinoxEqu(vv);
892
861
        v.normalize();
893
 
        double cosLimFov = cos(limitFov * M_PI/180.);
 
862
        double cosLimFov = std::cos(limitFov * M_PI/180.);
894
863
        Vec3d equPos;
895
864
 
896
 
        vector<Planet*>::const_iterator iter = systemPlanets.begin();
897
 
        while (iter != systemPlanets.end())
 
865
        foreach (const PlanetP& p, systemPlanets)
898
866
        {
899
 
                equPos = (*iter)->getEquinoxEquatorialPos(core->getNavigator());
 
867
                equPos = p->getEquinoxEquatorialPos(core->getNavigator());
900
868
                equPos.normalize();
901
 
                if (equPos[0]*v[0] + equPos[1]*v[1] + equPos[2]*v[2]>=cosLimFov)
 
869
                if (equPos*v>=cosLimFov)
902
870
                {
903
 
                        result.push_back(*iter);
 
871
                        result.append(qSharedPointerCast<StelObject>(p));
904
872
                }
905
 
                iter++;
906
873
        }
907
874
        return result;
908
875
}
911
878
void SolarSystem::updateI18n()
912
879
{
913
880
        StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
914
 
        vector<Planet*>::iterator iter;
915
 
        for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
916
 
        {
917
 
                (*iter)->translateName(trans);
918
 
        }
919
 
        planetNameFont = StelApp::getInstance().getFontManager().getStandardFont(trans.getTrueLocaleName(), fontSize);
 
881
        foreach (PlanetP p, systemPlanets)
 
882
                p->translateName(trans);
920
883
}
921
884
 
922
885
QString SolarSystem::getPlanetHashString(void)
923
886
{
924
887
        QString str;
925
888
        QTextStream oss(&str);
926
 
        
927
 
        vector <Planet *>::iterator iter;
928
 
        for (iter = systemPlanets.begin(); iter != systemPlanets.end(); ++iter)
 
889
        foreach (const PlanetP& p, systemPlanets)
929
890
        {
930
 
                if((*iter)->getParent() != NULL && (*iter)->getParent()->getEnglishName() != "Sun")
 
891
                if (!p->getParent().isNull() && p->getParent()->getEnglishName() != "Sun")
931
892
                {
932
 
                        oss << (*iter)->getParent()->getEnglishName() << " : ";
 
893
                        oss << p->getParent()->getEnglishName() << " : ";
933
894
                }
934
 
                
935
 
                oss << (*iter)->getEnglishName() << endl;
936
 
                oss << (*iter)->getEnglishName() << endl;
 
895
                oss << p->getEnglishName() << endl;
 
896
                oss << p->getEnglishName() << endl;
937
897
        }
938
898
        return str;
939
899
}
940
900
 
941
901
void SolarSystem::startTrails(bool b)
942
902
{
943
 
        vector<Planet*>::iterator iter;
944
 
        for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
945
 
        {
946
 
                (*iter)->startTrail(b);
947
 
        }
 
903
        foreach (PlanetP p, systemPlanets)
 
904
                p->startTrail(b);
948
905
}
949
906
 
950
907
void SolarSystem::setFlagTrails(bool b)
951
908
{
952
 
        vector<Planet*>::iterator iter;
953
 
        for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
954
 
        {
955
 
                (*iter)->setFlagTrail(b);
956
 
        }
 
909
        foreach (PlanetP p, systemPlanets)
 
910
                p->setFlagTrail(b);
957
911
}
958
912
 
959
913
bool SolarSystem::getFlagTrails(void) const
960
914
{
961
 
        for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin();
962
 
             iter != systemPlanets.end(); iter++ ) {
963
 
                if ((*iter)->getFlagTrail()) return true;
 
915
        foreach (const PlanetP& p, systemPlanets)
 
916
        {
 
917
                if (p->getFlagTrail())
 
918
                        return true;
964
919
        }
965
920
        return false;
966
921
}
967
922
 
968
923
void SolarSystem::setFlagHints(bool b)
969
924
{
970
 
        vector<Planet*>::iterator iter;
971
 
        for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
972
 
        {
973
 
                (*iter)->setFlagHints(b);
974
 
        }
 
925
        foreach (PlanetP p, systemPlanets)
 
926
                p->setFlagHints(b);
975
927
}
976
928
 
977
929
bool SolarSystem::getFlagHints(void) const
978
930
{
979
 
        for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin(); iter != systemPlanets.end(); iter++)
 
931
        foreach (const PlanetP& p, systemPlanets)
980
932
        {
981
 
                if ((*iter)->getFlagHints()) return true;
 
933
                if (p->getFlagHints())
 
934
                        return true;
982
935
        }
983
936
        return false;
984
937
}
985
938
 
986
939
void SolarSystem::setFlagLabels(bool b)
987
940
{
988
 
        vector<Planet*>::iterator iter;
989
 
        for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
990
 
        {
991
 
                (*iter)->setFlagLabels(b);
992
 
        }
 
941
        foreach (PlanetP p, systemPlanets)
 
942
                p->setFlagLabels(b);
993
943
}
994
944
 
995
945
bool SolarSystem::getFlagLabels() const
996
946
{
997
 
        for (std::vector<Planet*>::const_iterator iter = systemPlanets.begin(); iter != systemPlanets.end(); iter++)
 
947
        foreach (const PlanetP& p, systemPlanets)
998
948
        {
999
 
                if ((*iter)->getFlagLabels()) return true;
 
949
                if (p->getFlagLabels())
 
950
                        return true;
1000
951
        }
1001
952
        return false;
1002
953
}
1004
955
void SolarSystem::setFlagOrbits(bool b)
1005
956
{
1006
957
        flagOrbits = b;
1007
 
        if (!b || !selected || selected == sun)
1008
 
        {
1009
 
                vector<Planet*>::iterator iter;
1010
 
                for( iter = systemPlanets.begin(); iter < systemPlanets.end(); iter++ )
 
958
        if (!b || !selected || selected==sun)
 
959
        {
 
960
                foreach (PlanetP p, systemPlanets)
 
961
                        p->setFlagOrbits(b);
 
962
        }
 
963
        else
 
964
        {
 
965
                // If a Planet is selected and orbits are on, fade out non-selected ones
 
966
                foreach (PlanetP p, systemPlanets)
1011
967
                {
1012
 
                        (*iter)->setFlagOrbits(b);
 
968
                        if (selected == p)
 
969
                                p->setFlagOrbits(b);
 
970
                        else
 
971
                                p->setFlagOrbits(false);
1013
972
                }
1014
973
        }
1015
 
        else
1016
 
        {
1017
 
                // if a Planet is selected and orbits are on,
1018
 
                // fade out non-selected ones
1019
 
                vector<Planet*>::iterator iter;
1020
 
                for (iter = systemPlanets.begin();
1021
 
                     iter != systemPlanets.end(); iter++ )
1022
 
                {
1023
 
                        if (selected == (*iter)) (*iter)->setFlagOrbits(b);
1024
 
                        else (*iter)->setFlagOrbits(false);
1025
 
                }               
1026
 
        }
1027
974
}
1028
975
 
1029
976
void SolarSystem::setFlagLightTravelTime(bool b)
1031
978
        flagLightTravelTime = b;
1032
979
}
1033
980
 
1034
 
void SolarSystem::setSelected(StelObject* obj)
 
981
void SolarSystem::setSelected(PlanetP obj)
1035
982
{
1036
 
    if (obj && obj->getType() == "Planet")
1037
 
        selected = obj;
1038
 
    else
1039
 
        selected = NULL;
 
983
        if (obj && obj->getType() == "Planet")
 
984
                selected = obj;
 
985
        else
 
986
                selected.clear();;
1040
987
        // Undraw other objects hints, orbit, trails etc..
1041
988
        setFlagHints(getFlagHints());
1042
989
        setFlagOrbits(getFlagOrbits());
1051
998
 
1052
999
        // Determine if home planet has changed, and restart planet trails
1053
1000
        // since the data is no longer useful
1054
 
        if (nav->getHomePlanet() != lastHomePlanet)
 
1001
        if (lastHomePlanet && nav->getCurrentLocation().planetName != lastHomePlanet->getEnglishName())
1055
1002
        {
1056
 
                lastHomePlanet = nav->getHomePlanet();
 
1003
                lastHomePlanet = searchByEnglishName(nav->getCurrentLocation().planetName);
 
1004
                Q_ASSERT(!lastHomePlanet.isNull());
1057
1005
                restartTrails = true;
1058
1006
        }
1059
1007
 
1060
 
        vector<Planet*>::iterator iter = systemPlanets.begin();
1061
 
        while (iter != systemPlanets.end())
 
1008
        foreach (PlanetP p, systemPlanets)
1062
1009
        {
1063
 
                if(restartTrails) (*iter)->startTrail(true);
1064
 
                (*iter)->updateTrail(nav);
1065
 
                (*iter)->update((int)(deltaTime*1000));
1066
 
                iter++;
 
1010
                if (restartTrails)
 
1011
                        p->startTrail(true);
 
1012
                p->updateTrail(nav);
 
1013
                p->update((int)(deltaTime*1000));
1067
1014
        }
1068
1015
}
1069
1016
 
1096
1043
QStringList SolarSystem::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
1097
1044
{
1098
1045
        QStringList result;
1099
 
        if (maxNbItem==0) return result;
1100
 
        
 
1046
        if (maxNbItem==0)
 
1047
                return result;
1101
1048
        QString objw = objPrefix.toUpper();
1102
 
        
1103
 
        vector <Planet*>::const_iterator iter;
1104
 
        for (iter=systemPlanets.begin(); iter!=systemPlanets.end(); ++iter)
 
1049
        foreach (const PlanetP& p, systemPlanets)
1105
1050
        {
1106
 
                QString constw = (*iter)->getNameI18n().mid(0, objw.size()).toUpper();
 
1051
                QString constw = p->getNameI18n().mid(0, objw.size()).toUpper();
1107
1052
                if (constw==objw)
1108
1053
                {
1109
 
                        result << (*iter)->getNameI18n();
 
1054
                        result << p->getNameI18n();
1110
1055
                        if (result.size()==maxNbItem)
1111
1056
                                return result;
1112
1057
                }
1118
1063
{
1119
1064
        const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)->getSelectedObject("Planet");
1120
1065
        if (!newSelected.empty())
1121
 
                setSelected(newSelected[0].get());
 
1066
                setSelected(qSharedPointerCast<Planet>(newSelected[0]));
1122
1067
}
1123
1068
 
1124
1069
// Activate/Deactivate planets display
1125
 
void SolarSystem::setFlagPlanets(bool b) 
 
1070
void SolarSystem::setFlagPlanets(bool b)
1126
1071
{
1127
1072
        flagShow=b;
1128
1073
}
1149
1094
        flagMoonScale = b;
1150
1095
}
1151
1096
 
1152
 
// Set/Get Moon display scaling factor 
 
1097
// Set/Get Moon display scaling factor
1153
1098
void SolarSystem::setMoonScale(float f)
1154
1099
{
1155
1100
        moonScale = f;
1163
1108
        setSelected(searchByEnglishName(englishName));
1164
1109
}
1165
1110
 
1166
 
bool SolarSystem::biggerDistance::operator()(Planet* p1, Planet* p2)
1167
 
{
1168
 
        return p1->getDistance() > p2->getDistance();
1169
 
}
1170
1111
 
1171
1112
// Get the list of all the planet english names
1172
1113
QStringList SolarSystem::getAllPlanetEnglishNames() const
1173
1114
{
1174
1115
        QStringList res;
1175
 
        for (std::vector<Planet*>::const_iterator iter(systemPlanets.begin());iter!=systemPlanets.end();iter++)
1176
 
        {
1177
 
                res.append((*iter)->englishName);
1178
 
        }
 
1116
        foreach (const PlanetP& p, systemPlanets)
 
1117
                res.append(p->englishName);
1179
1118
        return res;
1180
1119
}