[education/kstars] /: Improve the manual focus dialog for the SkyMap
Jasem Mutlaq
null at kde.org
Fri Jun 10 17:01:25 BST 2022
Git commit 63bc10769c7ad6f23f13b57de32076413da92e9c by Jasem Mutlaq, on behalf of Akarsh Simha.
Committed on 10/06/2022 at 16:01.
Pushed by mutlaqja into branch 'master'.
Improve the manual focus dialog for the SkyMap
The focus dialog in the Sky Map allows for manual centering of a field by specifying its coordinates. Most commonly, this would be the J2000 equatorial coordinates. To this end, this MR introduces the following changes:
* Makes the tab order more natural for mouse-free use of the dialog
* Makes J2000 the default epoch for the coordinate entry
* Fixes a bug in which the existing center point was sometimes altered by the dialog
* Refactors the code to make a single code path that does not rely on knowing whether the epoch is JNow or not (at the cost of some extra calculation).
M +1 -1 doc/commands.docbook
M +33 -38 kstars/dialogs/focusdialog.cpp
M +0 -1 kstars/dialogs/focusdialog.h
M +4 -2 kstars/dialogs/focusdialog.ui
https://invent.kde.org/education/kstars/commit/63bc10769c7ad6f23f13b57de32076413da92e9c
diff --git a/doc/commands.docbook b/doc/commands.docbook
index f36051a21..8560d8da7 100644
--- a/doc/commands.docbook
+++ b/doc/commands.docbook
@@ -1467,7 +1467,7 @@ for specifying a sky object on which to center.</para></listitem>
<varlistentry><term><keycombo action="simul">&Ctrl;<keycap>M</keycap></keycombo>
</term>
<listitem><para>Open the <guilabel>Set Coordinates Manually</guilabel> tool,
-for specifying RA/Dec or Az/Alt coordinates on which to center.</para></listitem>
+ for specifying RA/Dec or Az/Alt coordinates on which to center. The tool defaults to <link linkend="ai-epoch">J2000 epoch</link> for the RA/Dec.</para></listitem>
</varlistentry>
<varlistentry>
diff --git a/kstars/dialogs/focusdialog.cpp b/kstars/dialogs/focusdialog.cpp
index 3b8824e7e..abf0873db 100644
--- a/kstars/dialogs/focusdialog.cpp
+++ b/kstars/dialogs/focusdialog.cpp
@@ -33,6 +33,7 @@ FocusDialog::FocusDialog() : QDialog(KStars::Instance())
//initialize point to the current focus position
Point = SkyMap::Instance()->focus();
+ constexpr const char* J2000EpochString = "2000.0";
fd = new FocusDialogUI(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -49,12 +50,7 @@ FocusDialog::FocusDialog() : QDialog(KStars::Instance())
okB = buttonBox->button(QDialogButtonBox::Ok);
okB->setEnabled(false);
- // When editing epoch, set JNow to false.
- connect(fd->epochBox, &QLineEdit::editingFinished, [this]()
- {
- UseJNow = false;
- });
- fd->epochBox->setText(QString::number(KStarsData::Instance()->lt().epoch(), 'f', 3));
+ fd->epochBox->setText(J2000EpochString);
fd->epochBox->setValidator(new QDoubleValidator(fd->epochBox));
fd->raBox->setMinimumWidth(fd->raBox->fontMetrics().boundingRect("00h 00m 00s").width());
fd->azBox->setMinimumWidth(fd->raBox->fontMetrics().boundingRect("00h 00m 00s").width());
@@ -62,21 +58,23 @@ FocusDialog::FocusDialog() : QDialog(KStars::Instance())
fd->raBox->setDegType(false); //RA box should be HMS-style
fd->raBox->setFocus(); //set input focus
- SkyPoint *center {nullptr};
+ const SkyPoint *center {nullptr};
if (SkyMap::Instance()->focusObject())
- center = dynamic_cast<SkyPoint*>(SkyMap::Instance()->focusObject());
+ center = dynamic_cast<const SkyPoint*>(SkyMap::Instance()->focusObject());
else
- center = SkyMap::Instance()->focusPoint();
+ center = const_cast<const SkyPoint*>(SkyMap::Instance()->focusPoint());
if (center)
{
+ // Make a copy so as to not affect the existing center point / object
+ SkyPoint centerCopy {*center};
//center->deprecess(KStarsData::Instance()->updateNum());
- center->catalogueCoord(KStarsData::Instance()->updateNum()->julianDay());
- fd->raBox->show(center->ra());
- fd->decBox->show(center->dec());
+ centerCopy.catalogueCoord(KStarsData::Instance()->updateNum()->julianDay());
+ fd->raBox->show(centerCopy.ra());
+ fd->decBox->show(centerCopy.dec());
- fd->azBox->show(center->az());
- fd->altBox->show(center->alt());
+ fd->azBox->show(centerCopy.az());
+ fd->altBox->show(centerCopy.alt());
checkLineEdits();
}
@@ -88,13 +86,11 @@ FocusDialog::FocusDialog() : QDialog(KStars::Instance())
connect(fd->J2000B, &QPushButton::clicked, [this]()
{
- fd->epochBox->setText("2000.0");
- UseJNow = false;
+ fd->epochBox->setText(J2000EpochString);
});
connect(fd->JNowB, &QPushButton::clicked, [this]()
{
fd->epochBox->setText(QString::number(KStarsData::Instance()->lt().epoch(), 'f', 3));
- UseJNow = true;
});
}
@@ -137,36 +133,35 @@ void FocusDialog::validatePoint()
return;
}
- // JNow
- if (UseJNow)
+ bool ok { false };
+ double epoch0 = KStarsDateTime::stringToEpoch(fd->epochBox->text(), ok);
+ if (!ok)
{
- Point->setRA(ra);
- Point->setDec(dec);
- //Point->deprecess(KStarsData::Instance()->updateNum());
- Point->catalogueCoord(KStarsData::Instance()->updateNum()->julianDay());
- // N.B. At this point (ra, dec) and (ra0, dec0) are both J2000.0 values
- // Therefore, we precess again to get the JNow values in (ra, dec)
- Point->apparentCoord(static_cast<long double>(J2000), KStarsData::Instance()->updateNum()->julianDay());
+ KSNotification::sorry(message, i18n("Invalid Epoch format"));
+ return;
}
- else
- {
- bool ok { false };
- double epoch0 = KStarsDateTime::stringToEpoch(fd->epochBox->text(), ok);
- if (!ok)
- {
- KSNotification::sorry(message, i18n("Invalid Epoch format"));
- return;
- }
- long double jd0 = KStarsDateTime::epochToJd(epoch0);
+ long double jd0 = KStarsDateTime::epochToJd(epoch0);
+ // Set RA and Dec to whatever epoch we have been given (may be J2000, JNow or something completely different)
+ Point->setRA(ra);
+ Point->setDec(dec);
+
+ if (jd0 != J2000) {
+ // Compute and set the J2000 coordinates of Point
+ Point->catalogueCoord(jd0);
+ } else {
Point->setRA0(ra);
Point->setDec0(dec);
- Point->apparentCoord(jd0, KStarsData::Instance()->updateNum()->julianDay());
}
+ // N.B. At this point (ra, dec) and (ra0, dec0) are both
+ // J2000.0 values Therefore, we precess again to get the
+ // values for the present draw epoch into (ra, dec)
+ Point->apparentCoord(static_cast<long double>(J2000), KStarsData::Instance()->updateNum()->julianDay());
+
Point->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
// At this point, both (RA, Dec) and (Alt, Az) should correspond to current time
- // (RA0, Dec0) may either be J2000.0 or some other epoch -- asimha
+ // (RA0, Dec0) will be J2000.0 -- asimha
QDialog::accept();
}
diff --git a/kstars/dialogs/focusdialog.h b/kstars/dialogs/focusdialog.h
index 81d8c8483..8df3a4ef4 100644
--- a/kstars/dialogs/focusdialog.h
+++ b/kstars/dialogs/focusdialog.h
@@ -70,5 +70,4 @@ class FocusDialog : public QDialog
FocusDialogUI *fd { nullptr };
bool UsedAltAz { false };
QPushButton *okB { nullptr };
- bool UseJNow { true };
};
diff --git a/kstars/dialogs/focusdialog.ui b/kstars/dialogs/focusdialog.ui
index 89cd1968e..9c3c172ed 100644
--- a/kstars/dialogs/focusdialog.ui
+++ b/kstars/dialogs/focusdialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>290</width>
- <height>129</height>
+ <width>306</width>
+ <height>172</height>
</rect>
</property>
<layout class="QVBoxLayout">
@@ -239,6 +239,8 @@
<tabstop>raBox</tabstop>
<tabstop>decBox</tabstop>
<tabstop>epochBox</tabstop>
+ <tabstop>JNowB</tabstop>
+ <tabstop>J2000B</tabstop>
<tabstop>azBox</tabstop>
<tabstop>altBox</tabstop>
</tabstops>
More information about the kde-doc-english
mailing list