11#include " ScmConstellation.hpp"
22
3- scm::ScmConstellation::ScmConstellation (std::vector<scm::CoordinateLine> coordinates, std::vector<scm::StarLine> stars)
3+ scm::ScmConstellation::ScmConstellation (const std::vector<scm::CoordinateLine> &coordinates,
4+ const std::vector<scm::StarLine> &stars)
45 : constellationCoordinates(coordinates)
56 , constellationStars(stars)
67{
7- QSettings* conf = StelApp::getInstance ().getSettings ();
8+ QSettings * conf = StelApp::getInstance ().getSettings ();
89 constellationLabelFont.setPixelSize (conf->value (" viewing/constellation_font_size" , 15 ).toInt ());
9-
10+
1011 QString defaultColor = conf->value (" color/default_color" , " 0.5,0.5,0.7" ).toString ();
11- colorDrawDefault = Vec3f (conf->value (" color/const_lines_color" , defaultColor).toString ());
12- colorLabelDefault = Vec3f (conf->value (" color/const_names_color" , defaultColor).toString ());
12+ colorDrawDefault = Vec3f (conf->value (" color/const_lines_color" , defaultColor).toString ());
13+ colorLabelDefault = Vec3f (conf->value (" color/const_names_color" , defaultColor).toString ());
14+
15+ updateTextPosition ();
1316}
1417
15- void scm::ScmConstellation::setId (QString id)
18+ void scm::ScmConstellation::setId (const QString & id)
1619{
1720 ScmConstellation::id = id;
1821}
@@ -22,7 +25,7 @@ QString scm::ScmConstellation::getId() const
2225 return id;
2326}
2427
25- void scm::ScmConstellation::setEnglishName (QString name)
28+ void scm::ScmConstellation::setEnglishName (const QString & name)
2629{
2730 englishName = name;
2831}
@@ -32,56 +35,54 @@ QString scm::ScmConstellation::getEnglishName() const
3235 return englishName;
3336}
3437
35- void scm::ScmConstellation::setNativeName (std::optional<QString> name)
38+ void scm::ScmConstellation::setNativeName (const std::optional<QString> & name)
3639{
3740 nativeName = name;
3841}
3942
40- void scm::ScmConstellation::setPronounce (std::optional<QString> pronounce)
43+ void scm::ScmConstellation::setPronounce (const std::optional<QString> & pronounce)
4144{
4245 ScmConstellation::pronounce = pronounce;
4346}
4447
45- void scm::ScmConstellation::setIPA (std::optional<QString> ipa)
48+ void scm::ScmConstellation::setIPA (const std::optional<QString> & ipa)
4649{
4750 ScmConstellation::ipa = ipa;
4851}
4952
50- void scm::ScmConstellation::setConstellation (std::vector<CoordinateLine> coordinates, std::vector<StarLine> stars)
53+ void scm::ScmConstellation::setConstellation (const std::vector<CoordinateLine> &coordinates,
54+ const std::vector<StarLine> &stars)
5155{
5256 constellationCoordinates = coordinates;
53- constellationStars = stars;
57+ constellationStars = stars;
58+
59+ updateTextPosition ();
5460}
5561
56- void scm::ScmConstellation::drawConstellation (StelCore *core, Vec3f color)
62+ void scm::ScmConstellation::drawConstellation (StelCore *core, const Vec3f & color) const
5763{
5864 StelPainter painter (core->getProjection (drawFrame));
5965 painter.setBlending (true );
6066 painter.setLineSmooth (true );
6167 painter.setFont (constellationLabelFont);
62-
68+
6369 bool alpha = 1 .0f ;
6470 painter.setColor (color, alpha);
6571
66- XYZname.set (0 .,0 .,0 .);
6772 for (CoordinateLine p : constellationCoordinates)
6873 {
6974 painter.drawGreatCircleArc (p.start , p.end );
70- XYZname += p.end ;
71- XYZname += p.start ;
7275 }
7376
74- XYZname.normalize ();
75-
76- drawNames (core, painter, colorLabelDefault);
77+ drawNames (core, painter);
7778}
7879
79- void scm::ScmConstellation::drawConstellation (StelCore *core)
80+ void scm::ScmConstellation::drawConstellation (StelCore *core) const
8081{
8182 drawConstellation (core, colorDrawDefault);
8283}
8384
84- void scm::ScmConstellation::drawNames (StelCore *core, StelPainter sPainter , Vec3f labelColor)
85+ void scm::ScmConstellation::drawNames (StelCore *core, StelPainter & sPainter , const Vec3f & labelColor) const
8586{
8687 sPainter .setBlending (true );
8788
@@ -91,26 +92,27 @@ void scm::ScmConstellation::drawNames(StelCore *core, StelPainter sPainter, Vec3
9192 velocityObserver = core->getAberrationVec (core->getJDE ());
9293 }
9394
94- XYZname+=velocityObserver;
95- XYZname.normalize ();
95+ Vec3d namePose = XYZname;
96+ namePose += velocityObserver;
97+ namePose.normalize ();
9698
97- if (!sPainter .getProjector ()->projectCheck (XYZname, this ->XYname ))
99+ Vec3d XYname;
100+ if (!sPainter .getProjector ()->projectCheck (XYZname, XYname))
98101 {
99102 return ;
100103 }
101104
102- sPainter .getProjector ()->project (XYZname, XYname);
103105 sPainter .setColor (labelColor, 1 .0f );
104- sPainter .drawText (static_cast <float >(XYname[0 ]), static_cast <float >(XYname[1 ]), englishName, 0 ., -sPainter .getFontMetrics ().boundingRect (englishName).width ()/2 , 0 , false );
106+ sPainter .drawText (static_cast <float >(XYname[0 ]), static_cast <float >(XYname[1 ]), englishName, 0 .,
107+ -sPainter .getFontMetrics ().boundingRect (englishName).width () / 2 , 0 , false );
105108}
106109
107- void scm::ScmConstellation::drawNames (StelCore *core, StelPainter sPainter )
110+ void scm::ScmConstellation::drawNames (StelCore *core, StelPainter & sPainter ) const
108111{
109112 drawNames (core, sPainter , colorLabelDefault);
110113}
111114
112-
113- QJsonObject scm::ScmConstellation::toJson (QString &skyCultureName) const
115+ QJsonObject scm::ScmConstellation::toJson (const QString &skyCultureName) const
114116{
115117 QJsonObject json;
116118
@@ -120,7 +122,7 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
120122 if (constellationStars.size () != 0 )
121123 {
122124 // Stars are NOT empty
123- for (const auto &star: constellationStars)
125+ for (const auto &star : constellationStars)
124126 {
125127 linesArray.append (star.toJson ());
126128 }
@@ -134,7 +136,7 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
134136 }
135137 }
136138
137- json[" id" ] = " CON " + skyCultureName + " " + id;
139+ json[" id" ] = " CON " + skyCultureName + " " + id;
138140 json[" lines" ] = linesArray;
139141
140142 // Assemble common name object
@@ -155,7 +157,7 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
155157 if (references.has_value () && !references->isEmpty ())
156158 {
157159 QJsonArray refsArray;
158- for (const auto & ref : references.value ())
160+ for (const auto & ref : references.value ())
159161 {
160162 refsArray.append (ref);
161163 }
@@ -164,4 +166,15 @@ QJsonObject scm::ScmConstellation::toJson(QString &skyCultureName) const
164166 json[" common_name" ] = commonNameObj;
165167
166168 return json;
167- }
169+ }
170+
171+ void scm::ScmConstellation::updateTextPosition ()
172+ {
173+ XYZname.set (0 ., 0 ., 0 .);
174+ for (CoordinateLine p : constellationCoordinates)
175+ {
176+ XYZname += p.end ;
177+ XYZname += p.start ;
178+ }
179+ XYZname.normalize ();
180+ }
0 commit comments