Warning, file /education/kstars/kstars/skycomponents/milkyway.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2005 Jason Harris <kstars@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "milkyway.h" 0008 0009 #include "ksfilereader.h" 0010 #include "kstarsdata.h" 0011 #ifdef KSTARS_LITE 0012 #include "skymaplite.h" 0013 #else 0014 #include "skymap.h" 0015 #endif 0016 #include "Options.h" 0017 #include "skypainter.h" 0018 #include "skycomponents/skiphashlist.h" 0019 0020 #include <QtConcurrent> 0021 0022 MilkyWay::MilkyWay(SkyComposite *parent) : LineListIndex(parent, i18n("Milky Way")) 0023 { 0024 intro(); 0025 // Milky way 0026 //loadContours("milkyway.dat", i18n("Loading Milky Way")); 0027 // Magellanic clouds 0028 //loadContours("lmc.dat", i18n("Loading Large Magellanic Clouds")); 0029 //loadContours("smc.dat", i18n("Loading Small Magellanic Clouds")); 0030 //summary(); 0031 0032 QtConcurrent::run(this, &MilkyWay::loadContours, QString("milkyway.dat"), i18n("Loading Milky Way")); 0033 QtConcurrent::run(this, &MilkyWay::loadContours, QString("lmc.dat"), i18n("Loading Large Magellanic Clouds")); 0034 QtConcurrent::run(this, &MilkyWay::loadContours, QString("smc.dat"), i18n("Loading Small Magellanic Clouds")); 0035 } 0036 0037 const IndexHash &MilkyWay::getIndexHash(LineList *lineList) 0038 { 0039 SkipHashList *skipList = dynamic_cast<SkipHashList *>(lineList); 0040 return skyMesh()->indexLine(skipList->points(), skipList->skipHash()); 0041 } 0042 0043 SkipHashList *MilkyWay::skipList(LineList *lineList) 0044 { 0045 return dynamic_cast<SkipHashList *>(lineList); 0046 } 0047 0048 bool MilkyWay::selected() 0049 { 0050 #ifndef KSTARS_LITE 0051 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMap::IsSlewing()); 0052 #else 0053 return Options::showMilkyWay() && !(Options::hideOnSlew() && Options::hideMilkyWay() && SkyMapLite::IsSlewing()); 0054 #endif 0055 } 0056 0057 void MilkyWay::draw(SkyPainter *skyp) 0058 { 0059 if (!selected()) 0060 return; 0061 0062 QColor color = KStarsData::Instance()->colorScheme()->colorNamed("MWColor"); 0063 skyp->setPen(QPen(color, 3, Qt::SolidLine)); 0064 skyp->setBrush(QBrush(color)); 0065 0066 if (Options::fillMilkyWay()) 0067 { 0068 drawFilled(skyp); 0069 } 0070 else 0071 { 0072 drawLines(skyp); 0073 } 0074 } 0075 0076 void MilkyWay::loadContours(QString fname, QString greeting) 0077 { 0078 KSFileReader fileReader; 0079 std::shared_ptr<LineList> skipList; 0080 int iSkip = 0; 0081 0082 if (!fileReader.open(fname)) 0083 return; 0084 0085 fileReader.setProgress(greeting, 2136, 5); 0086 while (fileReader.hasMoreLines()) 0087 { 0088 QString line = fileReader.readLine(); 0089 QChar firstChar = line.at(0); 0090 0091 fileReader.showProgress(); 0092 if (firstChar == '#') 0093 continue; 0094 0095 bool okRA = false, okDec = false; 0096 double ra = line.midRef(2, 8).toDouble(&okRA); 0097 double dec = line.midRef(11, 8).toDouble(&okDec); 0098 0099 if (!okRA || !okDec) 0100 { 0101 qDebug() << Q_FUNC_INFO << QString("%1: conversion error on line: %2\n").arg(fname).arg(fileReader.lineNumber()); 0102 continue; 0103 } 0104 0105 if (firstChar == 'M') 0106 { 0107 if (skipList.get()) 0108 appendBoth(skipList); 0109 skipList.reset(); 0110 iSkip = 0; 0111 } 0112 0113 if (!skipList.get()) 0114 skipList.reset(new SkipHashList()); 0115 0116 std::shared_ptr<SkyPoint> point(new SkyPoint(ra, dec)); 0117 0118 skipList->append(std::move(point)); 0119 if (firstChar == 'S') 0120 static_cast<SkipHashList*>(skipList.get())->setSkip(iSkip); 0121 0122 iSkip++; 0123 } 0124 if (skipList.get()) 0125 appendBoth(skipList); 0126 }