Kstars

catalogobject.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
3 SPDX-FileCopyrightText: 2021 Valentin Boettcher <hiro at protagon.space; @hiro98:tchncs.de>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "catalogobject.h"
9#include "ksutils.h"
10#include "Options.h"
11#include "skymap.h"
12#include "texturemanager.h"
13#include "kstarsdata.h"
14#include "kspopupmenu.h"
15#include "catalogsdb.h"
16#include <QCryptographicHash>
17#include <typeinfo>
18
20{
21 Q_ASSERT(typeid(this) == typeid(static_cast<const CatalogObject *>(
22 this))); // Ensure we are not slicing a derived class
23 return new CatalogObject(*this); // NOLINT, (b.c. returning raw memory is bad!)
24}
25
26float CatalogObject::e() const
27{
28 if (m_major_axis == 0.0 || m_minor_axis == 0.0)
29 return 1.0; //assume circular
30 return m_minor_axis / m_major_axis;
31}
32
34{
35 //Calculate object size in pixels
36 double major_axis = m_major_axis;
37 double minor_axis = m_minor_axis;
38
39 if (major_axis == 0.0 && type() == 1) //catalog stars
40 {
41 major_axis = 1.0;
42 minor_axis = 1.0;
43 }
44
45 double size =
46 ((major_axis + minor_axis) / 2.0) * dms::PI * Options::zoomFactor() / 10800.0;
47
48 return 0.5 * size + 4.;
49}
50
52{
53 QString oName;
54 if (Options::showDeepSkyNames())
55 {
56 if (Options::deepSkyLongLabels() && translatedLongName() != translatedName())
57 oName = translatedLongName() + " (" + translatedName() + ')';
58 else
59 oName = translatedName();
60 }
61
62 if (Options::showDeepSkyMagnitudes() && !std::isnan(mag()))
63 {
64 if (Options::showDeepSkyNames())
65 oName += ' ';
66 oName += '[' + QLocale().toString(mag(), 'f', 1) + "m]";
67 }
68
69 return oName;
70}
71
73{
74 return m_object_id.toLongLong(); // = qint64
75}
76
78{
79 KStarsData *data{ KStarsData::Instance() };
80
81 if (m_updateID != data->updateID())
82 {
83 m_updateID = data->updateID();
84
85 if (m_updateNumID != data->updateNumID())
86 {
87 updateCoords(data->updateNum());
88 m_updateNumID = data->updateNumID();
89 }
90
91 EquatorialToHorizontal(data->lst(), data->geo()->lat());
92 }
93}
94
96{
97#ifndef KSTARS_LITE
98 pmenu->createCatalogObjectMenu(this);
99#else
100 Q_UNUSED(pmenu);
101#endif
102}
103
105{
106 if (m_database_path.get().length() == 0)
107 return {};
108
109 CatalogsDB::DBManager db{ m_database_path };
110
111 const auto &success = db.get_catalog(m_catalog_id);
112 return (success.first ? success.second : CatalogsDB::Catalog{});
113}
114
116
117{
118 return CatalogObject::getId(SkyObject::TYPE(type()), ra0().Degrees(),
119 dec0().Degrees(), name(), catalogIdentifier());
120}
121
122const CatalogObject::oid CatalogObject::getId(const SkyObject::TYPE type, const double ra,
123 const double dec, const QString &name,
124 const QString &catalog_identifier)
125{
126 QString data;
127 data += QString::number(type);
128 data += QString::number(static_cast<int>(std::floor(ra)));
129 data += QString::number(static_cast<int>(std::floor(dec)));
130 data += name;
131 data += catalog_identifier;
132
134 hash.addData(data.toUtf8());
135
136 return hash.result();
137}
138
140{
141 if (!m_image_loaded)
142 {
143 QString tname = name().toLower().remove(' ');
144 m_image = TextureManager::getImage(tname);
145 m_image_loaded = true;
146 }
147}
A simple container object to hold the minimum information for a Deep Sky Object to be drawn on the sk...
double labelOffset() const override
QString labelString() const override
float e() const
CatalogObject(oid id={}, const SkyObject::TYPE t=SkyObject::STAR, const dms &r=dms(0.0), const dms &d=dms(0.0), const float m=NaN::f, const QString &n=QString(), const QString &lname=QString(), const QString &catalog_identifier=QString(), const int catalog_id=-1, const float a=0.0, const float b=0.0, const double pa=0.0, const float flux=0, const QString &database_path="")
void load_image()
Load the image for this object.
void initPopupMenu(KSPopupMenu *pmenu) override
Initialize the popup menu for a CatalogObject.
const oid getId() const
SkyObject::UID getUID() const override
Generates a KStars internal UID from the object id.
const QString & catalogIdentifier() const
void JITupdate()
Update the cooridnates and the horizontal coordinates if updateID or updateNumID have changed (global...
const CatalogsDB::Catalog getCatalog() const
Get information about the catalog that this objects stems from.
CatalogObject * clone() const override
Clones the object and returns a pointer to it.
Manages the catalog database and provides an interface to provide an interface to query and modify th...
Definition catalogsdb.h:183
The KStars Popup Menu.
Definition kspopupmenu.h:35
void createCatalogObjectMenu(CatalogObject *obj)
Create a popup menu for a deep-sky catalog object.
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
QString translatedName() const
Definition skyobject.h:148
qint64 UID
Type for Unique object IDenticator.
Definition skyobject.h:49
virtual QString name(void) const
Definition skyobject.h:145
QString translatedLongName() const
Definition skyobject.h:169
int type(void) const
Definition skyobject.h:188
float mag() const
Definition skyobject.h:206
TYPE
The type classification of the SkyObject.
Definition skyobject.h:112
const CachingDms & dec() const
Definition skypoint.h:269
const CachingDms & ra0() const
Definition skypoint.h:251
const CachingDms & ra() const
Definition skypoint.h:263
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
virtual void updateCoords(const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, bool forceRecompute=false)
Determine the current coordinates (RA, Dec) from the catalog coordinates (RA0, Dec0),...
Definition skypoint.cpp:582
const CachingDms & dec0() const
Definition skypoint.h:257
static const QImage & getImage(const QString &name)
Return texture image.
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
Definition dms.h:385
qlonglong toLongLong(bool *ok, int base) const const
bool addData(QIODevice *device)
QString toString(QDate date, FormatType format) const const
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString toLower() const const
QByteArray toUtf8() const const
A simple struct to hold information about catalogs.
Definition catalogsdb.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 12:00:41 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.