[kstars] kstars: Fix a couple of issues with flags. They are supposed to be saved in J2000 internally but where in JNow before.
Jasem Mutlaq
null at kde.org
Tue Feb 7 15:40:28 UTC 2017
Git commit 8ed61da615ba9dceda1b2a4301feb5c2324172ed by Jasem Mutlaq.
Committed on 07/02/2017 at 15:38.
Pushed by mutlaqja into branch 'master'.
Fix a couple of issues with flags. They are supposed to be saved in J2000 internally but where in JNow before.
Fixed other issues with adding, updating, and removing flags.
CCMAIL:kstars-devel at kde.org
M +49 -15 kstars/skycomponents/flagcomponent.cpp
M +7 -5 kstars/skycomponents/flagcomponent.h
M +2 -0 kstars/skycomponents/skymapcomposite.cpp
M +3 -3 kstars/tools/flagmanager.cpp
https://commits.kde.org/kstars/8ed61da615ba9dceda1b2a4301feb5c2324172ed
diff --git a/kstars/skycomponents/flagcomponent.cpp b/kstars/skycomponents/flagcomponent.cpp
index b4bef9b9c..6897e4b10 100644
--- a/kstars/skycomponents/flagcomponent.cpp
+++ b/kstars/skycomponents/flagcomponent.cpp
@@ -99,7 +99,9 @@ void FlagComponent::loadFromFile() {
SkyPoint* flagPoint = new SkyPoint( r, d );
// Convert to JNow
- toJNow(flagPoint, flagEntry.at( 2 ));
+ toJ2000(flagPoint, flagEntry.at( 2 ));
+
+ flagPoint->updateCoordsNow(KStarsData::Instance()->updateNum());
pointList().append( flagPoint );
@@ -155,14 +157,20 @@ void FlagComponent::saveToFile() {
}
}
-void FlagComponent::add( SkyPoint* flagPoint, QString epoch, QString image, QString label, QColor labelColor ) {
+void FlagComponent::add( const SkyPoint & flagPoint, QString epoch, QString image, QString label, QColor labelColor ) {
//JM 2015-02-21: Insert original coords in list and convert skypint to JNow
- m_EpochCoords.append(qMakePair(flagPoint->ra().Degrees(), flagPoint->dec().Degrees()));
+ // JM 2017-02-07: Discard above! We add RAW epoch coordinates to list.
+ // If not J2000, we convert to J2000
+ m_EpochCoords.append(qMakePair(flagPoint.ra().Degrees(), flagPoint.dec().Degrees()));
+
+ SkyPoint *newFlagPoint = new SkyPoint(flagPoint.ra(), flagPoint.dec());
+
+ toJ2000(newFlagPoint, epoch);
- toJNow(flagPoint, epoch);
+ newFlagPoint->updateCoordsNow(KStarsData::Instance()->updateNum());
- pointList().append( flagPoint );
+ pointList().append( newFlagPoint );
m_Epoch.append( epoch );
for(int i = 0; i<m_Names.size(); i++ ) {
@@ -176,7 +184,8 @@ void FlagComponent::add( SkyPoint* flagPoint, QString epoch, QString image, QStr
void FlagComponent::remove( int index ) {
// check if flag of required index exists
- if ( index > pointList().size() - 1 ) {
+ if ( index > pointList().size() - 1 )
+ {
return;
}
@@ -193,17 +202,22 @@ void FlagComponent::remove( int index ) {
#endif
}
-void FlagComponent::updateFlag( int index, SkyPoint *flagPoint, QString epoch, QString image, QString label, QColor labelColor ) {
- if ( index > pointList().size() -1 ) {
+void FlagComponent::updateFlag( int index, const SkyPoint &flagPoint, QString epoch, QString image, QString label, QColor labelColor )
+{
+ if ( index > pointList().size() -1 )
return;
- }
- delete pointList().at( index );
- m_EpochCoords.replace(index, qMakePair(flagPoint->ra().Degrees(), flagPoint->dec().Degrees()));
+ SkyPoint *existingFlag = pointList().at( index );
+
+ existingFlag->setRA0(flagPoint.ra());
+ existingFlag->setDec0(flagPoint.dec());
- toJNow(flagPoint, epoch);
+ // If epoch not J2000, to convert to J2000
+ toJ2000(existingFlag, epoch);
- pointList().replace( index, flagPoint);
+ existingFlag->updateCoordsNow(KStarsData::Instance()->updateNum());
+
+ m_EpochCoords.replace(index, qMakePair(flagPoint.ra().Degrees(), flagPoint.dec().Degrees()));
m_Epoch.replace( index, epoch );
@@ -314,12 +328,19 @@ QImage FlagComponent::imageList( int index ) {
return m_Images.at( index );
}
-void FlagComponent::toJNow(SkyPoint *p, QString epoch)
+void FlagComponent::toJ2000(SkyPoint *p, QString epoch)
{
KStarsDateTime dt;
dt.setFromEpoch(epoch);
- p->apparentCoord(dt.djd(), KStarsData::Instance()->ut().djd());
+ if (dt.djd() == J2000)
+ return;
+
+ p->apparentCoord(dt.djd(), J2000);
+
+ // Store J2000 coords in RA0, DEC0
+ p->setRA0(p->ra());
+ p->setDec0(p->dec());
}
QPair<double, double> FlagComponent::epochCoords(int index)
@@ -331,3 +352,16 @@ QPair<double, double> FlagComponent::epochCoords(int index)
return m_EpochCoords.at(index);
}
+
+void FlagComponent::update( KSNumbers *num )
+{
+ if ( ! selected() )
+ return;
+ KStarsData *data = KStarsData::Instance();
+ foreach ( SkyPoint *p, pointList() )
+ {
+ if (num)
+ p->updateCoordsNow(num);
+ p->EquatorialToHorizontal(data->lst(), data->geo()->lat() );
+ }
+}
diff --git a/kstars/skycomponents/flagcomponent.h b/kstars/skycomponents/flagcomponent.h
index bacffafa7..1039bd670 100644
--- a/kstars/skycomponents/flagcomponent.h
+++ b/kstars/skycomponents/flagcomponent.h
@@ -55,13 +55,15 @@ public:
virtual bool selected();
+ virtual void update( KSNumbers *num=0 );
+
/** @short Add a flag.
- * @param SkyPoint Reference to the SkyPoint used to store coordinates
+ * @param SkyPoint Sky point in epoch coordinates
* @param epoch Moment for which celestial coordinates are specified
* @param image Image name
* @param label Label of the flag
*/
- void add( SkyPoint* flagPoint, QString epoch, QString image, QString label, QColor labelColor );
+ void add( const SkyPoint & flagPoint, QString epoch, QString image, QString label, QColor labelColor );
/** @short Remove a flag.
* @param index Index of the flag to be remove.
@@ -70,13 +72,12 @@ public:
/** @short Update a flag.
*@param index index of the flag to be updated.
- *@param flagPoint new flag point.
*@param epoch new flag epoch.
*@param image new flag image.
*@param label new flag label.
*@param labelColor new flag label color.
*/
- void updateFlag ( int index, SkyPoint* flagPoint, QString epoch, QString image, QString label, QColor labelColor );
+ void updateFlag(int index, const SkyPoint &flagPoint, QString epoch, QString image, QString label, QColor labelColor );
/** @short Return image names.
* @return the list of all image names
@@ -149,7 +150,8 @@ public:
void saveToFile();
private:
- void toJNow(SkyPoint *p, QString epoch);
+ // Convert from given epoch to J2000. If epoch is already J2000, do nothing
+ void toJ2000(SkyPoint *p, QString epoch);
QStringList m_Epoch; /**< List of epochs */
QList<QPair<double, double>> m_EpochCoords; /**< RA/DEC stored in original Epoch */
diff --git a/kstars/skycomponents/skymapcomposite.cpp b/kstars/skycomponents/skymapcomposite.cpp
index 460cb5c9d..b6173ee87 100644
--- a/kstars/skycomponents/skymapcomposite.cpp
+++ b/kstars/skycomponents/skymapcomposite.cpp
@@ -221,6 +221,8 @@ void SkyMapComposite::update(KSNumbers *num )
m_Supernovae->update(num);
//15. Horizon
m_Horizon->update( num );
+ //16. Flags
+ m_Flags->update(num);
}
void SkyMapComposite::updateSolarSystemBodies(KSNumbers *num )
diff --git a/kstars/tools/flagmanager.cpp b/kstars/tools/flagmanager.cpp
index 2f6f3fce0..6717377f1 100644
--- a/kstars/tools/flagmanager.cpp
+++ b/kstars/tools/flagmanager.cpp
@@ -206,13 +206,13 @@ void FlagManager::deleteFlagItem( int flagIdx ) {
void FlagManager::slotAddFlag() {
dms ra( ui->raBox->createDms( false) ); //false means expressed in hours
- dms dec( ui->decBox->createDms( true ) );
- SkyPoint* flagPoint = new SkyPoint( ra, dec );
+ dms dec( ui->decBox->createDms( true ) );
insertFlag( true );
FlagComponent *flags = m_Ks->data()->skyComposite()->flags();
//Add flag in FlagComponent
+ SkyPoint flagPoint( ra, dec );
flags->add( flagPoint, ui->epochBox->text(), ui->flagCombobox->currentText(), ui->flagLabel->text(), ui->labelColorcombo->color() );
ui->flagList->selectRow( m_Model->rowCount() - 1 );
@@ -304,7 +304,7 @@ void FlagManager::slotSaveChanges() {
dms ra( ui->raBox->createDms( false) ); //false means expressed in hours
dms dec( ui->decBox->createDms( true ) );
- SkyPoint* flagPoint = new SkyPoint( ra, dec );
+ SkyPoint flagPoint( ra, dec );
//Update FlagComponent
m_Ks->data()->skyComposite()->flags()->updateFlag( row, flagPoint, ui->epochBox->text(), ui->flagCombobox->currentText(),
More information about the Kstars-devel
mailing list