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

Stellarium / stellarium / 15291801018

28 May 2025 04:52AM UTC coverage: 11.931% (-0.02%) from 11.951%
15291801018

push

github

alex-w
Added new set of navigational stars (XIX century)

0 of 6 new or added lines in 2 files covered. (0.0%)

14124 existing lines in 74 files now uncovered.

14635 of 122664 relevant lines covered (11.93%)

18291.42 hits per line

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

0.0
/src/core/modules/AsterismMgr.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

21
#include "AsterismMgr.hpp"
22
#include "Asterism.hpp"
23
#include "StarMgr.hpp"
24
#include "StelApp.hpp"
25
#include "StelProjector.hpp"
26
#include "StelObjectMgr.hpp"
27
#include "StelLocaleMgr.hpp"
28
#include "StelSkyCultureMgr.hpp"
29
#include "StelModuleMgr.hpp"
30
#include "StelFileMgr.hpp"
31
#include "StelCore.hpp"
32
#include "StelPainter.hpp"
33
#include "Planet.hpp"
34
#include "StelUtils.hpp"
35

36
#include <vector>
37
#include <QDebug>
38
#include <QFile>
39
#include <QSettings>
40
#include <QRegularExpression>
41
#include <QString>
42
#include <QStringList>
43
#include <QDir>
44

45
// constructor which loads all data from appropriate files
46
AsterismMgr::AsterismMgr(StarMgr *_hip_stars)
×
47
        : hipStarMgr(_hip_stars)
×
48
        , linesDisplayed(false)
×
49
        , rayHelpersDisplayed(false)
×
50
        , namesDisplayed(false)
×
51
        , hasAsterism(false)
×
52
        , isolateAsterismSelected(false)
×
53
        , linesFadeDuration(1.f)
×
54
        , namesFadeDuration(1.f)
×
55
        , rayHelpersFadeDuration(1.f)
×
56
        , asterismLineThickness(1)
×
57
        , rayHelperThickness(1)
×
58
{
59
        setObjectName("AsterismMgr");
×
60
        Q_ASSERT(hipStarMgr);
×
61
}
×
62

63
AsterismMgr::~AsterismMgr()
×
64
{
65
        for (auto* asterism : asterisms)
×
66
        {
67
                delete asterism;
×
68
        }
69
}
×
70

71
void AsterismMgr::init()
×
72
{
73
        QSettings* conf = StelApp::getInstance().getSettings();
×
74
        Q_ASSERT(conf);
×
75

76
        setFontSize(conf->value("viewing/asterism_font_size", 14).toInt());
×
77
        setFlagLines(conf->value("viewing/flag_asterism_drawing").toBool());
×
78
        setFlagRayHelpers(conf->value("viewing/flag_rayhelper_drawing").toBool());
×
79
        setFlagLabels(conf->value("viewing/flag_asterism_name").toBool());
×
80
        setAsterismLineThickness(conf->value("viewing/asterism_line_thickness", 1).toInt());
×
81
        setRayHelperThickness(conf->value("viewing/rayhelper_line_thickness", 1).toInt());
×
82
        setFlagIsolateAsterismSelected(conf->value("viewing/flag_asterism_isolate_selected", false).toBool());
×
83

84
        setLinesFadeDuration(conf->value("viewing/asterism_lines_fade_duration", 1.0f).toFloat());
×
85
        setLabelsFadeDuration(conf->value("viewing/asterism_labels_fade_duration", 1.0f).toFloat());
×
86
        setRayHelpersFadeDuration(conf->value("viewing/rayhelper_lines_fade_duration", 1.0f).toFloat());
×
87

88
        // Load colors from config file
89
        QString defaultColor = conf->value("color/default_color").toString();
×
90
        setLinesColor(Vec3f(conf->value("color/asterism_lines_color", defaultColor).toString()));
×
91
        setLabelsColor(Vec3f(conf->value("color/asterism_names_color", defaultColor).toString()));
×
92
        setRayHelpersColor(Vec3f(conf->value("color/rayhelper_lines_color", defaultColor).toString()));
×
93

94
        StelObjectMgr *objectManager = GETSTELMODULE(StelObjectMgr);
×
95
        objectManager->registerStelObjectMgr(this);
×
96
        connect(objectManager, SIGNAL(selectedObjectChanged(StelModule::StelModuleSelectAction)),
×
97
                        this, SLOT(selectedObjectChange(StelModule::StelModuleSelectAction)));
98
        StelApp *app = &StelApp::getInstance();
×
99
        connect(app, SIGNAL(languageChanged()), this, SLOT(updateI18n()));
×
100
        connect(&app->getSkyCultureMgr(), &StelSkyCultureMgr::currentSkyCultureChanged, this, &AsterismMgr::updateSkyCulture);
×
101

102
        QString displayGroup = N_("Display Options");
×
103
        addAction("actionShow_Asterism_Lines", displayGroup, N_("Asterism lines"), "linesDisplayed", "Alt+A");        
×
104
        addAction("actionShow_Asterism_Labels", displayGroup, N_("Asterism labels"), "namesDisplayed", "Alt+V");
×
105
        addAction("actionShow_Asterism_Isolated", displayGroup, N_("Toggle single asterism selection mode"), "switchSelectionMode()");
×
106
        addAction("actionShow_Ray_Helpers", displayGroup, N_("Ray helpers"), "rayHelpersDisplayed", "Alt+R");
×
107
}
×
108

