Kstars

satellitegroup.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Jerome SONRIER <jsid@emor3j.fr.eu.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "satellitegroup.h"
8
9#include "ksutils.h"
10#include "kspaths.h"
11#include "skyobjects/satellite.h"
12
13#include <QTextStream>
14
16{
17 m_name = name;
18 m_tle_file = tle_filename;
19 m_tle_url = update_url;
20
21 // Read TLE file and create satellites
22 readTLE();
23}
24
26{
27 QFile file;
29
30 // Delete all satellites
31 qDeleteAll(*this);
32 clear();
33
34 // Read TLE file
35 if (KSUtils::openDataFile(file, m_tle_file))
36 {
37 QTextStream stream(&file);
38 while (!stream.atEnd())
39 {
40 // Read satellite name
41 QString sat_name = stream.readLine().trimmed();
42 line1 = stream.readLine();
43 line2 = stream.readLine();
44 // Create a new satellite and add it to the list of satellites
45 if (line1.startsWith('1') && line2.startsWith('2'))
47 }
48 file.close();
49 }
50}
51
53{
55
56 while (sats.hasNext())
57 {
58 Satellite *sat = sats.next();
59
60 if (sat->selected())
61 {
62 int rc = sat->updatePos();
63 // If position cannot be calculated, remove it from list
64 if (rc != 0)
65 sats.remove();
66 }
67 }
68}
69
71{
72 // Return absolute path with "file:" before the path
73 //return QUrl( "file:" + (QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath(m_tle_file));
74 return QUrl::fromLocalFile(QDir(KSPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath(m_tle_file));
75}
76
78{
79 return m_tle_url;
80}
81
83{
84 return m_name;
85}
void updateSatellitesPos()
Compute current position of the each satellites in the group.
SatelliteGroup(const QString &name, const QString &tle_filename, const QUrl &update_url)
Constructor.
void readTLE()
Read TLE file of the group and create all satellites found in the file.
Represents an artificial satellites.
Definition satellite.h:23
int updatePos()
Update satellite position.
bool selected()
virtual void close() override
void append(const T &value)
QString trimmed() const const
bool atEnd() const const
QString readLine(qint64 maxlen)
QUrl fromLocalFile(const QString &localFile)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:45:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.