]> git.mxchange.org Git - flightgear.git/blob - src/GUI/MapWidget.hxx
Aircraft path support in the Qt launcher
[flightgear.git] / src / GUI / MapWidget.hxx
1 #ifndef GUI_MAPWIDGET_HXX
2 #define GUI_MAPWIDGET_HXX
3
4 #include <map>
5 #include <simgear/compiler.h>
6 #include <simgear/math/SGMath.hxx>
7 #include <simgear/props/props.hxx>
8
9 #include <Navaids/positioned.hxx>
10 #include <plib/pu.h>
11
12 #include "FGPUIDialog.hxx"
13
14 // forward decls
15 class FGRouteMgr;
16 class FGRunway;
17 class FGHelipad;
18 class FGAirport;
19 class FGNavRecord;
20 class FGFix;
21 class MapData;
22 class SGMagVar;
23
24 typedef std::vector<SGGeod> SGGeodVec;
25
26 class MapWidget : public puObject, public FGPUIDialog::ActiveWidget
27 {
28 public:
29   MapWidget(int x, int y, int width, int height);
30   virtual ~MapWidget();
31   
32     // puObject over-rides
33   virtual void setSize(int width, int height);
34   virtual void doHit( int button, int updown, int x, int y ) ;
35   virtual void draw( int dx, int dy ) ;
36   virtual int checkKey(int key, int updown);
37     
38   void setProperty(SGPropertyNode_ptr prop);
39     
40     // PUIDialog::ActiveWidget over-rides
41     virtual void update();
42     
43 private:
44     enum Projection {
45         PROJECTION_SAMSON_FLAMSTEED,
46         PROJECTION_AZIMUTHAL_EQUIDISTANT,
47         PROJECTION_ORTHO_AZIMUTH,
48         PROJECTION_SPHERICAL
49     };
50     
51   int zoom() const;
52   
53   void handlePan(int x, int y);
54   
55   void pan(const SGVec2d& delta);
56   void zoomIn();
57   void zoomOut();
58   
59   void paintAircraftLocation(const SGGeod& aircraftPos);
60   void paintRoute();
61   void paintRuler();
62   void drawFlightHistory();
63   
64   void drawGPSData();
65   void drawNavRadio(SGPropertyNode_ptr radio);
66   void drawTunedLocalizer(SGPropertyNode_ptr radio);
67   
68   void drawLatLonGrid();
69   SGVec2d gridPoint(int ix, int iy);
70   bool drawLineClipped(const SGVec2d& a, const SGVec2d& b);
71   
72   void drawAirport(FGAirport* apt);
73   int scoreAirportRunways(FGAirport* apt);
74   void drawRunwayPre(FGRunway* rwy);
75   void drawRunway(FGRunway* rwy);
76   void drawHelipad(FGHelipad* hp);
77   void drawILS(bool tuned, FGRunway* rwy);
78   
79   void drawPositioned();
80   void drawNDB(bool tuned, FGNavRecord* nav);
81   void drawVOR(bool tuned, FGNavRecord* nav);
82   void drawFix(FGFix* fix);
83
84   void drawPOI(FGPositioned* rec);
85     
86   void drawTraffic();
87     
88     class DrawAIObject
89     {
90     public:
91         DrawAIObject(SGPropertyNode* model, const SGGeod& g);
92         
93         SGPropertyNode* model;
94         bool boat;
95         SGGeod pos;
96         double heading;
97         int speedKts;
98         std::string label;
99         std::string legend;
100     };
101     
102     typedef std::vector<DrawAIObject> AIDrawVec;
103     AIDrawVec _aiDrawVec;
104     
105     void updateAIObjects();
106     void drawAI(const DrawAIObject& dai);
107   
108   void drawData();
109   bool validDataForKey(void* key);
110   MapData* getOrCreateDataForKey(void* key);
111   MapData* createDataForKey(void* key);
112   void setAnchorForKey(void* key, const SGVec2d& anchor);
113   void clearData();
114   
115   SGVec2d project(const SGGeod& geod) const;
116   SGGeod unproject(const SGVec2d& p) const;
117   double currentScale() const;
118   
119   int displayHeading(double trueHeading) const;
120   
121   void circleAt(const SGVec2d& center, int nSides, double r);
122   void circleAtAlt(const SGVec2d& center, int nSides, double r, double r2);
123   void squareAt(const SGVec2d& center, double r);
124   void drawLine(const SGVec2d& p1, const SGVec2d& p2);
125   void drawLegendBox(const SGVec2d& pos, const std::string& t);
126   
127   int _width, _height;
128   int _cachedZoom;
129   double _drawRangeNm;
130   double _upHeading; // true heading corresponding to +ve y-axis
131   bool _magneticHeadings;
132   bool _hasPanned;
133   bool _aircraftUp;
134   int _displayHeading;
135     
136   SGGeod _projectionCenter;
137   Projection _projection;
138   SGGeod _aircraft;
139   SGGeod _clickGeod;
140   SGVec2d _hitLocation;
141   FGRouteMgr* _route;
142   SGPropertyNode_ptr _root;
143   SGPropertyNode_ptr _gps;
144   SGGeodVec _flightHistoryPath;
145     
146   FGPositionedList _itemsToDraw;
147     
148   typedef std::map<void*, MapData*> KeyDataMap;
149   KeyDataMap _mapData;
150   std::vector<MapData*> _dataQueue;
151   
152   SGMagVar* _magVar;
153   
154   typedef std::map<int, SGVec2d> GridPointCache;
155   GridPointCache _gridCache;
156   double _gridSpacing;
157   SGGeod _gridCenter;
158 };
159
160 #endif // of GUI_MAPWIDGET_HXX