109
/*************************************************************************
110
 Reimplementation of the getCallOrder method
111
*************************************************************************/
112
double AsterismMgr::getCallOrder(StelModuleActionName actionName) const
×
113
{
114
        if (actionName==StelModule::ActionDraw)
×
115
                return StelApp::getInstance().getModuleMgr().getModule("GridLinesMgr")->getCallOrder(actionName)+11;
×
116
        return 0;
×
117
}
118

119
void AsterismMgr::updateSkyCulture(const StelSkyCulture& skyCulture)
×
120
{
121
        static QSettings *conf=StelApp::getInstance().getSettings();
×
UNCOV
122
        currentSkyCultureID = skyCulture.id;
×
123

124
        StelObjectMgr* objMgr = GETSTELMODULE(StelObjectMgr);
×
125
        const QList<StelObjectP> selectedObject = objMgr->getSelectedObject("Asterism");
×
126
        if (!selectedObject.isEmpty()) // Unselect asterism
×
UNCOV
127
                objMgr->unSelect();
×
128

UNCOV
129
        if (skyCulture.asterisms.isEmpty())
×
130
        {
131
                // No data!
132
                asterisms.clear();
×
133
                selected.clear();
×
134
                hasAsterism = false;
×
UNCOV
135
                qInfo() << "No asterisms for skyculture" << currentSkyCultureID;
×
136
        }
137
        else
138
        {
139
                hasAsterism = true;
×
140
                for(auto* asterism : asterisms)
×
141
                        delete asterism;
×
142
                asterisms.clear();
×
143
                asterisms.resize(skyCulture.asterisms.size());
×
144
                unsigned readOK = 0;
×
145

146
                // Configure exclusion by user preference!
147
                QString exclude=conf->value(QString("SCExcludeReferences/%1").arg(currentSkyCultureID), QString()).toString();
×
148
                QSet<int>excludeRefs;
×
UNCOV
149
                if (!exclude.isEmpty())
×
150
                {
151
        #if  (QT_VERSION<QT_VERSION_CHECK(5,14,0))
152
                        QStringList excludeRefStrings=exclude.split(',', QString::SkipEmptyParts);
153
        #else
154
                        QStringList excludeRefStrings=exclude.split(',', Qt::SkipEmptyParts);
×
155
        #endif
156
                        QMutableListIterator<QString> it(excludeRefStrings);
×
UNCOV
157
                        while (it.hasNext())
×
158
                        {
159
                                bool ok;
160
                                int numRef=it.next().toInt(&ok); // ok=false for strings e.g. from asterisms
×
161
                                if (ok)
×
162
                                {
UNCOV
163
                                        excludeRefs.insert(numRef);
×
UNCOV
164
                                        it.remove();
×
165
                                }
166
                        }
UNCOV
167
                        qInfo() << "Skyculture" << currentSkyCultureID << "configured to exclude asterisms referenced from" << excludeRefs;
×
UNCOV
168
                }
×
169

170
                for (unsigned n = 0, m=0; n < asterisms.size(); ++n, ++m)
×
171
                {
UNCOV
172
                        auto& aster = asterisms[n];
×
UNCOV
173
                        aster = new Asterism;
×
UNCOV
174
                        if (aster->read(skyCulture.asterisms[m].toObject(), hipStarMgr, excludeRefs))
×
175
                        {
176
                                aster->lineFader.setDuration(static_cast<int>(linesFadeDuration * 1000.f));
×
UNCOV
177
                                aster->rayHelperFader.setDuration(static_cast<int>(rayHelpersFadeDuration * 1000.f));
×
178
                                aster->nameFader.setDuration(static_cast<int>(namesFadeDuration * 1000.f));
×
UNCOV
179
                                aster->setFlagLines(linesDisplayed);
×
180
                                aster->setFlagLabels(namesDisplayed);
×
UNCOV
181
                                aster->setFlagRayHelpers(rayHelpersDisplayed);
×
182
                                ++readOK;
×
183
                        }
184
                        else
185
                        {
UNCOV
186
                                delete asterisms[n];
×
187
                                asterisms.erase(asterisms.begin() + n);
×
UNCOV
188
                                --n;
×
189
                        }
190
                }
UNCOV
191
                qInfo().noquote() << "Loaded" << readOK << "/" << skyCulture.asterisms.size()
×
192
                                  << "asterism records successfully for culture" << currentSkyCultureID;
×
193

194
                // Set current states
UNCOV
195
                setFlagLines(linesDisplayed);
×
196
                setFlagLabels(namesDisplayed);
×
197
                setFlagRayHelpers(rayHelpersDisplayed);
×
UNCOV
198
        }
×
199

200
        // Translate asterism names for the new sky culture
201
        updateI18n();
×
UNCOV
202
}
×
203

UNCOV
204
void AsterismMgr::setLinesColor(const Vec3f& color)
×
205
{
UNCOV
206
        if (color != Asterism::lineColor)
×
207
        {
UNCOV
208
                Asterism::lineColor = color;
×
209
                emit linesColorChanged(color);
×
210
        }
211
}
×
212

UNCOV
213
Vec3f AsterismMgr::getLinesColor() const
×
214
{
UNCOV
215
        return Asterism::lineColor;
×
216
}
217

218
void AsterismMgr::setRayHelpersColor(const Vec3f& color)
×
219
{
UNCOV
220
        if (color != Asterism::rayHelperColor)
×
221
        {
UNCOV
222
                Asterism::rayHelperColor = color;
×
223
                emit rayHelpersColorChanged(color);
×
224
        }
225
}
×
226

227
Vec3f AsterismMgr::getRayHelpersColor() const
×
228
{
229
        return Asterism::rayHelperColor;
×
230
}
231

232

233
void AsterismMgr::setLabelsColor(const Vec3f& color)
×
234
{
UNCOV
235
        if (Asterism::labelColor != color)
×
236
        {
UNCOV
237
                Asterism::labelColor = color;
×
238
                emit namesColorChanged(color);
×
239
        }
240
}
×
241

242
Vec3f AsterismMgr::getLabelsColor() const
×
243
{
244
        return Asterism::labelColor;
×
245
}
246

247
void AsterismMgr::setFontSize(const int newFontSize)
×
248
{
249
        if ((asterFont.pixelSize() - newFontSize) != 0)
×
250
        {
251
                asterFont.setPixelSize(newFontSize);
×
UNCOV
252
                StelApp::immediateSave("viewing/asterism_font_size", newFontSize);
×
253
                emit fontSizeChanged(newFontSize);
×
254
        }
255
}
×
256

257
int AsterismMgr::getFontSize() const
×
258
{
UNCOV
259
        return asterFont.pixelSize();
×
260
}
261

262
void AsterismMgr::setAsterismLineThickness(const int thickness)
×
263
{
264
        if(thickness!=asterismLineThickness)
×
265
        {
266
                asterismLineThickness = thickness;
×
267
                if (asterismLineThickness<=0) // The line can not be negative or zero thickness
×
268
                        asterismLineThickness = 1;
×
269

270
                StelApp::immediateSave("viewing/asterism_line_thickness", thickness);
×
UNCOV
271
                emit asterismLineThicknessChanged(thickness);
×
272
        }
273
}
×
274

275
void AsterismMgr::setRayHelperThickness(const int thickness)
×
276
{
UNCOV
277
        if(thickness!=rayHelperThickness)
×
278
        {
279
                rayHelperThickness = thickness;
×
280
                if (rayHelperThickness<=0) // The line can not be negative or zero thickness
×
281
                        rayHelperThickness = 1;
×
282

UNCOV
283
                StelApp::immediateSave("viewing/rayhelper_line_thickness", thickness);
×
284
                emit rayHelperThicknessChanged(thickness);
×
285
        }
UNCOV
286
}
×
287

288
void AsterismMgr::draw(StelCore* core)
×
289
{
290
        const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
×
291
        StelPainter sPainter(prj);
×
292
        sPainter.setFont(asterFont);
×
UNCOV
293
        drawLines(sPainter, core);
×
UNCOV
294
        drawRayHelpers(sPainter, core);
×
UNCOV
295
        drawNames(sPainter);
×
296
}
×
297

