deepskyobject.cpp 6.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/***************************************************************************
                          deepskyobject.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : Sun Feb 11 2001
    copyright            : (C) 2001 by Jason Harris
    email                : jharris@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.                                   *
 *                                                                         *
 ***************************************************************************/

18
19
#include "deepskyobject.h"

20
21
#include <typeinfo>

22
23
24
25
#include <QFile>
#include <QRegExp>
#include <QPainter>
#include <QImage>
26

27
28
#include <assert.h>

29
#include "kstarsdata.h"
30
31
#include "ksutils.h"
#include "dms.h"
32
#ifndef KSTARS_LITE
33
#include "kspopupmenu.h"
34
#endif
35
#include "Options.h"
36
#include "skymap.h"
37
#include "texturemanager.h"
38
#include "catalogentrydata.h"
39

40
#include <QDebug>
41
#include <KLocalizedString>
42

Henry de Valence's avatar
Henry de Valence committed
43
44
45
46
47
48
49
50
51
DeepSkyObject::DeepSkyObject( const DeepSkyObject &o )
    : SkyObject( o )
    , PositionAngle( o.PositionAngle )
    , m_image( o.m_image )
    , UGC( o.UGC )
    , PGC( o.PGC )
    , MajorAxis( o.MajorAxis )
    , MinorAxis( o.MinorAxis )
    , Catalog( o.Catalog )
52
{
Jasem Mutlaq's avatar
Jasem Mutlaq committed
53
    customCat = NULL;
54
55
    Flux = o.flux();
    setMag( o.mag() );
56
    updateID = updateNumID = 0;
57
58
59
}

DeepSkyObject::DeepSkyObject( int t, dms r, dms d, float m,
60
61
62
                              const QString &n, const QString &n2,
                              const QString &lname, const QString &cat,
                              float a, float b, double pa, int pgc, int ugc )
63
64
        : SkyObject( t, r, d, m, n, n2, lname )
{
65
66
67
68
69
70
    MajorAxis = a;
    MinorAxis = b;
    PositionAngle = pa;
    PGC = pgc;
    UGC = ugc;
    setCatalog( cat );
71
    updateID = updateNumID = 0;
Jasem Mutlaq's avatar
Jasem Mutlaq committed
72
73
    customCat = NULL;
    Flux = 0;
74
75
76

    // Disable image loading on init
    //loadImage();
77
78
}

79
DeepSkyObject::DeepSkyObject( const CatalogEntryData &data, CatalogComponent *cat )
80
81
82
{
    // FIXME: This assumes that CatalogEntryData coordinates have
    // J2000.0 as epoch as opposed to the catalog's epoch!!! -- asimha
83
    qWarning() << "Creating a DeepSkyObject from CatalogEntryData assumes that coordinates are J2000.0";
84
85
86
87
    setType( data.type );
    setRA0( data.ra/15.0 ); // NOTE: CatalogEntryData stores RA in degrees, whereas setRA0() wants it in hours.
    setDec0( data.dec );
    setLongName( data.long_name );
88
89
90
91
92
93
    if( ! data.catalog_name.isEmpty() )
        setName( data.catalog_name + ' ' + QString::number( data.ID ) );
    else {
        setName( data.long_name );
        setLongName( QString() );
    }
94
95
96
    MajorAxis = data.major_axis;
    MinorAxis = data.minor_axis;
    PositionAngle = data.position_angle;
97
    setMag( data.magnitude );
98
99
100
101
    PGC = 0;
    UGC = 0;
    setCatalog( data.catalog_name );
    updateID = updateNumID = 0;
102
    customCat = cat;
103
    Flux = data.flux;
104
105
106

    // Disable image loading on init
    //loadImage();
107
108
}

109
110
DeepSkyObject* DeepSkyObject::clone() const
{
111
    Q_ASSERT( typeid( this ) == typeid( static_cast<const DeepSkyObject *>( this ) ) ); // Ensure we are not slicing a derived class
112
113
    return new DeepSkyObject(*this);
}
Akarsh Simha's avatar
Akarsh Simha committed
114

