Skip to content

Commit de11d03

Browse files
committed
add drawing modes
1 parent 2abc052 commit de11d03

File tree

7 files changed

+110
-81
lines changed

7 files changed

+110
-81
lines changed

plugins/SkyCultureMaker/src/ScmConstellation.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
#include <QFileInfo>
2727

2828
scm::ScmConstellation::ScmConstellation(const std::vector<scm::CoordinateLine> &coordinates,
29-
const std::vector<scm::StarLine> &stars)
29+
const std::vector<scm::StarLine> &stars, const bool isDarkConstellation)
3030
: coordinates(coordinates)
3131
, stars(stars)
32+
, isDarkConstellation(isDarkConstellation)
3233
{
3334
QSettings *conf = StelApp::getInstance().getSettings();
3435
constellationNameFont.setPixelSize(conf->value("viewing/constellation_font_size", 15).toInt());
@@ -109,12 +110,12 @@ void scm::ScmConstellation::setConstellation(const std::vector<CoordinateLine> &
109110
updateTextPosition();
110111
}
111112

112-
const std::vector<scm::CoordinateLine>& scm::ScmConstellation::getCoordinates() const
113+
const std::vector<scm::CoordinateLine> &scm::ScmConstellation::getCoordinates() const
113114
{
114115
return coordinates;
115116
}
116117

117-
const std::vector<scm::StarLine>& scm::ScmConstellation::getStars() const
118+
const std::vector<scm::StarLine> &scm::ScmConstellation::getStars() const
118119
{
119120
return stars;
120121
}
@@ -198,17 +199,17 @@ QJsonObject scm::ScmConstellation::toJson(const QString &skyCultureId) const
198199
// Assemble lines object
199200
QJsonArray linesArray;
200201

201-
if (stars.size() != 0)
202+
if (!isDarkConstellation)
202203
{
203-
// Stars are NOT empty
204+
// not a dark constellation, so we can add stars
204205
for (const auto &star : stars)
205206
{
206207
linesArray.append(star.toJson());
207208
}
208209
}
209210
else
210211
{
211-
// Stars are empty, use the coordinates
212+
// dark constellation, so only add coordinates
212213
for (const auto &coord : coordinates)
213214
{
214215
linesArray.append(coord.toJson());
@@ -220,7 +221,7 @@ QJsonObject scm::ScmConstellation::toJson(const QString &skyCultureId) const
220221
if (artwork.getHasArt() && !artworkPath.isEmpty())
221222
{
222223
QFileInfo fileInfo(artworkPath);
223-
// the '/' separator is default in all skycultures
224+
// the '/' separator is default in all sky cultures
224225
json["image"] = artwork.toJson("illustrations/" + fileInfo.fileName());
225226
}
226227

plugins/SkyCultureMaker/src/ScmConstellation.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ namespace scm
4242
class ScmConstellation
4343
{
4444
public:
45-
ScmConstellation(const std::vector<CoordinateLine> &coordinates, const std::vector<StarLine> &stars);
45+
ScmConstellation(const std::vector<CoordinateLine> &coordinates, const std::vector<StarLine> &stars,
46+
bool isDarkConstellation = false)
47+
: coordinates(coordinates)
48+
, stars(stars)
49+
, isDarkConstellation(isDarkConstellation) {};
4650

4751
/// The frame that is used for calculation and is drawn on.
4852
static const StelCore::FrameType drawFrame = StelCore::FrameJ2000;
@@ -258,6 +262,9 @@ class ScmConstellation
258262
/// Whether the constellation should be drawn or not.
259263
bool isHidden = false;
260264

265+
/// Indicates if the constellation is a dark constellation.
266+
bool isDarkConstellation = false;
267+
261268
/**
262269
* @brief Updates the XYZname that is used for the text position.
263270
*/

plugins/SkyCultureMaker/src/ScmDraw.cpp

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool scm::ScmDraw::segmentIntersect(const Vec2d &startA, const Vec2d &directionA
123123

124124
scm::ScmDraw::ScmDraw()
125125
: drawState(Drawing::None)
126-
, snapToStar(true)
126+
, drawingMode(DrawingMode::StarsAndDSO)
127127
{
128128
std::get<CoordinateLine>(currentLine).start.set(0, 0, 0);
129129
std::get<CoordinateLine>(currentLine).end.set(0, 0, 0);
@@ -191,46 +191,48 @@ void scm::ScmDraw::handleMouseClicks(class QMouseEvent *event)
191191
// Draw line
192192
if (event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonPress)
193193
{
194-
StelApp &app = StelApp::getInstance();
195-
StelCore *core = app.getCore();
196-
StelProjectorP prj = core->getProjection(drawFrame);
197-
Vec3d point;
198-
std::optional<QString> starID;
199-
prj->unProject(x, y, point);
200-
201-
// We want to combine any near start point to an existing point so that we don't create
202-
// duplicates.
203-
std::optional<StarPoint> nearest = findNearestPoint(x, y, prj);
204-
if (nearest.has_value())
205-
{
206-
point = nearest.value().coordinate;
207-
starID = nearest.value().star;
208-
}
209-
else if (snapToStar)
194+
StelApp &app = StelApp::getInstance();
195+
StelCore *core = app.getCore();
196+
197+
if (drawingMode == DrawingMode::StarsAndDSO)
210198
{
211-
if (hasFlag(drawState, Drawing::hasEndExistingPoint))
212-
{
213-
point = std::get<CoordinateLine>(currentLine).end;
214-
starID = std::get<StarLine>(currentLine).end;
215-
}
216-
else
199+
StelObjectMgr &objectMgr = app.getStelObjectMgr();
200+
if (objectMgr.getWasSelected())
217201
{
218-
StelObjectMgr &objectMgr = app.getStelObjectMgr();
219-
220-
if (objectMgr.getWasSelected())
202+
StelObjectP stelObj = objectMgr.getLastSelectedObject();
203+
Vec3d stelPos = stelObj->getJ2000EquatorialPos(core);
204+
if (stelObj->getType() == "Star" || stelObj->getType() == "Nebula")
221205
{
222-
StelObjectP stelObj = objectMgr.getLastSelectedObject();
223-
Vec3d stelPos = stelObj->getJ2000EquatorialPos(core);
224-
point = stelPos;
225-
if (stelObj->getType() == "Star")
206+
QString stelObjID = stelObj->getID();
207+
if (stelObjID.trimmed().isEmpty())
226208
{
227-
starID = stelObj->getID();
209+
qDebug() << "SkyCultureMaker: Ignored sky object with empty ID";
210+
}
211+
else
212+
{
213+
appendDrawPoint(stelPos, stelObjID);
214+
qDebug() << "SkyCultureMaker: Added sky object to "
215+
"constellation with ID "
216+
<< stelObjID;
228217
}
229218
}
230219
}
231220
}
232-
233-
appendDrawPoint(point, starID);
221+
else if (drawingMode == DrawingMode::Coordinates)
222+
{
223+
StelProjectorP prj = core->getProjection(drawFrame);
224+
Vec3d point;
225+
prj->unProject(x, y, point);
226+
227+
// We want to combine any near start point to an existing point so that we don't create
228+
// duplicates.
229+
std::optional<StarPoint> nearest = findNearestPoint(x, y, prj);
230+
if (nearest.has_value())
231+
{
232+
point = nearest.value().coordinate;
233+
appendDrawPoint(point, std::nullopt);
234+
}
235+
}
234236

235237
event->accept();
236238
return;
@@ -272,16 +274,22 @@ bool scm::ScmDraw::handleMouseMoves(int x, int y, Qt::MouseButtons b)
272274

273275
if (activeTool == DrawTools::Pen)
274276
{
275-
if (snapToStar)
277+
if (drawingMode == DrawingMode::StarsAndDSO)
276278
{
277279
// this wouldve been easier with cleverFind but that is private
278280
StelObjectMgr &objectMgr = app.getStelObjectMgr();
279281
bool found = objectMgr.findAndSelect(core, x, y);
280-
// only keep the selection if a star was selected
281282
if (found && objectMgr.getWasSelected())
282283
{
283284
StelObjectP stelObj = objectMgr.getLastSelectedObject();
284-
if (stelObj->getType() != "Star")
285+
// only keep the selection if a star or nebula was selected
286+
// and it has a valid id
287+
if (stelObj->getType() != "Star" && stelObj->getType() != "Nebula")
288+
{
289+
objectMgr.unSelect();
290+
}
291+
// also unselect if the id is empty or only whitespace
292+
else if (stelObj->getID().trimmed().isEmpty())
285293
{
286294
objectMgr.unSelect();
287295
}
@@ -293,26 +301,8 @@ bool scm::ScmDraw::handleMouseMoves(int x, int y, Qt::MouseButtons b)
293301
StelProjectorP prj = core->getProjection(drawFrame);
294302
Vec3d position;
295303
prj->unProject(x, y, position);
296-
if (snapToStar)
297-
{
298-
StelObjectMgr &objectMgr = app.getStelObjectMgr();
299-
if (objectMgr.getWasSelected())
300-
{
301-
StelObjectP stelObj = objectMgr.getLastSelectedObject();
302-
Vec3d stelPos = stelObj->getJ2000EquatorialPos(core);
303-
std::get<CoordinateLine>(currentLine).end = stelPos;
304-
}
305-
else
306-
{
307-
std::get<CoordinateLine>(currentLine).end = position;
308-
}
309-
}
310-
else
311-
{
312-
std::get<CoordinateLine>(currentLine).end = position;
313-
}
314-
315-
drawState = Drawing::hasFloatingEnd;
304+
std::get<CoordinateLine>(currentLine).end = position;
305+
drawState = Drawing::hasFloatingEnd;
316306
}
317307
}
318308
else if (activeTool == DrawTools::Eraser)
@@ -368,13 +358,6 @@ void scm::ScmDraw::handleKeys(QKeyEvent *e)
368358
{
369359
if (activeTool == DrawTools::Pen)
370360
{
371-
if (e->key() == Qt::Key::Key_Control)
372-
{
373-
snapToStar = e->type() != QEvent::KeyPress;
374-
375-
e->accept();
376-
}
377-
378361
if (e->key() == Qt::Key::Key_Z && e->modifiers() == Qt::Modifier::CTRL)
379362
{
380363
undoLastLine();

plugins/SkyCultureMaker/src/ScmDraw.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "enumBitops.hpp"
3131
#include "types/CoordinateLine.hpp"
3232
#include "types/DrawTools.hpp"
33+
#include "types/DrawingMode.hpp"
3334
#include "types/Drawing.hpp"
3435
#include "types/Lines.hpp"
3536
#include "types/StarLine.hpp"
@@ -57,8 +58,8 @@ class ScmDraw : public QObject
5758
/// Indicates that the startPoint has been set.
5859
Drawing drawState = Drawing::None;
5960

60-
/// Indicates if a line start or end will snap to the nearest star.
61-
bool snapToStar = false;
61+
/// The current drawing mode.
62+
DrawingMode drawingMode = DrawingMode::StarsAndDSO;
6263

6364
/// The current pending point.
6465
std::tuple<CoordinateLine, StarLine> currentLine;

plugins/SkyCultureMaker/src/gui/ScmConstellationDialog.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ private slots:
9494
/// Help text on how to use the pen for Mac users.
9595
const QString helpDrawInfoPen = "Use RightClick or Control + Click to draw a connected line.\n"
9696
"Use Double-RightClick or Control + Double-Click to stop drawing the line.\n"
97-
"Use Command to disable snap to stars.\n"
9897
"Use Command + F to search and connect stars.";
9998
/// Help text on how to use the eraser for Mac users.
10099
const QString helpDrawInfoEraser = "Hold RightClick or Control + Click to delete the line under the cursor.\n";
101100
#else
102101
/// Help text on how to use the pen for non-Mac users.
103102
const QString helpDrawInfoPen = "Use RightClick to draw a connected line.\n"
104103
"Use Double-RightClick to stop drawing the line.\n"
105-
"Use CTRL to disable snap to stars.\n"
106104
"Use CTRL + F to search and connect stars.";
107105
/// Help text on how to use the eraser for non-Mac users.
108106
const QString helpDrawInfoEraser = "Hold RightClick to delete the line under the cursor.\n";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Sky Culture Maker plug-in for Stellarium
3+
*
4+
* Copyright (C) 2025 Vincent Gerlach
5+
* Copyright (C) 2025 Luca-Philipp Grumbach
6+
* Copyright (C) 2025 Fabian Hofer
7+
* Copyright (C) 2025 Mher Mnatsakanyan
8+
* Copyright (C) 2025 Richard Hofmann
9+
*
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License
12+
* as published by the Free Software Foundation; either version 2
13+
* of the License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
#ifndef SCM_TYPES_DRAWINGMODE_HPP
25+
#define SCM_TYPES_DRAWINGMODE_HPP
26+
27+
namespace scm
28+
{
29+
30+
enum class DrawingMode
31+
{
32+
StarsAndDSO,
33+
34+
Coordinates
35+
};
36+
} // namespace scm
37+
38+
#endif

plugins/SkyCultureMaker/src/types/StarLine.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct StarLine
4545
*
4646
* @param starId The ID of the star, which may contain identifiers like "HIP" or "Gaia DR3".
4747
*/
48-
static QString getStarIdNumber(QString starId)
48+
static QString getStarId(QString starId)
4949
{
5050
QRegularExpression hipExpression(R"(HIP\s+(\d+))");
5151
QRegularExpression gaiaExpression(R"(Gaia DR3\s+(\d+))");
@@ -60,7 +60,8 @@ struct StarLine
6060
{
6161
return gaiaMatch.captured(1);
6262
}
63-
return "-1";
63+
// Neither HIP nor Gaia, return as DSO
64+
return "DSO:" + starId.remove(' ');
6465
}
6566

6667
/**
@@ -74,7 +75,7 @@ struct StarLine
7475

7576
if (start.has_value())
7677
{
77-
QString number = getStarIdNumber(start.value());
78+
QString number = getStarId(start.value());
7879

7980
if (start.value().contains("HIP"))
8081
{
@@ -83,7 +84,7 @@ struct StarLine
8384
}
8485
else
8586
{
86-
// Gaia is required as string
87+
// Other ids are required as string
8788
json.append(number);
8889
}
8990
}
@@ -94,7 +95,7 @@ struct StarLine
9495

9596
if (end.has_value())
9697
{
97-
QString number = getStarIdNumber(end.value());
98+
QString number = getStarId(end.value());
9899

99100
if (end.value().contains("HIP"))
100101
{
@@ -103,7 +104,7 @@ struct StarLine
103104
}
104105
else
105106
{
106-
// Gaia is required as string
107+
// Other ids are required as string
107108
json.append(number);
108109
}
109110
}

0 commit comments

Comments
 (0)