Kstars

constellationnamescomponent.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Thomas Kabelmann <[email protected]>
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  QtConcurrent::run(this, &ConstellationNamesComponent::loadData, cultures);
25 }
26 
27 void ConstellationNamesComponent::loadData(CultureList *cultures)
28 {
29  uint i = 0;
30  bool culture = false;
31  KSFileReader fileReader;
32  QString cultureName;
33 
34  if (!fileReader.open("cnames.dat"))
35  return;
36 
37  emitProgressText(i18n("Loading constellation names"));
38 
39  localCNames = Options::useLocalConstellNames();
40 
41  while (fileReader.hasMoreLines())
42  {
43  QString line, name, abbrev;
44  int rah, ram, ras, dd, dm, ds;
45  QChar sgn, mode;
46 
47  line = fileReader.readLine();
48 
49  mode = line.at(0);
50  if (mode == 'C')
51  {
52  cultureName = line.mid(2).trimmed();
53  culture = cultureName == cultures->current();
54  i++;
55  continue;
56  }
57 
58  if (culture)
59  {
60  rah = line.midRef(0, 2).toInt();
61  ram = line.midRef(2, 2).toInt();
62  ras = line.midRef(4, 2).toInt();
63 
64  sgn = line.at(6);
65  dd = line.midRef(7, 2).toInt();
66  dm = line.midRef(9, 2).toInt();
67  ds = line.midRef(11, 2).toInt();
68 
69  abbrev = line.mid(13, 3);
70  name = line.mid(17).trimmed();
71 
72  if (Options::useLocalConstellNames())
73  name = i18nc("Constellation name (optional)", name.toLocal8Bit().data());
74 
75  dms r;
76  r.setH(rah, ram, ras);
77  dms d(dd, dm, ds);
78 
79  if (sgn == '-')
80  d.setD(-1.0 * d.Degrees());
81 
82  SkyObject *o = new SkyObject(SkyObject::CONSTELLATION, r, d, 0.0, name, abbrev);
83  o->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
85 
86  //Add name to the list of object names
87  objectNames(SkyObject::CONSTELLATION).append(name);
88  objectLists(SkyObject::CONSTELLATION).append(QPair<QString, const SkyObject *>(name, o));
89  }
90  }
91 }
92 
94 {
95 #ifndef KSTARS_LITE
96  return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMap::IsSlewing());
97 #else
98  return Options::showCNames() && !(Options::hideOnSlew() && Options::hideCNames() && SkyMapLite::IsSlewing());
99 #endif
100 }
101 
102 // Don't precess the location of the names
104 {
105  if (!selected())
106  return;
107  KStarsData *data = KStarsData::Instance();
108  foreach (SkyObject *o, m_ObjectList)
109  o->EquatorialToHorizontal(data->lst(), data->geo()->lat());
110 }
111 
113 {
114  Q_UNUSED(skyp);
115 #ifndef KSTARS_LITE
116  if (!selected())
117  return;
118 
119  const Projector *proj = SkyMap::Instance()->projector();
120  SkyLabeler *skyLabeler = SkyLabeler::Instance();
121  //skyLabeler->useStdFont();
122  // Subjective change, but constellation names really need to stand out against everything else
123  skyLabeler->setFont(QFont("Arial", 14));
124  skyLabeler->setPen(QColor(KStarsData::Instance()->colorScheme()->colorNamed("CNameColor")));
125 
126  QString name;
127  foreach (SkyObject *p, m_ObjectList)
128  {
129  if (!proj->checkVisibility(p))
130  continue;
131 
132  bool visible = false;
133  QPointF o = proj->toScreen(p, false, &visible);
134  if (!visible || !proj->onScreen(o))
135  continue;
136 
137  if (Options::useLatinConstellNames() || Options::useLocalConstellNames())
138  name = p->name();
139  else
140  name = p->name2();
141 
142  o.setX(o.x() - 5.0 * name.length());
143  skyLabeler->drawGuideLabel(o, name, 0.0);
144  }
145 
146  skyLabeler->resetFont();
147 #endif
148 }
int toInt(bool *ok, int base) const const
QFuture< T > run(Function function,...)
QStringRef midRef(int position, int n) const const
bool open(const QString &fname)
opens the file fname from the QStandardPaths::AppLocalDataLocation directory and uses that file for t...
QString trimmed() const const
CachingDms * lst()
Definition: kstarsdata.h:223
void resetFont()
sets the font in SkyLabeler and in psky back to the zoom dependent value that was set in reset().
Definition: skylabeler.cpp:222
virtual QString name(void) const
Definition: skyobject.h:145
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:197
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 emitProgressText(const QString &message)
Emit signal about progress.
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
virtual void setH(const double &x)
Sets floating-point value of angle, in hours.
Definition: dms.h:210
QString i18n(const char *text, const TYPE &arg...)
void setX(qreal x)
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
const CachingDms * lat() const
Definition: geolocation.h:70
bool hasMoreLines() const
Definition: ksfilereader.h:100
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
Definition: skylabeler.cpp:112
QString current() const
Return the current sky culture.
Definition: culturelist.h:23
GeoLocation * geo()
Definition: kstarsdata.h:229
void appendListObject(SkyObject *object)
Add an object to the Object list.
int length() const const
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.
GeoCoordinates geo(const QVariant &location)
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
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.
Definition: skylabeler.cpp:187
ConstellationNamesComponent(SkyComposite *parent, CultureList *cultures)
Constructor parent Pointer to the parent SkyComposite object.
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
qreal x() const const
QString name(StandardShortcut id)
QString readLine()
increments the line number and returns the next line from the file as a QString.
Definition: ksfilereader.h:105
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
const QChar at(int position) const const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString name2(void) const
Definition: skyobject.h:156
const Projector * projector() const
Get the current projector.
Definition: skymap.h:299
QByteArray toLocal8Bit() const const
QString mid(int position, int n) const const
Information about an object in the sky.
Definition: skyobject.h:41
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:183
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 8 2022 04:13:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.