• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 6093339559

06 Sep 2023 06:04AM UTC coverage: 11.86% (-0.004%) from 11.864%
6093339559

push

github

alex-w
A new plugin is translatable now

14815 of 124919 relevant lines covered (11.86%)

21886.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.69
/plugins/MissingStars/src/MissingStar.cpp
1
/*
2
 * Copyright (C) 2023 Alexander Wolf
3
 *
4
 * This program is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU General Public License
6
 * as published by the Free Software Foundation; either version 2
7
 * of the License, or (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
17
 */
18

19
#include "MissingStar.hpp"
20
#include "StelObject.hpp"
21
#include "StelPainter.hpp"
22
#include "StelApp.hpp"
23
#include "StelCore.hpp"
24
#include "StelUtils.hpp"
25
#include "StelTranslator.hpp"
26
#include "StelModuleMgr.hpp"
27
#include "StelSkyDrawer.hpp"
28
#include "StelLocaleMgr.hpp"
29
#include "StarMgr.hpp"
30
#include "Planet.hpp"
31

32
#include <QTextStream>
33
#include <QDebug>
34
#include <QVariant>
35
#include <QVariantMap>
36
#include <QVariant>
37
#include <QList>
38

39
const QString MissingStar::MISSINGSTAR_TYPE = QStringLiteral("MissingStar");
15✔
40

41
MissingStar::MissingStar(const QVariantMap& map)
×
42
        : initialized(false)
×
43
        , designation("")
×
44
        , RA(0.)
×
45
        , DEC(0.)
×
46
        , pmRA(0.f)
×
47
        , pmDEC(0.f)
×
48
        , bMag(-99.f)
×
49
        , vMag(-99.f)
×
50
        , parallax(0.f)
×
51
        , parallaxErr(0.f)
×
52
        , spType("")
×
53
        , colorIndex(0)
×
54
{
55
        if (!map.contains("designation") || !map.contains("RA") || !map.contains("DEC") || !map.contains("vMag"))
×
56
        {
57
                qWarning() << "MissingStar: INVALID star!" << map.value("designation").toString();
×
58
                return;
×
59
        }
60

61
        designation = map.value("designation").toString();
×
62
        RA          = StelUtils::getDecAngle(map.value("RA").toString());
×
63
        DEC         = StelUtils::getDecAngle(map.value("DEC").toString());
×
64
        pmRA        = map.value("pmRA", 0.f).toFloat();
×
65
        pmDEC       = map.value("pmDEC", 0.f).toFloat();
×
66
        bMag        = map.value("bMag", -99.f).toFloat();
×
67
        vMag        = map.value("vMag", -99.f).toFloat();
×
68
        parallax    = map.value("parallax", 0.f).toFloat();
×
69
        parallaxErr = map.value("parallaxErr", 0.f).toFloat();
×
70
        spType      = map.value("SpType", "").toString();
×
71

72
        if (bMag>-99.f && vMag>-99.f)
×
73
        {
74
                double b_v = (bMag-vMag)*1000.0;
×
75
                if (b_v < -500.) {
×
76
                        b_v = -500.;
×
77
                } else if (b_v > 3499.) {
×
78
                        b_v = 3499.;
×
79
                }
80
                colorIndex = (unsigned int)floor(0.5+127.0*((500.0+b_v)/4000.0));
×
81
        }
82

83
        initialized = true;
×
84
}
×
85

86
MissingStar::~MissingStar()
×
87
{
88
        //
89
}
×
90

91
QVariantMap MissingStar::getMap(void) const
×
92
{
93
        const QVariantMap map = {
94
                {"designation", designation},
×
95
                {"RA", RA},
×
96
                {"DEC", DEC},
×
97
                {"pmRA", pmRA},
×
98
                {"pmDEC", pmDEC},
×
99
                {"bMag", bMag},
×
100
                {"vMag", vMag},
×
101
                {"parallax", parallax},
×
102
                {"parallaxErr", parallaxErr},
×
103
                {"SpType", spType}
×
104
        };
×
105

106
        return map;
×
107
}
108

109
QString MissingStar::getNameI18n(void) const
×
110
{
111
        return designation;
×
112
}
113

114
QString MissingStar::getEnglishName(void) const
×
115
{
116
        return designation;
×
117
}
118

119
QString MissingStar::getInfoString(const StelCore* core, const InfoStringGroup& flags) const
×
120
{
121
        QString str;
×
122
        QTextStream oss(&str);
×
123

124
        if (flags&Name)
×
125
                oss << "<h2>" << getNameI18n() << "</h2>";
×
126

127
        if (flags&ObjectType)
×
128
                oss << QString("%1: <b>%2</b>").arg(q_("Type"), getObjectTypeI18n()) << "<br />";
×
129

130
        if (flags&Magnitude)
×
131
                oss << getMagnitudeInfoString(core, flags, 2);
×
132

133
        if (flags&AbsoluteMagnitude)
×
134
        {
135
                if (parallax>0.f)
×
136
                        oss << QString("%1: %2").arg(q_("Absolute Magnitude")).arg(getVMagnitude(core)+5.*(1.+std::log10(0.001*parallax)), 0, 'f', 2) << "<br />";
×
137
                oss << getExtraInfoStrings(AbsoluteMagnitude).join("");
×
138
        }
139

140
        if (flags&Extra)
×
141
                oss << QString("%1: <b>%2</b>").arg(q_("Color Index (B-V)"), QString::number(bMag-vMag, 'f', 2)) << "<br />";
×
142

143
        // Ra/Dec etc.
144
        oss << getCommonInfoString(core, flags);
×
145

146
        if (flags&Distance)
×
147
        {
148
                if (parallax>0.f)
×
149
                {
150
                        //TRANSLATORS: Unit of measure for distance - Light Years
151
                        QString ly = qc_("ly", "distance");
×
152
                        double k = AU/(SPEED_OF_LIGHT*86400*365.25);
×
153
                        double d = ((0.001/3600.)*(M_PI/180));
×
154
                        double distance = k/(parallax*d);
×
155
                        if (parallaxErr>0.f && parallax>parallaxErr) // No distance when error of parallax is bigger than parallax!
×
156
                                oss << QString("%1: %2%3%4 %5").arg(q_("Distance"), QString::number(distance, 'f', 2), QChar(0x00B1), QString::number(qAbs(k/((parallaxErr + parallax)*d) - distance), 'f', 2), ly) << "<br />";
×
157
                        else
158
                                oss << QString("%1: %2 %3").arg(q_("Distance"), QString::number(distance, 'f', 2), ly) << "<br />";
×
159
                }
×
160
                oss << getExtraInfoStrings(Distance).join("");
×
161
        }
162

163
        if (flags&ProperMotion && (pmRA!=0.0 && pmDEC!=0.0))
×
164
        {
165
                double pa = std::atan2(pmRA, pmDEC)*M_180_PI;
×
166
                if (pa<0)
×
167
                        pa += 360.;
×
168
                oss << QString("%1: %2 %3 %4 %5&deg;<br />").arg(q_("Proper motion"),
×
169
                               QString::number(std::sqrt(pmRA*pmRA + pmDEC*pmDEC), 'f', 1), qc_("mas/yr", "milliarc second per year"),
×
170
                               qc_("towards", "into the direction of"), QString::number(pa, 'f', 1));
×
171
                oss << QString("%1: %2 %3 (%4)<br />").arg(q_("Proper motions by axes"), QString::number(pmRA, 'f', 1), QString::number(pmDEC, 'f', 1), qc_("mas/yr", "milliarc second per year"));
×
172
        }
173

174
        if (flags&Extra)
×
175
        {
176
                if (parallax>0.f)
×
177
                {
178
                        QString plx = q_("Parallax");
×
179
                        if (parallaxErr>0.f)
×
180
                                oss <<  QString("%1: %2%3%4 ").arg(plx, QString::number(parallax, 'f', 3), QChar(0x00B1), QString::number(parallaxErr, 'f', 3));
×
181
                        else
182
                                oss << QString("%1: %2 ").arg(plx, QString::number(parallax, 'f', 3));
×
183
                        oss  << qc_("mas", "parallax") << "<br />";
×
184
                }
×
185

186
                if (!spType.isEmpty())
×
187
                        oss << QString("%1: %2").arg(q_("Spectral Type"), spType) << "<br />";
×
188
        }
189

190
        oss << getSolarLunarInfoString(core, flags);
×
191
        postProcessInfoString(str, flags);
×
192
        return str;
×
193
}
×
194

