~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/modules/LandscapeMgr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2009-03-13 20:07:22 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (11.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090313200722-gbgujsmzsa8a02ty
Import upstream version 0.10.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "StelFileMgr.hpp"
34
34
#include "Planet.hpp"
35
35
#include "StelIniParser.hpp"
36
 
#include "SFont.hpp"
37
 
#include "SkyDrawer.hpp"
 
36
#include "StelFont.hpp"
 
37
#include "StelSkyDrawer.hpp"
38
38
#include "StelStyle.hpp"
 
39
#include "StelPainter.hpp"
39
40
 
40
41
// Class which manages the cardinal points displaying
41
42
class Cardinals
42
43
{
43
44
public:
44
45
        Cardinals(float _radius = 1.);
45
 
    virtual ~Cardinals();
46
 
        void draw(const Projector* prj, double latitude, bool gravityON = false) const;
 
46
        virtual ~Cardinals();
 
47
        void draw(const StelCore* core, double latitude, bool gravityON = false) const;
47
48
        void setColor(const Vec3f& c) {color = c;}
48
49
        Vec3f get_color() {return color;}
49
50
        void updateI18n();
54
55
private:
55
56
        float radius;
56
57
        double fontSize;
57
 
        SFont& font;
 
58
        StelFont& font;
58
59
        Vec3f color;
59
60
        QString sNorth, sSouth, sEast, sWest;
60
61
        LinearFader fader;
78
79
 
79
80
// Draw the cardinals points : N S E W
80
81
// handles special cases at poles
81
 
void Cardinals::draw(const Projector* prj, double latitude, bool gravityON) const
 
82
void Cardinals::draw(const StelCore* core, double latitude, bool gravityON) const
82
83
{
 
84
        const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz);
 
85
        StelPainter sPainter(prj);
 
86
        
83
87
        if (!fader.getInterstate()) return;
84
88
 
85
89
        // direction text
103
107
        Vec3f pos;
104
108
        Vec3d xy;
105
109
 
106
 
        prj->setCurrentFrame(Projector::FrameLocal);
107
 
 
108
110
        float shift = font.getStrLen(sNorth)/2;
109
111
 
110
112
        // N for North
111
113
        pos.set(-1.f, 0.f, 0.f);
112
 
        if (prj->project(pos,xy)) prj->drawText(&font, xy[0], xy[1], d[0], 0., -shift, -shift);
 
114
        if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[0], 0., -shift, -shift);
113
115
 
114
116
        // S for South
115
117
        pos.set(1.f, 0.f, 0.f);
116
 
        if (prj->project(pos,xy)) prj->drawText(&font, xy[0], xy[1], d[1], 0., -shift, -shift);
 
118
        if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[1], 0., -shift, -shift);
117
119
 
118
120
        // E for East
119
121
        pos.set(0.f, 1.f, 0.f);
120
 
        if (prj->project(pos,xy)) prj->drawText(&font, xy[0], xy[1], d[2], 0., -shift, -shift);
 
122
        if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[2], 0., -shift, -shift);
121
123
 
122
124
        // W for West
123
125
        pos.set(0.f, -1.f, 0.f);
124
 
        if (prj->project(pos,xy)) prj->drawText(&font, xy[0], xy[1], d[3], 0., -shift, -shift);
 
126
        if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[3], 0., -shift, -shift);
125
127
 
126
128
}
127
129
 
