StarMgr.cpp   StarMgr.cpp 
skipping to change at line 23 skipping to change at line 23
* 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.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include <QCryptographicHash>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QRegExp>
#include <QSettings>
#include <QString>
#include <QTextStream>
#include <QDir>
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "StelObject.hpp" #include "StelObject.hpp"
#include "renderer/StelRenderer.hpp" #include "StelTexture.hpp"
#include "renderer/StelTextureNew.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 "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelTextureMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelSkyCultureMgr.hpp" #include "StelSkyCultureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelPainter.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "ZoneArray.hpp" #include "ZoneArray.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "RefractionExtinction.hpp" #include "RefractionExtinction.hpp"
#include <errno.h> #include <QTextStream>
#ifndef Q_OS_WIN #include <QFile>
#include <unistd.h> #include <QSettings>
#else #include <QString>
#include "kdewin32/unistd.h" #include <QRegExp>
#endif #include <QDebug>
#include <QFileInfo>
#include <QDir>
#include <QCryptographicHash>
using namespace BigStarCatalogExtension; #include <errno.h>;
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 // 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 can also be incremented when the defaultStarsConfig.json file change.
// It should always matchs the version field of the defaultStarsConfig.json file // It should always matchs the version field of the defaultStarsConfig.json file
static const int StarCatalogFormatVersion = 4; static const int StarCatalogFormatVersion = 6;
// Initialise statics // Initialise statics
bool StarMgr::flagSciNames = true; bool StarMgr::flagSciNames = true;
QHash<int,QString> StarMgr::commonNamesMap; QHash<int,QString> StarMgr::commonNamesMap;
QHash<int,QString> StarMgr::commonNamesMapI18n; QHash<int,QString> StarMgr::commonNamesMapI18n;
QMap<QString,int> StarMgr::commonNamesIndexI18n; QMap<QString,int> StarMgr::commonNamesIndexI18n;
QMap<QString,int> StarMgr::commonNamesIndex; QMap<QString,int> StarMgr::commonNamesIndex;
QHash<int,QString> StarMgr::sciNamesMapI18n; QHash<int,QString> StarMgr::sciNamesMapI18n;
QMap<QString,int> StarMgr::sciNamesIndexI18n; QMap<QString,int> StarMgr::sciNamesIndexI18n;
QHash<int,QString> StarMgr::sciAdditionalNamesMapI18n; QHash<int,QString> StarMgr::sciAdditionalNamesMapI18n;
skipping to change at line 126 skipping to change at line 120
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, const Vec3f &c0, const Vec3f &c1, const Vec3f &c2) void StarMgr::initTriangle(int lev,int index, const Vec3f &c0, const Vec3f &c1, const Vec3f &c2)
{ {
ZoneArrayMap::const_iterator it(zoneArrays.find(lev)); gridLevels[lev]->initTriangle(index,c0,c1,c2);
if (it!=zoneArrays.constEnd())
it.value()->initTriangle(index,c0,c1,c2);
} }
StarMgr::StarMgr(void) StarMgr::StarMgr(void)
: hipIndex(new HipIndexStruct[NR_OF_HIP+1]) : flagStarName(false)
, texPointer(NULL) , labelsAmount(0.)
, gravityLabel(false)
, 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(StelApp::getInstance().getSettings()->value("g ui/base_font_size", 13).toInt()); starFont.setPixelSize(StelApp::getInstance().getSettings()->value("g ui/base_font_size", 13).toInt());
objectMgr = GETSTELMODULE(StelObjectMgr); objectMgr = GETSTELMODULE(StelObjectMgr);
skipping to change at line 159 skipping to change at line 153
*************************************************************************/ *************************************************************************/
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)
{ {
ZoneArrayMap::iterator it(zoneArrays.end()); foreach(ZoneArray* z, gridLevels)
while (it!=zoneArrays.begin()) delete z;
{ gridLevels.clear();
--it;
delete it.value();
it.value() = NULL;
}
zoneArrays.clear();
if (hipIndex) if (hipIndex)
delete[] hipIndex; delete[] hipIndex;
if(NULL != texPointer)
{
delete texPointer;
}
} }
QString StarMgr::getCommonName(int hip) QString StarMgr::getCommonName(int hip)
{ {
QHash<int,QString>::const_iterator it(commonNamesMapI18n.find(hip)); QHash<int,QString>::const_iterator it(commonNamesMapI18n.find(hip));
if (it!=commonNamesMapI18n.end()) if (it!=commonNamesMapI18n.end())
return it.value(); return it.value();
return QString(); return QString();
} }
skipping to change at line 287 skipping to change at line 272
return -99; return -99;
} }
void StarMgr::copyDefaultConfigFile() void StarMgr::copyDefaultConfigFile()
{ {
try try
{ {
StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/stars/default"); StelFileMgr::makeSureDirExistsAndIsWritable(StelFileMgr::get UserDir()+"/stars/default");
starConfigFileFullPath = StelFileMgr::getUserDir()+"/stars/d efault/starsConfig.json"; starConfigFileFullPath = StelFileMgr::getUserDir()+"/stars/d efault/starsConfig.json";
qDebug() << "Creates file " << QDir::toNativeSeparators(star ConfigFileFullPath); qDebug() << "Creates file " << QDir::toNativeSeparators(star ConfigFileFullPath);
QFile::copy(StelFileMgr::findFile("stars/default/defaultStar QFile::copy(StelFileMgr::getInstallationDir()+"/stars/defaul
sConfig.json"), starConfigFileFullPath); t/defaultStarsConfig.json", starConfigFileFullPath);
QFile::setPermissions(starConfigFileFullPath, QFile::permiss
ions(starConfigFileFullPath) | QFileDevice::WriteOwner);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << e.what(); qWarning() << e.what();
qFatal("Could not create configuration file stars/default/st arsConfig.json"); 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);
try starConfigFileFullPath = StelFileMgr::findFile("stars/default/starsC
{ onfig.json", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::File));
starConfigFileFullPath = StelFileMgr::findFile("stars/defaul if (starConfigFileFullPath.isEmpty())
t/starsConfig.json", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::
File));
}
catch (std::runtime_error& e)
{ {
qWarning() << "Could not find the starsConfig.json file: wil l copy the default one."; qWarning() << "Could not find the starsConfig.json file: wil l copy the default one.";
copyDefaultConfigFile(); copyDefaultConfigFile();
} }
QFile fic(starConfigFileFullPath); QFile fic(starConfigFileFullPath);
fic.open(QIODevice::ReadOnly); if(fic.open(QIODevice::ReadOnly))
starSettings = StelJsonParser::parse(&fic).toMap(); {
fic.close(); starSettings = StelJsonParser::parse(&fic).toMap();
fic.close();
}
// Increment the 1 each time any star catalog file change // Increment the 1 each time any star catalog file change
if (starSettings.value("version").toInt()!=StarCatalogFormatVersion) if (starSettings.value("version").toInt()!=StarCatalogFormatVersion)
{ {
qWarning() << "Found an old starsConfig.json file, upgrade.. "; qWarning() << "Found an old starsConfig.json file, upgrade.. ";
fic.remove(); fic.remove();
copyDefaultConfigFile(); copyDefaultConfigFile();
QFile fic2(starConfigFileFullPath); QFile fic2(starConfigFileFullPath);
fic2.open(QIODevice::ReadOnly); if(fic2.open(QIODevice::ReadOnly))
starSettings = StelJsonParser::parse(&fic2).toMap(); {
fic2.close(); starSettings = StelJsonParser::parse(&fic2).toMap();
fic2.close();
}
} }
loadData(starSettings); loadData(starSettings);
starFont.setPixelSize(StelApp::getInstance().getSettings()->value("g ui/base_font_size", 13).toInt()); starFont.setPixelSize(StelApp::getInstance().getSettings()->value("g ui/base_font_size", 13).toInt());
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.f).toFloat()); setLabelsAmount(conf->value("stars/labels_amount",3.f).toFloat());
objectMgr->registerStelObjectMgr(this); objectMgr->registerStelObjectMgr(this);
texPointer = StelApp::getInstance().getTextureManager().createTextur e(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png"); // Load p ointer 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 foreach(ZoneArray* z, gridLevels)
rays.end();it++) z->scaleAxis();
{
it.value()->scaleAxis();
}
StelApp *app = &StelApp::getInstance(); StelApp *app = &StelApp::getInstance();
connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n())); connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n()));
connect(app, SIGNAL(skyCultureChanged(const QString&)), this, SLOT(u pdateSkyCulture(const QString&))); connect(app, SIGNAL(skyCultureChanged(const QString&)), this, SLOT(u pdateSkyCulture(const QString&)));
connect(app, SIGNAL(colorSchemeChanged(const QString&)), this, SLOT( setStelStyle(const QString&))); connect(app, SIGNAL(colorSchemeChanged(const QString&)), this, SLOT( setStelStyle(const QString&)));
QString displayGroup = N_("Display Options");
addAction("actionShow_Stars", displayGroup, N_("Stars"), "flagStarsD
isplayed", "S");
addAction("actionShow_Stars_Labels", displayGroup, N_("Stars labels"
), "flagLabelsDisplayed", "Alt+S");
} }
void StarMgr::drawPointer(StelRenderer* renderer, StelProjectorP projector, const StelCore* core) void StarMgr::drawPointer(StelPainter& sPainter, const StelCore* core)
{ {
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(core); Vec3d pos=obj->getJ2000EquatorialPos(core);
Vec3d win; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!projector->project(pos, win)) if (!sPainter.getProjector()->project(pos, screenpos))
{
return; return;
}
if(NULL == texPointer)
{
texPointer = renderer->createTexture("textures/point
eur2.png"); // Load pointer texture
}
Vec3f c(obj->getInfoColor()); Vec3f c(obj->getInfoColor());
if (StelApp::getInstance().getVisionModeNight()) sPainter.setColor(c[0], c[1], c[2]);
c = StelUtils::getNightColor(c);
renderer->setGlobalColor(c[0], c[1], c[2]);
texPointer->bind(); texPointer->bind();
renderer->setBlendMode(BlendMode_Alpha); sPainter.enableTexture2d(true);
const float angle = StelApp::getInstance().getTotalRunTime() glEnable(GL_BLEND);
* 40.0f; glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal
renderer->drawTexturedRect(win[0] - 13.0f, win[1] - 13.0f, 2 transparency mode
6.0f, 26.0f, angle); sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 13.f,
StelApp::getInstance().getTotalRunTime()*40.);
} }
} }
void StarMgr::setStelStyle(const QString& section) void StarMgr::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();
setLabelColor(StelUtils::strToVec3f(conf->value(section+"/star_label _color", defaultColor).toString())); setLabelColor(StelUtils::strToVec3f(conf->value(section+"/star_label _color", defaultColor).toString()));
} }
bool StarMgr::checkAndLoadCatalog(QVariantMap catDesc) bool StarMgr::checkAndLoadCatalog(const QVariantMap& catDesc)
{ {
const bool checked = catDesc.value("checked").toBool(); const bool checked = catDesc.value("checked").toBool();
QString catalogFileName = catDesc.value("fileName").toString(); QString catalogFileName = catDesc.value("fileName").toString();
// See if it is an absolute path, else prepend default path // See if it is an absolute path, else prepend default path
if (!(StelFileMgr::isAbsolute(catalogFileName))) if (!(StelFileMgr::isAbsolute(catalogFileName)))
catalogFileName = "stars/default/"+catalogFileName; catalogFileName = "stars/default/"+catalogFileName;
QString catalogFilePath; QString catalogFilePath = StelFileMgr::findFile(catalogFileName);
try if (catalogFilePath.isEmpty())
{
catalogFilePath = StelFileMgr::findFile(catalogFileName);
}
catch (std::runtime_error e)
{ {
// The file is supposed to be checked, but we can't find it // The file is supposed to be checked, but we can't find it
if (checked) if (checked)
{ {
qWarning() << QString("Warning: could not find star catalog %1").arg(QDir::toNativeSeparators(catalogFileName)); qWarning() << QString("Warning: could not find star catalog %1").arg(QDir::toNativeSeparators(catalogFileName));
setCheckFlag(catDesc.value("id").toString(), false); setCheckFlag(catDesc.value("id").toString(), false);
} }
return false; return false;
} }
// Possibly fixes crash on Vista // Possibly fixes crash on Vista
skipping to change at line 427 skipping to change at line 403
qWarning() << QString("Warning: User does not have permissio ns to read catalog %1").arg(QDir::toNativeSeparators(catalogFilePath)); qWarning() << QString("Warning: User does not have permissio ns to read catalog %1").arg(QDir::toNativeSeparators(catalogFilePath));
return false; return false;
} }
if (!checked) if (!checked)
{ {
// The file is not checked but we found it, maybe from a pre vious download/version // The file is not checked but we found it, maybe from a pre vious download/version
qWarning() << "Found file " << QDir::toNativeSeparators(cata logFilePath) << ", checking md5sum.."; qWarning() << "Found file " << QDir::toNativeSeparators(cata logFilePath) << ", checking md5sum..";
QFile fic(catalogFilePath); QFile fic(catalogFilePath);
fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered); if(fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
// Compute the MD5 sum {
QCryptographicHash md5Hash(QCryptographicHash::Md5); // Compute the MD5 sum
const qint64 cat_sz = fic.size(); QCryptographicHash md5Hash(QCryptographicHash::Md5);
qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775807LL); const qint64 cat_sz = fic.size();
uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd5) : NUL qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775
L; 807LL);
if (!cat) uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd
{ 5) : NULL;
// The OS was not able to map the file, revert to sl if (!cat)
ower not mmap based method
static const qint64 maxStarBufMd5 = 1024*1024*8;
char* mmd5buf = (char*)malloc(maxStarBufMd5);
while (!fic.atEnd())
{ {
qint64 sz = fic.read(mmd5buf, maxStarBufMd5) // The OS was not able to map the file, reve
; rt to slower not mmap based method
md5Hash.addData(mmd5buf, sz); static const qint64 maxStarBufMd5 = 1024*102
4*8;
char* mmd5buf = (char*)malloc(maxStarBufMd5)
;
while (!fic.atEnd())
{
qint64 sz = fic.read(mmd5buf, maxSta
rBufMd5);
md5Hash.addData(mmd5buf, sz);
}
free(mmd5buf);
} }
free(mmd5buf); else
} {
else md5Hash.addData((const char*)cat, cat_sz);
{ fic.unmap(cat);
md5Hash.addData((const char*)cat, cat_sz); }
fic.unmap(cat); fic.close();
} if (md5Hash.result().toHex()!=catDesc.value("checksu
fic.close(); m").toByteArray())
if (md5Hash.result().toHex()!=catDesc.value("checksum").toBy {
teArray()) qWarning() << "Error: File " << QDir::toNati
{ veSeparators(catalogFileName) << " is corrupt, MD5 mismatch! Found " << md5
qWarning() << "Error: File " << QDir::toNativeSepara Hash.result().toHex() << " expected " << catDesc.value("checksum").toByteAr
tors(catalogFileName) << " is corrupt, MD5 mismatch! Found " << md5Hash.res ray();
ult().toHex() << " expected " << catDesc.value("checksum").toByteArray(); fic.remove();
fic.remove(); return false;
return false; }
qWarning() << "MD5 sum correct!";
setCheckFlag(catDesc.value("id").toString(), true);
} }
qWarning() << "MD5 sum correct!";
setCheckFlag(catDesc.value("id").toString(), true);
} }
ZoneArray* const z = ZoneArray::create(catalogFilePath, true); ZoneArray* z = ZoneArray::create(catalogFilePath, true);
if (z) if (z)
{ {
if (maxGeodesicGridLevel < z->level) if (z->level<gridLevels.size())
{
maxGeodesicGridLevel = z->level;
}
ZoneArray *pos(zoneArrays[z->level]);
if (pos)
{ {
qWarning() << QDir::toNativeSeparators(catalogFileNa me) << ", " << z->level << ": duplicate level"; qWarning() << QDir::toNativeSeparators(catalogFileNa me) << ", " << z->level << ": duplicate level";
delete z; delete z;
return true;
} }
else Q_ASSERT(z->level==maxGeodesicGridLevel+1);
{ Q_ASSERT(z->level==gridLevels.size());
zoneArrays[z->level] = z; ++maxGeodesicGridLevel;
pos = z; gridLevels.append(z);
}
} }
return true; return true;
} }
void StarMgr::setCheckFlag(const QString& catId, bool b) void StarMgr::setCheckFlag(const QString& catId, bool b)
{ {
// Update the starConfigFileFullPath file to take into account that we now have a new catalog // Update the starConfigFileFullPath file to take into account that we now have a new catalog
int idx=0; int idx=0;
foreach (const QVariant& catV, catalogsDescription) foreach (const QVariant& catV, catalogsDescription)
{ {
skipping to change at line 500 skipping to change at line 473
QVariantMap m = catV.toMap(); QVariantMap m = catV.toMap();
if (m.value("id").toString()!=catId) if (m.value("id").toString()!=catId)
continue; continue;
const bool checked = m.value("checked").toBool(); const bool checked = m.value("checked").toBool();
if (checked==b) if (checked==b)
return; return;
m["checked"]=b; m["checked"]=b;
catalogsDescription[idx-1]=m; catalogsDescription[idx-1]=m;
starSettings["catalogs"]=catalogsDescription; starSettings["catalogs"]=catalogsDescription;
QFile tmp(starConfigFileFullPath); QFile tmp(starConfigFileFullPath);
tmp.open(QIODevice::WriteOnly); if(tmp.open(QIODevice::WriteOnly))
StelJsonParser::write(starSettings, &tmp); {
tmp.close(); StelJsonParser::write(starSettings, &tmp);
tmp.close();
}
} }
} }
void StarMgr::loadData(QVariantMap starsConfig) void StarMgr::loadData(QVariantMap starsConfig)
{ {
// 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 ...";
skipping to change at line 526 skipping to change at line 501
QVariantMap m = catV.toMap(); QVariantMap m = catV.toMap();
checkAndLoadCatalog(m); checkAndLoadCatalog(m);
} }
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.constBegin()); it != foreach(ZoneArray* z, gridLevels)
zoneArrays.constEnd();++it) z->updateHipIndex(hipIndex);
{
it.value()->updateHipIndex(hipIndex);
}
const QString cat_hip_sp_file_name = starsConfig.value("hipSpectralF ile").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 QString tmpFic = StelFileMgr::findFile("stars/default/" + ca
{ t_hip_sp_file_name);
spectral_array = initStringListFromFile(StelFileMgr: if (tmpFic.isEmpty())
:findFile("stars/default/" + cat_hip_sp_file_name)); qWarning() << "ERROR while loading data from " << QD
} ir::toNativeSeparators(("stars/default/" + cat_hip_sp_file_name));
catch (std::runtime_error& e) else
{ spectral_array = initStringListFromFile(tmpFic);
qWarning() << "ERROR while loading data from "
<< QDir::toNativeSeparators(("sta
rs/default/" + cat_hip_sp_file_name))
<< ": " << e.what();
}
} }
const QString cat_hip_cids_file_name = starsConfig.value("hipCompone ntsIdsFile").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 QString tmpFic = StelFileMgr::findFile("stars/default/" + ca
{ t_hip_cids_file_name);
component_array = initStringListFromFile(StelFileMgr if (tmpFic.isEmpty())
::findFile("stars/default/" + cat_hip_cids_file_name)); qWarning() << "ERROR while loading data from " << QD
} ir::toNativeSeparators(("stars/default/" + cat_hip_cids_file_name));
catch (std::runtime_error& e) else
{ component_array = initStringListFromFile(tmpFic);
qWarning() << "ERROR while loading data from "
<< QDir::toNativeSeparators(("sta
rs/default/" + cat_hip_cids_file_name)) << ": " << 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)
{ {
commonNamesMap.clear(); commonNamesMap.clear();
skipping to change at line 799 skipping to change at line 763
varStarsIndexI18n[variableStar.designation.toUpper()] = hip; varStarsIndexI18n[variableStar.designation.toUpper()] = hip;
++readOk; ++readOk;
} }
qDebug() << "Loaded" << readOk << "/" << totalRecords << "variable s tars"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "variable s tars";
} }
int StarMgr::getMaxSearchLevel() const int StarMgr::getMaxSearchLevel() const
{ {
int rval = -1; int rval = -1;
for (ZoneArrayMap::const_iterator it(zoneArrays.constBegin());it!=zo neArrays.constEnd();++it) foreach(const ZoneArray* z, gridLevels)
{ {
const float mag_min = 0.001f*it.value()->mag_min; const float mag_min = 0.001f*z->mag_min;
float rcmag[2]; RCMag rcmag;
if (StelApp::getInstance().getCore()->getSkyDrawer()->comput if (StelApp::getInstance().getCore()->getSkyDrawer()->comput
eRCMag(mag_min,rcmag)==false) eRCMag(mag_min, &rcmag)==false)
break; break;
rval = it.key(); rval = z->level;
} }
return rval; return rval;
} }
// Draw all the stars // Draw all the stars
void StarMgr::draw(StelCore* core, StelRenderer* renderer) void StarMgr::draw(StelCore* core)
{ {
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 QVector<SphericalCap> viewportCaps = prj->getViewportConvexPolygon()
icGrid(maxSearchLevel)->search(prj->getViewportConvexPolygon()->getBounding ->getBoundingSphericalCaps();
SphericalCaps(),maxSearchLevel); viewportCaps.append(core->getVisibleSkyArea());
const GeodesicSearchResult* geodesic_search_result = core->getGeodes
icGrid(maxSearchLevel)->search(viewportCaps,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 for drawing many stars // Prepare openGL for drawing many stars
renderer->setFont(starFont); StelPainter sPainter(prj);
skyDrawer->preDrawPointSource(); sPainter.setFont(starFont);
skyDrawer->preDrawPointSource(&sPainter);
// draw all the stars of all the selected zones
// GZ: This table must be enlarged from 2x256 to many more entries. // Prepare a table for storing precomputed RCMag for all ZoneArrays
CORRELATE IN Zonearray.cpp! RCMag rcmag_table[RCMAG_TABLE_SIZE];
//float rcmag_table[2*256];
//float rcmag_table[2*16384]; // Draw all the stars of all the selected zones
float rcmag_table[2 * RCMAG_TABLE_SIZE]; foreach(const ZoneArray* z, gridLevels)
{
for (ZoneArrayMap::const_iterator it(zoneArrays.constBegin()); it!=z int limitMagIndex=RCMAG_TABLE_SIZE;
oneArrays.constEnd();++it) const float mag_min = 0.001f*z->mag_min;
{ const float k = (0.001f*z->mag_range)/z->mag_steps; // MagSt
const float mag_min = 0.001f*it.value()->mag_min; epIncrement
const float k = (0.001f*it.value()->mag_range)/it.value()->m for (int i=0;i<RCMAG_TABLE_SIZE;++i)
ag_steps; // MagStepIncrement
// GZ: add a huge number of entries to rcMag
//for (int i=it.value()->mag_steps-1;i>=0;--i)
for (int i=RCMAG_TABLE_SIZE-1;i>=0;--i)
{ {
const float mag = mag_min+k*i; const float mag = mag_min+k*i;
if (skyDrawer->computeRCMag(mag,rcmag_table + 2*i)== if (skyDrawer->computeRCMag(mag, &rcmag_table[i])==f
false) alse)
{
if (i==0) goto exit_loop;
}
if (skyDrawer->getDrawStarsAsPoints())
{
rcmag_table[2*i+1] *= starsFader.getIntersta
te();
}
else
{ {
rcmag_table[2*i] *= starsFader.getInterstate if (i==0)
(); goto exit_loop;
// The last magnitude at which the star is v
isible
limitMagIndex = i-1;
// We reached the point where stars are not
visible anymore
// Fill the rest of the table with zero and
leave.
for (;i<RCMAG_TABLE_SIZE;++i)
{
rcmag_table[i].luminance=0;
rcmag_table[i].radius=0;
}
break;
} }
rcmag_table[i].radius *= starsFader.getInterstate();
} }
lastMaxSearchLevel = it.key(); lastMaxSearchLevel = z->level;
unsigned int maxMagStarName = 0; unsigned int maxMagStarName = 0;
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.key());(zone = it1.next()) >= 0;) for (GeodesicSearchInsideIterator it1(*geodesic_search_resul
it.value()->draw(prj, renderer, zone, true, rcmag_ta t,z->level);(zone = it1.next()) >= 0;)
ble, core, maxMagStarName, names_brightness); z->draw(&sPainter, zone, true, rcmag_table, limitMag
for (GeodesicSearchBorderIterator it1(*geodesic_search_resul Index, core, maxMagStarName, names_brightness, viewportCaps);
t,it.key());(zone = it1.next()) >= 0;) for (GeodesicSearchBorderIterator it1(*geodesic_search_resul
it.value()->draw(prj, renderer, zone, false, rcmag_t t,z->level);(zone = it1.next()) >= 0;)
able, core, maxMagStarName,names_brightness); z->draw(&sPainter, zone, false, rcmag_table, limitMa
gIndex, core, maxMagStarName,names_brightness, viewportCaps);
} }
exit_loop: exit_loop:
// Finish drawing many stars // Finish drawing many stars
skyDrawer->postDrawPointSource(prj); skyDrawer->postDrawPointSource(&sPainter);
if (objectMgr->getFlagSelectedObjectPointer()) if (objectMgr->getFlagSelectedObjectPointer())
drawPointer(renderer, prj, core); drawPointer(sPainter, core);
} }
// 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 937 skipping to change at line 909
e0 *= f; e0 *= f;
e1 *= f; e1 *= f;
e2 *= f; e2 *= f;
e3 *= f; e3 *= f;
// Search the triangles // Search the triangles
SphericalConvexPolygon c(e3, e2, e2, e0); SphericalConvexPolygon c(e3, e2, e2, e0);
const GeodesicSearchResult* geodesic_search_result = core->getGeodes icGrid(lastMaxSearchLevel)->search(c.getBoundingSphericalCaps(),lastMaxSear chLevel); 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.constBegin());it!=zo neArrays.constEnd();it++) foreach(ZoneArray* z, gridLevels)
{ {
//qDebug() << "search inside(" << it->first << "):"; //qDebug() << "search inside(" << it->first << "):";
int zone; int zone;
for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it.key());(zone = it1.next()) >= 0;) for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,z->level);(zone = it1.next()) >= 0;)
{ {
it.value()->searchAround(core, zone,v,f,result); z->searchAround(core, zone,v,f,result);
//qDebug() << " " << zone; //qDebug() << " " << zone;
} }
//qDebug() << endl << "search border(" << it->first << "):"; //qDebug() << endl << "search border(" << it->first << "):";
for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,it.key()); (zone = it1.next()) >= 0;) for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,z->level); (zone = it1.next()) >= 0;)
{ {
it.value()->searchAround(core, zone,v,f,result); z->searchAround(core, zone,v,f,result);
//qDebug() << " " << zone; //qDebug() << " " << zone;
} }
} }
return result; return result;
} }
//! Update i18 names from english names according to passed translator. //! Update i18 names from english names according to passed translator.
//! The translation is done using gettext with translated strings defined i n translations.h //! The translation is done using gettext with translated strings defined i n translations.h
void StarMgr::updateI18n() void StarMgr::updateI18n()
{ {
QRegExp transRx("_[(]\"(.*)\"[)]"); QRegExp transRx("_[(]\"(.*)\"[)]");
StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyT ranslator(); const StelTranslator& trans = StelApp::getInstance().getLocaleMgr(). getSkyTranslator();
commonNamesMapI18n.clear(); commonNamesMapI18n.clear();
commonNamesIndexI18n.clear(); commonNamesIndexI18n.clear();
for (QHash<int,QString>::ConstIterator it(commonNamesMap.constBegin( ));it!=commonNamesMap.constEnd();it++) for (QHash<int,QString>::ConstIterator it(commonNamesMap.constBegin( ));it!=commonNamesMap.constEnd();it++)
{ {
const int i = it.key(); const int i = it.key();
transRx.exactMatch(it.value()); transRx.exactMatch(it.value());
QString tt = transRx.capturedTexts().at(1); QString tt = transRx.capturedTexts().at(1);
const QString t = trans.qtranslate(tt); const QString t = trans.qtranslate(tt);
//const QString t(trans.qtranslate(it.value())); //const QString t(trans.qtranslate(it.value()));
commonNamesMapI18n[i] = t; commonNamesMapI18n[i] = t;
skipping to change at line 1285 skipping to change at line 1257
maxNbItem--; maxNbItem--;
} }
} }
} }
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(float newFontSize)
{ {
starFont.setPixelSize(newFontSize); starFont.setPixelSize(newFontSize);
} }
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 QString fic = StelFileMgr::findFile("skycultures/" + skyCultureDir +
{ "/star_names.fab");
loadCommonNames(StelFileMgr::findFile("skycultures/" + skyCu if (fic.isEmpty())
ltureDir + "/star_names.fab")); qDebug() << "Could not load star_names.fab for sky culture "
} << QDir::toNativeSeparators(skyCultureDir);
catch(std::runtime_error& e) else
{ loadCommonNames(fic);
qDebug() << "Could not load star_names.fab for sky culture "
<< QDir::toNativeSeparators(skyCultureDir) << ": " << e.what();
}
try fic = StelFileMgr::findFile("stars/default/name.fab");
{ if (fic.isEmpty())
loadSciNames(StelFileMgr::findFile("stars/default/name.fab") qWarning() << "WARNING: could not load scientific star names
); file: stars/default/name.fab";
} else
catch (std::runtime_error& e) loadSciNames(fic);
{
qWarning() << "WARNING: could not load scientific star names
file: " << e.what();
}
try fic = StelFileMgr::findFile("stars/default/gcvs_hip_part.dat");
{ if (fic.isEmpty())
loadGcvs(StelFileMgr::findFile("stars/default/gcvs_hip_part. qWarning() << "WARNING: could not load variable stars file:
dat")); stars/default/gcvs_hip_part.dat";
} else
catch (std::runtime_error& e) loadGcvs(fic);
{
qWarning() << "WARNING: could not load variable stars 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. 62 change blocks. 
254 lines changed or deleted 217 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/