Kstars

milkyway.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Jason Harris <[email protected]>
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 
22 MilkyWay::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 
43 SkipHashList *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  {
68  drawFilled(skyp);
69  }
70  else
71  {
72  drawLines(skyp);
73  }
74 }
75 
76 void MilkyWay::loadContours(QString fname, QString greeting)
77 {
78  KSFileReader fileReader;
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 }
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
QFuture< T > run(Function function,...)
bool selected() override
Definition: milkyway.cpp:48
void drawFilled(SkyPainter *skyp)
Draws all the lines in m_listList as filled polygons in float mode.
void drawLines(SkyPainter *skyp)
Draws all the lines in m_listList as simple lines in float mode.
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
QStringRef midRef(int position, int n) const const
bool open(const QString &fname)
opens the file fname from the QStandardPaths::AppLocalDataLocation directory and uses that file for t...
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
void appendBoth(const std::shared_ptr< LineList > &lineList)
a convenience method that adds a lineList to both the lineIndex and the polyIndex.
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).
SkyMesh * skyMesh()
Returns the SkyMesh object.
Definition: linelistindex.h:99
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
void draw(SkyPainter *skyp) override
The top level draw routine.
Definition: milkyway.cpp:57
QString i18n(const char *text, const TYPE &arg...)
double toDouble(bool *ok) const const
bool hasMoreLines() const
Definition: ksfilereader.h:100
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
void showProgress()
emits progress reports when required and updates bookkeeping for when to send the next report.
MilkyWay(SkyComposite *parent)
Constructor parent pointer to the parent SkyComposite.
Definition: milkyway.cpp:22
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
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
const QChar at(int position) const const
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:140
SolidLine
void loadContours(QString fname, QString greeting)
Load skiplists from file.
Definition: milkyway.cpp:76
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
int lineNumber() const
returns the current line number
Definition: ksfilereader.h:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.