Пример #1
0
void modCalcAzel::slotComputeCoords()
{
	SkyPoint sp;
	double epoch0 = getEpoch( epochName->text() );
	KStarsDateTime dt;
	dt.setFromEpoch( epoch0 );
	long double jd = getDateTime().djd();
	long double jd0 = dt.djd();

	dms LST( getDateTime().gst().Degrees() + getLongitude().Degrees() );

	if(radioApCoords->isChecked()) {
		sp = getEquCoords();
		sp.apparentCoord(jd0, jd);
		dms lat(getLatitude());
		sp.EquatorialToHorizontal( &LST, &lat );
		showHorCoords( sp );

	} else {
		sp = getHorCoords();
		dms lat(getLatitude());
		sp.HorizontalToEquatorial( &LST, &lat );
		showEquCoords( sp );
	}

}
unsigned short MoonPhaseCalendar::computeMoonPhase( const KStarsDateTime &date ) {

    KSNumbers num( date.djd() );
    KSPlanet earth( I18N_NOOP( "Earth" ), QString(), QColor( "white" ), 12756.28 /*diameter in km*/ );
    earth.findPosition( &num );

    m_Moon.findGeocentricPosition( &num, &earth );
    m_Moon.findPhase();

    return m_Moon.getIPhase();

}
Пример #3
0
SkyPoint SkyObject::recomputeCoords( const KStarsDateTime &dt, const GeoLocation *geo ) {
	//store current position
	SkyPoint original( ra(), dec() );

	// compute coords for new time jd
	KSNumbers num( dt.djd() );
	if ( isSolarSystem() && geo ) {
		dms LST = geo->GSTtoLST( dt.gst() );
		updateCoords( &num, true, geo->lat(), &LST );
	} else {
		updateCoords( &num );
	}

	//the coordinates for the date dt:
	SkyPoint sp = SkyPoint( ra(), dec() );

	// restore original coords
	setRA( original.ra()->Hours() );
	setDec( original.dec()->Degrees() );

	return sp;
}
Пример #4
0
void modCalcVlsr::slotCompute()
{
    bool ok1(false), ok2(false);
    SkyPoint sp( RA->createDms(false, &ok1), Dec->createDms(true, &ok2) );
    if ( !ok1 || !ok2 ) return;

    KStarsDateTime dt = Date->dateTime();
    double vst[3];
    geoPlace->TopocentricVelocity( vst, dt.gst() );

    if ( sender()->objectName() == "VLSR" )   velocityFlag = 0;
    if ( sender()->objectName() == "VHelio" ) velocityFlag = 1;
    if ( sender()->objectName() == "VGeo" )   velocityFlag = 2;
    if ( sender()->objectName() == "VTopo" )  velocityFlag = 3;

    switch ( velocityFlag ) {
    case 0: //Hold VLSR constant, compute the others
        {
            double vlsr = VLSR->text().toDouble();
            double vhelio = sp.vHeliocentric( vlsr, dt.djd() );
            double vgeo = sp.vGeocentric( vhelio, dt.djd() );

            VHelio->setText( QString::number( vhelio ) );
            VGeo->setText( QString::number( vgeo ) );
            VTopo->setText( QString::number( sp.vTopocentric(vgeo, vst) ) );
            break;
        }

    case 1: //Hold VHelio constant, compute the others
        {
            double vhelio = VHelio->text().toDouble();
            double vlsr = sp.vHelioToVlsr( vhelio, dt.djd() );
            double vgeo = sp.vGeocentric( vhelio, dt.djd() );

            VLSR->setText( QString::number( vlsr ) );
            VGeo->setText( QString::number( vgeo ) );
            VTopo->setText( QString::number( sp.vTopocentric(vgeo, vst) ) );
            break;
        }

    case 2: //Hold VGeo constant, compute the others
        {
            double vgeo = VGeo->text().toDouble();
            double vhelio = sp.vGeoToVHelio( vgeo, dt.djd() );
            double vlsr = sp.vHelioToVlsr( vhelio, dt.djd() );

            VLSR->setText( QString::number( vlsr ) );
            VHelio->setText( QString::number( vhelio ) );
            VTopo->setText( QString::number( sp.vTopocentric(vgeo, vst) ) );
            break;
        }

    case 3: //Hold VTopo constant, compute the others
        {
            double vtopo = VTopo->text().toDouble();
            double vgeo = sp.vTopoToVGeo( vtopo, vst );
            double vhelio = sp.vGeoToVHelio( vgeo, dt.djd() );
            double vlsr = sp.vHelioToVlsr( vhelio, dt.djd() );

            VLSR->setText( QString::number( vlsr ) );
            VHelio->setText( QString::number( vhelio ) );
            VGeo->setText( QString::number( vgeo ) );
            break;
        }

    default: //oops
        kDebug() << i18n("Error: do not know which velocity to use for input.");
        break;
    }
}
Пример #5
0
void modCalcAzel::processLines( QTextStream &istream ) {

	// we open the output file

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

	QString line;
	QString space = " ";
	int i = 0;
	long double jd0, jdf;
	dms LST;
	SkyPoint sp;
	dms raB, decB, latB, longB, azB, elB;
	double epoch0B;
	QTime utB;
	ExtDate dtB;

	while ( ! istream.eof() ) {
		line = istream.readLine();
		line.stripWhiteSpace();

		//Go through the line, looking for parameters

		QStringList fields = QStringList::split( " ", line );

		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 << utB.toString() << space;
		else
			if(utCheckBatch->isChecked() )
				ostream << utB.toString() << space;
			
		// Read date and write in ostream if corresponds
		
		if(dateCheckBatch->isChecked() ) {
			 dtB = ExtDate::fromString( fields[i] );
			 i++;
		} else
			dtB = dateBoxBatch->date();
		if ( allRadioBatch->isChecked() )
			ostream << dtB.toString().append(space);
		else
			if(dateCheckBatch->isChecked() )
			 	ostream << dtB.toString().append(space);
		
		// Read Longitude and write in ostream if corresponds
		
		if (longCheckBatch->isChecked() ) {
			longB = dms::fromString( fields[i],TRUE);
			i++;
		} else
			longB = longBoxBatch->createDms(TRUE);
		
		if ( allRadioBatch->isChecked() )
			ostream << longB.toDMSString() << space;
		else
			if (longCheckBatch->isChecked() )
				ostream << longB.toDMSString() << space;
		
		// Read Latitude


		if (latCheckBatch->isChecked() ) {
			latB = dms::fromString( fields[i], TRUE);
			i++;
		} else
			latB = latBoxBatch->createDms(TRUE);
		if ( allRadioBatch->isChecked() )
			ostream << latB.toDMSString() << space;
		else
			if (latCheckBatch->isChecked() )
				ostream << latB.toDMSString() << space;
		
		// Read Epoch and write in ostream if corresponds
	
		if(epochCheckBatch->isChecked() ) {
			epoch0B = fields[i].toDouble();
			i++;
		} else
			epoch0B = getEpoch( epochBoxBatch->text() );

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

		// We make the first calculations
		KStarsDateTime dt;
		dt.setFromEpoch( epoch0B );
		jdf = KStarsDateTime(dtB,utB).djd();
		jd0 = dt.djd();

		LST = KStarsDateTime(dtB,utB).gst().Degrees() + longB.Degrees();
		
		// Equatorial coordinates are the input coords.
		if (!horInputCoords) {
		// 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.toDMSString() << space;

			sp = SkyPoint (raB, decB);
			sp.apparentCoord(jd0, jdf);
			sp.EquatorialToHorizontal( &LST, &latB );
			ostream << sp.az()->toDMSString() << space << sp.alt()->toDMSString() << endl;

		// Input coords are horizontal coordinates
		
		} else {
			if(azCheckBatch->isChecked() ) {
				azB = dms::fromString( fields[i],FALSE);
				i++;
			} else
				azB = azBoxBatch->createDms();

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

			// Read DEC and write in ostream if corresponds

			if(elCheckBatch->isChecked() ) {
				elB = dms::fromString( fields[i], TRUE);
				i++;
			} else
				elB = decBoxBatch->createDms();

			if ( allRadioBatch->isChecked() )
				ostream << elB.toDMSString() << space;
			else
				if(elCheckBatch->isChecked() )
					ostream << elB.toDMSString() << space;

			sp.setAz(azB);
			sp.setAlt(elB);
			sp.HorizontalToEquatorial( &LST, &latB );
			ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl;
		}

	}


	fOut.close();
}
Пример #6
0
KStarsDateTime::KStarsDateTime( const KStarsDateTime &kdt ) : QDateTime()
{
    setDJD( kdt.djd() );
    setUtcOffset(kdt.utcOffset());
}
Пример #7
0
void modCalcJD::processLines( QTextStream &istream, int inputData ) {
    QFile fOut( OutputFileBatch->url().toLocalFile() );
    fOut.open(QIODevice::WriteOnly);
    QTextStream ostream(&fOut);

    QString line;
    long double jd(0);
    double mjd(0);
    KStarsDateTime dt;

    while ( ! istream.atEnd() ) {
        line = istream.readLine();
        line = line.trimmed();
        QStringList data = line.split( ' ', QString::SkipEmptyParts );

        if ( inputData == 0 ) { //Parse date & time
            //Is the first field parseable as a date or date&time?
            if ( data[0].length() > 10 )
                dt = KStarsDateTime::fromString( data[0] );
            else
                dt = KStarsDateTime( QDate::fromString( data[0] ), QTime(0,0,0) );

            //DEBUG
            kDebug() << data[0];
            if ( dt.isValid() ) kDebug() << dt.toString();

            if ( dt.isValid() ) {
                //Try to parse the second field as a time
                if ( data.size() > 1 ) {
                    QString s = data[1];
                    if ( s.length() == 4 ) s = '0'+s;
                    QTime t = QTime::fromString( s );
                    if ( t.isValid() ) dt.setTime( t );
                }

            } else { //Did not parse the first field as a date; try it as a time
                QTime t = QTime::fromString( data[0] );
                if ( t.isValid() ) {
                    dt.setTime( t );
                    //Now try the second field as a date
                    if ( data.size() > 1 ) {
                        QDate d = QDate::fromString( data[1] );
                        if ( d.isValid() ) dt.setDate( d );
                        else dt.setDate( QDate::currentDate() );
                    }
                }
            }

            if ( dt.isValid() ) {
                //Compute JD and MJD
                jd = dt.djd();
                mjd = jd - MJD0;
            }

        } else if ( inputData == 1 ) {//Parse Julian day
            bool ok(false);
            jd = data[0].toDouble(&ok);
            if ( ok ) {
                dt.setDJD( jd );
                mjd = jd - MJD0;
            }
        } else if ( inputData == 2 ) {//Parse Modified Julian day
            bool ok(false);
            mjd = data[0].toDouble(&ok);
            if ( ok ) {
                jd = mjd + MJD0;
                dt.setDJD( jd );
            }
        }

        //Write to output file
        ostream << KGlobal::locale()->formatDateTime( dt, KLocale::LongDate ) << "  "
                << QString::number( jd, 'f', 2 ) << "  "
                << QString::number( mjd, 'f', 2 ) << endl;

    }

    fOut.close();
}
Пример #8
0
ConjunctionsTool::ConjunctionsTool(QWidget *parentSplit)
    : QFrame(parentSplit), Object1( 0 ), Object2( 0 ) {

    setupUi(this);

    KStarsData *kd = KStarsData::Instance();
    KStarsDateTime dtStart ( KStarsDateTime::currentDateTime() );
    KStarsDateTime dtStop ( dtStart.djd() + 365.24 ); // TODO: Refine

    //startDate -> setDateTime( dtStart.dateTime() );
    //stopDate -> setDateTime( dtStop.dateTime() );
    //TODO Check if this change works
    startDate -> setDateTime( dtStart );
    stopDate -> setDateTime( dtStop );

    geoPlace = kd -> geo();
    LocationButton -> setText( geoPlace -> fullName() );

    // Init filter type combobox
    FilterTypeComboBox->addItem( i18n ("Single Object...") );
    FilterTypeComboBox->addItem( i18n ("Any") );
    FilterTypeComboBox->addItem( i18n ("Stars") );
    FilterTypeComboBox->addItem( i18n ("Solar System") );
    FilterTypeComboBox->addItem( i18n ("Planets") );
    FilterTypeComboBox->addItem( i18n ("Comets") );
    FilterTypeComboBox->addItem( i18n ("Asteroids") );
    FilterTypeComboBox->addItem( i18n ("Open Clusters") );
    FilterTypeComboBox->addItem( i18n ("Globular Clusters") );
    FilterTypeComboBox->addItem( i18n ("Gaseous Nebulae") );
    FilterTypeComboBox->addItem( i18n ("Planetary Nebulae") );
    FilterTypeComboBox->addItem( i18n ("Galaxies") );

    pNames[KSPlanetBase::MERCURY] = i18n("Mercury");
    pNames[KSPlanetBase::VENUS] = i18n("Venus");
    pNames[KSPlanetBase::MARS] = i18n("Mars");
    pNames[KSPlanetBase::JUPITER] = i18n("Jupiter");
    pNames[KSPlanetBase::SATURN] = i18n("Saturn");
    pNames[KSPlanetBase::URANUS] = i18n("Uranus");
    pNames[KSPlanetBase::NEPTUNE] = i18n("Neptune");
    //pNames[KSPlanetBase::PLUTO] = i18n("Pluto");
    pNames[KSPlanetBase::SUN] = i18n("Sun");
    pNames[KSPlanetBase::MOON] = i18n("Moon");

    for ( int i=0; i<KSPlanetBase::UNKNOWN_PLANET; ++i ) {
        //      Obj1ComboBox->insertItem( i, pNames[i] );
        Obj2ComboBox->insertItem( i, pNames[i] );
    }

    // Initialize the Maximum Separation box to 1 degree
    maxSeparationBox->setDegType( true );
    maxSeparationBox->setDMS( "01 00 00.0" );

    //Set up the Table Views
    m_Model = new QStandardItemModel( 0, 5, this );
    m_Model->setHorizontalHeaderLabels( QStringList() << i18n( "Conjunction/Opposition" )
                                        << i18n( "Date & Time (UT)" ) << i18n( "Object 1" ) << i18n( "Object 2" ) << i18n( "Separation" ) );
    m_SortModel = new QSortFilterProxyModel( this );
    m_SortModel->setSourceModel( m_Model );
    OutputList->setModel( m_SortModel );
    OutputList->setSortingEnabled(true);
    OutputList->horizontalHeader()->setStretchLastSection( true );
    OutputList->horizontalHeader()->setSectionResizeMode(  QHeaderView::Interactive );
    OutputList->horizontalHeader()->resizeSection(2, 100);
    OutputList->horizontalHeader()->resizeSection(3, 100);
    OutputList->horizontalHeader()->resizeSection(4, 120); //is it bad way to fix default size of columns ?

    //FilterEdit->showClearButton = true;
    ClearFilterButton->setIcon( QIcon::fromTheme( "edit-clear" , QIcon(":/icons/breeze/default/edit-clear.svg") ) );

    m_index = 0;

    // signals and slots connections
    connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
    connect(Obj1FindButton, SIGNAL(clicked()), this, SLOT(slotFindObject()));
    connect(ComputeButton, SIGNAL(clicked()), this, SLOT(slotCompute()));
    connect( FilterTypeComboBox, SIGNAL( currentIndexChanged(int) ), SLOT( slotFilterType(int) ) );
    connect( ClearButton, SIGNAL( clicked() ), this, SLOT( slotClear() ) );
    connect( ExportButton, SIGNAL( clicked() ), this, SLOT( slotExport() ) );
    connect( OutputList, SIGNAL( doubleClicked( const QModelIndex& ) ), this, SLOT( slotGoto() ) );
    connect( ClearFilterButton, SIGNAL( clicked() ), FilterEdit, SLOT( clear() ) );
    connect( FilterEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterReg( const QString & ) ) );

    show();
}
Пример #9
0
void ConjunctionsTool::slotCompute (void)
{
    KStarsDateTime dtStart = startDate -> dateTime();   // Start date
    KStarsDateTime dtStop = stopDate -> dateTime();     // Stop date
    long double startJD = dtStart.djd();                // Start julian day
    long double stopJD = dtStop.djd();                  // Stop julian day
    bool opposition = false;                            // true=opposition, false=conjunction
    if( Opposition->currentIndex() ) opposition = true;
    QStringList objects;                                // List of sky object used as Object1
    KStarsData *data = KStarsData::Instance();
    int progress = 0;

    // Check if we have a valid angle in maxSeparationBox
    dms maxSeparation( 0.0 );
    bool ok;
    maxSeparation = maxSeparationBox->createDms( true, &ok );

    if( !ok ) {
        KMessageBox::sorry( 0, i18n("Maximum separation entered is not a valid angle. Use the What's this help feature for information on how to enter a valid angle") );
        return;
    }

    // Check if Object1 and Object2 are set
    if( FilterTypeComboBox->currentIndex() == 0 && !Object1 ) {
        KMessageBox::sorry( 0, i18n("Please select an object to check conjunctions with, by clicking on the \'Find Object\' button.") );
        return;
    }
    Object2 = KSPlanetBase::createPlanet( Obj2ComboBox->currentIndex() );
    if( FilterTypeComboBox->currentIndex() == 0 && Object1->name() == Object2->name() ) {
        // FIXME: Must free the created Objects
        KMessageBox::sorry( 0 , i18n("Please select two different objects to check conjunctions with.") );
        return;
    }

    // Init KSConjunct object
    KSConjunct ksc;
    connect( &ksc, SIGNAL(madeProgress(int)), this, SLOT(showProgress(int)) );
    ksc.setGeoLocation( geoPlace );

    switch ( FilterTypeComboBox->currentIndex() ) {
    case 1: // All object types
        foreach( int type, data->skyComposite()->objectNames().keys() )
            objects += data->skyComposite()->objectNames( type );
        break;
    case 2: // Stars
        objects += data->skyComposite()->objectNames( SkyObject::STAR );
        objects += data->skyComposite()->objectNames( SkyObject::CATALOG_STAR );
        break;
    case 3: // Solar system
        objects += data->skyComposite()->objectNames( SkyObject::PLANET );
        objects += data->skyComposite()->objectNames( SkyObject::COMET );
        objects += data->skyComposite()->objectNames( SkyObject::ASTEROID );
        objects += data->skyComposite()->objectNames( SkyObject::MOON );
        objects += i18n("Sun");
        // Remove Object2  planet
        objects.removeAll( Object2->name() );
        break;
    case 4: // Planet
        objects += data->skyComposite()->objectNames( SkyObject::PLANET );
        // Remove Object2  planet
        objects.removeAll( Object2->name() );
        break;
    case 5: // Comet
        objects += data->skyComposite()->objectNames( SkyObject::COMET );
        break;
    case 6: // Ateroid
        objects += data->skyComposite()->objectNames( SkyObject::ASTEROID );
        break;
    case 7: // Open Clusters
        objects = data->skyComposite()->objectNames( SkyObject::OPEN_CLUSTER );
        break;
    case 8: // Open Clusters
        objects = data->skyComposite()->objectNames( SkyObject::GLOBULAR_CLUSTER );
        break;
    case 9: // Gaseous nebulae
        objects = data->skyComposite()->objectNames( SkyObject::GASEOUS_NEBULA );
        break;
    case 10: // Planetary nebula
        objects = data->skyComposite()->objectNames( SkyObject::PLANETARY_NEBULA );
        break;
    case 11: // Galaxies
        objects = data->skyComposite()->objectNames( SkyObject::GALAXY );
        break;
    }

    // Remove all Jupiter and Saturn moons
    // KStars crash if we compute a conjunction between a planet and one of this moon
    if ( FilterTypeComboBox->currentIndex() == 1 ||
            FilterTypeComboBox->currentIndex() == 3 ||
            FilterTypeComboBox->currentIndex() == 6 ) {
        objects.removeAll( "Io" );
        objects.removeAll( "Europa" );
        objects.removeAll( "Ganymede" );
        objects.removeAll( "Callisto" );
        objects.removeAll( "Mimas" );
        objects.removeAll( "Enceladus" );
        objects.removeAll( "Tethys" );
        objects.removeAll( "Dione" );
        objects.removeAll( "Rhea" );
        objects.removeAll( "Titan" );
        objects.removeAll( "Hyperion" );
        objects.removeAll( "Iapetus" );
    }

    if ( FilterTypeComboBox->currentIndex() != 0 ) {
        // Show a progress dialog while processing
        QProgressDialog progressDlg( i18n( "Compute conjunction..." ), i18n( "Abort" ), 0, objects.count(), this);
        progressDlg.setWindowModality( Qt::WindowModal );
        progressDlg.setValue( 0 );

        foreach( QString object, objects ) {
            // If the user click on the 'cancel' button
            if ( progressDlg.wasCanceled() )
                break;

            // Update progress dialog
            ++progress;
            progressDlg.setValue( progress );
            progressDlg.setLabelText( i18n( "Compute conjunction between %1 and %2", Object2->name(), object ) );

            // Compute conjuction
            Object1 = data->skyComposite()->findByName( object );
            showConjunctions( ksc.findClosestApproach(*Object1, *Object2, startJD, stopJD, maxSeparation, opposition), object, Object2->name() );
        }

        progressDlg.setValue( objects.count() );
    } else {