]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/NavDisplay.hxx
Fix (nearly) all the std:: namespace violations in headers, in preparation for fixing...
[flightgear.git] / src / Instrumentation / NavDisplay.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_ND_HXX
24 #define _INST_ND_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 #include <simgear/math/sg_geodesy.hxx>
34
35 #include <vector>
36 #include <string>
37
38 class FGODGauge;
39 class FGRouteMgr;
40 class FGNavRecord;
41 class FGPositioned;
42
43 class SymbolInstance;
44 class SymbolDef;
45
46 namespace flightgear
47 {
48     class Waypt;
49 }
50
51 typedef std::set<std::string> string_set;
52 typedef std::vector<SymbolDef*> SymbolDefVector;
53
54 class NavDisplay : public SGSubsystem
55 {
56 public:
57
58     NavDisplay(SGPropertyNode *node);
59     virtual ~NavDisplay();
60
61     virtual void init();
62     virtual void update(double dt);
63
64 protected:
65     std::string _name;
66     int _num;
67     double _time;
68     double _updateInterval;
69
70     SGPropertyNode_ptr _serviceable_node;
71     SGPropertyNode_ptr _Instrument;
72     SGPropertyNode_ptr _radar_mode_control_node;
73
74     SGPropertyNode_ptr _user_lat_node;
75     SGPropertyNode_ptr _user_lon_node;
76     SGPropertyNode_ptr _user_heading_node;
77     SGPropertyNode_ptr _user_alt_node;
78
79     FGODGauge *_odg;
80
81     // Convenience function for creating a property node with a
82     // default value
83     template<typename DefaultType>
84     SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
85
86 private:
87     void addSymbolsToScene();
88     void addSymbolToScene(SymbolInstance* sym);
89     void limitDisplayedSymbols();
90     
91     void findItems();
92     void foundPositionedItem(FGPositioned* pos);
93     void computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyNode* nd, double& heading);
94     void computePositionedState(FGPositioned* pos, string_set& states);
95     void processRoute();
96     void computeWayptPropsAndHeading(flightgear::Waypt* wpt, const SGGeod& pos, SGPropertyNode* nd, double& heading);
97     void processNavRadios();
98     FGNavRecord* processNavRadio(const SGPropertyNode_ptr& radio);
99     void processAI();
100     void computeAIStates(const SGPropertyNode* ai, string_set& states);
101     
102     bool anyRuleForType(const std::string& type) const;
103     bool anyRuleMatches(const std::string& type, const string_set& states) const;
104     void findRules(const std::string& type, const string_set& states, SymbolDefVector& rules);
105     
106     void addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars);
107     void addLine(osg::Vec2 a, osg::Vec2 b, const osg::Vec4& color);
108     osg::Vec2 projectBearingRange(double bearingDeg, double rangeNm) const;
109     osg::Vec2 projectGeod(const SGGeod& geod) const;
110     
111     void updateFont();
112     
113     std::string _texture_path;
114
115
116     float _scale;   // factor to convert nm to display units
117     float _view_heading;
118     
119     SGPropertyNode_ptr _Radar_controls;
120
121
122     
123     SGPropertyNode_ptr _font_node;
124     SGPropertyNode_ptr _ai_enabled_node;
125     SGPropertyNode_ptr _navRadio1Node;
126     SGPropertyNode_ptr _navRadio2Node;
127     
128     osg::ref_ptr<osg::Texture2D> _resultTexture;
129     osg::ref_ptr<osg::Texture2D> _symbolTexture;
130     osg::ref_ptr<osg::Geode> _radarGeode;
131     osg::ref_ptr<osg::Geode> _textGeode;
132   
133     osg::Geometry *_geom;
134   
135     osg::DrawArrays* _symbolPrimSet;
136     osg::Vec2Array *_vertices;
137     osg::Vec2Array *_texCoords;
138     osg::Vec4Array* _quadColors;
139     
140     osg::Geometry* _lineGeometry;
141     osg::DrawArrays* _linePrimSet;
142     osg::Vec2Array* _lineVertices;
143     osg::Vec4Array* _lineColors;
144   
145   
146     osg::Matrixf _centerTrans;
147     osg::Matrixf _projectMat;
148     
149     osg::ref_ptr<osgText::Font> _font;
150     osg::Vec4 _font_color;
151     float _font_size;
152     float _font_spacing;
153
154     FGRouteMgr* _route;
155     SGGeod _pos;
156     double _rangeNm;
157
158     SymbolDefVector _rules;
159     FGNavRecord* _nav1Station;
160     FGNavRecord* _nav2Station;
161     std::vector<SymbolInstance*> _symbols;
162     std::set<FGPositioned*> _routeSources;
163     SGPropertyNode_ptr _excessDataNode;
164 };
165
166 #endif // _INST_ND_HXX