298
// Draw asterisms lines
299
void AsterismMgr::drawLines(StelPainter& sPainter, const StelCore* core) const
×
300
{
301
        if (!hasAsterism)
×
302
                return;
×
303

304
        const float ppx = static_cast<float>(sPainter.getProjector()->getDevicePixelsPerPixel());
×
305
        sPainter.setBlending(true);
×
UNCOV
306
        if (asterismLineThickness>1 || ppx>1.f)
×
307
                sPainter.setLineWidth(asterismLineThickness*ppx); // set line thickness
×
308
        sPainter.setLineSmooth(true);
×
309

310
        const SphericalCap& viewportHalfspace = sPainter.getProjector()->getBoundingCap();
×
311
        for (auto* asterism : asterisms)
×
312
        {
313
                if (asterism->isAsterism())
×
314
                        asterism->drawOptim(sPainter, core, viewportHalfspace);
×
315
        }
UNCOV
316
        if (asterismLineThickness>1 || ppx>1.f)
×
UNCOV
317
                sPainter.setLineWidth(1); // restore line thickness
×
UNCOV
318
        sPainter.setLineSmooth(false);
×
319
}
320

321
// Draw asterisms lines
322
void AsterismMgr::drawRayHelpers(StelPainter& sPainter, const StelCore* core) const
×
323
{
324
        if (!hasAsterism)
×
UNCOV
325
                return;
×
326

327
        const float ppx = static_cast<float>(sPainter.getProjector()->getDevicePixelsPerPixel());
×
UNCOV
328
        sPainter.setBlending(true);
×
329
        if (rayHelperThickness>1 || ppx>1.f)
×
UNCOV
330
                sPainter.setLineWidth(rayHelperThickness*ppx); // set line thickness
×
331
        sPainter.setLineSmooth(true);
×
332

UNCOV
333
        const SphericalCap& viewportHalfspace = sPainter.getProjector()->getBoundingCap();
×
334
        for (auto* asterism : asterisms)
×
335
        {
336
                if (!asterism->isAsterism())
×
337
                        asterism->drawOptim(sPainter, core, viewportHalfspace);
×
338
        }
UNCOV
339
        if (rayHelperThickness>1 || ppx>1.f)
×
340
                sPainter.setLineWidth(1); // restore line thickness
×
341
        sPainter.setLineSmooth(false);
×
342
}
343

344
// Draw the names of all the asterisms
345
void AsterismMgr::drawNames(StelPainter& sPainter) const
×
346
{
347
        if (!hasAsterism)
×
UNCOV
348
                return;
×
349

350
        StelCore *core=StelApp::getInstance().getCore();
×
UNCOV
351
        static StelSkyCultureMgr* scMgr= GETSTELMODULE(StelSkyCultureMgr);
×
352
        const bool abbreviateLabel=scMgr->getFlagUseAbbreviatedNames();
×
UNCOV
353
        StelObject::CulturalDisplayStyle culturalDisplayStyle=scMgr->getScreenLabelStyle();
×
354

UNCOV
355
        sPainter.setBlending(true);
×
UNCOV
356
        for (auto* asterism : asterisms)
×
357
        {
UNCOV
358
                if (!asterism->flagAsterism) continue;
×
359
                // Check if in the field of view
UNCOV
360
                Vec3d XYZname=asterism->XYZname;
×
UNCOV
361
                if (core->getUseAberration())
×
362
                {
UNCOV
363
                        const Vec3d vel = core->getAberrationVec(core->getJDE());
×
364
                        XYZname.normalize();
×
365
                        XYZname+=vel;
×
UNCOV
366
                        XYZname.normalize();
×
367
                }
368

369
                if (sPainter.getProjector()->projectCheck(XYZname, asterism->XYname))
×
UNCOV
370
                        asterism->drawName(sPainter, abbreviateLabel);
×
371
        }
372
}
373

374
Asterism* AsterismMgr::findFromAbbreviation(const QString& abbreviation) const
×
375
{
UNCOV
376
        for (auto* asterism : asterisms)
×
377
        {
UNCOV
378
                if (asterism->abbreviation.compare(abbreviation, Qt::CaseInsensitive) == 0)
×
379
                        return asterism;
×
380
        }
381
        return nullptr;
×
382
}
383

