• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • skycomponents
supernovaecomponent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  supernovaecomponent.cpp - K Desktop Planetarium
3  -------------------
4  begin : 2011/18/06
5  copyright : (C) 2011 by Samikshan Bairagya
6  email : samikshan@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "supernovaecomponent.h"
19 #include "skymap.h"
20 #include "skypainter.h"
21 #include "skymesh.h"
22 #include "skylabeler.h"
23 #include "projections/projector.h"
24 #include "dms.h"
25 #include "Options.h"
26 #include "notifyupdatesui.h"
27 
28 #include "kdebug.h"
29 #include "ksfilereader.h"
30 #include "kstandarddirs.h"
31 #include "kstarsdata.h"
32 
33 SupernovaeComponent::SupernovaeComponent(SkyComposite* parent): ListComponent(parent), m_Parser(0)
34 {
35  loadData();
36 }
37 
38 SupernovaeComponent::~SupernovaeComponent() {}
39 
40 void SupernovaeComponent::update(KSNumbers* num)
41 {
42  if ( ! selected() )
43  return;
44  KStarsData *data = KStarsData::Instance();
45  foreach ( SkyObject *so, m_ObjectList ) {
46  if( num )
47  so->updateCoords( num );
48  so->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
49  }
50 }
51 
52 bool SupernovaeComponent::selected()
53 {
54  return Options::showSupernovae();
55 }
56 
57 void SupernovaeComponent::loadData()
58 {
59  QString serialNo, hostGalaxy, date, type, offset, SNPosition, discoverers ;
60  dms ra, dec;
61  float magnitude;
62  kDebug()<<"Loading Supernovae data"<<endl;
63  //m_ObjectList.clear();
64  latest.clear();
65  objectNames(SkyObject::SUPERNOVA).clear();
66 
67  KStarsData *m_data = KStarsData::Instance(); // to convert equatorial coordinate to horizontal
68 
69  //SN ,Host Galaxy ,Date , R.A. , Decl., Offset ,Mag., Disc. Ref. , SN Position , Posn. Ref. ,Typ, SN ,Discoverer(s)
70  QList< QPair<QString,KSParser::DataTypes> > sequence;
71  sequence.append(qMakePair(QString("serialNo"), KSParser::D_QSTRING));
72  sequence.append(qMakePair(QString("hostGalaxy"), KSParser::D_QSTRING));
73  sequence.append(qMakePair(QString("date"), KSParser::D_QSTRING));
74  sequence.append(qMakePair(QString("ra"), KSParser::D_QSTRING));
75  sequence.append(qMakePair(QString("dec"), KSParser::D_QSTRING));
76  sequence.append(qMakePair(QString("offset"), KSParser::D_QSTRING));
77  sequence.append(qMakePair(QString("magnitude"), KSParser::D_FLOAT));
78  sequence.append(qMakePair(QString("ignore1"), KSParser::D_SKIP));
79  sequence.append(qMakePair(QString("SNPosition"), KSParser::D_QSTRING));
80  sequence.append(qMakePair(QString("ignore2"), KSParser::D_SKIP));
81  sequence.append(qMakePair(QString("type"), KSParser::D_QSTRING));
82  sequence.append(qMakePair(QString("ignore3"), KSParser::D_SKIP));
83  sequence.append(qMakePair(QString("discoverers"), KSParser::D_QSTRING));
84 
85  QString file_name = KStandardDirs::locate("appdata",
86  QString("supernovae.dat"));
87  KSParser snParser(file_name, '#', sequence);
88 
89  QHash<QString, QVariant> row_content;
90  while (snParser.HasNextRow()){
91  Supernova *sup=0;
92  row_content = snParser.ReadNextRow();
93 
94  if(row_content["serialNo"].toString() == "Null")
95  continue;
96 
97  serialNo = row_content["serialNo"].toString();
98  hostGalaxy = row_content["hostGalaxy"].toString();
99  date = row_content["date"].toString();
100  ra = dms(row_content["ra"].toString(), false);
101  dec = dms(row_content["dec"].toString());
102  offset = row_content["offset"].toString();
103  magnitude = row_content["magnitude"].toFloat();
104  SNPosition = row_content["SNPosition"].toString();
105  type = row_content["type"].toString();
106  discoverers = row_content["discoverers"].toString();
107 
108  if (magnitude == KSParser::EBROKEN_FLOAT)
109  magnitude = 99.9;
110 
111  sup=new Supernova(ra, dec, date, magnitude, serialNo, type, hostGalaxy, offset, discoverers);
112  sup->EquatorialToHorizontal(m_data->lst(),m_data->geo()->lat());
113  if (!m_ObjectList.empty())
114  {
115  if ( findByName(sup->name() ) == 0 )
116  {
117  //kDebug()<<"List of supernovae not empty. Found new supernova";
118  m_ObjectList.append(sup);
119  latest.append(sup);
120  }/*
121  else
122  m_ObjectList.append(sup);*/
123  }
124  else //if the list is empty
125  {
126  m_ObjectList.append(sup);
127  latest.append(sup);
128  //notifyNewSupernovae();
129  }
130 
131  objectNames(SkyObject::SUPERNOVA).append(sup->name());
132  }
133  //notifyNewSupernovae();
134 }
135 
136 
137 SkyObject* SupernovaeComponent::findByName(const QString& name)
138 {
139  foreach (SkyObject* o, m_ObjectList)
140  {
141  if( QString::compare( o->name(),name, Qt::CaseInsensitive ) == 0 )
142  return o;
143  }
144  //if no object is found then..
145  return 0;
146 }
147 
148 SkyObject* SupernovaeComponent::objectNearest(SkyPoint* p, double& maxrad)
149 {
150  SkyObject* oBest=0;
151  double rBest=maxrad;
152 
153  foreach ( SkyObject* so, m_ObjectList)
154  {
155  double r = so->angularDistanceTo(p).Degrees();
156  //kDebug()<<r;
157  if( r < rBest )
158  {
159  oBest=so;
160  rBest=r;
161  }
162  }
163  maxrad = rBest;
164  return oBest;
165 }
166 
167 
168 float SupernovaeComponent::zoomMagnitudeLimit()
169 {
170  //adjust maglimit for ZoomLevel
171  double lgmin = log10(MINZOOM);
172  double lgz = log10(Options::zoomFactor());
173 
174  return 14.0 + 2.222*( lgz - lgmin ) + 2.222*log10( static_cast<double>(Options::starDensity()) );
175 }
176 
177 
178 void SupernovaeComponent::draw(SkyPainter *skyp)
179 {
180  //kDebug()<<"selected()="<<selected();
181  if ( ! selected() )
182  return;
183 
184  double maglim = zoomMagnitudeLimit();
185 
186  foreach ( SkyObject *so, m_ObjectList ) {
187  Supernova *sup = (Supernova*) so;
188  float mag = sup->mag();
189 
190  if (mag > float( Options::magnitudeLimitShowSupernovae())) continue;
191 
192  //Do not draw if mag>maglim
193  if ( mag > maglim ) {
194  continue;
195  }
196  skyp->drawSupernova(sup);
197  }
198 }
199 
200 void SupernovaeComponent::notifyNewSupernovae()
201 {
202  //kDebug()<<"New Supernovae discovered";
203  QList<SkyObject*> latestList;
204  foreach (SkyObject * so, latest)
205  {
206  Supernova * sup = (Supernova *)so;
207 
208  if (sup->getMagnitude() > float(Options::magnitudeLimitAlertSupernovae()))
209  {
210  kDebug()<<"Not Bright enough to be notified";
211  continue;
212  }
213 
214  kDebug()<<"Bright enough to be notified";
215  latestList.append(so);
216  }
217  if (!latestList.empty())
218  {
219  NotifyUpdatesUI * ui = new NotifyUpdatesUI(0);
220  ui->addItems(latestList);
221  ui->show();
222  }
223 // if (!latest.empty())
224 // KMessageBox::informationList(0, i18n("New Supernovae discovered!"), latestList, i18n("New Supernovae discovered!"));
225 }
226 
227 
228 void SupernovaeComponent::slotTriggerDataFileUpdate()
229 {
230  QString filename= KStandardDirs::locate("appdata","scripts/supernova_updates_parser.py") ;
231  kDebug()<<filename;
232  m_Parser = new QProcess;
233  connect( m_Parser, SIGNAL( finished( int, QProcess::ExitStatus ) ), this, SLOT( slotDataFileUpdateFinished( int, QProcess::ExitStatus ) ) );
234  m_Parser->start("python2", QStringList( filename ));
235 }
236 
237 void SupernovaeComponent::slotDataFileUpdateFinished( int exitCode, QProcess::ExitStatus exitStatus )
238 {
239  if ( exitCode ) {
240  QString errmsg;
241  switch ( exitCode ) {
242  case -2:
243  errmsg = i18n("Could not run python to update supernova information");
244  break;
245  case -1:
246  errmsg = i18n("Python process that updates the supernova information crashed");
247  break;
248  default:
249  errmsg = i18n( "Python process that updates the supernova information failed with error code %1", QString::number( exitCode ) );
250  break;
251  }
252  if( KStars::Instance() && SkyMap::Instance() ) // Displaying a message box causes entry of control into the Qt event loop. Can lead to segfault if we are checking for supernovae alerts during initialization!
253  KMessageBox::sorry( 0, errmsg, i18n("Supernova information update failed") );
254  // FIXME: There should be a better way to check if KStars is fully initialized. Maybe we should have a static boolean in the KStars class. --asimha
255  }
256  else {
257  kDebug()<<"HERE";
258  latest.clear();
259  loadData();
260  notifyNewSupernovae();
261  }
262  delete m_Parser;
263  m_Parser = 0;
264 }
SupernovaeComponent::SupernovaeComponent
SupernovaeComponent(SkyComposite *parent)
Definition: supernovaecomponent.cpp:33
notifyupdatesui.h
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
KSParser
Generic class for text file parsers used in KStars.
Definition: ksparser.h:49
Supernova::getMagnitude
float getMagnitude()
Definition: supernova.h:73
ListComponent::m_ObjectList
QList< SkyObject * > m_ObjectList
Definition: listcomponent.h:64
NotifyUpdatesUI
Definition: notifyupdatesui.h:30
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
Options::magnitudeLimitAlertSupernovae
static double magnitudeLimitAlertSupernovae()
Get Set magnitude limit for supernovae to be alerted.
Definition: Options.h:1512
Options::showSupernovae
static bool showSupernovae()
Get Draw supernovae in the sky map?
Definition: Options.h:1436
SupernovaeComponent::~SupernovaeComponent
virtual ~SupernovaeComponent()
Definition: supernovaecomponent.cpp:38
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
skypainter.h
SkyPoint::updateCoords
virtual void updateCoords(KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0), accounting for both precession and nutation.
Definition: skypoint.cpp:317
Options::starDensity
static int starDensity()
Get Density of stars in the field of view.
Definition: Options.h:2626
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
ListComponent
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyObjects.
Definition: listcomponent.h:36
SupernovaeComponent::notifyNewSupernovae
virtual void notifyNewSupernovae()
Definition: supernovaecomponent.cpp:200
SupernovaeComponent::selected
virtual bool selected()
Definition: supernovaecomponent.cpp:52
dms.h
SupernovaeComponent::objectNearest
virtual SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Find the SkyObject nearest the given SkyPoint.
Definition: supernovaecomponent.cpp:148
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
NotifyUpdatesUI::addItems
void addItems(QList< SkyObject * > updatesList)
Definition: notifyupdatesui.cpp:44
SupernovaeComponent::draw
virtual void draw(SkyPainter *skyp)
Definition: supernovaecomponent.cpp:178
KSParser::D_FLOAT
Definition: ksparser.h:70
SupernovaeComponent::slotTriggerDataFileUpdate
void slotTriggerDataFileUpdate()
This initiates updating of the data file by using supernovae_updates_parser.py.
Definition: supernovaecomponent.cpp:228
MINZOOM
#define MINZOOM
Definition: kstarsdata.h:38
Supernova
Represents the supernova object.
Definition: supernova.h:44
skymap.h
SkyPainter::drawSupernova
virtual bool drawSupernova(Supernova *sup)=0
Draw a Supernova.
SupernovaeComponent::findByName
virtual SkyObject * findByName(const QString &name)
Search the children of this SkyComponent for a SkyObject whose name matches the argument name the nam...
Definition: supernovaecomponent.cpp:137
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyComposite
SkyComposite is a kind of container class for SkyComponent objects.
Definition: skycomposite.h:43
KSParser::EBROKEN_FLOAT
static const float EBROKEN_FLOAT
Definition: ksparser.h:55
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
Options.h
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
ksfilereader.h
Options::magnitudeLimitShowSupernovae
static double magnitudeLimitShowSupernovae()
Get Set magnitude limit for supernovae to be shown on the skymap.
Definition: Options.h:1474
SupernovaeComponent::update
virtual void update(KSNumbers *num=0)
Update the sky positions of this component.
Definition: supernovaecomponent.cpp:40
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
projector.h
SkyMap::Instance
static SkyMap * Instance()
Definition: skymap.cpp:141
SkyObject::SUPERNOVA
Definition: skyobject.h:112
kstarsdata.h
skylabeler.h
skymesh.h
SupernovaeComponent::zoomMagnitudeLimit
static float zoomMagnitudeLimit()
Definition: supernovaecomponent.cpp:168
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
SkyComponent::objectNames
QHash< int, QStringList > & objectNames()
Definition: skycomponent.h:127
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
KSParser::D_SKIP
Definition: ksparser.h:72
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
KSParser::D_QSTRING
Definition: ksparser.h:68
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
Supernova::name
virtual QString name(void) const
Definition: supernova.h:58
QList
supernovaecomponent.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal