[Kstars-devel] [kstars] kstars: Introducing files for Recent Supernovae.
Samikshan Bairagya
samikshan at gmail.com
Sun Aug 14 21:32:00 UTC 2011
Git commit 91553505100e8f905e82bf980868d2ec7ba8213b by Samikshan Bairagya.
Committed on 28/07/2011 at 10:11.
Pushed by bairagya into branch 'master'.
Introducing files for Recent Supernovae.
kstars/skyobjects/supernova.h
kstars/skyobjects/supernova.cpp
kstars/skycomponents/supernovaecomponent.h
kstars/skycomponents/supernovaecomponent.cpp
CCMAIL: kstars-devel at kde.org
A +69 -0 kstars/skycomponents/supernovaecomponent.h [License: GPL (v2+)]
A +10 -0 kstars/skyobjects/supernova.cpp [License: UNKNOWN] *
A +194 -0 kstars/skycomponents/supernovaecomponent.cpp [License: GPL (v2+)]
A +100 -0 kstars/skyobjects/supernova.h [License: GPL (v2+)]
The files marked with a * at the end have a non valid license. Please read: http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.
http://commits.kde.org/kstars/91553505100e8f905e82bf980868d2ec7ba8213b
diff --git a/kstars/skycomponents/supernovaecomponent.cpp b/kstars/skycomponents/supernovaecomponent.cpp
new file mode 100644
index 0000000..f0cf6ff
--- /dev/null
+++ b/kstars/skycomponents/supernovaecomponent.cpp
@@ -0,0 +1,194 @@
+/***************************************************************************
+ supernovaecomponent.cpp - K Desktop Planetarium
+ -------------------
+ begin : 2011/18/06
+ copyright : (C) 2011 by Samikshan Bairagya
+ email : samikshan at 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. *
+ * *
+ ***************************************************************************/
+
+#include "supernovaecomponent.h"
+#include "skymap.h"
+#include "skypainter.h"
+#include "skymesh.h"
+#include "skylabeler.h"
+#include "projections/projector.h"
+#include "dms.h"
+#include "Options.h"
+
+#include "kdebug.h"
+#include "ksfilereader.h"
+#include "kprocess.h"
+#include "kstandarddirs.h"
+#include "kstarsdata.h"
+
+SupernovaeComponent::SupernovaeComponent(SkyComposite* parent): ListComponent(parent)
+{
+ loadData();
+}
+
+SupernovaeComponent::~SupernovaeComponent() {}
+
+void SupernovaeComponent::update(KSNumbers* num)
+{
+ if ( ! selected() )
+ return;
+ KStarsData *data = KStarsData::Instance();
+ foreach ( SkyObject *so, m_ObjectList ) {
+ if( num )
+ so->updateCoords( num );
+ so->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
+ }
+}
+
+bool SupernovaeComponent::selected()
+{
+ return Options::showSupernovae();
+}
+
+void SupernovaeComponent::loadData()
+{
+ QString line;
+ QString serialNo, hostGalaxy, date, type, offset, SNPosition, discoverers ;
+ QStringList fields;
+ dms ra, dec;
+ float magnitude;
+ KSFileReader fileReader;
+ bool ok;
+ kDebug()<<"Loading Supernovae data"<<endl;
+ if( !fileReader.open("supernovae.dat")) return;
+ latest.clear();
+ objectNames(SkyObject::SUPERNOVA).clear();
+ int lineNum=0;
+
+ while (fileReader.hasMoreLines())
+ {
+ line=fileReader.readLine();
+ Supernova *sup=0;
+ //kDebug()<<line[0]<<" "<<line.size()<<endl;
+ if(line[0]=='#' || line.size()<10) continue;
+ fields=line.split(",");
+ serialNo=fields.at(0);
+ hostGalaxy=fields.at(1);
+ date=fields.at(2);
+
+ ra=dms(fields.at(3),false);
+ dec=dms(fields.at(4));
+
+ offset=fields.at(5);
+
+ if(fields.at(6).isEmpty())
+ magnitude=99;
+ else
+ magnitude=fields.at(6).toFloat(&ok);
+
+ SNPosition=fields.at(8);
+ type=fields.at(10);
+ discoverers=fields.at(12);
+
+ sup=new Supernova(ra, dec, date, magnitude, serialNo, type, hostGalaxy, offset, discoverers);
+
+ if (!m_ObjectList.empty())
+ {
+ if ( findByName(sup->name() ) == 0 )
+ {
+ m_ObjectList.append(sup);
+ latest.append(sup);
+ }
+ else
+ m_ObjectList.append(sup);
+ }
+ else //if the list is empty
+ {
+ m_ObjectList.append(sup);
+ latest.append(sup);
+ }
+
+ objectNames(SkyObject::SUPERNOVA).append(sup->name());
+ }
+}
+
+
+SkyObject* SupernovaeComponent::findByName(const QString& name)
+{
+ foreach (SkyObject* o, m_ObjectList)
+ {
+ if( QString::compare( o->name(),name, Qt::CaseInsensitive ) == 0 )
+ return o;
+ }
+ //if no object is found then..
+ return 0;
+}
+
+SkyObject* SupernovaeComponent::objectNearest(SkyPoint* p, double& maxrad)
+{
+ SkyObject* oBest=0;
+ double rBest=maxrad;
+
+ foreach ( SkyObject* so, m_ObjectList)
+ {
+ double r = so->angularDistanceTo(p).Degrees();
+ //kDebug()<<r;
+ if( r < rBest )
+ {
+ oBest=so;
+ rBest=r;
+ }
+ }
+ maxrad = rBest;
+ return oBest;
+}
+
+
+float SupernovaeComponent::zoomMagnitudeLimit(){
+
+ //adjust maglimit for ZoomLevel
+ double lgmin = log10(MINZOOM);
+ double lgz = log10(Options::zoomFactor());
+
+ return 14.0 + 2.222*( lgz - lgmin ) + 2.222*log10( Options::starDensity() );
+}
+
+
+void SupernovaeComponent::draw(SkyPainter *skyp)
+{
+ if ( ! selected() )
+ return;
+
+ SkyMap *map = SkyMap::Instance();
+
+ bool checkSlewing = ( map->isSlewing() && Options::hideOnSlew() );
+
+ double maglim = zoomMagnitudeLimit();
+
+ foreach ( SkyObject *so, m_ObjectList )
+ {
+ Supernova *sup = (Supernova*) so;
+
+ float mag = sup->mag();
+
+ //Do not draw if mag>maglim
+ if ( mag > maglim )
+ {
+ continue;
+ }
+
+ bool drawn = skyp->drawSupernova(sup);
+ }
+}
+
+void SupernovaeComponent::updateDataFile()
+{
+ KProcess *parser=new KProcess;
+ QString filename= KStandardDirs::locateLocal("appdata","scripts/supernova_updates_parser.py") ;
+ parser->execute("python",QStringList(filename));
+ loadData();
+}
diff --git a/kstars/skycomponents/supernovaecomponent.h b/kstars/skycomponents/supernovaecomponent.h
new file mode 100644
index 0000000..ab824c6
--- /dev/null
+++ b/kstars/skycomponents/supernovaecomponent.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ supernovaecomponent.h - K Desktop Planetarium
+ -------------------
+ begin : 2011/18/06
+ copyright : (C) 2011 by Samikshan Bairagya
+ email : samikshan at 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef SUPERNOVAE_COMPONENT_H
+#define SUPERNOVAE_COMPONENT_H
+
+#include "listcomponent.h"
+#include "skyobjects/supernova.h"
+
+#include "ksnumbers.h"
+
+#include <QList>
+
+/**
+ * @class SupernovaeComponent This class encapsulates Supernovae.
+ *
+ * @author Samikshan Bairagya
+ *
+ * @version 0.1
+ */
+
+class Supernova;
+
+class SupernovaeComponent : public ListComponent
+{
+public:
+ SupernovaeComponent(SkyComposite* parent);
+ virtual ~SupernovaeComponent();
+ virtual bool selected();
+ virtual void update(KSNumbers* num = 0);
+ virtual SkyObject* findByName(const QString& name);
+ virtual SkyObject* objectNearest(SkyPoint* p, double& maxrad);
+
+ /**
+ * @note This should actually be implemented in a better manner.
+ * Possibly by checking if the host galaxy for the supernova is drawn.
+ */
+ virtual void draw(SkyPainter* skyp);
+
+ /**
+ * @short This updates the data file by using supernovae_updates_parser.py
+ */
+ void updateDataFile();
+
+ /**
+ * @note Basically copy pasted from StarComponent::zoomMagnitudeLimit()
+ */
+ static float zoomMagnitudeLimit();
+private:
+ void loadData();
+
+ QList<SkyObject*> latest;
+};
+
+#endif
\ No newline at end of file
diff --git a/kstars/skyobjects/supernova.cpp b/kstars/skyobjects/supernova.cpp
new file mode 100644
index 0000000..1719977
--- /dev/null
+++ b/kstars/skyobjects/supernova.cpp
@@ -0,0 +1,10 @@
+#include "supernova.h"
+
+Supernova::Supernova(dms ra, dms dec, QString& date ,float m, const QString& serialNo,
+ const QString& type, const QString& hostGalaxy, const QString& offset,
+ const QString& discoverer)
+ : SkyObject(SkyObject::SUPERNOVA,ra, dec, m, serialNo), RA(ra),
+ Dec(dec),date(date), Magnitude(m),serialNumber(serialNo), type(type), hostGalaxy(hostGalaxy),
+ offset(offset), discoverers(discoverer)
+
+{}
\ No newline at end of file
diff --git a/kstars/skyobjects/supernova.h b/kstars/skyobjects/supernova.h
new file mode 100644
index 0000000..6e801e4
--- /dev/null
+++ b/kstars/skyobjects/supernova.h
@@ -0,0 +1,100 @@
+/***************************************************************************
+ supernova.h - K Desktop Planetarium
+ -------------------
+ begin : Sunday, 19th June, 2011
+ copyright : (C) 2011 by Samikshan Bairagya
+ email : samikshan at 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef SUPERNOVA_H
+#define SUPERNOVA_H
+
+#include "skyobject.h"
+
+#include <qvarlengtharray.h>
+
+/**
+ * @class Supernova
+ * Represents the supernova object. It is a subclass of the SkyObject class.
+ * This class has the information for different supernovae.
+ * @author Samikshan Bairagya
+ */
+
+/**
+ * @note The Data File Contains the following parameters
+ * @li RA Right Ascension
+ * @li Dec Declination
+ * @li Magnitude Magnitude at discovery
+ * @li serialNumber Serial Number for the Supernova
+ * @li type Supernova Type
+ * @li hostGalaxy Host Galaxy for the supernova
+ * @li offset Offset from the nucleus of the host galaxy as reported at time of discovery
+ * @li discoverer Discoverer(s) of the supernova
+ * @li date Date of observation of the supernova
+ */
+class Supernova : public SkyObject
+{
+public:
+ explicit Supernova( dms ra, dms dec, QString& date, float m = 0.0, const QString& serialNo=QString(),
+ const QString& type=QString(), const QString& hostGalaxy=QString(), const QString& offset=QString(),const QString& discoverer=QString() );
+ //virtual Supernova* clone() const;
+
+ /** Destructor(Empty) */
+ virtual ~Supernova() {}
+
+ //virtual bool loadData();
+
+ //void setNames( QString name, QString name2 );
+
+ /** @return true if the star has a serial number */
+ inline bool hasName() const { return ( !serialNumber.isEmpty()); }
+
+ /** @return the Serial Number of the Supernova */
+ inline virtual QString name( void ) const { return serialNumber;}
+
+ /**
+ *@return the Right Ascension
+ */
+ inline dms getRA() { return RA ; }
+
+ /**
+ *@return the Declination
+ */
+ inline dms getDec() { return Dec ; }
+
+ /**
+ * @return Magnitude for the Supernova
+ */
+ inline float getMagnitude() { return Magnitude ; }
+
+ /**
+ * @return the type of the supernova
+ */
+ inline QString getType() { return type; }
+
+ /**
+ * @return the host galaxy of the supernova
+ */
+ inline QString getHostGalaxy() { return hostGalaxy; }
+
+ /**
+ * @return the date the supernova was observed
+ */
+ inline QString getDate() { return date; }
+
+private:
+ QString serialNumber, type, hostGalaxy, offset, discoverers, date;
+ dms RA, Dec;
+ float Magnitude;
+};
+
+#endif
\ No newline at end of file
More information about the Kstars-devel
mailing list