@@ -123,7 +123,7 @@ bool scm::ScmDraw::segmentIntersect(const Vec2d &startA, const Vec2d &directionA
123123
124124scm::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 ();
0 commit comments