catalogcomponent.cpp 5.44 KB
Newer Older
1
/***************************************************************************
2
                    catalogcomponent.cpp  -  K Desktop Planetarium
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
                             -------------------
    begin                : 2005/17/08
    copyright            : (C) 2005 by Thomas Kabelmann
    email                : thomas.kabelmann@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

18
#include "catalogcomponent.h"
19

20 21 22
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
23 24 25 26
#include <QDir>
#include <QFile>
#include <QPixmap>
#include <QTextStream>
27 28 29
#include "kstars/Options.h"
#include "kstars/kstarsdata.h"
#include "kstars/skymap.h"
30 31
#include "skyobjects/starobject.h"
#include "skyobjects/deepskyobject.h"
32
#include "kstars/skypainter.h"
33

34 35 36
QStringList CatalogComponent::m_Columns
                            = QString( "ID RA Dc Tp Nm Mg Flux Mj Mn PA Ig" )
                              .split( ' ',QString::SkipEmptyParts );
37

38 39 40 41 42
CatalogComponent::CatalogComponent(SkyComposite *parent,
                                   const QString &catname,
                                   bool showerrs, int index)
                                 : ListComponent(parent), m_catName(catname),
                                   m_Showerrs(showerrs), m_ccIndex(index) {
43
    loadData();
44 45
}

46
CatalogComponent::~CatalogComponent() {
47 48
}

49
void CatalogComponent::loadData() {
50
    emitProgressText( i18n("Loading custom catalog: %1", m_catName ) );
51

Rishab Arora's avatar
Rishab Arora committed
52
    QList < QPair <int, QString> > names;
53

54 55 56 57
    KStars::Instance()->data()->catalogdb()->GetAllObjects(m_catName,
                                                           m_ObjectList,
                                                           names,
                                                           this);
Rishab Arora's avatar
Rishab Arora committed
58 59 60 61
    for (int iter = 0; iter < names.size(); iter++) {
        if (names.at(iter).first <= SkyObject::TYPE_UNKNOWN) {
            objectNames(names.at(iter).first).append(names.at(iter).second);
        }
62
    }
63

64 65 66 67 68 69 70
    CatalogData loaded_catalog_data;
    KStars::Instance()->data()->catalogdb()->GetCatalogData(m_catName, loaded_catalog_data);
    m_catPrefix = loaded_catalog_data.prefix;
    m_catColor = loaded_catalog_data.color;
    m_catFluxFreq = loaded_catalog_data.fluxfreq;
    m_catFluxUnit = loaded_catalog_data.fluxunit;
    m_catEpoch = loaded_catalog_data.epoch;
71 72
}

73
void CatalogComponent::update( KSNumbers * ) {
74
    if ( selected() ) {
75
        KStarsData *data = KStarsData::Instance();
76
        foreach ( SkyObject *obj, m_ObjectList ) {
77
            DeepSkyObject *dso  = dynamic_cast< DeepSkyObject * >( obj );
78
            StarObject *so = dynamic_cast< StarObject *>( obj );
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
            Q_ASSERT( dso || so ); // We either have stars, or deep sky objects
            if( dso ) {
                // Update the deep sky object if need be
                if ( dso->updateID != data->updateID() ) {
                    dso->updateID = data->updateID();
                    if ( dso->updateNumID != data->updateNumID() ) {
                        dso->updateCoords( data->updateNum() );

                    }
                    dso->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
                }
            }
            else {
                // Do exactly the same thing for stars
                if ( so->updateID != data->updateID() ) {
                    so->updateID = data->updateID();
                    if ( so->updateNumID != data->updateNumID() ) {
                        so->updateCoords( data->updateNum() );
                    }
                    so->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
                }
            }
101
        }
102
        this->updateID = data->updateID();
103 104 105
    }
}

106
void CatalogComponent::draw( SkyPainter *skyp ) {
107
    if ( ! selected() ) return;
108

109 110
    skyp->setBrush( Qt::NoBrush );
    skyp->setPen( QColor( m_catColor ) );
111

112 113 114 115
    // Check if the coordinates have been updated
    if( updateID != KStarsData::Instance()->updateID() )
        update( 0 );

116
    //Draw Custom Catalog objects
117
    foreach ( SkyObject *obj, m_ObjectList ) {
118
        if ( obj->type()==0 ) {
119 120
            StarObject *starobj = static_cast<StarObject*>(obj);
            // FIXME SKYPAINTER
121 122
            skyp->drawPointSource(starobj, starobj->mag(), starobj->spchar() );
        } else {
123 124
            // FIXME: this PA calc is totally different from the one that was
            // in DeepSkyComponent which is now in SkyPainter .... O_o
125
            //      --hdevalence
126 127 128 129
            // PA for Deep-Sky objects is 90 + PA because major axis is
            // horizontal at PA=0
            // double pa = 90. + map->findPA( dso, o.x(), o.y() );
            DeepSkyObject *dso = static_cast<DeepSkyObject*>(obj);
130
            skyp->drawDeepSkyObject(dso, true);
131 132
        }
    }
133
}
134

135
bool CatalogComponent::selected() {
136 137 138 139
    if (Options::showCatalogNames().contains(m_catName))
      return true;
    return false;
}