]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/NavDisplay.hxx
NavDisplay: fix update lag when switching range or centre.
[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 #include <memory>
38
39 #include <Navaids/positioned.hxx>
40
41 class FGODGauge;
42 class FGRouteMgr;
43 class FGNavRecord;
44
45 class SymbolInstance;
46 class SymbolDef;
47
48 namespace flightgear
49 {
50     class Waypt;
51 }
52
53 typedef std::set<std::string> string_set;
54 typedef std::vector<SymbolDef*> SymbolDefVector;
55
56 class NavDisplay : public SGSubsystem
57 {
58 public:
59
60     NavDisplay(SGPropertyNode *node);
61     virtual ~NavDisplay();
62
63     virtual void init();
64     virtual void update(double dt);
65
66     void invalidatePositionedCache()
67     {
68         _cachedItemsValid = false;
69     }
70     
71     double textureSize() const
72     { return _textureSize; }
73     
74     void forceUpdate()
75     { _forceUpdate = true; }
76     
77 protected:
78     std::string _name;
79     int _num;
80     double _time;
81     double _updateInterval;
82     bool _forceUpdate;
83     
84     SGPropertyNode_ptr _serviceable_node;
85     SGPropertyNode_ptr _Instrument;
86     SGPropertyNode_ptr _radar_mode_control_node;
87     SGPropertyNode_ptr _user_heading_node;
88     SGPropertyNode_ptr _testModeNode;
89   
90     FGODGauge *_odg;
91
92     // Convenience function for creating a property node with a
93     // default value
94     template<typename DefaultType>
95     SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
96
97 private:
98     void addSymbolsToScene();
99     void addSymbolToScene(SymbolInstance* sym);
100     void limitDisplayedSymbols();
101     
102     void findItems();
103     void foundPositionedItem(FGPositioned* pos);
104     void computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyNode* nd, double& heading);
105     void computePositionedState(FGPositioned* pos, string_set& states);
106     void processRoute();
107     void computeWayptPropsAndHeading(flightgear::Waypt* wpt, const SGGeod& pos, SGPropertyNode* nd, double& heading);
108     void processNavRadios();
109     FGNavRecord* processNavRadio(const SGPropertyNode_ptr& radio);
110     void processAI();
111     void computeAIStates(const SGPropertyNode* ai, string_set& states);
112     
113     bool anyRuleForType(const std::string& type) const;
114     bool anyRuleMatches(const std::string& type, const string_set& states) const;
115     void findRules(const std::string& type, const string_set& states, SymbolDefVector& rules);
116     
117     SymbolInstance* addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars);
118     void addLine(osg::Vec2 a, osg::Vec2 b, const osg::Vec4& color);
119     osg::Vec2 projectBearingRange(double bearingDeg, double rangeNm) const;
120     osg::Vec2 projectGeod(const SGGeod& geod) const;
121     bool isProjectedClipped(const osg::Vec2& projected) const;
122     void updateFont();
123     
124     void addTestSymbol(const std::string& type, const std::string& states, const SGGeod& pos, double heading, SGPropertyNode* vars);
125     void addTestSymbols();
126   
127     std::string _texture_path;
128     unsigned int _textureSize;
129
130     float _scale;   // factor to convert nm to display units
131     float _view_heading;
132     
133     SGPropertyNode_ptr _Radar_controls;
134
135
136     
137     SGPropertyNode_ptr _font_node;
138     SGPropertyNode_ptr _ai_enabled_node;
139     SGPropertyNode_ptr _navRadio1Node;
140     SGPropertyNode_ptr _navRadio2Node;
141     SGPropertyNode_ptr _xCenterNode, _yCenterNode;
142     
143     osg::ref_ptr<osg::Texture2D> _resultTexture;
144     osg::ref_ptr<osg::Texture2D> _symbolTexture;
145     osg::ref_ptr<osg::Geode> _radarGeode;
146     osg::ref_ptr<osg::Geode> _textGeode;
147   
148     osg::Geometry *_geom;
149   
150     osg::DrawArrays* _symbolPrimSet;
151     osg::Vec2Array *_vertices;
152     osg::Vec2Array *_texCoords;
153     osg::Vec4Array* _quadColors;
154     
155     osg::Geometry* _lineGeometry;
156     osg::DrawArrays* _linePrimSet;
157     osg::Vec2Array* _lineVertices;
158     osg::Vec4Array* _lineColors;
159   
160   
161     osg::Matrixf _centerTrans;
162     osg::Matrixf _projectMat;
163     
164     osg::ref_ptr<osgText::Font> _font;
165     osg::Vec4 _font_color;
166     float _font_size;
167     float _font_spacing;
168
169     FGRouteMgr* _route;
170     SGGeod _pos;
171     double _rangeNm;
172     SGPropertyNode_ptr _rangeNode;
173     
174     SymbolDefVector _rules;
175     FGNavRecord* _nav1Station;
176     FGNavRecord* _nav2Station;
177     std::vector<SymbolInstance*> _symbols;
178     std::set<FGPositioned*> _routeSources;
179     
180     bool _cachedItemsValid;
181     SGVec3d _cachedPos;
182     FGPositioned::List _itemsInRange;
183     SGPropertyNode_ptr _excessDataNode;
184     
185     class CacheListener;
186     std::auto_ptr<CacheListener> _cacheListener;
187     
188     class ForceUpdateListener;
189     std::auto_ptr<ForceUpdateListener> _forceUpdateListener;
190 };
191
192 #endif // _INST_ND_HXX