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

Exoplanet plugin with QtChart #2447

Merged
merged 8 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion plugins/Exoplanets/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SET(Exoplanets_RES ../resources/Exoplanets.qrc)
QT5_ADD_RESOURCES(Exoplanets_RES_CXX ${Exoplanets_RES})

ADD_LIBRARY(Exoplanets-static STATIC ${Exoplanets_SRCS} ${Exoplanets_RES_CXX} ${ExoplanetsDialog_UIS_H})
TARGET_LINK_LIBRARIES(Exoplanets-static Qt5::Core Qt5::Network Qt5::Widgets qcustomplot_stel)
TARGET_LINK_LIBRARIES(Exoplanets-static Qt5::Core Qt5::Network Qt5::Widgets Qt5::Charts)
SET_TARGET_PROPERTIES(Exoplanets-static PROPERTIES OUTPUT_NAME "Exoplanets")
SET_TARGET_PROPERTIES(Exoplanets-static PROPERTIES COMPILE_FLAGS "-DQT_STATICPLUGIN")
ADD_DEPENDENCIES(AllStaticPlugins Exoplanets-static)
Expand Down
27 changes: 12 additions & 15 deletions plugins/Exoplanets/src/Exoplanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ Exoplanet::Exoplanet(const QVariantMap& map)
starAltNames = map.value("starAltNames").toString();
RA = StelUtils::getDecAngle(map.value("RA").toString());
DE = StelUtils::getDecAngle(map.value("DE").toString());
StelUtils::spheToRect(RA, DE, XYZ);
double RAdd = RA * M_180_PI;
double DEdd = DE * M_180_PI;
StelUtils::spheToRect(RA, DE, XYZ);
distance = map.value("distance").toDouble();
stype = map.value("stype").toString();
smass = map.value("smass").toDouble();
Expand Down Expand Up @@ -155,10 +153,9 @@ Exoplanet::Exoplanet(const QVariantMap& map)
yearDiscoveryList.append(p.discovered);
effectiveTempHostStarList.append(effectiveTemp);
metallicityHostStarList.append(smetal);
if (Vmag<99)
vMagHostStarList.append(Vmag);
raHostStarList.append(RAdd);
decHostStarList.append(DEdd);
vMagHostStarList.append(Vmag); // Vmag may be 99 as "invalid" marker. Still, append it!
raHostStarList.append(StelUtils::fmodpos(RA * M_180_PI, 360.)); // Fix some stars with negative RA
decHostStarList.append(DE * M_180_PI);
distanceHostStarList.append(distance);
massHostStarList.append(smass);
radiusHostStarList.append(sradius);
Expand Down Expand Up @@ -223,7 +220,7 @@ float Exoplanet::getSelectPriority(const StelCore *core) const