115
void DeepSkyObject::initPopupMenu( KSPopupMenu *pmenu ) {
116
#ifndef KSTARS_LITE
117
    pmenu->createDeepSkyObjectMenu( this );
118
#endif
119
120
}

121
122
123
float DeepSkyObject::e() const {
    if ( MajorAxis==0.0 || MinorAxis==0.0 )
        return 1.0; //assume circular
124
    return MinorAxis / MajorAxis;
125
126
127
}

QString DeepSkyObject::catalog() const {
128
129
130
131
    if ( isCatalogM() ) return QString("M");
    if ( isCatalogNGC() ) return QString("NGC");
    if ( isCatalogIC() ) return QString("IC");
    return QString();
132
133
134
}

void DeepSkyObject::setCatalog( const QString &cat ) {
135
136
137
138
    if ( cat.toUpper() == "M" ) Catalog = (unsigned char)CAT_MESSIER;
    else if ( cat.toUpper() == "NGC" ) Catalog = (unsigned char)CAT_NGC;
    else if ( cat.toUpper() == "IC"  ) Catalog = (unsigned char)CAT_IC;
    else Catalog = (unsigned char)CAT_UNKNOWN;
Akarsh Simha's avatar
Akarsh Simha committed
139
}
140

141
void DeepSkyObject::loadImage()
142
{
143
    QString tname = name().toLower().remove(' ');
144
    m_image = TextureManager::getImage( tname );
145
    imageLoaded=true;
146
}
147

148
double DeepSkyObject::labelOffset() const {
149
150
    //Calculate object size in pixels
    double majorAxis = a();
151
152
153
154
155
    double minorAxis = b();
    if ( majorAxis == 0.0 && type() == 1 ) { //catalog stars
      majorAxis = 1.0;
      minorAxis = 1.0;
    }
Henry de Valence's avatar
Henry de Valence committed
156
    double size = ((majorAxis + minorAxis) / 2.0 ) * dms::PI * Options::zoomFactor()/10800.0;
157
    return 0.5*size + 4.;
158
}
159

160
161
QString DeepSkyObject::labelString() const
{
162
    QString oName;
163
164
    if( Options::showDeepSkyNames() )
    {
165
166
167
168
169
170
        if( Options::deepSkyLongLabels() && translatedLongName() != translatedName() )
            oName = translatedLongName() + " (" + translatedName() + ')';
        else
            oName = translatedName();
    }

171
172
    if( Options::showDeepSkyMagnitudes() )
    {
173
        if( Options::showDeepSkyNames() )
174
175
            oName += " ";
        oName += "[" + QLocale().toString( mag(), 'f', 1 ) + "m]";
176
177
178
179
180
    }

    return oName;
}

181
182
183
184

SkyObject::UID DeepSkyObject::getUID() const
{
    // mag takes 10 bit
Akarsh Simha's avatar
Akarsh Simha committed
185
    SkyObject::UID m = mag()*10;
186
187
188
    if( m < 0 ) m = 0;

    // Both RA & dec fits in 24-bits
189
190
    SkyObject::UID ra  = ra0().Degrees() * 36000;
    SkyObject::UID dec = (ra0().Degrees()+91) * 36000;
191
192
193
194
195

    assert("Magnitude is expected to fit into 10bits" && m>=0 && m<(1<<10));
    assert("RA should fit into 24bits"  && ra>=0  && ra <(1<<24));
    assert("Dec should fit into 24bits" && dec>=0 && dec<(1<<24));

Akarsh Simha's avatar
Akarsh Simha committed
196
    // Choose kind of
197
198
199
    SkyObject::UID kind = type() == SkyObject::GALAXY ? SkyObject::UID_GALAXY : SkyObject::UID_DEEPSKY;
    return (kind << 60) | (m << 48) | (ra << 24) | dec;
}