UNCOV
384
void AsterismMgr::updateI18n()
×
385
{
386
        const StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSkyTranslator();
×
UNCOV
387
        for (auto* asterism : asterisms)
×
388
        {
389
                const QString context = asterism->context;
×
UNCOV
390
                asterism->culturalName.translatedI18n = trans.tryQtranslate(asterism->culturalName.translated, context);
×
UNCOV
391
                if (asterism->culturalName.translatedI18n.isEmpty())
×
392
                {
393
                        if (context.isEmpty())
×
394
                                asterism->culturalName.translatedI18n = q_(asterism->culturalName.translated);
×
395
                        else
396
                                asterism->culturalName.translatedI18n = qc_(asterism->culturalName.translated, context);
×
397
                }
UNCOV
398
                asterism->culturalName.pronounceI18n = trans.tryQtranslate(asterism->culturalName.pronounce, context);
×
399
                if (asterism->culturalName.pronounceI18n.isEmpty())
×
400
                {
401
                        if (context.isEmpty())
×
UNCOV
402
                                asterism->culturalName.pronounceI18n = q_(asterism->culturalName.pronounce);
×
403
                        else
UNCOV
404
                                asterism->culturalName.pronounceI18n = qc_(asterism->culturalName.pronounce, context);
×
405
                }
406
                asterism->abbreviationI18n = trans.tryQtranslate(asterism->abbreviation, context);
×
UNCOV
407
                if (asterism->abbreviationI18n.isEmpty())
×
408
                {
UNCOV
409
                        if (context.isEmpty())
×
410
                                asterism->abbreviationI18n = q_(asterism->abbreviation);
×
411
                        else
UNCOV
412
                                asterism->abbreviationI18n = qc_(asterism->abbreviation, context);
×
413
                }
UNCOV
414
        }
×
415
}
×
416

417
// update faders
418
void AsterismMgr::update(double deltaTime)
×
419
{
420
        const int delta = static_cast<int>(deltaTime*1000);
×
UNCOV
421
        for (auto* asterism : asterisms)
×
422
        {
UNCOV
423
                asterism->update(delta);
×
424
        }
425
}
×
426

427
void AsterismMgr::setFlagLines(const bool displayed)
×
428
{
429
        if(linesDisplayed != displayed)
×
430
        {
UNCOV
431
                linesDisplayed = displayed;
×
432
                if (!selected.empty() && getFlagIsolateAsterismSelected())
×
433
                {
UNCOV
434
                        for (auto* asterism : selected)
×
UNCOV
435
                                asterism->setFlagLines(linesDisplayed);
×
436
                }
437
                else
438
                {
UNCOV
439
                        for (auto* asterism : asterisms)
×
440
                                asterism->setFlagLines(linesDisplayed);
×
441
                }
UNCOV
442
                StelApp::immediateSave("viewing/flag_asterism_drawing", displayed);
×
443
                emit linesDisplayedChanged(displayed);
×
444
        }
445
}
×
446

447
bool AsterismMgr::getFlagLines(void) const
×
448
{
UNCOV
449
        return linesDisplayed;
×
450
}
451

452
void AsterismMgr::setFlagRayHelpers(const bool displayed)
×
453
{
454
        if(rayHelpersDisplayed != displayed)
×
455
        {
456
                rayHelpersDisplayed = displayed;
×
457
                for (auto* asterism : asterisms)
×
458
                {
459
                        asterism->setFlagRayHelpers(rayHelpersDisplayed);
×
460
                }
UNCOV
461
                StelApp::immediateSave("viewing/flag_rayhelper_drawing", displayed);
×
462
                emit rayHelpersDisplayedChanged(displayed);
×
463
        }
464
}
×
465

UNCOV
466
bool AsterismMgr::getFlagRayHelpers(void) const
×
467
{
468
        return rayHelpersDisplayed;
×
469
}
470

471
void AsterismMgr::setFlagLabels(const bool displayed)
×
472
{
473
        if (namesDisplayed != displayed)
×
474
        {
UNCOV
475
                namesDisplayed = displayed;
×
476
                if (!selected.empty() && getFlagIsolateAsterismSelected())
×
477
                {
478
                        for (auto* asterism : selected)
×
479
                                asterism->setFlagLabels(namesDisplayed);
×
480
                }
481
                else
482
                {
483
                        for (auto* asterism : asterisms)
×
484
                                asterism->setFlagLabels(namesDisplayed);
×
485
                }
UNCOV
486
                StelApp::immediateSave("viewing/flag_asterism_name", displayed);
×
UNCOV
487
                emit namesDisplayedChanged(displayed);
×
488
        }
489
}
×
490

491
bool AsterismMgr::getFlagLabels(void) const
×
492
{
UNCOV
493
        return namesDisplayed;
×
494
}
495

496
StelObjectP AsterismMgr::searchByNameI18n(const QString& nameI18n) const
×
497
{
498
        QString nameI18nUpper = nameI18n.toUpper();
×
UNCOV
499
        for (auto* asterism : asterisms)
×
500
        {
UNCOV
501
                if (asterism->culturalName.translatedI18n.toUpper() == nameI18nUpper) return asterism;
×
502
                if (asterism->culturalName.pronounceI18n.toUpper()  == nameI18nUpper) return asterism;
×
503
        }
504
        return nullptr;
×
UNCOV
505
}
×
506

