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

Stellarium / stellarium / 15670918640

16 Jun 2025 02:08AM UTC coverage: 11.775% (-0.2%) from 11.931%
15670918640

push

github

alex-w
Updated data

14700 of 124846 relevant lines covered (11.77%)

18324.52 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 "StelCore.hpp"
31
#include "StelPainter.hpp"
32
#include "Planet.hpp"
33

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

192
                // Set current states
193
                setFlagLines(linesDisplayed);
×
194
                setFlagLabels(namesDisplayed);
×
195
                setFlagRayHelpers(rayHelpersDisplayed);
×
196
        }
×
197

198
        // Translate asterism names for the new sky culture
199
        updateI18n();
×
200
}
×
201

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

211
Vec3f AsterismMgr::getLinesColor() const
×
212
{
213
        return Asterism::lineColor;
×
214
}
215

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

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

230

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

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

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

255
int AsterismMgr::getFontSize() const
×
256
{
257
        return asterFont.pixelSize();
×
258
}
259

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

268
                StelApp::immediateSave("viewing/asterism_line_thickness", thickness);
×
269
                emit asterismLineThicknessChanged(thickness);
×
270
        }
271
}
×
272

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

281
                StelApp::immediateSave("viewing/rayhelper_line_thickness", thickness);
×
282
                emit rayHelperThicknessChanged(thickness);
×
283
        }
284
}
×
285

286
void AsterismMgr::draw(StelCore* core)
×
287
{
288
        const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
×
289
        StelPainter sPainter(prj);
×
290
        sPainter.setFont(asterFont);
×
291
        drawLines(sPainter, core);
×
292
        drawRayHelpers(sPainter, core);
×
293
        Vec3d vel(0.);
×
294
        if (core->getUseAberration())
×
295
        {
296
                vel = core->getAberrationVec(core->getJDE());
×
297
        }
298
        drawNames(sPainter, vel);
×
299
}
×
300

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

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

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

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

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

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

347
// Draw the names of all the asterisms
348
void AsterismMgr::drawNames(StelPainter& sPainter, const Vec3d &obsVelocity) const
×
349
{
350
        if (!hasAsterism)
×
351
                return;
×
352

353
        sPainter.setBlending(true);
×
354
        for (auto* asterism : asterisms)
×
355
        {
356
                if (!asterism->flagAsterism) continue;
×
357

358
                for (int i=0; i<asterism->XYZname.size(); ++i)
×
359
                {
360
                        Vec3d XYZname=asterism->XYZname.at(i);
×
361
                        XYZname.normalize();
×
362
                        XYZname+=obsVelocity;
×
363
                        XYZname.normalize();
×
364

365
                        Vec3d xyName;
×
366
                        // Check if in the field of view
367
                        if (sPainter.getProjector()->projectCheck(XYZname, xyName))
×
368
                                asterism->drawName(xyName, sPainter);
×
369
                }
370
        }
371
}
372

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

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

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

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

444
bool AsterismMgr::getFlagLines(void) const
×
445
{
446
        return linesDisplayed;
×
447
}
448

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

463
bool AsterismMgr::getFlagRayHelpers(void) const
×
464
{
465
        return rayHelpersDisplayed;
×
466
}
467

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

488
bool AsterismMgr::getFlagLabels(void) const
×
489
{
490
        return namesDisplayed;
×
491
}
492

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

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

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

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

549
QString AsterismMgr::getStelObjectType() const
×
550
{
551
        return Asterism::ASTERISM_TYPE;
×
552
}
553

554
void AsterismMgr::setFlagIsolateAsterismSelected(const bool isolate)
×
555
{
556
        if (isolateAsterismSelected != isolate)
×
557
        {
558
                isolateAsterismSelected = isolate;
×
559

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

574
bool AsterismMgr::getFlagIsolateAsterismSelected(void) const
×
575
{
576
        return isolateAsterismSelected;
×
577
}
578

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

586
                if (getFlagIsolateAsterismSelected())
×
587
                {
588
                        // Propagate current settings to newly selected asterism
589
                        a->setFlagLines(getFlagLines());
×
590
                        a->setFlagLabels(getFlagLabels());
×
591

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

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

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

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

636
                // And remove all selections
637
                selected.clear();
×
638
        }
639
}
640

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

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

673
void AsterismMgr::selectAsterism(const QString &englishName)
×
674
{
675
        if (!getFlagIsolateAsterismSelected())
×
676
                setFlagIsolateAsterismSelected(true); // Enable isolated selection
×
677

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

692
void AsterismMgr::deselectAsterism(const QString &englishName)
×
693
{
694
        if (!getFlagIsolateAsterismSelected())
×
695
                setFlagIsolateAsterismSelected(true); // Enable isolated selection
×
696

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

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

718
        if (!found)
×
719
                qDebug() << "The asterism" << englishName << "is not found";
×
720
}
×
721

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

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

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

759
void AsterismMgr::selectAllAsterisms()
×
760
{
761
        for (auto* asterism : asterisms)
×
762
                setSelectedAsterism(asterism);
×
763
}
×
764

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

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

784
void AsterismMgr::switchSelectionMode()
×
785
{
786
        bool state = getFlagIsolateAsterismSelected();
×
787
        setFlagIsolateAsterismSelected(!state);
×
788
        if (!state)
×
789
                deselectAsterisms();
×
790
}
×
791

792
void AsterismMgr::setLinesFadeDuration(const float duration)
×
793
{
794
        if (!qFuzzyCompare(linesFadeDuration, duration))
×
795
        {
796
                linesFadeDuration = duration;
×
797

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

807
float AsterismMgr::getLinesFadeDuration() const
×
808
{
809
        return linesFadeDuration;
×
810
}
811

812
void AsterismMgr::setLabelsFadeDuration(const float duration)
×
813
{
814
        if (!qFuzzyCompare(namesFadeDuration, duration))
×
815
        {
816
                namesFadeDuration = duration;
×
817

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

827
float AsterismMgr::getLabelsFadeDuration() const
×
828
{
829
        return namesFadeDuration;
×
830
}
831

832
void AsterismMgr::setRayHelpersFadeDuration(const float duration)
×
833
{
834
        if (!qFuzzyCompare(rayHelpersFadeDuration, duration))
×
835
        {
836
                rayHelpersFadeDuration = duration;
×
837

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

847
float AsterismMgr::getRayHelpersFadeDuration() const
×
848
{
849
        return rayHelpersFadeDuration;
×
850
}
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