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>
53 typedef std::set<std::string> string_set;
54 typedef std::vector<SymbolDef*> SymbolDefVector;
56 class NavDisplay : public SGSubsystem
60 NavDisplay(SGPropertyNode *node);
61 virtual ~NavDisplay();
64 virtual void update(double dt);
66 void invalidatePositionedCache()
68 _cachedItemsValid = false;
74 double _updateInterval;
76 SGPropertyNode_ptr _serviceable_node;
77 SGPropertyNode_ptr _Instrument;
78 SGPropertyNode_ptr _radar_mode_control_node;
79 SGPropertyNode_ptr _user_heading_node;
80 SGPropertyNode_ptr _testModeNode;
84 // Convenience function for creating a property node with a
86 template<typename DefaultType>
87 SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
90 void addSymbolsToScene();
91 void addSymbolToScene(SymbolInstance* sym);
92 void limitDisplayedSymbols();
95 void foundPositionedItem(FGPositioned* pos);
96 void computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyNode* nd, double& heading);
97 void computePositionedState(FGPositioned* pos, string_set& states);
99 void computeWayptPropsAndHeading(flightgear::Waypt* wpt, const SGGeod& pos, SGPropertyNode* nd, double& heading);
100 void processNavRadios();
101 FGNavRecord* processNavRadio(const SGPropertyNode_ptr& radio);
103 void computeAIStates(const SGPropertyNode* ai, string_set& states);
105 bool anyRuleForType(const std::string& type) const;
106 bool anyRuleMatches(const std::string& type, const string_set& states) const;
107 void findRules(const std::string& type, const string_set& states, SymbolDefVector& rules);
109 bool addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars);
110 void addLine(osg::Vec2 a, osg::Vec2 b, const osg::Vec4& color);
111 osg::Vec2 projectBearingRange(double bearingDeg, double rangeNm) const;
112 osg::Vec2 projectGeod(const SGGeod& geod) const;
113 bool isProjectedClipped(const osg::Vec2& projected) const;
116 void addTestSymbol(const std::string& type, const std::string& states, const SGGeod& pos, double heading, SGPropertyNode* vars);
117 void addTestSymbols();
119 std::string _texture_path;
122 float _scale; // factor to convert nm to display units
125 SGPropertyNode_ptr _Radar_controls;
129 SGPropertyNode_ptr _font_node;
130 SGPropertyNode_ptr _ai_enabled_node;
131 SGPropertyNode_ptr _navRadio1Node;
132 SGPropertyNode_ptr _navRadio2Node;
134 osg::ref_ptr<osg::Texture2D> _resultTexture;
135 osg::ref_ptr<osg::Texture2D> _symbolTexture;
136 osg::ref_ptr<osg::Geode> _radarGeode;
137 osg::ref_ptr<osg::Geode> _textGeode;
139 osg::Geometry *_geom;
141 osg::DrawArrays* _symbolPrimSet;
142 osg::Vec2Array *_vertices;
143 osg::Vec2Array *_texCoords;
144 osg::Vec4Array* _quadColors;
146 osg::Geometry* _lineGeometry;
147 osg::DrawArrays* _linePrimSet;
148 osg::Vec2Array* _lineVertices;
149 osg::Vec4Array* _lineColors;
152 osg::Matrixf _centerTrans;
153 osg::Matrixf _projectMat;
155 osg::ref_ptr<osgText::Font> _font;
156 osg::Vec4 _font_color;
163 SGPropertyNode_ptr _rangeNode;
165 SymbolDefVector _rules;
166 FGNavRecord* _nav1Station;
167 FGNavRecord* _nav2Station;
168 std::vector<SymbolInstance*> _symbols;
169 std::set<FGPositioned*> _routeSources;
171 bool _cachedItemsValid;
173 FGPositioned::List _itemsInRange;
174 SGPropertyNode_ptr _excessDataNode;
177 std::auto_ptr<CacheListener> _cacheListener;
180 #endif // _INST_ND_HXX