• 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.0
/plugins/MissingStars/src/MissingStars.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 "StelProjector.hpp"
20
#include "StelPainter.hpp"
21
#include "StelApp.hpp"
22
#include "StelCore.hpp"
23
#include "StelLocaleMgr.hpp"
24
#include "StelModuleMgr.hpp"
25
#include "StelObjectMgr.hpp"
26
#include "StelTextureMgr.hpp"
27
#include "StelJsonParser.hpp"
28
#include "StelFileMgr.hpp"
29
#include "StelUtils.hpp"
30
#include "StelTranslator.hpp"
31
#include "LabelMgr.hpp"
32
#include "MissingStar.hpp"
33
#include "MissingStars.hpp"
34
#include "MissingStarsDialog.hpp"
35

36
#include <QKeyEvent>
37
#include <QDebug>
38
#include <QFileInfo>
39
#include <QFile>
40
#include <QVariantMap>
41
#include <QVariant>
42
#include <QList>
43
#include <QSharedPointer>
44
#include <QStringList>
45
#include <QDir>
46
#include <QSettings>
47
#include <stdexcept>
48

49
#define CATALOG_FORMAT_VERSION 1 /* Version of format of catalog */
50

51
/*
52
 This method is the one called automatically by the StelModuleMgr just 
53
 after loading the dynamic library
54
*/
55
StelModule* MissingStarsStelPluginInterface::getStelModule() const
×
56
{
57
        return new MissingStars();
×
58
}
59

60
StelPluginInfo MissingStarsStelPluginInterface::getPluginInfo() const
×
61
{
62
        Q_INIT_RESOURCE(MissingStars);
×
63

64
        StelPluginInfo info;
×
65
        info.id = "MissingStars";
×
66
        info.displayedName = N_("Missing Stars");
×
67
        info.authors = "Alexander Wolf";
×
68
        info.contact = STELLARIUM_DEV_URL;
×
69
        info.description = N_("This plugin allows you to see some missing stars.");
×
70
        info.version = MISSINGSTARS_PLUGIN_VERSION;
×
71
        info.license = MISSINGSTARS_PLUGIN_LICENSE;
×
72
        return info;
×
73
}
×
74

75
/*
76
 Constructor
77
*/
78
MissingStars::MissingStars()
×
79
{
80
        setObjectName("MissingStars");
×
81
        configDialog = new MissingStarsDialog();
×
82
        conf = StelApp::getInstance().getSettings();
×
83
        setFontSize(StelApp::getInstance().getScreenFontSize());
×
84
        connect(&StelApp::getInstance(), SIGNAL(screenFontSizeChanged(int)), this, SLOT(setFontSize(int)));
×
85
}
×
86

87
/*
88
 Destructor
89
*/
90
MissingStars::~MissingStars()
×
91
{
92
        delete configDialog;
×
93
}
×
94

95
void MissingStars::deinit()
×
96
{
97
        texPointer.clear();
×
98
}
×
99

100
/*
101
 Reimplementation of the getCallOrder method
102
*/
103
double MissingStars::getCallOrder(StelModuleActionName actionName) const
×
104
{
105
        if (actionName==StelModule::ActionDraw)
×
106
                return StelApp::getInstance().getModuleMgr().getModule("StarMgr")->getCallOrder(actionName);
×
107
        return 0;
×
108
}
109

110

111
/*
112
 Init our module
113
*/
114
void MissingStars::init()
×
115
{
116
        texPointer = StelApp::getInstance().getTextureManager().createTexture(StelFileMgr::getInstallationDir()+"/textures/pointeur2.png");
×
117

118
        // key bindings and other actions
119
        addAction("actionShow_MissingStars_ConfigDialog", N_("Missing Stars"), N_("Missing Stars configuration window"), configDialog, "visible", ""); // Allow assign shortkey
×
120

121
        readJsonFile();
×
122

123
        GETSTELMODULE(StelObjectMgr)->registerStelObjectMgr(this);
×
124
}
×
125

126
/*
127
 Draw our module. This should print name of first missing star in the main window
128
*/
129
void MissingStars::draw(StelCore* core)
×
130
{
131
        StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
×
132
        StelPainter painter(prj);
×
133
        painter.setFont(font);
×
134
        
135
        for (const auto& ms : qAsConst(missingstars))
×
136
        {
137
                if (ms && ms->initialized)
×
138
                        ms->draw(core, painter);
×
139
        }
140

141
        if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
×
142
                drawPointer(core, painter);
×
143
}
×
144

