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