]> git.mxchange.org Git - flightgear.git/blob - src/GUI/MapWidget.hxx
Support for multiple data dirs.
[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 <plib/pu.h>
10
11 #include "dialog.hxx" // for GUI_ID
12
13 // forward decls
14 class FGRouteMgr;
15 class FGRunway;
16 class FGHelipad;
17 class FGAirport;
18 class FGNavRecord;
19 class FGFix;
20 class MapData;
21 class SGMagVar;
22
23 class MapWidget : public puObject
24 {
25 public:
26   MapWidget(int x, int y, int width, int height);
27   virtual ~MapWidget();
28   
29   virtual void setSize(int width, int height);
30   virtual void doHit( int button, int updown, int x, int y ) ;
31   virtual void draw( int dx, int dy ) ;
32   virtual int checkKey(int key, int updown);
33     
34   void setProperty(SGPropertyNode_ptr prop);
35 private:
36     enum Projection {
37         PROJECTION_SAMSON_FLAMSTEED,
38         PROJECTION_ORTHO_AZIMUTH,
39         PROJECTION_SPHERICAL
40     };
41     
42   int zoom() const;
43   
44   void handlePan(int x, int y);
45   
46   void pan(const SGVec2d& delta);
47   void zoomIn();
48   void zoomOut();
49   
50   void paintAircraftLocation(const SGGeod& aircraftPos);
51   void paintRoute();
52   void paintRuler();
53   void drawFlightHistory();
54   
55   void drawGPSData();
56   void drawNavRadio(SGPropertyNode_ptr radio);
57   void drawTunedLocalizer(SGPropertyNode_ptr radio);
58   
59   void drawLatLonGrid();
60   SGVec2d gridPoint(int ix, int iy);
61   bool drawLineClipped(const SGVec2d& a, const SGVec2d& b);
62   
63   void drawAirports();
64   void drawAirport(FGAirport* apt);
65   int scoreAirportRunways(FGAirport* apt);
66   void drawRunwayPre(FGRunway* rwy);
67   void drawRunway(FGRunway* rwy);
68   void drawHelipad(FGHelipad* hp);
69   void drawILS(bool tuned, FGRunway* rwy);
70   
71   void drawNavaids();
72   void drawPOIs();
73   void drawNDB(bool tuned, FGNavRecord* nav);
74   void drawVOR(bool tuned, FGNavRecord* nav);
75   void drawFix(FGFix* fix);
76
77   void drawCountries(FGNavRecord* rec);
78   void drawCities(FGNavRecord* rec);
79   void drawTowns(FGNavRecord* rec);
80   
81   void drawTraffic();
82   void drawAIAircraft(const SGPropertyNode* model, const SGGeod& pos, double hdg);
83   void drawAIShip(const SGPropertyNode* model, const SGGeod& pos, double hdg);
84   
85   void drawData();
86   bool validDataForKey(void* key);
87   MapData* getOrCreateDataForKey(void* key);
88   MapData* createDataForKey(void* key);
89   void setAnchorForKey(void* key, const SGVec2d& anchor);
90   void clearData();
91   
92   SGVec2d project(const SGGeod& geod) const;
93   SGGeod unproject(const SGVec2d& p) const;
94   double currentScale() const;
95   
96   int displayHeading(double trueHeading) const;
97   
98   void circleAt(const SGVec2d& center, int nSides, double r);
99   void circleAtAlt(const SGVec2d& center, int nSides, double r, double r2);
100   void squareAt(const SGVec2d& center, double r);
101   void drawLine(const SGVec2d& p1, const SGVec2d& p2);
102   void drawLegendBox(const SGVec2d& pos, const std::string& t);
103   
104   int _width, _height;
105   int _cachedZoom;
106   double _drawRangeNm;
107   double _upHeading; // true heading corresponding to +ve y-axis
108   bool _magneticHeadings;
109   bool _hasPanned;
110   
111   SGGeod _projectionCenter;
112   Projection _projection;
113   SGGeod _aircraft;
114   SGGeod _clickGeod;
115   SGVec2d _hitLocation;
116   FGRouteMgr* _route;
117   SGPropertyNode_ptr _root;
118   SGPropertyNode_ptr _gps;
119   
120   typedef std::map<void*, MapData*> KeyDataMap;
121   KeyDataMap _mapData;
122   std::vector<MapData*> _dataQueue;
123   
124   SGMagVar* _magVar;
125   
126   typedef std::map<int, SGVec2d> GridPointCache;
127   GridPointCache _gridCache;
128   double _gridSpacing;
129   SGGeod _gridCenter;
130 };
131
132 #endif // of GUI_MAPWIDGET_HXX