1 // Wx Radar background texture
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
7 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
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.
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.
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.
26 #include <osg/ref_ptr>
28 #include <osg/Texture2D>
29 #include <osgText/Text>
31 #include <simgear/props/props.hxx>
32 #include <simgear/structure/subsystem_mgr.hxx>
33 #include <simgear/math/sg_geodesy.hxx>
39 #include <Navaids/positioned.hxx>
54 typedef std::set<std::string> string_set;
55 typedef std::vector<SymbolRule*> SymbolRuleVector;
56 typedef std::vector<SymbolDef*> SymbolDefVector;
58 class NavDisplay : public SGSubsystem
62 NavDisplay(SGPropertyNode *node);
63 virtual ~NavDisplay();
66 virtual void update(double dt);
68 void invalidatePositionedCache()
70 _cachedItemsValid = false;
73 double textureSize() const
74 { return _textureSize; }
77 { _forceUpdate = true; }
79 bool anyRuleForType(const std::string& type) const;
80 bool isPositionedShown(FGPositioned* pos);
85 double _updateInterval;
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;
96 // Convenience function for creating a property node with a
98 template<typename DefaultType>
99 SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
102 friend class SymbolRule;
103 friend class SymbolDef;
105 void addRule(SymbolRule*);
107 void addSymbolsToScene();
108 void addSymbolToScene(SymbolInstance* sym);
109 void limitDisplayedSymbols();
112 void isPositionedShownInner(FGPositioned* pos, SymbolRuleVector& rules);
113 void foundPositionedItem(FGPositioned* pos);
114 void computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyNode* nd, double& heading);
115 void computePositionedState(FGPositioned* pos, string_set& states);
117 void computeWayptPropsAndHeading(flightgear::Waypt* wpt, const SGGeod& pos, SGPropertyNode* nd, double& heading);
118 void processNavRadios();
119 FGNavRecord* processNavRadio(const SGPropertyNode_ptr& radio);
121 void computeAIStates(const SGPropertyNode* ai, string_set& states);
124 bool anyRuleMatches(const std::string& type, const string_set& states) const;
125 void findRules(const std::string& type, const string_set& states, SymbolRuleVector& rules);
127 SymbolInstance* addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars);
128 void addLine(osg::Vec2 a, osg::Vec2 b, const osg::Vec4& color);
129 osg::Vec2 projectBearingRange(double bearingDeg, double rangeNm) const;
130 osg::Vec2 projectGeod(const SGGeod& geod) const;
131 bool isProjectedClipped(const osg::Vec2& projected) const;
134 void addTestSymbol(const std::string& type, const std::string& states, const SGGeod& pos, double heading, SGPropertyNode* vars);
135 void addTestSymbols();
137 std::string _texture_path;
138 unsigned int _textureSize;
140 float _scale; // factor to convert nm to display units
143 SGPropertyNode_ptr _Radar_controls;
147 SGPropertyNode_ptr _font_node;
148 SGPropertyNode_ptr _ai_enabled_node;
149 SGPropertyNode_ptr _navRadio1Node;
150 SGPropertyNode_ptr _navRadio2Node;
151 SGPropertyNode_ptr _xCenterNode, _yCenterNode;
152 SGPropertyNode_ptr _viewHeadingNode;
154 osg::ref_ptr<osg::Texture2D> _symbolTexture;
155 osg::ref_ptr<osg::Geode> _radarGeode;
156 osg::ref_ptr<osg::Geode> _textGeode;
158 osg::Geometry *_geom;
160 osg::DrawArrays* _symbolPrimSet;
161 osg::Vec2Array *_vertices;
162 osg::Vec2Array *_texCoords;
163 osg::Vec4Array* _quadColors;
165 osg::Geometry* _lineGeometry;
166 osg::DrawArrays* _linePrimSet;
167 osg::Vec2Array* _lineVertices;
168 osg::Vec4Array* _lineColors;
171 osg::Matrixf _centerTrans;
172 osg::Matrixf _projectMat;
174 osg::ref_ptr<osgText::Font> _font;
175 osg::Vec4 _font_color;
182 SGPropertyNode_ptr _rangeNode;
184 SymbolDefVector _definitions;
185 SymbolRuleVector _rules;
186 FGNavRecord* _nav1Station;
187 FGNavRecord* _nav2Station;
188 std::vector<SymbolInstance*> _symbols;
189 std::set<FGPositioned*> _routeSources;
191 bool _cachedItemsValid;
193 FGPositioned::List _itemsInRange;
194 SGPropertyNode_ptr _excessDataNode;
198 std::auto_ptr<CacheListener> _cacheListener;
200 class ForceUpdateListener;
201 std::auto_ptr<ForceUpdateListener> _forceUpdateListener;
204 #endif // _INST_ND_HXX