507
StelObjectP AsterismMgr::searchByName(const QString& name) const
×
508
{
509
        QString nameUpper = name.toUpper();
×
UNCOV
510
        for (auto* asterism : asterisms)
×
511
        {
512
                if (asterism->culturalName.translated.toUpper()      == nameUpper) return asterism;
×
UNCOV
513
                if (asterism->culturalName.native.toUpper()          == nameUpper) return asterism;
×
514
                if (asterism->culturalName.pronounce.toUpper()       == nameUpper) return asterism;
×
UNCOV
515
                if (asterism->culturalName.transliteration.toUpper() == nameUpper) return asterism;
×
516
                if (asterism->abbreviation.toUpper() == nameUpper)                 return asterism;
×
517
        }
UNCOV
518
        return nullptr;
×
519
}
×
520

521
QStringList AsterismMgr::listAllObjects(bool inEnglish) const
×
522
{
523
        QStringList result;
×
524
        if (inEnglish)
×
525
        {
UNCOV
526
                for (auto* asterism : asterisms)
×
527
                {
528
                        if (asterism->isAsterism())
×
UNCOV
529
                                result << asterism->getEnglishName();
×
530
                }
531
        }
532
        else
533
        {
534
                for (auto* asterism : asterisms)
×
535
                {
UNCOV
536
                        if (asterism->isAsterism())
×
537
                                result << asterism->getNameI18n();
×
538
                }
539
        }
540
        return result;
×
UNCOV
541
}
×
542

UNCOV
543
StelObjectP AsterismMgr::searchByID(const QString &id) const
×
544
{
UNCOV
545
        for (auto* asterism : asterisms)
×
546
        {
547
                if (asterism->getID() == id) return asterism;
×
548
        }
UNCOV
549
        return nullptr;
×
550
}
551

552
QString AsterismMgr::getStelObjectType() const
×
553
{
UNCOV
554
        return Asterism::ASTERISM_TYPE;
×
555
}
556

557
void AsterismMgr::setFlagIsolateAsterismSelected(const bool isolate)
×
558
{
UNCOV
559
        if (isolateAsterismSelected != isolate)
×
560
        {
UNCOV
561
                isolateAsterismSelected = isolate;
×
562

563
                // when turning off isolated selection mode, clear existing isolated selections.
UNCOV
564
                if (!isolateAsterismSelected)
×
565
                {
566
                        for (auto* asterism : asterisms)
×
567
                        {
UNCOV
568
                                asterism->setFlagLines(getFlagLines());
×
UNCOV
569
                                asterism->setFlagLabels(getFlagLabels());
×
570
                        }
571
                }
572
                StelApp::immediateSave("viewing/flag_asterism_isolate_selected", isolate);
×
UNCOV
573
                emit isolateAsterismSelectedChanged(isolate);
×
574
        }
575
}
×
576

UNCOV
577
bool AsterismMgr::getFlagIsolateAsterismSelected(void) const
×
578
{
579
        return isolateAsterismSelected;
×
580
}
581

UNCOV
582
void AsterismMgr::setSelectedAsterism(Asterism *a)
×
583
{
584
        // update states for other asterisms to fade them out
585
        if (a != nullptr)
×
586
        {
UNCOV
587
                selected.push_back(a);
×
588

UNCOV
589
                if (getFlagIsolateAsterismSelected())
×
590
                {
591
                        // Propagate current settings to newly selected asterism
UNCOV
592
                        a->setFlagLines(getFlagLines());
×
UNCOV
593
                        a->setFlagLabels(getFlagLabels());
×
594

595
                        for (auto* asterism : asterisms)
×
596
                        {
UNCOV
597
                                bool match = false;
×
UNCOV
598
                                for (auto* selected_asterisms : selected)
×
599
                                {
600
                                        if (asterism == selected_asterisms)
×
601
                                        {
602
                                                match=true; // this is a selected asterism
×
UNCOV
603
                                                break;
×
604
                                        }
605
                                }
606

607
                                if(!match)
×
608
                                {
609
                                        // Not selected asterism
UNCOV
610
                                        asterism->setFlagLines(false);
×
UNCOV
611
                                        asterism->setFlagLabels(false);
×
612
                                }
613
                        }
614
                }
615
                else
616
                {
UNCOV
617
                        for (auto* asterism : asterisms)
×
618
                        {
619
                                asterism->setFlagLines(false);
×
UNCOV
620
                                asterism->setFlagLabels(false);
×
621
                        }
622

623
                        // Propagate current settings to newly selected asterism
UNCOV
624
                        a->setFlagLines(getFlagLines());
×
625
                        a->setFlagLabels(getFlagLabels());
×
626
                }
627
        }
628
        else
629
        {
UNCOV
630
                if (selected.empty()) return;
×
631

632
                // Otherwise apply standard flags to all asterisms
633
                for (auto* asterism : asterisms)
×
634
                {
UNCOV
635
                        asterism->setFlagLines(getFlagLines());
×
636
                        asterism->setFlagLabels(getFlagLabels());
×
637
                }
638

639
                // And remove all selections
UNCOV
640
                selected.clear();
×
641
        }
642
}
643

644
//! Remove a asterism from the selected asterism list
UNCOV
645
void AsterismMgr::unsetSelectedAsterism(Asterism *a)
×
646
{
647
        if (a != nullptr)
×
648
        {
UNCOV
649
                for (auto iter = selected.begin(); iter != selected.end();)
×
650
                {
UNCOV
651
                        if( (*iter)->getEnglishName().toLower() == a->getEnglishName().toLower() )
×
652
                                iter = selected.erase(iter);
×
653
                        else
UNCOV
654
                                ++iter;
×
655
                }
656

657
                // If no longer any selection, restore all flags on all asterisms
658
                if (selected.empty())
×
659
                {
660
                        // Otherwise apply standard flags to all asterisms
661
                        for (auto* asterism : asterisms)
×
662
                        {
UNCOV
663
                                asterism->setFlagLines(getFlagLines());
×
UNCOV
664
                                asterism->setFlagLabels(getFlagLabels());
×
665
                        }
666
                }
UNCOV
667
                else if(isolateAsterismSelected)
×
668
                {
669
                        // No longer selected asterism
UNCOV
670
                        a->setFlagLines(false);
×
671
                        a->setFlagLabels(false);
×
672
                }
673
        }
UNCOV
674
}
×
675

676
void AsterismMgr::selectAsterism(const QString &englishName)
×
677
{
678
        if (!getFlagIsolateAsterismSelected())
×
UNCOV
679
                setFlagIsolateAsterismSelected(true); // Enable isolated selection
×
680

UNCOV
681
        bool found = false;
×
682
        for (auto* asterism : asterisms)
×
683
        {
684
                if (asterism->getEnglishName().toLower()==englishName.toLower())
×
685
                {
UNCOV
686
                        setSelectedAsterism(asterism);
×
687
                        found = true;
×
UNCOV
688
                        break;
×
689
                }
690
        }
UNCOV
691
        if (!found)
×
692
                qDebug() << "The asterism" << englishName << "is not found";
×
693
}
×
694

UNCOV
695
void AsterismMgr::deselectAsterism(const QString &englishName)
×
696
{
UNCOV
697
        if (!getFlagIsolateAsterismSelected())
×
698
                setFlagIsolateAsterismSelected(true); // Enable isolated selection
×
699

UNCOV
700
        bool found = false;
×
UNCOV
701
        for (auto* asterism : asterisms)
×
702
        {
UNCOV
703
                if (asterism->getEnglishName().toLower()==englishName.toLower())
×
704
                {
705
                        unsetSelectedAsterism(asterism);
×
UNCOV
706
                        found = true;
×
UNCOV
707
                        break;
×
708
                }
709
        }
710

711
        if (selected.size()==0 && found)
×
712
        {
713
                // Let's remove the selection for all asterisms if the list of selected asterisms is empty
714
                for (auto* asterism : asterisms)
×
715
                {
UNCOV
716
                        asterism->setFlagLines(false);
×
717
                        asterism->setFlagLabels(false);
×
718
                }
719
        }
720

721
        if (!found)
×
UNCOV
722
                qDebug() << "The asterism" << englishName << "is not found";
×
723
}
×
724

725
void AsterismMgr::deselectAsterisms(void)
×
726
{
727
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
728
        Q_ASSERT(omgr);
×
729
        if (getFlagIsolateAsterismSelected())
×
730
        {
731
                // The list of selected asterisms is empty, but...
732
                if (selected.size()==0)
×
733
                {
734
                        // ...let's unselect all asterisms for guarantee
735
                        for (auto* asterism : asterisms)
×
736
                        {
UNCOV
737
                                asterism->setFlagLines(false);
×
738
                                asterism->setFlagLabels(false);
×
739
                        }
740
                }
741

742
                // If any asterism is selected at the moment, then let's do not touch to it!
UNCOV
743
                if (omgr->getWasSelected() && !selected.empty())
×
744
                        selected.pop_back();
×
745

746
                // Let's hide all previously selected asterisms
747
                for (auto* asterism : selected)
×
748
                {
UNCOV
749
                        asterism->setFlagLines(false);
×
750
                        asterism->setFlagLabels(false);
×
751
                }
752
        }
753
        else
754
        {
UNCOV
755
                const QList<StelObjectP> newSelectedConst = omgr->getSelectedObject("Asterism");
×
756
                if (!newSelectedConst.empty())
×
UNCOV
757
                        omgr->unSelect();
×
758
        }
×
UNCOV
759
        selected.clear();
×
760
}
×
761

UNCOV
762
void AsterismMgr::selectAllAsterisms()
×
763
{
UNCOV
764
        for (auto* asterism : asterisms)
×
765
                setSelectedAsterism(asterism);
×
UNCOV
766
}
×
767

UNCOV
768
void AsterismMgr::selectedObjectChange(StelModule::StelModuleSelectAction action)
×
769
{
770
        StelObjectMgr* omgr = GETSTELMODULE(StelObjectMgr);
×
UNCOV
771
        Q_ASSERT(omgr);
×
772
        const QList<StelObjectP> newSelected = omgr->getSelectedObject();
×
UNCOV
773
        if (newSelected.empty())
×
774
                return;
×
775

776
        const QList<StelObjectP> newSelectedAsterisms = omgr->getSelectedObject("Asterism");
×
UNCOV
777
        if (!newSelectedAsterisms.empty())
×
778
        {
779
                // If removing this selection
780
                if(action == StelModule::RemoveFromSelection)
×
781
                        unsetSelectedAsterism(static_cast<Asterism *>(newSelectedAsterisms[0].data()));
×
782
                else // Add asterism to selected list (do not select a star, just the constellation)
783
                        setSelectedAsterism(static_cast<Asterism *>(newSelectedAsterisms[0].data()));
×
784
        }
785
}
×
786

787
void AsterismMgr::switchSelectionMode()
×
788
{
UNCOV
789
        bool state = getFlagIsolateAsterismSelected();
×
790
        setFlagIsolateAsterismSelected(!state);
×
UNCOV
791
        if (!state)
×
792
                deselectAsterisms();
×
UNCOV
793
}
×
794

UNCOV
795
void AsterismMgr::setLinesFadeDuration(const float duration)
×
796
{
UNCOV
797
        if (!qFuzzyCompare(linesFadeDuration, duration))
×
798
        {
UNCOV
799
                linesFadeDuration = duration;
×
800

801
                for (auto* asterism : asterisms)
×
802
                {
803
                        asterism->lineFader.setDuration(static_cast<int>(duration * 1000.f));
×
804
                }
805
                StelApp::immediateSave("viewing/asterism_lines_fade_duration", duration);
×
UNCOV
806
                emit linesFadeDurationChanged(duration);
×
807
        }
UNCOV
808
}
×
809

UNCOV
810
float AsterismMgr::getLinesFadeDuration() const
×
811
{
UNCOV
812
        return linesFadeDuration;
×
813
}
814

UNCOV
815
void AsterismMgr::setLabelsFadeDuration(const float duration)
×
816
{
UNCOV
817
        if (!qFuzzyCompare(namesFadeDuration, duration))
×
818
        {
UNCOV
819
                namesFadeDuration = duration;
×
820

UNCOV
821
                for (auto* asterism : asterisms)
×
822
                {
UNCOV
823
                        asterism->nameFader.setDuration(static_cast<int>(duration * 1000.f));
×
824
                }
UNCOV
825
                StelApp::immediateSave("viewing/asterism_labels_fade_duration", duration);
×
UNCOV
826
                emit namesFadeDurationChanged(duration);
×
827
        }
UNCOV
828
}
×
829

UNCOV
830
float AsterismMgr::getLabelsFadeDuration() const
×
831
{
UNCOV
832
        return namesFadeDuration;
×
833
}
834

UNCOV
835
void AsterismMgr::setRayHelpersFadeDuration(const float duration)
×
836
{
UNCOV
837
        if (!qFuzzyCompare(rayHelpersFadeDuration, duration))
×
838
        {
UNCOV
839
                rayHelpersFadeDuration = duration;
×
840

UNCOV
841
                for (auto* asterism : asterisms)
×
842
                {
UNCOV
843
                        asterism->rayHelperFader.setDuration(static_cast<int>(duration * 1000.f));
×
844
                }
UNCOV
845
                StelApp::immediateSave("viewing/rayhelper_lines_fade_duration", duration);
×
UNCOV
846
                emit rayHelpersFadeDurationChanged(duration);
×
847
        }
UNCOV
848
}
×
849

UNCOV
850
float AsterismMgr::getRayHelpersFadeDuration() const
×
851
{
UNCOV
852
        return rayHelpersFadeDuration;
×
853
}
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