Commit e1ecb213 authored by Jasem Mutlaq's avatar Jasem Mutlaq

Fix manual focus dialog calculating wrong sky point based on bogus epoch

parent cd598e8a
......@@ -32,14 +32,14 @@ FocusDialogUI::FocusDialogUI( QWidget *parent ) : QFrame( parent ) {
setupUi( this );
}
FocusDialog::FocusDialog( KStars *_ks )
: QDialog( _ks ), ks( _ks )
FocusDialog::FocusDialog()
: QDialog(KStars::Instance())
{
#ifdef Q_OS_OSX
setWindowFlags(Qt::Tool| Qt::WindowStaysOnTopHint);
#endif
//initialize point to the current focus position
Point = *ks->map()->focus();
Point = SkyMap::Instance()->focus();
UsedAltAz = false; //assume RA/Dec by default
......@@ -75,26 +75,33 @@ FocusDialog::FocusDialog( KStars *_ks )
FocusDialog::~FocusDialog(){
}
void FocusDialog::checkLineEdits() {
void FocusDialog::checkLineEdits()
{
bool raOk(false), decOk(false), azOk(false), altOk(false);
fd->raBox->createDms( false, &raOk );
fd->decBox->createDms( true, &decOk );
fd->azBox->createDms( true, &azOk );
fd->altBox->createDms( true, &altOk );
if ( ( raOk && decOk ) || ( azOk && altOk ) )
okB->setEnabled(true );
okB->setEnabled(true);
else
okB->setEnabled(false);
}
void FocusDialog::validatePoint() {
void FocusDialog::validatePoint()
{
bool raOk(false), decOk(false), azOk(false), altOk(false);
dms ra( fd->raBox->createDms( false, &raOk ) ); //false means expressed in hours
//false means expressed in hours
dms ra( fd->raBox->createDms( false, &raOk ) );
dms dec( fd->decBox->createDms( true, &decOk ) );
QString message;
if ( raOk && decOk ) {
if ( raOk && decOk )
{
//make sure values are in valid range
if ( ra.Hours() < 0.0 || ra.Hours() > 24.0 )
message = i18n( "The Right Ascension value must be between 0.0 and 24.0." );
......@@ -105,12 +112,13 @@ void FocusDialog::validatePoint() {
return;
}
Point.set( ra, dec );
bool ok; // Ignored. FIXME: Make a version of KStarsDateTime::stringToEpoch that doesn't mandate the ok arg
Point->set( ra, dec );
bool ok;
double epoch0 = KStarsDateTime::stringToEpoch( fd->epochBox->text(), ok );
long double jd0 = KStarsDateTime::epochToJd ( epoch0 );
Point.apparentCoord(jd0, ks->data()->ut().djd() );
Point.EquatorialToHorizontal( ks->data()->lst(), ks->data()->geo()->lat() );
Point->apparentCoord(jd0, KStarsData::Instance()->ut().djd() );
Point->EquatorialToHorizontal( KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat() );
QDialog::accept();
} else {
......@@ -128,9 +136,9 @@ void FocusDialog::validatePoint() {
return;
}
Point.setAz( az );
Point.setAlt( alt );
Point.HorizontalToEquatorial( ks->data()->lst(), ks->data()->geo()->lat() );
Point->setAz( az );
Point->setAlt( alt );
Point->HorizontalToEquatorial( KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat() );
UsedAltAz = true;
......
......@@ -41,13 +41,13 @@ class FocusDialog : public QDialog {
Q_OBJECT
public:
/**Constructor. */
explicit FocusDialog( KStars *_ks );
explicit FocusDialog();
/**Destructor (empty). */
~FocusDialog();
/** @return pointer to the SkyPoint described by the entered RA, Dec */
inline SkyPoint& point() { return Point; }
inline SkyPoint* point() { return Point; }
/** @return suggested size of focus window. */
QSize sizeHint() const;
......@@ -70,8 +70,7 @@ public slots:
void validatePoint();
private:
KStars *ks;
SkyPoint Point;
SkyPoint *Point;
FocusDialogUI *fd;
bool UsedAltAz;
QPushButton *okB;
......
......@@ -1123,29 +1123,31 @@ void KStars::slotTrack() {
}
void KStars::slotManualFocus() {
QPointer<FocusDialog> focusDialog = new FocusDialog( this ); // = new FocusDialog( this );
QPointer<FocusDialog> focusDialog = new FocusDialog();
if ( Options::useAltAz() ) focusDialog->activateAzAltPage();
if ( focusDialog->exec() == QDialog::Accepted ) {
//DEBUG
qDebug() << "focusDialog point: " << &focusDialog;
if ( focusDialog->exec() == QDialog::Accepted )
{
//If the requested position is very near the pole, we need to point first
//to an intermediate location just below the pole in order to get the longitudinal
//position (RA/Az) right.
double realAlt( focusDialog->point().alt().Degrees() );
double realDec( focusDialog->point().dec().Degrees() );
if ( Options::useAltAz() && realAlt > 89.0 ) {
focusDialog->point().setAlt( 89.0 );
focusDialog->point().HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
double realAlt( focusDialog->point()->alt().Degrees() );
double realDec( focusDialog->point()->dec().Degrees() );
if ( Options::useAltAz() && realAlt > 89.0 )
{
focusDialog->point()->setAlt( 89.0 );
focusDialog->point()->HorizontalToEquatorial( data()->lst(), data()->geo()->lat() );
}
if ( ! Options::useAltAz() && realDec > 89.0 ) {
focusDialog->point().setDec( 89.0 );
focusDialog->point().EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
if ( ! Options::useAltAz() && realDec > 89.0 )
{
focusDialog->point()->setDec( 89.0 );
focusDialog->point()->EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
}
map()->setClickedPoint( & focusDialog->point() );
if ( Options::isTracking() ) slotTrack();
map()->setClickedPoint( focusDialog->point() );
if ( Options::isTracking() )
slotTrack();
map()->slotCenter();
......@@ -1157,15 +1159,20 @@ void KStars::slotManualFocus() {
//Also, if the requested position was within 1 degree of the coordinate pole, this will
//automatically correct the final pointing from the intermediate offset position to the final position
data()->setSnapNextFocus();
if ( Options::useAltAz() ) {
map()->setDestinationAltAz( focusDialog->point().alt(), focusDialog->point().az() );
} else {
map()->setDestination( focusDialog->point().ra(), focusDialog->point().dec() );
if ( Options::useAltAz() )
{
map()->setDestinationAltAz( focusDialog->point()->alt(), focusDialog->point()->az() );
}
else
{
map()->setDestination( focusDialog->point()->ra(), focusDialog->point()->dec() );
}
//Now, if the requested point was near a pole, we need to reset the Alt/Dec of the focus.
if ( Options::useAltAz() && realAlt > 89.0 ) map()->focus()->setAlt( realAlt );
if ( ! Options::useAltAz() && realDec > 89.0 ) map()->focus()->setDec( realAlt );
if ( Options::useAltAz() && realAlt > 89.0 )
map()->focus()->setAlt( realAlt );
if ( ! Options::useAltAz() && realDec > 89.0 )
map()->focus()->setDec( realAlt );
//Don't track if we set Alt/Az coordinates. This way, Alt/Az remain constant.
if ( focusDialog->usedAltAz() )
......
......@@ -263,17 +263,24 @@ double KStarsDateTime::jdToEpoch(long double jd, KStarsDateTime::EpochType type)
}
double KStarsDateTime::stringToEpoch(const QString& eName, bool &ok) {
double epoch;
double KStarsDateTime::stringToEpoch(const QString& eName, bool &ok)
{
double epoch = J2000;
ok = false;
if ( eName.isEmpty() ) // By default, assume J2000
return J2000;
return epoch;
if ( eName.startsWith( 'J' ) )
epoch = eName.mid( 1 ).toDouble(&ok);
else if ( eName.startsWith( 'B' ) ) {
else if ( eName.startsWith( 'B' ) )
{
epoch = eName.mid( 1 ).toDouble(&ok);
epoch = jdToEpoch( epochToJd( epoch, BESSELIAN ), JULIAN ); // Convert Besselian epoch to Julian epoch
}
// Assume it's Julian
else
epoch = eName.toDouble(&ok);
return epoch;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment