1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/***************************************************************************
focusdialog.cpp - description
-------------------
begin : Sat Mar 23 2002
copyright : (C) 2002 by Jason Harris
email : kstars@30doradus.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <tqtabwidget.h>
#include <tqlayout.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <tqstring.h>
#include <knumvalidator.h>
#include "kstars.h"
#include "kstarsdata.h"
#include "dms.h"
#include "skypoint.h"
#include "dmsbox.h"
#include "focusdialog.h"
FocusDialog::FocusDialog( TQWidget *parent )
: KDialogBase( KDialogBase::Plain, i18n( "Set Focus Manually" ), Ok|Cancel, Ok, parent ) {
Point = 0; //initialize pointer to null
UsedAltAz = false; //assume RA/Dec by default
TQFrame *page = plainPage();
setMainWidget(page);
TQVBoxLayout *vlay = new TQVBoxLayout( page, 0, spacingHint() );
fdlg = new FocusDialogDlg(page);
fdlg->epochName->setValidator( new KDoubleValidator( fdlg->epochName ) );
vlay->addWidget( fdlg );
connect( fdlg->raBox, TQT_SIGNAL(textChanged( const TQString & ) ), this, TQT_SLOT( checkLineEdits() ) );
connect( fdlg->decBox, TQT_SIGNAL(textChanged( const TQString & ) ), this, TQT_SLOT( checkLineEdits() ) );
connect( fdlg->azBox, TQT_SIGNAL(textChanged( const TQString & ) ), this, TQT_SLOT( checkLineEdits() ) );
connect( fdlg->altBox, TQT_SIGNAL(textChanged( const TQString & ) ), this, TQT_SLOT( checkLineEdits() ) );
connect( this, TQT_SIGNAL( okClicked() ), this, TQT_SLOT( validatePoint() ) );
fdlg->raBox->setDegType(false); //RA box should be HMS-style
fdlg->raBox->setFocus(); //set input focus
enableButtonOK( false ); //disable until both lineedits are filled
}
FocusDialog::~FocusDialog(){
}
void FocusDialog::checkLineEdits() {
bool raOk(false), decOk(false), azOk(false), altOk(false);
fdlg->raBox->createDms( false, &raOk );
fdlg->decBox->createDms( true, &decOk );
fdlg->azBox->createDms( true, &azOk );
fdlg->altBox->createDms( true, &altOk );
if ( ( raOk && decOk ) || ( azOk && altOk ) )
enableButtonOK( true );
else
enableButtonOK( false );
}
void FocusDialog::slotOk() {
emit okClicked();
}
void FocusDialog::validatePoint() {
bool raOk(false), decOk(false), azOk(false), altOk(false);
dms ra( fdlg->raBox->createDms( false, &raOk ) ); //false means expressed in hours
dms dec( fdlg->decBox->createDms( true, &decOk ) );
TQString message;
KStars *ks = (KStars*) parent();
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." );
if ( dec.Degrees() < -90.0 || dec.Degrees() > 90.0 )
message += "\n" + i18n( "The Declination value must be between -90.0 and 90.0." );
if ( ! message.isEmpty() ) {
KMessageBox::sorry( 0, message, i18n( "Invalid Coordinate Data" ) );
return;
}
Point = new SkyPoint( ra, dec );
double epoch0 = getEpoch( fdlg->epochName->text() );
long double jd0 = epochToJd ( epoch0 );
Point->apparentCoord(jd0, ks->data()->ut().djd() );
TQDialog::accept();
} else {
dms az( fdlg->azBox->createDms( true, &azOk ) );
dms alt( fdlg->altBox->createDms( true, &altOk ) );
if ( azOk && altOk ) {
//make sure values are in valid range
if ( az.Degrees() < 0.0 || az.Degrees() > 360.0 )
message = i18n( "The Azimuth value must be between 0.0 and 360.0." );
if ( alt.Degrees() < -90.0 || alt.Degrees() > 90.0 )
message += "\n" + i18n( "The Altitude value must be between -90.0 and 90.0." );
if ( ! message.isEmpty() ) {
KMessageBox::sorry( 0, message, i18n( "Invalid Coordinate Data" ) );
return;
}
Point = new SkyPoint();
Point->setAz( az );
Point->setAlt( alt );
UsedAltAz = true;
TQDialog::accept();
} else {
TQDialog::reject();
}
}
}
double FocusDialog::getEpoch (TQString eName) {
//If eName is empty (or not a number) assume 2000.0
bool ok(false);
double epoch = eName.toDouble( &ok );
if ( eName.isEmpty() || ! ok )
return 2000.0;
return epoch;
}
long double FocusDialog::epochToJd (double epoch) {
double yearsTo2000 = 2000.0 - epoch;
if (epoch == 1950.0) {
return 2433282.4235;
} else if ( epoch == 2000.0 ) {
return J2000;
} else {
return ( J2000 - yearsTo2000 * 365.2425 );
}
}
TQSize FocusDialog::sizeHint() const
{
return TQSize(240,210);
}
void FocusDialog::activateAzAltPage() {
fdlg->fdTab->showPage( fdlg->aaTab );
fdlg->azBox->setFocus();
}
#include "focusdialog.moc"
|