195
float MissingStar::getVMagnitude(const StelCore* core) const
×
196
{
197
        Q_UNUSED(core)
198
        return vMag;
×
199
}
200

201
Vec3f MissingStar::getInfoColor(void) const
×
202
{
203
        return StelSkyDrawer::indexToColor(colorIndex);
×
204
}
205

206
void MissingStar::update(double deltaTime)
×
207
{
208
        labelsFader.update(static_cast<int>(deltaTime*1000));
×
209
}
×
210

211
void MissingStar::draw(StelCore* core, StelPainter& painter)
×
212
{
213
        StelSkyDrawer* sd = core->getSkyDrawer();
×
214
        const float mlimit = sd->getLimitMagnitude();
×
215
        const float mag = getVMagnitudeWithExtinction(core);
×
216
        const float shift = 8.f;
×
217
        
218
        if (mag <= mlimit)
×
219
        {
220
                const Vec3f color = getInfoColor();
×
221
                Vec3f vf(getJ2000EquatorialPos(core).toVec3f());
×
222
                Vec3f altAz(vf);
×
223
                altAz.normalize();
×
224
                core->j2000ToAltAzInPlaceNoRefraction(&altAz);
×
225
                RCMag rcMag;
226
                sd->computeRCMag(mag, &rcMag);
×
227
                sd->preDrawPointSource(&painter);
×
228
                // allow height-dependent twinkle and suppress twinkling in higher altitudes. Keep 0.1 twinkle amount in zenith.
229
                sd->drawPointSource(&painter, vf.toVec3d(), rcMag, color, true, qMin(1.0f, 1.0f-0.9f*altAz[2]));
×
230
                sd->postDrawPointSource(&painter);
×
231
                painter.setColor(color, 1.f);
×
232
                StarMgr* smgr = GETSTELMODULE(StarMgr); // It's need for checking displaying of labels for stars
×
233
                if (labelsFader.getInterstate()<=0.f && (mag+5.f)<mlimit && smgr->getFlagLabels())
×
234
                        painter.drawText(getJ2000EquatorialPos(core), designation, 0, shift, shift, false);
×
235
        }        
236
}
×
237

238
Vec3d MissingStar::getJ2000EquatorialPos(const StelCore* core) const
×
239
{
240
        Vec3d v;
×
241
        static const double d2000 = 2451545.0;
242
        const double movementFactor = (M_PI/180.)*(0.0001/3600.) * (core->getJDE()-d2000)/365.25;
×
243
        const double cRA = RA + movementFactor*pmRA;
×
244
        const double cDE = DEC + movementFactor*pmDEC;
×
245
        StelUtils::spheToRect(cRA, cDE, v);
×
246

247
        //StelUtils::spheToRect(RA, DEC, v);
248

249
        if ((core) && (core->getUseAberration()) && (core->getCurrentPlanet()))
×
250
        {
251
                Vec3d vel=core->getCurrentPlanet()->getHeliocentricEclipticVelocity();
×
252
                vel=StelCore::matVsop87ToJ2000*vel*core->getAberrationFactor()*(AU/(86400.0*SPEED_OF_LIGHT));
×
253
                Vec3d pos=v+vel;
×
254
                pos.normalize();
×
255
                return pos;
×
256
        }
257
        else
258
                return v;
×
259
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc