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
20#include <QtConcurrent>
21
22MilkyWay::MilkyWay(SkyComposite *parent) : LineListIndex(parent, i18n("Milky Way"))
23{
24 intro();
25 // Milky way
26 //loadContours("milkyway.dat", i18n("Loading Milky Way"));
27 // Magellanic clouds
28 //loadContours("lmc.dat", i18n("Loading Large Magellanic Clouds"));
29 //loadContours("smc.dat", i18n("Loading Small Magellanic Clouds"));
30 //summary();
31
32 QtConcurrent::run(this, &MilkyWay::loadContours, QString("milkyway.dat"), i18n("Loading Milky Way"));
33 QtConcurrent::run(this, &MilkyWay::loadContours, QString("lmc.dat"), i18n("Loading Large Magellanic Clouds"));
34 QtConcurrent::run(this, &MilkyWay::loadContours, QString("smc.dat"), i18n("Loading Small Magellanic Clouds"));
35}
36
38{
39 SkipHashList *skipList = dynamic_cast<SkipHashList *>(lineList);
40 return skyMesh()->indexLine(skipList->points(), skipList->skipHash());
41}
42
43SkipHashList *MilkyWay::skipList(LineList *lineList)
44{
45 return dynamic_cast<SkipHashList *>(lineList);
46}
47
49{
50#ifndef KSTARS_LITE
51 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMap::IsSlewing());
52#else
53 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMapLite::IsSlewing());
54#endif
55}
56
58{
59 if (!selected())
60 return;
61
62 QColor color = KStarsData::Instance()->colorScheme()->colorNamed("MWColor");
63 skyp->setPen(QPen(color, 3, Qt::SolidLine));
64 skyp->setBrush(QBrush(color));
65
66 if (Options::fillMilkyWay())
67 {
69 }
70 else
71 {
73 }
74}
75
77{
79 std::shared_ptr<LineList> skipList;
80 int iSkip = 0;
81
82 if (!fileReader.open(fname))
83 return;
84
85 fileReader.setProgress(greeting, 2136, 5);
86 while (fileReader.hasMoreLines())
87 {
88 QString line = fileReader.readLine();
89 QChar firstChar = line.at(0);
90
91 fileReader.showProgress();
92 if (firstChar == '#')
93 continue;
94
95 bool okRA = false, okDec = false;
96 double ra = line.midRef(2, 8).toDouble(&okRA);
97 double dec = line.midRef(11, 8).toDouble(&okDec);
98
99 if (!okRA || !okDec)
100 {
101 qDebug() << Q_FUNC_INFO << QString("%1: conversion error on line: %2\n").arg(fname).arg(fileReader.lineNumber());
102 continue;
103 }
104
105 if (firstChar == 'M')
106 {
107 if (skipList.get())
109 skipList.reset();
110 iSkip = 0;
111 }
112
113 if (!skipList.get())
114 skipList.reset(new SkipHashList());
115
116 std::shared_ptr<SkyPoint> point(new SkyPoint(ra, dec));
117
118 skipList->append(std::move(point));
119 if (firstChar == 'S')
120 static_cast<SkipHashList*>(skipList.get())->setSkip(iSkip);
121
122 iSkip++;
123 }
124 if (skipList.get())
126}
I totally rewrote this because the earlier scheme of reading all the lines of a file into a buffer be...
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:76
SkipHashList * skipList(LineList *lineList) override
Returns a boolean indicating whether to skip the i-th line segment in the SkipList skipList.
Definition milkyway.cpp:43
bool selected() override
Definition milkyway.cpp:48
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:37
void draw(SkyPainter *skyp) override
The top level draw routine.
Definition milkyway.cpp:57
MilkyWay(SkyComposite *parent)
Constructor parent pointer to the parent SkyComposite.
Definition milkyway.cpp:22
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...)
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 Tue Mar 26 2024 11:19:04 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.