Kstars

milkyway.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 "milkyway.h"
8
9#include "ksfilereader.h"
10#include "kstarsdata.h"
11#ifdef KSTARS_LITE
12#include "skymaplite.h"
13#else
14#include "skymap.h"
15#endif
16#include "Options.h"
17#include "skypainter.h"
18#include "skycomponents/skiphashlist.h"
19#include "skymapcomposite.h"
20#include "solarsystemcomposite.h"
21#include "kssun.h"
22
23#include <QtConcurrent>
24
25MilkyWay::MilkyWay(SkyComposite *parent) : LineListIndex(parent, i18n("Milky Way"))
26{
27 intro();
28 // Milky way
29 //loadContours("milkyway.dat", i18n("Loading Milky Way"));
30 // Magellanic clouds
31 //loadContours("lmc.dat", i18n("Loading Large Magellanic Clouds"));
32 //loadContours("smc.dat", i18n("Loading Small Magellanic Clouds"));
33 //summary();
34
35#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
36 QtConcurrent::run(&MilkyWay::loadContours, this, QString("milkyway.dat"), i18n("Loading Milky Way"));
37 QtConcurrent::run(&MilkyWay::loadContours, this, QString("lmc.dat"), i18n("Loading Large Magellanic Clouds"));
38 QtConcurrent::run(&MilkyWay::loadContours, this, QString("smc.dat"), i18n("Loading Small Magellanic Clouds"));
39#else
40 QtConcurrent::run(this, &MilkyWay::loadContours, QString("milkyway.dat"), i18n("Loading Milky Way"));
41 QtConcurrent::run(this, &MilkyWay::loadContours, QString("lmc.dat"), i18n("Loading Large Magellanic Clouds"));
42 QtConcurrent::run(this, &MilkyWay::loadContours, QString("smc.dat"), i18n("Loading Small Magellanic Clouds"));
43#endif
44}
45
47{
48 SkipHashList *skipList = dynamic_cast<SkipHashList *>(lineList);
49 return skyMesh()->indexLine(skipList->points(), skipList->skipHash());
50}
51
52SkipHashList *MilkyWay::skipList(LineList *lineList)
53{
54 return dynamic_cast<SkipHashList *>(lineList);
55}
56
58{
59#ifndef KSTARS_LITE
60 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMap::IsSlewing());
61#else
62 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMapLite::IsSlewing());
63#endif
64}
65
67{
68 if (!selected())
69 return;
70
71 QColor color = KStarsData::Instance()->colorScheme()->colorNamed("MWColor");
72 if (Options::simulateDaytime())
73 {
74 KSSun *sun = KStarsData::Instance()->skyComposite()->solarSystemComposite()->sun();
75 if (sun)
76 {
77 // No Milky Way in the daytime. Blends into sky color.
78 QColor mwDayColor = KStarsData::Instance()->colorScheme()->colorNamed("SkyColorDaytime");
79 const double nightFraction = sun->nightFraction();
80 const double dayFraction = 1 - nightFraction;
81 color = QColor(nightFraction * color.red() + dayFraction * mwDayColor.red(),
82 nightFraction * color.green() + dayFraction * mwDayColor.green(),
83 nightFraction * color.blue() + dayFraction * mwDayColor.blue());
84 }
85 }
86
87 skyp->setPen(QPen(color, 3, Qt::SolidLine));
88 skyp->setBrush(QBrush(color));
89
90 if (Options::fillMilkyWay())
91 {
92 drawFilled(skyp);
93 }
94 else
95 {
96 drawLines(skyp);
97 }
98}
99
101{
102 KSFileReader fileReader;
103 std::shared_ptr<LineList> skipList;
104 int iSkip = 0;
105
106 if (!fileReader.open(fname))
107 return;
108
109 fileReader.setProgress(greeting, 2136, 5);
110 while (fileReader.hasMoreLines())
111 {
112 QString line = fileReader.readLine();
113 QChar firstChar = line.at(0);
114
115 fileReader.showProgress();
116 if (firstChar == '#')
117 continue;
118
119 bool okRA = false, okDec = false;
120 double ra = line.mid(2, 8).toDouble(&okRA);
121 double dec = line.mid(11, 8).toDouble(&okDec);
122
123 if (!okRA || !okDec)
124 {
125 qDebug() << Q_FUNC_INFO << QString("%1: conversion error on line: %2\n").arg(fname).arg(fileReader.lineNumber());
126 continue;
127 }
128
129 if (firstChar == 'M')
130 {
131 if (skipList.get())
133 skipList.reset();
134 iSkip = 0;
135 }
136
137 if (!skipList.get())
138 skipList.reset(new SkipHashList());
139
140 std::shared_ptr<SkyPoint> point(new SkyPoint(ra, dec));
141
142 skipList->append(std::move(point));
143 if (firstChar == 'S')
144 static_cast<SkipHashList*>(skipList.get())->setSkip(iSkip);
145
146 iSkip++;
147 }
148 if (skipList.get())
150}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
I totally rewrote this because the earlier scheme of reading all the lines of a file into a buffer be...
int lineNumber() const
returns the current line number
void setProgress(QString label, unsigned int lastLine, unsigned int numUpdates=10)
Prepares this instance to emit progress reports on how much of the file has been read (in percent).
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...
void showProgress()
emits progress reports when required and updates bookkeeping for when to send the next report.
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition kssun.h:24
ColorScheme * colorScheme()
Definition kstarsdata.h:174
SkyMapComposite * skyComposite()
Definition kstarsdata.h:168
Contains almost all the code needed for indexing and drawing and clipping lines and polygons.
void drawLines(SkyPainter *skyp)
Draws all the lines in m_listList as simple lines in float mode.
void intro()
displays a message that we are loading m_name.
void appendBoth(const std::shared_ptr< LineList > &lineList)
a convenience method that adds a lineList to both the lineIndex and the polyIndex.
SkyMesh * skyMesh()
Returns the SkyMesh object.
void drawFilled(SkyPainter *skyp)
Draws all the lines in m_listList as filled polygons in float mode.
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
void loadContours(QString fname, QString greeting)
Load skiplists from file.
Definition milkyway.cpp:100
SkipHashList * skipList(LineList *lineList) override
Returns a boolean indicating whether to skip the i-th line segment in the SkipList skipList.
Definition milkyway.cpp:52
bool selected() override
Definition milkyway.cpp:57
const IndexHash & getIndexHash(LineList *skipList) override
Returns an IndexHash from the SkyMesh that contains the set of trixels that cover the SkipList lineLi...
Definition milkyway.cpp:46
void draw(SkyPainter *skyp) override
The top level draw routine.
Definition milkyway.cpp:66
MilkyWay(SkyComposite *parent)
Constructor parent pointer to the parent SkyComposite.
Definition milkyway.cpp:25
SkyComposite is a kind of container class for SkyComponent objects.
const IndexHash & indexLine(SkyList *points)
fills a QHash with the trixel indices needed to cover all the line segments specified in the QVector<...
Definition skymesh.cpp:126
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
QString i18n(const char *text, const TYPE &arg...)
int blue() const const
int green() const const
int red() const const
QString arg(Args &&... args) const const
const QChar at(qsizetype position) const const
QString mid(qsizetype position, qsizetype n) const const
double toDouble(bool *ok) const const
SolidLine
QFuture< T > run(Function function,...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:47:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.