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 QtConcurrent::run(this, &MilkyWay::loadContours, QString("milkyway.dat"), i18n("Loading Milky Way"));
36 QtConcurrent::run(this, &MilkyWay::loadContours, QString("lmc.dat"), i18n("Loading Large Magellanic Clouds"));
37 QtConcurrent::run(this, &MilkyWay::loadContours, QString("smc.dat"), i18n("Loading Small Magellanic Clouds"));
38}
39
41{
42 SkipHashList *skipList = dynamic_cast<SkipHashList *>(lineList);
43 return skyMesh()->indexLine(skipList->points(), skipList->skipHash());
44}
45
46SkipHashList *MilkyWay::skipList(LineList *lineList)
47{
48 return dynamic_cast<SkipHashList *>(lineList);
49}
50
52{
53#ifndef KSTARS_LITE
54 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMap::IsSlewing());
55#else
56 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMapLite::IsSlewing());
57#endif
58}
59
61{
62 if (!selected())
63 return;
64
65 QColor color = KStarsData::Instance()->colorScheme()->colorNamed("MWColor");
66 if (Options::simulateDaytime())
67 {
68 KSSun *sun = KStarsData::Instance()->skyComposite()->solarSystemComposite()->sun();
69 if (sun)
70 {
71 // No Milky Way in the daytime. Blends into sky color.
72 QColor mwDayColor = KStarsData::Instance()->colorScheme()->colorNamed("SkyColorDaytime");
73 const double nightFraction = sun->nightFraction();
74 const double dayFraction = 1 - nightFraction;
75 color = QColor(nightFraction * color.red() + dayFraction * mwDayColor.red(),
76 nightFraction * color.green() + dayFraction * mwDayColor.green(),
77 nightFraction * color.blue() + dayFraction * mwDayColor.blue());
78 }
79 }
80
81 skyp->setPen(QPen(color, 3, Qt::SolidLine));
82 skyp->setBrush(QBrush(color));
83
84 if (Options::fillMilkyWay())
85 {
87 }
88 else
89 {
91 }
92}
93
95{
97 std::shared_ptr<LineList> skipList;
98 int iSkip = 0;
99
100 if (!fileReader.open(fname))
101 return;
102
103 fileReader.setProgress(greeting, 2136, 5);
104 while (fileReader.hasMoreLines())
105 {
106 QString line = fileReader.readLine();
107 QChar firstChar = line.at(0);
108
109 fileReader.showProgress();
110 if (firstChar == '#')
111 continue;
112
113 bool okRA = false, okDec = false;
114 double ra = line.midRef(2, 8).toDouble(&okRA);
115 double dec = line.midRef(11, 8).toDouble(&okDec);
116
117 if (!okRA || !okDec)
118 {
119 qDebug() << Q_FUNC_INFO << QString("%1: conversion error on line: %2\n").arg(fname).arg(fileReader.lineNumber());
120 continue;
121 }
122
123 if (firstChar == 'M')
124 {
125 if (skipList.get())
127 skipList.reset();
128 iSkip = 0;
129 }
130
131 if (!skipList.get())
132 skipList.reset(new SkipHashList());
133
134 std::shared_ptr<SkyPoint> point(new SkyPoint(ra, dec));
135
136 skipList->append(std::move(point));
137 if (firstChar == 'S')
138 static_cast<SkipHashList*>(skipList.get())->setSkip(iSkip);
139
140 iSkip++;
141 }
142 if (skipList.get())
144}
I totally rewrote this because the earlier scheme of reading all the lines of a file into a buffer be...
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition kssun.h:24
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:94
SkipHashList * skipList(LineList *lineList) override
Returns a boolean indicating whether to skip the i-th line segment in the SkipList skipList.
Definition milkyway.cpp:46
bool selected() override
Definition milkyway.cpp:51
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:40
void draw(SkyPainter *skyp) override
The top level draw routine.
Definition milkyway.cpp:60
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
The sky coordinates of a point in the sky.
Definition skypoint.h:45
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
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 Jun 14 2024 11:55:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.