1 // AirportDiagram.hxx - part of GUI launcher using Qt5 2 // 3 // Written by James Turner, started December 2014. 4 // 5 // Copyright (C) 2014 James Turner <zakalawe@mac.com> 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License as 9 // published by the Free Software Foundation; either version 2 of the 10 // License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, but 13 // WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 // General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program; if not, write to the Free Software 19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 21 #ifndef GUI_AIRPORT_DIAGRAM_HXX 22 #define GUI_AIRPORT_DIAGRAM_HXX 23 24 #include "BaseDiagram.hxx" 25 26 #include <QPixmap> 27 28 #include "UnitsModel.hxx" 29 30 #include <Airports/parking.hxx> 31 #include <Airports/runways.hxx> 32 #include <simgear/math/sg_geodesy.hxx> 33 34 // forward decls 35 class QmlPositioned; 36 37 class AirportDiagram : public BaseDiagram 38 { 39 Q_OBJECT 40 41 Q_PROPERTY(QmlPositioned* selection READ selection WRITE setSelection NOTIFY selectionChanged) 42 Q_PROPERTY(qlonglong airport READ airportGuid WRITE setAirportGuid NOTIFY airportChanged) 43 44 Q_PROPERTY(bool approachExtensionEnabled READ approachExtensionEnabled WRITE setApproachExtensionEnabled NOTIFY approachExtensionChanged) 45 Q_PROPERTY(QuantityValue approachExtension READ approachExtension WRITE setApproachExtension NOTIFY approachExtensionChanged) 46 public: 47 AirportDiagram(QQuickItem* pr = nullptr); 48 virtual ~AirportDiagram(); 49 50 void setAirport(FGAirportRef apt); 51 52 void addRunway(FGRunwayRef rwy); 53 void addParking(FGParkingRef park); 54 void addHelipad(FGHelipadRef pad); 55 56 QmlPositioned* selection() const; 57 58 void setSelection(QmlPositioned* pos); 59 60 void setApproachExtension(QuantityValue distance); 61 QuantityValue approachExtension() const; 62 63 qlonglong airportGuid() const; 64 void setAirportGuid(qlonglong guid); 65 approachExtensionEnabled() const66 bool approachExtensionEnabled() const 67 { 68 return m_approachExtensionEnabled; 69 } 70 71 void setApproachExtensionEnabled(bool e); 72 Q_SIGNALS: 73 void clicked(QmlPositioned* pos); 74 75 void selectionChanged(); 76 void airportChanged(); 77 void approachExtensionChanged(); 78 79 protected: 80 81 void mouseReleaseEvent(QMouseEvent* me) override; 82 83 void paintContents(QPainter*) override; 84 85 void doComputeBounds() override; 86 private: 87 struct RunwayData { 88 QPointF p1, p2; 89 int widthM; 90 FGRunwayRef runway; 91 }; 92 93 struct TaxiwayData { 94 QPointF p1, p2; 95 int widthM; 96 operator <AirportDiagram::TaxiwayData97 bool operator<(const TaxiwayData& other) const 98 { 99 return widthM < other.widthM; 100 } 101 }; 102 103 struct ParkingData 104 { 105 QPointF pt; 106 FGParkingRef parking; 107 }; 108 109 struct HelipadData 110 { 111 QPointF pt; 112 FGHelipadRef helipad; 113 }; 114 115 void buildTaxiways(); 116 void buildPavements(); 117 118 void drawILS(QPainter *painter, FGRunwayRef runway) const; 119 120 void drawParkings(QPainter *p) const; 121 void drawParking(QPainter *painter, const ParkingData &p) const; 122 123 ParkingData findParkingData(const FGParkingRef& pk) const; 124 125 void drawHelipads(QPainter *painter); 126 127 QPainterPath pathForRunway(const RunwayData &r, const QTransform &t, const double minWidth) const; 128 QPainterPath pathForHelipad(const HelipadData &h, const QTransform &t) const; 129 QPainterPath pathForParking(const ParkingData &p, const QTransform &t) const; 130 131 private: 132 FGAirportRef m_airport; 133 134 QVector<RunwayData> m_runways; 135 QVector<TaxiwayData> m_taxiways; 136 QVector<QPainterPath> m_pavements; 137 QVector<ParkingData> m_parking; 138 QVector<HelipadData> m_helipads; 139 140 QPainterPath m_parkingIconPath, // arrow points right 141 m_parkingIconLeftPath; // arrow points left 142 QuantityValue m_approachDistance; 143 bool m_approachExtensionEnabled = false; 144 145 QPainterPath m_helipadIconPath, m_helipadBoundsPath; 146 FGPositionedRef m_selection; 147 }; 148 149 #endif // of GUI_AIRPORT_DIAGRAM_HXX 150