]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/wxradar.hxx
Potential fix for bug #471 (crash in checkspeedadjustment).
[flightgear.git] / src / Instrumentation / wxradar.hxx
1 // Wx Radar background texture
2 //
3 // Written by Harald JOHNSEN, started May 2005.
4 // With major amendments by Vivian MEAZZA May 2007
5 // Ported to OSG by Tim MOORE Jun 2007
6 //
7 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22
23 #ifndef _INST_WXRADAR_HXX
24 #define _INST_WXRADAR_HXX
25
26 #include <osg/ref_ptr>
27 #include <osg/Geode>
28 #include <osg/Texture2D>
29 #include <osgText/Text>
30
31 #include <simgear/props/props.hxx>
32 #include <simgear/structure/subsystem_mgr.hxx>
33
34 #include <vector>
35 #include <string>
36
37 using std::vector;
38 using std::string;
39
40 class FGODGauge;
41
42 class wxRadarBg : public SGSubsystem, public SGPropertyChangeListener {
43 public:
44
45     wxRadarBg(SGPropertyNode *node);
46     wxRadarBg();
47     virtual ~wxRadarBg();
48
49     virtual void init();
50     virtual void update(double dt);
51     virtual void valueChanged(SGPropertyNode *);
52
53 protected:
54     std::string _name;
55     int _num;
56     double _time;
57     double _interval;
58     double _elapsed_time;
59     double _persistance;
60     bool _sim_init_done;
61
62     SGPropertyNode_ptr _serviceable_node;
63     SGPropertyNode_ptr _Instrument;
64     SGPropertyNode_ptr _radar_mode_control_node;
65
66     SGPropertyNode_ptr _user_lat_node;
67     SGPropertyNode_ptr _user_lon_node;
68     SGPropertyNode_ptr _user_heading_node;
69     SGPropertyNode_ptr _user_alt_node;
70
71     FGODGauge *_odg;
72
73     typedef struct {
74         double bearing;
75         double range;
76         double elevation;
77         double bumpiness;
78         double elapsed_time;
79     }ground_echo;
80
81     typedef vector <ground_echo*> ground_echo_vector_type;
82     typedef ground_echo_vector_type::iterator ground_echo_vector_iterator;
83
84     ground_echo_vector_type       ground_echoes;
85     ground_echo_vector_iterator   ground_echoes_iterator;
86
87     // Convenience function for creating a property node with a
88     // default value
89     template<typename DefaultType>
90     SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
91
92 private:
93     std::string _texture_path;
94
95     typedef enum { ARC, MAP, PLAN, ROSE, BSCAN} DisplayMode;
96     DisplayMode _display_mode;
97
98     float _range_nm;
99     float _scale;   // factor to convert nm to display units
100     float _angle_offset;
101     float _view_heading;
102     float _x_offset, _y_offset;
103
104     double _radar_ref_rng;
105     double _lat, _lon;
106     double _antenna_ht;
107
108     SGPropertyNode_ptr _Tacan;
109     SGPropertyNode_ptr _Radar_controls;
110
111     SGPropertyNode_ptr _user_speed_east_fps_node;
112     SGPropertyNode_ptr _user_speed_north_fps_node;
113
114     SGPropertyNode_ptr _tacan_serviceable_node;
115     SGPropertyNode_ptr _tacan_distance_node;
116     SGPropertyNode_ptr _tacan_name_node;
117     SGPropertyNode_ptr _tacan_bearing_node;
118     SGPropertyNode_ptr _tacan_in_range_node;
119
120     SGPropertyNode_ptr _radar_weather_node;
121     SGPropertyNode_ptr _radar_position_node;
122     SGPropertyNode_ptr _radar_data_node;
123     SGPropertyNode_ptr _radar_symbol_node;
124
125     SGPropertyNode_ptr _radar_centre_node;
126     SGPropertyNode_ptr _radar_coverage_node;
127     SGPropertyNode_ptr _radar_ref_rng_node;
128     SGPropertyNode_ptr _radar_hdg_marker_node;
129     SGPropertyNode_ptr _radar_rotate_node;
130     SGPropertyNode_ptr _radar_tcas_node;
131     SGPropertyNode_ptr _radar_absalt_node;
132
133     SGPropertyNode_ptr _font_node;
134     SGPropertyNode_ptr _ai_enabled_node;
135
136     osg::ref_ptr<osg::Texture2D> _resultTexture;
137     osg::ref_ptr<osg::Texture2D> _wxEcho;
138     osg::ref_ptr<osg::Geode> _radarGeode;
139     osg::ref_ptr<osg::Geode> _textGeode;
140     osg::Geometry *_geom;
141     osg::Vec2Array *_vertices;
142     osg::Vec2Array *_texCoords;
143     osg::Matrixf _centerTrans;
144     osg::ref_ptr<osgText::Font> _font;
145     osg::Vec4 _font_color;
146     osg::Vec4 _tcas_colors[4];
147     float _font_size;
148     float _font_spacing;
149
150 // FIXME: implementation of radar echoes missing
151 //    list_of_SGWxRadarEcho _radarEchoBuffer;
152
153     void update_weather();
154     void update_aircraft();
155     void update_tacan();
156     void update_heading_marker();
157     void update_data(const SGPropertyNode *ac, double alt, double heading,
158         double radius, double bearing, bool selected);
159     bool update_tcas(const SGPropertyNode *model,double range,double user_alt,double alt,
160                      double bearing,double radius, bool absMode);
161     void center_map();
162     void apply_map_offset();
163     void updateFont();
164     void calcRangeBearing(double lat, double lon, double lat2, double lon2,
165         double &range, double &bearing) const;
166
167     bool withinRadarHorizon(double user_alt, double alt, double range);
168     bool inRadarRange(double sigma, double range);
169
170     float calcRelBearing(float bearing, float heading);
171     float calcRelBearingDeg(float bearing, float heading);
172 };
173
174
175 template<> inline
176 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, bool value)
177 {
178     SGPropertyNode *result = _Instrument->getNode(name, true);
179     if (!result->hasValue())
180         result->setBoolValue(value);
181     return result;
182 }
183
184
185 template<> inline
186 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, double value)
187 {
188     SGPropertyNode *result = _Instrument->getNode(name, true);
189     if (!result->hasValue())
190         result->setDoubleValue(value);
191     return result;
192 }
193
194
195 template<> inline
196 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, const char *value)
197 {
198     SGPropertyNode *result = _Instrument->getNode(name, true);
199     if (result->hasValue())
200         result->setStringValue(value);
201     return result;
202 }
203
204
205 #endif // _INST_WXRADAR_HXX