9#include <QRegularExpression>
10#include <QStringBuilder>
23using namespace swift::misc::network;
24using namespace swift::misc::physical_quantities;
29namespace swift::misc::aviation
40 : m_remarks(
cleanRemarks(remarks)), m_voiceCapabilities(voiceCapabilities)
50 if (m_selcalCode == selcal || selcal.
length() != 4)
55 CFlightPlanRemarks::replaceRemark(m_remarks, QStringLiteral(
"SEL/"), QStringLiteral(
"SEL/%1").arg(selcal));
62 m_voiceCapabilities = capabilities;
83 return !m_radioTelephony.
isEmpty() || !m_flightOperator.isEmpty() || m_airlineIcao.hasValidDesignator();
88 const QString s = (m_registration.isEmpty() ?
QString() : u
"reg.: " % m_registration.toQString(i18n)) %
90 (m_radioTelephony.isEmpty() ?
QString() : u
" radio tel.:" % m_radioTelephony) %
91 (m_flightOperator.isEmpty() ?
QString() : u
" operator: " % m_flightOperator) %
92 (!m_selcalCode.isValid() ?
QString() : u
" SELCAL: " % m_selcalCode.getCode()) % u
" voice: " %
93 m_voiceCapabilities.toQString(i18n);
111 return newCapRemarks;
130 return newCapRemarks % u
' ' % r;
148 if (!force && m_isParsed)
153 if (m_remarks.isEmpty())
161 m_registration =
CCallsign(callsign, CCallsign::Aircraft);
163 m_voiceCapabilities = m_voiceCapabilities.isUnknown() ?
CVoiceCapabilities(m_remarks) : m_voiceCapabilities;
165 getRemark(remarks,
"OPR/");
166 m_selcalCode =
CSelcal(getRemark(remarks,
"SEL/"));
167 m_radioTelephony = getRemark(remarks,
"CALLSIGN/");
168 if (m_radioTelephony.isEmpty())
170 m_radioTelephony = getRemark(remarks,
"RT/");
176 m_flightOperator.clear();
182 const int maxIndex = remarks.
size() - 1;
183 int f = remarks.
indexOf(marker);
199 thread_local const QRegularExpression nextMarker(
"\\s+\\w*/|$");
200 int to1 = remarks.
indexOf(nextMarker, f + 1);
205 int to2 = remarks.
indexOf(
'/', f + 1);
210 const int to = qMin(to1, to2);
215 QString CFlightPlanRemarks::replaceRemark(
const QString &remarks,
const QString &marker,
const QString &newRemark)
218 const int maxIndex = remarks.
size() - 1;
219 int f = remarks.
indexOf(marker);
227 thread_local const QRegularExpression nextMarker(
"\\s+\\w*/|$");
228 int to1 = remarks.
indexOf(nextMarker, f + 1);
233 int to2 = remarks.
indexOf(
'/', f + 1);
238 const int to = qMin(to1, to2);
241 return r.isEmpty() ? newRemark : r % u
" " % newRemark;
257 : m_callsign(callsign), m_aircraftInfo(aircraftInfo), m_originAirportIcao(originAirportIcao),
258 m_destinationAirportIcao(destinationAirportIcao), m_alternateAirportIcao(alternateAirportIcao),
259 m_takeoffTimePlanned(takeoffTimePlanned), m_takeoffTimeActual(takeoffTimeActual), m_enrouteTime(enrouteTime),
260 m_fuelTime(fuelTime), m_cruiseAltitude(cruiseAltitude), m_cruiseTrueAirspeed(cruiseTrueAirspeed),
264 m_callsign.setTypeHint(CCallsign::Aircraft);
271 m_callsign = callsign;
279 m_takeoffTimePlanned = takeoffTimePlanned.
toUTC();
284 m_takeoffTimeActual = takeoffTimeActual.
toUTC();
305 m_remarks.setVoiceCapabilities(vc);
326 case IndexAlternateAirportIcao:
return m_alternateAirportIcao.propertyByIndex(index.
copyFrontRemoved());
327 case IndexDestinationAirportIcao:
return m_destinationAirportIcao.propertyByIndex(index.
copyFrontRemoved());
328 case IndexOriginAirportIcao:
return m_originAirportIcao.propertyByIndex(index.
copyFrontRemoved());
329 case IndexCallsign:
return m_callsign.propertyByIndex(index.
copyFrontRemoved());
351 case IndexAlternateAirportIcao:
352 m_alternateAirportIcao.setPropertyByIndex(index.
copyFrontRemoved(), variant);
354 case IndexDestinationAirportIcao:
355 m_destinationAirportIcao.setPropertyByIndex(index.
copyFrontRemoved(), variant);
357 case IndexOriginAirportIcao: m_originAirportIcao.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
358 case IndexCallsign: m_callsign.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
368 QString CFlightPlan::buildString(
bool i18n,
const QString &separator)
const
371 m_callsign.
toQString(i18n) % u
" aircraft: " % m_aircraftInfo.
asIcaoString() % separator % u
"origin: " %
372 m_originAirportIcao.
toQString(i18n) % u
" destination: " % m_destinationAirportIcao.
toQString(i18n) %
373 u
" alternate: " % m_alternateAirportIcao.
toQString(i18n) % separator % u
"takeoff planed: " %
374 m_takeoffTimePlanned.
toString(
"ddhhmm") % u
" actual: " % m_takeoffTimeActual.
toString(
"ddhhmm") %
375 separator % u
"enroute time: " % m_enrouteTime.
toQString(i18n) % u
" fuel time:" %
376 m_fuelTime.
toQString(i18n) % separator % u
"altitude: " % m_cruiseAltitude.
toQString(i18n) % u
" speed: " %
377 m_cruiseTrueAirspeed.
toQString(i18n) % separator % u
"route: " % m_route % separator % u
"remarks: " %
419 const int enrouteMins =
432 if (departureTime.
length() == 4)
453 const CAltitude alt(altStr.
length() < 4 ?
"FL" + altStr : altStr +
"ft");
458 const int fuelMins = values.
value(
"FuelMinutes").toInt() + 60 * values.
value(
"FuelHours").toInt();
461 const int enrouteMins = values.
value(
"FlightMinutes").toInt() + 60 * values.
value(
"FlightHours").toInt();
476 int airspeedKts = values.
value(
"Airspeed").toInt();
526 const int cruiseAltFt = cruiseAlt.
toInt(&ok);
530 if (cruiseAlt.
endsWith(
"00") && cruiseAltFt > 5000)
535 if (cruiseAltFt >= 10000)
549 const int tasKts = tas.
toInt(&ok);
562 const int enrouteSecs = enroute.
toInt(&ok);
568 const int enduranceSecs = endurance.
toInt(&ok);
574 const int depTimeUnixTs = depTime.
toInt(&ok);
589 const int b = equipment.
indexOf(
'-');
590 const int e = equipment.
indexOf(
'/');
592 if (e > b && e >= 0 && b >= 0 && equipment.
size() > e)
596 const QChar wtcChar = equipment.
mid(0, 1).
at(0);
599 const QString comNavEquipmentString = equipment.
mid(b + 1, e - b - 1);
602 const QString ssrEquipmentString = equipment.
mid(e + 1);
611 bool remarksChanged =
false;
616 remarksChanged = c || remarksChanged;
674 .validationError(u
"File '%1' does not exist")
687 .validationError(u
"File '%1' does not contain data")
706 if (!json::looksLikeSwiftJson(data))
709 u
"Reading '%1' yields no data",
true)
721 if (json::looksLikeSwiftTypeValuePairJson(jsonObject))
734 u
"Wrong format for flight plan in '%1'")
751 "Parse error in " + fileName);
770 QStringLiteral(
"Parsing flight plan from '%1' failed.").arg(fileName)));
780 static const QString s(
"SVFR");
781 static const QString d(
"DVFR");
782 static const QString unknown(
"???");
824 static const QStringList r({
"IFR",
"VFR",
"SVFR",
"DVFR" });
static QString readFileToString(const QString &fileNameAndPath)
Read file into string.
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
static const QString & flightPlan()
Flight plan.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void push_back(const T &value)
Appends an element at the end of the sequence.
Streamable status message, e.g.
static CStatusMessage fromJsonException(const CJsonException &ex, const CLogCategoryList &categories, const QString &prefix)
Object from JSON exception message.
static constexpr auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T value() const
Return the value converted to the type T.
void convertFromJson(const QJsonObject &json)
Assign from JSON object.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Value object for ICAO classification.
static bool isValidAirlineDesignator(const QString &airline)
Valid designator?
Value object encapsulating information of airport ICAO data.
Altitude as used in aviation, can be AGL or MSL altitude.
bool toFlightLevel()
MSL to flightlevel.
Value object encapsulating information of a callsign.
static QString unifyCallsign(const QString &callsign, TypeHint hint=NoHint)
Unify the callsign by removing illegal characters.
static bool isValidAircraftCallsign(const QString &callsign)
Valid callsign?
void setTypeHint(TypeHint hint)
Type hint.
ICAO flightplan field 10a.
Flightplan-related information about an aircraft (aircraft ICAO, equipment and WTC).
QString asIcaoString() const
Full string in ICAO format: "AIRCRAFT_ICAO/WTC-EQUIPMENT/SSR".
CAircraftIcaoCode getAircraftIcao() const
Get Aircraft ICAO.
QString asHTML(bool i18n=false) const
As HTML.
static bool isVFRRules(FlightRules rule)
Is rule a VFR rule?
void setAircraftInfo(const CFlightPlanAircraftInfo &aircraftInfo)
Set information about the aircraft used in this flightplan.
CIcons::IconIndex toIcon() const
As icon, not implemented by all classes.
void setFlightPlanRemarks(const CFlightPlanRemarks &remarks)
Set FP remarks.
CFlightPlan()=default
Default constructor.
void setFlightRule(FlightRules flightRule)
Set flight rules (VFR or IFR).
const CFlightPlanRemarks & getFlightPlanRemarks() const
Get the parsable remarks.
static FlightRules stringToFlightRules(const QString &flightRules)
String to flight rules.
QString getTakeoffTimePlannedHourMin() const
Get planned takeoff time (planned).
ColumnIndex
Properties by index.
void setVoiceCapabilities(const QString &capabilities)
Set voice capabilities.
void setOriginAirportIcao(const QString &originAirportIcao)
Set origin airport ICAO code.
void setTakeoffTimePlanned(const QDateTime &takeoffTimePlanned)
Set planned takeoff time.
void setCruiseTrueAirspeed(const physical_quantities::CSpeed &cruiseTrueAirspeed)
Set planned cruise TAS.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setAlternateAirportIcao(const QString &alternateAirportIcao)
Set alternate destination airport ICAO code.
void setFuelTime(const physical_quantities::CTime &fuelTime)
Set amount of fuel load in time.
static const QStringList & flightRules()
All rules as string.
static CFlightPlan fromSimBriefFormat(const QString &simBrief)
From SimBrief format (XML).
FlightRules
Flight rules (VFR or IFR).
@ IFR
Instrument flight rules.
@ VFR
Visual flight rules.
@ SVFR
Special VFR (reserved for ATC use),.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static CFlightPlan fromMultipleFormats(const QString &data, const QString &fileSuffix)
From multiple formats.
static const QString & flightRulesToString(FlightRules rules)
Rules to string.
const QString & getRemarks() const
Get remarks string.
void setTakeoffTimeActual(const QDateTime &takeoffTimeActual)
Set actual takeoff time (reserved for ATC use).
void setCruiseAltitudeString(const QString &altitudeString)
Cruising altitude already as string.
QString getTakeoffTimeActualHourMin() const
Get actual takeoff time (actual).
void setRemarks(const QString &remarks)
Set remarks string (max 100 characters).
static const QStringList & getLogCategories()
The log. catgeories.
QString convertToQString(bool i18n=false) const
Cast as QString.
void setEnrouteTime(const physical_quantities::CTime &enrouteTime)
Set planned enroute flight time.
static CFlightPlan fromSB4Format(const QString &sbData)
From SB4 data.
static constexpr int MaxRemarksLength
Max.remarks length.
void setRoute(const QString &route)
Set route string.
static CFlightPlan fromVPilotFormat(const QString &vPilotData)
From vPilot data.
static bool isIFRRules(FlightRules rule)
Is rule a IFR rule?
static constexpr int MaxRouteLength
Max.route length.
void setDestinationAirportIcao(const QString &destinationAirportIcao)
Set destination airport ICAO code.
void setCruiseAltitude(const CAltitude &cruiseAltitude)
Set planned cruise altitude.
CFlightPlanAircraftInfo getAircraftInfo() const
Get ICAO aircraft NAV/COM equipment.
static CFlightPlan loadFromMultipleFormats(const QString &fileName, CStatusMessageList *msgs=nullptr)
Load from multiple formats.
void setCallsign(const CCallsign &callsign)
Callsign (of aircraft).
ICAO flightplan field 10b.
ICAO wake turbulence category.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating information for voice capabilities.
const QString & toFlightPlanRemarks() const
To flight plan remarks.
static CVoiceCapabilities fromText(const QString &text)
From text like "text only".
static CLengthUnit ft()
Foot ft.
static CSpeedUnit kts()
Knots.
QDateTime toQDateTime() const
To Qt date time.
bool parseFromString_hhmm(const QString &hhmm)
From string like 2211 (hhmm).
static CTimeUnit min()
Minute.
static CTimeUnit hrmin()
Hours, minutes.
static CTimeUnit s()
Second s.
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
JSON Object from string.
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate)
Remove accents / diacritic marks from a string.
SWIFT_MISC_EXPORT QMap< QString, QString > parseIniValues(const QString &data)
Obtain ini file like values, e.g. foo=bar.
QString asciiOnlyString(const QString &string)
String only with ASCII values.
QDateTime currentDateTimeUtc()
QDateTime fromSecsSinceEpoch(qint64 secs)
void setTimeZone(const QTimeZone &toZone, QDateTime::TransitionResolution resolve)
QString toString(QStringView format) const const
QDateTime toUTC() const const
QDomNodeList elementsByTagName(const QString &tagname) const const
QDomDocument::ParseResult setContent(QAnyStringView text, QDomDocument::ParseOptions options)
QString attribute(const QString &name, const QString &defValue) const const
QString text() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
QDomNode at(int index) const const
bool isEmpty() const const
bool exists(const QString &path)
QString suffix() const const
T value(const Key &key, const T &defaultValue) const const
const QChar at(qsizetype position) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString simplified() const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString toLower() const const
QString toUpper() const const
QString trimmed() const const
QVariant fromValue(T &&value)
QString toString() const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.