Skip to content

Commit

Permalink
Fixed procedure drawing for course/heading to radial termination legs.
Browse files Browse the repository at this point in the history
Changed drawing order of highlight circles to top.
Added debug painting for procedure legs.
closes #406
  • Loading branch information
albar965 committed Aug 16, 2019
1 parent 74410e2 commit 07acc6b
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 16 deletions.
13 changes: 13 additions & 0 deletions src/mappainter/mappainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ void MapPainter::drawCircle(const PaintContext *context, const atools::geo::Pos&
context->painter->drawEllipse(pt, radius, radius);
}

void MapPainter::drawText(const PaintContext *context, const Pos& pos, const QString& text, bool topCorner,
bool leftCorner)
{
QPoint pt = wToS(pos);
if(!pt.isNull())
{
QFontMetrics metrics = context->painter->fontMetrics();
pt.setX(leftCorner ? pt.x() : pt.x() - metrics.width(text));
pt.setY(topCorner ? pt.y() + metrics.ascent() : pt.y() - metrics.descent());
context->painter->drawText(pt, text);
}
}

void MapPainter::drawCross(const PaintContext *context, int x, int y, int size)
{
context->painter->drawLine(x, y - size, x, y + size);
Expand Down
4 changes: 4 additions & 0 deletions src/mappainter/mappainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class MapPainter :
void drawLine(const PaintContext *context, const atools::geo::Line& line);
void drawCircle(const PaintContext *context, const atools::geo::Pos& center, int radius);

/* Draw simple text with current settings. Corners are the text corners pointing to the position */
void drawText(const PaintContext *context, const atools::geo::Pos& pos, const QString& text, bool topCorner,
bool leftCorner);

void drawCross(const PaintContext *context, int x, int y, int size);

/* No GC and no rhumb */
Expand Down
8 changes: 4 additions & 4 deletions src/mappainter/mappaintermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void MapPainterMark::render(PaintContext *context)

map::MapMarkTypes types = NavApp::getMapMarkHandler()->getMarkTypes();

paintHighlights(context);

paintMark(context);
paintHome(context);

Expand All @@ -88,6 +86,8 @@ void MapPainterMark::render(PaintContext *context)

paintCompassRose(context);

paintHighlights(context);

paintRouteDrag(context);
paintUserpointDrag(context);
}
Expand Down Expand Up @@ -270,7 +270,7 @@ void MapPainterMark::paintHighlights(PaintContext *context)
{
if(wToS(leg.procedureTurnPos, x, y))
{
// Draw turn position of the procedur turn
// Draw turn position of the procedure turn
if(!context->drawFast)
{
painter->setPen(QPen(mapcolors::highlightBackColor, size / 3 + 2));
Expand All @@ -282,10 +282,10 @@ void MapPainterMark::paintHighlights(PaintContext *context)
}
}

// Draw hightlights from the flight plan view =====================================================
if(context->mapLayerEffective->isAirport())
size = std::max(size, context->mapLayerEffective->getAirportSymbolSize());

// Draw hightlights from the flight plan view =====================================================
const QList<int>& routeHighlightResults = mapPaintWidget->getRouteHighlights();
positions.clear();
for(int idx : routeHighlightResults)
Expand Down
8 changes: 5 additions & 3 deletions src/mappainter/mappainterroute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void MapPainterRoute::paintProcedure(proc::MapProcedureLeg& lastLegPoint, const
{
// Do not draw background for passed legs but calculate lastLine
bool draw = (i >= passedProcLeg) || !activeValid || preview;
if(legs.at(i).isCircleToLand() || legs.at(i).isStraightIn() || legs.at(i).isVectors()|| legs.at(i).isManual())
if(legs.at(i).isCircleToLand() || legs.at(i).isStraightIn() || legs.at(i).isVectors() || legs.at(i).isManual())
// Do not draw outline for circle-to-land approach legs
draw = false;

Expand Down Expand Up @@ -743,13 +743,15 @@ void MapPainterRoute::paintProcedureSegment(const PaintContext *context, const p
proc::HEADING_TO_ALTITUDE_TERMINATION,
proc::HEADING_TO_MANUAL_TERMINATION,
proc::COURSE_TO_INTERCEPT,
proc::HEADING_TO_INTERCEPT}))
proc::HEADING_TO_INTERCEPT,
proc::COURSE_TO_RADIAL_TERMINATION,
proc::HEADING_TO_RADIAL_TERMINATION}))
{
if(contains(leg.turnDirection, {"R", "L"}) &&
prevLeg != nullptr && prevLeg->type != proc::INITIAL_FIX && prevLeg->type != proc::START_OF_PROCEDURE)
{
float lineDist = static_cast<float>(QLineF(lastLines.last().p2(), line.p1()).length());
if(!lastLines.last().p2().isNull() && lineDist > 2)
if(!lastLines.last().p2().isNull() && lineDist > 2.f)
{
// Lines are not connected which can happen if a CF follows after a FD or similar
paintProcedureBow(prevLeg, lastLines, painter, line, leg, intersectPoint, draw);
Expand Down
55 changes: 55 additions & 0 deletions src/mappainter/mappaintertop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#include "navapp.h"
#include "util/paintercontextsaver.h"

#ifdef DEBUG_INFORMATION
#include "common/proctypes.h"
#include "mapgui/mappaintwidget.h"
#endif

#include <marble/GeoPainter.h>

MapPainterTop::MapPainterTop(MapPaintWidget *mapWidgetParam, MapScale *mapScale)
Expand Down Expand Up @@ -86,6 +91,56 @@ void MapPainterTop::render(PaintContext *context)
drawTouchIcons(context, std::max(std::min(iconSize, 30), 10));
}
}

#ifdef DEBUG_INFORMATION
{
const proc::MapProcedureLeg& leg = mapPaintWidget->getProcedureLegHighlights();
atools::util::PainterContextSaver saver(context->painter);
painter->setBrush(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode);
painter->setBackground(Qt::black);

if(leg.geometry.isValid())
{
painter->setPen(QPen(Qt::red, 6));
drawLineString(context, leg.geometry);
}
if(leg.line.isValid())
{
painter->setPen(QPen(Qt::yellow, 3));
drawLine(context, leg.line);
drawText(context, leg.line.getPos1(), "P1", false, false);
drawText(context, leg.line.getPos2(), QString("P2,%1°,%2nm").
arg(leg.course, 0, 'f', 1).arg(leg.distance, 0, 'f', 1), false, false);

}
if(leg.holdLine.isValid())
{
painter->setPen(QPen(Qt::blue, 3));
drawLine(context, leg.line);
}
if(leg.procedureTurnPos.isValid())
{
painter->setPen(QPen(Qt::blue, 2));
drawText(context, leg.procedureTurnPos, "PTFIX", false, false);
}
if(leg.interceptPos.isValid())
{
painter->setPen(QPen(Qt::yellow, 2));
drawText(context, leg.interceptPos, "ICPT", true, false);
}
if(leg.recFixPos.isValid())
{
painter->setPen(QPen(Qt::lightGray, 2));
drawText(context, leg.recFixPos, leg.recFixIdent.isEmpty() ? "RECFIX" : leg.recFixIdent, false, true);
}
if(leg.fixPos.isValid())
{
painter->setPen(QPen(Qt::white, 2));
drawText(context, leg.fixPos, leg.fixIdent.isEmpty() ? "FIX" : leg.fixIdent, true, true);
}
}
#endif
}

