Skip to content

Commit 31b8a7c

Browse files
authored
feat: edit constellations (#128)
1 parent 191d319 commit 31b8a7c

18 files changed

Lines changed: 841 additions & 472 deletions

plugins/SkyCultureMaker/src/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ SET( SkyCultureMaker_SRCS
3030
gui/ScmConstellationDialog.cpp
3131
gui/ScmSkyCultureDialog.hpp
3232
gui/ScmSkyCultureDialog.cpp
33-
gui/ScmImageAnchor.hpp
34-
gui/ScmImageAnchor.cpp
35-
gui/ScmImageAnchored.hpp
36-
gui/ScmImageAnchored.cpp
33+
gui/ScmConstellationImageAnchor.hpp
34+
gui/ScmConstellationImageAnchor.cpp
35+
gui/ScmConstellationImage.hpp
36+
gui/ScmConstellationImage.cpp
3737
gui/ScmSkyCultureExportDialog.hpp
3838
gui/ScmSkyCultureExportDialog.cpp
3939
gui/ScmHideOrAbortMakerDialog.hpp

plugins/SkyCultureMaker/src/ScmConstellation.cpp

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
scm::ScmConstellation::ScmConstellation(const std::vector<scm::CoordinateLine> &coordinates,
2929
const std::vector<scm::StarLine> &stars)
30-
: constellationCoordinates(coordinates)
31-
, constellationStars(stars)
30+
: coordinates(coordinates)
31+
, stars(stars)
3232
{
3333
QSettings *conf = StelApp::getInstance().getSettings();
3434
constellationNameFont.setPixelSize(conf->value("viewing/constellation_font_size", 15).toInt());
@@ -65,32 +65,66 @@ void scm::ScmConstellation::setNativeName(const std::optional<QString> &name)
6565
nativeName = name;
6666
}
6767

68+
std::optional<QString> scm::ScmConstellation::getNativeName() const
69+
{
70+
return nativeName;
71+
}
72+
6873
void scm::ScmConstellation::setPronounce(const std::optional<QString> &pronounce)
6974
{
7075
ScmConstellation::pronounce = pronounce;
7176
}
7277

78+
std::optional<QString> scm::ScmConstellation::getPronounce() const
79+
{
80+
return pronounce;
81+
}
82+
7383
void scm::ScmConstellation::setIPA(const std::optional<QString> &ipa)
7484
{
7585
ScmConstellation::ipa = ipa;
7686
}
7787

88+
std::optional<QString> scm::ScmConstellation::getIPA() const
89+
{
90+
return ipa;
91+
}
92+
7893
void scm::ScmConstellation::setArtwork(const ScmConstellationArtwork &artwork)
7994
{
8095
ScmConstellation::artwork = artwork;
8196
}
8297

98+
const scm::ScmConstellationArtwork &scm::ScmConstellation::getArtwork() const
99+
{
100+
return artwork;
101+
}
102+
83103
void scm::ScmConstellation::setConstellation(const std::vector<CoordinateLine> &coordinates,
84104
const std::vector<StarLine> &stars)
85105
{
86-
constellationCoordinates = coordinates;
87-
constellationStars = stars;
106+
scm::ScmConstellation::coordinates = coordinates;
107+
scm::ScmConstellation::stars = stars;
88108

89109
updateTextPosition();
90110
}
91111

112+
const std::vector<scm::CoordinateLine>& scm::ScmConstellation::getCoordinates() const
113+
{
114+
return coordinates;
115+
}
116+
117+
const std::vector<scm::StarLine>& scm::ScmConstellation::getStars() const
118+
{
119+
return stars;
120+
}
121+
92122
void scm::ScmConstellation::drawConstellation(StelCore *core, const Vec3f &lineColor, const Vec3f &nameColor) const
93123
{
124+
if (isHidden)
125+
{
126+
return;
127+
}
94128
StelPainter painter(core->getProjection(drawFrame));
95129
painter.setBlending(true);
96130
painter.setLineSmooth(true);
@@ -99,7 +133,7 @@ void scm::ScmConstellation::drawConstellation(StelCore *core, const Vec3f &lineC
99133
bool alpha = 1.0f;
100134
painter.setColor(lineColor, alpha);
101135

102-
for (CoordinateLine p : constellationCoordinates)
136+
for (CoordinateLine p : coordinates)
103137
{
104138
painter.drawGreatCircleArc(p.start, p.end);
105139
}
@@ -111,11 +145,20 @@ void scm::ScmConstellation::drawConstellation(StelCore *core, const Vec3f &lineC
111145

112146
void scm::ScmConstellation::drawConstellation(StelCore *core) const
113147
{
148+
if (isHidden)
149+
{
150+
return;
151+
}
114152
drawConstellation(core, defaultConstellationLineColor, defaultConstellationNameColor);
115153
}
116154

117155
void scm::ScmConstellation::drawNames(StelCore *core, StelPainter &sPainter, const Vec3f &nameColor) const
118156
{
157+
if (isHidden)
158+
{
159+
return;
160+
}
161+
119162
sPainter.setBlending(true);
120163

121164
Vec3d velocityObserver(0.);
@@ -141,6 +184,11 @@ void scm::ScmConstellation::drawNames(StelCore *core, StelPainter &sPainter, con
141184

142185
void scm::ScmConstellation::drawNames(StelCore *core, StelPainter &sPainter) const
143186
{
187+
if (isHidden)
188+
{
189+
return;
190+
}
191+
144192
drawNames(core, sPainter, defaultConstellationNameColor);
145193
}
146194

@@ -151,18 +199,18 @@ QJsonObject scm::ScmConstellation::toJson(const QString &skyCultureId) const
151199
// Assemble lines object
152200
QJsonArray linesArray;
153201

154-
if (constellationStars.size() != 0)
202+
if (stars.size() != 0)
155203
{
156204
// Stars are NOT empty
157-
for (const auto &star : constellationStars)
205+
for (const auto &star : stars)
158206
{
159207
linesArray.append(star.toJson());
160208
}
161209
}
162210
else
163211
{
164212
// Stars are empty, use the coordinates
165-
for (const auto &coord : constellationCoordinates)
213+
for (const auto &coord : coordinates)
166214
{
167215
linesArray.append(coord.toJson());
168216
}
@@ -223,10 +271,20 @@ bool scm::ScmConstellation::saveArtwork(const QString &directory)
223271
void scm::ScmConstellation::updateTextPosition()
224272
{
225273
XYZname.set(0., 0., 0.);
226-
for (CoordinateLine p : constellationCoordinates)
274+
for (CoordinateLine p : coordinates)
227275
{
228276
XYZname += p.end;
229277
XYZname += p.start;
230278
}
231279
XYZname.normalize();
232280
}
281+
282+
void scm::ScmConstellation::hide()
283+
{
284+
isHidden = true;
285+
}
286+
287+
void scm::ScmConstellation::show()
288+
{
289+
isHidden = false;
290+
}

plugins/SkyCultureMaker/src/ScmConstellation.hpp

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,55 @@ class ScmConstellation
8282
*/
8383
void setNativeName(const std::optional<QString> &name);
8484

85+
/**
86+
* @brief Gets the native name of the constellation
87+
*
88+
* @return The native name
89+
*/
90+
std::optional<QString> getNativeName() const;
91+
8592
/**
8693
* @brief Sets the pronounciation of the constellation
8794
*
8895
* @param pronounce The pronounciation
8996
*/
9097
void setPronounce(const std::optional<QString> &pronounce);
9198

99+
/**
100+
* @brief Gets the pronounciation of the constellation
101+
*
102+
* @return The pronounciation
103+
*/
104+
std::optional<QString> getPronounce() const;
105+
92106
/**
93107
* @brief Sets the IPA.
94108
*
95109
* @param ipa The optional ipa
96110
*/
97111
void setIPA(const std::optional<QString> &ipa);
98112

113+
/**
114+
* @brief Gets the IPA.
115+
*
116+
* @return The optional ipa
117+
*/
118+
std::optional<QString> getIPA() const;
119+
99120
/**
100121
* @brief Sets the artwork.
101122
*
102123
* @param artwork The artwork.
103124
*/
104125
void setArtwork(const ScmConstellationArtwork &artwork);
105126

127+
/**
128+
* @brief Gets the artwork.
129+
*
130+
* @return The artwork.
131+
*/
132+
const ScmConstellationArtwork &getArtwork() const;
133+
106134
/**
107135
* @brief Sets the coordinate lines and star lines of the constellation.
108136
*
@@ -111,6 +139,20 @@ class ScmConstellation
111139
*/
112140
void setConstellation(const std::vector<CoordinateLine> &coordinates, const std::vector<StarLine> &stars);
113141

142+
/**
143+
* @brief Gets the coordinates of the constellation.
144+
*
145+
* @return The coordinates of the constellation.
146+
*/
147+
const std::vector<CoordinateLine> &getCoordinates() const;
148+
149+
/**
150+
* @brief Gets the stars of the constellation.
151+
*
152+
* @return The stars of the constellation.
153+
*/
154+
const std::vector<StarLine> &getStars() const;
155+
114156
/**
115157
* @brief Draws the constellation based on the coordinates.
116158
*
@@ -160,6 +202,16 @@ class ScmConstellation
160202
*/
161203
bool saveArtwork(const QString &directory);
162204

205+
/**
206+
* @brief Hides the constellation from being drawn.
207+
*/
208+
void hide();
209+
210+
/**
211+
* @brief Enables the constellation to be drawn.
212+
*/
213+
void show();
214+
163215
private:
164216
/// Identifier of the constellation
165217
QString id;
@@ -180,10 +232,10 @@ class ScmConstellation
180232
std::optional<QVector<int>> references;
181233

182234
/// List of coordinates forming the segments.
183-
std::vector<CoordinateLine> constellationCoordinates;
235+
std::vector<CoordinateLine> coordinates;
184236

185237
/// List of stars forming the segments. Might be empty.
186-
std::vector<StarLine> constellationStars;
238+
std::vector<StarLine> stars;
187239

188240
/// Direction vector pointing on constellation name drawing position
189241
Vec3d XYZname;
@@ -203,6 +255,9 @@ class ScmConstellation
203255
/// Holds the path the artwork was saved to.
204256
QString artworkPath;
205257

258+
/// Whether the constellation should be drawn or not.
259+
bool isHidden = false;
260+
206261
/**
207262
* @brief Updates the XYZname that is used for the text position.
208263
*/

plugins/SkyCultureMaker/src/ScmConstellationArtwork.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ void scm::ScmConstellationArtwork::setupArt()
7272
// check for null pointers
7373
if (s1obj.isNull() || s2obj.isNull() || s3obj.isNull())
7474
{
75-
qWarning() << "SkyCultureMaker: could not find stars:" << anchors[0].hip << ", " << anchors[1].hip << "or "
76-
<< anchors[2].hip;
75+
qWarning() << "SkyCultureMaker: could not find stars:" << anchors[0].hip << ", " << anchors[1].hip
76+
<< "or " << anchors[2].hip;
7777
return;
7878
}
7979

@@ -180,6 +180,12 @@ bool scm::ScmConstellationArtwork::getHasArt() const
180180
return hasArt;
181181
}
182182

183+
void scm::ScmConstellationArtwork::reset()
184+
{
185+
hasArt = false;
186+
isSetup = false;
187+
}
188+
183189
void scm::ScmConstellationArtwork::draw(StelCore *core) const
184190
{
185191
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000);
@@ -254,16 +260,16 @@ bool scm::ScmConstellationArtwork::save(const QString &filepath) const
254260
bool success = fileInfo.absoluteDir().mkpath(fileInfo.absolutePath());
255261
if (success == false)
256262
{
257-
qWarning() << "SkyCultureMaker: Failed to create the directory structure for: '" << fileInfo.absolutePath()
258-
<< "'";
263+
qWarning() << "SkyCultureMaker: Failed to create the directory structure for: '"
264+
<< fileInfo.absolutePath() << "'";
259265
return false;
260266
}
261267

262268
success = artwork.save(fileInfo.absoluteFilePath());
263269
if (success == false)
264270
{
265-
qWarning() << "SkyCultureMaker: Failed to save the image to the given path: '" << fileInfo.absoluteFilePath()
266-
<< "'";
271+
qWarning() << "SkyCultureMaker: Failed to save the image to the given path: '"
272+
<< fileInfo.absoluteFilePath() << "'";
267273
return false;
268274
}
269275

plugins/SkyCultureMaker/src/ScmConstellationArtwork.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class ScmConstellationArtwork
114114
*/
115115
bool save(const QString &filepath) const;
116116

117+
/**
118+
* @brief Resets the artwork state.
119+
*/
120+
void reset();
121+
117122
private:
118123
/**
119124
* @brief Draw the artwork in an optimized manner.

plugins/SkyCultureMaker/src/ScmDraw.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,24 @@ std::vector<scm::CoordinateLine> scm::ScmDraw::getCoordinates() const
406406
return drawnLines.coordinates;
407407
}
408408

409+
void scm::ScmDraw::loadLines(const std::vector<CoordinateLine>& coordinates, const std::vector<StarLine>& stars)
410+
{
411+
// copy the coordinates and stars to drawnLines
412+
drawnLines.coordinates = coordinates;
413+
drawnLines.stars = stars;
414+
415+
if (!drawnLines.coordinates.empty())
416+
{
417+
currentLine = std::make_tuple(drawnLines.coordinates.back(), drawnLines.stars.back());
418+
drawState = Drawing::hasFloatingEnd;
419+
}
420+
else
421+
{
422+
currentLine = std::make_tuple(CoordinateLine(), StarLine());
423+
drawState = Drawing::None;
424+
}
425+
}
426+
409427
void scm::ScmDraw::setTool(scm::DrawTools tool)
410428
{
411429
activeTool = tool;

plugins/SkyCultureMaker/src/ScmDraw.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ public slots:
180180
*/
181181
std::vector<CoordinateLine> getCoordinates() const;
182182

183+
/**
184+
* @brief Loads lines into the buffer from a tuple of coordinates and stars.
185+
*
186+
*/
187+
void loadLines(const std::vector<CoordinateLine>& coordinates, const std::vector<StarLine>& stars);
188+
183189
/**
184190
* @brief Set the active draw tool
185191
*

0 commit comments

Comments
 (0)