StarMgr.cpp   StarMgr.cpp 
skipping to change at line 31 skipping to change at line 31
*/ */
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QRegExp> #include <QRegExp>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include <QTextStream> #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 "renderer/StelRenderer.hpp"
#include "renderer/StelTextureNew.hpp" #include "renderer/StelTextureNew.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelToneReproducer.hpp" #include "StelToneReproducer.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
skipping to change at line 57 skipping to change at line 58
#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 "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 <errno.h>
#ifndef Q_OS_WIN
#include <unistd.h> #include <unistd.h>
#else
#include "kdewin32/unistd.h"
#endif
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 // 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 = 3; static const int StarCatalogFormatVersion = 4;
// 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;
QMap<QString,int> StarMgr::sciAdditionalNamesIndexI18n;
QHash<int, varstar> StarMgr::varStarsMapI18n;
QMap<QString, int> StarMgr::varStarsIndexI18n;
QStringList initStringListFromFile(const QString& file_name) QStringList initStringListFromFile(const QString& file_name)
{ {
QStringList list; QStringList list;
QFile f(file_name); QFile f(file_name);
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) if (f.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
while (!f.atEnd()) while (!f.atEnd())
{ {
QString s = QString::fromUtf8(f.readLine()); QString s = QString::fromUtf8(f.readLine());
skipping to change at line 182 skipping to change at line 191
} }
QString StarMgr::getSciName(int hip) QString StarMgr::getSciName(int hip)
{ {
QHash<int,QString>::const_iterator it(sciNamesMapI18n.find(hip)); QHash<int,QString>::const_iterator it(sciNamesMapI18n.find(hip));
if (it!=sciNamesMapI18n.end()) if (it!=sciNamesMapI18n.end())
return it.value(); return it.value();
return QString(); return QString();
} }
QString StarMgr::getSciAdditionalName(int hip)
{
QHash<int,QString>::const_iterator it(sciAdditionalNamesMapI18n.find
(hip));
if (it!=sciAdditionalNamesMapI18n.end())
return it.value();
return QString();
}
QString StarMgr::getGCVSName(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().designation;
return QString();
}
QString StarMgr::getGCVSVariabilityType(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().vtype;
return QString();
}
float StarMgr::getGCVSMaxMagnitude(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().maxmag;
return -99.f;
}
int StarMgr::getGCVSMagnitudeFlag(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().mflag;
return 0;
}
float StarMgr::getGCVSMinMagnitude(int hip, bool firstMinimumFlag)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
{
if (firstMinimumFlag)
{
return it.value().min1mag;
}
else
{
return it.value().min2mag;
}
}
return -99.f;
}
QString StarMgr::getGCVSPhotometricSystem(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().photosys;
return QString();
}
double StarMgr::getGCVSEpoch(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().epoch;
return -99.f;
}
double StarMgr::getGCVSPeriod(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().period;
return -99.f;
}
int StarMgr::getGCVSMM(int hip)
{
QHash<int,varstar>::const_iterator it(varStarsMapI18n.find(hip));
if (it!=varStarsMapI18n.end())
return it.value().Mm;
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 " << starConfigFileFullPath; qDebug() << "Creates file " << QDir::toNativeSeparators(star ConfigFileFullPath);
QFile::copy(StelFileMgr::findFile("stars/default/defaultStar sConfig.json"), starConfigFileFullPath); QFile::copy(StelFileMgr::findFile("stars/default/defaultStar sConfig.json"), starConfigFileFullPath);
} }
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()
skipping to change at line 311 skipping to change at line 409
QString catalogFilePath; QString catalogFilePath;
try try
{ {
catalogFilePath = StelFileMgr::findFile(catalogFileName); catalogFilePath = StelFileMgr::findFile(catalogFileName);
} }
catch (std::runtime_error e) 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(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
if (!StelFileMgr::isReadable(catalogFilePath)) if (!StelFileMgr::isReadable(catalogFilePath))
{ {
qWarning() << QString("Warning: User does not have permissio ns to read catalog %1").arg(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 " << catalogFilePath << ", checkin g md5sum.."; qWarning() << "Found file " << QDir::toNativeSeparators(cata logFilePath) << ", checking md5sum..";
QFile fic(catalogFilePath); QFile fic(catalogFilePath);
fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered); fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
// Compute the MD5 sum // Compute the MD5 sum
QCryptographicHash md5Hash(QCryptographicHash::Md5); QCryptographicHash md5Hash(QCryptographicHash::Md5);
const qint64 cat_sz = fic.size(); const qint64 cat_sz = fic.size();
qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775807LL); qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775807LL);
uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd5) : NUL L; uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd5) : NUL L;
if (!cat) if (!cat)
{ {
skipping to change at line 355 skipping to change at line 453
free(mmd5buf); free(mmd5buf);
} }
else else
{ {
md5Hash.addData((const char*)cat, cat_sz); md5Hash.addData((const char*)cat, cat_sz);
fic.unmap(cat); fic.unmap(cat);
} }
fic.close(); fic.close();
if (md5Hash.result().toHex()!=catDesc.value("checksum").toBy teArray()) if (md5Hash.result().toHex()!=catDesc.value("checksum").toBy teArray())
{ {
qWarning() << "Error: File " << catalogFileName << " is corrupt, MD5 mismatch! Found " << md5Hash.result().toHex() << " expecte d " << catDesc.value("checksum").toByteArray(); qWarning() << "Error: File " << QDir::toNativeSepara tors(catalogFileName) << " is corrupt, MD5 mismatch! Found " << md5Hash.res ult().toHex() << " expected " << catDesc.value("checksum").toByteArray();
fic.remove(); fic.remove();
return false; return false;
} }
qWarning() << "MD5 sum correct!"; qWarning() << "MD5 sum correct!";
setCheckFlag(catDesc.value("id").toString(), true); setCheckFlag(catDesc.value("id").toString(), true);
} }
ZoneArray* const z = ZoneArray::create(catalogFilePath, true); ZoneArray* const z = ZoneArray::create(catalogFilePath, true);
if (z) if (z)
{ {
if (maxGeodesicGridLevel < z->level) if (maxGeodesicGridLevel < z->level)
{ {
maxGeodesicGridLevel = z->level; maxGeodesicGridLevel = z->level;
} }
ZoneArray *&pos(zoneArrays[z->level]); ZoneArray *pos(zoneArrays[z->level]);
if (pos) if (pos)
{ {
qWarning() << catalogFileName << ", " << z->level << ": duplicate level"; qWarning() << QDir::toNativeSeparators(catalogFileNa me) << ", " << z->level << ": duplicate level";
delete z; delete z;
} }
else else
{ {
zoneArrays[z->level] = z;
pos = z; pos = 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;
skipping to change at line 446 skipping to change at line 545
} }
else else
{ {
try try
{ {
spectral_array = initStringListFromFile(StelFileMgr: :findFile("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_name) << QDir::toNativeSeparators(("sta rs/default/" + cat_hip_sp_file_name))
<< ": " << e.what(); << ": " << 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 try
{ {
component_array = initStringListFromFile(StelFileMgr ::findFile("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_ci ds_file_name) << ": " << e.what(); << 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();
commonNamesMapI18n.clear(); commonNamesMapI18n.clear();
commonNamesIndexI18n.clear(); commonNamesIndexI18n.clear();
commonNamesIndex.clear(); commonNamesIndex.clear();
qDebug() << "Loading star names from" << commonNameFile; qDebug() << "Loading star names from" << QDir::toNativeSeparators(co mmonNameFile);
QFile cnFile(commonNameFile); QFile cnFile(commonNameFile);
if (!cnFile.open(QIODevice::ReadOnly | QIODevice::Text)) if (!cnFile.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
qWarning() << "WARNING - could not open" << commonNameFile; qWarning() << "WARNING - could not open" << QDir::toNativeSe parators(commonNameFile);
return 0; return 0;
} }
int readOk=0; int readOk=0;
int totalRecords=0; int totalRecords=0;
int lineNumber=0; int lineNumber=0;
QString record; QString record;
QRegExp commentRx("^(\\s*#.*|\\s*)$"); QRegExp commentRx("^(\\s*#.*|\\s*)$");
// record structure is delimited with a | character. We will // record structure is delimited with a | character. We will
// use a QRegExp to extract the fields. with whitespace padding perm itted // use a QRegExp to extract the fields. with whitespace padding perm itted
skipping to change at line 511 skipping to change at line 610
while(!cnFile.atEnd()) while(!cnFile.atEnd())
{ {
record = QString::fromUtf8(cnFile.readLine()); record = QString::fromUtf8(cnFile.readLine());
lineNumber++; lineNumber++;
if (commentRx.exactMatch(record)) if (commentRx.exactMatch(record))
continue; continue;
totalRecords++; totalRecords++;
if (!recordRx.exactMatch(record)) if (!recordRx.exactMatch(record))
{ {
qWarning() << "WARNING - parse error at line" << lin eNumber << "in" << commonNameFile qWarning() << "WARNING - parse error at line" << lin eNumber << "in" << QDir::toNativeSeparators(commonNameFile)
<< " - record does not match record patte rn"; << " - record does not match record patte rn";
continue; continue;
} }
else else
{ {
// The record is the right format. Extract the fiel ds // The record is the right format. Extract the fiel ds
bool ok; bool ok;
unsigned int hip = recordRx.capturedTexts().at(1).to UInt(&ok); unsigned int hip = recordRx.capturedTexts().at(1).to UInt(&ok);
if (!ok) if (!ok)
{ {
qWarning() << "WARNING - parse error at line " << lineNumber << "in" << commonNameFile qWarning() << "WARNING - parse error at line " << lineNumber << "in" << QDir::toNativeSeparators(commonNameFile)
<< " - failed to convert " << rec ordRx.capturedTexts().at(1) << "to a number"; << " - failed to convert " << rec ordRx.capturedTexts().at(1) << "to a number";
continue; continue;
} }
QString englishCommonName = recordRx.capturedTexts() .at(2).trimmed(); QString englishCommonName = recordRx.capturedTexts() .at(2).trimmed();
if (englishCommonName.isEmpty()) if (englishCommonName.isEmpty())
{ {
qWarning() << "WARNING - parse error at line " << lineNumber << "in" << commonNameFile qWarning() << "WARNING - parse error at line " << lineNumber << "in" << QDir::toNativeSeparators(commonNameFile)
<< " - empty name field"; << " - empty name field";
continue; continue;
} }
// Fix for translate star names // Fix for translate star names
// englishCommonName.replace('_', ' '); // englishCommonName.replace('_', ' ');
const QString commonNameI18n = q_(englishCommonName) ; const QString commonNameI18n = q_(englishCommonName) ;
QString commonNameI18n_cap = commonNameI18n.toUpper( ); QString commonNameI18n_cap = commonNameI18n.toUpper( );
commonNamesMap[hip] = englishCommonName; commonNamesMap[hip] = englishCommonName;
skipping to change at line 557 skipping to change at line 656
qDebug() << "Loaded" << readOk << "/" << totalRecords << "common sta r names"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "common sta r names";
return 1; return 1;
} }
// Load scientific names from file // Load scientific names from file
void StarMgr::loadSciNames(const QString& sciNameFile) void StarMgr::loadSciNames(const QString& sciNameFile)
{ {
sciNamesMapI18n.clear(); sciNamesMapI18n.clear();
sciNamesIndexI18n.clear(); sciNamesIndexI18n.clear();
sciAdditionalNamesMapI18n.clear();
sciAdditionalNamesIndexI18n.clear();
qDebug() << "Loading star names from" << sciNameFile; qDebug() << "Loading star names from" << QDir::toNativeSeparators(sc iNameFile);
QFile snFile(sciNameFile); QFile snFile(sciNameFile);
if (!snFile.open(QIODevice::ReadOnly | QIODevice::Text)) if (!snFile.open(QIODevice::ReadOnly | QIODevice::Text))
{ {
qWarning() << "WARNING - could not open" << sciNameFile; qWarning() << "WARNING - could not open" << QDir::toNativeSe parators(sciNameFile);
return; return;
} }
const QStringList& allRecords = QString::fromUtf8(snFile.readAll()). split('\n'); const QStringList& allRecords = QString::fromUtf8(snFile.readAll()). split('\n');
snFile.close(); snFile.close();
int readOk=0; int readOk=0;
int totalRecords=0; int totalRecords=0;
int lineNumber=0; int lineNumber=0;
// record structure is delimited with a | character. Example record strings: // record structure is delimited with a | character. Example record strings:
// " 10819|c_And" // " 10819|c_And"
skipping to change at line 584 skipping to change at line 685
foreach(const QString& record, allRecords) foreach(const QString& record, allRecords)
{ {
++lineNumber; ++lineNumber;
if (record.isEmpty()) if (record.isEmpty())
continue; continue;
++totalRecords; ++totalRecords;
const QStringList& fields = record.split('|'); const QStringList& fields = record.split('|');
if (fields.size()!=2) if (fields.size()!=2)
{ {
qWarning() << "WARNING - parse error at line" << lin eNumber << "in" << sciNameFile qWarning() << "WARNING - parse error at line" << lin eNumber << "in" << QDir::toNativeSeparators(sciNameFile)
<< " - record does not match record patte rn"; << " - record does not match record patte rn";
continue; continue;
} }
else else
{ {
// The record is the right format. Extract the fiel ds // The record is the right format. Extract the fiel ds
bool ok; bool ok;
unsigned int hip = fields.at(0).toUInt(&ok); unsigned int hip = fields.at(0).toUInt(&ok);
if (!ok) if (!ok)
{ {
qWarning() << "WARNING - parse error at line " << lineNumber << "in" << sciNameFile qWarning() << "WARNING - parse error at line " << lineNumber << "in" << QDir::toNativeSeparators(sciNameFile)
<< " - failed to convert " << fie lds.at(0) << "to a number"; << " - failed to convert " << fie lds.at(0) << "to a number";
continue; continue;
} }
// Don't set the sci name if it's already set
if (sciNamesMapI18n.find(hip)!=sciNamesMapI18n.end()
)
continue;
QString sci_name_i18n = fields.at(1).trimmed(); QString sci_name_i18n = fields.at(1).trimmed();
if (sci_name_i18n.isEmpty()) if (sci_name_i18n.isEmpty())
{ {
qWarning() << "WARNING - parse error at line " << lineNumber << "in" << sciNameFile qWarning() << "WARNING - parse error at line " << lineNumber << "in" << QDir::toNativeSeparators(sciNameFile)
<< " - empty name field"; << " - empty name field";
continue; continue;
} }
sci_name_i18n.replace('_',' '); sci_name_i18n.replace('_',' ');
sciNamesMapI18n[hip] = sci_name_i18n; // Don't set the main sci name if it's already set -
sciNamesIndexI18n[sci_name_i18n.toUpper()] = hip; it's additional sci name
if (sciNamesMapI18n.find(hip)!=sciNamesMapI18n.end()
)
{
sciAdditionalNamesMapI18n[hip] = sci_name_i1
8n;
sciAdditionalNamesIndexI18n[sci_name_i18n.to
Upper()] = hip;
}
else
{
sciNamesMapI18n[hip] = sci_name_i18n;
sciNamesIndexI18n[sci_name_i18n.toUpper()] =
hip;
}
++readOk; ++readOk;
} }
} }
qDebug() << "Loaded" << readOk << "/" << totalRecords << "scientific star names"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "scientific star names";
} }
// Load GCVS from file
void StarMgr::loadGCVS(const QString& GCVSFile)
{
varStarsMapI18n.clear();
varStarsIndexI18n.clear();
qDebug() << "Loading variable stars from" << QDir::toNativeSeparator
s(GCVSFile);
QFile vsFile(GCVSFile);
if (!vsFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qWarning() << "WARNING - could not open" << QDir::toNativeSe
parators(GCVSFile);
return;
}
const QStringList& allRecords = QString::fromUtf8(vsFile.readAll()).
split('\n');
vsFile.close();
int readOk=0;
int totalRecords=0;
int lineNumber=0;
// record structure is delimited with a tab character.
foreach(const QString& record, allRecords)
{
++lineNumber;
if (record.isEmpty())
continue;
++totalRecords;
const QStringList& fields = record.split('\t');
bool ok;
unsigned int hip = fields.at(0).toUInt(&ok);
if (!ok)
{
qWarning() << "WARNING - parse error at line" << lin
eNumber << "in" << QDir::toNativeSeparators(GCVSFile)
<< " - failed to convert " << fields.at(0
) << "to a number";
continue;
}
// Don't set the star if it's already set
if (varStarsMapI18n.find(hip)!=varStarsMapI18n.end())
continue;
varstar variableStar;
variableStar.designation = fields.at(1).trimmed();
variableStar.vtype = fields.at(2).trimmed();
variableStar.maxmag = fields.at(3).toFloat();
variableStar.mflag = fields.at(4).toInt();
variableStar.min1mag = fields.at(5).toFloat();
if (fields.at(6).isEmpty())
variableStar.min2mag = 99.f;
else
variableStar.min2mag = fields.at(6).toFloat();
variableStar.photosys = fields.at(7).trimmed();
variableStar.epoch = fields.at(8).toDouble();
variableStar.period = fields.at(9).toDouble();
variableStar.Mm = fields.at(10).toInt();
variableStar.stype = fields.at(11).trimmed();
varStarsMapI18n[hip] = variableStar;
varStarsIndexI18n[variableStar.designation.toUpper()] = hip;
++readOk;
}
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) for (ZoneArrayMap::const_iterator it(zoneArrays.constBegin());it!=zo neArrays.constEnd();++it)
{ {
const float mag_min = 0.001f*it.value()->mag_min; const float mag_min = 0.001f*it.value()->mag_min;
float rcmag[2]; float rcmag[2];
if (StelApp::getInstance().getCore()->getSkyDrawer()->comput eRCMag(mag_min,rcmag)==false) if (StelApp::getInstance().getCore()->getSkyDrawer()->comput eRCMag(mag_min,rcmag)==false)
break; break;
rval = it.key(); rval = it.key();
skipping to change at line 843 skipping to change at line 1017
return searchHP(it.value()); return searchHP(it.value());
} }
// Search by sci name // Search by sci name
QMap<QString,int>::const_iterator it2 = sciNamesIndexI18n.find(objw) ; QMap<QString,int>::const_iterator it2 = sciNamesIndexI18n.find(objw) ;
if (it2!=sciNamesIndexI18n.end()) if (it2!=sciNamesIndexI18n.end())
{ {
return searchHP(it2.value()); return searchHP(it2.value());
} }
// Search by additional sci name
QMap<QString,int>::const_iterator it3 = sciAdditionalNamesIndexI18n.
find(objw);
if (it3!=sciAdditionalNamesIndexI18n.end())
{
return searchHP(it3.value());
}
// Search by GCVS name
QMap<QString,int>::const_iterator it4 = varStarsIndexI18n.find(objw)
;
if (it4!=varStarsIndexI18n.end())
{
return searchHP(it4.value());
}
return StelObjectP(); return StelObjectP();
} }
StelObjectP StarMgr::searchByName(const QString& name) const StelObjectP StarMgr::searchByName(const QString& name) const
{ {
QString objw = name.toUpper(); QString objw = name.toUpper();
// Search by HP number if it's an HP formated number // Search by HP number if it's an HP formated number
QRegExp rx("^\\s*(HP|HIP)\\s*(\\d+)\\s*$", Qt::CaseInsensitive); QRegExp rx("^\\s*(HP|HIP)\\s*(\\d+)\\s*$", Qt::CaseInsensitive);
if (rx.exactMatch(objw)) if (rx.exactMatch(objw))
skipping to change at line 864 skipping to change at line 1052
return searchHP(rx.capturedTexts().at(2).toInt()); return searchHP(rx.capturedTexts().at(2).toInt());
} }
// Search by sci name // Search by sci name
QMap<QString,int>::const_iterator it = sciNamesIndexI18n.find(objw); QMap<QString,int>::const_iterator it = sciNamesIndexI18n.find(objw);
if (it!=sciNamesIndexI18n.end()) if (it!=sciNamesIndexI18n.end())
{ {
return searchHP(it.value()); return searchHP(it.value());
} }
// Search by additional sci name
QMap<QString,int>::const_iterator it2 = sciAdditionalNamesIndexI18n.
find(objw);
if (it2!=sciAdditionalNamesIndexI18n.end())
{
return searchHP(it2.value());
}
return StelObjectP(); return StelObjectP();
} }
//! Find and return the list of at most maxNbItem objects auto-completing //! Find and return the list of at most maxNbItem objects auto-completing
//! the passed object I18n name. //! the passed object I18n name.
QStringList StarMgr::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const QStringList StarMgr::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
{ {
QStringList result; QStringList result;
if (maxNbItem==0) return result; if (maxNbItem==0) return result;
skipping to change at line 912 skipping to change at line 1107
{ {
if (maxNbItem==0) if (maxNbItem==0)
break; break;
result << getSciName(it.value()); result << getSciName(it.value());
--maxNbItem; --maxNbItem;
} }
else if (it.key().at(0) != objw.at(0)) else if (it.key().at(0) != objw.at(0))
break; break;
} }
for (QMap<QString,int>::const_iterator it(sciAdditionalNamesIndexI18
n.lowerBound(objw)); it!=sciAdditionalNamesIndexI18n.end(); ++it)
{
if (it.key().indexOf(bayerRegEx)==0)
{
if (maxNbItem==0)
break;
result << getSciAdditionalName(it.value());
--maxNbItem;
}
else if (it.key().at(0) != objw.at(0))
break;
}
for (QMap<QString,int>::const_iterator it(varStarsIndexI18n.lowerBou
nd(objw)); it!=varStarsIndexI18n.end(); ++it)
{
if (it.key().startsWith(objw))
{
if (maxNbItem==0)
break;
result << getGCVSName(it.value());
--maxNbItem;
}
else
break;
}
// Add exact Hp catalogue numbers // Add exact Hp catalogue numbers
QRegExp hpRx("^(HIP|HP)\\s*(\\d+)\\s*$"); QRegExp hpRx("^(HIP|HP)\\s*(\\d+)\\s*$");
hpRx.setCaseSensitivity(Qt::CaseInsensitive); hpRx.setCaseSensitivity(Qt::CaseInsensitive);
if (hpRx.exactMatch(objw)) if (hpRx.exactMatch(objw))
{ {
bool ok; bool ok;
int hpNum = hpRx.capturedTexts().at(2).toInt(&ok); int hpNum = hpRx.capturedTexts().at(2).toInt(&ok);
if (ok) if (ok)
{ {
StelObjectP s = searchHP(hpNum); StelObjectP s = searchHP(hpNum);
skipping to change at line 979 skipping to change at line 1200
{ {
if (maxNbItem==0) if (maxNbItem==0)
break; break;
result << getSciName(it.value()); result << getSciName(it.value());
--maxNbItem; --maxNbItem;
} }
else if (it.key().at(0) != objw.at(0)) else if (it.key().at(0) != objw.at(0))
break; break;
} }
for (QMap<QString,int>::const_iterator it(sciAdditionalNamesIndexI18
n.lowerBound(objw)); it!=sciAdditionalNamesIndexI18n.end(); ++it)
{
if (it.key().indexOf(bayerRegEx)==0)
{
if (maxNbItem==0)
break;
result << getSciAdditionalName(it.value());
--maxNbItem;
}
else if (it.key().at(0) != objw.at(0))
break;
}
// Search for sci names for var stars
for (QMap<QString,int>::const_iterator it(varStarsIndexI18n.lowerBou
nd(objw)); it!=varStarsIndexI18n.end(); ++it)
{
if (it.key().startsWith(objw))
{
if (maxNbItem==0)
break;
result << getGCVSName(it.value());
--maxNbItem;
}
else
break;
}
// Add exact Hp catalogue numbers // Add exact Hp catalogue numbers
QRegExp hpRx("^(HIP|HP)\\s*(\\d+)\\s*$"); QRegExp hpRx("^(HIP|HP)\\s*(\\d+)\\s*$");
hpRx.setCaseSensitivity(Qt::CaseInsensitive); hpRx.setCaseSensitivity(Qt::CaseInsensitive);
if (hpRx.exactMatch(objw)) if (hpRx.exactMatch(objw))
{ {
bool ok; bool ok;
int hpNum = hpRx.capturedTexts().at(2).toInt(&ok); int hpNum = hpRx.capturedTexts().at(2).toInt(&ok);
if (ok) if (ok)
{ {
StelObjectP s = searchHP(hpNum); StelObjectP s = searchHP(hpNum);
skipping to change at line 1016 skipping to change at line 1264
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(StelFileMgr::findFile("skycultures/" + skyCu ltureDir + "/star_names.fab")); loadCommonNames(StelFileMgr::findFile("skycultures/" + skyCu ltureDir + "/star_names.fab"));
} }
catch(std::runtime_error& e) catch(std::runtime_error& e)
{ {
qDebug() << "Could not load star_names.fab for sky culture " << skyCultureDir << ": " << e.what(); qDebug() << "Could not load star_names.fab for sky culture " << QDir::toNativeSeparators(skyCultureDir) << ": " << e.what();
} }
try try
{ {
loadSciNames(StelFileMgr::findFile("stars/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();
} }
try
{
loadGCVS(StelFileMgr::findFile("stars/default/gcvs_hip_part.
dat"));
}
catch (std::runtime_error& e)
{
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. 36 change blocks. 
28 lines changed or deleted 305 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/