Kstars

constellationnamescomponent.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "constellationnamescomponent.h"
8
9#include "ksfilereader.h"
10#include "kstarsdata.h"
11#include "Options.h"
12#include "skylabeler.h"
13#ifndef KSTARS_LITE
14#include "skymap.h"
15#endif
16#include "projections/projector.h"
17#include "skycomponents/culturelist.h"
18
19#include <QtConcurrent>
20
22 : ListComponent(parent)
23{
24#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
25 QtConcurrent::run(&ConstellationNamesComponent::loadData, this, cultures);
26#else
27 QtConcurrent::run(this, &ConstellationNamesComponent::loadData, cultures);
28#endif
29
30}
31
32void ConstellationNamesComponent::loadData(CultureList *cultures)
33{
34 clear();
35 objectNames(SkyObject::CONSTELLATION).clear();
36 objectLists(SkyObject::CONSTELLATION).clear();
37
38 uint i = 0;
39 bool culture = false;
40 KSFileReader fileReader;
41 QString cultureName;
42
43 if (!fileReader.open("cnames.dat"))
44 return;
45
46 emitProgressText(i18n("Loading constellation names"));
47
48 localCNames = Options::useLocalConstellNames();
49
50 while (fileReader.hasMoreLines())
51 {
52 QString line, name, abbrev;
53 int rah, ram, ras, dd, dm, ds;
54 QChar sgn, mode;
55
56 line = fileReader.readLine();
57
58 mode = line.at(0);
59 if (mode == 'C')
60 {
61 cultureName = line.mid(2).trimmed();
62 culture = cultureName == cultures->current();
63 i++;
64 continue;
65 }
66
67 if (culture)
68 {
69 rah = line.mid(0, 2).toInt();
70 ram = line.mid(2, 2).toInt();
71 ras = line.mid(4, 2).toInt();
72
73 sgn = line.at(6);
74 dd = line.mid(7, 2).toInt();
75 dm = line.mid(9, 2).toInt();
76 ds = line.mid(11, 2).toInt();
77
78 abbrev = line.mid(13, 3);
79 name = line.mid(17).trimmed();
80
81 if (Options::useLocalConstellNames())
82 name = i18nc("Constellation name (optional)", name.toLocal8Bit().data());
83
84 dms r;
85 r.setH(rah, ram, ras);
86 dms d(dd, dm, ds);
87
88 if (sgn == '-')
89 d.setD(-1.0 * d.Degrees());
90
91 SkyObject *o = new SkyObject(SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev);
92 o->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
94
95 //Add name to the list of object names
96 objectNames(SkyObject::CONSTELLATION).append(name);
97 objectLists(SkyObject::CONSTELLATION).append(QPair<QString, const SkyObject *>(name, o));
98 }
99 }
100}
101
103{
104#ifndef KSTARS_LITE
105 return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing());
106#else
107 return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMapLite::IsSlewing());
108#endif
109}
110
111// Don't precess the location of the names
113{
114 if (!selected())
115 return;
116 KStarsData *data = KStarsData::Instance();
117 foreach (SkyObject *o, m_ObjectList)
118 o->EquatorialToHorizontal(data->lst(), data->geo()->lat());
119}
120
122{
123 Q_UNUSED(skyp);
124#ifndef KSTARS_LITE
125 if (!selected())
126 return;
127
128 const Projector *proj = SkyMap::Instance()->projector();
129 SkyLabeler *skyLabeler = SkyLabeler::Instance();
130 //skyLabeler->useStdFont();
131 // Subjective change, but constellation names really need to stand out against everything else
132 skyLabeler->setFont(QFont("Arial", 14));
133 skyLabeler->setPen(QColor(KStarsData::Instance()->colorScheme()->colorNamed("CNameColor")));
134
135 QString name;
136 foreach (SkyObject *p, m_ObjectList)
137 {
138 if (!proj->checkVisibility(p))
139 continue;
140
141 bool visible = false;
142 QPointF o = proj->toScreen(p, false, &visible);
143 if (!visible || !proj->onScreen(o))
144 continue;
145
146 if (Options::useLatinConstellNames() || Options::useLocalConstellNames())
147 name = p->name();
148 else
149 name = p->name2();
150
151 o.setX(o.x() - 5.0 * name.length());
152 skyLabeler->drawGuideLabel(o, name, 0.0);
153 }
154
155 skyLabeler->resetFont();
156#endif
157}
ConstellationNamesComponent(SkyComposite *parent, CultureList *cultures)
Constructor parent Pointer to the parent SkyComposite object.
void update(KSNumbers *num) override
we need a custom routine (for now) so we don't precess the locations of the names.
void draw(SkyPainter *skyp) override
Draw constellation names on the sky map.
A list of all cultures FIXME: Why not use a QStringList?
Definition culturelist.h:17
QString current() const
Return the current sky culture.
Definition culturelist.h:23
const CachingDms * lat() const
Definition geolocation.h:70
I totally rewrote this because the earlier scheme of reading all the lines of a file into a buffer be...
QString readLine()
increments the line number and returns the next line from the file as a QString.
bool hasMoreLines() const
bool open(const QString &fname)
opens the file fname from the QStandardPaths::AppLocalDataLocation directory and uses that file for t...
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
CachingDms * lst()
Definition kstarsdata.h:226
GeoLocation * geo()
Definition kstarsdata.h:232
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyObjects.
void appendListObject(SkyObject *object)
Add an object to the Object list.
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition projector.cpp:93
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition projector.cpp:98
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
virtual void emitProgressText(const QString &message)
Emit signal about progress.
SkyComposite is a kind of container class for SkyComponent objects.
The purpose of this class is to prevent labels from overlapping.
Definition skylabeler.h:99
void resetFont()
sets the font in SkyLabeler and in psky back to the zoom dependent value that was set in reset().
void setFont(const QFont &font)
tells the labeler the font you will be using so it can figure out the height and width of the labels.
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
const Projector * projector() const
Get the current projector.
Definition skymap.h:300
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
virtual QString name(void) const
Definition skyobject.h:146
QString name2(void) const
Definition skyobject.h:157
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
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
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
virtual void setH(const double &x)
Sets floating-point value of angle, in hours.
Definition dms.h:210
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
GeoCoordinates geo(const QVariant &location)
QString name(StandardAction id)
char * data()
void clear()
void setX(qreal x)
qreal x() const const
const QChar at(qsizetype position) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
int toInt(bool *ok, int base) const const
QByteArray toLocal8Bit() const const
QString trimmed() const const
QFuture< T > run(Function function,...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.