give the controller the information he needs and that he can configure the tags
This commit is contained in:
151
src/PlugIn.cpp
151
src/PlugIn.cpp
@@ -71,8 +71,8 @@ PlugIn::PlugIn() :
|
||||
this->RegisterTagItemType("PTA", static_cast<int>(PlugIn::TagItemElement::PlannedTimeOfArrival));
|
||||
this->RegisterTagItemType("Delta time", static_cast<int>(PlugIn::TagItemElement::DeltaTime));
|
||||
this->RegisterTagItemType("Fixed plan indicator", static_cast<int>(PlugIn::TagItemElement::FixedPlanIndicator));
|
||||
this->RegisterTagItemFunction("Force planning", static_cast<int>(PlugIn::TagItemFunction::ForceToBackendMenu));
|
||||
this->RegisterTagItemFunction("Runway selection", static_cast<int>(PlugIn::TagItemFunction::RunwaySelectMenu));
|
||||
this->RegisterTagItemFunction("Direct to", static_cast<int>(PlugIn::TagItemFunction::DirectToMenu));
|
||||
|
||||
this->DisplayUserMessage(PLUGIN_NAME, "INFO", (std::string("Loaded ") + PLUGIN_NAME + " " + PLUGIN_VERSION).c_str(), true, true, false, false, false);
|
||||
|
||||
@@ -498,6 +498,32 @@ bool PlugIn::OnCompileCommand(const char* cmdline) {
|
||||
this->m_sweatboxValid = false;
|
||||
retval = true;
|
||||
}
|
||||
else if (std::string::npos != message.find("FORCE")) {
|
||||
const auto elements = String::splitString(message, " ");
|
||||
|
||||
if (3 <= elements.size()) {
|
||||
const auto callsign = elements[2];
|
||||
|
||||
const auto radarTarget = this->RadarTargetSelect(callsign.c_str());
|
||||
|
||||
if (true == radarTarget.IsValid()) {
|
||||
std::string destination(radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetDestination());
|
||||
std::transform(destination.begin(), destination.end(), destination.begin(), ::toupper);
|
||||
std::lock_guard updateGuard(this->m_updateQueueLock);
|
||||
|
||||
auto it = this->m_updateQueue.find(destination);
|
||||
|
||||
if (this->m_updateQueue.end() != it) {
|
||||
auto cIt = std::find(this->m_forcedToBackendCallsigns.cbegin(), this->m_forcedToBackendCallsigns.cend(), callsign);
|
||||
|
||||
if (this->m_forcedToBackendCallsigns.cend() == cIt)
|
||||
this->m_forcedToBackendCallsigns.push_back(callsign);
|
||||
else
|
||||
this->m_forcedToBackendCallsigns.erase(cIt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (true == retval) {
|
||||
if (true == this->m_sweatboxValid)
|
||||
@@ -527,7 +553,7 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug
|
||||
std::transform(destination.begin(), destination.end(), destination.begin(), ::toupper);
|
||||
#pragma warning(default: 4244)
|
||||
|
||||
bool planExpected = false, forced = false;
|
||||
bool forced = false;
|
||||
const gsl::span<char, 16> tagString(itemString, 16UL);
|
||||
|
||||
this->m_updateQueueLock.lock();
|
||||
@@ -538,9 +564,6 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug
|
||||
forced = this->m_forcedToBackendCallsigns.cend() != cIt;
|
||||
}
|
||||
|
||||
/* check if the inbound is expected to be planned */
|
||||
planExpected = this->m_updateQueue.cend() != this->m_updateQueue.find(destination);
|
||||
|
||||
this->m_updateQueueLock.unlock();
|
||||
|
||||
std::lock_guard guard(this->m_inboundsQueueLock);
|
||||
@@ -550,10 +573,16 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug
|
||||
switch (static_cast<TagItemElement>(itemCode)) {
|
||||
case TagItemElement::EstimatedTimeOfArrival:
|
||||
{
|
||||
if (this->m_inbounds.cend() != it)
|
||||
message = UtcTime::timeToString(it->second.eta(), "%H:%M");
|
||||
else if (true == forced || true == planExpected)
|
||||
if (this->m_inbounds.cend() != it) {
|
||||
const auto eta = it->second.eta();
|
||||
if (UtcTime::Point() == eta)
|
||||
message = "??:??";
|
||||
else
|
||||
message = UtcTime::timeToString(it->second.eta(), "%H:%M");
|
||||
}
|
||||
else if (true == forced) {
|
||||
message = "??:??";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TagItemElement::PlannedTimeOfArrival:
|
||||
@@ -563,9 +592,9 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug
|
||||
if (UtcTime::Point() == pta)
|
||||
message = "??:??";
|
||||
else
|
||||
message = UtcTime::timeToString(it->second.pta(), "%H:%M");
|
||||
message = UtcTime::timeToString(pta, "%H:%M");
|
||||
}
|
||||
else if (true == forced || true == planExpected) {
|
||||
else if (true == forced) {
|
||||
message = "??:??";
|
||||
}
|
||||
break;
|
||||
@@ -578,7 +607,7 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug
|
||||
stream << ttl;
|
||||
message = stream.str();
|
||||
}
|
||||
else if (true == forced || true == planExpected) {
|
||||
else if (true == forced) {
|
||||
message = "??";
|
||||
}
|
||||
break;
|
||||
@@ -586,7 +615,7 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug
|
||||
case TagItemElement::FixedPlanIndicator:
|
||||
if (this->m_inbounds.cend() != it && false == it->second.fixedPlan())
|
||||
message = "*";
|
||||
else if (this->m_inbounds.cend() == it && (true == forced || true == planExpected))
|
||||
else if (this->m_inbounds.cend() == it && true == forced)
|
||||
message = "*";
|
||||
break;
|
||||
default:
|
||||
@@ -603,54 +632,20 @@ void PlugIn::OnFunctionCall(int functionId, const char* itemString, POINT pt, RE
|
||||
std::ignore = itemString;
|
||||
std::ignore = pt;
|
||||
|
||||
const auto radarTarget = this->RadarTargetSelectASEL();
|
||||
auto radarTarget = this->RadarTargetSelectASEL();
|
||||
if (false == radarTarget.IsValid() || false == radarTarget.GetCorrelatedFlightPlan().IsValid())
|
||||
return;
|
||||
|
||||
std::string callsign(radarTarget.GetCallsign());
|
||||
|
||||
std::lock_guard guardUpdate(this->m_updateQueueLock);
|
||||
std::lock_guard guardInbound(this->m_inboundsQueueLock);
|
||||
|
||||
switch (static_cast<PlugIn::TagItemFunction>(functionId)) {
|
||||
case PlugIn::TagItemFunction::ForceToBackendMenu:
|
||||
{
|
||||
this->OpenPopupList(area, "AMAN", 1);
|
||||
bool inList = this->m_forcedToBackendCallsigns.cend() != std::find(this->m_forcedToBackendCallsigns.cbegin(), this->m_forcedToBackendCallsigns.cend(), callsign);
|
||||
this->AddPopupListElement("Add to AMAN", "", static_cast<int>(PlugIn::TagItemFunction::ForceToBackendSelect),
|
||||
false, EuroScopePlugIn::POPUP_ELEMENT_NO_CHECKBOX, true == inList);
|
||||
this->AddPopupListElement("Remove from AMAN", "", static_cast<int>(PlugIn::TagItemFunction::ForceToBackendSelect),
|
||||
false, EuroScopePlugIn::POPUP_ELEMENT_NO_CHECKBOX, false == inList);
|
||||
break;
|
||||
}
|
||||
case PlugIn::TagItemFunction::ForceToBackendSelect:
|
||||
{
|
||||
std::string destination(radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetDestination());
|
||||
std::transform(destination.begin(), destination.end(), destination.begin(), ::toupper);
|
||||
|
||||
std::lock_guard guard(this->m_updateQueueLock);
|
||||
auto it = this->m_updateQueue.find(destination);
|
||||
|
||||
if (0 == std::strcmp(itemString, "Add to AMAN")) {
|
||||
if (this->m_updateQueue.end() != it) {
|
||||
auto cIt = std::find(this->m_forcedToBackendCallsigns.cbegin(), this->m_forcedToBackendCallsigns.cend(), callsign);
|
||||
if (this->m_forcedToBackendCallsigns.cend() == cIt)
|
||||
this->m_forcedToBackendCallsigns.push_back(callsign);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this->m_updateQueue.end() != it) {
|
||||
auto cIt = std::find(this->m_forcedToBackendCallsigns.begin(), this->m_forcedToBackendCallsigns.end(), callsign);
|
||||
if (this->m_forcedToBackendCallsigns.cend() != cIt)
|
||||
this->m_forcedToBackendCallsigns.erase(cIt);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case PlugIn::TagItemFunction::RunwaySelectMenu:
|
||||
{
|
||||
std::string destination(radarTarget.GetCorrelatedFlightPlan().GetFlightPlanData().GetDestination());
|
||||
std::transform(destination.begin(), destination.end(), destination.begin(), ::toupper);
|
||||
|
||||
std::lock_guard guard(this->m_updateQueueLock);
|
||||
auto it = this->m_updateQueue.find(destination);
|
||||
|
||||
if (this->m_updateQueue.cend() != it) {
|
||||
@@ -667,8 +662,6 @@ void PlugIn::OnFunctionCall(int functionId, const char* itemString, POINT pt, RE
|
||||
}
|
||||
case PlugIn::TagItemFunction::RunwaySelect:
|
||||
{
|
||||
std::lock_guard guard(this->m_updateQueueLock);
|
||||
|
||||
if (0 == std::strcmp(itemString, "Remove")) {
|
||||
auto it = this->m_selectedRunway.find(callsign);
|
||||
if (this->m_selectedRunway.end() != it)
|
||||
@@ -681,7 +674,38 @@ void PlugIn::OnFunctionCall(int functionId, const char* itemString, POINT pt, RE
|
||||
else
|
||||
this->m_selectedRunway.insert({ callsign, itemString });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlugIn::TagItemFunction::DirectToMenu:
|
||||
{
|
||||
auto it = this->m_inbounds.find(callsign);
|
||||
|
||||
if (this->m_inbounds.cend() != it && 0 != it->second.arrivalRoute().size()) {
|
||||
this->OpenPopupList(area, "Direct To", 2);
|
||||
|
||||
for (const auto& waypoint : std::as_const(it->second.arrivalRoute())) {
|
||||
std::string message;
|
||||
|
||||
if (it->second.nextWaypoint() == waypoint.name())
|
||||
message = "-> ";
|
||||
message += waypoint.name().c_str();
|
||||
|
||||
this->AddPopupListElement(message.c_str(), UtcTime::timeToString(waypoint.plannedArrivalTime(), "%H:%M").c_str(),
|
||||
static_cast<int>(PlugIn::TagItemFunction::DirectTo));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case PlugIn::TagItemFunction::DirectTo:
|
||||
{
|
||||
std::string_view message(itemString);
|
||||
if (0 != message.rfind("-> ", 0)) {
|
||||
auto it = this->m_inbounds.find(callsign);
|
||||
|
||||
if (this->m_inbounds.end() != it)
|
||||
it->second.directTo(radarTarget, itemString);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -722,13 +746,6 @@ void PlugIn::updateInbound(EuroScopePlugIn::CRadarTarget& radarTarget) {
|
||||
it->second.update(radarTarget);
|
||||
}
|
||||
|
||||
void PlugIn::updateInbound(EuroScopePlugIn::CFlightPlan& plan) {
|
||||
std::lock_guard guard(this->m_inboundsQueueLock);
|
||||
auto it = this->m_inbounds.find(plan.GetCorrelatedRadarTarget().GetCallsign());
|
||||
if (this->m_inbounds.end() != it)
|
||||
it->second.update(plan);
|
||||
}
|
||||
|
||||
void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarget) {
|
||||
/* do nothing if the reporter is not initialized and ignore invalid targets */
|
||||
if (false == this->m_compatible || false == Backend::instance().initialized() || false == radarTarget.IsValid())
|
||||
@@ -746,14 +763,18 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
|
||||
}
|
||||
|
||||
void PlugIn::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn::CFlightPlan flightPlan, int type) {
|
||||
/* handle only relevant changes */
|
||||
if (EuroScopePlugIn::CTR_DATA_TYPE_HEADING != type && EuroScopePlugIn::CTR_DATA_TYPE_DIRECT_TO != type)
|
||||
auto radarTarget = flightPlan.GetCorrelatedRadarTarget();
|
||||
|
||||
if (EuroScopePlugIn::CTR_DATA_TYPE_DIRECT_TO != type || false == radarTarget.IsValid())
|
||||
return;
|
||||
|
||||
if (false == flightPlan.GetCorrelatedRadarTarget().IsValid())
|
||||
return;
|
||||
|
||||
this->updateInbound(flightPlan);
|
||||
std::string waypoint(flightPlan.GetControllerAssignedData().GetDirectToPointName());
|
||||
if (0 != waypoint.length()) {
|
||||
std::lock_guard guard(this->m_inboundsQueueLock);
|
||||
auto it = this->m_inbounds.find(flightPlan.GetCorrelatedRadarTarget().GetCallsign());
|
||||
if (this->m_inbounds.end() != it)
|
||||
it->second.directTo(radarTarget, waypoint);
|
||||
}
|
||||
}
|
||||
|
||||
void PlugIn::OnFlightPlanDisconnect(EuroScopePlugIn::CFlightPlan flightPlan) {
|
||||
|
||||
Reference in New Issue
Block a user