From: James Turner Date: Fri, 6 Nov 2015 05:47:49 +0000 (-0500) Subject: Navaid diagram work X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=adedf7af65171dac0ffeaeb814e026210ab6bff3;p=flightgear.git Navaid diagram work --- diff --git a/src/GUI/AirportDiagram.cxx b/src/GUI/AirportDiagram.cxx index ab9236034..a800bf1e2 100644 --- a/src/GUI/AirportDiagram.cxx +++ b/src/GUI/AirportDiagram.cxx @@ -182,14 +182,7 @@ void AirportDiagram::addParking(FGParkingRef park) void AirportDiagram::paintContents(QPainter* p) { - // fit bounds within our available space, allowing for a margin -// const int MARGIN = 32; // pixels - // double ratioInX = (width() - MARGIN * 2) / m_bounds.width(); - // double ratioInY = (height() - MARGIN * 2) / m_bounds.height(); - // double scale = std::min(ratioInX, ratioInY); - - QTransform t(transform()); - p->setTransform(t); + QTransform t = p->transform(); // pavements QBrush brush(QColor(0x9f, 0x9f, 0x9f)); diff --git a/src/GUI/BaseDiagram.cxx b/src/GUI/BaseDiagram.cxx index b1e114c07..ddc59f0ad 100644 --- a/src/GUI/BaseDiagram.cxx +++ b/src/GUI/BaseDiagram.cxx @@ -113,6 +113,9 @@ void BaseDiagram::wheelEvent(QWheelEvent *we) m_autoScalePan = false; int delta = we->angleDelta().y(); + if (delta == 0) + return; + if (intSign(m_wheelAngleDeltaAccumulator) != intSign(delta)) { m_wheelAngleDeltaAccumulator = 0; } @@ -121,7 +124,7 @@ void BaseDiagram::wheelEvent(QWheelEvent *we) if (m_wheelAngleDeltaAccumulator > 120) { m_wheelAngleDeltaAccumulator = 0; m_scale *= 2.0; - } else if (m_wheelAngleDeltaAccumulator < 120) { + } else if (m_wheelAngleDeltaAccumulator < -120) { m_wheelAngleDeltaAccumulator = 0; m_scale *= 0.5; } diff --git a/src/GUI/NavaidDiagram.cxx b/src/GUI/NavaidDiagram.cxx index a913c7df8..b31e881cd 100644 --- a/src/GUI/NavaidDiagram.cxx +++ b/src/GUI/NavaidDiagram.cxx @@ -41,12 +41,71 @@ void NavaidDiagram::setNavaid(FGPositionedRef nav) { m_navaid = nav; m_projectionCenter = nav ? nav->geod() : SGGeod(); - m_scale = 1.0; - m_bounds = QRectF(); // clear + m_geod = nav->geod(); + recomputeBounds(true); +} + +void NavaidDiagram::setGeod(const SGGeod &geod) +{ + m_navaid.clear(); + m_geod = geod; + m_projectionCenter = m_geod; + recomputeBounds(true); +} + +void NavaidDiagram::setOffsetEnabled(bool offset) +{ + if (m_offsetEnabled == offset) + return; + m_offsetEnabled = offset; + recomputeBounds(true); +} + +void NavaidDiagram::setOffsetDistanceNm(double distanceNm) +{ + m_offsetDistanceNm = distanceNm; update(); } -void NavaidDiagram::paintContents(QPainter *) +void NavaidDiagram::setOffsetBearingDeg(int bearingDeg) { + m_offsetBearingDeg = bearingDeg; + update(); +} + +void NavaidDiagram::paintContents(QPainter *painter) +{ + QPointF base = project(m_geod); + + if (m_offsetEnabled) { + double d = m_offsetDistanceNm * SG_NM_TO_METER; + SGGeod offsetGeod = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d); + QPointF offset = project(offsetGeod); + + qDebug() << base << offset; + + QPen pen(Qt::green); + pen.setCosmetic(true); + painter->setPen(pen); + painter->drawLine(base, offset); + } +} + +void NavaidDiagram::doComputeBounds() +{ + extendBounds(project(m_geod)); + +// project three points around the base location at 40nm to give some +// coverage + for (int i=0; i<3; ++i) { + SGGeod pt = SGGeodesy::direct(m_geod, i * 120, SG_NM_TO_METER * 40.0); + extendBounds(project(pt)); + } + + if (m_offsetEnabled) { + double d = m_offsetDistanceNm * SG_NM_TO_METER; + SGGeod offsetPos = SGGeodesy::direct(m_geod, m_offsetBearingDeg, d); + extendBounds(project(offsetPos)); + } } diff --git a/src/GUI/NavaidDiagram.hxx b/src/GUI/NavaidDiagram.hxx index 32c75b176..dd22c6b57 100644 --- a/src/GUI/NavaidDiagram.hxx +++ b/src/GUI/NavaidDiagram.hxx @@ -35,8 +35,10 @@ public: void setNavaid(FGPositionedRef nav); + void setGeod(const SGGeod& geod); + bool isOffsetEnabled() const; - void setOffsetEnabled(bool m_offset); + void setOffsetEnabled(bool offset); void setOffsetDistanceNm(double distanceNm); double offsetDistanceNm() const; @@ -49,8 +51,10 @@ public: protected: void paintContents(QPainter *) Q_DECL_OVERRIDE; + void doComputeBounds() Q_DECL_OVERRIDE; private: FGPositionedRef m_navaid; + SGGeod m_geod; bool m_offsetEnabled; double m_offsetDistanceNm;