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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
// class used to manage groups of Stars
#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 <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 "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelTextureMgr.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 "StelStyle.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "ZoneArray.hpp" #include "ZoneArray.hpp"
#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 // 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 = 2; static const int StarCatalogFormatVersion = 2;
// Initialise statics // Initialise statics
bool StarMgr::flagSciNames = true; bool StarMgr::flagSciNames = true;
std::map<int,QString> StarMgr::commonNamesMap; QHash<int,QString> StarMgr::commonNamesMap;
std::map<int,QString> StarMgr::commonNamesMapI18n; QHash<int,QString> StarMgr::commonNamesMapI18n;
std::map<QString,int> StarMgr::commonNamesIndex; QMap<QString,int> StarMgr::commonNamesIndexI18n;
std::map<QString,int> StarMgr::commonNamesIndexI18n; QHash<int,QString> StarMgr::sciNamesMapI18n;
std::map<int,QString> StarMgr::sciNamesMapI18n; QMap<QString,int> StarMgr::sciNamesIndexI18n;
std::map<QString,int> StarMgr::sciNamesIndexI18n;
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 120 skipping to change at line 112
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 Vec3f &c0, const Vec3f
const Vec3d &c0, &c1, const Vec3f &c2)
const Vec3d &c1, {
const Vec3d &c2) { ZoneArrayMap::const_iterator it(zoneArrays.find(lev));
ZoneArrayMap::const_iterator it(zoneArrays.find(lev)); if (it!=zoneArrays.constEnd())
if (it!=zoneArrays.end()) it->second->initTriangle(index,c0,c1,c2); it.value()->initTriangle(index,c0,c1,c2);
} }
StarMgr::StarMgr(void) : hipIndex(new HipIndexStruct[NR_OF_HIP+1]) 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;
skipping to change at line 158 skipping to change at line 149
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()); ZoneArrayMap::iterator it(zoneArrays.end());
while (it!=zoneArrays.begin()) while (it!=zoneArrays.begin())
{ {
--it; --it;
delete it->second; delete it.value();
it->second = NULL; it.value() = NULL;
} }
zoneArrays.clear(); zoneArrays.clear();
if (hipIndex) if (hipIndex)
delete[] hipIndex; delete[] hipIndex;
} }
QString StarMgr::getCommonName(int hip) QString StarMgr::getCommonName(int hip)
{ {
std::map<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->second; return it.value();
return QString(); return QString();
} }
QString StarMgr::getSciName(int hip) QString StarMgr::getSciName(int hip)
{ {
std::map<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->second; return it.value();
return QString(); return QString();
} }
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 " << starConfigFileFullPath;
skipping to change at line 235 skipping to change at line 226
fic2.open(QIODevice::ReadOnly); fic2.open(QIODevice::ReadOnly);
starSettings = StelJsonParser::parse(&fic2).toMap(); starSettings = StelJsonParser::parse(&fic2).toMap();
fic2.close(); fic2.close();
} }
loadData(starSettings); loadData(starSettings);
starFont.setPixelSize(13); 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.f).toFloat());
objectMgr->registerStelObjectMgr(this); objectMgr->registerStelObjectMgr(this);
texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png"); // Load pointer texture texPointer = StelApp::getInstance().getTextureManager().createTextur e("textures/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.value()->scaleAxis();
} }
} }
void StarMgr::drawPointer(StelPainter& sPainter, 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 (!sPainter.getProjector()->project(pos, screenpos)) if (!sPainter.getProjector()->project(pos, screenpos))
return; return;
const Vec3d& c(obj->getInfoColor()); const Vec3f& c(obj->getInfoColor());
sPainter.setColor(c[0],c[1],c[2]); sPainter.setColor(c[0],c[1],c[2]);
texPointer->bind(); texPointer->bind();
sPainter.enableTexture2d(true); sPainter.enableTexture2d(true);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 13.f, StelApp::getInstance().getTotalRunTime()*40.); sPainter.drawSprite2dMode(screenpos[0], screenpos[1], 13.f, StelApp::getInstance().getTotalRunTime()*40.);
} }
} }
void StarMgr::setStelStyle(const StelStyle& style) 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 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()));
} }
bool StarMgr::checkAndLoadCatalog(QVariantMap catDesc, StelLoadingBar* lb) bool StarMgr::checkAndLoadCatalog(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;
try try
skipping to change at line 316 skipping to change at line 306
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(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 " << catalogFilePath << ", checkin g md5sum..";
QFile fic(catalogFilePath); QFile fic(catalogFilePath);
fic.open(QIODevice::ReadOnly); fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered);
// Compute the MD5 sum // Compute the MD5 sum
QCryptographicHash md5Hash(QCryptographicHash::Md5); QCryptographicHash md5Hash(QCryptographicHash::Md5);
static const qint64 maxStarBufMd5 = 1024*1024*8; const qint64 cat_sz = fic.size();
char* mmd5buf = (char*)malloc(maxStarBufMd5); qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775807LL);
while (!fic.atEnd()) uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd5) : NUL
L;
if (!cat)
{
// The OS was not able to map the file, revert to sl
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)
;
md5Hash.addData(mmd5buf, sz);
}
free(mmd5buf);
}
else
{ {
qint64 sz = fic.read(mmd5buf, maxStarBufMd5); md5Hash.addData((const char*)cat, cat_sz);
md5Hash.addData(mmd5buf, sz); fic.unmap(cat);
} }
free(mmd5buf);
fic.close(); fic.close();
if (md5Hash.result().toHex()!=catDesc.value("checksum").toBy teArray()) 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(); qWarning() << "Error: File " << catalogFileName << " is corrupt, MD5 mismatch! Found " << md5Hash.result().toHex() << " expecte d " << 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, lb); 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() << catalogFileName << ", " << z->level << ": duplicate level";
skipping to change at line 384 skipping to change at line 386
starSettings["catalogs"]=catalogsDescription; starSettings["catalogs"]=catalogsDescription;
QFile tmp(starConfigFileFullPath); QFile tmp(starConfigFileFullPath);
tmp.open(QIODevice::WriteOnly); tmp.open(QIODevice::WriteOnly);
StelJsonParser::write(starSettings, &tmp); StelJsonParser::write(starSettings, &tmp);
tmp.close(); tmp.close();
} }
} }
void StarMgr::loadData(QVariantMap starsConfig) 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 ...";
catalogsDescription = starsConfig.value("catalogs").toList(); catalogsDescription = starsConfig.value("catalogs").toList();
foreach (const QVariant& catV, catalogsDescription) foreach (const QVariant& catV, catalogsDescription)
{ {
QVariantMap m = catV.toMap(); QVariantMap m = catV.toMap();
const QString& catalogId = m.value("id").toString(); checkAndLoadCatalog(m);
const QString& catalogFileName = m.value("fileName").toStrin
g();
lb->SetMessage(q_("Loading catalog %1 from file %2").arg(cat
alogId, catalogFileName));
checkAndLoadCatalog(m, lb);
} }
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()); it != zone Arrays.end();it++) for (ZoneArrayMap::const_iterator it(zoneArrays.constBegin()); it != zoneArrays.constEnd();++it)
{ {
it->second->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 try
skipping to change at line 458 skipping to change at line 455
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();
commonNamesIndex.clear();
commonNamesIndexI18n.clear(); commonNamesIndexI18n.clear();
qDebug() << "Loading star names from" << commonNameFile; qDebug() << "Loading star names from" << commonNameFile;
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" << commonNameFile;
return 0; return 0;
} }
skipping to change at line 519 skipping to change at line 515
qWarning() << "WARNING - parse error at line " << lineNumber << "in" << commonNameFile qWarning() << "WARNING - parse error at line " << lineNumber << "in" << commonNameFile
<< " - empty name field"; << " - empty name field";
continue; continue;
} }
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;
commonNamesIndex[englishCommonName] = hip;
commonNamesMapI18n[hip] = commonNameI18n; commonNamesMapI18n[hip] = commonNameI18n;
commonNamesIndexI18n[commonNameI18n_cap] = hip; commonNamesIndexI18n[commonNameI18n_cap] = hip;
readOk++; readOk++;
} }
} }
cnFile.close(); cnFile.close();
qDebug() << "Loaded" << readOk << "/" << totalRecords << "common sta r names"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "common sta r names";
return 1; return 1;
} }
skipping to change at line 544 skipping to change at line 539
sciNamesMapI18n.clear(); sciNamesMapI18n.clear();
sciNamesIndexI18n.clear(); sciNamesIndexI18n.clear();
qDebug() << "Loading star names from" << sciNameFile; qDebug() << "Loading star names from" << sciNameFile;
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" << sciNameFile;
return; return;
} }
const QStringList& allRecords = QString::fromUtf8(snFile.readAll()).
split('\n');
snFile.close();
int readOk=0; int readOk=0;
int totalRecords=0; int totalRecords=0;
int lineNumber=0; int lineNumber=0;
QString record; // record structure is delimited with a | character. Example record
QRegExp commentRx("^(\\s*#.*|\\s*)$"); strings:
// record structure is delimited with a | character. We will
// use a QRegExp to extract the fields. with whitespace padding perm
itted
// (i.e. it will be stripped automatically) Example record strings:
// " 10819|c_And" // " 10819|c_And"
// "113726|1_And" // "113726|1_And"
QRegExp recordRx("^\\s*(\\d+)\\s*\\|(.*)\\n"); foreach(const QString& record, allRecords)
while(!snFile.atEnd())
{ {
record = QString::fromUtf8(snFile.readLine()); ++lineNumber;
lineNumber++; if (record.isEmpty())
if (commentRx.exactMatch(record))
continue; continue;
totalRecords++; ++totalRecords;
if (!recordRx.exactMatch(record)) const QStringList& fields = record.split('|');
if (fields.size()!=2)
{ {
qWarning() << "WARNING - parse error at line" << lin eNumber << "in" << sciNameFile qWarning() << "WARNING - parse error at line" << lin eNumber << "in" << 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 = recordRx.capturedTexts().at(1).to UInt(&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" << sciNameFile
<< " - failed to convert " << rec ordRx.capturedTexts().at(1) << "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 // Don't set the sci name if it's already set
if (sciNamesMapI18n.find(hip)!=sciNamesMapI18n.end() ) if (sciNamesMapI18n.find(hip)!=sciNamesMapI18n.end() )
{
//qWarning() << "WARNING - duplicate name fo
r HP" << hip << "at line"
// << lineNumber << "in" << sciNam
eFile << "SKIPPING";
continue; continue;
}
QString sci_name_i18n = recordRx.capturedTexts().at( 2).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" << sciNameFile
<< " - empty name field"; << " - empty name field";
continue; continue;
} }
sci_name_i18n.replace('_',' '); sci_name_i18n.replace('_',' ');
QString sci_name_i18n_cap = sci_name_i18n.toUpper();
sciNamesMapI18n[hip] = sci_name_i18n; sciNamesMapI18n[hip] = sci_name_i18n;
sciNamesIndexI18n[sci_name_i18n_cap] = hip; sciNamesIndexI18n[sci_name_i18n.toUpper()] = hip;
readOk++; ++readOk;
} }
} }
snFile.close();
qDebug() << "Loaded" << readOk << "/" << totalRecords << "scientific star names"; qDebug() << "Loaded" << readOk << "/" << totalRecords << "scientific star names";
} }
int StarMgr::getMaxSearchLevel() const int StarMgr::getMaxSearchLevel() const
{ {
int rval = -1; int rval = -1;
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArr ays.end();++it) for (ZoneArrayMap::const_iterator it(zoneArrays.constBegin());it!=zo neArrays.constEnd();++it)
{ {
const float mag_min = 0.001f*it->second->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->first; rval = it.key();
} }
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();
skipping to change at line 649 skipping to change at line 635
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(prj); StelPainter sPainter(prj);
sPainter.setFont(starFont); sPainter.setFont(starFont);
skyDrawer->preDrawPointSource(&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.constBegin()); it!=z oneArrays.constEnd();++it)
{ {
const float mag_min = 0.001f*it->second->mag_min; const float mag_min = 0.001f*it.value()->mag_min;
const float k = (0.001f*it->second->mag_range)/it->second->m const float k = (0.001f*it.value()->mag_range)/it.value()->m
ag_steps; ag_steps;
for (int i=it->second->mag_steps-1;i>=0;--i) for (int i=it.value()->mag_steps-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)== false) if (skyDrawer->computeRCMag(mag,rcmag_table + 2*i)== false)
{ {
if (i==0) goto exit_loop; if (i==0) goto exit_loop;
} }
if (skyDrawer->getFlagPointStar()) if (skyDrawer->getFlagPointStar())
{ {
rcmag_table[2*i+1] *= starsFader.getIntersta te(); rcmag_table[2*i+1] *= starsFader.getIntersta te();
} }
else else
{ {
rcmag_table[2*i] *= starsFader.getInterstate (); rcmag_table[2*i] *= starsFader.getInterstate ();
} }
} }
lastMaxSearchLevel = it->first; lastMaxSearchLevel = it.key();
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 for (GeodesicSearchInsideIterator it1(*geodesic_search_resul
t,it->first);(zone = it1.next()) >= 0;) t,it.key());(zone = it1.next()) >= 0;)
it->second->draw(&sPainter, zone, true, rcmag_table, it.value()->draw(&sPainter, zone, true, rcmag_table,
core, maxMagStarName, names_brightness); core, maxMagStarName, names_brightness);
for (GeodesicSearchBorderIterator it1(*geodesic_search_resul for (GeodesicSearchBorderIterator it1(*geodesic_search_resul
t,it->first);(zone = it1.next()) >= 0;) t,it.key());(zone = it1.next()) >= 0;)
it->second->draw(&sPainter, zone, false, rcmag_table it.value()->draw(&sPainter, zone, false, rcmag_table
, core, maxMagStarName,names_brightness); , core, maxMagStarName,names_brightness);
} }
exit_loop: exit_loop:
// Finish drawing many stars // Finish drawing many stars
skyDrawer->postDrawPointSource(&sPainter); skyDrawer->postDrawPointSource(&sPainter);
if (objectMgr->getFlagSelectedObjectPointer()) if (objectMgr->getFlagSelectedObjectPointer())
drawPointer(sPainter, nav); drawPointer(sPainter, nav);
} }
// Return a stl vector containing the stars located // Return a stl vector containing the stars located
skipping to change at line 748 skipping to change at line 734
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.begin());it!=zoneArr ays.end();it++) for (ZoneArrayMap::const_iterator it(zoneArrays.constBegin());it!=zo neArrays.constEnd();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.key());(zone = it1.next()) >= 0;)
{ {
it->second->searchAround(core->getNavigator(), zone, v,f,result); it.value()->searchAround(core->getNavigator(), 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->first); (zone = it1.next()) >= 0;) for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,it.key()); (zone = it1.next()) >= 0;)
{ {
it->second->searchAround(core->getNavigator(), zone, v,f,result); it.value()->searchAround(core->getNavigator(), 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()
{ {
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 (QHash<int,QString>::ConstIterator it(commonNamesMap.constBegin( ));it!=commonNamesMap.constEnd();it++)
{ {
const int i = it->first; const int i = it.key();
const QString t(trans.qtranslate(it->second)); const QString t(trans.qtranslate(it.value()));
commonNamesMapI18n[i] = t; commonNamesMapI18n[i] = t;
commonNamesIndexI18n[t.toUpper()] = i; commonNamesIndexI18n[t.toUpper()] = i;
} }
} }
// 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)
{ {
skipping to change at line 811 skipping to change at line 797
QString objw = nameI18n.toUpper(); QString objw = nameI18n.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*(HIP|HP)\\s*(\\d+)\\s*$", Qt::CaseInsensitive); QRegExp rx("^\\s*(HIP|HP)\\s*(\\d+)\\s*$", Qt::CaseInsensitive);
if (rx.exactMatch(objw)) if (rx.exactMatch(objw))
{ {
return searchHP(rx.capturedTexts().at(2).toInt()); return searchHP(rx.capturedTexts().at(2).toInt());
} }
// Search by I18n common name // Search by I18n common name
std::map<QString,int>::const_iterator it(commonNamesIndexI18n.find(o bjw)); QMap<QString,int>::const_iterator it(commonNamesIndexI18n.find(objw) );
if (it!=commonNamesIndexI18n.end()) if (it!=commonNamesIndexI18n.end())
{ {
return searchHP(it->second); return searchHP(it.value());
} }
// Search by sci name // Search by sci name
it = sciNamesIndexI18n.find(objw); QMap<QString,int>::const_iterator it2 = sciNamesIndexI18n.find(objw)
if (it!=sciNamesIndexI18n.end()) ;
if (it2!=sciNamesIndexI18n.end())
{ {
return searchHP(it->second); return searchHP(it2.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))
{ {
return searchHP(rx.capturedTexts().at(2).toInt()); return searchHP(rx.capturedTexts().at(2).toInt());
} }
// Search by sci name // Search by sci name
std::map<QString,int>::const_iterator it = sciNamesIndexI18n.find(ob jw); QMap<QString,int>::const_iterator it = sciNamesIndexI18n.find(objw);
if (it!=sciNamesIndexI18n.end()) if (it!=sciNamesIndexI18n.end())
{ {
return searchHP(it->second); return searchHP(it.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;
QString objw = objPrefix.toUpper(); QString objw = objPrefix.toUpper();
// Search for common names // Search for common names
for (std::map<QString,int>::const_iterator it(commonNamesIndexI18n.l ower_bound(objw)); it!=commonNamesIndexI18n.end(); ++it) for (QMap<QString,int>::const_iterator it(commonNamesIndexI18n.lower Bound(objw)); it!=commonNamesIndexI18n.end(); ++it)
{ {
if (it->first.startsWith(objw)) if (it.key().startsWith(objw))
{ {
if (maxNbItem==0) if (maxNbItem==0)
break; break;
result << getCommonName(it->second); result << getCommonName(it.value());
--maxNbItem; --maxNbItem;
} }
else else
break; break;
} }
// Search for sci names // Search for sci names
QString bayerPattern = objw; QString bayerPattern = objw;
QRegExp bayerRegEx(bayerPattern); QRegExp bayerRegEx(bayerPattern);
// if the first character is a Greek letter, check if there's an ind ex // if the first character is a Greek letter, check if there's an ind ex
// after it, such as "alpha1 Cen". // after it, such as "alpha1 Cen".
if (objw.at(0).unicode() >= 0x0391 && objw.at(0).unicode() <= 0x03A9 ) if (objw.at(0).unicode() >= 0x0391 && objw.at(0).unicode() <= 0x03A9 )
bayerRegEx.setPattern(bayerPattern.insert(1,"\\d?")); bayerRegEx.setPattern(bayerPattern.insert(1,"\\d?"));
for (std::map<QString,int>::const_iterator it(sciNamesIndexI18n.lowe r_bound(objw)); it!=sciNamesIndexI18n.end(); ++it) for (QMap<QString,int>::const_iterator it(sciNamesIndexI18n.lowerBou nd(objw)); it!=sciNamesIndexI18n.end(); ++it)
{ {
if (it->first.indexOf(bayerRegEx)==0) if (it.key().indexOf(bayerRegEx)==0)
{ {
if (maxNbItem==0) if (maxNbItem==0)
break; break;
result << getSciName(it->second); result << getSciName(it.value());
--maxNbItem; --maxNbItem;
} }
else if (it->first.at(0) != objw.at(0)) else if (it.key().at(0) != objw.at(0))
break; 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);
 End of changes. 70 change blocks. 
119 lines changed or deleted 107 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/