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

Stellarium / stellarium / 12904061178

22 Jan 2025 08:11AM UTC coverage: 12.141% (-0.04%) from 12.184%
12904061178

push

github

web-flow
Translate stellarium-scripts.pot in lt

100% translated source file: 'stellarium-scripts.pot'
on 'lt'.

14599 of 120244 relevant lines covered (12.14%)

19025.65 hits per line

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

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

20
#include "StelProjector.hpp"
21
#include "Asterism.hpp"
22
#include "StarMgr.hpp"
23

24
#include "StelPainter.hpp"
25
#include "StelApp.hpp"
26
#include "StelCore.hpp"
27
#include "StelUtils.hpp"
28
#include "ZoneArray.hpp"
29

30
#include <algorithm>
31
#include <QString>
32
#include <QTextStream>
33
#include <QDebug>
34
#include <QFontMetrics>
35
#include <QIODevice>
36

37
Vec3f Asterism::lineColor = Vec3f(0.4f,0.4f,0.8f);
38
Vec3f Asterism::rayHelperColor = Vec3f(1.0f,1.0f,0.0f);
39
Vec3f Asterism::labelColor = Vec3f(0.4f,0.4f,0.8f);
40
const QString Asterism::ASTERISM_TYPE = QStringLiteral("Asterism");
41

42
Asterism::Asterism()
×
43
        : numberOfSegments(0)
×
44
        , typeOfAsterism(1)
×
45
        , flagAsterism(true)
×
46
        , asterism(Q_NULLPTR)
×
47
{
48
}
×
49

50
Asterism::~Asterism()
×
51
{
52
        delete[] asterism;
×
53
        asterism = Q_NULLPTR;
×
54
}
×
55

56
bool Asterism::read(const QString& record, StarMgr *starMgr)
×
57
{
58
        abbreviation.clear();
×
59
        numberOfSegments = 0;
×
60
        typeOfAsterism = 1;
×
61
        flagAsterism = true;
×
62

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

70
        StelCore *core = StelApp::getInstance().getCore();
×
71
        asterism = new StelObjectP[numberOfSegments*2];
×
72
        for (unsigned int i=0;i<numberOfSegments*2;++i)
×
73
        {
74
                switch (typeOfAsterism)
×
75
                {
76
                        case 0: // Ray helpers
×
77
                        case 1: // A big asterism with lines by HIP stars
78
                        {
79
                                StarId HP = 0;
×
80
                                istr >> HP;
×
81
                                if(HP == 0)
×
82
                                {
83
                                        return false;
×
84
                                }
85
                                if (HP <= NR_OF_HIP)
×
86
                                {
87
                                        asterism[i]=starMgr->searchHP(static_cast<int>(HP));
×
88
                                }
89
                                else
90
                                {
91
                                        asterism[i]=starMgr->searchGaia(HP);
×
92
                                }
93
                                
94
                                if (!asterism[i])
×
95
                                {
96
                                        qWarning() << "Error in asterism" << abbreviation << "- can't find star HIP" << HP;
×
97
                                        return false;
×
98
                                }
99
                                break;
×
100
                        }
101
                        case 2: // A small asterism with lines by J2000.0 coordinates
×
102
                        {
103
                                double RA, DE;
104
                                Vec3d coords;
×
105

106
                                istr >> RA >> DE;                                
×
107
                                StelUtils::spheToRect(RA*M_PI/12., DE*M_PI/180., coords);
×
108
                                QList<StelObjectP> stars = starMgr->searchAround(coords, 0.1, core);
×
109
                                StelObjectP s = Q_NULLPTR;
×
110
                                double d = 10.;
×
111
                                for (const auto& p : stars)
×
112
                                {
113
                                        double a = coords.angle(p->getJ2000EquatorialPos(core));
×
114
                                        if (a<d)
×
115
                                        {
116
                                                d = a;
×
117
                                                s = p;
×
118
                                        }
119
                                }
120
                                asterism[i] = s;
×
121
                                if (!asterism[i])
×
122
                                {
123
                                        qWarning() << "Error in asterism" << abbreviation << "- can't find star with coordinates" << RA << "/" << DE;
×
124
                                        return false;
×
125
                                }
126
                                break;
×
127
                        }
×
128
                }
129
        }
130

131
        if (typeOfAsterism>0)
×
132
        {
133
                XYZname.set(0.,0.,0.);
×
134
                for(unsigned int j=0;j<numberOfSegments*2;++j)
×
135
                        XYZname+= asterism[j]->getJ2000EquatorialPos(core);
×
136
                XYZname.normalize();
×
137
        }
138
        else
139
                flagAsterism = false;
×
140

141
        return true;
×
142
}
×
143

144
void Asterism::drawOptim(StelPainter& sPainter, const StelCore* core, const SphericalCap& viewportHalfspace) const
×
145
{
146
        if (flagAsterism)
×
147
        {
148
                if (lineFader.getInterstate()<=0.0001f)
×
149
                        return;
×
150

151
                sPainter.setColor(lineColor, lineFader.getInterstate());
×
152
        }
153
        else
154
        {
155
                if (rayHelperFader.getInterstate()<=0.0001f)
×
156
                        return;
×
157

158
                sPainter.setColor(rayHelperColor, rayHelperFader.getInterstate());
×
159
        }
160

161
        Vec3d star1;
×
162
        Vec3d star2;
×
163
        for (unsigned int i=0;i<numberOfSegments;++i)
×
164
        {
165
                star1=asterism[2*i]->getJ2000EquatorialPos(core);
×
166
                star2=asterism[2*i+1]->getJ2000EquatorialPos(core);
×
167
                star1.normalize();
×
168
                star2.normalize();
×
169
                sPainter.drawGreatCircleArc(star1, star2, &viewportHalfspace);
×
170
        }
171
}
172

173
void Asterism::drawName(StelPainter& sPainter) const
×
174
{
175
        if ((nameFader.getInterstate()==0.0f) || !flagAsterism)
×
176
                return;
×
177

178
        if (typeOfAsterism==2 && sPainter.getProjector()->getFov()>60.f)
×
179
                return;
×
180

181
        QString name = getNameI18n();
×
182
        sPainter.setColor(labelColor, nameFader.getInterstate());
×
183
        sPainter.drawText(static_cast<float>(XYname[0]), static_cast<float>(XYname[1]), name, 0., -sPainter.getFontMetrics().boundingRect(name).width()/2, 0, false);
×
184
}
×
185

186
void Asterism::update(int deltaTime)
×
187
{
188
        lineFader.update(deltaTime);
×
189
        rayHelperFader.update(deltaTime);
×
190
        nameFader.update(deltaTime);
×
191
}
×
192

193
QString Asterism::getInfoString(const StelCore *core, const InfoStringGroup &flags) const
×
194
{
195
        Q_UNUSED(core)
196
        QString str;
×
197
        QTextStream oss(&str);
×
198

199
        if (flags&Name)
×
200
                oss << "<h2>" << getNameI18n() << "</h2>";
×
201

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

205
        oss << getSolarLunarInfoString(core, flags);
×
206
        postProcessInfoString(str, flags);
×
207

208
        return str;
×
209
}
×
210

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