-
-
Notifications
You must be signed in to change notification settings - Fork 865
/
Copy pathConstellationMgr.hpp
435 lines (381 loc) · 18.4 KB
/
ConstellationMgr.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/*
* Stellarium
* Copyright (C) 2002 Fabien Chereau
* Copyright (C) 2012 Timothy Reaves
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#ifndef CONSTELLATIONMGR_HPP
#define CONSTELLATIONMGR_HPP
#include "StelObjectType.hpp"
#include "StelObjectModule.hpp"
#include "StelObject.hpp"
#include <vector>
#include <QString>
#include <QStringList>
#include <QFont>
class StelToneReproducer;
class StarMgr;
class Constellation;
class StelProjector;
class StelPainter;
class StelSkyCulture;
//! @class ConstellationMgr
//! Display and manage the constellations.
//! It can display constellations lines, names, art textures and boundaries.
//! It also supports several different sky cultures.
class ConstellationMgr : public StelObjectModule
{
Q_OBJECT
Q_PROPERTY(bool artDisplayed
READ getFlagArt
WRITE setFlagArt
NOTIFY artDisplayedChanged)
Q_PROPERTY(float artFadeDuration
READ getArtFadeDuration
WRITE setArtFadeDuration
NOTIFY artFadeDurationChanged)
Q_PROPERTY(float artIntensity
READ getArtIntensity
WRITE setArtIntensity
NOTIFY artIntensityChanged)
Q_PROPERTY(Vec3f boundariesColor
READ getBoundariesColor
WRITE setBoundariesColor
NOTIFY boundariesColorChanged)
Q_PROPERTY(bool boundariesDisplayed
READ getFlagBoundaries
WRITE setFlagBoundaries
NOTIFY boundariesDisplayedChanged)
Q_PROPERTY(int fontSize
READ getFontSize
WRITE setFontSize
NOTIFY fontSizeChanged)
Q_PROPERTY(bool isolateSelected
READ getFlagIsolateSelected
WRITE setFlagIsolateSelected
NOTIFY isolateSelectedChanged)
Q_PROPERTY(bool flagConstellationPick
READ getFlagConstellationPick
WRITE setFlagConstellationPick
NOTIFY flagConstellationPickChanged)
Q_PROPERTY(Vec3f linesColor
READ getLinesColor
WRITE setLinesColor
NOTIFY linesColorChanged)
Q_PROPERTY(bool linesDisplayed
READ getFlagLines
WRITE setFlagLines
NOTIFY linesDisplayedChanged)
Q_PROPERTY(Vec3f namesColor
READ getLabelsColor
WRITE setLabelsColor
NOTIFY namesColorChanged)
Q_PROPERTY(bool namesDisplayed
READ getFlagLabels
WRITE setFlagLabels
NOTIFY namesDisplayedChanged)
Q_PROPERTY(StelObject::CulturalDisplayStyle constellationDisplayStyle
READ getConstellationDisplayStyle
WRITE setConstellationDisplayStyle
NOTIFY constellationsDisplayStyleChanged)
Q_PROPERTY(int constellationLineThickness
READ getConstellationLineThickness
WRITE setConstellationLineThickness
NOTIFY constellationLineThicknessChanged)
Q_PROPERTY(int constellationBoundariesThickness
READ getConstellationBoundariesThickness
WRITE setConstellationBoundariesThickness
NOTIFY constellationBoundariesThicknessChanged)
public:
//! Constructor
ConstellationMgr(StarMgr *stars);
//! Destructor
~ConstellationMgr() override;
///////////////////////////////////////////////////////////////////////////
// Methods defined in the StelModule class
//! Initialize the ConstellationMgr.
//! Reads from the configuration parser object and updates the loading bar
//! as constellation objects are loaded for the required sky culture.
void init() override;
//! Draw constellation lines, art, names and boundaries.
void draw(StelCore* core) override;
//! Updates time-varying state for each Constellation.
void update(double deltaTime) override;
//! Return the value defining the order of call for the given action
//! @param actionName the name of the action for which we want the call order
//! @return the value defining the order. The closer to 0 the earlier the module's action will be called
double getCallOrder(StelModuleActionName actionName) const override;
///////////////////////////////////////////////////////////////////////////
// Methods defined in StelObjectModule class
QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const override;
//! @return the matching constellation object's pointer if exists or Q_NULLPTR
//! @param nameI18n The case in-sensitive constellation name
StelObjectP searchByNameI18n(const QString& nameI18n) const override;
//! @return the matching constellation if exists or Q_NULLPTR
//! @param name The case in-sensitive standard program name (three letter abbreviation)
StelObjectP searchByName(const QString& name) const override;
StelObjectP searchByID(const QString &id) const override;
QStringList listAllObjects(bool inEnglish) const override;
QString getName() const override { return "Constellations"; }
QString getStelObjectType() const override;
// Moved to become StelObject::CulturalDisplayStyle, Then apply maybe even separately to Constellations and Planets, and whether applied to screen labels or infoString.
// Describes how to display constellation labels. The viewDialog GUI has a combobox which corresponds to these values.
// TODO: This could of course become a bitfield, but having just discrete options may still be easier to maintain.
//enum ConstellationDisplayStyle
//{
// Abbreviated = 0, // short label
// Native = 1, // may show non-Latin glyphs
// Translated = 2, // user language
// English = 3, // Useful in case of adding names in modern English terminology (planets etc.). Maybe "Modern" would be better, and should show object scientific name in modern terminology, translated.
// Pronounce = 4, // user-language transliteration/pronunciation aid. Usually the original form like pinyin is also used in users' languages, but it may be translatable to user language, e.g. for other coding system.
//};
//Q_ENUM(ConstellationDisplayStyle)
///////////////////////////////////////////////////////////////////////////
// Properties setters and getters
public slots:
//! Set whether constellation art will be displayed
void setFlagArt(const bool displayed);
//! Get whether constellation art is displayed
bool getFlagArt(void) const;
//! Set constellation art fade duration in second
void setArtFadeDuration(const float duration);
//! Get constellation art fade duration in second
float getArtFadeDuration() const;
//! Set constellation maximum art intensity (between 0 and 1)
//! Note that the art intensity is linearly faded out if the FOV is in a specific interval,
//! which can be adjusted using setArtIntensityMinimumFov() and setArtIntensityMaximumFov()
void setArtIntensity(const float intensity);
//! Return constellation maximum art intensity (between 0 and 1)
//! Note that the art intensity is linearly faded out if the FOV is in a specific interval,
//! which can be adjusted using setArtIntensityMinimumFov() and setArtIntensityMaximumFov()
float getArtIntensity() const;
//! Sets the lower bound on the FOV at which the art intensity fades to zero.
//! See LP:#1294483. The default is 1.0.
void setArtIntensityMinimumFov(const double fov);
//! Returns the lower bound on the FOV at which the art intensity fades to zero.
//! See LP:#1294483. The default is 1.0.
double getArtIntensityMinimumFov() const;
//! Sets the upper bound on the FOV at which the art intensity becomes the maximum
//! set by setArtIntensity()
//! See LP:#1294483. The default is 2.0.
void setArtIntensityMaximumFov(const double fov);
//! Returns the upper bound on the FOV at which the art intensity becomes the maximum
//! set by setArtIntensity()
//! See LP:#1294483. The default is 2.0.
double getArtIntensityMaximumFov() const;
//! Define boundary color
//! @param color The color of boundaries
//! @code
//! // example of usage in scripts
//! ConstellationMgr.setBoundariesColor(Vec3f(1.0,0.0,0.0));
//! @endcode
void setBoundariesColor(const Vec3f& color);
//! Get current boundary color
Vec3f getBoundariesColor() const;
//! Set whether constellation boundaries lines will be displayed
void setFlagBoundaries(const bool displayed);
//! Get whether constellation boundaries lines are displayed
bool getFlagBoundaries(void) const;
//! Set whether selected constellation must be displayed alone
void setFlagIsolateSelected(const bool isolate);
//! Get whether selected constellation is displayed alone
bool getFlagIsolateSelected(void) const;
//! Set whether only one selected constellation must be displayed
void setFlagConstellationPick(const bool mode);
//! Get whether only one selected constellation is displayed
bool getFlagConstellationPick(void) const;
//! Define line color
//! @param color The color of lines
//! @code
//! // example of usage in scripts
//! ConstellationMgr.setLinesColor(Vec3f(1.0,0.0,0.0));
//! @endcode
void setLinesColor(const Vec3f& color);
//! Get line color
Vec3f getLinesColor() const;
//! Set whether constellation lines will be displayed
void setFlagLines(const bool displayed);
//! Get whether constellation lines are displayed
bool getFlagLines(void) const;
//! Set label color for names
//! @param color The color of labels
//! @code
//! // example of usage in scripts
//! ConstellationMgr.setLabelsColor(Vec3f(1.0,0.0,0.0));
//! @endcode
void setLabelsColor(const Vec3f& color);
//! Get label color for names
Vec3f getLabelsColor() const;
//! Set whether constellation names will be displayed
void setFlagLabels(const bool displayed);
//! Set whether constellation names are displayed
bool getFlagLabels(void) const;
//! Set the font size used for constellation names display
void setFontSize(const int newFontSize);
//! Get the font size used for constellation names display
int getFontSize() const;
//! Set the way how constellation names are displayed: abbreviated/as-given/translated
//! @param style the new display style
void setConstellationDisplayStyle(StelObject::CulturalDisplayStyle style);
//! get the way how constellation names are displayed: abbreviated/as-given/translated
StelObject::CulturalDisplayStyle getConstellationDisplayStyle();
//! Returns the currently set constellation display style as string, instead of enum
//! @see getConstellationDisplayStyle()
static QString getConstellationDisplayStyleString(StelObject::CulturalDisplayStyle style);
//! Set the thickness of lines of the constellations
//! @param thickness of line in pixels
void setConstellationLineThickness(const int thickness);
//! Get the thickness of lines of the constellations
int getConstellationLineThickness() const { return constellationLineThickness; }
//! Set the thickness of boundaries of the constellations
//! @param thickness of line in pixels
void setConstellationBoundariesThickness(const int thickness);
//! Get the thickness of boundaries of the constellations
int getConstellationBoundariesThickness() const { return constellationBoundariesThickness; }
//! Remove constellations from selected objects
void deselectConstellations(void);
//! Select all constellations
void selectAllConstellations(void);
//! Select the constellation by his English name. Calling this method will enable
//! isolated selection for the constellations if it is not enabled yet.
//! @param englishName the English name of the constellation
//! @code
//! // example of usage in scripts: select the Orion constellation
//! ConstellationMgr.selectConstellation("Orion");
//! @endcode
void selectConstellation(const QString& englishName);
//! Select the constellation where celestial body with English name is located.
//! Calling this method will enable isolated selection for the constellations if it is
//! not enabled yet.
//! @param englishName the English name of the celestial body
//! @code
//! // example of usage in scripts: select constellation where Venus is located
//! ConstellationMgr.selectConstellationByObjectName("Venus");
//! @endcode
//! @note the method will be correct work for sky cultures with boundaries
//! otherwise you may use star names from constellation lines as celestial body
void selectConstellationByObjectName(const QString& englishName);
//! Remove the constellation from list of selected constellations by his English
//! name. Calling this method will enable isolated selection for the constellations
//! if it is not enabled yet.
//! @param englishName the English name of the constellation
//! @code
//! // example of usage in scripts: remove selection from the Orion constellation
//! ConstellationMgr.deselectConstellation("Orion");
//! @endcode
//! @note all constellations will be hidden when list of selected constellations will be empty
void deselectConstellation(const QString& englishName);
//! Get the list of English names of all constellations for loaded sky culture
QStringList getConstellationsEnglishNames();
signals:
void artDisplayedChanged(const bool displayed);
void artFadeDurationChanged(const float duration);
void artIntensityChanged(const double intensity);
void boundariesColorChanged(const Vec3f & color);
void boundariesDisplayedChanged(const bool displayed);
void fontSizeChanged(const int newSize);
void isolateSelectedChanged(const bool isolate);
void flagConstellationPickChanged(const bool mode);
void linesColorChanged(const Vec3f & color);
void linesDisplayedChanged(const bool displayed);
void namesColorChanged(const Vec3f & color);
void namesDisplayedChanged(const bool displayed);
void constellationsDisplayStyleChanged(const StelObject::CulturalDisplayStyle style);
void constellationLineThicknessChanged(int thickness);
void constellationBoundariesThicknessChanged(int thickness);
private slots:
//! Limit the number of constellations to draw based on selected stars.
//! The selected objects changed, check if some stars are selected and display the
//! matching constellations if isolateSelected mode is activated.
//! @param action define whether to add to, replace, or remove from the existing selection
void selectedObjectChange(StelModule::StelModuleSelectAction action);
//! Loads new constellation data and art if the SkyCulture has changed.
//! @param skyCultureDir the name of the directory containing the sky culture to use.
void updateSkyCulture(const StelSkyCulture& skyCulture);
//! Update i18n names from English names according to current
//! locale, and update font for locale.
//! The translation is done using gettext with translated strings defined
//! in translations.h
void updateI18n();
void reloadSkyCulture(void);
private:
void setFlagCheckLoadingData(const bool flag) { checkLoadingData = flag; }
bool getFlagCheckLoadingData(void) const { return checkLoadingData; }
//! Load constellation line shapes, art textures and boundaries shapes from data files.
//! @param constellationsData The structure describing all the constellations
void loadLinesNamesAndArt(const QJsonArray& constellationsData, const StelSkyCulture& culture, bool preferNativeNames);
//! Load the constellation boundary file.
//! This function deletes any currently loaded constellation boundaries
//! and loads a new set from the data passed as the parameter.
//! @param epoch: Specified as JSON key "edges_epoch".
//! Can be "Bxxxx.x" (Besselian year), "Jxxxx.x" (Julian year), "JDjjjjjjjj.jjj" (Julian day number) and pure doubles as JD.
//! The most common cases, "B1875" (for IAU boundaries) and "J2000" are handled most efficiently.
bool loadBoundaries(const QJsonArray& boundaryData, const QString& epoch);
//! Draw the constellation lines at the epoch given by the StelCore.
void drawLines(StelPainter& sPainter, const StelCore* core) const;
//! Draw the constellation art. obsVelocity required for aberration
void drawArt(StelPainter& sPainter, const Vec3d &obsVelocity) const;
//! Draw the constellation name labels.
void drawNames(StelPainter& sPainter, const Vec3d &obsVelocity) const;
//! Draw the constellation boundaries.
//! @param obsVelocity is the speed vector of the observer planet to distort boundaries by aberration.
void drawBoundaries(StelPainter& sPainter, const Vec3d &obsVelocity) const;
//! Handle single and multi-constellation selections.
void setSelectedConst(Constellation* c);
//! Handle unselecting a single constellation.
void unsetSelectedConst(Constellation* c);
//! Define which constellation is selected from its abbreviation.
void setSelected(const QString& abbreviation);
//! Define which constellation is selected and return brightest star.
StelObjectP setSelectedStar(const QString& abbreviation);
//! Define which constellation is selected from a star number.
void setSelected(const StelObject* s);
//! Remove all selected constellations.
void deselect() { setSelected(Q_NULLPTR); }
//! Get the first selected constellation.
//! NOTE: this function should return a list of all, or may be deleted. Please
//! do not use until it exhibits the proper behavior.
StelObject* getSelected(void) const;
std::vector<Constellation*> selected; // More than one can be selected at a time
Constellation* isStarIn(const StelObject *s) const;
Constellation* isObjectIn(const StelObject *s) const;
Constellation* findFromAbbreviation(const QString& abbreviation) const;
std::vector<Constellation*> constellations;
QFont asterFont;
StarMgr* hipStarMgr;
bool isolateSelected; // true to pick individual constellations.
bool flagConstellationPick; // TODO: CLEAR DESCRIPTION
std::vector<std::vector<Vec3d> *> allBoundarySegments;
QStringList constellationsEnglishNames;
//! this controls how constellations (and also star names) are printed: Abbreviated/as-given/translated
StelObject::CulturalDisplayStyle constellationDisplayStyle;
static const QMap<QString, StelObject::CulturalDisplayStyle>ConstellationDisplayStyleMap;
// These are THE master settings - individual constellation settings can vary based on selection status
float artFadeDuration;
float artIntensity;
double artIntensityMinimumFov;
double artIntensityMaximumFov;
bool artDisplayed;
bool boundariesDisplayed;
bool linesDisplayed;
bool namesDisplayed;
bool checkLoadingData;
// Store the thickness of lines of the constellations
int constellationLineThickness;
// Store the thickness of boundaries of the constellations
int constellationBoundariesThickness;
};
#endif // CONSTELLATIONMGR_HPP