StarMgr.cpp   StarMgr.cpp 
skipping to change at line 70 skipping to change at line 70
#include <list> #include <list>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
using namespace BigStarCatalogExtension; using namespace BigStarCatalogExtension;
static QStringList spectral_array; static QStringList spectral_array;
static QStringList component_array; static QStringList component_array;
// Initialise statics
bool StarMgr::flagSciNames = true;
std::map<int,QString> StarMgr::commonNamesMap;
std::map<int,QString> StarMgr::commonNamesMapI18n;
std::map<QString,int> StarMgr::commonNamesIndex;
std::map<QString,int> StarMgr::commonNamesIndexI18n;
std::map<int,QString> StarMgr::sciNamesMapI18n;
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());
s.chop(1); s.chop(1);
skipping to change at line 115 skipping to change at line 124
} }
void StarMgr::initTriangle(int lev,int index, void StarMgr::initTriangle(int lev,int index,
const Vec3d &c0, const Vec3d &c0,
const Vec3d &c1, const Vec3d &c1,
const Vec3d &c2) { const Vec3d &c2) {
ZoneArrayMap::const_iterator it(zoneArrays.find(lev)); ZoneArrayMap::const_iterator it(zoneArrays.find(lev));
if (it!=zoneArrays.end()) it->second->initTriangle(index,c0,c1,c2); if (it!=zoneArrays.end()) it->second->initTriangle(index,c0,c1,c2);
} }
StarMgr::StarMgr(void) : StarMgr::StarMgr(void) : hipIndex(new HipIndexStruct[NR_OF_HIP+1]), fontSiz
hipIndex(new HipIndexStruct[NR_OF_HIP+1]), e(13.), starFont(NULL)
fontSize(13.),
starFont(0)
{ {
setObjectName("StarMgr"); setObjectName("StarMgr");
if (hipIndex == 0) { if (hipIndex == 0)
qWarning() << "ERROR: StarMgr::StarMgr: no memory"; {
exit(1); qFatal("ERROR: StarMgr::StarMgr: no memory");
} }
maxGeodesicGridLevel = -1; maxGeodesicGridLevel = -1;
lastMaxSearchLevel = -1; lastMaxSearchLevel = -1;
objectMgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(objectMgr);
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
double StarMgr::getCallOrder(StelModuleActionName actionName) const double StarMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Cons tellationMgr")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Cons tellationMgr")->getCallOrder(actionName)+10;
return 0; return 0;
skipping to change at line 155 skipping to change at line 163
{ {
--it; --it;
delete it->second; delete it->second;
it->second = NULL; it->second = NULL;
} }
zoneArrays.clear(); zoneArrays.clear();
if (hipIndex) if (hipIndex)
delete[] hipIndex; delete[] hipIndex;
} }
bool StarMgr::flagSciNames = true; QString StarMgr::getCommonName(int hip)
double StarMgr::currentJDay = 0; {
std::map<int,QString> StarMgr::commonNamesMap; std::map<int,QString>::const_iterator it(commonNamesMapI18n.find(hip
std::map<int,QString> StarMgr::commonNamesMapI18n; ));
std::map<QString,int> StarMgr::commonNamesIndex; if (it!=commonNamesMapI18n.end())
std::map<QString,int> StarMgr::commonNamesIndexI18n; return it->second;
return QString();
std::map<int,QString> StarMgr::sciNamesMapI18n;
std::map<QString,int> StarMgr::sciNamesIndexI18n;
QString StarMgr::getCommonName(int hip) {
std::map<int,QString>::const_iterator it(commonNamesMapI18n.find(hip));
if (it!=commonNamesMapI18n.end()) return it->second;
return "";
} }
QString StarMgr::getSciName(int hip) { QString StarMgr::getSciName(int hip)
std::map<int,QString>::const_iterator it(sciNamesMapI18n.find(hip)); {
if (it!=sciNamesMapI18n.end()) return it->second; std::map<int,QString>::const_iterator it(sciNamesMapI18n.find(hip));
return ""; if (it!=sciNamesMapI18n.end())
return it->second;
return QString();
} }
void StarMgr::init() void StarMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
loadStarSettings(); loadStarSettings();
loadData(); loadData();
double fontSize = 12; double fontSize = 12;
starFont = &StelApp::getInstance().getFontManager().getStandardFont( StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize); starFont = &StelApp::getInstance().getFontManager().getStandardFont( StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize);
setFlagStars(conf->value("astro/flag_stars", true).toBool()); setFlagStars(conf->value("astro/flag_stars", true).toBool());
setFlagLabels(conf->value("astro/flag_star_name",true).toBool()); setFlagLabels(conf->value("astro/flag_star_name",true).toBool());
setLabelsAmount(conf->value("stars/labels_amount",3).toDouble()); setLabelsAmount(conf->value("stars/labels_amount",3).toDouble());
StelApp::getInstance().getStelObjectMgr().registerStelObjectMgr(this ); objectMgr->registerStelObjectMgr(this);
StelApp::getInstance().getTextureManager().setDefaultParams(); StelApp::getInstance().getTextureManager().setDefaultParams();
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR); StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png"); // Load pointer texture texPointer = StelApp::getInstance().getTextureManager().createTextur e("pointeur2.png"); // Load pointer texture
StelApp::getInstance().getCore()->getGeodesicGrid(maxGeodesicGridLev el)->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this); StelApp::getInstance().getCore()->getGeodesicGrid(maxGeodesicGridLev el)->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this);
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();it++) for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();it++)
{ {
it->second->scaleAxis(); it->second->scaleAxis();
} }
} }
void StarMgr::drawPointer(const StelProjectorP& prj, const StelNavigator * nav) void StarMgr::drawPointer(const StelProjectorP& prj, const StelNavigator * nav)
{ {
const QList<StelObjectP> newSelected = StelApp::getInstance().getSte lObjectMgr().getSelectedObject("Star"); const QList<StelObjectP> newSelected = objectMgr->getSelectedObject( "Star");
if (!newSelected.empty()) if (!newSelected.empty())
{ {
const StelObjectP obj = newSelected[0]; const StelObjectP obj = newSelected[0];
Vec3d pos=obj->getJ2000EquatorialPos(nav); Vec3d pos=obj->getJ2000EquatorialPos(nav);
Vec3d screenpos; Vec3d screenpos;
// Compute 2D pos and return if outside screen // Compute 2D pos and return if outside screen
if (!prj->project(pos, screenpos)) if (!prj->project(pos, screenpos))
return; return;
StelPainter sPainter(prj); StelPainter sPainter(prj);
skipping to change at line 361 skipping to change at line 363
<< ("stars/default/" + cat_hip_cids_file_ name) << ("stars/default/" + cat_hip_cids_file_ name)
<< ": " << e.what(); << ": " << e.what();
} }
} }
lastMaxSearchLevel = maxGeodesicGridLevel; lastMaxSearchLevel = maxGeodesicGridLevel;
qDebug() << "Finished loading star catalogue data, max_geodesic_leve l: " << maxGeodesicGridLevel; qDebug() << "Finished loading star catalogue data, max_geodesic_leve l: " << maxGeodesicGridLevel;
} }
// Load common names from file // Load common names from file
int StarMgr::loadCommonNames(const QString& commonNameFile) { int StarMgr::loadCommonNames(const QString& commonNameFile)
{
commonNamesMap.clear(); commonNamesMap.clear();
commonNamesMapI18n.clear(); commonNamesMapI18n.clear();
commonNamesIndex.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;
skipping to change at line 518 skipping to change at line 521
sciNamesIndexI18n[sci_name_i18n_cap] = hip; sciNamesIndexI18n[sci_name_i18n_cap] = hip;
readOk++; readOk++;
} }
} }
snFile.close(); 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()); for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArr
it!=zoneArrays.end();it++) { ays.end();++it)
const float mag_min = 0.001f*it->second->mag_min; {
float rcmag[2]; const float mag_min = 0.001f*it->second->mag_min;
if (StelApp::getInstance().getCore()->getSkyDrawer()->computeRCMag(mag_ float rcmag[2];
min,rcmag)==false) if (StelApp::getInstance().getCore()->getSkyDrawer()->comput
break; eRCMag(mag_min,rcmag)==false)
rval = it->first; break;
} rval = it->first;
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();
currentJDay = nav->getJDay(); // If stars are turned off don't waste time below
// projecting all stars just to draw disembodied labels
// If stars are turned off don't waste time below if (!starsFader.getInterstate())
// projecting all stars just to draw disembodied labels
if (!starsFader.getInterstate())
return; return;
int maxSearchLevel = getMaxSearchLevel(); int maxSearchLevel = getMaxSearchLevel();
const GeodesicSearchResult* geodesic_search_result = core->getGeodes icGrid(maxSearchLevel)->search(prj->unprojectViewport(),maxSearchLevel); const GeodesicSearchResult* geodesic_search_result = core->getGeodes icGrid(maxSearchLevel)->search(prj->getViewportConvexPolygon(),maxSearchLev el);
// Set temporary static variable for optimization // Set temporary static variable for optimization
const float names_brightness = labelsFader.getInterstate() * starsFader const float names_brightness = labelsFader.getInterstate() * starsFa
.getInterstate(); der.getInterstate();
// Prepare openGL for drawing many stars // Prepare openGL for drawing many stars
StelPainter* sPainter = new StelPainter(prj); StelPainter* sPainter = new StelPainter(prj);
skyDrawer->preDrawPointSource(sPainter); skyDrawer->preDrawPointSource(sPainter);
Q_ASSERT(sPainter); Q_ASSERT(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!=zoneArray s.end();++it) for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneAr rays.end();++it)
{ {
const float mag_min = 0.001f*it->second->mag_min; const float mag_min = 0.001f*it->second->mag_min;
const float k = (0.001f*it->second->mag_range)/it->second->m ag_steps; const float k = (0.001f*it->second->mag_range)/it->second->m ag_steps;
for (int i=it->second->mag_steps-1;i>=0;--i) for (int i=it->second->mag_steps-1;i>=0;--i)
{ {
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;
} }
skipping to change at line 591 skipping to change at line 592
if (labelsFader.getInterstate()>0.f) if (labelsFader.getInterstate()>0.f)
{ {
// Adapt magnitude limit of the stars labels accordi ng to FOV and labelsAmount // Adapt magnitude limit of the stars labels accordi ng to FOV and labelsAmount
float maxMag = (skyDrawer->getLimitMagnitude()-6.5)* 0.7+(labelsAmount*1.2f)-2.f; float maxMag = (skyDrawer->getLimitMagnitude()-6.5)* 0.7+(labelsAmount*1.2f)-2.f;
int x = (int)((maxMag-mag_min)/k); int x = (int)((maxMag-mag_min)/k);
if (x > 0) if (x > 0)
maxMagStarName = x; maxMagStarName = x;
} }
int zone; int zone;
for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;) for (GeodesicSearchInsideIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;)
it->second->draw(zone, true, rcmag_table, prj, maxMa gStarName, names_brightness, starFont); it->second->draw(zone, true, rcmag_table, core, maxM agStarName, names_brightness, starFont);
for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;) for (GeodesicSearchBorderIterator it1(*geodesic_search_resul t,it->first);(zone = it1.next()) >= 0;)
it->second->draw(zone, false, rcmag_table, prj, maxM it->second->draw(zone, false, rcmag_table, core, max
agStarName,names_brightness, starFont); MagStarName,names_brightness, starFont);
} }
exit_loop: exit_loop:
// Finish drawing many stars // Finish drawing many stars
skyDrawer->postDrawPointSource(); skyDrawer->postDrawPointSource();
delete sPainter; delete sPainter;
sPainter = NULL; sPainter = NULL;
drawPointer(prj, nav); if (objectMgr->getFlagSelectedObjectPointer())
} drawPointer(prj, nav);
// Look for a star by XYZ coords
StelObjectP StarMgr::search(Vec3d pos) const {
Q_ASSERT(0);
pos.normalize();
QList<StelObjectP > v = searchAround(pos,
0.8, // just an arbitrary number
NULL);
StelObjectP nearest;
double cos_angle_nearest = -10.0;
for (QList<StelObjectP >::const_iterator it(v.begin());it!=v.end();it++)
{
const double c = (*it)->getJ2000EquatorialPos(0)*pos;
if (c > cos_angle_nearest) {
cos_angle_nearest = c;
nearest = *it;
}
}
return nearest;
} }
// 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, QList<StelObjectP > StarMgr::searchAround(const Vec3d& vv, double limFov, c
double limFov, // degrees onst StelCore* core) const
{
const StelCore* core) const { QList<StelObjectP > result;
QList<StelObjectP > result; if (!getFlagStars())
if (!getFlagStars()) return result;
return result;
Vec3d v(vv);
Vec3d v(vv); v.normalize();
v.normalize();
// find any vectors h0 and h1 (length 1), so that h0*v=h1*v=h0*h1=0 // find any vectors h0 and h1 (length 1), so that h0*v=h1*v=h0*h1=0
int i; int i;
{ {
const double a0 = fabs(v[0]); const double a0 = fabs(v[0]);
const double a1 = fabs(v[1]); const double a1 = fabs(v[1]);
const double a2 = fabs(v[2]); const double a2 = fabs(v[2]);
if (a0 <= a1) { if (a0 <= a1)
if (a0 <= a2) i = 0; {
else i = 2; if (a0 <= a2) i = 0;
} else { else i = 2;
if (a1 <= a2) i = 1; } else
else i = 2; {
} if (a1 <= a2) i = 1;
} else i = 2;
Vec3d h0(0.0,0.0,0.0); }
h0[i] = 1.0; }
Vec3d h1 = h0 ^ v; Vec3d h0(0.0,0.0,0.0);
h1.normalize(); h0[i] = 1.0;
h0 = h1 ^ v; Vec3d h1 = h0 ^ v;
h0.normalize(); h1.normalize();
// now we have h0*v=h1*v=h0*h1=0. h0 = h1 ^ v;
// construct a region with 4 corners e0,e1,e2,e3 inside which h0.normalize();
// all desired stars must be:
double f = 1.4142136 * tan(limFov * M_PI/180.0); // Now we have h0*v=h1*v=h0*h1=0.
h0 *= f; // Construct a region with 4 corners e0,e1,e2,e3 inside which all de
h1 *= f; sired stars must be:
Vec3d e0 = v + h0; double f = 1.4142136 * tan(limFov * M_PI/180.0);
Vec3d e1 = v + h1; h0 *= f;
Vec3d e2 = v - h0; h1 *= f;
Vec3d e3 = v - h1; Vec3d e0 = v + h0;
f = 1.0/e0.length(); Vec3d e1 = v + h1;
e0 *= f; Vec3d e2 = v - h0;
e1 *= f; Vec3d e3 = v - h1;
e2 *= f; f = 1.0/e0.length();
e3 *= f; e0 *= f;
// search the triangles e1 *= f;
const GeodesicSearchResult* geodesic_search_result = core->getGeodesicGri e2 *= f;
d(lastMaxSearchLevel)->search(e3,e2,e1,e0,lastMaxSearchLevel); e3 *= f;
// iterate over the stars inside the triangles: // Search the triangles
f = cos(limFov * M_PI/180.); const GeodesicSearchResult* geodesic_search_result = core->getGeodes
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); icGrid(lastMaxSearchLevel)->search(e3,e2,e1,e0,lastMaxSearchLevel);
it!=zoneArrays.end();it++) {
//qDebug() << "search inside(" << it->first << "):"; // Iterate over the stars inside the triangles
int zone; f = cos(limFov * M_PI/180.);
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,it->first for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArr
); ays.end();it++)
(zone = it1.next()) >= 0;) { {
it->second->searchAround(zone,v,f,result); //qDebug() << "search inside(" << it->first << "):";
//qDebug() << " " << zone; int zone;
} for (GeodesicSearchInsideIterator it1(*geodesic_search_resul
//qDebug() << endl << "search border(" << it->first << "):"; t,it->first);(zone = it1.next()) >= 0;)
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,it->first {
); it->second->searchAround(core->getNavigator(), zone,
(zone = it1.next()) >= 0;) { v,f,result);
it->second->searchAround(zone,v,f,result); //qDebug() << " " << zone;
//qDebug() << " " << zone; }
} //qDebug() << endl << "search border(" << it->first << "):";
} for (GeodesicSearchBorderIterator it1(*geodesic_search_resul
return result; t,it->first); (zone = it1.next()) >= 0;)
{
it->second->searchAround(core->getNavigator(), zone,
v,f,result);
//qDebug() << " " << zone;
}
}
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().getSkyTransl {
ator(); StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyT
commonNamesMapI18n.clear(); ranslator();
commonNamesIndexI18n.clear(); commonNamesMapI18n.clear();
for (std::map<int,QString>::iterator it(commonNamesMap.begin()); commonNamesIndexI18n.clear();
it!=commonNamesMap.end();it++) { for (std::map<int,QString>::iterator it(commonNamesMap.begin());it!=
const int i = it->first; commonNamesMap.end();it++)
const QString t(trans.qtranslate(it->second));
commonNamesMapI18n[i] = t;
commonNamesIndexI18n[t.toUpper()] = i;
}
starFont = &StelApp::getInstance().getFontManager().getStandardFont(trans
.getTrueLocaleName(), fontSize);
}
StelObjectP StarMgr::search(const QString& name) const
{
// Use this QRegExp to extract the catalogue number and prefix
QRegExp catRx("^(HP|HD|SAO)\\s*(\\d+)$");
QString n = name.toUpper();
n.replace('_', ' ');
if (catRx.exactMatch(n))
{
QString cat = catRx.capturedTexts().at(1);
if (cat=="HP")
return searchHP(catRx.capturedTexts().at(2).toInt())
;
else // currently we only support searching by string for HP
catalogue
return NULL;
}
else
{ {
// Maybe the HP prefix is missing and we just have a number. const int i = it->first;
.. const QString t(trans.qtranslate(it->second));
bool ok; commonNamesMapI18n[i] = t;
int num = n.toInt(&ok); commonNamesIndexI18n[t.toUpper()] = i;
if (!ok)
return NULL;
else
return searchHP(num);
} }
starFont = &StelApp::getInstance().getFontManager().getStandardFont( trans.getTrueLocaleName(), fontSize);
} }
// Search the star by HP number // Search the star by HP number
StelObjectP StarMgr::searchHP(int _HP) const { StelObjectP StarMgr::searchHP(int hp) const
if (0 < _HP && _HP <= NR_OF_HIP) { {
const Star1 *const s = hipIndex[_HP].s; if (0 < hp && hp <= NR_OF_HIP)
if (s) { {
const SpecialZoneArray<Star1> *const a = hipIndex[_HP].a; const Star1 *const s = hipIndex[hp].s;
const SpecialZoneData<Star1> *const z = hipIndex[_HP].z; if (s)
return s->createStelObject(a,z); {
} const SpecialZoneArray<Star1> *const a = hipIndex[hp
} ].a;
return StelObjectP(); const SpecialZoneData<Star1> *const z = hipIndex[hp]
.z;
return s->createStelObject(a,z);
}
}
return StelObjectP();
} }
StelObjectP StarMgr::searchByNameI18n(const QString& nameI18n) const StelObjectP StarMgr::searchByNameI18n(const QString& nameI18n) const
{ {
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*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(1).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)); std::map<QString,int>::const_iterator it(commonNamesIndexI18n.find(o bjw));
if (it!=commonNamesIndexI18n.end()) if (it!=commonNamesIndexI18n.end())
{ {
return searchHP(it->second); return searchHP(it->second);
} }
// Search by sci name // Search by sci name
skipping to change at line 782 skipping to change at line 745
} }
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\\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(1).toInt()); return searchHP(rx.capturedTexts().at(2).toInt());
} }
/* Should we try this anyway?
// Search by common name
std::map<QString,int>::const_iterator it(commonNamesIndexI18n.find(o
bjw));
if (it!=commonNamesIndexI18n.end()) {
return searchHP(it->second);
} */
// Search by sci name // Search by sci name
std::map<QString,int>::const_iterator it = sciNamesIndexI18n.find(ob jw); std::map<QString,int>::const_iterator it = sciNamesIndexI18n.find(ob jw);
if (it!=sciNamesIndexI18n.end()) { if (it!=sciNamesIndexI18n.end())
{
return searchHP(it->second); return searchHP(it->second);
} }
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 for (std::map<QString,int>::const_iterator it(commonNamesIndexI18n.l
ower_bound(objw)); ower_bound(objw)); it!=commonNamesIndexI18n.end(); ++it)
it!=commonNamesIndexI18n.end(); {
it++) if (it->first.startsWith(objw))
{ {
const QString constw(it->first.mid(0,objw.size())); if (maxNbItem==0)
if (constw==objw) { break;
if (maxNbItem==0) break;
result << getCommonName(it->second); result << getCommonName(it->second);
maxNbItem--; --maxNbItem;
} }
else else
break; break;
} }
// Search for sci names // Search for sci names
for (std::map<QString,int>::const_iterator it(sciNamesIndexI18n.lowe QString bayerPattern = objw;
r_bound(objw)); QRegExp bayerRegEx(bayerPattern);
it!=sciNamesIndexI18n.end();
it++) // if the first character is a Greek letter, check if there's an ind
{ ex
const QString constw(it->first.mid(0,objw.size())); // after it, such as "alpha1 Cen".
if (constw==objw) { if (objw.at(0).unicode() >= 0x0391 && objw.at(0).unicode() <= 0x03A9
if (maxNbItem==0) break; )
bayerRegEx.setPattern(bayerPattern.insert(1,"\\d?"));
for (std::map<QString,int>::const_iterator it(sciNamesIndexI18n.lowe
r_bound(objw)); it!=sciNamesIndexI18n.end(); ++it)
{
if (it->first.indexOf(bayerRegEx)==0)
{
if (maxNbItem==0)
break;
result << getSciName(it->second); result << getSciName(it->second);
maxNbItem--; --maxNbItem;
} }
else else if (it->first.at(0) != objw.at(0))
break; break;
} }
// Add exact Hp catalogue numbers // Add exact Hp catalogue numbers
QRegExp hpRx("^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(1).toInt(&ok); int hpNum = hpRx.capturedTexts().at(2).toInt(&ok);
if (ok) if (ok)
{ {
StelObjectP s = searchHP(hpNum); StelObjectP s = searchHP(hpNum);
if (s && maxNbItem>0) if (s && maxNbItem>0)
{ {
result << QString("HP%1").arg(hpNum); result << QString("HIP%1").arg(hpNum);
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(double newFontSize)
{ {
fontSize = newFontSize; fontSize = newFontSize;
starFont = &StelApp::getInstance().getFontManager().getStandardFont( starFont = &StelApp::getInstance().getFontManager().getStandardFont(
StelApp::getInstance().getLocaleMgr().getSkyLanguage(),fontS ize); StelApp::getInstance().getLocaleMgr().getSkyLanguage(),fontS ize);
} }
void StarMgr::updateSkyCulture() void StarMgr::updateSkyCulture(const QString& skyCultureDir)
{ {
QString skyCultureDir = StelApp::getInstance().getSkyCultureMgr().ge
tCurrentSkyCultureID();
// Load culture star names in english // Load culture star names in english
try try
{ {
loadCommonNames(StelApp::getInstance().getFileMgr().findFile ("skycultures/" + skyCultureDir + "/star_names.fab")); loadCommonNames(StelApp::getInstance().getFileMgr().findFile ("skycultures/" + skyCultureDir + "/star_names.fab"));
} }
catch(std::runtime_error& e) catch(std::runtime_error& e)
{ {
qWarning() << "WARNING: could not load star_names.fab for sk y culture " qWarning() << "WARNING: could not load star_names.fab for sk y culture "
<< skyCultureDir << ": " << e.what(); << skyCultureDir << ": " << e.what();
} }
 End of changes. 39 change blocks. 
242 lines changed or deleted 207 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/