Skip to content

Commit

Permalink
Add new tag item sources: assignedStar and estimatedLandingTime (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenAR committed Jun 14, 2021
1 parent 867a17e commit 53d2e9b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
8 changes: 5 additions & 3 deletions Aman/AmanAircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AmanAircraft {
std::string callsign;
std::string finalFix;
std::string arrivalRunway;
std::string assignedStar;
std::string icaoType;
std::string nextFix;
std::string scratchPad;
Expand All @@ -16,11 +17,12 @@ class AmanAircraft {
bool trackedByMe;
bool isSelected;
char wtc;
int eta;
uint32_t targetFixEta;
uint32_t destinationEta;
double distLeft;
int secondsBehindPreceeding;
uint32_t secondsBehindPreceeding;

bool operator< (const AmanAircraft& other) const {
return eta < other.eta;
return targetFixEta < other.targetFixEta;
}
};
20 changes: 12 additions & 8 deletions Aman/AmanPlugIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixNa

int targetFixIndex = getFixIndexByName(route, fixName);

if (targetFixIndex != -1 && // Target fix found
if (targetFixIndex > -1 && // Target fix found
route.GetPointDistanceInMinutes(targetFixIndex) > -1 && // Target fix has not been passed
hasCorrectDestination(rt.GetCorrelatedFlightPlan().GetFlightPlanData(), destinationAirports)) { // Aircraft going to the correct destination
bool fixIsDestination = targetFixIndex == route.GetPointsNumber() - 1;

bool targetFixIsDestination = targetFixIndex == route.GetPointsNumber() - 1;
int timeToFix;

if (fixIsDestination) {
float restDistance = predictions.GetPosition(predictions.GetPointsNumber() - 1)
.DistanceTo(route.GetPointPosition(targetFixIndex));
timeToFix = (predictions.GetPointsNumber() - 1) * 60 + (restDistance / groundSpeed) * 60.0 * 60.0;
float restDistance = predictions.GetPosition(predictions.GetPointsNumber() - 1).DistanceTo(route.GetPointPosition(targetFixIndex));
int timeToDestination = (predictions.GetPointsNumber() - 1) * 60 + (restDistance / groundSpeed) * 60.0 * 60.0;

if (targetFixIsDestination) {
timeToFix = timeToDestination;
} else {
// Find the two position prediction points closest to the target point
float min1dist = INFINITE;
Expand Down Expand Up @@ -106,13 +108,15 @@ std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixNa
ac.callsign = rt.GetCallsign();
ac.finalFix = fixName;
ac.arrivalRunway = rt.GetCorrelatedFlightPlan().GetFlightPlanData().GetArrivalRwy();
ac.assignedStar = rt.GetCorrelatedFlightPlan().GetFlightPlanData().GetStarName();
ac.icaoType = rt.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftFPType();
ac.nextFix = rt.GetCorrelatedFlightPlan().GetControllerAssignedData().GetDirectToPointName();
ac.viaFixIndex = getFirstViaFixIndex(route, viaFixes);
ac.trackedByMe = rt.GetCorrelatedFlightPlan().GetTrackingControllerIsMe();
ac.isSelected = isSelectedAircraft;
ac.wtc = rt.GetCorrelatedFlightPlan().GetFlightPlanData().GetAircraftWtc();
ac.eta = timeNow + timeToFix - rt.GetPosition().GetReceivedTime();
ac.targetFixEta = timeNow + timeToFix - rt.GetPosition().GetReceivedTime();
ac.destinationEta = timeNow + timeToDestination - rt.GetPosition().GetReceivedTime();
ac.distLeft = findRemainingDist(rt, route, targetFixIndex);
ac.secondsBehindPreceeding = 0; // Updated in the for-loop below
ac.scratchPad = rt.GetCorrelatedFlightPlan().GetControllerAssignedData().GetScratchPadString();
Expand All @@ -127,7 +131,7 @@ std::vector<AmanAircraft> AmanPlugIn::getInboundsForFix(const std::string& fixNa
auto curr = &aircraftList[i];
auto next = &aircraftList[i + 1];

curr->secondsBehindPreceeding = curr->eta - next->eta;
curr->secondsBehindPreceeding = curr->targetFixEta - next->targetFixEta;
}
}

Expand Down
38 changes: 21 additions & 17 deletions Aman/AmanTimelineView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ CRect AmanTimelineView::render(HDC hdc, std::shared_ptr<AmanTimeline> timeline,
*timeline->getAircraftList(), timeline->getTagItems());
}

// Draw the fix id
// Draw the timeline identifier
COLORREF oldBackgroundColor = SetBkColor(hdc, AMAN_COLOR_FIX_BACKGROUND);
SetBkMode(hdc, OPAQUE);
int oldBkMode = SetBkMode(hdc, OPAQUE);
SetTextColor(hdc, AMAN_COLOR_FIX_TEXT);
SelectObject(hdc, AMAN_FIX_FONT);
CRect rect = { timelineStartX - AMAN_RULER_WITDH, myTotalArea.bottom - 20,
Expand Down Expand Up @@ -161,7 +161,7 @@ void AmanTimelineView::drawAircraftChain(HDC hdc, int timeNow, int xStart, int y

for (int ac = 0; ac < aircraftList.size(); ac++) {
AmanAircraft aircraft = aircraftList.at(ac);
int acPosY = yStart - (aircraft.eta - timeNow) * pixelsPerSec;
int acPosY = yStart - (aircraft.targetFixEta - timeNow) * pixelsPerSec;

COLORREF defaultColor = aircraft.trackedByMe ? AMAN_COLOR_TRACKED : AMAN_COLOR_UNTRACKED;
HBRUSH brush = aircraft.trackedByMe ? AMAN_TRACKED_BRUSH : AMAN_UNTRACKED_BRUSH;
Expand Down Expand Up @@ -249,24 +249,26 @@ CRect AmanTimelineView::drawMultiColorText(HDC hdc, CPoint pt, std::vector<TextS
}

void AmanTimelineView::drawViafixColorLegend(HDC hdc, std::shared_ptr<AmanTimeline> timeline, CPoint position) {
if (!timeline->getViaFixes().empty()) {
SelectObject(hdc, AMAN_LEGEND_FONT);
CRect startRect;
startRect.MoveToXY(position);
SelectObject(hdc, AMAN_LEGEND_FONT);

if (!timeline->getViaFixes().empty()) {
std::vector<TextSegment> textSegments;
for (int i = 0; i < timeline->getViaFixes().size(); i++) {
auto viafix = " " + timeline->getViaFixes().at(i) + " ";
DrawText(hdc, viafix.c_str(), viafix.length(), &startRect, DT_LEFT | DT_CALCRECT);
DrawText(hdc, viafix.c_str(), viafix.length(), &startRect, DT_LEFT);
SelectObject(hdc, VIA_FIX_PENS[i]);
MoveToEx(hdc, startRect.left + 5, startRect.top + 3, NULL);
LineTo(hdc, startRect.left + 5, startRect.bottom - 5);
startRect.MoveToY(startRect.bottom);
textSegments.push_back({5, false, VIA_FIX_COLORS[i], timeline->getViaFixes().at(i) });
}
drawMultiColorText(hdc, position, textSegments, true);
}
}

std::string AmanTimelineView::formatTime(uint32_t totalSeconds, bool minutesOnly = false) {
std::string AmanTimelineView::formatTimestamp(uint32_t unixTime, const char* format) {
std::time_t temp = unixTime;
std::tm* t = std::gmtime(&temp);
static std::stringstream ss;
ss << std::put_time(t, format);
return ss.str();
}

std::string AmanTimelineView::formatMinutes(uint32_t totalSeconds, bool minutesOnly = false) {
if (minutesOnly) {
int minutesRounded = round((float)totalSeconds / 60.0f);
return std::to_string(minutesRounded);
Expand Down Expand Up @@ -294,11 +296,13 @@ std::vector<AmanTimelineView::TextSegment> AmanTimelineView::generateLabel(AmanA

if (sourceId == "callsign") displayValue = aircraft.callsign;
else if (sourceId == "assignedRunway") displayValue = aircraft.arrivalRunway;
else if (sourceId == "assignedStar") displayValue = aircraft.assignedStar;
else if (sourceId == "aircraftType") displayValue = aircraft.icaoType;
else if (sourceId == "aircraftWtc") displayValue = { aircraft.wtc };
else if (sourceId == "minutesBehindPreceedingRounded") displayValue = timeRelevant ? formatTime(aircraft.secondsBehindPreceeding, true) : "";
else if (sourceId == "timeBehindPreceeding") displayValue = timeRelevant ? formatTime(aircraft.secondsBehindPreceeding) : "";
else if (sourceId == "minutesBehindPreceedingRounded") displayValue = timeRelevant ? formatMinutes(aircraft.secondsBehindPreceeding, true) : "";
else if (sourceId == "timeBehindPreceeding") displayValue = timeRelevant ? formatMinutes(aircraft.secondsBehindPreceeding) : "";
else if (sourceId == "remainingDistance") displayValue = std::to_string(remainingDistance);
else if (sourceId == "estimatedLandingTime") displayValue = formatTimestamp(aircraft.destinationEta, "%H:%M");
else if (sourceId == "directRouting") displayValue = aircraft.nextFix.size() > 0 ? aircraft.nextFix : tagItem->getDefaultValue();
else if (sourceId == "scratchPad") displayValue = aircraft.scratchPad;
else if (sourceId == "static") displayValue = tagItem->getDefaultValue();
Expand Down
3 changes: 2 additions & 1 deletion Aman/AmanTimelineView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ class AmanTimelineView {
static CRect drawMultiColorText(HDC hdc, CPoint pt, std::vector<TextSegment> texts, bool vertical = false);
static void drawViafixColorLegend(HDC hdc, std::shared_ptr<AmanTimeline> timeline, CPoint position);
static std::vector<TextSegment> generateLabel(AmanAircraft aircraft, std::vector<std::shared_ptr<TagItem>> tagItems, COLORREF defaultColor);
static std::string formatTime(uint32_t totalSeconds, bool minutesOnly);
static std::string formatMinutes(uint32_t totalSeconds, bool minutesOnly);
static std::string formatTimestamp(uint32_t unixTime, const char* format);
};

0 comments on commit 53d2e9b

Please sign in to comment.