void MapPainterTop::paintCopyright(PaintContext *context)
Expand Down
53 changes: 44 additions & 9 deletions src/query/procedurequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,8 @@ void ProcedureQuery::processLegs(proc::MapProcedureLegs& legs)

// Check if this is a reversal maneuver which should be connected with a bow instead of an intercept
// Always intercept if course could not be calculated (e.g. first procedure leg)
if(courseDiff < 130. || !(courseDiff < map::INVALID_COURSE_VALUE))
// Everthing bigger than 150 degree is considered a reversal - draw bow instead of intercept
if(courseDiff < 150. || !(courseDiff < map::INVALID_COURSE_VALUE))
{
// Try left or right intercept
Pos intr1 = Pos::intersectingRadials(extended, legCourse, lastPos, legCourse - 45.f).normalize();
Expand Down Expand Up @@ -1426,23 +1427,57 @@ void ProcedureQuery::processLegs(proc::MapProcedureLegs& legs)
// ===========================================================
else if(contains(type, {proc::COURSE_TO_RADIAL_TERMINATION, proc::HEADING_TO_RADIAL_TERMINATION}))
{
Pos start = lastPos.isValid() ? lastPos : leg.fixPos;
if(!lastPos.isValid())
lastPos = start;
// Distance to recommended fix for radial
float distToRecMeter = lastPos.distanceMeterTo(leg.recFixPos);

// Create a course line from start position with the given course
Line crsLine(lastPos, distToRecMeter * 10.f, leg.legTrueCourse());

// Create base distance for parallel line after turn to leg course
float parallelDist = 0.f;
if(leg.turnDirection == "L")
parallelDist = nmToMeter(2.f);
else if(leg.turnDirection == "R")
parallelDist = nmToMeter(-2.f);

// Now create parallel lines based on the course line until a valid intersection with the radial can be found
// Move parallel one step away from course line and lengthen parallel a bit for each iteration
Pos intersect;
Line parallel;
bool valid = false;
float ext = 0.f;
for(int j = 0; j < 5; j++)
{
parallel = crsLine.parallel(parallelDist).extended(ext, ext);
intersect = Pos::intersectingRadials(parallel.getPos1(), parallel.angleDeg(),
leg.recFixPos, leg.theta + leg.magvar);

Pos center = leg.recFixPos.isValid() ? leg.recFixPos : leg.fixPos;
// Need maximum of 200 NM and minimum of 1.5 NM distance to the navaid from the intersection point
if(intersect.isValid() && intersect.distanceMeterTo(leg.recFixPos) < nmToMeter(200.f) &&
intersect.distanceMeterTo(leg.recFixPos) > nmToMeter(1.5f))
{
valid = true;
break;
}
// Move away from base
parallelDist *= 1.2f;

Pos intersect = Pos::intersectingRadials(start, leg.legTrueCourse(), center, leg.theta + leg.magvar);
// Make half a NM longer
ext += 0.5f;
}

if(intersect.isValid() && intersect.distanceMeterTo(start) < nmToMeter(200.f))
if(valid)
{
lastPos = parallel.getPos1();
curPos = intersect;
leg.displayText << leg.recFixIdent + "/" + QLocale().toString(leg.theta, 'f', 0) + tr("°M");
}
else
{
curPos = center;
curPos = lastPos;
qWarning() << "leg line type" << type << "fix" << leg.fixIdent << "no intersectingRadials found"
<< "approachId" << leg.approachId << "transitionId" << leg.transitionId << "legId" << leg.legId;
}
leg.displayText << leg.recFixIdent + "/" + QLocale().toString(leg.theta, 'f', 0);
}
// ===========================================================
else if(type == proc::TRACK_FROM_FIX_FROM_DISTANCE)
Expand Down

0 comments on commit 07acc6b

Please sign in to comment.