7 #include <QWriteLocker>
39 using namespace swift::misc::physical_quantities;
40 using namespace swift::misc::aviation;
41 using namespace swift::misc::network;
42 using namespace swift::misc::geo;
43 using namespace swift::misc::audio;
44 using namespace swift::misc::simulation;
48 namespace swift::core::context
58 m_historyTimer.
start(2500);
59 m_situationHistory.
setSortHint(CAircraftSituationList::TimestampLatestFirst);
66 &CContextOwnAircraft::allSwiftWebDataRead);
70 this->initOwnAircraft();
129 void CContextOwnAircraft::initOwnAircraft()
136 ownAircraft = m_ownAircraft;
142 ownAircraft.
setPilot(m_currentNetworkServer.
get().getUser());
157 m_ownAircraft = ownAircraft;
161 void CContextOwnAircraft::evaluateUpdateHistory()
163 if (!m_history) {
return; }
171 constexpr
int minElements = qRound(MaxHistoryElements * 0.75);
172 if (m_situationHistory.
size() < minElements) {
return; }
177 static const CLength maxDistance(25, CLengthUnit::km());
187 m_situationHistory.
clear();
195 bool modified =
false;
197 CDatabaseUtils::consolidateOwnAircraftModelWithDbData(model,
false, &modified);
211 const bool changed = (m_ownAircraft.
getModel() != updateModel);
212 if (!changed) {
return false; }
213 m_ownAircraft.
setModel(updateModel);
217 emit this->ps_changedModel(updateModel,
identifier);
227 if (m_situationHistory.
isEmpty() ||
231 if (m_situationHistory.
size() > MaxHistoryElements) { m_situationHistory.
pop_back(); }
239 const bool changed = (m_ownAircraft.
getParts() != parts);
240 if (!changed) {
return false; }
248 const bool changed = (m_ownAircraft.
getModel().
getCG() != cg);
249 if (!changed) {
return false; }
250 m_ownAircraft.
setCG(cg);
263 bool changed = (m_ownAircraft.
getPosition() != position);
264 if (changed) { m_ownAircraft.
setPosition(position); }
291 if (changed) { m_ownAircraft.
setCockpit(com1, com2, transponder); }
316 if (unit != CComSystem::Com1 && unit != CComSystem::Com2) {
return false; }
317 if (!CComSystem::isValidComFrequency(frequency)) {
return false; }
329 const bool changed = this->
updateCockpit(com1, com2, xpdr, originator);
337 if (m_ownAircraft.
getPilot() == pilot) {
return false; }
368 if (m_ownAircraft.
getCallsign() == callsign) {
return false; }
380 if (!m_ownAircraft.
setIcaoCodes(aircraftIcaoCode, airlineIcaoCode)) {
return false; }
390 if (m_ownAircraft.
getSelcal() == selcal) {
return false; }
402 void CContextOwnAircraft::xCtxChangedSimulatorStatus(
int status)
404 const ISimulator::SimulatorStatus s =
static_cast<ISimulator::SimulatorStatus
>(status);
413 m_situationHistory.
clear();
417 void CContextOwnAircraft::actionToggleTransponder(
bool keydown)
419 if (!keydown) {
return; }
423 void CContextOwnAircraft::actionIdent(
bool keydown)
430 void CContextOwnAircraft::allSwiftWebDataRead()
439 if (commandLine.
isEmpty()) {
return false; }
444 parser.
parse(commandLine);
445 if (!parser.isKnownCommand()) {
return false; }
448 if (parser.matchesCommand(
".x",
".xpdr") && parser.countParts() > 1)
451 int xprCode = parser.toInt(1);
452 if (CTransponder::isValidTransponderCode(xprCode))
470 else if (parser.commandStartsWith(
"com") || parser.commandStartsWith(
"c"))
472 CFrequency frequency(parser.toDouble(1), CFrequencyUnit::MHz());
473 if (CComSystem::isValidComFrequency(frequency))
479 else {
return false; }
484 else if (parser.matchesCommand(
".selcal"))
486 if (CSelcal::isValidCode(parser.part(1)))
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
CWebDataServices * getWebDataServices() const
Get the web data services.
ContextMode
How to handle a given context.
The class providing facades (the contexts) for all DBus relevant operations.
void swiftDbAllDataRead()
All swift DB data have been read.
static bool isAnyConnectedStatus(SimulatorStatus status)
Any connected status?
bool setTransponderMode(swift::misc::aviation::CTransponder::TransponderMode mode)
Set XPDR mode.
swift::misc::simulation::CAircraftModel getOwnAircraftModel() const
Own aircraft model.
bool updateActiveComFrequency(const swift::misc::physical_quantities::CFrequency &frequency, swift::misc::aviation::CComSystem::ComUnit comUnit, const swift::misc::CIdentifier &originator)
Tune in a COM frequency.
swift::misc::aviation::CAircraftSituation getOwnAircraftSituation() const
Get own aircraft.
swift::misc::physical_quantities::CLength getDistanceToOwnAircraft(const swift::misc::geo::ICoordinateGeodetic &position) const
Distance to own aircraft.
bool updateTransponderMode(const swift::misc::aviation::CTransponder::TransponderMode &transponderMode, const swift::misc::CIdentifier &originator)
Update own transponder mode.
bool updateOwnPosition(const swift::misc::geo::CCoordinateGeodetic &position, const swift::misc::aviation::CAltitude &altitude, const swift::misc::aviation::CAltitude &pressureAltitude)
Update position.
swift::misc::aviation::CTransponder getOwnTransponder() const
Get own transponder.
bool updateOwnCallsign(const swift::misc::aviation::CCallsign &callsign)
Set callsign.
bool updateOwnIcaoCodes(const swift::misc::aviation::CAircraftIcaoCode &aircraftIcaoCode, const swift::misc::aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO data.
swift::misc::geo::CCoordinateGeodetic getOwnAircraftPosition() const
Own aircraft's position.
swift::misc::simulation::CSimulatedAircraft getOwnAircraft() const
Get own aircraft.
swift::misc::aviation::CCallsign getOwnCallsign() const
Own aircraft's callsign.
bool updateOwnSituation(const swift::misc::aviation::CAircraftSituation &situation)
Update own situation.
void toggleTransponderMode()
Toggle XPDR mode.
bool updateCockpit(const swift::misc::aviation::CComSystem &com1, const swift::misc::aviation::CComSystem &com2, const swift::misc::aviation::CTransponder &transponder, const swift::misc::CIdentifier &originator)
Update own cockpit.
bool updateOwnModel(const swift::misc::simulation::CAircraftModel &model)
Update model.
bool updateOwnParts(const swift::misc::aviation::CAircraftParts &parts)
Update own parts.
swift::misc::aviation::CAircraftParts getOwnAircraftParts() const
Own aircraft's parts.
bool updateOwnCG(const swift::misc::physical_quantities::CLength &cg)
Update own parts.
bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot)
Set current pilot.
swift::misc::aviation::CComSystem getOwnComSystem(swift::misc::aviation::CComSystem::ComUnit unit) const
Get own COM system.
bool updateSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Own SELCAL code.
static void registerHelp()
Register help.
CCoreFacade * getRuntime()
Runtime.
const IContextSimulator * getIContextSimulator() const
Context for simulator.
bool isDebugEnabled() const
Debug enabled?
void changedAircraftCockpit(const swift::misc::simulation::CSimulatedAircraft &aircraft, const swift::misc::CIdentifier &originator)
Aircraft cockpit update.
void changedPilot(const swift::misc::network::CUser &pilot)
Own pilot (aka the swift user) changed.
void changedCallsign(const swift::misc::aviation::CCallsign &callsign)
Own callsign was changed.
void changedAircraftIcaoCodes(const swift::misc::aviation::CAircraftIcaoCode &aircraftIcaoCode, const swift::misc::aviation::CAirlineIcaoCode &airlineIcaoCode)
Own ICAO was changed.
void movedAircraft(const swift::misc::physical_quantities::CLength &distance)
Aircraft has been moved from one location to another (changed scenery)
static swift::misc::simulation::CAircraftModel getDefaultOwnAircraftModel()
Default own aircraft.
static const swift::misc::aviation::CAircraftSituation & getDefaultSituation()
Default situation.
void changedSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Changed SELCAL code.
T get() const
Get a copy of the current value.
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
const CIdentifier & identifier() const
Get identifier.
Value object encapsulating information identifying a component of a modular distributed swift process...
static const QString & contextSlot()
Context slots.
Class for emitting a log message.
Derived & debug()
Set the severity to debug.
size_type size() const
Returns number of elements in the sequence.
void pop_back()
Removes an element at the end of the sequence.
reference front()
Access the first element.
void clear()
Removes all elements in the sequence.
bool isEmpty() const
Synonym for empty.
Utility methods for simple line parsing used with the command line.
void parse(const QString &commandLine)
Parse.
qint64 getTimeDifferenceMs(qint64 compareTime) const
Time difference in ms.
void setSortHint(HintTimestampSort hint)
Set the hint.
void push_frontKeepLatestAdjustedFirst(const OBJ &value, bool replaceSameTimestamp=true, int maxElements=-1)
Insert as first element by keeping maxElements and the latest first.
Value object for ICAO classification.
bool hasValidDesignator() const
Valid aircraft designator?
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of an aircraft's situation.
List of aircraft situations.
Value object for ICAO classification.
Altitude as used in aviation, can be AGL or MSL altitude.
Value object encapsulating information of a callsign.
void setFrequencyActive(const physical_quantities::CFrequency &frequency)
Set active frequency.
void setTransponderCode(int transponderCode)
Set transponder code.
bool setTransponderMode(TransponderMode mode)
Set transponder mode.
void toggleTransponderMode()
Transponder mode toggled.
TransponderMode
Transponder codes.
Geodetic coordinate, a position in 3D space relative to the reference geoid.
physical_quantities::CLength calculateGreatCircleDistance(const ICoordinateGeodetic &otherCoordinate) const
Great circle distance.
bool containsObjectOutsideRange(const ICoordinateGeodetic &coordinate, const physical_quantities::CLength &range) const
Any object in range?
CONTAINER findFarthest(int number, const ICoordinateGeodetic &coordinate) const
Find 0..n objects farthest to the given coordinate.
Value object encapsulating information of a user.
Physical unit length (length)
Aircraft model (used by another pilot, my models on disk)
const physical_quantities::CLength & getCG() const
Get center of gravity.
Comprehensive information of an aircraft.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
const aviation::CSelcal getSelcal() const
SELCAL.
void setModel(const CAircraftModel &model)
Set model.
void initTransponder()
Meaningful default settings for Transponder.
const aviation::CAircraftSituation & getSituation() const
Get situation.
void setCockpit(const CSimulatedAircraft &aircraft)
Set COM unit (all values + transponder and SELCAL)
const aviation::CComSystem & getCom2System() const
Get COM2 system.
void initComSystems()
Meaningful default settings for COM Systems.
const aviation::CTransponder & getTransponder() const
Get transponder.
bool setTransponderMode(aviation::CTransponder::TransponderMode mode)
Set transponder mode.
bool setCG(const physical_quantities::CLength &cg)
Set the center of gravity.
void setSelcal(const aviation::CSelcal &selcal)
Own SELCAL code.
const aviation::CAltitude & getPressureAltitude() const
Get pressure altitude.
void setPosition(const geo::CCoordinateGeodetic &position)
Set position.
void setSituation(const aviation::CAircraftSituation &situation)
Set situation. Won't overwrite the velocity unless it held the default value.
void setPressureAltitude(const aviation::CAltitude &altitude)
Set pressure altitude.
const network::CUser & getPilot() const
Get user.
const aviation::CCallsign & getCallsign() const
Get callsign.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Get aircraft ICAO info.
bool hasChangedCockpitData(const aviation::CComSystem &com1, const aviation::CComSystem &com2, const aviation::CTransponder &transponder) const
Changed cockpit data?
geo::CCoordinateGeodetic getPosition() const
Get position.
bool hasValidCallsign() const
Valid callsign?
const simulation::CAircraftModel & getModel() const
Get model (model used for mapping)
aviation::CComSystem getComSystem(aviation::CComSystem::ComUnit unit) const
Get COM unit.
void setParts(const aviation::CAircraftParts &parts)
Set aircraft parts.
bool setIcaoCodes(const aviation::CAircraftIcaoCode &aircraftIcaoCode, const aviation::CAirlineIcaoCode &airlineIcaoCode)
Set ICAO info.
const aviation::CAltitude & getAltitude() const
Get altitude.
const aviation::CComSystem & getCom1System() const
Get COM1 system.
const aviation::CAircraftParts & getParts() const
Get aircraft parts.
void setPilot(const network::CUser &user)
Set pilot.
void setAltitude(const aviation::CAltitude &altitude)
Set altitude.
bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator)
Parse a given command line.
Classes interacting with the swift database (aka "datastore").
Backend services of the swift project, like dealing with the network or the simulators.
Free functions in swift::misc.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
bool isEmpty() const const