Kstars

skyobjitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Samikshan Bairagya <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "skyobjitem.h"
8 
9 #include "catalogobject.h"
10 #include "ksfilereader.h"
11 #include "kspaths.h"
12 #include "ksplanetbase.h"
13 #include "kstarsdata.h"
14 #include "ksutils.h"
15 
16 #include <QDirIterator>
17 
19  : m_Name(so->name()), m_LongName(so->longname()), m_TypeName(so->typeName()), m_So(so)
20 {
21  switch (so->type())
22  {
23  case SkyObject::PLANET:
24  case SkyObject::MOON:
25  m_Type = Planet;
26  break;
27  case SkyObject::STAR:
28  case SkyObject::CATALOG_STAR:
29  case SkyObject::MULT_STAR:
30  m_Type = Star;
31  break;
32  case SkyObject::CONSTELLATION:
33  case SkyObject::ASTERISM:
34  m_Type = Constellation;
35  break;
36  case SkyObject::GALAXY:
37  m_Type = Galaxy;
38  break;
39  case SkyObject::OPEN_CLUSTER:
40  case SkyObject::GLOBULAR_CLUSTER:
41  case SkyObject::GALAXY_CLUSTER:
42  m_Type = Cluster;
43  break;
44  case SkyObject::PLANETARY_NEBULA:
45  case SkyObject::SUPERNOVA_REMNANT:
46  case SkyObject::GASEOUS_NEBULA:
47  case SkyObject::DARK_NEBULA:
48  m_Type = Nebula;
49  break;
50  case SkyObject::SUPERNOVA:
51  m_Type = Supernova;
52  }
53 
54  setPosition(m_So);
55 }
56 
58 {
59  switch (role)
60  {
61  case DispNameRole:
62  return getDescName();
63  case DispImageRole:
64  return getImageURL(true);
65  case DispSummaryRole:
66  return getSummary(true);
67  case CategoryRole:
68  return getType();
69  case CategoryNameRole:
70  return getTypeName();
71  default:
72  return QVariant();
73  }
74 }
75 
76 ///Moved to skyobjlistmodel.cpp
77 /*
78 QHash<int, QByteArray> SkyObjItem::roleNames() const
79 {
80  QHash<int, QByteArray> roles;
81  roles[DispNameRole] = "dispName";
82  roles[CategoryRole] = "type";
83  roles[CategoryNameRole] = "typeName";
84  return roles;
85 }
86 */
87 
89 {
90  double altitude;
91  dms azimuth;
92  if (so->type() == SkyObject::SATELLITE)
93  {
94  altitude = so->alt().Degrees();
95  azimuth = so->az();
96  }
97  else
98  {
99  KStarsData *data = KStarsData::Instance();
100  KStarsDateTime ut = data->geo()->LTtoUT(
101  KStarsDateTime(QDateTime::currentDateTime().toLocalTime()));
102  SkyPoint sp = so->recomputeCoords(ut, data->geo());
103 
104  //check altitude of object at this time.
105  sp.EquatorialToHorizontal(data->lst(), data->geo()->lat());
106  altitude = sp.alt().Degrees();
107  azimuth = sp.az();
108  }
109 
110  double rounded_altitude = (int)(altitude / 5.0) * 5.0;
111 
112  if (rounded_altitude <= 0)
113  m_Position = "<span style='color:red'>" +
114  xi18n("NOT VISIBLE: About %1 degrees below the %2 horizon",
115  -rounded_altitude, KSUtils::toDirectionString(azimuth)) +
116  "</span>";
117  else
118  m_Position = "<span style='color:yellow'>" +
119  xi18n("Now visible: About %1 degrees above the %2 horizon",
120  rounded_altitude, KSUtils::toDirectionString(azimuth)) +
121  "</span>";
122 }
123 
124 QString findImage(const QString &prefix, const SkyObject &obj, const QString &suffix)
125 {
126  static const auto base =
127  KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
128  QDirIterator search(
129  base,
130  QStringList() << prefix + obj.name().toLower().remove(' ').remove('/') + suffix,
132 
133  return search.hasNext() ? QUrl::fromLocalFile(search.next()).url() : "";
134 }
135 QString SkyObjItem::getImageURL(bool preferThumb) const
136 {
137  const auto &thumbURL = findImage("thumb-", *m_So, ".png");
138 
139  const auto &fullSizeURL = findImage("image-", *m_So, ".png");
140  const auto &wikiImageURL =
142  "descriptions/wikiImage-" +
143  m_So->name().toLower().remove(' ') +
144  ".png"))
145  .url();
146  QString XPlanetURL =
148  "xplanet/" + m_So->name() + ".png"))
149  .url();
150 
151  //First try to return the preferred file
152  if (!thumbURL.isEmpty() && preferThumb)
153  return thumbURL;
154  if (!fullSizeURL.isEmpty() && (!preferThumb))
155  return fullSizeURL;
156 
157  //If that fails, try to return the large image first, then the thumb, and then if it is a planet, the xplanet image. Finally if all else fails, the wiki image.
158  QString fname = fullSizeURL;
159 
160  if (fname.isEmpty())
161  {
162  fname = thumbURL;
163  }
164  if (fname.isEmpty() && m_Type == Planet)
165  {
166  fname = XPlanetURL;
167  }
168  if (fname.isEmpty())
169  {
170  fname = wikiImageURL;
171  }
172  return fname;
173 }
174 
175 QString SkyObjItem::getSummary(bool includeDescription) const
176 {
177  if (includeDescription)
178  {
179  QString description = loadObjectDescription();
180  if(description.indexOf(".") > 0) //This will shorten the description in the list to just a sentence, whereas in the larger space of the Object Information Summary, it is a full paragraph.
181  return m_So->typeName() + "<BR>" + getRADE() + "<BR>" + getAltAz() + "<BR><BR>" + description.left(description.indexOf(".") + 1);
182  else
183  return m_So->typeName() + "<BR>" + getRADE() + "<BR>" + getAltAz() + "<BR><BR>" + description;
184  }
185  else
186  return m_So->typeName() + "<BR>" + getRADE() + "<BR>" + getAltAz();
187 }
188 
190 {
191  /** Surface Brightness is applicable only for extended light sources like
192  * Deep-Sky Objects. Here we use the formula SB = m + log10(a*b/4)
193  * where m is the magnitude of the sky-object. a and b are the major and minor
194  * axis lengths of the objects respectively in arcminutes. SB is the surface
195  * brightness obtained in mag * arcminutes^-2
196  */
197 
198  auto *dso = dynamic_cast<CatalogObject*>(m_So);
199  float SB = m_So->mag();
200 
201  if (dso != nullptr)
202  SB += 2.5 * log10(dso->a() * dso->b() / 4);
203 
204  switch (getType())
205  {
206  case Galaxy:
207  case Nebula:
208  return QLocale().toString(SB, 'f', 2) + "<BR> (mag/arcmin^2)";
209  default:
210  return QString(" --"); // Not applicable for other sky-objects
211  }
212 }
213 
215 {
216  switch (getType())
217  {
218  case Galaxy:
219  case Cluster:
220  case Nebula:
221  return QLocale().toString(((CatalogObject *)m_So)->a(), 'f', 2) + "\"";
222  case Planet:
223  return QLocale().toString(((KSPlanetBase *)m_So)->angSize(), 'f', 2) + "\"";
224  default:
225  return QString(" --");
226  }
227 }
228 
229 inline QString SkyObjItem::loadObjectDescription() const
230 {
231  QFile file;
232  QString fname = "description-" + getName().toLower().remove(' ') + ".html";
233  //determine filename in local user KDE directory tree.
234  file.setFileName(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("descriptions/" + fname));
235 
236  if (file.exists())
237  {
238  if (file.open(QIODevice::ReadOnly))
239  {
240  QTextStream in(&file);
241  QString line;
242  line = in.readLine(); //This should only read the description since the source is on the next line
243  file.close();
244  return line;
245  }
246  }
247  return getTypeName();
248 }
249 
251 {
252  return "RA: " + m_So->ra().toHMSString() + "<BR>DE: " + m_So->dec().toDMSString();
253 }
254 
256 {
257  return "Alt: " + QString::number(m_So->alt().Degrees(), 'f', 2) +
258  ", Az: " + QString::number(m_So->az().Degrees(), 'f', 2);
259 }
260 
262 {
263  return m_So->mag();
264 }
const dms & alt() const
Definition: skypoint.h:281
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
float getMagnitude() const
Get magnitude of sky-object associated with the SkyObjItem.
Definition: skyobjitem.cpp:261
QString number(int n, int base)
int getType() const
Get category of sky-object associated with the SkyObjItem as an integer.
Definition: skyobjitem.h:99
virtual bool open(QIODevice::OpenMode mode) override
QDateTime currentDateTime()
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
QString getDescName() const
Get longname of sky-object associated with the SkyObjItem.
Definition: skyobjitem.h:75
QString url(QUrl::FormattingOptions options) const const
virtual QString name(void) const
Definition: skyobject.h:145
float mag() const
Definition: skyobject.h:206
QString xi18n(const char *text, const TYPE &arg...)
bool exists() const const
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition: skypoint.cpp:77
const QString toHMSString(const bool machineReadable=false, const bool highPrecision=false) const
Definition: dms.cpp:370
int type(void) const
Definition: skyobject.h:188
QString getSummary(bool includeDescription) const
Get Summary Description for the SkyObjItem.
Definition: skyobjitem.cpp:175
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
Definition: dms.cpp:279
const CachingDms & dec() const
Definition: skypoint.h:269
bool isEmpty() const const
QUrl fromLocalFile(const QString &localFile)
SkyObjItem(SkyObject *so=nullptr)
Constructor.
Definition: skyobjitem.cpp:18
QString toString(qlonglong i) const const
void setFileName(const QString &name)
SkyPoint recomputeCoords(const KStarsDateTime &dt, const GeoLocation *geo=nullptr) const
The equatorial coordinates for the object on date dt are computed and returned, but the object's inte...
Definition: skyobject.cpp:295
virtual void close() override
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QString & remove(int position, int n)
QString getTypeName() const
Get category of sky-object associated with the SkyObjItem as a QString.
Definition: skyobjitem.h:93
QString getRADE() const
Get current RA/DE of sky-object associated with the SkyObjItem.
Definition: skyobjitem.cpp:250
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
static QString typeName(const int t)
Definition: skyobject.cpp:338
QString toLower() const const
const CachingDms & ra() const
Definition: skypoint.h:263
QString left(int n) const const
const double & Degrees() const
Definition: dms.h:141
QString getName() const
Get name of sky-object associated with the SkyObjItem.
Definition: skyobjitem.h:69
QString getSize() const
Get size of sky-object associated with the SkyObjItem as a QString to be displayed on the details-vie...
Definition: skyobjitem.cpp:214
A simple container object to hold the minimum information for a Deep Sky Object to be drawn on the sk...
Definition: catalogobject.h:40
Information about an object in the sky.
Definition: skyobject.h:41
QString getAltAz() const
Get current Altitude and Azimuth of sky-object associated with the SkyObjItem.
Definition: skyobjitem.cpp:255
void setPosition(SkyObject *so)
Set current position of the sky-object in the sky.
Definition: skyobjitem.cpp:88
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
QString getSurfaceBrightness() const
Get surface-brightness of sky-object associated with the SkyObjItem as a QString to be displayed on t...
Definition: skyobjitem.cpp:189
QVariant data(int role)
Get data associated with a particular role for the SkyObjItem.
Definition: skyobjitem.cpp:57
const dms & az() const
Definition: skypoint.h:275
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:55:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.