128
130
// Translate cardinal labels with gettext to current sky language and update font for the language
129
131
void Cardinals::updateI18n()
130
132
{
131
 
        Translator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
 
133
        StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
132
134
        sNorth = trans.qtranslate("N");
133
135
        sSouth = trans.qtranslate("S");
134
136
        sEast = trans.qtranslate("E");
171
173
        // Compute the atmosphere color and intensity
172
174
        // Compute the sun position in local coordinate
173
175
        SolarSystem* ssystem = (SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("SolarSystem");
174
 
        Navigator* nav = StelApp::getInstance().getCore()->getNavigation();
175
 
        Projector* prj = StelApp::getInstance().getCore()->getProjection();
176
 
        ToneReproducer* eye = StelApp::getInstance().getCore()->getToneReproducer();
 
176
        StelNavigator* nav = StelApp::getInstance().getCore()->getNavigator();
177
177
        
178
178
        Vec3d sunPos = ssystem->getSun()->getAltAzPos(nav);
179
179
        // Compute the moon position in local coordinate
180
180
        Vec3d moonPos = ssystem->getMoon()->getAltAzPos(nav);
181
181
        atmosphere->computeColor(nav->getJDay(), sunPos, moonPos,
182
 
                                  ssystem->getMoon()->getPhase(ssystem->getEarth()->getHeliocentricEclipticPos()),
183
 
                                  eye, prj, nav->getCurrentLocation().latitude, nav->getCurrentLocation().altitude,
184
 
                                  15.f, 40.f);  // Temperature = 15c, relative humidity = 40%
 
182
                ssystem->getMoon()->getPhase(ssystem->getEarth()->getHeliocentricEclipticPos()),
 
183
                StelApp::getInstance().getCore(), nav->getCurrentLocation().latitude, nav->getCurrentLocation().altitude,
 
184
                15.f, 40.f);    // Temperature = 15c, relative humidity = 40%
185
185
        
186
186
        StelApp::getInstance().getCore()->getSkyDrawer()->reportLuminanceInFov(3.75+atmosphere->getAverageLuminance()*3.5, true);
187
187
        
236
236
 
237
237
void LandscapeMgr::draw(StelCore* core)
238
238
{
239
 
        Navigator* nav = core->getNavigation();
240
 
        Projector* prj = core->getProjection();
241
 
        ToneReproducer* eye = core->getToneReproducer();
242
 
        
243
239
        // Draw the atmosphere
244
240
        atmosphere->draw(core);
245
241
 
246
242
        // Draw the landscape
247
 
        landscape->draw(eye, prj, nav);
 
243
        landscape->draw(core);
248
244
 
249
245
        // Draw the cardinal points
250
 
        cardinalsPoints->draw(prj, StelApp::getInstance().getCore()->getNavigation()->getCurrentLocation().latitude);
 
246
        cardinalsPoints->draw(core, StelApp::getInstance().getCore()->getNavigator()->getCurrentLocation().latitude);
251
247
}
252
248
 
253
249
void LandscapeMgr::init()
254
250
{
255
251
        QSettings* conf = StelApp::getInstance().getSettings();
256
 
        assert(conf);
 
252
        Q_ASSERT(conf);
257
253
 
258
254
        atmosphere = new Atmosphere();
259
255
        landscape = new LandscapeOldStyle();
260
256
        defaultLandscapeID = conf->value("init_location/landscape_name").toString();
261
 
        setCurrentLandscapeID(defaultLandscapeID);
 
257
        setCurrentLandscapeID(defaultLandscapeID, true);
262
258
        setFlagLandscape(conf->value("landscape/flag_landscape", conf->value("landscape/flag_ground", true).toBool()).toBool());
263
259
        setFlagFog(conf->value("landscape/flag_fog",true).toBool());
264
260
        setFlagAtmosphere(conf->value("landscape/flag_atmosphere").toBool());
276
272
                setAtmosphereBortleLightPollution(3);
277
273
                ok = true;
278
274
        }
 
275
        connect(this, SIGNAL(requestSetCurrentLandscapeID(const QString&)), this, SLOT(doSetCurrentLandscapeID(const QString&)));
 
276
        connect(this, SIGNAL(requestSetCurrentLandscapeName(const QString&)), this, SLOT(doSetCurrentLandscapeName(const QString&)));
279
277
}
280
278
 
281
279
void LandscapeMgr::setStelStyle(const StelStyle& style)
288
286
        setColorCardinalPoints(StelUtils::strToVec3f(conf->value(section+"/cardinal_color", defaultColor).toString()));
289
287
}
290
288
 
 
289
bool LandscapeMgr::setCurrentLandscapeID(const QString& id, bool inThread)
 
290
{
 
291
        if (inThread)
 
292
                return doSetCurrentLandscapeID(id);
 
293
        else
 
294
        {
 
295
                emit(requestSetCurrentLandscapeID(id));
 
296
                return true;
 
297
        }
 
298
}
291
299
 
