33
33
#include "StelFileMgr.hpp"
34
34
#include "Planet.hpp"
35
35
#include "StelIniParser.hpp"
37
#include "SkyDrawer.hpp"
36
#include "StelFont.hpp"
37
#include "StelSkyDrawer.hpp"
38
38
#include "StelStyle.hpp"
39
#include "StelPainter.hpp"
40
41
// Class which manages the cardinal points displaying
44
45
Cardinals(float _radius = 1.);
46
void draw(const Projector* prj, double latitude, bool gravityON = false) const;
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;}
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
84
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz);
85
StelPainter sPainter(prj);
83
87
if (!fader.getInterstate()) return;
106
prj->setCurrentFrame(Projector::FrameLocal);
108
110
float shift = font.getStrLen(sNorth)/2;
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);
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);
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);
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);
128
130
// Translate cardinal labels with gettext to current sky language and update font for the language
129
131
void Cardinals::updateI18n()
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();
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%
186
186
StelApp::getInstance().getCore()->getSkyDrawer()->reportLuminanceInFov(3.75+atmosphere->getAverageLuminance()*3.5, true);
237
237
void LandscapeMgr::draw(StelCore* core)
239
Navigator* nav = core->getNavigation();
240
Projector* prj = core->getProjection();
241
ToneReproducer* eye = core->getToneReproducer();
243
239
// Draw the atmosphere
244
240
atmosphere->draw(core);
246
242
// Draw the landscape
247
landscape->draw(eye, prj, nav);
243
landscape->draw(core);
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);
253
249
void LandscapeMgr::init()
255
251
QSettings* conf = StelApp::getInstance().getSettings();
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);
275
connect(this, SIGNAL(requestSetCurrentLandscapeID(const QString&)), this, SLOT(doSetCurrentLandscapeID(const QString&)));
276
connect(this, SIGNAL(requestSetCurrentLandscapeName(const QString&)), this, SLOT(doSetCurrentLandscapeName(const QString&)));
281
279
void LandscapeMgr::setStelStyle(const StelStyle& style)
288
286
setColorCardinalPoints(StelUtils::strToVec3f(conf->value(section+"/cardinal_color", defaultColor).toString()));
289
bool LandscapeMgr::setCurrentLandscapeID(const QString& id, bool inThread)
292
return doSetCurrentLandscapeID(id);
295
emit(requestSetCurrentLandscapeID(id));
292
bool LandscapeMgr::setCurrentLandscapeName(const QString& newLandscapeName)
300
bool LandscapeMgr::setCurrentLandscapeName(const QString& name, bool inThread)
294
if (newLandscapeName.isEmpty())
297
302
QMap<QString,QString> nameToDirMap = getNameToDirMap();
298
if (nameToDirMap.find(newLandscapeName)!=nameToDirMap.end())
303
if (nameToDirMap.find(name)!=nameToDirMap.end())
300
return setCurrentLandscapeID(nameToDirMap[newLandscapeName]);
306
return setCurrentLandscapeID(nameToDirMap[name], true);
309
emit(requestSetCurrentLandscapeName(name));
304
qWarning() << "Can't find a landscape with name=" << newLandscapeName << endl;
310
bool LandscapeMgr::setCurrentLandscapeID(const QString& newLandscapeID)
312
if (newLandscapeID.isEmpty())
315
// we want to lookup the landscape ID (dir) from the name.
316
StelFileMgr& fileMan = StelApp::getInstance().getFileMgr();
317
Landscape* newLandscape = NULL;
321
newLandscape = createFromFile(fileMan.findFile("landscapes/" + newLandscapeID + "/landscape.ini"), newLandscapeID);
323
catch (std::runtime_error& e)
325
qWarning() << "ERROR while loading landscape " << "landscapes/" + newLandscapeID + "/landscape.ini" << ", (" << e.what() << ")" << endl;
333
// Copy display parameters from previous landscape to new one
334
newLandscape->setFlagShow(landscape->getFlagShow());
335
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
337
landscape = newLandscape;
339
currentLandscapeID = newLandscapeID;
341
if (getFlagLandscapeSetsLocation())
343
StelApp::getInstance().getCore()->getNavigation()->moveObserverTo(landscape->getLocation());
315
qWarning() << "Can't find a landscape with name=" << name << endl;
348
320
// Change the default landscape to the landscape with the ID specified.
395
QStringList LandscapeMgr::getAllLandscapeIDs() const
397
QMap<QString,QString> nameToDirMap = getNameToDirMap();
400
// We just look over the map of names to IDs and extract the keys
401
foreach (QString i, nameToDirMap.values())
423
408
QString LandscapeMgr::getCurrentLandscapeName() const
425
410
return landscape->getName();
517
502
setAtmosphereLightPollutionLuminance(qMax(0.,0.0020*std::pow(bIndex-1, 2.1)));
505
void LandscapeMgr::setZRotation(double d)
508
landscape->setZRotation(d);
520
511
float LandscapeMgr::getLuminance(void)
522
513
return atmosphere->getRealDisplayIntensityFactor();
566
557
else if (param["type"]=="spherical")
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());
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());
622
bool LandscapeMgr::doSetCurrentLandscapeID(const QString& id)
626
emit(requestCompleteSetCurrentLandscapeID(false));
630
// we want to lookup the landscape ID (dir) from the name.
631
StelFileMgr& fileMan = StelApp::getInstance().getFileMgr();
632
Landscape* newLandscape = NULL;
636
newLandscape = createFromFile(fileMan.findFile("landscapes/" + id + "/landscape.ini"), id);
638
catch (std::runtime_error& e)
640
qWarning() << "ERROR while loading landscape " << "landscapes/" + id + "/landscape.ini" << ", (" << e.what() << ")" << endl;
645
emit(requestCompleteSetCurrentLandscapeID(false));
651
// Copy display parameters from previous landscape to new one
652
newLandscape->setFlagShow(landscape->getFlagShow());
653
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
655
landscape = newLandscape;
657
currentLandscapeID = id;
659
if (getFlagLandscapeSetsLocation())
661
StelApp::getInstance().getCore()->getNavigator()->moveObserverTo(landscape->getLocation());
664
emit(requestCompleteSetCurrentLandscapeID(true));
668
bool LandscapeMgr::doSetCurrentLandscapeName(const QString& name)
672
emit(requestCompleteSetCurrentLandscapeName(false));
676
QMap<QString,QString> nameToDirMap = getNameToDirMap();
677
if (nameToDirMap.find(name)!=nameToDirMap.end())
679
bool result = setCurrentLandscapeID(nameToDirMap[name], true);
680
emit(requestCompleteSetCurrentLandscapeName(result));
685
qWarning() << "Can't find a landscape with name=" << name << endl;
686
emit(requestCompleteSetCurrentLandscapeName(false));