Kstars

constellationlines.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "constellationlines.h"
8 
9 #include "kstarsdata.h"
10 #include "kstars_debug.h"
11 #include "linelist.h"
12 #ifdef KSTARS_LITE
13 #include "skymaplite.h"
14 #else
15 #include "skymap.h"
16 #endif
17 #include "Options.h"
18 #include "skypainter.h"
19 #include "skycomponents/culturelist.h"
20 #include "skycomponents/starcomponent.h"
21 #include "ksparser.h"
22 
24  : LineListIndex(parent, i18n("Constellation Lines")), m_reindexNum(J2000)
25 {
26  //Create the ConstellationLinesComponents. Each is a series of points
27  //connected by line segments. A single constellation can be composed of
28  //any number of these series, and we don't need to know which series
29  //belongs to which constellation.
30 
31  //The constellation lines data file (clines.dat) contains lists
32  //of abbreviated genetive star names in the same format as they
33  //appear in the star data files (hipNNN.dat).
34  //
35  //Each constellation consists of a QList of SkyPoints,
36  //corresponding to the stars at each "node" of the constellation.
37  //These are pointers to the starobjects themselves, so the nodes
38  //will automatically be fixed to the stars even as the star
39  //positions change due to proper motions. In addition, each node
40  //has a corresponding flag that determines whether a line should
41  //connect this node and the previous one.
42 
43  intro();
44 
45  bool culture = false;
46  std::shared_ptr<LineList> lineList;
47  double maxPM(0.0);
48  KSFileReader fileReader;
49 
50  if (!fileReader.open("clines.dat"))
51  return;
52 
53  while (fileReader.hasMoreLines())
54  {
55  QString line = fileReader.readLine();
56 
57  if (line.isEmpty())
58  continue;
59 
60  QChar mode = line.at(0);
61 
62  //ignore lines beginning with "#":
63  if (mode == '#')
64  continue;
65  //If the first character is "M", we are starting a new series.
66  //In this case, add the existing clc component to the composite,
67  //then prepare a new one.
68 
69  if (mode == 'C')
70  {
71  QString cultureName = line.mid(2).trimmed();
72  culture = cultureName == cultures->current();
73  continue;
74  }
75 
76  if (culture)
77  {
78  //Mode == 'M' starts a new series of line segments, joined end to end
79  if (mode == 'M')
80  {
81  if (lineList.get())
82  appendLine(lineList);
83  lineList.reset(new LineList());
84  }
85 
86  int HDnum = line.mid(2).trimmed().toInt();
87  std::shared_ptr<SkyPoint> star;
88  StarObject* tempStar = StarComponent::Instance()->findByHDIndex(HDnum);
89 
90  if (tempStar && lineList)
91  {
92  double pm = tempStar->pmMagnitude();
93 
94  star.reset(new StarObject(*tempStar));
95  if (maxPM < pm)
96  maxPM = pm;
97 
98  lineList->append(std::move(star));
99  }
100  else if (!star.get())
101  qCWarning(KSTARS) << i18n("Star HD%1 not found.", HDnum);
102  }
103  }
104  //Add the last clc component
105  if (lineList.get())
106  appendLine(lineList);
107 
108  m_reindexInterval = StarObject::reindexInterval(maxPM);
109  //printf("CLines: maxPM = %6.1f milliarcsec/year\n", maxPM );
110  //printf("CLines: Update Interval = %6.1f years\n", m_reindexInterval * 100.0 );
111  summary();
112 }
113 
115 {
116 #ifndef KSTARS_LITE
117  return Options::showCLines() && !(Options::hideOnSlew() && Options::hideCLines() && SkyMap::IsSlewing());
118 #else
119  return Options::showCLines() && !(Options::hideOnSlew() && Options::hideCLines() && SkyMapLite::IsSlewing());
120 #endif
121 }
122 
124 {
125  KStarsData *data = KStarsData::Instance();
126  QColor color = data->colorScheme()->colorNamed("CLineColor");
127  skyp->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
128 }
129 
131 {
132  return skyMesh()->indexStarLine(lineList->points());
133 }
134 
135 // JIT updating makes this simple. Star updates are called from within both
136 // StarComponent and ConstellationLines. If the update is redundant then
137 // StarObject::JITupdate() simply returns without doing any work.
139 {
140  KStarsData *data = KStarsData::Instance();
141  lineList->updateID = data->updateID();
142 
143  SkyList *points = lineList->points();
144 
145  for (const auto &point : *points)
146  {
147  StarObject *star = (StarObject *)point.get();
148 
149  star->JITupdate();
150  }
151 }
152 
153 void ConstellationLines::reindex(KSNumbers *num)
154 {
155  if (!num)
156  return;
157 
158  if (fabs(num->julianCenturies() - m_reindexNum.julianCenturies()) < m_reindexInterval)
159  return;
160 
161  //printf("Re-indexing CLines to year %4.1f...\n", 2000.0 + num->julianCenturies() * 100.0);
162 
163  m_reindexNum = KSNumbers(*num);
164  skyMesh()->setKSNumbers(num);
166 
167  //printf("Done.\n");
168 }
void JITupdate(LineList *lineList) override
we need to override the update routine because stars are updated differently from mere SkyPoints.
void setKSNumbers(KSNumbers *num)
sets the time for indexing StarObjects and CLines.
Definition: skymesh.h:145
bool open(const QString &fname)
opens the file fname from the QStandardPaths::AppLocalDataLocation directory and uses that file for t...
QString trimmed() const const
bool selected() override
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
static StarComponent * Instance()
Definition: starcomponent.h:64
const IndexHash & indexStarLine(SkyList *points)
Fills a hash with all the trixels needed to cover all the line segments in the SkyList where each Sky...
Definition: skymesh.cpp:145
SkyMesh * skyMesh()
Returns the SkyMesh object.
Definition: linelistindex.h:99
double pmMagnitude() const
returns the magnitude of the proper motion correction in milliarcsec/year
Definition: starobject.h:193
void reindexLines()
as the name says, recreates the lineIndex using the LineLists in the previous index.
QString i18n(const char *text, const TYPE &arg...)
void summary()
prints out some summary statistics if the skyMesh debug is greater than 1.
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
subclass of SkyObject specialized for stars.
Definition: starobject.h:32
bool hasMoreLines() const
Definition: ksfilereader.h:100
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
QString current() const
Return the current sky culture.
Definition: culturelist.h:23
bool isEmpty() const const
int toInt(bool *ok, int base) const const
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
SkyList * points()
return the list of points for iterating or appending (or whatever).
Definition: linelist.h:33
void intro()
displays a message that we are loading m_name.
QString readLine()
increments the line number and returns the next line from the file as a QString.
Definition: ksfilereader.h:105
void appendLine(const std::shared_ptr< LineList > &lineList)
Typically called from within a subclasses constructors.
const QChar at(int position) const const
void JITupdate()
added for JIT updates from both StarComponent and ConstellationLines
Definition: starobject.cpp:526
void preDraw(SkyPainter *skyp) override
Set the QColor and QPen for drawing.
double julianCenturies() const
Definition: ksnumbers.h:88
ConstellationLines(SkyComposite *parent, CultureList *cultures)
Constructor parent Pointer to the parent SkyComposite object.
SolidLine
StarObject * findByHDIndex(int HDnum)
Find stars by HD catalog index.
QString mid(int position, int n) const const
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
static double reindexInterval(double pm)
returns the reindex interval (in centuries!) for the given magnitude of proper motion (in milliarcsec...
Definition: starobject.cpp:46
const IndexHash & getIndexHash(LineList *lineList) override
Returns an IndexHash from the SkyMesh that contains the set of trixels that cover lineList.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 04:06:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.