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#include <QPointer>
25
26#include "traffic/TrafficDataSource_Abstract.h"
27
28using namespace Qt::Literals::StringLiterals;
29
30
31namespace Traffic {
32
38 Q_OBJECT
39
40public:
47 TrafficDataSource_Simulate(bool isCanonical, QObject* parent);
48
49 // Standard destructor
50 ~TrafficDataSource_Simulate() override = default;
51
56 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
57
65 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_file_download.svg"_s; }
66
74 [[nodiscard]] auto sourceName() const -> QString override
75 {
76 return tr("Simulator data");
77 }
78
79public slots:
85 void connectToTrafficReceiver() override;
86
93
99 {
100 barometricHeight = barAlt;
101 }
102
107 void setCoordinate(const QGeoCoordinate& coordinate)
108 {
109 geoInfo.setCoordinate(coordinate);
110 geoInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, 0.0);
111 }
112
118 {
119 geoInfo.setAttribute(QGeoPositionInfo::GroundSpeed, GS.toMPS());
120 }
121
127 {
128 geoInfo.setAttribute(QGeoPositionInfo::Direction, TT.toDEG());
129 }
130
137 {
138 delete trafficFactor_DistanceOnly;
139 if (factor != nullptr) {
140 factor->setParent( this );
141 trafficFactor_DistanceOnly = factor;
142 }
143 }
144
150 {
151 geoInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, vSpeed.toMPS());
152 }
153
160 {
161 factor->setParent(this);
162 trafficFactors.append(factor);
163 }
164
167 {
168 qDeleteAll(trafficFactors);
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<QPointer<TrafficFactor_WithPosition>> trafficFactors;
185 QPointer<TrafficFactor_DistanceOnly> trafficFactor_DistanceOnly;
186};
187
188} // namespace Traffic
TrafficDataSource_Abstract(bool isCanonical, QObject *parent)
Default constructor.
Traffic receiver: Simulator that provides constant data.
void setTrafficFactor_DistanceOnly(Traffic::TrafficFactor_DistanceOnly *factor=nullptr)
Set traffic factor (distance only) that is to be reported by this class.
void setTT(Units::Angle TT)
Set angle that is to be reported by this class as the true track of ownship.
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.
void addTraffic(Traffic::TrafficFactor_WithPosition *factor)
Add a traffic factor that is to be reported by this class.
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.
Traffic factor where only distance is known.
Traffic factor whose precise position is known.
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:36
Q_INVOKABLE double toMPS() const
Convert to meters per second.
Definition Speed.h:182