7 #include <QDomDocument>
9 #include <QRegularExpression>
10 #include <QStringBuilder>
23 using namespace swift::misc::network;
24 using namespace swift::misc::physical_quantities;
29 namespace swift::misc::aviation
31 CFlightPlanRemarks::CFlightPlanRemarks(
const QString &remarks,
bool parse) : m_remarks(cleanRemarks(remarks))
37 : m_remarks(cleanRemarks(remarks)), m_voiceCapabilities(voiceCapabilities)
44 if (m_selcalCode == selcal || selcal.
length() != 4) {
return false; }
46 CFlightPlanRemarks::replaceRemark(m_remarks, QStringLiteral(
"SEL/"), QStringLiteral(
"SEL/%1").arg(selcal));
53 m_voiceCapabilities = capabilities;
61 if (!m_isParsed) {
return false; }
67 if (!m_isParsed) {
return false; }
75 (m_radioTelephony.
isEmpty() ?
QString() : u
" radio tel.:" % m_radioTelephony) %
76 (m_flightOperator.
isEmpty() ?
QString() : u
" operator: " % m_flightOperator) %
90 if (newCapRemarks.
isEmpty()) {
return oldRemarks; }
91 if (oldRemarks.
isEmpty()) {
return newCapRemarks; }
109 return newCapRemarks % u
' ' % r;
127 if (!force && m_isParsed) {
return; }
129 if (m_remarks.
isEmpty()) {
return; }
135 getRemark(remarks,
"OPR/");
136 m_selcalCode =
CSelcal(getRemark(remarks,
"SEL/"));
137 m_radioTelephony = getRemark(remarks,
"CALLSIGN/");
138 if (m_radioTelephony.
isEmpty()) { m_radioTelephony = getRemark(remarks,
"RT/"); }
143 m_flightOperator.
clear();
149 const int maxIndex = remarks.
size() - 1;
150 int f = remarks.
indexOf(marker);
151 if (f < 0) {
return {}; }
153 if (maxIndex <= f) {
return {}; }
161 int to1 = remarks.
indexOf(nextMarker, f + 1);
162 if (to1 < 0) { to1 = maxIndex + 1; }
163 int to2 = remarks.
indexOf(
'/', f + 1);
164 if (to2 < 0) { to2 = maxIndex + 1; }
165 const int to = qMin(to1, to2);
173 const int maxIndex = remarks.
size() - 1;
174 int f = remarks.
indexOf(marker);
178 if (maxIndex <= f) {
return remarks; }
180 int to1 = remarks.
indexOf(nextMarker, f + 1);
181 if (to1 < 0) { to1 = maxIndex + 1; }
182 int to2 = remarks.
indexOf(
'/', f + 1);
183 if (to2 < 0) { to2 = maxIndex + 1; }
184 const int to = qMin(to1, to2);
187 return r.isEmpty() ? newRemark : r % u
" " % newRemark;
203 : m_callsign(callsign), m_aircraftInfo(aircraftInfo), m_originAirportIcao(originAirportIcao),
204 m_destinationAirportIcao(destinationAirportIcao), m_alternateAirportIcao(alternateAirportIcao),
205 m_takeoffTimePlanned(takeoffTimePlanned), m_takeoffTimeActual(takeoffTimeActual), m_enrouteTime(enrouteTime),
206 m_fuelTime(fuelTime), m_cruiseAltitude(cruiseAltitude), m_cruiseTrueAirspeed(cruiseTrueAirspeed),
207 m_flightRules(flightRules), m_route(route.trimmed().left(MaxRouteLength).toUpper()),
208 m_remarks(remarks.trimmed().left(MaxRemarksLength).toUpper())
217 m_callsign = callsign;
225 m_takeoffTimePlanned = takeoffTimePlanned.
toUTC();
230 m_takeoffTimeActual = takeoffTimeActual.
toUTC();
291 case IndexAlternateAirportIcao:
294 case IndexDestinationAirportIcao:
308 QString CFlightPlan::buildString(
bool i18n,
const QString &separator)
const
311 m_callsign.
toQString(i18n) % u
" aircraft: " % m_aircraftInfo.
asIcaoString() % separator % u
"origin: " %
312 m_originAirportIcao.
toQString(i18n) % u
" destination: " % m_destinationAirportIcao.
toQString(i18n) %
313 u
" alternate: " % m_alternateAirportIcao.
toQString(i18n) % separator % u
"takeoff planed: " %
314 m_takeoffTimePlanned.
toString(
"ddhhmm") % u
" actual: " % m_takeoffTimeActual.
toString(
"ddhhmm") %
315 separator % u
"enroute time: " % m_enrouteTime.
toQString(i18n) % u
" fuel time:" %
316 m_fuelTime.
toQString(i18n) % separator % u
"altitude: " % m_cruiseAltitude.
toQString(i18n) % u
" speed: " %
317 m_cruiseTrueAirspeed.
toQString(i18n) % separator % u
"route: " % m_route % separator % u
"remarks: " %
324 if (vPilotData.
isEmpty()) {
return {}; }
334 const CSpeed airspeed(airspeedKts, CSpeedUnit::kts());
354 const CTime fuelTime(fuelMins, CTimeUnit::min());
356 const int enrouteMins =
358 const CTime enrouteTime(enrouteMins, CTimeUnit::min());
369 if (departureTime.
length() == 4)
380 if (sbData.
isEmpty()) {
return {}; }
384 const CAltitude alt(altStr.
length() < 4 ?
"FL" + altStr : altStr +
"ft");
389 const int fuelMins = values.
value(
"FuelMinutes").toInt() + 60 * values.
value(
"FuelHours").toInt();
390 const CTime fuelTime(fuelMins, CTimeUnit::min());
392 const int enrouteMins = values.
value(
"FlightMinutes").toInt() + 60 * values.
value(
"FlightHours").toInt();
393 const CTime enrouteTime(enrouteMins, CTimeUnit::min());
407 int airspeedKts = values.
value(
"Airspeed").toInt();
408 const CSpeed airspeed(airspeedKts, CSpeedUnit::kts());
418 if (simBrief.
isEmpty()) {
return {}; }
454 const int cruiseAltFt = cruiseAlt.
toInt(&ok);
465 const int tasKts = tas.
toInt(&ok);
475 const int enrouteSecs = enroute.
toInt(&ok);
478 const int enduranceSecs = endurance.
toInt(&ok);
481 const int depTimeUnixTs = depTime.
toInt(&ok);
496 const int b = equipment.
indexOf(
'-');
497 const int e = equipment.
indexOf(
'/');
499 if (e > b && e >= 0 && b >= 0 && equipment.
size() > e)
503 const QChar wtcChar = equipment.
mid(0, 1).
at(0);
506 const QString comNavEquipmentString = equipment.
mid(b + 1, e - b - 1);
509 const QString ssrEquipmentString = equipment.
mid(e + 1);
518 bool remarksChanged =
false;
523 remarksChanged = c || remarksChanged;
534 if (data.
isEmpty()) {
return {}; }
572 .validationError(u
"File '%1' does not exist")
585 .validationError(u
"File '%1' does not contain data")
597 if (!json::looksLikeSwiftJson(data))
600 u
"Reading '%1' yields no data",
true)
609 if (json::looksLikeSwiftTypeValuePairJson(jsonObject))
622 u
"Wrong format for flight plan in '%1'")
636 "Parse error in " + fileName);
652 QStringLiteral(
"Parsing flight plan from '%1' failed.").arg(fileName)));
662 static const QString s(
"SVFR");
663 static const QString d(
"DVFR");
664 static const QString unknown(
"???");
691 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.
constexpr static 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?
const QString & getDesignator() const
Get airline, e.g. "DLH".
bool hasValidDesignator() const
Airline designator available?
Value object encapsulating information of airport ICAO data.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Altitude as used in aviation, can be AGL or MSL altitude.
bool toFlightLevel()
MSL to flightlevel.
Value object encapsulating information of a callsign.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static QString unifyCallsign(const QString &callsign, TypeHint hint=NoHint)
Unify the callsign by removing illegal characters.
bool isEmpty() const
Is empty?
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.
Value object for a flight plan.
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)
static FlightRules stringToFlightRules(const QString &flightRules)
String to flight rules.
QString getTakeoffTimePlannedHourMin() const
Get planned takeoff time (planned)
const CFlightPlanRemarks & getFlightPlanRemarks() const
Get the parsable remarks.
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.
void setTakeoffTimeActual(const QDateTime &takeoffTimeActual)
Set actual takeoff time (reserved for ATC use)
const QString & getRemarks() const
Get remarks string.
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.
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)
bool isValid() const
Is valid?
const QString & getCode() const
Get SELCAL code.
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.
bool isUnknown() const
Is capability known.
const QString & toFlightPlanRemarks() const
To flight plan remarks.
PQ & switchUnit(const MU &newUnit)
Change unit, and convert value to maintain the same quantity.
QDateTime toQDateTime() const
To Qt date time.
bool parseFromString_hhmm(const QString &hhmm)
From string like 2211 (hhmm)
static CTimeUnit hrmin()
Hours, minutes.
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
JSON Object from string.
SWIFT_MISC_EXPORT QMap< QString, QString > parseIniValues(const QString &data)
Obtain ini file like values, e.g. foo=bar.
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate)
Remove accents / diacritic marks from a string.
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
qsizetype length() 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.