LandscapeMgr.cpp   LandscapeMgr.cpp 
/* /*
* Stellarium * Stellarium
* Copyright (C) 2006 Fabien Chereau * Copyright (C) 2006 Fabien Chereau
* Copyright (C) 2010 Bogdan Marinov (add/remove landscapes feature) * Copyright (C) 2010 Bogdan Marinov (add/remove landscapes feature)
* Copyright (C) 2011 Alexander Wolf
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 93 skipping to change at line 94
} }
Cardinals::~Cardinals() Cardinals::~Cardinals()
{ {
} }
// Draw the cardinals points : N S E W // Draw the cardinals points : N S E W
// handles special cases at poles // handles special cases at poles
void Cardinals::draw(const StelCore* core, double latitude) const void Cardinals::draw(const StelCore* core, double latitude) const
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ; const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setFont(font); sPainter.setFont(font);
if (!fader.getInterstate()) return; if (!fader.getInterstate()) return;
// direction text // direction text
QString d[4]; QString d[4];
d[0] = sNorth; d[0] = sNorth;
d[1] = sSouth; d[1] = sSouth;
skipping to change at line 188 skipping to change at line 189
void LandscapeMgr::update(double deltaTime) void LandscapeMgr::update(double deltaTime)
{ {
atmosphere->update(deltaTime); atmosphere->update(deltaTime);
landscape->update(deltaTime); landscape->update(deltaTime);
cardinalsPoints->update(deltaTime); cardinalsPoints->update(deltaTime);
// Compute the atmosphere color and intensity // Compute the atmosphere color and intensity
// Compute the sun position in local coordinate // Compute the sun position in local coordinate
SolarSystem* ssystem = (SolarSystem*)StelApp::getInstance().getModul eMgr().getModule("SolarSystem"); SolarSystem* ssystem = (SolarSystem*)StelApp::getInstance().getModul eMgr().getModule("SolarSystem");
StelNavigator* nav = StelApp::getInstance().getCore()->getNavigator( );
Vec3d sunPos = ssystem->getSun()->getAltAzPos(nav); StelCore* core = StelApp::getInstance().getCore();
Vec3d sunPos = ssystem->getSun()->getAltAzPosApparent(core);
// Compute the moon position in local coordinate // Compute the moon position in local coordinate
Vec3d moonPos = ssystem->getMoon()->getAltAzPos(nav); Vec3d moonPos = ssystem->getMoon()->getAltAzPosApparent(core);
atmosphere->computeColor(nav->getJDay(), sunPos, moonPos, atmosphere->computeColor(core->getJDay(), sunPos, moonPos,
ssystem->getMoon()->getPhase(ssystem->getEarth()->getHelioce ntricEclipticPos()), ssystem->getMoon()->getPhase(ssystem->getEarth()->getHelioce ntricEclipticPos()),
StelApp::getInstance().getCore(), nav->getCurrentLocation(). latitude, nav->getCurrentLocation().altitude, core, core->getCurrentLocation().latitude, core->getCurrentL ocation().altitude,
15.f, 40.f); // Temperature = 15c, relative humidity = 40 % 15.f, 40.f); // Temperature = 15c, relative humidity = 40 %
StelApp::getInstance().getCore()->getSkyDrawer()->reportLuminanceInF ov(3.75+atmosphere->getAverageLuminance()*3.5, true); core->getSkyDrawer()->reportLuminanceInFov(3.75+atmosphere->getAvera geLuminance()*3.5, true);
// Compute the ground luminance based on every planets around // Compute the ground luminance based on every planets around
// float groundLuminance = 0; // float groundLuminance = 0;
// const vector<Planet*>& allPlanets = ssystem->getAllPlanets(); // const vector<Planet*>& allPlanets = ssystem->getAllPlanets();
// for (vector<Planet*>::const_iterator i=allPlanets.begin();i!=allPlan ets.end();++i) // for (vector<Planet*>::const_iterator i=allPlanets.begin();i!=allPlan ets.end();++i)
// { // {
// Vec3d pos = (*i)->getAltAzPos(nav); // Vec3d pos = (*i)->getAltAzPos(core);
// pos.normalize(); // pos.normalize();
// if (pos[2] <= 0) // if (pos[2] <= 0)
// { // {
// // No need to take this body into the landscape illu mination computation // // No need to take this body into the landscape illu mination computation
// // because it is under the horizon // // because it is under the horizon
// } // }
// else // else
// { // {
// // Compute the Illuminance E of the ground caused by the planet in lux = lumen/m^2 // // Compute the Illuminance E of the ground caused by the planet in lux = lumen/m^2
// float E = pow10(((*i)->get_mag(nav)+13.988)/-2.5); // float E = pow10(((*i)->get_mag(core)+13.988)/-2.5);
// //qDebug() << "mag=" << (*i)->get_mag(nav) << " illu // //qDebug() << "mag=" << (*i)->get_mag(core) << " ill
m=" << E; um=" << E;
// // Luminance in cd/m^2 // // Luminance in cd/m^2
// groundLuminance += E/0.44*pos[2]*pos[2]; // 1m^2 fro m 1.5 m above the ground is 0.44 sr. // groundLuminance += E/0.44*pos[2]*pos[2]; // 1m^2 fro m 1.5 m above the ground is 0.44 sr.
// } // }
// } // }
// groundLuminance*=atmosphere->getFadeIntensity(); // groundLuminance*=atmosphere->getFadeIntensity();
// groundLuminance=atmosphere->getAverageLuminance()/50; // groundLuminance=atmosphere->getAverageLuminance()/50;
// qDebug() << "Atmosphere lum=" << atmosphere->getAverageLuminance() < < " ground lum=" << groundLuminance; // qDebug() << "Atmosphere lum=" << atmosphere->getAverageLuminance() < < " ground lum=" << groundLuminance;
// qDebug() << "Adapted Atmosphere lum=" << eye->adaptLuminance(atmosph ere->getAverageLuminance()) << " Adapted ground lum=" << eye->adaptLuminanc e(groundLuminance); // qDebug() << "Adapted Atmosphere lum=" << eye->adaptLuminance(atmosph ere->getAverageLuminance()) << " Adapted ground lum=" << eye->adaptLuminanc e(groundLuminance);
// compute global ground brightness in a simplistic way, directly in RGB // compute global ground brightness in a simplistic way, directly in RGB
skipping to change at line 239 skipping to change at line 240
moonPos.normalize(); moonPos.normalize();
// We define the brigthness zero when the sun is 8 degrees below the horizon. // We define the brigthness zero when the sun is 8 degrees below the horizon.
float sinSunAngleRad = sin(qMin(M_PI_2, asin(sunPos[2])+8.*M_PI/180. )); float sinSunAngleRad = sin(qMin(M_PI_2, asin(sunPos[2])+8.*M_PI/180. ));
if(sinSunAngleRad < -0.1/1.5 ) if(sinSunAngleRad < -0.1/1.5 )
landscapeBrightness = 0.01; landscapeBrightness = 0.01;
else else
landscapeBrightness = (0.01 + 1.5*(sinSunAngleRad+0.1/1.5)); landscapeBrightness = (0.01 + 1.5*(sinSunAngleRad+0.1/1.5));
if (moonPos[2] > -0.1/1.5) if (moonPos[2] > -0.1/1.5)
landscapeBrightness += qMax(0.2/-12.*ssystem->getMoon()->get VMagnitude(nav),0.)*moonPos[2]; landscapeBrightness += qMax(0.2/-12.*ssystem->getMoon()->get VMagnitude(core),0.)*moonPos[2];
// TODO make this more generic for non-atmosphere planets // TODO make this more generic for non-atmosphere planets
if(atmosphere->getFadeIntensity() == 1) if(atmosphere->getFadeIntensity() == 1)
{ {
// If the atmosphere is on, a solar eclipse might darken the sky // If the atmosphere is on, a solar eclipse might darken the sky
// otherwise we just use the sun position calculation above // otherwise we just use the sun position calculation above
landscapeBrightness *= (atmosphere->getRealDisplayIntensityF actor()+0.1); landscapeBrightness *= (atmosphere->getRealDisplayIntensityF actor()+0.1);
} }
// TODO: should calculate dimming with solar eclipse even without at mosphere on // TODO: should calculate dimming with solar eclipse even without at mosphere on
skipping to change at line 262 skipping to change at line 263
void LandscapeMgr::draw(StelCore* core) void LandscapeMgr::draw(StelCore* core)
{ {
// Draw the atmosphere // Draw the atmosphere
atmosphere->draw(core); atmosphere->draw(core);
// Draw the landscape // Draw the landscape
landscape->draw(core); landscape->draw(core);
// Draw the cardinal points // Draw the cardinal points
cardinalsPoints->draw(core, StelApp::getInstance().getCore()->getNav igator()->getCurrentLocation().latitude); cardinalsPoints->draw(core, StelApp::getInstance().getCore()->getCur rentLocation().latitude);
} }
void LandscapeMgr::init() void LandscapeMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
atmosphere = new Atmosphere(); atmosphere = new Atmosphere();
landscape = new LandscapeOldStyle(); landscape = new LandscapeOldStyle();
defaultLandscapeID = conf->value("init_location/landscape_name").toS tring(); defaultLandscapeID = conf->value("init_location/landscape_name").toS tring();
skipping to change at line 284 skipping to change at line 285
setFlagLandscape(conf->value("landscape/flag_landscape", conf->value ("landscape/flag_ground", true).toBool()).toBool()); setFlagLandscape(conf->value("landscape/flag_landscape", conf->value ("landscape/flag_ground", true).toBool()).toBool());
setFlagFog(conf->value("landscape/flag_fog",true).toBool()); setFlagFog(conf->value("landscape/flag_fog",true).toBool());
setFlagAtmosphere(conf->value("landscape/flag_atmosphere").toBool()) ; setFlagAtmosphere(conf->value("landscape/flag_atmosphere").toBool()) ;
setAtmosphereFadeDuration(conf->value("landscape/atmosphere_fade_dur ation",0.5).toFloat()); setAtmosphereFadeDuration(conf->value("landscape/atmosphere_fade_dur ation",0.5).toFloat());
setAtmosphereLightPollutionLuminance(conf->value("viewing/light_poll ution_luminance",0.0).toFloat()); setAtmosphereLightPollutionLuminance(conf->value("viewing/light_poll ution_luminance",0.0).toFloat());
cardinalsPoints = new Cardinals(); cardinalsPoints = new Cardinals();
cardinalsPoints->setFlagShow(conf->value("viewing/flag_cardinal_poin ts",true).toBool()); cardinalsPoints->setFlagShow(conf->value("viewing/flag_cardinal_poin ts",true).toBool());
setFlagLandscapeSetsLocation(conf->value("landscape/flag_landscape_s ets_location",false).toBool()); setFlagLandscapeSetsLocation(conf->value("landscape/flag_landscape_s ets_location",false).toBool());
bool ok =true; bool ok =true;
setAtmosphereBortleLightPollution(conf->value("stars/init_bortle_sca le",3).toInt(&ok)); setAtmosphereBortleLightPollution(conf->value("landscape/init_bortle _scale",3).toInt(&ok));
if (!ok) if (!ok)
{ {
conf->setValue("stars/init_bortle_scale",3); conf->setValue("landscape/init_bortle_scale",3);
setAtmosphereBortleLightPollution(3); setAtmosphereBortleLightPollution(3);
ok = true; ok = true;
} }
StelApp *app = &StelApp::getInstance();
connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n()));
connect(app, SIGNAL(colorSchemeChanged(const QString&)), this, SLOT(
setStelStyle(const QString&)));
} }
void LandscapeMgr::setStelStyle(const QString& section) void LandscapeMgr::setStelStyle(const QString& section)
{ {
// Load colors from config file // Load colors from config file
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
QString defaultColor = conf->value(section+"/default_color").toStrin g(); QString defaultColor = conf->value(section+"/default_color").toStrin g();
setColorCardinalPoints(StelUtils::strToVec3f(conf->value(section+"/c ardinal_color", defaultColor).toString())); setColorCardinalPoints(StelUtils::strToVec3f(conf->value(section+"/c ardinal_color", defaultColor).toString()));
} }
skipping to change at line 333 skipping to change at line 337
// Copy display parameters from previous landscape to new on e // Copy display parameters from previous landscape to new on e
newLandscape->setFlagShow(landscape->getFlagShow()); newLandscape->setFlagShow(landscape->getFlagShow());
newLandscape->setFlagShowFog(landscape->getFlagShowFog()); newLandscape->setFlagShowFog(landscape->getFlagShowFog());
delete landscape; delete landscape;
landscape = newLandscape; landscape = newLandscape;
} }
currentLandscapeID = id; currentLandscapeID = id;
if (getFlagLandscapeSetsLocation()) if (getFlagLandscapeSetsLocation())
{ {
StelApp::getInstance().getCore()->getNavigator()->moveObserv StelApp::getInstance().getCore()->moveObserverTo(landscape->
erTo(landscape->getLocation()); getLocation());
// GZ Patch: allow change in fog, extinction, refraction par
ameters and light pollution
//QSettings* conf = StelApp::getInstance().getSettings();
//Q_ASSERT(conf);
StelSkyDrawer* drawer=StelApp::getInstance().getCore()->getS
kyDrawer();
if (landscape->getDefaultFogSetting() >-1)
{
setFlagFog((bool) landscape->getDefaultFogSetting());
landscape->setFlagShowFog((bool) landscape->getDefaultFo
gSetting());
}
if (landscape->getDefaultBortleIndex() > 0)
{
setAtmosphereBortleLightPollution(landscape->getDefaultB
ortleIndex());
// TODO: HOWTO make the GUI aware of the new value?
// conf->setValue("landscape/init_bortle_scale", landsca
pe->getDefaultBortleIndex());
}
if (landscape->getDefaultAtmosphericExtinction() >= 0.0)
{
drawer->setExtinctionCoefficient(landscape->getDefaultAt
mosphericExtinction());
}
if (landscape->getDefaultAtmosphericTemperature() > -273.15)
{
drawer->setAtmosphereTemperature(landscape->getDefaultAt
mosphericTemperature());
}
if (landscape->getDefaultAtmosphericPressure() >= 0.0)
{
drawer->setAtmospherePressure(landscape->getDefaultAtmos
phericPressure());
}
else if (landscape->getDefaultAtmosphericPressure() == -1.0)
{
// compute standard pressure for standard atmosphere in
given altitude if landscape.ini coded as atmospheric_pressure=-1
// International altitude formula found in Wikipedia.
double alt=landscape->getLocation().altitude;
double p=1013.25*std::pow(1-(0.0065*alt)/288.15, 5.255);
drawer->setAtmospherePressure(p);
}
} }
return true; return true;
} }
bool LandscapeMgr::setCurrentLandscapeName(const QString& name) bool LandscapeMgr::setCurrentLandscapeName(const QString& name)
{ {
if (name.isEmpty()) if (name.isEmpty())
return false; return false;
QMap<QString,QString> nameToDirMap = getNameToDirMap(); QMap<QString,QString> nameToDirMap = getNameToDirMap();
skipping to change at line 442 skipping to change at line 482
return result; return result;
} }
QString LandscapeMgr::getCurrentLandscapeName() const QString LandscapeMgr::getCurrentLandscapeName() const
{ {
return landscape->getName(); return landscape->getName();
} }
QString LandscapeMgr::getCurrentLandscapeHtmlDescription() const QString LandscapeMgr::getCurrentLandscapeHtmlDescription() const
{ {
QString desc = QString("<h3>%1</h3>").arg(landscape->getName()); SolarSystem* ssmgr = GETSTELMODULE(SolarSystem);
desc += landscape->getDescription(); QString planetName = ssmgr->searchByEnglishName(landscape->getLocati
desc+="<br><br>"; on().planetName)->getNameI18n();
QString desc = getDescription();
desc+="<p>";
desc+="<b>"+q_("Author: ")+"</b>"; desc+="<b>"+q_("Author: ")+"</b>";
desc+=landscape->getAuthorName(); desc+=landscape->getAuthorName();
desc+="<br>"; desc+="<br>";
desc+="<b>"+q_("Location: ")+"</b>"; desc+="<b>"+q_("Location: ")+"</b>";
if (landscape->getLocation().longitude>-500.0 && landscape->getLocat ion().latitude>-500.0) if (landscape->getLocation().longitude>-500.0 && landscape->getLocat ion().latitude>-500.0)
{ {
desc += StelUtils::radToDmsStrAdapt(landscape->getLocation() .longitude * M_PI/180.); desc += StelUtils::radToDmsStrAdapt(landscape->getLocation() .longitude * M_PI/180.);
desc += "/" + StelUtils::radToDmsStrAdapt(landscape->getLoca tion().latitude *M_PI/180.); desc += "/" + StelUtils::radToDmsStrAdapt(landscape->getLoca tion().latitude *M_PI/180.);
desc += QString(q_(", %1 m")).arg(landscape->getLocation().a ltitude); desc += QString(q_(", %1 m")).arg(landscape->getLocation().a ltitude);
if (landscape->getLocation().planetName!="") if (planetName!="")
{ {
desc += "<br><b>"+q_("Planet: ")+"</b>"+landscape->g etLocation().planetName; desc += "<br><b>"+q_("Planet: ")+"</b>"+planetName;
} }
desc += "<br><br>"; desc += "<br><br>";
} }
return desc; return desc;
} }
//! Set flag for displaying Cardinals Points //! Set flag for displaying Cardinals Points
void LandscapeMgr::setFlagCardinalsPoints(bool b) void LandscapeMgr::setFlagCardinalsPoints(bool b)
{ {
cardinalsPoints->setFlagShow(b); cardinalsPoints->setFlagShow(b);
skipping to change at line 918 skipping to change at line 959
QDir landscapeDir(landscapePath); QDir landscapeDir(landscapePath);
foreach (QFileInfo file, landscapeDir.entryInfoList(QDir::Files | QD ir::NoDotAndDotDot)) foreach (QFileInfo file, landscapeDir.entryInfoList(QDir::Files | QD ir::NoDotAndDotDot))
{ {
//qDebug() << "name:" << file.baseName() << "size:" << file. size(); //qDebug() << "name:" << file.baseName() << "size:" << file. size();
landscapeSize += file.size(); landscapeSize += file.size();
} }
return landscapeSize; return landscapeSize;
} }
QString LandscapeMgr::getDescription() const
{
QString lang = StelApp::getInstance().getLocaleMgr().getAppLanguage(
);
QString descriptionFile = StelFileMgr::findFile("landscapes/" + getC
urrentLandscapeID(), StelFileMgr::Directory) + "/description." + lang + ".u
tf8";
QString desc;
if(QFileInfo(descriptionFile).exists())
{
QFile file(descriptionFile);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&file);
in.setCodec("UTF-8");
desc = in.readAll();
file.close();
}
else
{
desc = QString("<h2>%1</h2>").arg(q_(landscape->getName()));
desc += landscape->getDescription();
}
return desc;
}
 End of changes. 19 change blocks. 
22 lines changed or deleted 74 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/