]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/wxradar.hxx
Csaba HALASZ & Syd ADAMS: make radar font configurable
[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 //
24
25 #ifndef _INST_WXRADAR_HXX
26 #define _INST_WXRADAR_HXX
27
28 #include <osg/ref_ptr>
29 #include <osg/Geode>
30 #include <osg/Texture2D>
31 #include <osgText/Text>
32
33 #include <simgear/props/props.hxx>
34 #include <simgear/structure/subsystem_mgr.hxx>
35 #include <simgear/environment/visual_enviro.hxx>
36
37 #include <AIModel/AIBase.hxx>
38 #include <AIModel/AIManager.hxx>
39 #include <vector>
40 #include <string>
41 SG_USING_STD(vector);
42 SG_USING_STD(string);
43
44 class FGAIBase;
45
46 class FGODGauge;
47
48 class wxRadarBg : public SGSubsystem, public SGPropertyChangeListener {
49 public:
50
51     wxRadarBg ( SGPropertyNode *node );
52     wxRadarBg ();
53     virtual ~wxRadarBg ();
54
55     virtual void init ();
56     virtual void update (double dt);
57     virtual void valueChanged(SGPropertyNode*);
58
59     double _interval;
60     double _time;
61     bool _sim_init_done;
62     string _name;
63     int _num;
64
65     SGPropertyNode_ptr _serviceable_node;
66     SGPropertyNode_ptr _Instrument;
67     SGPropertyNode_ptr _radar_mode_control_node;
68
69     SGPropertyNode_ptr _user_lat_node;
70     SGPropertyNode_ptr _user_lon_node;
71     SGPropertyNode_ptr _user_heading_node;
72     SGPropertyNode_ptr _user_alt_node;
73
74     FGODGauge *_odg;
75
76     // Convenience function for creating a property node with a
77     // default value
78     template<typename DefaultType>
79     SGPropertyNode* getInstrumentNode(const char* name, DefaultType value);
80
81 private:
82     string _texture_path;
83
84     typedef enum { ARC, MAP, PLAN, ROSE } DisplayMode;
85     DisplayMode _display_mode;
86
87     string _last_switchKnob;
88
89     float _range_nm;
90     float _scale;   // factor to convert nm to display units
91     float _angle_offset;
92     float _view_heading;
93     float _x_offset, _y_offset;
94
95     double _radar_ref_rng;
96     double _lat, _lon;
97
98     SGPropertyNode_ptr _Tacan;
99     SGPropertyNode_ptr _Radar_controls;
100
101     SGPropertyNode_ptr _user_speed_east_fps_node;
102     SGPropertyNode_ptr _user_speed_north_fps_node;
103
104     SGPropertyNode_ptr _tacan_serviceable_node;
105     SGPropertyNode_ptr _tacan_distance_node;
106     SGPropertyNode_ptr _tacan_name_node;
107     SGPropertyNode_ptr _tacan_bearing_node;
108     SGPropertyNode_ptr _tacan_in_range_node;
109
110     SGPropertyNode_ptr _radar_weather_node;
111     SGPropertyNode_ptr _radar_position_node;
112     SGPropertyNode_ptr _radar_data_node;
113     SGPropertyNode_ptr _radar_symbol_node;
114
115     SGPropertyNode_ptr _radar_centre_node;
116     SGPropertyNode_ptr _radar_coverage_node;
117     SGPropertyNode_ptr _radar_ref_rng_node;
118     SGPropertyNode_ptr _radar_hdg_marker_node;
119     SGPropertyNode_ptr _radar_rotate_node;
120
121     SGPropertyNode_ptr _font_node;
122     SGPropertyNode_ptr _ai_enabled_node;
123
124     osg::ref_ptr<osg::Texture2D> _resultTexture;
125     osg::ref_ptr<osg::Texture2D> _wxEcho;
126     osg::ref_ptr<osg::Geode> _radarGeode;
127     osg::ref_ptr<osg::Geode> _textGeode;
128     osg::Geometry *_geom;
129     osg::Vec2Array *_vertices;
130     osg::Vec2Array *_texCoords;
131     osg::Matrixf _centerTrans;
132     osg::ref_ptr<osgText::Font> _font;
133     osg::Vec4 _font_color;
134     float _font_size;
135     float _font_spacing;
136
137     list_of_SGWxRadarEcho _radarEchoBuffer;
138
139     FGAIManager* _ai;
140
141     void update_weather();
142     void update_aircraft();
143     void update_tacan();
144     void update_heading_marker();
145     void update_data(FGAIBase* ac, double radius, double bearing, bool selected);
146     void center_map();
147     void apply_map_offset();
148     void updateFont();
149     void calcRangeBearing(double lat, double lon, double lat2, double lon2,
150             double &range, double &bearing) const;
151
152     bool withinRadarHorizon(double user_alt, double alt, double range);
153     bool inRadarRange(int type, double range);
154
155     float calcRelBearing(float bearing, float heading);
156 };
157
158
159 template<> inline
160 SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, bool value)
161 {
162     SGPropertyNode* result = _Instrument->getNode(name, true);
163     if (result->getType() == SGPropertyNode::NONE)
164         result->setBoolValue(value);
165     return result;
166 }
167
168
169 template<> inline
170 SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, double value)
171 {
172     SGPropertyNode* result = _Instrument->getNode(name, true);
173     if (result->getType() == SGPropertyNode::NONE)
174         result->setDoubleValue(value);
175     return result;
176 }
177
178
179 template<> inline
180 SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name,
181                                              const char* value)
182 {
183     SGPropertyNode* result = _Instrument->getNode(name, true);
184     if (result->getType() == SGPropertyNode::NONE)
185         result->setStringValue(value);
186     return result;
187 }
188
189
190 #endif // _INST_WXRADAR_HXX