modelmanager.cpp 6.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/***************************************************************************
                          modelmanager.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : 2012/26/05
    copyright            : (C) 2012 by Samikshan Bairagya
    email                : samikshan@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "ksfilereader.h"
19
#include "modelmanager.h"
20
#include "kstarsdatetime.h"
21 22 23
#include "skymapcomposite.h"
#include "skyobject.h"

24
ModelManager::ModelManager(ObsConditions * obs)
25
{
26 27 28 29 30 31 32
    m_ObsConditions = obs;
    m_PlanetsModel = new SkyObjListModel();
    m_StarsModel = new SkyObjListModel();
    m_GalModel = new SkyObjListModel();
    m_ConModel = new SkyObjListModel();
    m_ClustModel = new SkyObjListModel();
    m_NebModel = new SkyObjListModel();
33 34
    m_MessierModel = new SkyObjListModel();
    m_SharplessModel = new SkyObjListModel();
35 36 37 38 39 40

    m_InitObjects[Star_Model] = QList<SkyObject *>();
    m_InitObjects[Galaxy_Model] = QList<SkyObject *>();
    m_InitObjects[Constellation_Model] = QList<SkyObject *>();
    m_InitObjects[Cluster_Model] = QList<SkyObject *>();
    m_InitObjects[Nebula_Model] = QList<SkyObject *>();
41 42
    m_InitObjects[Messier_Model] = QList<SkyObject *>();
    m_InitObjects[Sharpless_Model] = QList<SkyObject *>();
43
    updateModels(obs);
44 45
}

Samikshan Bairagya's avatar
Samikshan Bairagya committed
46 47
ModelManager::~ModelManager()
{
48 49 50 51 52 53
    delete m_PlanetsModel;
    delete m_StarsModel;
    delete m_GalModel;
    delete m_ConModel;
    delete m_ClustModel;
    delete m_NebModel;
54 55
    delete m_MessierModel;
    delete m_SharplessModel;
Samikshan Bairagya's avatar
Samikshan Bairagya committed
56
}
57

58
void ModelManager::updateModels(ObsConditions * obs)
59
{
60 61
    m_ObsConditions = obs;
    m_InitObjects.clear();
62 63
    resetModels();

64
    KStarsData * data = KStarsData::Instance();
65

66
    KSFileReader fileReader;
67
    if (!fileReader.open("Interesting.dat")) return;
68

69
    while (fileReader.hasMoreLines())
70
    {
71
        QString line = fileReader.readLine();
72

73
        if (line.length() == 0 || line[0] == '#')
74 75
            continue;

76
        SkyObject * o;
77
        if ((o = data->skyComposite()->findByName(line)))
78
        {
79
            //qDebug()<<o->longname()<<o->typeName();
80
            switch(o->type())
81
            {
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                case SkyObject::OPEN_CLUSTER:
                case SkyObject::GLOBULAR_CLUSTER:
                case SkyObject::GALAXY_CLUSTER:
                    m_InitObjects[Cluster_Model].append(o);
                    break;
                case SkyObject::PLANETARY_NEBULA:
                case SkyObject::DARK_NEBULA:
                case SkyObject::GASEOUS_NEBULA:
                    m_InitObjects[Nebula_Model].append(o);
                    break;
                case SkyObject::STAR:
                    m_InitObjects[Star_Model].append(o);
                    break;
                case SkyObject::CONSTELLATION:
                    m_InitObjects[Constellation_Model].append(o);
                    break;
                case SkyObject::GALAXY:
                    m_InitObjects[Galaxy_Model].append(o);
                    break;
101
            }
102 103 104
        }
    }

105
    foreach (SkyObject * so, m_InitObjects.value(Star_Model))
106
    {
107
        //qDebug()<<so->longname()<<so->typeName();
108
        if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
109
        {
110
            m_StarsModel->addSkyObject(new SkyObjItem(so));
111
        }
112 113
    }

114
    foreach (SkyObject * so, m_InitObjects.value(Galaxy_Model))
115
    {
116
        //qDebug()<<so->longname()<<so->typeName();
117
        if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
118
        {
119
            m_GalModel->addSkyObject(new SkyObjItem(so));
120
        }
121 122
    }

123
    foreach (SkyObject * so, m_InitObjects.value(Constellation_Model))
124
    {
125
        if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
126
        {
127
            m_ConModel->addSkyObject(new SkyObjItem(so));
128
        }
129 130
    }

131
    foreach (SkyObject * so, m_InitObjects.value(Cluster_Model))
132
    {
133
        if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
134
        {
135
            m_ClustModel->addSkyObject(new SkyObjItem(so));
136
        }
137 138
    }

139
    foreach (SkyObject * so, m_InitObjects.value(Nebula_Model))
140
    {
141
        if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
142
        {
143
            m_NebModel->addSkyObject(new SkyObjItem(so));
144
        }
145 146
    }

147
    foreach (const QString &name, data->skyComposite()->objectNames(SkyObject::PLANET))
148
    {
149
        SkyObject * so = data->skyComposite()->findByName(name);
150
        //qDebug()<<so->name()<<so->mag();
151
        if (m_ObsConditions->isVisible(data->geo(), data->lst(), so))
152
        {
153
            if (so->name() == "Sun") continue;
154
            m_PlanetsModel->addSkyObject(new SkyObjItem(so));
155 156
        }
    }
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

     for(int i=1;i<=110;i++)
     {
            SkyObject * o;
            if ((o = data->skyComposite()->findByName("M " + QString::number(i))))
                m_MessierModel->addSkyObject(new SkyObjItem(o));
     }
/**
     for(int i=1;i<=350;i++)
     {
            SkyObject * o;
            if ((o = data->skyComposite()->findByName("Sh2 " + QString::number(i))))
                m_SharplessModel->addSkyObject(new SkyObjItem(o));
     }
**/
172 173
}

174 175
void ModelManager::resetModels()
{
176 177 178 179 180 181
    m_PlanetsModel->resetModel();
    m_StarsModel->resetModel();
    m_ConModel->resetModel();
    m_GalModel->resetModel();
    m_ClustModel->resetModel();
    m_NebModel->resetModel();
182 183
    m_MessierModel->resetModel();
    m_SharplessModel->resetModel();
184 185
}

186
SkyObjListModel * ModelManager::returnModel(int type)
187
{
188
    switch(type)
189
    {
190 191 192 193 194 195 196 197 198 199 200 201
        case 0:    //Planet type
            return m_PlanetsModel;
        case 1:    //Star type
            return m_StarsModel;
        case 2:    //Constellation type
            return m_ConModel;
        case 3:    //Galaxy Type
            return m_GalModel;
        case 4:    //Cluster type
            return m_ClustModel;
        case 5:    //Nebula type
            return m_NebModel;
202 203 204 205
        case 6:    //Messier Objects
            return m_MessierModel;
        case 7:    //Sharpless Objects
            return m_SharplessModel;
206 207
        default:
            return 0;
208
    }
209
}