65
65
using namespace BigStarCatalogExtension;
67
static StringArray spectral_array;
68
static StringArray component_array;
70
QString StarMgr::convertToSpectralType(int index) {
71
if (index < 0 || index >= spectral_array.getSize()) {
72
qDebug() << "convertToSpectralType: bad index: " << index
73
<< ", max: " << spectral_array.getSize();
76
return spectral_array[index];
79
QString StarMgr::convertToComponentIds(int index) {
80
if (index < 0 || index >= component_array.getSize()) {
81
qDebug() << "convertToComponentIds: bad index: " << index
82
<< ", max: " << component_array.getSize();
85
return component_array[index];
67
static QStringList spectral_array;
68
static QStringList component_array;
71
bool StarMgr::flagSciNames = true;
72
std::map<int,QString> StarMgr::commonNamesMap;
73
std::map<int,QString> StarMgr::commonNamesMapI18n;
74
std::map<QString,int> StarMgr::commonNamesIndex;
75
std::map<QString,int> StarMgr::commonNamesIndexI18n;
76
std::map<int,QString> StarMgr::sciNamesMapI18n;
77
std::map<QString,int> StarMgr::sciNamesIndexI18n;
79
QStringList initStringListFromFile(const QString& file_name)
83
if (f.open(QIODevice::ReadOnly | QIODevice::Text))
87
QString s = QString::fromUtf8(f.readLine());
96
QString StarMgr::convertToSpectralType(int index)
98
if (index < 0 || index >= spectral_array.size())
100
qDebug() << "convertToSpectralType: bad index: " << index << ", max: " << spectral_array.size();
103
return spectral_array.at(index);
106
QString StarMgr::convertToComponentIds(int index)
108
if (index < 0 || index >= component_array.size())
110
qDebug() << "convertToComponentIds: bad index: " << index << ", max: " << component_array.size();
113
return component_array.at(index);
92
117
void StarMgr::initTriangle(int lev,int index,
126
StarMgr::~StarMgr(void) {
127
ZoneArrayMap::iterator it(zoneArrays.end());
128
while (it!=zoneArrays.begin()) {
134
if (hipIndex) delete[] hipIndex;
137
bool StarMgr::flagSciNames = true;
138
double StarMgr::currentJDay = 0;
139
std::map<int,QString> StarMgr::commonNamesMap;
140
std::map<int,QString> StarMgr::commonNamesMapI18n;
141
std::map<QString,int> StarMgr::commonNamesIndex;
142
std::map<QString,int> StarMgr::commonNamesIndexI18n;
144
std::map<int,QString> StarMgr::sciNamesMapI18n;
145
std::map<QString,int> StarMgr::sciNamesIndexI18n;
147
QString StarMgr::getCommonName(int hip) {
148
std::map<int,QString>::const_iterator it(commonNamesMapI18n.find(hip));
149
if (it!=commonNamesMapI18n.end()) return it->second;
153
QString StarMgr::getSciName(int hip) {
154
std::map<int,QString>::const_iterator it(sciNamesMapI18n.find(hip));
155
if (it!=sciNamesMapI18n.end()) return it->second;
162
void StarMgr::init() {
150
StarMgr::~StarMgr(void)
154
ZoneArrayMap::iterator it(zoneArrays.end());
155
while (it!=zoneArrays.begin())
166
QString StarMgr::getCommonName(int hip)
168
std::map<int,QString>::const_iterator it(commonNamesMapI18n.find(hip));
169
if (it!=commonNamesMapI18n.end())
174
QString StarMgr::getSciName(int hip)
176
std::map<int,QString>::const_iterator it(sciNamesMapI18n.find(hip));
177
if (it!=sciNamesMapI18n.end())
163
184
QSettings* conf = StelApp::getInstance().getSettings();
167
189
double fontSize = 12;
168
190
starFont = &StelApp::getInstance().getFontManager().getStandardFont(StelApp::getInstance().getLocaleMgr().getSkyLanguage(), fontSize);
171
193
setFlagLabels(conf->value("astro/flag_star_name",true).toBool());
172
194
setLabelsAmount(conf->value("stars/labels_amount",3).toDouble());
174
StelApp::getInstance().getStelObjectMgr().registerStelObjectMgr(this);
196
objectMgr->registerStelObjectMgr(this);
176
198
StelApp::getInstance().getTextureManager().setDefaultParams();
199
StelApp::getInstance().getTextureManager().setMinFilter(GL_LINEAR);
177
200
texPointer = StelApp::getInstance().getTextureManager().createTexture("pointeur2.png"); // Load pointer texture
180
void StarMgr::setGrid(GeodesicGrid* geodesicGrid) {
181
geodesicGrid->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this);
182
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());
183
it!=zoneArrays.end();it++) {
184
it->second->scaleAxis();
189
void StarMgr::drawPointer(const Projector* prj, const Navigator * nav)
202
StelApp::getInstance().getCore()->getGeodesicGrid(maxGeodesicGridLevel)->visitTriangles(maxGeodesicGridLevel,initTriangleFunc,this);
203
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneArrays.end();it++)
205
it->second->scaleAxis();
210
void StarMgr::drawPointer(const StelProjectorP& prj, const StelNavigator * nav)
191
const QList<StelObjectP> newSelected = StelApp::getInstance().getStelObjectMgr().getSelectedObject("Star");
212
const QList<StelObjectP> newSelected = objectMgr->getSelectedObject("Star");
192
213
if (!newSelected.empty())
194
215
const StelObjectP obj = newSelected[0];
195
Vec3d pos=obj->getObsJ2000Pos(nav);
216
Vec3d pos=obj->getJ2000EquatorialPos(nav);
197
218
// Compute 2D pos and return if outside screen
198
if (!prj->project(pos, screenpos)) return;
219
if (!prj->project(pos, screenpos))
222
StelPainter sPainter(prj);
200
223
glColor3fv(obj->getInfoColor());
201
224
float diameter = 26.f;
202
225
texPointer->bind();
203
226
glEnable(GL_TEXTURE_2D);
204
227
glEnable(GL_BLEND);
205
228
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
206
prj->drawSprite2dMode(screenpos[0], screenpos[1], diameter, StelApp::getInstance().getTotalRunTime()*40.);
229
sPainter.drawSprite2dMode(screenpos[0], screenpos[1], diameter, StelApp::getInstance().getTotalRunTime()*40.);
217
240
setLabelColor(StelUtils::strToVec3f(conf->value(section+"/star_label_color", defaultColor).toString()));
243
void StarMgr::loadStarSettings()
248
iniFile = StelApp::getInstance().getFileMgr().findFile("stars/default/stars.ini");
250
catch (std::runtime_error& e)
252
qWarning() << "ERROR - could not find stars/default/stars.ini : " << e.what() << iniFile;
256
starSettings = new QSettings(iniFile, StelIniFormat);
257
if (starSettings->status() != QSettings::NoError)
259
qWarning() << "ERROR while parsing " << iniFile;
262
starSettings->beginGroup("stars");
220
265
/***************************************************************************
221
266
Load star catalogue data from files.
222
267
If a file is not found, it will be skipped.
223
268
***************************************************************************/
224
269
void StarMgr::loadData()
226
LoadingBar& lb = *StelApp::getInstance().getLoadingBar();
271
StelLoadingBar& lb = *StelApp::getInstance().getStelLoadingBar();
228
273
// Please do not init twice:
229
assert(maxGeodesicGridLevel < 0);
274
Q_ASSERT(maxGeodesicGridLevel < 0);
231
276
qDebug() << "Loading star data ...";
236
iniFile = StelApp::getInstance().getFileMgr().findFile("stars/default/stars.ini");
238
catch (std::runtime_error& e)
240
qWarning() << "ERROR - could not find stars/default/stars.ini : " << e.what() << iniFile;
244
QSettings conf(iniFile, StelIniFormat);
245
if (conf.status() != QSettings::NoError)
247
qWarning() << "ERROR while parsing " << iniFile;
251
for (int i=0; i<100; i++)
253
//sprintf(key_name,"cat_file_name_%02d",i);
254
QString keyName = QString("cat_file_name_%1").arg(i,2,10,QChar('0'));
255
const QString cat_file_name = conf.value(QString("stars/")+keyName,"").toString();
256
if (!cat_file_name.isEmpty()) {
257
lb.SetMessage(q_("Loading catalog %1").arg(cat_file_name));
258
ZoneArray *const z = ZoneArray::create(*this,cat_file_name,lb);
261
if (maxGeodesicGridLevel < z->level)
263
maxGeodesicGridLevel = z->level;
265
ZoneArray *&pos(zoneArrays[z->level]);
268
qDebug() << cat_file_name << ", " << z->level << ": duplicate level";
278
qulonglong memoryUsed = 0;
279
const qulonglong maxMemory = StelApp::getInstance().getSettings()->value("stars/max_memory", 128).toULongLong() * 1024*1024;
281
QStringList cats = starSettings->childGroups();
282
QListIterator<QString> it(cats);
283
StelFileMgr& fileMgr = StelApp::getInstance().getFileMgr();
286
QString cat = it.next();
287
QString cat_file_name = starSettings->value(cat+"/path").toString();
288
QString cat_file_path = fileMgr.findFile("stars/default/"+cat_file_name);
290
lb.SetMessage(q_("Loading catalog %1 from file %2").arg(cat, cat_file_name));
291
memoryUsed += fileMgr.size(cat_file_path);
292
ZoneArray *const z = ZoneArray::create(cat_file_name, memoryUsed > maxMemory, lb);
295
if (maxGeodesicGridLevel < z->level)
297
maxGeodesicGridLevel = z->level;
299
ZoneArray *&pos(zoneArrays[z->level]);
302
qDebug() << cat_file_name << ", " << z->level << ": duplicate level";
492
525
int StarMgr::getMaxSearchLevel() const
495
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());
496
it!=zoneArrays.end();it++) {
497
const float mag_min = 0.001f*it->second->mag_min;
499
if (StelApp::getInstance().getCore()->getSkyDrawer()->computeRCMag(mag_min,rcmag)==false)
528
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArrays.end();++it)
530
const float mag_min = 0.001f*it->second->mag_min;
532
if (StelApp::getInstance().getCore()->getSkyDrawer()->computeRCMag(mag_min,rcmag)==false)
507
540
// Draw all the stars
508
541
void StarMgr::draw(StelCore* core)
510
Navigator* nav = core->getNavigation();
511
Projector* prj = core->getProjection();
512
SkyDrawer* skyDrawer = core->getSkyDrawer();
514
currentJDay = nav->getJDay();
543
StelNavigator* nav = core->getNavigator();
544
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
545
StelSkyDrawer* skyDrawer = core->getSkyDrawer();
516
// If stars are turned off don't waste time below
517
// projecting all stars just to draw disembodied labels
518
if (!starsFader.getInterstate())
547
// If stars are turned off don't waste time below
548
// projecting all stars just to draw disembodied labels
549
if (!starsFader.getInterstate())
521
552
int maxSearchLevel = getMaxSearchLevel();
522
const GeodesicSearchResult* geodesic_search_result = core->getGeodesicGrid()->search(prj->unprojectViewport(),maxSearchLevel);
553
const GeodesicSearchResult* geodesic_search_result = core->getGeodesicGrid(maxSearchLevel)->search(prj->getViewportConvexPolygon(),maxSearchLevel);
524
// Set temporary static variable for optimization
525
const float names_brightness = labelsFader.getInterstate() * starsFader.getInterstate();
527
prj->setCurrentFrame(Projector::FrameJ2000);
555
// Set temporary static variable for optimization
556
const float names_brightness = labelsFader.getInterstate() * starsFader.getInterstate();
529
558
// Prepare openGL for drawing many stars
530
skyDrawer->preDrawPointSource();
559
StelPainter* sPainter = new StelPainter(prj);
560
skyDrawer->preDrawPointSource(sPainter);
532
// draw all the stars of all the selected zones
533
float rcmag_table[2*256];
563
// draw all the stars of all the selected zones
564
float rcmag_table[2*256];
535
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneArrays.end();it++)
566
for (ZoneArrayMap::const_iterator it(zoneArrays.begin()); it!=zoneArrays.end();++it)
537
568
const float mag_min = 0.001f*it->second->mag_min;
538
569
const float k = (0.001f*it->second->mag_range)/it->second->mag_steps;
539
for (int i=it->second->mag_steps-1;i>=0;i--)
570
for (int i=it->second->mag_steps-1;i>=0;--i)
541
572
const float mag = mag_min+k*i;
542
573
if (skyDrawer->computeRCMag(mag,rcmag_table + 2*i)==false)
567
598
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,it->first);(zone = it1.next()) >= 0;)
568
it->second->draw(zone, true, rcmag_table, prj, maxMagStarName, names_brightness, starFont);
599
it->second->draw(zone, true, rcmag_table, core, maxMagStarName, names_brightness, starFont);
569
600
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,it->first);(zone = it1.next()) >= 0;)
570
it->second->draw(zone, false, rcmag_table, prj, maxMagStarName,names_brightness, starFont);
601
it->second->draw(zone, false, rcmag_table, core, maxMagStarName,names_brightness, starFont);
573
604
// Finish drawing many stars
574
605
skyDrawer->postDrawPointSource();
576
drawPointer(prj, nav);
584
// Look for a star by XYZ coords
585
StelObjectP StarMgr::search(Vec3d pos) const {
588
QList<StelObjectP > v = searchAround(pos,
589
0.8, // just an arbitrary number
592
double cos_angle_nearest = -10.0;
593
for (QList<StelObjectP >::const_iterator it(v.begin());it!=v.end();it++) {
594
const double c = (*it)->getObsJ2000Pos(0)*pos;
595
if (c > cos_angle_nearest) {
596
cos_angle_nearest = c;
610
if (objectMgr->getFlagSelectedObjectPointer())
611
drawPointer(prj, nav);
603
615
// Return a stl vector containing the stars located
604
616
// inside the limFov circle around position v
605
QList<StelObjectP > StarMgr::searchAround(const Vec3d& vv,
606
double limFov, // degrees
607
const StelCore* core) const {
608
QList<StelObjectP > result;
614
// find any vectors h0 and h1 (length 1), so that h0*v=h1*v=h0*h1=0
617
const double a0 = fabs(v[0]);
618
const double a1 = fabs(v[1]);
619
const double a2 = fabs(v[2]);
628
Vec3d h0(0.0,0.0,0.0);
634
// now we have h0*v=h1*v=h0*h1=0.
635
// construct a region with 4 corners e0,e1,e2,e3 inside which
636
// all desired stars must be:
637
double f = 1.4142136 * tan(limFov * M_PI/180.0);
649
// search the triangles
650
const GeodesicSearchResult* geodesic_search_result = core->getGeodesicGrid()->search(e3,e2,e1,e0,lastMaxSearchLevel);
651
// iterate over the stars inside the triangles:
652
f = cos(limFov * M_PI/180.);
653
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());
654
it!=zoneArrays.end();it++) {
655
//qDebug() << "search inside(" << it->first << "):";
657
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,it->first);
658
(zone = it1.next()) >= 0;) {
659
it->second->searchAround(zone,v,f,result);
660
//qDebug() << " " << zone;
662
//qDebug() << endl << "search border(" << it->first << "):";
663
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,it->first);
664
(zone = it1.next()) >= 0;) {
665
it->second->searchAround(zone,v,f,result);
666
//qDebug() << " " << zone;
617
QList<StelObjectP > StarMgr::searchAround(const Vec3d& vv, double limFov, const StelCore* core) const
619
QList<StelObjectP > result;
626
// find any vectors h0 and h1 (length 1), so that h0*v=h1*v=h0*h1=0
629
const double a0 = fabs(v[0]);
630
const double a1 = fabs(v[1]);
631
const double a2 = fabs(v[2]);
642
Vec3d h0(0.0,0.0,0.0);
649
// Now we have h0*v=h1*v=h0*h1=0.
650
// Construct a region with 4 corners e0,e1,e2,e3 inside which all desired stars must be:
651
double f = 1.4142136 * tan(limFov * M_PI/180.0);
663
// Search the triangles
664
const GeodesicSearchResult* geodesic_search_result = core->getGeodesicGrid(lastMaxSearchLevel)->search(e3,e2,e1,e0,lastMaxSearchLevel);
666
// Iterate over the stars inside the triangles
667
f = cos(limFov * M_PI/180.);
668
for (ZoneArrayMap::const_iterator it(zoneArrays.begin());it!=zoneArrays.end();it++)
670
//qDebug() << "search inside(" << it->first << "):";
672
for (GeodesicSearchInsideIterator it1(*geodesic_search_result,it->first);(zone = it1.next()) >= 0;)
674
it->second->searchAround(core->getNavigator(), zone,v,f,result);
675
//qDebug() << " " << zone;
677
//qDebug() << endl << "search border(" << it->first << "):";
678
for (GeodesicSearchBorderIterator it1(*geodesic_search_result,it->first); (zone = it1.next()) >= 0;)
680
it->second->searchAround(core->getNavigator(), zone,v,f,result);
681
//qDebug() << " " << zone;
677
688
//! Update i18 names from english names according to passed translator.
678
689
//! The translation is done using gettext with translated strings defined in translations.h
679
void StarMgr::updateI18n() {
680
Translator trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
681
commonNamesMapI18n.clear();
682
commonNamesIndexI18n.clear();
683
for (std::map<int,QString>::iterator it(commonNamesMap.begin());
684
it!=commonNamesMap.end();it++) {
685
const int i = it->first;
686
const QString t(trans.qtranslate(it->second));
687
commonNamesMapI18n[i] = t;
688
commonNamesIndexI18n[t.toUpper()] = i;
690
starFont = &StelApp::getInstance().getFontManager().getStandardFont(trans.getTrueLocaleName(), fontSize);
690
void StarMgr::updateI18n()
692
StelTranslator trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
693
commonNamesMapI18n.clear();
694
commonNamesIndexI18n.clear();
695
for (std::map<int,QString>::iterator it(commonNamesMap.begin());it!=commonNamesMap.end();it++)
697
const int i = it->first;
698
const QString t(trans.qtranslate(it->second));
699
commonNamesMapI18n[i] = t;
700
commonNamesIndexI18n[t.toUpper()] = i;
702
starFont = &StelApp::getInstance().getFontManager().getStandardFont(trans.getTrueLocaleName(), fontSize);
694
StelObjectP StarMgr::search(const QString& name) const
696
// Use this QRegExp to extract the catalogue number and prefix
697
QRegExp catRx("^(HP|HD|SAO)\\s*(\\d+)$");
698
QString n = name.toUpper();
701
if (catRx.exactMatch(n))
703
QString cat = catRx.capturedTexts().at(1);
705
return searchHP(catRx.capturedTexts().at(2).toInt());
706
else // currently we only support searching by string for HP catalogue
711
// Maybe the HP prefix is missing and we just have a number...
713
int num = n.toInt(&ok);
717
return searchHP(num);
721
705
// Search the star by HP number
722
StelObjectP StarMgr::searchHP(int _HP) const {
723
if (0 < _HP && _HP <= NR_OF_HIP) {
724
const Star1 *const s = hipIndex[_HP].s;
726
const SpecialZoneArray<Star1> *const a = hipIndex[_HP].a;
727
const SpecialZoneData<Star1> *const z = hipIndex[_HP].z;
728
return s->createStelObject(a,z);
731
return StelObjectP();
706
StelObjectP StarMgr::searchHP(int hp) const
708
if (0 < hp && hp <= NR_OF_HIP)
710
const Star1 *const s = hipIndex[hp].s;
713
const SpecialZoneArray<Star1> *const a = hipIndex[hp].a;
714
const SpecialZoneData<Star1> *const z = hipIndex[hp].z;
715
return s->createStelObject(a,z);
718
return StelObjectP();
734
721
StelObjectP StarMgr::searchByNameI18n(const QString& nameI18n) const
799
778
QString objw = objPrefix.toUpper();
801
780
// Search for common names
802
for (std::map<QString,int>::const_iterator it(commonNamesIndexI18n.lower_bound(objw));
803
it!=commonNamesIndexI18n.end();
781
for (std::map<QString,int>::const_iterator it(commonNamesIndexI18n.lower_bound(objw)); it!=commonNamesIndexI18n.end(); ++it)
806
const QString constw(it->first.mid(0,objw.size()));
808
if (maxNbItem==0) break;
783
if (it->first.startsWith(objw))
809
787
result << getCommonName(it->second);
816
794
// Search for sci names
817
for (std::map<QString,int>::const_iterator it(sciNamesIndexI18n.lower_bound(objw));
818
it!=sciNamesIndexI18n.end();
795
QString bayerPattern = objw;
796
QRegExp bayerRegEx(bayerPattern);
798
// if the first character is a Greek letter, check if there's an index
799
// after it, such as "alpha1 Cen".
800
if (objw.at(0).unicode() >= 0x0391 && objw.at(0).unicode() <= 0x03A9)
801
bayerRegEx.setPattern(bayerPattern.insert(1,"\\d?"));
803
for (std::map<QString,int>::const_iterator it(sciNamesIndexI18n.lower_bound(objw)); it!=sciNamesIndexI18n.end(); ++it)
821
const QString constw(it->first.mid(0,objw.size()));
823
if (maxNbItem==0) break;
805
if (it->first.indexOf(bayerRegEx)==0)
824
809
result << getSciName(it->second);
812
else if (it->first.at(0) != objw.at(0))
816
// Add exact Hp catalogue numbers
817
QRegExp hpRx("^(HIP|HP)\\s*(\\d+)\\s*$");
818
hpRx.setCaseSensitivity(Qt::CaseInsensitive);
819
if (hpRx.exactMatch(objw))
822
int hpNum = hpRx.capturedTexts().at(2).toInt(&ok);
825
StelObjectP s = searchHP(hpNum);
826
if (s && maxNbItem>0)
828
result << QString("HIP%1").arg(hpNum);