Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Gaia ID in other functionalities #4064

Merged
merged 8 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/core/modules/Asterism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "StelApp.hpp"
#include "StelCore.hpp"
#include "StelUtils.hpp"
#include "ZoneArray.hpp"

#include <algorithm>
#include <QString>
Expand All @@ -51,86 +52,94 @@
delete[] asterism;
asterism = Q_NULLPTR;
}

bool Asterism::read(const QString& record, StarMgr *starMgr)
{
abbreviation.clear();
numberOfSegments = 0;
typeOfAsterism = 1;
flagAsterism = true;

QString buf(record);
QTextStream istr(&buf, QIODevice::ReadOnly);
// We allow mixed-case abbreviations now that they can be displayed on screen. We then need toUpper() in comparisons.
istr >> abbreviation >> typeOfAsterism >> numberOfSegments;
if (istr.status()!=QTextStream::Ok)
return false;

StelCore *core = StelApp::getInstance().getCore();
asterism = new StelObjectP[numberOfSegments*2];
for (unsigned int i=0;i<numberOfSegments*2;++i)
{
switch (typeOfAsterism)
{
case 0: // Ray helpers
case 1: // A big asterism with lines by HIP stars
{
unsigned int HP = 0;
StarId HP = 0;
istr >> HP;
if(HP == 0)
{
return false;
}
asterism[i]=starMgr->searchHP(static_cast<int>(HP));
if (HP <= NR_OF_HIP)
{
asterism[i]=starMgr->searchHP(static_cast<int>(HP));
}
else
{
asterism[i]=starMgr->searchGaia(HP);
}

if (!asterism[i])
{
qWarning() << "Error in asterism" << abbreviation << "- can't find star HIP" << HP;
return false;
}
break;
}
case 2: // A small asterism with lines by J2000.0 coordinates
{
double RA, DE;
Vec3d coords;

istr >> RA >> DE;
StelUtils::spheToRect(RA*M_PI/12., DE*M_PI/180., coords);
QList<StelObjectP> stars = starMgr->searchAround(coords, 0.1, core);
StelObjectP s = Q_NULLPTR;
double d = 10.;
for (const auto& p : stars)
{
double a = coords.angle(p->getJ2000EquatorialPos(core));
if (a<d)
{
d = a;
s = p;
}
}
asterism[i] = s;
if (!asterism[i])
{
qWarning() << "Error in asterism" << abbreviation << "- can't find star with coordinates" << RA << "/" << DE;
return false;
}
break;
}
}
}

if (typeOfAsterism>0)
{
XYZname.set(0.,0.,0.);
for(unsigned int j=0;j<numberOfSegments*2;++j)
XYZname+= asterism[j]->getJ2000EquatorialPos(core);
XYZname.normalize();
}
else
flagAsterism = false;

return true;
}

Check notice on line 142 in src/core/modules/Asterism.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/core/modules/Asterism.cpp#L55-L142

Complex Method