292
 
bool LandscapeMgr::setCurrentLandscapeName(const QString& newLandscapeName)
 
300
bool LandscapeMgr::setCurrentLandscapeName(const QString& name, bool inThread)
293
301
{
294
 
        if (newLandscapeName.isEmpty())
295
 
                return 0;
296
 
        
297
302
        QMap<QString,QString> nameToDirMap = getNameToDirMap();
298
 
        if (nameToDirMap.find(newLandscapeName)!=nameToDirMap.end())
 
303
        if (nameToDirMap.find(name)!=nameToDirMap.end())
299
304
        {
300
 
                return setCurrentLandscapeID(nameToDirMap[newLandscapeName]);
 
305
                if (inThread)
 
306
                        return setCurrentLandscapeID(nameToDirMap[name], true);
 
307
                else
 
308
                {
 
309
                        emit(requestSetCurrentLandscapeName(name));
 
310
                        return true;
 
311
                }
301
312
        }
302
313
        else
303
314
        {
304
 
                qWarning() << "Can't find a landscape with name=" << newLandscapeName << endl;
305
 
                return false;
306
 
        }
307
 
}
308
 
 
309
 
 
310
 
bool LandscapeMgr::setCurrentLandscapeID(const QString& newLandscapeID)
311
 
{
312
 
        if (newLandscapeID.isEmpty())
313
 
                return 0;
314
 
        
315
 
        // we want to lookup the landscape ID (dir) from the name.
316
 
        StelFileMgr& fileMan = StelApp::getInstance().getFileMgr();
317
 
        Landscape* newLandscape = NULL;
318
 
        
319
 
        try
320
 
        {
321
 
                newLandscape = createFromFile(fileMan.findFile("landscapes/" + newLandscapeID + "/landscape.ini"), newLandscapeID);
322
 
        }
323
 
        catch (std::runtime_error& e)
324
 
        {
325
 
                qWarning() << "ERROR while loading landscape " << "landscapes/" + newLandscapeID + "/landscape.ini" << ", (" << e.what() << ")" << endl;
326
 
        }
327
 
 
328
 
        if (!newLandscape)
329
 
                return false;
330
 
 
331
 
        if (landscape)
332
 
        {
333
 
                // Copy display parameters from previous landscape to new one
334
 
                newLandscape->setFlagShow(landscape->getFlagShow());
335
 
                newLandscape->setFlagShowFog(landscape->getFlagShowFog());
336
 
                delete landscape;
337
 
                landscape = newLandscape;
338
 
        }
339
 
        currentLandscapeID = newLandscapeID;
340
 
        
341
 
        if (getFlagLandscapeSetsLocation())
342
 
        {
343
 
                StelApp::getInstance().getCore()->getNavigation()->moveObserverTo(landscape->getLocation());
344
 
        }
345
 
        return true;
 
315
                qWarning() << "Can't find a landscape with name=" << name << endl;
 
316
                return false;
 
317
        }
346
318
}
347
319
 
348
320
// Change the default landscape to the landscape with the ID specified.
420
392
        return result;
421
393
}
422
394
 
 
395
QStringList LandscapeMgr::getAllLandscapeIDs() const
 
396
{
 
397
        QMap<QString,QString> nameToDirMap = getNameToDirMap();
 
398
        QStringList result;
 
399
        
 
400
        // We just look over the map of names to IDs and extract the keys
 
401
        foreach (QString i, nameToDirMap.values())
 
402
        {
 
403
                result += i;
 
404
        }
 
405
        return result;
 
406
}
 
407
 
423
408
QString LandscapeMgr::getCurrentLandscapeName() const
424
409
{
425
410
        return landscape->getName();
517
502
        setAtmosphereLightPollutionLuminance(qMax(0.,0.0020*std::pow(bIndex-1, 2.1)));
518
503
}
519
504
 
 
505
void LandscapeMgr::setZRotation(double d)
 
506
{
 
507
        if (landscape)
 
508
                landscape->setZRotation(d);
 
509
}
 
