Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_Simulate.h
1/***************************************************************************
2 * Copyright (C) 2021-2024 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QGeoPositionInfo>
24
25#include <optional>
26
27#include "traffic/TrafficDataSource_Abstract.h"
28
29using namespace Qt::Literals::StringLiterals;
30
31
32namespace Traffic {
33
40 Q_OBJECT
41
42public:
49 TrafficDataSource_Simulate(bool isCanonical, QObject* parent);
50
51 // Standard destructor
52 ~TrafficDataSource_Simulate() override = default;
53
58 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
59
67 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_file_download.svg"_s; }
68
76 [[nodiscard]] auto sourceName() const -> QString override
77 {
78 return tr("Simulator data");
79 }
80
81public slots:
87 void connectToTrafficReceiver() override;
88
95
101 {
102 barometricHeight = barAlt;
103 }
104
109 void setCoordinate(const QGeoCoordinate& coordinate)
110 {
111 geoInfo.setCoordinate(coordinate);
112 geoInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, 0.0);
113 }
114
120 {
121 geoInfo.setAttribute(QGeoPositionInfo::GroundSpeed, GS.toMPS());
122 }
123
129 {
130 geoInfo.setAttribute(QGeoPositionInfo::Direction, TT.toDEG());
131 }
132
138 {
139 trafficFactor_DistanceOnly = factor;
140 }
141
144 {
145 trafficFactor_DistanceOnly.reset();
146 }
147
153 {
154 geoInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, vSpeed.toMPS());
155 }
156
162 {
163 trafficFactors.append(factor);
164 }
165
168 {
169 trafficFactors.clear();
170 }
171
172private slots:
173 // Send out simulated data. This slot will be called once per second once
174 // connectToTrafficReceiver() has been called
175 void sendSimulatorData();
176
177private:
178 Q_DISABLE_COPY_MOVE(TrafficDataSource_Simulate)
179
180 // Simulator related members
181 QTimer simulatorTimer;
182 QGeoPositionInfo geoInfo;
183 Units::Distance barometricHeight;
184 QVector<TrafficFactorData_WithPosition> trafficFactors;
185 std::optional<TrafficFactorData_DistanceOnly> trafficFactor_DistanceOnly = std::nullopt;
186};
187
188} // namespace Traffic
TrafficDataSource_Abstract(bool isCanonical, QObject *parent)
Default constructor.
Traffic receiver: Simulator that provides configurable simulated data.
void setTT(Units::Angle TT)
Set angle that is to be reported by this class as the true track of ownship.
void clearTrafficFactor_DistanceOnly()
Stop reporting distance-only traffic.
void setVSpeed(Units::Speed vSpeed)
Set speed that is to be reported by this class as the vertical speed of ownship.
void setGS(Units::Speed GS)
Set speed that is to be reported by this class as the ground speed of ownship.
TrafficDataSource_Simulate(bool isCanonical, QObject *parent)
Default constructor.
QString icon() const override
Getter function for the property with the same name.
void connectToTrafficReceiver() override
Start attempt to connect to traffic receiver.
QString dataFormat() const override
Getter function for the property with the same name.
auto sourceName() const -> QString override
Getter function for the property with the same name.
void setCoordinate(const QGeoCoordinate &coordinate)
Set coordinate that is to be reported by this class as the position of ownship.
void setBarometricHeight(Units::Distance barAlt)
Set distance that is to be reported by this class as the barometric altitude of ownship.
void removeTraffic()
Remove all traffic factors (with position).
void disconnectFromTrafficReceiver() override
Disconnect from traffic receiver.
void setTrafficFactor_DistanceOnly(const Traffic::TrafficFactorData_DistanceOnly &factor)
Set traffic factor (distance only) that is to be reported by this class.
void addTraffic(const Traffic::TrafficFactorData_WithPosition &factor)
Add a traffic factor that is to be reported by this class.
Convenience class for angle computations.
Definition Angle.h:41
Q_INVOKABLE double toDEG() const
Convert angle to degrees.
Definition Angle.h:172
Convenience class for distance computations.
Definition Distance.h:35
Convenience class for speed computations.
Definition Speed.h:39
Q_INVOKABLE double toMPS() const
Convert to meters per second.
Definition Speed.h:185
Plain-data record of a traffic factor whose position is not known.
Plain-data record of a traffic factor whose precise position is known.