void Asterism::drawOptim(StelPainter& sPainter, const StelCore* core, const SphericalCap& viewportHalfspace) const
{
Expand Down
13 changes: 11 additions & 2 deletions src/core/modules/Constellation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "StelCore.hpp"
#include "StelUtils.hpp"
#include "ConstellationMgr.hpp"
#include "ZoneArray.hpp"

#include <algorithm>
#include <QString>
Expand Down Expand Up @@ -62,7 +63,7 @@ Constellation::~Constellation()

bool Constellation::read(const QString& record, StarMgr *starMgr)
{
unsigned int HP;
StarId HP;

abbreviation.clear();
numberOfSegments = 0;
Expand All @@ -84,7 +85,15 @@ bool Constellation::read(const QString& record, StarMgr *starMgr)
return false;
}

constellation[i]=starMgr->searchHP(static_cast<int>(HP));
if (HP <= NR_OF_HIP)
{
constellation[i]=starMgr->searchHP(static_cast<int>(HP));
}
else
{
constellation[i]=starMgr->searchGaia(HP);
}

if (!constellation[i])
{
qWarning() << "Error in Constellation " << abbreviation << ": can't find star HIP" << HP;
Expand Down
87 changes: 47 additions & 40 deletions src/core/modules/Star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,61 +29,68 @@ const QString STAR_TYPE = QStringLiteral("Star");

QString Star1::getNameI18n(void) const
{
QStringList starNames;
StarId star_id;
if (getHip())
{
QStringList starNames;
starNames << StarMgr::getCommonName(getHip()) << getDesignation();
starNames.removeAll(QString(""));
if (starNames.count()>0)
return starNames.first();
else
return QString();
star_id = getHip();
}
return QString();
else
{
star_id = getGaia();
}
starNames << StarMgr::getCommonName(star_id) << getDesignation();
starNames.removeAll(QString(""));
if (starNames.count()>0)
return starNames.first();
else
return QString();
}

QString Star1::getScreenNameI18n(void) const
{
QStringList starNames;
StarId star_id;
if (getHip())
star_id = getHip();
else
star_id = getGaia();
if (!StarMgr::getDesignationUsage())
starNames << StarMgr::getCommonName(star_id);
if (StarMgr::getFlagSciNames()) // The scientific designations can be used for western sky cultures only
{
QStringList starNames;
if (!StarMgr::getDesignationUsage())
starNames << StarMgr::getCommonName(getHip());
if (StarMgr::getFlagSciNames()) // The scientific designations can be used for western sky cultures only
{
starNames << StarMgr::getSciName(getHip()).split(" - ");
if (StarMgr::getFlagDblStarsDesignation()) // append the traditional designations of double stars
starNames << StarMgr::getSciExtraName(getHip()).split(" - ");
if (StarMgr::getFlagVarStarsDesignation()) // append the designations of variable stars (from GCVS)
starNames << StarMgr::getGcvsName(getHip());
if (StarMgr::getFlagHIPDesignation()) // append the HIP numbers of stars
starNames << QString("HIP %1").arg(getHip());
}
starNames.removeAll(QString(""));
if (starNames.count()>0)
return starNames.first();
else
return QString();
starNames << StarMgr::getSciName(star_id).split(" - ");
if (StarMgr::getFlagDblStarsDesignation()) // append the traditional designations of double stars
starNames << StarMgr::getSciExtraName(star_id).split(" - ");
if (StarMgr::getFlagVarStarsDesignation()) // append the designations of variable stars (from GCVS)
starNames << StarMgr::getGcvsName(star_id);
if (StarMgr::getFlagHIPDesignation()) // append the HIP numbers of stars
starNames << QString("HIP %1").arg(star_id);
}
return QString();
starNames.removeAll(QString(""));
if (starNames.count()>0)
return starNames.first();
else
return QString();
}

QString Star1::getDesignation() const
{
QStringList starNames;
StarId star_id;
if (getHip())
{
QStringList starNames;
starNames << StarMgr::getSciName(getHip()).split(" - ");
starNames << StarMgr::getSciExtraName(getHip()).split(" - ");
starNames << StarMgr::getGcvsName(getHip());
starNames << QString("HIP %1").arg(getHip());
starNames.removeAll(QString(""));
if (starNames.count()>0)
return starNames.first();
else
return QString();
}
return QString();
star_id = getHip();
else
star_id = getGaia();
starNames << StarMgr::getSciName(star_id).split(" - ");
starNames << StarMgr::getSciExtraName(star_id).split(" - ");
starNames << StarMgr::getGcvsName(star_id);
starNames << QString("HIP %1").arg(star_id);
starNames.removeAll(QString(""));
if (starNames.count()>0)
return starNames.first();
else
return QString();
}

int Star1::hasComponentID(void) const
Expand Down
15 changes: 8 additions & 7 deletions src/core/modules/Star.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "StelObjectType.hpp"
#include "StelUtils.hpp"
#include "StarMgr.hpp"
#include "ZoneData.hpp"
#include <QString>
#include <QtEndian>
Expand Down Expand Up @@ -92,7 +93,7 @@ struct Star
// VIP flag is for situation where it can bypass some check (e.g., magnitude display cutoff for Star1 in far
// past/future)
inline bool isVIP() const { return static_cast<const Derived *>(this)->isVIP(); }
inline int64_t getGaia() const { return static_cast<const Derived *>(this)->getGaia(); }
inline StarId getGaia() const { return static_cast<const Derived *>(this)->getGaia(); }
inline bool hasName() const { return static_cast<const Derived *>(this)->hasName(); }
inline QString getNameI18n() const { return static_cast<const Derived *>(this)->getNameI18n(); }
inline QString getScreenNameI18n() const { return static_cast<const Derived *>(this)->getScreenNameI18n(); }
Expand Down Expand Up @@ -126,7 +127,7 @@ struct Star
inline double getRV() const
{
return static_cast<const Derived *>(this)->getRV();
} // should return in km/s, 0 means no parallax error
} // should return in km/s, 0 means no radial velocity
inline bool getPreciseAstrometricFlag() const
{
return static_cast<const Derived *>(this)->getPreciseAstrometricFlag();
Expand Down Expand Up @@ -287,16 +288,16 @@ struct Star1 : public Star<Star1>
// no point of doing proper propagation if any of them is missing
return (getPlx() || getPlxErr()) && (getPlx() / getPlxErr() > 5) && (getDx0() || getDx1() || getDx2()) && getRV();
}
inline int getHip() const
inline StarId getHip() const
{
// Combine the 3 bytes into a 24-bit integer (little-endian)
quint32 combined_value = d.hip[0] | d.hip[1] << 8 | d.hip[2] << 16;
// Extract the 17-bit ID (shift right by 5 bits)
qint32 hip_id = combined_value >> 5;
quint64 hip_id = combined_value >> 5;
return hip_id;
}

inline int64_t getGaia() const { return d.gaia_id; }
inline StarId getGaia() const { return d.gaia_id; }
inline int getComponentIds() const
{
// Combine the 3 bytes into a 24-bit integer (little-endian)
Expand Down Expand Up @@ -345,7 +346,7 @@ struct Star2 : public Star<Star2>
return sqrt((getDx0() * cos(getX1()) * getDx0() * cos(getX1())) + (getDx1() * getDx1()));
}
StelObjectP createStelObject(const SpecialZoneArray<Star2> * a, const SpecialZoneData<Star2> * z) const;
int64_t getGaia() const { return d.gaia_id; }
StarId getGaia() const { return d.gaia_id; }
float getBV(void) const { return static_cast<float>(d.b_v) / 1000.f; }
QString getNameI18n(void) const { return QString(); }
QString getScreenNameI18n(void) const { return QString(); }
Expand Down Expand Up @@ -398,7 +399,7 @@ struct Star3 : public Star<Star3>
double getRV() const { return 0.; }
double getBV() const { return (0.025 * d.b_v) - 1.; } // in mag
double getMag() const { return d.vmag * 20 + 16000; } // in milli-mag
int64_t getGaia() const { return d.gaia_id; }
StarId getGaia() const { return d.gaia_id; }
QString getNameI18n() const { return QString(); }
QString getScreenNameI18n() const { return QString(); }
QString getDesignation() const { return QString(); }
Expand Down
Loading
Loading