diff --git a/Changelog.txt b/Changelog.txt index 0a6d93d..4273298 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,13 +1,21 @@ [Changelog v0.14.3] +>[!NOTE] +> Feedback from users with consecutive SID letters welcome to validate proper matching +> e.g. WERRA vs WERA / PAZZE vs PAZE + :new: **New Features** * FPLN - temporarily added scratch pad info which callsign used the sync command +* CONF - collapsing SID or TRANS base when consecutive characters are the same as new Navigraph data collapses those names which are then present in the sector file (#358) :gear: **Changed Features / Behaviour** * GEN - changed topsky and ccams lookup check to lower case * FPLN - added checks to _CTL_ and _AUTO_ scratch pad entries to not trigger sync queue processing * FPLN - moved clearance flag sync release to flight plan data update +:lady_beetle: **Fixes** +* CONF - fixed a crash when SID health check was triggered for different SID numbers due to an accidentally wrong type assignment + [Changelog v0.14.2] :new: **New Features** diff --git a/sid.cpp b/sid.cpp index 68f18aa..43d972a 100644 --- a/sid.cpp +++ b/sid.cpp @@ -22,6 +22,30 @@ bool vsid::Sid::empty() const return base == ""; } +bool vsid::Sid::collapsedBaseMatch(std::string_view other, std::optional trans) +{ + std::string collapsed; + std::string_view s; + + if (!trans) + { + collapsed.reserve(this->base.size()); + s = this->base; + } + else + { + collapsed.reserve(trans.value().size()); + s = trans.value(); + } + + for (char c : s) + { + if (collapsed.empty() || collapsed.back() != c) collapsed.push_back(c); + } + + return collapsed == other; +} + bool vsid::Sid::operator==(const Sid& sid) { if (this->designator != "") diff --git a/sid.h b/sid.h index 3559eec..8ddd414 100644 --- a/sid.h +++ b/sid.h @@ -25,6 +25,7 @@ along with this program. If not, see . #include #include #include +#include namespace vsid { @@ -128,7 +129,18 @@ namespace vsid */ bool empty() const; - bool isExactly(const vsid::Sid& other) const; + //************************************ + // Description: Collapses sid / trans bases with consecutive letters for a match + // Method: collapsedBaseMatch + // FullName: vsid::Sid::collapsedBaseMatch + // Access: public + // Returns: bool + // Qualifier: + // Parameter: std::string_view other - the other string to compare to (usually from .ese file) + // Parameter: std::optional trans - as multiple transitions can be held it has to be specified + // for the check, if nullopt the sid base is checked + //************************************ + bool collapsedBaseMatch(std::string_view other, std::optional trans = std::nullopt); /** * @brief Compares if two SIDs are the same * diff --git a/vSIDPlugin.cpp b/vSIDPlugin.cpp index 34b66b3..3283d10 100644 --- a/vSIDPlugin.cpp +++ b/vSIDPlugin.cpp @@ -4978,7 +4978,23 @@ void vsid::VSIDPlugin::UpdateActiveAirports() for (vsid::Sid& sid : this->activeAirports[sectionSid.apt].sids) { - if (sid.base != sectionSid.base) continue; + if (sid.base != sectionSid.base) + { + // skip unmatching first two char comparison (filter) + if (sid.base.length() > 2 && sectionSid.base.length() > 2) + { + if (sid.base[0] != sectionSid.base[0]) continue; + if (sid.base[1] != sectionSid.base[1]) continue; + if (sid.base[2] != sectionSid.base[2]) continue; + } + + if (!sid.collapsedBaseMatch(sectionSid.base)) + { + messageHandler->writeMessage("DEBUG", "[" + sid.base + "] sid collapsed didn't match [" + sectionSid.base + "]", vsid::MessageHandler::DebugArea::Dev); + continue; + } + else messageHandler->writeMessage("DEBUG", "[" + sid.base + "] sid collapsed matched [" + sectionSid.base + "]", vsid::MessageHandler::DebugArea::Dev); + } if (sid.designator != (sectionSid.desig ? std::string(1, *sectionSid.desig) : "")) continue; if (!vsid::utils::contains(sid.rwys, sectionSid.rwy)) continue; @@ -5003,7 +5019,24 @@ void vsid::VSIDPlugin::UpdateActiveAirports() } else if (sid.number != "") // health check for possible errors in .ese config { - int currNumber = std::stoi(sid.number); + int currNumber = -1; + + try + { + currNumber = std::stoi(sid.number); // #dev - removed int -> debugging + } + catch (const std::invalid_argument& e) + { + messageHandler->writeMessage("ERROR", "Collapsing SID [" + sid.idName() + "] caused an error while collapsing base for section SID [" + + sectionSid.base + "]. Error: " + e.what()); + } + catch (const std::out_of_range& e) + { + messageHandler->writeMessage("ERROR", "Collapsing SID [" + sid.idName() + "] caused an error while collapsing base for section SID [" + + sectionSid.base + "]. Error: " + e.what()); + } + if (currNumber == -1) continue; + int newNumber = sectionSid.number - '0'; if (currNumber > newNumber || (currNumber == 1 && newNumber == 9)) @@ -5018,7 +5051,7 @@ void vsid::VSIDPlugin::UpdateActiveAirports() std::to_string(currNumber) + " (ID: " + sid.id + "). Now found additional number: " + std::to_string(newNumber) + " - (Runway: " + sectionSid.rwy + ") . Setting additional number (is higher or after restarting count) due to possible sectore file error!"); - sid.number = newNumber; + sid.number = std::to_string(newNumber); } else if (currNumber != newNumber) { @@ -5026,7 +5059,7 @@ void vsid::VSIDPlugin::UpdateActiveAirports() std::to_string(currNumber) + " (ID: " + sid.id + "). Now found additional number: " + std::to_string(newNumber) + " - (Runway: " + sectionSid.rwy + ") . Setting additional number as it couldn't be determined which one is more likely to be correct!"); - sid.number = newNumber; + sid.number = std::to_string(newNumber); } } @@ -5039,7 +5072,23 @@ void vsid::VSIDPlugin::UpdateActiveAirports() for (auto& [transBase, trans] : sid.transition) { - if (transBase != sectionSid.trans.base) continue; + if (transBase != sectionSid.trans.base) + { + // skip unmatching first two char comparison (filter) + if (transBase.length() > 2 && sectionSid.trans.base.length() > 2) + { + if (transBase[0] != sectionSid.trans.base[0]) continue; + if (transBase[1] != sectionSid.trans.base[1]) continue; + if (transBase[2] != sectionSid.trans.base[2]) continue; + } + + if (!sid.collapsedBaseMatch(sectionSid.trans.base, transBase)) + { + messageHandler->writeMessage("DEBUG", "[" + transBase + "] trans collapsed didn't match [" + sectionSid.trans.base + "]", vsid::MessageHandler::DebugArea::Dev); + continue; + } + else messageHandler->writeMessage("DEBUG", "[" + transBase + "] trans collapsed matched [" + sectionSid.trans.base + "]", vsid::MessageHandler::DebugArea::Dev); + } if (trans.designator != (sectionSid.trans.desig ? std::string(1, *sectionSid.trans.desig) : "")) continue; if (trans.number != "") // #refactor .number to char {