kstars /kstars/tools/modcalcapcoord.cpp

Language C++ Lines 284
MD5 Hash 6f93d92345983e5acf2f2bc9faf90f9d
Repository https://gitlab.com/g10h4ck/kstars.git View Raw File
  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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/***************************************************************************
                          modcalcapcoord.cpp  -  description
                             -------------------
    begin                : Wed Apr 10 2002
    copyright            : (C) 2002 by Pablo de Vicente
    email                : vicente@oan.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "modcalcapcoord.h"

#include <QTextStream>
#include <QFileDialog>

#include <KLocalizedString>
#include <KMessageBox>

#include "kstars.h"
#include "dms.h"
#include "skyobjects/skypoint.h"
#include "kstarsdatetime.h"
#include "dialogs/finddialog.h"
#include "widgets/dmsbox.h"

modCalcApCoord::modCalcApCoord(QWidget *parentSplit)
        : QFrame(parentSplit) {

    setupUi(this);
    showCurrentTime();
    RACat->setDegType(false);
    DecCat->setDegType(true);

    connect( ObjectButton, SIGNAL( clicked() ), this, SLOT( slotObject() ) );
    connect( NowButton, SIGNAL( clicked() ), this, SLOT( showCurrentTime() ) );
    connect( RACat, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
    connect( DecCat, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
    connect( UT, SIGNAL( timeChanged( const QTime & ) ), this, SLOT( slotCompute() ) );
    connect( Date, SIGNAL( dateChanged( const QDate & ) ), this, SLOT( slotCompute() ) );

    connect( utCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch()) );
    connect( dateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch()) );
    connect( raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()) );
    connect( decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()) );
    connect( epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()) );
    connect( runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()) );

    show();
}

modCalcApCoord::~modCalcApCoord(){
}

void modCalcApCoord::showCurrentTime (void)
{
    KStarsDateTime dt( KStarsDateTime::currentDateTime() );
    Date->setDate( dt.date() );
    UT->setTime( dt.time() );
    EpochTarget->setText( QString::number( dt.epoch(), 'f', 3 ) );
}

void modCalcApCoord::slotCompute(){
    KStarsDateTime dt( Date->date(), UT->time() );
    long double jd = dt.djd();

    dt.setFromEpoch( EpochCat->value() );
    long double jd0 = dt.djd();

    SkyPoint sp( RACat->createDms(false), DecCat->createDms() );
    sp.apparentCoord(jd0, jd);

    RA->setText( sp.ra().toHMSString() );
    Dec->setText( sp.dec().toDMSString() );
}

void modCalcApCoord::slotObject() {
    QPointer<FindDialog> fd = new FindDialog( this );
    if ( fd->exec() == QDialog::Accepted ) {
        SkyObject *o = fd->selectedObject();
        RACat->showInHours( o->ra0() );
        DecCat->showInDegrees( o->dec0() );
        EpochCat->setValue( 2000.0 );

        slotCompute();
    }
    delete fd;
}

void modCalcApCoord::slotUtCheckedBatch(){
    if ( utCheckBatch->isChecked() )
        utBoxBatch->setEnabled( false );
    else {
        utBoxBatch->setEnabled( true );
    }
}

void modCalcApCoord::slotDateCheckedBatch(){

    if ( dateCheckBatch->isChecked() )
        dateBoxBatch->setEnabled( false );
    else {
        dateBoxBatch->setEnabled( true );
    }
}

void modCalcApCoord::slotRaCheckedBatch(){

    if ( raCheckBatch->isChecked() )
        raBoxBatch->setEnabled( false );
    else {
        raBoxBatch->setEnabled( true );
    }
}

void modCalcApCoord::slotDecCheckedBatch(){

    if ( decCheckBatch->isChecked() )
        decBoxBatch->setEnabled( false );
    else {
        decBoxBatch->setEnabled( true );
    }
}

void modCalcApCoord::slotEpochCheckedBatch(){

    if ( epochCheckBatch->isChecked() )
        epochBoxBatch->setEnabled( false );
    else {
        epochBoxBatch->setEnabled( true );
    }
}

void modCalcApCoord::slotRunBatch() {

    QString inputFileName = InputLineEditBatch->url().toLocalFile();

    // We open the input file and read its content

    if ( QFile::exists(inputFileName) ) {
        QFile f( inputFileName );
        if ( !f.open( QIODevice::ReadOnly) ) {
            QString message = xi18n( "Could not open file %1.", f.fileName() );
            KMessageBox::sorry( 0, message, xi18n( "Could Not Open File" ) );
            inputFileName.clear();
            return;
        }

        //		processLines(&f);
        QTextStream istream(&f);
        processLines(istream);
        //		readFile( istream );
        f.close();
    } else  {
        QString message = xi18n( "Invalid file: %1", inputFileName );
        KMessageBox::sorry( 0, message, xi18n( "Invalid file" ) );
        inputFileName.clear();
        InputLineEditBatch->setText( inputFileName );
        return;
    }
}

//void modCalcApCoord::processLines( const QFile * fIn ) {
void modCalcApCoord::processLines( QTextStream &istream ) {

    // we open the output file

    //	QTextStream istream(&fIn);
    QString outputFileName;
    outputFileName = OutputLineEditBatch->text();
    QFile fOut( outputFileName );
    fOut.open(QIODevice::WriteOnly);
    QTextStream ostream(&fOut);

    QString line;
    QChar space = ' ';
    int i = 0;
    long double jd, jd0;
    SkyPoint sp;
    QTime utB;
    QDate dtB;
    dms raB, decB;
    QString epoch0B;

    while ( ! istream.atEnd() ) {
        line = istream.readLine();
        line.trimmed();

        //Go through the line, looking for parameters

        QStringList fields = line.split( ' ' );

        i = 0;

        // Read Ut and write in ostream if corresponds

        if(utCheckBatch->isChecked() ) {
            utB = QTime::fromString( fields[i] );
            i++;
        } else
            utB = utBoxBatch->time();

        if ( allRadioBatch->isChecked() )
            ostream << QLocale().toString( utB ) << space;
        else
            if(utCheckBatch->isChecked() )
                ostream << QLocale().toString( utB ) << space;

        // Read date and write in ostream if corresponds

        if(dateCheckBatch->isChecked() ) {
            dtB = QDate::fromString( fields[i] );
            i++;
        } else
            dtB = dateBoxBatch->date();

        if ( allRadioBatch->isChecked() )
            ostream << QLocale().toString( dtB, QLocale::LongFormat ).append(space);
        else
            if(dateCheckBatch->isChecked() )
                ostream << QLocale().toString( dtB, QLocale::LongFormat ).append(space);

        // Read RA and write in ostream if corresponds

        if(raCheckBatch->isChecked() ) {
            raB = dms::fromString( fields[i],false);
            i++;
        } else
            raB = raBoxBatch->createDms(false);

        if ( allRadioBatch->isChecked() )
            ostream << raB.toHMSString() << space;
        else
            if(raCheckBatch->isChecked() )
                ostream << raB.toHMSString() << space;

        // Read DEC and write in ostream if corresponds

        if(decCheckBatch->isChecked() ) {
            decB = dms::fromString( fields[i], true);
            i++;
        } else
            decB = decBoxBatch->createDms();

        if ( allRadioBatch->isChecked() )
            ostream << decB.toDMSString() << space;
        else
            if(decCheckBatch->isChecked() )
                ostream << decB.toHMSString() << space;

        // Read Epoch and write in ostream if corresponds

        if(epochCheckBatch->isChecked() ) {
            epoch0B = fields[i];
            i++;
        } else
            epoch0B = epochBoxBatch->text();

        if ( allRadioBatch->isChecked() )
            ostream << epoch0B;
        else
            if(decCheckBatch->isChecked() )
                ostream << epoch0B;

        KStarsDateTime dt;
        dt.setFromEpoch( epoch0B );
        jd = KStarsDateTime(dtB,utB).djd();
        jd0 = dt.djd();
        sp = SkyPoint (raB, decB);
        sp.apparentCoord(jd0, jd);

        ostream << sp.ra().toHMSString() << sp.dec().toDMSString() << endl;
    }

    fOut.close();
}
Back to Top