QString Exoplanet::getNameI18n(void) const
{
// Use SkyTranslator for translation star names
// Use SkyTranslator for translation of star names
const StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
QString name = trans.qtranslate(designation);
if (!starProperName.isEmpty())
Expand Down Expand Up @@ -336,7 +333,7 @@ QString Exoplanet::getInfoString(const StelCore* core, const InfoStringGroup& fl
{
//TRANSLATORS: Unit of measure for distance - Light Years
QString ly = qc_("ly", "distance");
oss << QString("%1: %2 %3").arg(q_("Distance"), QString::number(distance/0.306601, 'f', 2), ly) << "<br />";
oss << QString("%1: %2 %3").arg(q_("Distance"), QString::number(distance*PARSEC_LY, 'f', 2), ly) << "<br />";
}

if (flags&Extra)
Expand All @@ -363,13 +360,13 @@ QString Exoplanet::getInfoString(const StelCore* core, const InfoStringGroup& fl
QString planetNameLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Exoplanet"), qss);
QString planetProperNameLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Name"), qss);
QString periodLabel = QString("<td style=\"%3\">%1 (%2)</td>").arg(q_("Period"), qc_("days", "period"),qss);
QString massLabel = QString("<td style=\"%3\">%1 (M<sub>%2</sub>)</td>").arg(q_("Mass"), QChar(0x2643), qss);
QString massLabel = QString("<td style=\"%3\">%1 (M<sub>%2</sub>)</td>").arg(q_("Mass"), QChar(0x2643), qss); // QChar 0x2643=Jupiter
QString radiusLabel = QString("<td style=\"%3\">%1 (R<sub>%2</sub>)</td>").arg(q_("Radius"), QChar(0x2643), qss);
QString semiAxisLabel = QString("<td style=\"%3\">%1 (%2)</td>").arg(q_("Semi-Major Axis"), qc_("AU", "distance, astronomical unit"), qss);
QString eccentricityLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Eccentricity"), qss);
QString inclinationLabel = QString("<td style=\"%3\">%1 (%2)</td>").arg(q_("Inclination"), QChar(0x00B0), qss);
QString angleDistanceLabel = QString("<td style=\"%2\">%1 (\")</td>").arg(q_("Angle Distance"), qss);
QString discoveredLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Discovered year"), qss);
QString discoveredLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Discovery year"), qss);
QString detectionMethodLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Detection method"), qss);
QString pClassLabel = QString("<td style=\"%2\">%1</td>").arg(q_("Planetary class"), qss);
//TRANSLATORS: Full phrase is "Equilibrium Temperature"
Expand Down Expand Up @@ -569,7 +566,7 @@ QVariantMap Exoplanet::getInfoMap(const StelCore *core) const
QString Exoplanet::getPlanetaryClassI18n(QString ptype) const
{
QString result = "";
QRegularExpression dataRx("^(\\w)-(\\w+)\\s(\\w+)$");
static const QRegularExpression dataRx("^(\\w)-(\\w+)\\s(\\w+)$");
QRegularExpressionMatch dataMatch=dataRx.match(ptype);
if (dataMatch.hasMatch())
{
Expand Down Expand Up @@ -613,10 +610,10 @@ bool Exoplanet::isDiscovered(const StelCore *core)
discovery.append(p.discovered);
}
}
std::sort(discovery.begin(), discovery.end());
if (!discovery.isEmpty())
{
if (discovery.at(0)<=year && discovery.at(0)>0)
const double minYear=*std::min_element(discovery.begin(), discovery.end());
if (minYear<=year && minYear>0)
{
return true;
}
Expand Down Expand Up @@ -654,7 +651,7 @@ void Exoplanet::draw(StelCore* core, StelPainter *painter)
painter->drawSprite2dMode(getJ2000EquatorialPos(core), distributionMode ? 4.f : 5.f);

float coeff = 4.5f + std::log10(static_cast<float>(sradius) + 0.1f);
StarMgr* smgr = GETSTELMODULE(StarMgr); // It's need for checking displaying of labels for stars
StarMgr* smgr = GETSTELMODULE(StarMgr); // It's needed for checking displaying of labels for stars
if (labelsFader.getInterstate()<=0.f && !distributionMode && (mag+coeff)<mlimit && smgr->getFlagLabels())
{
if (showDesignations)
Expand Down
3 changes: 2 additions & 1 deletion plugins/Exoplanets/src/Exoplanet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct
class StelPainter;

//! @class Exoplanet
//! A exoplanet object represents one planetary system on the sky.
//! An exoplanet object represents one extrasolar planetary system in the sky.
//! Details about the exoplanets are passed using a QVariant which contains
//! a map of data from the json file.
//! @ingroup exoplanets
Expand Down Expand Up @@ -117,6 +117,7 @@ class Exoplanet : public StelObject
QStringList getExoplanetsNamesI18n(void) const;
QStringList getExoplanetsDesignations(void) const;

//! @returns whether system has been discovered by the current year.
bool isDiscovered(const StelCore* core);

void update(double deltaTime);
Expand Down
5 changes: 5 additions & 0 deletions plugins/Exoplanets/src/Exoplanets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ bool Exoplanets::getDisplayMode() const
void Exoplanets::setDisplayMode(bool b)
{
Exoplanet::distributionMode=b;
emit displayModeChanged(b);
}

bool Exoplanets::getFlagShowExoplanetsDesignations() const
Expand All @@ -821,6 +822,7 @@ bool Exoplanets::getFlagShowExoplanetsDesignations() const
void Exoplanets::setFlagShowExoplanetsDesignations(bool b)
{
Exoplanet::showDesignations=b;
emit flagShowExoplanetsDesignationsChanged(b);
}

bool Exoplanets::getFlagShowExoplanetsNumbers() const
Expand All @@ -831,6 +833,7 @@ bool Exoplanets::getFlagShowExoplanetsNumbers() const
void Exoplanets::setFlagShowExoplanetsNumbers(bool b)
{
Exoplanet::showNumbers=b;
emit flagShowExoplanetsNumbersChanged(b);
}

bool Exoplanets::getTimelineMode() const
Expand All @@ -841,6 +844,7 @@ bool Exoplanets::getTimelineMode() const
void Exoplanets::setTimelineMode(bool b)
{
Exoplanet::timelineMode=b;
emit timelineModeChanged(b);
}

bool Exoplanets::getHabitableMode() const
Expand All @@ -851,6 +855,7 @@ bool Exoplanets::getHabitableMode() const
void Exoplanets::setHabitableMode(bool b)
{
Exoplanet::habitableMode=b;
emit habitableModeChanged(b);
}

Vec3f Exoplanets::getMarkerColor() const
Expand Down
30 changes: 15 additions & 15 deletions plugins/Exoplanets/src/Exoplanets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,16 @@ typedef QSharedPointer<Exoplanet> ExoplanetP;
class Exoplanets : public StelObjectModule
{
Q_OBJECT
Q_PROPERTY(bool showExoplanets
READ getFlagShowExoplanets
WRITE setFlagShowExoplanets
NOTIFY flagExoplanetsVisibilityChanged
)
Q_PROPERTY(Vec3f markerColor
READ getMarkerColor
WRITE setMarkerColor
NOTIFY markerColorChanged
)
Q_PROPERTY(Vec3f habitableColor
READ getHabitableColor
WRITE setHabitableColor
NOTIFY habitableColorChanged
)
Q_PROPERTY(bool showExoplanets READ getFlagShowExoplanets WRITE setFlagShowExoplanets NOTIFY flagExoplanetsVisibilityChanged)
Q_PROPERTY(Vec3f markerColor READ getMarkerColor WRITE setMarkerColor NOTIFY markerColorChanged)
Q_PROPERTY(Vec3f habitableColor READ getHabitableColor WRITE setHabitableColor NOTIFY habitableColorChanged)

Q_PROPERTY(bool flagDisplayMode READ getDisplayMode WRITE setDisplayMode NOTIFY displayModeChanged)
Q_PROPERTY(bool flagTimelineMode READ getTimelineMode WRITE setTimelineMode NOTIFY timelineModeChanged)
Q_PROPERTY(bool flagHabitableMode READ getHabitableMode WRITE setHabitableMode NOTIFY habitableModeChanged)
Q_PROPERTY(bool flagShowExoplanetsDesignations READ getFlagShowExoplanetsDesignations WRITE setFlagShowExoplanetsDesignations NOTIFY flagShowExoplanetsDesignationsChanged)
Q_PROPERTY(bool flagShowExoplanetsNumbers READ getFlagShowExoplanetsNumbers WRITE setFlagShowExoplanetsNumbers NOTIFY flagShowExoplanetsNumbersChanged)

public:
//! @enum UpdateState
//! Used for keeping for track of the download/update status
Expand Down Expand Up @@ -243,6 +238,11 @@ class Exoplanets : public StelObjectModule
void flagExoplanetsVisibilityChanged(bool b);
void markerColorChanged(Vec3f);
void habitableColorChanged(Vec3f);
void displayModeChanged(bool);
void timelineModeChanged(bool);
void habitableModeChanged(bool);
void flagShowExoplanetsDesignationsChanged(bool);
void flagShowExoplanetsNumbersChanged(bool);

public slots:
//! Download JSON from web recources described in the module section of the
Expand Down
Loading