Kstars

constellationlines.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Jason Harris <kstars@30doradus.org>
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 "ksfilereader.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;
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
153void 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}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
const IndexHash & getIndexHash(LineList *lineList) override
Returns an IndexHash from the SkyMesh that contains the set of trixels that cover lineList.
void preDraw(SkyPainter *skyp) override
Set the QColor and QPen for drawing.
ConstellationLines(SkyComposite *parent, CultureList *cultures)
Constructor parent Pointer to the parent SkyComposite object.
void JITupdate(LineList *lineList) override
we need to override the update routine because stars are updated differently from mere SkyPoints.
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
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
double julianCenturies() const
Definition ksnumbers.h:88
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
ColorScheme * colorScheme()
Definition kstarsdata.h:172
Contains almost all the code needed for indexing and drawing and clipping lines and polygons.
void intro()
displays a message that we are loading m_name.
SkyMesh * skyMesh()
Returns the SkyMesh object.
void summary()
prints out some summary statistics if the skyMesh debug is greater than 1.
void appendLine(const std::shared_ptr< LineList > &lineList)
Typically called from within a subclasses constructors.
void reindexLines()
as the name says, recreates the lineIndex using the LineLists in the previous index.
A simple data container used by LineListIndex.
Definition linelist.h:25
SkyList * points()
return the list of points for iterating or appending (or whatever).
Definition linelist.h:33
SkyComposite is a kind of container class for SkyComponent objects.
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:131
void setKSNumbers(KSNumbers *num)
sets the time for indexing StarObjects and CLines.
Definition skymesh.h:145
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
static StarComponent * Instance()
StarObject * findByHDIndex(int HDnum)
Find stars by HD catalog index.
This is a subclass of SkyObject.
Definition starobject.h:33
static double reindexInterval(double pm)
returns the reindex interval (in centuries!) for the given magnitude of proper motion (in milliarcsec...
void JITupdate()
added for JIT updates from both StarComponent and ConstellationLines
double pmMagnitude() const
returns the magnitude of the proper motion correction in milliarcsec/year
Definition starobject.h:193
QString i18n(const char *text, const TYPE &arg...)
const QChar at(qsizetype position) const const
bool isEmpty() const const
QString mid(qsizetype position, qsizetype n) const const
int toInt(bool *ok, int base) const const
QString trimmed() const const
SolidLine
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:01:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.