LandscapeMgr.cpp   LandscapeMgr.cpp 
skipping to change at line 42 skipping to change at line 42
#include "Atmosphere.hpp" #include "Atmosphere.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelStyle.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
// Class which manages the cardinal points displaying // Class which manages the cardinal points displaying
class Cardinals class Cardinals
{ {
public: public:
Cardinals(float _radius = 1.); Cardinals(float _radius = 1.);
virtual ~Cardinals(); virtual ~Cardinals();
void draw(const StelCore* core, double latitude, bool gravityON = fa lse) const; void draw(const StelCore* core, double latitude) const;
void setColor(const Vec3f& c) {color = c;} void setColor(const Vec3f& c) {color = c;}
Vec3f get_color() {return color;} Vec3f get_color() {return color;}
void updateI18n(); void updateI18n();
void update(double deltaTime) {fader.update((int)(deltaTime*1000));} void update(double deltaTime) {fader.update((int)(deltaTime*1000));}
void set_fade_duration(float duration) {fader.setDuration((int)(dura tion*1000.f));} void set_fade_duration(float duration) {fader.setDuration((int)(dura tion*1000.f));}
void setFlagShow(bool b){fader = b;} void setFlagShow(bool b){fader = b;}
bool getFlagShow(void) const {return fader;} bool getFlagShow() const {return fader;}
private: private:
float radius; float radius;
QFont font; QFont font;
Vec3f color; Vec3f color;
QString sNorth, sSouth, sEast, sWest; QString sNorth, sSouth, sEast, sWest;
LinearFader fader; LinearFader fader;
}; };
Cardinals::Cardinals(float _radius) : radius(_radius), color(0.6,0.2,0.2) Cardinals::Cardinals(float _radius) : radius(_radius), color(0.6,0.2,0.2)
{ {
skipping to change at line 84 skipping to change at line 83
sEast = "E"; sEast = "E";
sWest = "W"; sWest = "W";
} }
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, bool gravityON) const void Cardinals::draw(const StelCore* core, double latitude) const
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ; const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ;
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];
skipping to change at line 111 skipping to change at line 110
if (latitude == 90.0 ) d[0] = d[1] = d[2] = d[3] = sSouth; if (latitude == 90.0 ) d[0] = d[1] = d[2] = d[3] = sSouth;
if (latitude == -90.0 ) d[0] = d[1] = d[2] = d[3] = sNorth; if (latitude == -90.0 ) d[0] = d[1] = d[2] = d[3] = sNorth;
sPainter.setColor(color[0],color[1],color[2],fader.getInterstate()); sPainter.setColor(color[0],color[1],color[2],fader.getInterstate());
glEnable(GL_BLEND); glEnable(GL_BLEND);
sPainter.enableTexture2d(true); sPainter.enableTexture2d(true);
// Normal transparency mode // Normal transparency mode
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Vec3f pos; Vec3f pos;
Vec3d xy; Vec3f xy;
float shift = sPainter.getFontMetrics().width(sNorth)/2; float shift = sPainter.getFontMetrics().width(sNorth)/2;
// N for North // N for North
pos.set(-1.f, 0.f, 0.f); pos.set(-1.f, 0.f, 0.f);
if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[0], 0., -shift, -shift); if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[0], 0., -shift, -shift);
// S for South // S for South
pos.set(1.f, 0.f, 0.f); pos.set(1.f, 0.f, 0.f);
if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[1], 0., -shift, -shift); if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[1], 0., -shift, -shift);
skipping to change at line 262 skipping to change at line 261
} }
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();
setCurrentLandscapeID(defaultLandscapeID, true); setCurrentLandscapeID(defaultLandscapeID);
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 setAtmosphereFadeDuration(conf->value("landscape/atmosphere_fade_dur
ation",1.5).toDouble()); ation",0.5).toFloat());
setAtmosphereLightPollutionLuminance(conf->value("viewing/light_poll setAtmosphereLightPollutionLuminance(conf->value("viewing/light_poll
ution_luminance",0.0).toDouble()); 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("stars/init_bortle_sca le",3).toInt(&ok));
if (!ok) if (!ok)
{ {
conf->setValue("stars/init_bortle_scale",3); conf->setValue("stars/init_bortle_scale",3);
setAtmosphereBortleLightPollution(3); setAtmosphereBortleLightPollution(3);
ok = true; ok = true;
} }
connect(this, SIGNAL(requestSetCurrentLandscapeID(const QString&)),
this, SLOT(doSetCurrentLandscapeID(const QString&)));
connect(this, SIGNAL(requestSetCurrentLandscapeName(const QString&))
, this, SLOT(doSetCurrentLandscapeName(const QString&)));
} }
void LandscapeMgr::setStelStyle(const StelStyle& style) 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 section = style.confSectionName;
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()));
} }
bool LandscapeMgr::setCurrentLandscapeID(const QString& id, bool inThread) bool LandscapeMgr::setCurrentLandscapeID(const QString& id)
{ {
if (inThread) if (id.isEmpty())
return doSetCurrentLandscapeID(id); return false;
else
// We want to lookup the landscape ID (dir) from the name.
Landscape* newLandscape = NULL;
try
{ {
emit(requestSetCurrentLandscapeID(id)); newLandscape = createFromFile(StelFileMgr::findFile("landsca
return true; pes/" + id + "/landscape.ini"), id);
}
catch (std::runtime_error& e)
{
qWarning() << "ERROR while loading default landscape " << "l
andscapes/" + id + "/landscape.ini" << ", (" << e.what() << ")";
}
if (!newLandscape)
return false;
if (landscape)
{
// Copy display parameters from previous landscape to new on
e
newLandscape->setFlagShow(landscape->getFlagShow());
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
delete landscape;
landscape = newLandscape;
}
currentLandscapeID = id;
if (getFlagLandscapeSetsLocation())
{
StelApp::getInstance().getCore()->getNavigator()->moveObserv
erTo(landscape->getLocation());
} }
return true;
} }
bool LandscapeMgr::setCurrentLandscapeName(const QString& name, bool inThre ad) bool LandscapeMgr::setCurrentLandscapeName(const QString& name)
{ {
if (name.isEmpty())
return false;
QMap<QString,QString> nameToDirMap = getNameToDirMap(); QMap<QString,QString> nameToDirMap = getNameToDirMap();
if (nameToDirMap.find(name)!=nameToDirMap.end()) if (nameToDirMap.find(name)!=nameToDirMap.end())
{ {
if (inThread) return setCurrentLandscapeID(nameToDirMap[name]);
return setCurrentLandscapeID(nameToDirMap[name], tru
e);
else
{
emit(requestSetCurrentLandscapeName(name));
return true;
}
} }
else else
{ {
qWarning() << "Can't find a landscape with name=" << name << endl; qWarning() << "Can't find a landscape with name=" << name << endl;
return false; return false;
} }
} }
// Change the default landscape to the landscape with the ID specified. // Change the default landscape to the landscape with the ID specified.
bool LandscapeMgr::setDefaultLandscapeID(const QString& id) bool LandscapeMgr::setDefaultLandscapeID(const QString& id)
{ {
if (id.isEmpty()) if (id.isEmpty())
return false; return false;
defaultLandscapeID = id; defaultLandscapeID = id;
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
conf->setValue("init_location/landscape_name", id); conf->setValue("init_location/landscape_name", id);
return true; return true;
} }
//! Load a landscape based on a hash of parameters mirroring the landscape.
ini file
//! and make it the current landscape
bool LandscapeMgr::loadLandscape(QMap<QString, QString>& param)
{
Landscape* newLandscape = createFromHash(param);
if (!newLandscape)
return false;
if (landscape)
{
// Copy parameters from previous landscape to new one
newLandscape->setFlagShow(landscape->getFlagShow());
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
delete landscape;
landscape = newLandscape;
}
currentLandscapeID = param["name"];
// probably not particularly useful, as not in landscape.ini file
return true;
}
void LandscapeMgr::updateI18n() void LandscapeMgr::updateI18n()
{ {
// Translate all labels with the new language // Translate all labels with the new language
if (cardinalsPoints) cardinalsPoints->updateI18n(); if (cardinalsPoints) cardinalsPoints->updateI18n();
} }
void LandscapeMgr::setFlagLandscape(bool b) void LandscapeMgr::setFlagLandscape(bool b)
{ {
landscape->setFlagShow(b); landscape->setFlagShow(b);
} }
bool LandscapeMgr::getFlagLandscape(void) const bool LandscapeMgr::getFlagLandscape() const
{ {
return landscape->getFlagShow(); return landscape->getFlagShow();
} }
void LandscapeMgr::setFlagFog(bool b) void LandscapeMgr::setFlagFog(bool b)
{ {
landscape->setFlagShowFog(b); landscape->setFlagShowFog(b);
} }
bool LandscapeMgr::getFlagFog(void) const bool LandscapeMgr::getFlagFog() const
{ {
return landscape->getFlagShowFog(); return landscape->getFlagShowFog();
} }
/********************************************************************* /*********************************************************************
Retrieve list of the names of all the available landscapes Retrieve list of the names of all the available landscapes
*********************************************************************/ *********************************************************************/
QStringList LandscapeMgr::getAllLandscapeNames() const QStringList LandscapeMgr::getAllLandscapeNames() const
{ {
QMap<QString,QString> nameToDirMap = getNameToDirMap(); QMap<QString,QString> nameToDirMap = getNameToDirMap();
skipping to change at line 448 skipping to change at line 444
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);
} }
//! Get flag for displaying Cardinals Points //! Get flag for displaying Cardinals Points
bool LandscapeMgr::getFlagCardinalsPoints(void) const bool LandscapeMgr::getFlagCardinalsPoints() const
{ {
return cardinalsPoints->getFlagShow(); return cardinalsPoints->getFlagShow();
} }
//! Set Cardinals Points color //! Set Cardinals Points color
void LandscapeMgr::setColorCardinalPoints(const Vec3f& v) void LandscapeMgr::setColorCardinalPoints(const Vec3f& v)
{ {
cardinalsPoints->setColor(v); cardinalsPoints->setColor(v);
} }
//! Get Cardinals Points color //! Get Cardinals Points color
Vec3f LandscapeMgr::getColorCardinalPoints(void) const Vec3f LandscapeMgr::getColorCardinalPoints() const
{ {
return cardinalsPoints->get_color(); return cardinalsPoints->get_color();
} }
/////////////////////////////////////////////////////////////////////////// //////////// /////////////////////////////////////////////////////////////////////////// ////////////
// Atmosphere // Atmosphere
//! Set flag for displaying Atmosphere //! Set flag for displaying Atmosphere
void LandscapeMgr::setFlagAtmosphere(bool b) void LandscapeMgr::setFlagAtmosphere(bool b)
{ {
atmosphere->setFlagShow(b); atmosphere->setFlagShow(b);
StelApp::getInstance().getCore()->getSkyDrawer()->setFlagHasAtmosphe re(b);
} }
//! Get flag for displaying Atmosphere //! Get flag for displaying Atmosphere
bool LandscapeMgr::getFlagAtmosphere(void) const bool LandscapeMgr::getFlagAtmosphere() const
{ {
return atmosphere->getFlagShow(); return atmosphere->getFlagShow();
} }
//! Set atmosphere fade duration in s //! Set atmosphere fade duration in s
void LandscapeMgr::setAtmosphereFadeDuration(float f) void LandscapeMgr::setAtmosphereFadeDuration(float f)
{ {
atmosphere->setFadeDuration(f); atmosphere->setFadeDuration(f);
} }
//! Get atmosphere fade duration in s //! Get atmosphere fade duration in s
float LandscapeMgr::getAtmosphereFadeDuration(void) const float LandscapeMgr::getAtmosphereFadeDuration() const
{ {
return atmosphere->getFadeDuration(); return atmosphere->getFadeDuration();
} }
//! Set light pollution luminance level //! Set light pollution luminance level
void LandscapeMgr::setAtmosphereLightPollutionLuminance(double f) void LandscapeMgr::setAtmosphereLightPollutionLuminance(float f)
{ {
atmosphere->setLightPollutionLuminance(f); atmosphere->setLightPollutionLuminance(f);
} }
//! Get light pollution luminance level //! Get light pollution luminance level
double LandscapeMgr::getAtmosphereLightPollutionLuminance(void) const float LandscapeMgr::getAtmosphereLightPollutionLuminance() const
{ {
return atmosphere->getLightPollutionLuminance(); return atmosphere->getLightPollutionLuminance();
} }
//! Set the light pollution following the Bortle Scale //! Set the light pollution following the Bortle Scale
void LandscapeMgr::setAtmosphereBortleLightPollution(int bIndex) void LandscapeMgr::setAtmosphereBortleLightPollution(int bIndex)
{ {
// This is an empirical formula // This is an empirical formula
setAtmosphereLightPollutionLuminance(qMax(0.,0.0020*std::pow(bIndex- 1, 2.1))); setAtmosphereLightPollutionLuminance(qMax(0.,0.0020*std::pow(bIndex- 1, 2.1)));
} }
//! Get the light pollution following the Bortle Scale //! Get the light pollution following the Bortle Scale
int LandscapeMgr::getAtmosphereBortleLightPollution(void) int LandscapeMgr::getAtmosphereBortleLightPollution()
{ {
return (int)std::pow(getAtmosphereLightPollutionLuminance()/0.0020, 1./2.1) + 1; return (int)std::pow(getAtmosphereLightPollutionLuminance()/0.0020, 1./2.1) + 1;
} }
void LandscapeMgr::setZRotation(double d) void LandscapeMgr::setZRotation(float d)
{ {
if (landscape) if (landscape)
landscape->setZRotation(d); landscape->setZRotation(d);
} }
float LandscapeMgr::getLuminance(void) float LandscapeMgr::getLuminance()
{ {
return atmosphere->getRealDisplayIntensityFactor(); return atmosphere->getRealDisplayIntensityFactor();
} }
Landscape* LandscapeMgr::createFromFile(const QString& landscapeFile, const QString& landscapeId) Landscape* LandscapeMgr::createFromFile(const QString& landscapeFile, const QString& landscapeId)
{ {
QSettings landscapeIni(landscapeFile, StelIniFormat); QSettings landscapeIni(landscapeFile, StelIniFormat);
QString s; QString s;
if (landscapeIni.status() != QSettings::NoError) if (landscapeIni.status() != QSettings::NoError)
{ {
skipping to change at line 559 skipping to change at line 556
// to avoid making this a fatal error, will load as a fishey e // to avoid making this a fatal error, will load as a fishey e
// if this fails, it just won't draw // if this fails, it just won't draw
ldscp = new LandscapeFisheye(); ldscp = new LandscapeFisheye();
} }
ldscp->load(landscapeIni, landscapeId); ldscp->load(landscapeIni, landscapeId);
return ldscp; return ldscp;
} }
Landscape* LandscapeMgr::createFromHash(QMap<QString, QString>& param)
{
// NOTE: textures should be full filename (and path)
if (param["type"]=="old_style")
{
LandscapeOldStyle* ldscp = new LandscapeOldStyle();
ldscp->create(1, param);
return ldscp;
}
else if (param["type"]=="spherical")
{
LandscapeSpherical* ldscp = new LandscapeSpherical();
ldscp->create(param["name"], 1, param["path"] + param["mapte
x"],param["angleRotateZ"].toDouble());
return ldscp;
}
else
{ // if (s=="fisheye")
LandscapeFisheye* ldscp = new LandscapeFisheye();
ldscp->create(param["name"], 1, param["path"] + param["mapte
x"],
param["texturefov"].toDouble(),
param["angleRotateZ"].toDouble());
return ldscp;
}
}
QString LandscapeMgr::nameToID(const QString& name) QString LandscapeMgr::nameToID(const QString& name)
{ {
QMap<QString,QString> nameToDirMap = getNameToDirMap(); QMap<QString,QString> nameToDirMap = getNameToDirMap();
if (nameToDirMap.find(name)!=nameToDirMap.end()) if (nameToDirMap.find(name)!=nameToDirMap.end())
{ {
Q_ASSERT(0); Q_ASSERT(0);
return "error"; return "error";
} }
else else
{ {
return nameToDirMap[name]; return nameToDirMap[name];
} }
} }
/************************************************************************** ** /************************************************************************** **
get a map of landscape name (from landscape.ini name field) to ID (dir nam e) get a map of landscape name (from landscape.ini name field) to ID (dir nam e)
************************************************************************** **/ ************************************************************************** **/
QMap<QString,QString> LandscapeMgr::getNameToDirMap(void) const QMap<QString,QString> LandscapeMgr::getNameToDirMap() const
{ {
QSet<QString> landscapeDirs; QSet<QString> landscapeDirs;
QMap<QString,QString> result; QMap<QString,QString> result;
try try
{ {
landscapeDirs = StelFileMgr::listContents("landscapes",StelF ileMgr::Directory); landscapeDirs = StelFileMgr::listContents("landscapes",StelF ileMgr::Directory);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "ERROR while trying list landscapes:" << e.what( ); qDebug() << "ERROR while trying list landscapes:" << e.what( );
skipping to change at line 630 skipping to change at line 602
QString k = landscapeIni.value("landscape/name").toS tring(); QString k = landscapeIni.value("landscape/name").toS tring();
result[k] = dir; result[k] = dir;
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
//qDebug << "WARNING: unable to successfully read la ndscape.ini file from landscape " << dir; //qDebug << "WARNING: unable to successfully read la ndscape.ini file from landscape " << dir;
} }
} }
return result; return result;
} }
bool LandscapeMgr::doSetCurrentLandscapeID(const QString& id)
{
if (id.isEmpty())
{
emit(requestCompleteSetCurrentLandscapeID(false));
return false;
}
// We want to lookup the landscape ID (dir) from the name.
Landscape* newLandscape = NULL;
try
{
newLandscape = createFromFile(StelFileMgr::findFile("landsca
pes/" + id + "/landscape.ini"), id);
}
catch (std::runtime_error& e)
{
qWarning() << "ERROR while loading landscape " << "landscape
s/" + id + "/landscape.ini" << ", (" << e.what() << ")" << endl;
}
if (!newLandscape)
{
emit(requestCompleteSetCurrentLandscapeID(false));
return false;
}
if (landscape)
{
// Copy display parameters from previous landscape to new on
e
newLandscape->setFlagShow(landscape->getFlagShow());
newLandscape->setFlagShowFog(landscape->getFlagShowFog());
delete landscape;
landscape = newLandscape;
}
currentLandscapeID = id;
if (getFlagLandscapeSetsLocation())
{
StelApp::getInstance().getCore()->getNavigator()->moveObserv
erTo(landscape->getLocation());
}
emit(requestCompleteSetCurrentLandscapeID(true));
return true;
}
bool LandscapeMgr::doSetCurrentLandscapeName(const QString& name)
{
if (name.isEmpty())
{
emit(requestCompleteSetCurrentLandscapeName(false));
return false;
}
QMap<QString,QString> nameToDirMap = getNameToDirMap();
if (nameToDirMap.find(name)!=nameToDirMap.end())
{
bool result = setCurrentLandscapeID(nameToDirMap[name], true
);
emit(requestCompleteSetCurrentLandscapeName(result));
return result;
}
else
{
qWarning() << "Can't find a landscape with name=" << name <<
endl;
emit(requestCompleteSetCurrentLandscapeName(false));
return false;
}
}
 End of changes. 34 change blocks. 
94 lines changed or deleted 64 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/