StarMgr.cpp   StarMgr.cpp 
skipping to change at line 32 skipping to change at line 32
// class used to manage groups of Stars // class used to manage groups of Stars
#include <config.h> #include <config.h>
#include <QTextStream> #include <QTextStream>
#include <QFile> #include <QFile>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QRegExp> #include <QRegExp>
#include <QDebug> #include <QDebug>
#include <QFileInfo>
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "StelTexture.hpp" #include "StelTexture.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelToneReproducer.hpp" #include "StelToneReproducer.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelGeodesicGrid.hpp" #include "StelGeodesicGrid.hpp"
#include "StelLoadingBar.hpp" #include "StelLoadingBar.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelFontMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "bytes.h"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelJsonParser.hpp"
#include "ZoneArray.hpp" #include "ZoneArray.hpp"
#include <list> #include <list>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
using namespace BigStarCatalogExtension; using namespace BigStarCatalogExtension;
static QStringList spectral_array; static QStringList spectral_array;
static QStringList component_array; static QStringList component_array;
// This number must be incremented each time the content or file format of
the stars catalogs change
// It can also be incremented when the defaultStarsConfig.json file change.
// It should always matchs the version field of the defaultStarsConfig.json
file
static const int StarCatalogFormatVersion = 2;
// Initialise statics // Initialise statics
bool StarMgr::flagSciNames = true; bool StarMgr::flagSciNames = true;
std::map<int,QString> StarMgr::commonNamesMap; std::map<int,QString> StarMgr::commonNamesMap;
std::map<int,QString> StarMgr::commonNamesMapI18n; std::map<int,QString> StarMgr::commonNamesMapI18n;
std::map<QString,int> StarMgr::commonNamesIndex; std::map<QString,int> StarMgr::commonNamesIndex;
std::map<QString,int> StarMgr::commonNamesIndexI18n; std::map<QString,int> StarMgr::commonNamesIndexI18n;
std::map<int,QString> StarMgr::sciNamesMapI18n; std::map<int,QString> StarMgr::sciNamesMapI18n;
std::map<QString,int> StarMgr::sciNamesIndexI18n; std::map<QString,int> StarMgr::sciNamesIndexI18n;
QStringList initStringListFromFile(const QString& file_name) QStringList initStringListFromFile(const QString& file_name)
skipping to change at line 101 skipping to change at line 105
f.close(); f.close();
} }
return list; return list;
} }
QString StarMgr::convertToSpectralType(int index) QString StarMgr::convertToSpectralType(int index)
{ {
if (index < 0 || index >= spectral_array.size()) if (index < 0 || index >= spectral_array.size())
{ {
qDebug() << "convertToSpectralType: bad index: " << index << ", max: " << spectral_array.size(); qDebug() << "convertToSpectralType: bad index: " << index << ", max: " << spectral_array.size();
return ""; return "";
} }
return spectral_array.at(index); return spectral_array.at(index);
} }
QString StarMgr::convertToComponentIds(int index) QString StarMgr::convertToComponentIds(int index)
{ {
if (index < 0 || index >= component_array.size()) if (index < 0 || index >= component_array.size())
{ {
qDebug() << "convertToComponentIds: bad index: " << index << ", max: " << component_array.size(); qDebug() << "convertToComponentIds: bad index: " << index << ", max: " << component_array.size();
return ""; return "";
} }
return component_array.at(index); return component_array.at(index);
} }
void StarMgr::initTriangle(int lev,int index, void StarMgr::initTriangle(int lev,int index,
const Vec3d &c0, const Vec3d &c0,
const Vec3d &c1, const Vec3d &c1,
const Vec3d &c2) { const Vec3d &c2) {
ZoneArrayMap::const_iterator it(zoneArrays.find(lev)); ZoneArrayMap::const_iterator it(zoneArrays.find(lev));
if (it!=zoneArrays.end()) it->second->initTriangle(index,c0,c1,c2); if (it!=zoneArrays.end()) it->second->initTriangle(index,c0,c1,c2);
} }
StarMgr::StarMgr(void) : hipIndex(new HipIndexStruct[NR_OF_HIP+1]), fontSiz e(13.), starFont(NULL) StarMgr::StarMgr(void) : hipIndex(new HipIndexStruct[NR_OF_HIP+1])
{ {
setObjectName("StarMgr"); setObjectName("StarMgr");
if (hipIndex == 0) if (hipIndex == 0)
{ {
qFatal("ERROR: StarMgr::StarMgr: no memory"); qFatal("ERROR: StarMgr::StarMgr: no memory");
} }
maxGeodesicGridLevel = -1; maxGeodesicGridLevel = -1;
lastMaxSearchLevel = -1; lastMaxSearchLevel = -1;
starFont.setPixelSize(13.);
objectMgr = GETSTELMODULE(StelObjectMgr); objectMgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(objectMgr); Q_ASSERT(objectMgr);
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
double StarMgr::getCallOrder(StelModuleActionName actionName) const double StarMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Cons tellationMgr")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Cons tellationMgr")->getCallOrder(actionName)+10;
return 0; return 0;
} }
StarMgr::~StarMgr(void) StarMgr::~StarMgr(void)
{ {
delete starSettings;
starSettings=NULL;
ZoneArrayMap::iterator it(zoneArrays.end()); ZoneArrayMap::iterator it(zoneArrays.end());
while (it!=zoneArrays.begin()) while (it!=zoneArrays.begin())
{ {
--it; --it;
delete it->second; delete it->second;
it->second = NULL; it->second = NULL;
} }
zoneArrays.clear(); zoneArrays.clear();
if (hipIndex) if (hipIndex)
delete[] hipIndex; delete[] hipIndex;
skipping to change at line 179 skipping to change at line 182
} }
QString StarMgr::getSciName(int hip) QString StarMgr::getSciName(int hip)
{ {
std::map<int,QString>::const_iterator it(sciNamesMapI18n.find(hip)); std::map<int,QString>::const_iterator it(sciNamesMapI18n.find(hip));
if (it!=sciNamesMapI18n.end()) if (it!=sciNamesMapI18n.end())
return it->second; return it->second;
return QString(); return QString();
} }
void StarMgr::copyDefaultConfigFile()
{
try
{
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get
UserDir()+"/stars/default");
starConfigFileFullPath = StelFileMgr::getUserDir()+"/stars/d
efault/starsConfig.json";
qDebug() << "Creates file " << starConfigFileFullPath;
QFile::copy(StelFileMgr::findFile("stars/default/defaultStar
sConfig.json"), starConfigFileFullPath);
}
catch (std::runtime_error& e)
{
qWarning() << e.what();
qFatal("Could not create configuration file stars/default/st
arsConfig.json");
}
}
void StarMgr::init() void StarMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
loadStarSettings(); try
loadData(); {
double fontSize = 12; starConfigFileFullPath = StelFileMgr::findFile("stars/defaul
starFont = &StelApp::getInstance().getFontManager().getStandardFont( t/starsConfig.json", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::
StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize); File));
}
catch (std::runtime_error& e)
{
qWarning() << "Could not find the starsConfig.json file: wil
l copy the default one.";
copyDefaultConfigFile();
}
QFile fic(starConfigFileFullPath);
fic.open(QIODevice::ReadOnly);
starSettings = StelJsonParser::parse(&fic).toMap();
fic.close();
// Increment the 1 each time any star catalog file change
if (starSettings.value("version").toInt()!=StarCatalogFormatVersion)
{
qWarning() << "Found an old starsConfig.json file, upgrade..
";
fic.remove();
copyDefaultConfigFile();
QFile fic2(starConfigFileFullPath);
fic2.open(QIODevice::ReadOnly);
starSettings = StelJsonParser::parse(&fic2).toMap();
fic2.close();
}
loadData(starSettings);
starFont.setPixelSize(13);
setFlagStars(conf->value("astro/flag_stars", true).toBool()); setFlagStars(conf->value("astro/flag_stars", true).toBool());
setFlagLabels(conf->value("astro/flag_star_name",true).toBool()); setFlagLabels(conf->value("astro/flag_star_name",true).toBool());
setLabelsAmount(conf->value("stars/labels_amount",3).toDouble()); setLabelsAmount(conf->value("stars/labels_amount",3).toDouble());
objectMgr->registerStelObjectMgr(this); objectMgr->registerStelObjectMgr(this);
StelApp::getInstance().getTextureManager().setDefaultParams();
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png"); // Load pointer texture texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png"); // Load pointer texture
StelApp::getInstance().getCore()->getGeodesicGrid(maxGeodesicGridLev el)->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this); StelApp::getInstance().getCore()->getGeodesicGrid(maxGeodesicGridLev el)->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this);
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();it++) for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();it++)
{ {
it->second->scaleAxis(); it->second->scaleAxis();
} }
} }
void StarMgr::drawPointer(const StelProjectorP& prj, const StelNavigator * nav) void StarMgr::drawPointer(StelPainter& sPainter, const StelNavigator * nav)
{ {
const QList<StelObjectP> newSelected = objectMgr->getSelectedObject( "Star"); const QList<StelObjectP> newSelected = objectMgr->getSelectedObject( "Star");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(nav); Vec3d pos=obj->getJ2000EquatorialPos(nav);
Vec3d screenpos; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!prj->project(pos, screenpos)) if (!sPainter.getProjector()->project(pos, screenpos))
return; return;
StelPainter sPainter(prj); const Vec3d& c(obj->getInfoColor());
glColor3fv(obj->getInfoColor()); sPainter.setColor(c[0],c[1],c[2]);
float diameter = 26.f;
texPointer->bind(); texPointer->bind();
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transp glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
arency mode transparency mode
sPainter.drawSprite2dMode(screenpos[0], screenpos[1], diamet sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 13.f,
er, StelApp::getInstance().getTotalRunTime()*40.); StelApp::getInstance().getTotalRunTime()*40.);
} }
} }
void StarMgr::setStelStyle(const StelStyle& style) void StarMgr::setStelStyle(const StelStyle& style)
{ {
// 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 section = style.confSectionName;
QString defaultColor = conf->value(section+"/default_color").toStrin g(); QString defaultColor = conf->value(section+"/default_color").toStrin g();
setLabelColor(StelUtils::strToVec3f(conf->value(section+"/star_label _color", defaultColor).toString())); setLabelColor(StelUtils::strToVec3f(conf->value(section+"/star_label _color", defaultColor).toString()));
} }
void StarMgr::loadStarSettings() bool StarMgr::checkAndLoadCatalog(QVariantMap catDesc, StelLoadingBar* lb)
{ {
QString iniFile; const bool checked = catDesc.value("checked").toBool();
QString catalogFileName = catDesc.value("fileName").toString();
// See if it is an absolute path, else prepend default path
if (!(StelFileMgr::isAbsolute(catalogFileName)))
catalogFileName = "stars/default/"+catalogFileName;
QString catalogFilePath;
try try
{ {
iniFile = StelApp::getInstance().getFileMgr().findFile("star s/default/stars.ini"); catalogFilePath = StelFileMgr::findFile(catalogFileName);
} }
catch (std::runtime_error& e) catch (std::runtime_error e)
{ {
qWarning() << "ERROR - could not find stars/default/stars.in // The file is supposed to be checked, but we can't find it
i : " << e.what() << iniFile; if (checked)
return; {
qWarning() << QString("Warning: could not find star
catalog %1").arg(catalogFileName);
setCheckFlag(catDesc.value("id").toString(), false);
}
return false;
}
// Possibly fixes crash on Vista
if (!StelFileMgr::isReadable(catalogFilePath))
{
qWarning() << QString("Warning: User does not have permissio
ns to read catalog %1").arg(catalogFilePath);
return false;
} }
starSettings = new QSettings(iniFile, StelIniFormat); if (!checked)
if (starSettings->status() != QSettings::NoError)
{ {
qWarning() << "ERROR while parsing " << iniFile; // The file is not checked but we found it, maybe from a pre
return; vious download/version
qWarning() << "Found file " << catalogFilePath << ", checkin
g md5sum..";
QFile fic(catalogFilePath);
fic.open(QIODevice::ReadOnly);
// Compute the MD5 sum
QCryptographicHash md5Hash(QCryptographicHash::Md5);
static const qint64 maxStarBufMd5 = 1024*1024*8;
char* mmd5buf = (char*)malloc(maxStarBufMd5);
while (!fic.atEnd())
{
qint64 sz = fic.read(mmd5buf, maxStarBufMd5);
md5Hash.addData(mmd5buf, sz);
}
free(mmd5buf);
fic.close();
if (md5Hash.result().toHex()!=catDesc.value("checksum").toBy
teArray())
{
qWarning() << "Error checking file" << catalogFileNa
me << ": file is corrupted. MD5 sums don't match: found " << md5Hash.result
().toHex() << " expected " << catDesc.value("checksum").toByteArray();
fic.remove();
return false;
}
qWarning() << "MD5 sum correct!";
setCheckFlag(catDesc.value("id").toString(), true);
} }
starSettings->beginGroup("stars");
ZoneArray* const z = ZoneArray::create(catalogFilePath, true, lb);
if (z)
{
if (maxGeodesicGridLevel < z->level)
{
maxGeodesicGridLevel = z->level;
}
ZoneArray *&pos(zoneArrays[z->level]);
if (pos)
{
qWarning() << catalogFileName << ", " << z->level <<
": duplicate level";
delete z;
}
else
{
pos = z;
}
}
return true;
} }
/************************************************************************** void StarMgr::setCheckFlag(const QString& catId, bool b)
*
Load star catalogue data from files.
If a file is not found, it will be skipped.
***************************************************************************
/
void StarMgr::loadData()
{ {
StelLoadingBar& lb = *StelApp::getInstance().getStelLoadingBar(); // Update the starConfigFileFullPath file to take into account that
we now have a new catalog
int idx=0;
foreach (const QVariant& catV, catalogsDescription)
{
++idx;
QVariantMap m = catV.toMap();
if (m.value("id").toString()!=catId)
continue;
const bool checked = m.value("checked").toBool();
if (checked==b)
return;
m["checked"]=b;
catalogsDescription[idx-1]=m;
starSettings["catalogs"]=catalogsDescription;
QFile tmp(starConfigFileFullPath);
tmp.open(QIODevice::WriteOnly);
StelJsonParser::write(starSettings, &tmp);
tmp.close();
}
}
void StarMgr::loadData(QVariantMap starsConfig)
{
StelLoadingBar* lb = StelApp::getInstance().getStelLoadingBar();
Q_ASSERT(lb);
// Please do not init twice: // Please do not init twice:
Q_ASSERT(maxGeodesicGridLevel < 0); Q_ASSERT(maxGeodesicGridLevel < 0);
qDebug() << "Loading star data ..."; qDebug() << "Loading star data ...";
qulonglong memoryUsed = 0; catalogsDescription = starsConfig.value("catalogs").toList();
const qulonglong maxMemory = StelApp::getInstance().getSettings()->v foreach (const QVariant& catV, catalogsDescription)
alue("stars/max_memory", 128).toULongLong() * 1024*1024; {
QVariantMap m = catV.toMap();
QStringList cats = starSettings->childGroups(); const QString& catalogId = m.value("id").toString();
QListIterator<QString> it(cats); const QString& catalogFileName = m.value("fileName").toStrin
StelFileMgr& fileMgr = StelApp::getInstance().getFileMgr(); g();
while(it.hasNext()) lb->SetMessage(q_("Loading catalog %1 from file %2").arg(cat
{ alogId, catalogFileName));
QString cat = it.next(); checkAndLoadCatalog(m, lb);
QString cat_file_name = starSettings->value(cat+"/path").toS
tring();
QString cat_file_path = fileMgr.findFile("stars/default/"+ca
t_file_name);
lb.SetMessage(q_("Loading catalog %1 from file %2").arg(cat,
cat_file_name));
memoryUsed += fileMgr.size(cat_file_path);
ZoneArray *const z = ZoneArray::create(cat_file_name, memory
Used > maxMemory, lb);
if (z)
{
if (maxGeodesicGridLevel < z->level)
{
maxGeodesicGridLevel = z->level;
}
ZoneArray *&pos(zoneArrays[z->level]);
if (pos)
{
qDebug() << cat_file_name << ", " << z->leve
l << ": duplicate level";
delete z;
}
else
{
pos = z;
}
}
} }
for (int i=0; i<=NR_OF_HIP; i++) for (int i=0; i<=NR_OF_HIP; i++)
{ {
hipIndex[i].a = 0; hipIndex[i].a = 0;
hipIndex[i].z = 0; hipIndex[i].z = 0;
hipIndex[i].s = 0; hipIndex[i].s = 0;
} }
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it != zone
it != zoneArrays.end();it++) Arrays.end();it++)
{ {
it->second->updateHipIndex(hipIndex); it->second->updateHipIndex(hipIndex);
} }
const QString cat_hip_sp_file_name = starSettings->value("cat_hip_sp _file_name","").toString(); const QString cat_hip_sp_file_name = starsConfig.value("hipSpectralF ile").toString();
if (cat_hip_sp_file_name.isEmpty()) if (cat_hip_sp_file_name.isEmpty())
{ {
qWarning() << "ERROR: stars:cat_hip_sp_file_name not found"; qWarning() << "ERROR: stars:cat_hip_sp_file_name not found";
} }
else else
{ {
try try
{ {
spectral_array = initStringListFromFile(fileMgr.find File("stars/default/" + cat_hip_sp_file_name)); spectral_array = initStringListFromFile(StelFileMgr: :findFile("stars/default/" + cat_hip_sp_file_name));
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "ERROR while loading data from " qWarning() << "ERROR while loading data from "
<< ("stars/default/" + cat_hip_sp_file_na << ("stars/default/" + cat_hip_sp
me) _file_name)
<< ": " << e.what(); << ": " << e.what();
} }
} }
const QString cat_hip_cids_file_name = starSettings->value("cat_hip_ cids_file_name","").toString(); const QString cat_hip_cids_file_name = starsConfig.value("hipCompone ntsIdsFile").toString();
if (cat_hip_cids_file_name.isEmpty()) if (cat_hip_cids_file_name.isEmpty())
{ {
qWarning() << "ERROR: stars:cat_hip_cids_file_name not found "; qWarning() << "ERROR: stars:cat_hip_cids_file_name not found ";
} }
else else
{ {
try try
{ {
component_array = initStringListFromFile(fileMgr.fin dFile("stars/default/" + cat_hip_cids_file_name)); component_array = initStringListFromFile(StelFileMgr ::findFile("stars/default/" + cat_hip_cids_file_name));
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "ERROR while loading data from " qWarning() << "ERROR while loading data from "
<< ("stars/default/" + cat_hip_cids_file_ << ("stars/default/" + cat_hip_ci
name) ds_file_name) << ": " << e.what();
<< ": " << e.what();
} }
} }
lastMaxSearchLevel = maxGeodesicGridLevel; lastMaxSearchLevel = maxGeodesicGridLevel;
qDebug() << "Finished loading star catalogue data, max_geodesic_leve l: " << maxGeodesicGridLevel; qDebug() << "Finished loading star catalogue data, max_geodesic_leve l: " << maxGeodesicGridLevel;
} }
// Load common names from file // Load common names from file
int StarMgr::loadCommonNames(const QString& commonNameFile) int StarMgr::loadCommonNames(const QString& commonNameFile)
{ {
skipping to change at line 539 skipping to change at line 630
} }
return rval; return rval;
} }
// Draw all the stars // Draw all the stars
void StarMgr::draw(StelCore* core) void StarMgr::draw(StelCore* core)
{ {
StelNavigator* nav = core->getNavigator(); StelNavigator* nav = core->getNavigator();
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelSkyDrawer* skyDrawer = core->getSkyDrawer(); StelSkyDrawer* skyDrawer = core->getSkyDrawer();
// If stars are turned off don't waste time below // If stars are turned off don't waste time below
// projecting all stars just to draw disembodied labels // projecting all stars just to draw disembodied labels
if (!starsFader.getInterstate()) if (!starsFader.getInterstate())
return; return;
int maxSearchLevel = getMaxSearchLevel(); int maxSearchLevel = getMaxSearchLevel();
const GeodesicSearchResult* geodesic_search_result = core->getGeodes icGrid(maxSearchLevel)->search(prj->getViewportConvexPolygon(),maxSearchLev el); const GeodesicSearchResult* geodesic_search_result = core->getGeodes icGrid(maxSearchLevel)->search(prj->getViewportConvexPolygon()->getBounding SphericalCaps(),maxSearchLevel);
// Set temporary static variable for optimization // Set temporary static variable for optimization
const float names_brightness = labelsFader.getInterstate() * starsFa der.getInterstate(); const float names_brightness = labelsFader.getInterstate() * starsFa der.getInterstate();
// Prepare openGL for drawing many stars // Prepare openGL for drawing many stars
StelPainter* sPainter = new StelPainter(prj); StelPainter sPainter(prj);
skyDrawer->preDrawPointSource(sPainter); sPainter.setFont(starFont);
Q_ASSERT(sPainter); skyDrawer->preDrawPointSource(&sPainter);
// draw all the stars of all the selected zones // draw all the stars of all the selected zones
float rcmag_table[2*256]; float rcmag_table[2*256];
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();++it) for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();++it)
{ {
const float mag_min = 0.001f*it->second->mag_min; const float mag_min = 0.001f*it->second->mag_min;
const float k = (0.001f*it->second->mag_range)/it->second->m ag_steps; const float k = (0.001f*it->second->mag_range)/it->second->m ag_steps;
for (int i=it->second->mag_steps-1;i>=0;--i) for (int i=it->second->mag_steps-1;i>=0;--i)
{ {
skipping to change at line 592 skipping to change at line 682
if (labelsFader.getInterstate()>0.f) if (labelsFader.getInterstate()>0.f)
{ {
// Adapt magnitude limit of the stars labels accordi ng to FOV and labelsAmount // Adapt magnitude limit of the stars labels accordi ng to FOV and labelsAmount
float maxMag = (skyDrawer->getLimitMagnitude()-6.5)* 0.7+(labelsAmount*1.2f)-2.f; float maxMag = (skyDrawer->getLimitMagnitude()-6.5)* 0.7+(labelsAmount*1.2f)-2.f;
int x = (int)((maxMag-mag_min)/k); int x = (int)((maxMag-mag_min)/k);
if (x > 0) if (x > 0)
maxMagStarName = x; maxMagStarName = x;
} }
int zone; int zone;
for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;) for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;)
it->second->draw(zone, true, rcmag_table, core, maxM agStarName, names_brightness, starFont); it->second->draw(&sPainter, zone, true, rcmag_table, core, maxMagStarName, names_brightness);
for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;) for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;)
it->second->draw(zone, false, rcmag_table, core, max MagStarName,names_brightness, starFont); it->second->draw(&sPainter, zone, false, rcmag_table , core, maxMagStarName,names_brightness);
} }
exit_loop: exit_loop:
// Finish drawing many stars // Finish drawing many stars
skyDrawer->postDrawPointSource(); skyDrawer->postDrawPointSource(&sPainter);
delete sPainter;
sPainter = NULL;
if (objectMgr->getFlagSelectedObjectPointer()) if (objectMgr->getFlagSelectedObjectPointer())
drawPointer(prj, nav); drawPointer(sPainter, nav);
} }
// Return a stl vector containing the stars located // Return a stl vector containing the stars located
// inside the limFov circle around position v // inside the limFov circle around position v
QList<StelObjectP > StarMgr::searchAround(const Vec3d& vv, double limFov, c onst StelCore* core) const QList<StelObjectP > StarMgr::searchAround(const Vec3d& vv, double limFov, c onst StelCore* core) const
{ {
QList<StelObjectP > result; QList<StelObjectP > result;
if (!getFlagStars()) if (!getFlagStars())
return result; return result;
skipping to change at line 656 skipping to change at line 743
Vec3d e0 = v + h0; Vec3d e0 = v + h0;
Vec3d e1 = v + h1; Vec3d e1 = v + h1;
Vec3d e2 = v - h0; Vec3d e2 = v - h0;
Vec3d e3 = v - h1; Vec3d e3 = v - h1;
f = 1.0/e0.length(); f = 1.0/e0.length();
e0 *= f; e0 *= f;
e1 *= f; e1 *= f;
e2 *= f; e2 *= f;
e3 *= f; e3 *= f;
// Search the triangles // Search the triangles
const GeodesicSearchResult* geodesic_search_result = core->getGeodes SphericalConvexPolygon c(e3, e2, e2, e0);
icGrid(lastMaxSearchLevel)->search(e3,e2,e1,e0,lastMaxSearchLevel); const GeodesicSearchResult* geodesic_search_result = core->getGeodes
icGrid(lastMaxSearchLevel)->search(c.getBoundingSphericalCaps(),lastMaxSear
chLevel);
// Iterate over the stars inside the triangles // Iterate over the stars inside the triangles
f = cos(limFov * M_PI/180.); f = cos(limFov * M_PI/180.);
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArr ays.end();it++) for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArr ays.end();it++)
{ {
//qDebug() << "search inside(" << it->first << "):"; //qDebug() << "search inside(" << it->first << "):";
int zone; int zone;
for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;) for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;)
{ {
it->second->searchAround(core->getNavigator(), zone, v,f,result); it->second->searchAround(core->getNavigator(), zone, v,f,result);
skipping to change at line 693 skipping to change at line 781
StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyT ranslator(); StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyT ranslator();
commonNamesMapI18n.clear(); commonNamesMapI18n.clear();
commonNamesIndexI18n.clear(); commonNamesIndexI18n.clear();
for (std::map<int,QString>::iterator it(commonNamesMap.begin());it!= commonNamesMap.end();it++) for (std::map<int,QString>::iterator it(commonNamesMap.begin());it!= commonNamesMap.end();it++)
{ {
const int i = it->first; const int i = it->first;
const QString t(trans.qtranslate(it->second)); const QString t(trans.qtranslate(it->second));
commonNamesMapI18n[i] = t; commonNamesMapI18n[i] = t;
commonNamesIndexI18n[t.toUpper()] = i; commonNamesIndexI18n[t.toUpper()] = i;
} }
starFont = &StelApp::getInstance().getFontManager().getStandardFont( trans.getTrueLocaleName(), fontSize);
} }
// Search the star by HP number // Search the star by HP number
StelObjectP StarMgr::searchHP(int hp) const StelObjectP StarMgr::searchHP(int hp) const
{ {
if (0 < hp && hp <= NR_OF_HIP) if (0 < hp && hp <= NR_OF_HIP)
{ {
const Star1 *const s = hipIndex[hp].s; const Star1 *const s = hipIndex[hp].s;
if (s) if (s)
{ {
skipping to change at line 831 skipping to change at line 918
} }
} }
result.sort(); result.sort();
return result; return result;
} }
//! Define font file name and size to use for star names display //! Define font file name and size to use for star names display
void StarMgr::setFontSize(double newFontSize) void StarMgr::setFontSize(double newFontSize)
{ {
fontSize = newFontSize; starFont.setPixelSize(newFontSize);
starFont = &StelApp::getInstance().getFontManager().getStandardFont(
StelApp::getInstance().getLocaleMgr().getSkyLanguage(),fontS
ize);
} }
void StarMgr::updateSkyCulture(const QString& skyCultureDir) void StarMgr::updateSkyCulture(const QString& skyCultureDir)
{ {
// Load culture star names in english // Load culture star names in english
try try
{ {
loadCommonNames(StelApp::getInstance().getFileMgr().findFile ("skycultures/" + skyCultureDir + "/star_names.fab")); loadCommonNames(StelFileMgr::findFile("skycultures/" + skyCu ltureDir + "/star_names.fab"));
} }
catch(std::runtime_error& e) catch(std::runtime_error& e)
{ {
qWarning() << "WARNING: could not load star_names.fab for sk qDebug() << "Could not load star_names.fab for sky culture "
y culture " << skyCultureDir << ": " << e.what();
<< skyCultureDir << ": " << e.what();
} }
try try
{ {
loadSciNames(StelApp::getInstance().getFileMgr().findFile("s tars/default/name.fab")); loadSciNames(StelFileMgr::findFile("stars/default/name.fab") );
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "WARNING: could not load scientific star names file: " << e.what(); qWarning() << "WARNING: could not load scientific star names file: " << e.what();
} }
// Turn on sci names/catalog names for western culture only // Turn on sci names/catalog names for western culture only
setFlagSciNames(skyCultureDir.startsWith("western")); setFlagSciNames(skyCultureDir.startsWith("western"));
updateI18n(); updateI18n();
} }
 End of changes. 49 change blocks. 
123 lines changed or deleted 219 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/