510
 
520
511
float LandscapeMgr::getLuminance(void) 
521
512
{
522
513
        return atmosphere->getRealDisplayIntensityFactor();
566
557
        else if (param["type"]=="spherical")
567
558
        {
568
559
                LandscapeSpherical* ldscp = new LandscapeSpherical();
569
 
                ldscp->create(param["name"], 1, param["path"] + param["maptex"],param["angleRotatez"].toDouble());
 
560
                ldscp->create(param["name"], 1, param["path"] + param["maptex"],param["angleRotateZ"].toDouble());
570
561
                return ldscp;
571
562
        }
572
563
        else
574
565
                LandscapeFisheye* ldscp = new LandscapeFisheye();
575
566
                ldscp->create(param["name"], 1, param["path"] + param["maptex"],
576
567
                              param["texturefov"].toDouble(),
577
 
                      param["angleRotatez"].toDouble());
 
568
                      param["angleRotateZ"].toDouble());
578
569
                return ldscp;
579
570
        }
580
571
}
585
576
        
586
577
        if (nameToDirMap.find(name)!=nameToDirMap.end())
587
578
        {
588
 
                assert(0);
 
579
                Q_ASSERT(0);
589
580
                return "error";
590
581
        }
591
582
        else
627
618
 
628
619
        return result;  
629
620
}
 
621
 
 
622
bool LandscapeMgr::doSetCurrentLandscapeID(const QString& id)
 
623
{
 
624
        if (id.isEmpty())
 
625
        {
 
626
                emit(requestCompleteSetCurrentLandscapeID(false));
 
627
                return false;
 
628
        }
 
629
        
 
630
        // we want to lookup the landscape ID (dir) from the name.
 
631
        StelFileMgr& fileMan = StelApp::getInstance().getFileMgr();
 
632
        Landscape* newLandscape = NULL;
 
633
        
 
634
        try
 
635
        {
 
636
                newLandscape = createFromFile(fileMan.findFile("landscapes/" + id + "/landscape.ini"), id);
 
637
        }
 
638
        catch (std::runtime_error& e)
 
639
        {
 
640
                qWarning() << "ERROR while loading landscape " << "landscapes/" + id + "/landscape.ini" << ", (" << e.what() << ")" << endl;
 
641
        }
 
642
 
 
643
        if (!newLandscape)
 
644
        {
 
645
                emit(requestCompleteSetCurrentLandscapeID(false));
 
646
                return false;
 
647
        }
 
648
 
 
649
        if (landscape)
 
650
        {
 
651
                // Copy display parameters from previous landscape to new one
 
652
                newLandscape->setFlagShow(landscape->getFlagShow());
 
653
                newLandscape->setFlagShowFog(landscape->getFlagShowFog());
 
654
                delete landscape;
 
655
                landscape = newLandscape;
 
656
        }
 
657
        currentLandscapeID = id;
 
658
        
 
659
        if (getFlagLandscapeSetsLocation())
 
660
        {
 
661
                StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(landscape->getLocation());
 
662
        }
 
663
 
 
664
        emit(requestCompleteSetCurrentLandscapeID(true));
 
665
        return true;
 
666
}
 
667
 
 
668
bool LandscapeMgr::doSetCurrentLandscapeName(const QString& name)
 
669
{
 
670
        if (name.isEmpty())
 
671
        {
 
672
                emit(requestCompleteSetCurrentLandscapeName(false));
 
673
                return false;
 
674
        }
 
675
        
 
676
        QMap<QString,QString> nameToDirMap = getNameToDirMap();
 
677
        if (nameToDirMap.find(name)!=nameToDirMap.end())
 
678
        {
 
679
                bool result = setCurrentLandscapeID(nameToDirMap[name], true);
 
680
                emit(requestCompleteSetCurrentLandscapeName(result));
 
681
                return result;
 
682
        }
 
683
        else
 
684
        {
 
685
                qWarning() << "Can't find a landscape with name=" << name << endl;
 
686
                emit(requestCompleteSetCurrentLandscapeName(false));
 
687
                return false;
 
688
        }
 
689
}
 
690