145
void MissingStars::drawPointer(StelCore* core, StelPainter& painter)
×
146
{
147
        const QList<StelObjectP> newSelected = GETSTELMODULE(StelObjectMgr)->getSelectedObject("MissingStar");
×
148
        if (!newSelected.empty())
×
149
        {
150
                const StelObjectP obj = newSelected[0];
×
151
                Vec3d pos=obj->getJ2000EquatorialPos(core);
×
152

153
                Vec3d screenpos;
×
154
                // Compute 2D pos and return if outside screen
155
                if (!painter.getProjector()->project(pos, screenpos))
×
156
                        return;
×
157

158
                const Vec3f& c(obj->getInfoColor());
×
159
                painter.setColor(c[0],c[1],c[2]);
×
160
                texPointer->bind();
×
161
                painter.setBlending(true);
×
162
                painter.drawSprite2dMode(static_cast<float>(screenpos[0]), static_cast<float>(screenpos[1]), 13.f, static_cast<float>(StelApp::getInstance().getTotalRunTime())*40.f);
×
163
        }
×
164
}
×
165

166
QList<StelObjectP> MissingStars::searchAround(const Vec3d& av, double limitFov, const StelCore* core) const
×
167
{
168
        QList<StelObjectP> result;
×
169

170
        Vec3d v(av);
×
171
        v.normalize();
×
172
        const double cosLimFov = cos(limitFov * M_PI/180.);
×
173
        Vec3d equPos;
×
174

175
        for (const auto& ms : missingstars)
×
176
        {
177
                if (ms->initialized)
×
178
                {
179
                        equPos = ms->getJ2000EquatorialPos(core);
×
180
                        equPos.normalize();
×
181
                        if (equPos.dot(v) >= cosLimFov)
×
182
                        {
183
                                result.append(qSharedPointerCast<StelObject>(ms));
×
184
                        }
185
                }
186
        }
187

188
        return result;
×
189
}
×
190

191
StelObjectP MissingStars::searchByName(const QString& englishName) const
×
192
{
193
        for (const auto& msn : missingstars)
×
194
        {
195
                if (msn->getEnglishName().toUpper() == englishName.toUpper())
×
196
                        return qSharedPointerCast<StelObject>(msn);
×
197
        }
198

199
        return Q_NULLPTR;
×
200
}
201

202
StelObjectP MissingStars::searchByNameI18n(const QString& nameI18n) const
×
203
{
204
        for (const auto& msn : missingstars)
×
205
        {
206
                if (msn->getNameI18n().toUpper() == nameI18n.toUpper())
×
207
                        return qSharedPointerCast<StelObject>(msn);
×
208
        }
209

210
        return Q_NULLPTR;
×
211
}
212

213
QStringList MissingStars::listAllObjects(bool inEnglish) const
×
214
{
215
        QStringList result;
×
216
        if (inEnglish)
×
217
        {
218
                for (const auto& msn : missingstars)
×
219
                {
220
                        result << msn->getEnglishName();
×
221
                }
222
        }
223
        else
224
        {
225
                for (const auto& msn : missingstars)
×
226
                {
227
                        result << msn->getNameI18n();
×
228
                }
229
        }
230
        return result;
×
231
}
×
232
 
233
/*
234
  Read the JSON file and create list of missing stars.
235
*/
236
void MissingStars::readJsonFile(void)
×
237
{
238
        setMissingStarsMap(loadMissingStarsMap());
×
239
}
×
240

241
/*
242
  Parse JSON file and load missing stars to map
243
*/
244
QVariantMap MissingStars::loadMissingStarsMap()
×
245
{
246
        QVariantMap map;
×
247
        QFile jsonFile(":/MissingStars/missingstars.json");
×
248
        if (jsonFile.open(QIODevice::ReadOnly))
×
249
        {
250
                map = StelJsonParser::parse(jsonFile.readAll()).toMap();
×
251
                jsonFile.close();
×
252
        }
253
        return map;
×
254
}
×
255

256
/*
257
  Set items for list of struct from data map
258
*/
259
void MissingStars::setMissingStarsMap(const QVariantMap& map)
×
260
{
261
        missingstars.clear();
×
262
        designations.clear();
×
263
        QVariantMap msMap = map.value("catalog").toMap();
×
264
        for (auto &msKey : msMap.keys())
×
265
        {
266
                QVariantMap msData = msMap.value(msKey).toMap();
×
267
                msData["designation"] = QString("%1").arg(msKey);
×
268

269
                MissingStarP ms(new MissingStar(msData));
×
270
                if (ms->initialized)
×
271
                {
272
                        missingstars.append(ms);
×
273
                        designations.append(ms->getID());
×
274
                }
275
        }
×
276
}
×
277

278
MissingStarP MissingStars::getByID(const QString& id) const
×
279
{
280
        for (const auto& msn : missingstars)
×
281
        {
282
                if (msn->initialized && msn->designation == id)
×
283
                        return msn;
×
284
        }
285
        return MissingStarP();
×
286
}
287

288
bool MissingStars::configureGui(bool show)
×
289
{
290
        if (show)
×
291
                configDialog->setVisible(true);
×
292
        return true;
×
293
}
294

295
QString MissingStars::getMissingStarsList() const
×
296
{
297
        return designations.join(", ");
×
298
}
299

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