Debian Codegraph @

src/Cockpit/NavDisplay.hxx

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