]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/NavDisplay.cxx
NavDisplay: respect initial values for various properties.
[flightgear.git] / src / Instrumentation / NavDisplay.cxx
1 // navigation display texture
2 //
3 // Written by James Turner, forked from wxradar code
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 //
20 //
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #endif
25
26 #include "NavDisplay.hxx"
27
28 #include <cassert>
29 #include <boost/foreach.hpp>
30 #include <algorithm>
31
32 #include <osg/Array>
33 #include <osg/Geometry>
34 #include <osg/Matrixf>
35 #include <osg/PrimitiveSet>
36 #include <osg/StateSet>
37 #include <osg/LineWidth>
38 #include <osg/Version>
39
40 #include <simgear/constants.h>
41 #include <simgear/misc/sg_path.hxx>
42 #include <simgear/scene/model/model.hxx>
43 #include <simgear/structure/exception.hxx>
44 #include <simgear/misc/sg_path.hxx>
45 #include <simgear/misc/strutils.hxx>
46 #include <simgear/math/sg_geodesy.hxx>
47
48 #include <sstream>
49 #include <iomanip>
50 #include <iostream>             // for cout, endl
51
52 using std::stringstream;
53 using std::endl;
54 using std::setprecision;
55 using std::fixed;
56 using std::setw;
57 using std::setfill;
58 using std::cout;
59 using std::endl;
60 using std::map;
61 using std::string;
62
63 #include <Main/fg_props.hxx>
64 #include <Main/globals.hxx>
65 #include <Cockpit/panel.hxx>
66 #include <Navaids/routePath.hxx>
67 #include <Autopilot/route_mgr.hxx>
68 #include <Navaids/navrecord.hxx>
69 #include <Navaids/navlist.hxx>
70 #include <Navaids/fix.hxx>
71 #include <Airports/simple.hxx>
72 #include <Airports/runways.hxx>
73
74 #include "instrument_mgr.hxx"
75 #include "od_gauge.hxx"
76
77 static const char *DEFAULT_FONT = "typewriter.txf";
78
79 static
80 osg::Matrixf degRotation(float angle)
81 {
82     return osg::Matrixf::rotate(angle * SG_DEGREES_TO_RADIANS, 0.0f, 0.0f, -1.0f);
83 }
84
85 static osg::Vec4 readColor(SGPropertyNode* colorNode, const osg::Vec4& c)
86 {
87     osg::Vec4 result;
88     result.r() = colorNode->getDoubleValue("red",   c.r());
89     result.g() = colorNode->getDoubleValue("green", c.g());
90     result.b() = colorNode->getDoubleValue("blue",  c.b());
91     result.a() = colorNode->getDoubleValue("alpha", c.a());
92     return result;
93 }
94
95 static osgText::Text::AlignmentType readAlignment(const std::string& t)
96 {
97     if (t == "left-top") {
98         return osgText::Text::LEFT_TOP;
99     } else if (t == "left-center") {
100         return osgText::Text::LEFT_CENTER;
101     } else if (t == "left-bottom") {
102         return osgText::Text::LEFT_BOTTOM;
103     } else if (t == "center-top") {
104         return osgText::Text::CENTER_TOP;
105     } else if (t == "center-center") {
106         return osgText::Text::CENTER_CENTER;
107     } else if (t == "center-bottom") {
108         return osgText::Text::CENTER_BOTTOM;
109     } else if (t == "right-top") {
110         return osgText::Text::RIGHT_TOP;
111     } else if (t == "right-center") {
112         return osgText::Text::RIGHT_CENTER;
113     } else if (t == "right-bottom") {
114         return osgText::Text::RIGHT_BOTTOM;
115     } else if (t == "left-baseline") {
116         return osgText::Text::LEFT_BASE_LINE;
117     } else if (t == "center-baseline") {
118         return osgText::Text::CENTER_BASE_LINE;
119     } else if (t == "right-baseline") {
120         return osgText::Text::RIGHT_BASE_LINE;
121     }
122     
123     return osgText::Text::BASE_LINE;
124 }
125
126 static string formatPropertyValue(SGPropertyNode* nd, const string& format)
127 {
128     assert(nd);
129     static char buf[512];
130     if (format.find('d') != string::npos) {
131         ::snprintf(buf, 512, format.c_str(), nd->getIntValue());
132         return buf;
133     }
134     
135     if (format.find('s') != string::npos) {
136         ::snprintf(buf, 512, format.c_str(), nd->getStringValue());
137         return buf;
138     }
139     
140 // assume it's a double/float
141     ::snprintf(buf, 512, format.c_str(), nd->getDoubleValue());
142     return buf;
143 }
144
145 static osg::Vec2 mult(const osg::Vec2& v, const osg::Matrixf& m)
146 {
147     osg::Vec3 r = m.preMult(osg::Vec3(v.x(), v.y(), 0.0));
148     return osg::Vec2(r.x(), r.y());
149 }
150
151 class NavDisplay::CacheListener : public SGPropertyChangeListener
152 {
153 public:
154     CacheListener(NavDisplay *nd) : 
155         _nd(nd)
156     {}
157     
158     virtual void valueChanged (SGPropertyNode * prop)
159     {
160         _nd->invalidatePositionedCache();
161         SG_LOG(SG_INSTR, SG_INFO, "invalidating NavDisplay cache");
162     }
163 private:
164     NavDisplay* _nd;
165 };
166
167 class NavDisplay::ForceUpdateListener : public SGPropertyChangeListener
168 {
169 public:
170   ForceUpdateListener(NavDisplay *nd) : 
171     _nd(nd)
172   {}
173   
174   virtual void valueChanged (SGPropertyNode * prop)
175   {
176     SG_LOG(SG_INSTR, SG_INFO, "forcing NavDisplay update");
177     _nd->forceUpdate();
178   }
179 private:
180   NavDisplay* _nd;
181 };
182
183 ///////////////////////////////////////////////////////////////////
184
185 class SymbolRule
186 {
187 public:
188     SymbolRule()
189     {
190         
191     }
192     
193     bool initFromNode(SGPropertyNode* node, NavDisplay* owner)
194     {
195         if (!node->getChild("type")) {
196             return false;
197         }
198         
199         type = node->getStringValue("type");
200         SGPropertyNode* enableNode = node->getChild("enable");
201         if (enableNode) { 
202             enable.reset(sgReadCondition(fgGetNode("/"), enableNode));
203         }
204         
205         int n=0;
206         while (node->hasChild("state", n)) {
207             string m = node->getChild("state", n++)->getStringValue();
208             if (m[0] == '!') {
209                 excluded_states.insert(m.substr(1));
210             } else {
211                 required_states.insert(m);
212             }
213         } // of matches parsing
214         
215         return true;
216     }
217     
218     void setDefinition(SymbolDef* d)
219     {
220         definition = d;
221     }
222     
223     SymbolDef* getDefinition() const
224     { return definition; }
225     
226     bool matches(const string_set& states) const
227     {
228         BOOST_FOREACH(const string& s, required_states) {
229             if (states.count(s) == 0) {
230                 return false;
231             }
232         }
233         
234         BOOST_FOREACH(const string& s, excluded_states) {
235             if (states.count(s) != 0) {
236                 return false;
237             }
238         }
239         
240         return true;
241     }
242     
243     void checkEnabled()
244     {
245         if (enable.get()) {
246             enabled = enable->test();
247         } else {
248             enabled = true;
249         }
250     }
251     
252     bool enabled; // cached enabled state
253     std::string type;
254 private:
255     SymbolDef* definition;
256     
257     std::auto_ptr<SGCondition> enable;
258     string_set required_states;
259     string_set excluded_states;
260     
261 };
262
263 class SymbolDef
264 {
265 public:
266     bool initFromNode(SGPropertyNode* node, NavDisplay* owner)
267     {
268         if (node->getChild("type")) {
269             SymbolRule* builtinRule = new SymbolRule;
270             builtinRule->initFromNode(node, owner);
271             builtinRule->setDefinition(this);
272             owner->addRule(builtinRule);
273         }
274         
275         if (node->hasChild("width")) {
276             float w = node->getFloatValue("width");
277             float h = node->getFloatValue("height", w);
278             xy0.x() = -w * 0.5;
279             xy0.y() = -h * 0.5;
280             xy1.x() = w * 0.5;
281             xy1.y() = h * 0.5;
282         } else {
283             xy0.x()  = node->getFloatValue("x0", 0.0);
284             xy0.y()  = node->getFloatValue("y0", 0.0);
285             xy1.x()  = node->getFloatValue("x1", 5);
286             xy1.y()  = node->getFloatValue("y1", 5);
287         }
288       
289         double texSize = node->getFloatValue("texture-size", owner->textureSize());
290         
291         uv0.x()  = node->getFloatValue("u0", 0) / texSize;
292         uv0.y()  = node->getFloatValue("v0", 0) / texSize;
293         uv1.x()  = node->getFloatValue("u1", 1) / texSize;
294         uv1.y()  = node->getFloatValue("v1", 1) / texSize;
295         
296         color = readColor(node->getChild("color"), osg::Vec4(1, 1, 1, 1));
297         priority = node->getIntValue("priority", 0);
298         zOrder = node->getIntValue("zOrder", 0);
299         rotateToHeading = node->getBoolValue("rotate-to-heading", false);
300         roundPos = node->getBoolValue("round-position", true);
301         hasText = false;
302         if (node->hasChild("text")) {
303             hasText = true;
304             alignment = readAlignment(node->getStringValue("text-align"));
305             textTemplate = node->getStringValue("text");
306             textOffset.x() = node->getFloatValue("text-offset-x", 0);
307             textOffset.y() = node->getFloatValue("text-offset-y", 0);
308             textColor = readColor(node->getChild("text-color"), color);
309         }
310         
311         drawLine = node->getBoolValue("draw-line", false);
312         lineColor = readColor(node->getChild("line-color"), color);
313         drawRouteLeg = node->getBoolValue("draw-leg", false);
314         
315         stretchSymbol = node->getBoolValue("stretch-symbol", false);
316         if (stretchSymbol) {
317             stretchY2 = node->getFloatValue("y2");
318             stretchY3 = node->getFloatValue("y3");
319             stretchV2 = node->getFloatValue("v2") / texSize;
320             stretchV3 = node->getFloatValue("v3") / texSize;
321         }
322       
323         return true;
324     }
325     
326     osg::Vec2 xy0, xy1;
327     osg::Vec2 uv0, uv1;
328     osg::Vec4 color;
329     
330     int priority;
331     int zOrder;
332     bool rotateToHeading;
333     bool roundPos; ///< should position be rounded to integer values
334     bool hasText;
335     osg::Vec4 textColor;
336     osg::Vec2 textOffset;
337     osgText::Text::AlignmentType alignment;
338     string textTemplate;
339     
340     bool drawLine;
341     osg::Vec4 lineColor;
342     
343 // symbol stretching creates three quads (instead of one) - a start,
344 // middle and end quad, positioned along the line of the symbol.
345 // X (and U) axis values determined by the values above, so we only need
346 // to define the Y (and V) values to build the other quads.
347     bool stretchSymbol;
348     double stretchY2, stretchY3;
349     double stretchV2, stretchV3;
350     
351     bool drawRouteLeg;
352     
353 };
354
355 class SymbolInstance
356 {
357 public:
358     SymbolInstance(const osg::Vec2& p, double h, SymbolDef* def, SGPropertyNode* vars) :
359         pos(p),
360         headingDeg(h),
361         definition(def),
362         props(vars)
363     { }
364     
365     osg::Vec2 pos; // projected position
366     osg::Vec2 endPos;
367     double headingDeg;
368     SymbolDef* definition;
369     SGPropertyNode_ptr props;
370     
371     string text() const
372     {
373         assert(definition->hasText);
374         string r;        
375         size_t lastPos = 0;
376         
377         while (true) {
378             size_t pos = definition->textTemplate.find('{', lastPos);
379             if (pos == string::npos) { // no more replacements
380                 r.append(definition->textTemplate.substr(lastPos));
381                 break;
382             }
383             
384             r.append(definition->textTemplate.substr(lastPos, pos - lastPos));
385             
386             size_t endReplacement = definition->textTemplate.find('}', pos+1);
387             if (endReplacement <= pos) {
388                 return "bad replacement";
389             }
390
391             string spec = definition->textTemplate.substr(pos + 1, endReplacement - (pos + 1));
392         // look for formatter in spec
393             size_t colonPos = spec.find(':');
394             if (colonPos == string::npos) {
395             // simple replacement
396                 r.append(props->getStringValue(spec));
397             } else {
398                 string format = spec.substr(colonPos + 1);
399                 string prop = spec.substr(0, colonPos);
400                 r.append(formatPropertyValue(props->getNode(prop), format));
401             }
402             
403             lastPos = endReplacement + 1;
404         }
405         
406         return r;
407     }
408 };
409
410 //////////////////////////////////////////////////////////////////
411
412 NavDisplay::NavDisplay(SGPropertyNode *node) :
413     _name(node->getStringValue("name", "nd")),
414     _num(node->getIntValue("number", 0)),
415     _time(0.0),
416     _updateInterval(node->getDoubleValue("update-interval-sec", 0.1)),
417     _forceUpdate(true),
418     _odg(0),
419     _scale(0),
420     _view_heading(0),
421     _resultTexture(0),
422     _font_size(0),
423     _font_spacing(0),
424     _rangeNm(0)
425 {
426     _Instrument = fgGetNode(string("/instrumentation/" + _name).c_str(), _num, true);
427     _font_node = _Instrument->getNode("font", true);
428
429 #define INITFONT(p, val, type) if (!_font_node->hasValue(p)) _font_node->set##type##Value(p, val)
430     INITFONT("name", DEFAULT_FONT, String);
431     INITFONT("size", 8, Float);
432     INITFONT("line-spacing", 0.25, Float);
433     INITFONT("color/red", 0, Float);
434     INITFONT("color/green", 0.8, Float);
435     INITFONT("color/blue", 0, Float);
436     INITFONT("color/alpha", 1, Float);
437 #undef INITFONT
438
439     _textureSize = _Instrument->getNode("symbol-texture-size", true)->getIntValue();
440     SGPropertyNode* symbolsNode = node->getNode("symbols");
441     SGPropertyNode* symbol;
442
443     map<string, SymbolDef*> definitionDict;
444     for (int i = 0; (symbol = symbolsNode->getChild("symbol", i)) != NULL; ++i) {
445         SymbolDef* def = new SymbolDef;
446         if (!def->initFromNode(symbol, this)) {
447           delete def;
448           continue;
449         }
450         
451         const char* id = symbol->getStringValue("id");
452         if (id && strlen(id)) {
453             definitionDict[id] = def;
454         }
455         
456         _definitions.push_back(def);
457     } // of symbol definition parsing
458     
459     SGPropertyNode* rulesNode = node->getNode("rules");
460     if (rulesNode) {
461         SGPropertyNode* rule;
462         
463         for (int i = 0; (rule = rulesNode->getChild("rule", i)) != NULL; ++i) {
464             SymbolRule* r = new SymbolRule;
465             if (!r->initFromNode(rule, this)) {
466                 delete r;
467                 continue;
468             }
469             
470             const char* id = symbol->getStringValue("symbol");
471             if (id && strlen(id) && (definitionDict.find(id) != definitionDict.end())) {
472                 r->setDefinition(definitionDict[id]);
473             } else {
474                 SG_LOG(SG_INSTR, SG_WARN, "symbol rule has missing/unknown definition id:" << id);
475                 delete r;
476                 continue;
477             }
478             
479             addRule(r);
480         } // of symbol rule parsing
481     }
482     
483 }
484
485
486 NavDisplay::~NavDisplay()
487 {
488 }
489
490
491 void
492 NavDisplay::init ()
493 {
494     _cachedItemsValid = false;
495     _cacheListener.reset(new CacheListener(this));
496     _forceUpdateListener.reset(new ForceUpdateListener(this));
497   
498     _serviceable_node = _Instrument->getNode("serviceable", true);
499     _rangeNode = _Instrument->getNode("range", true);
500     if (!_rangeNode->hasValue()) {
501       _rangeNode->setDoubleValue(40.0);
502     }
503     _rangeNode->addChangeListener(_cacheListener.get());
504     _rangeNode->addChangeListener(_forceUpdateListener.get());
505   
506     _xCenterNode = _Instrument->getNode("x-center");
507     if (!_xCenterNode->hasValue()) {
508       _xCenterNode->setDoubleValue(0.5);
509     }
510     _xCenterNode->addChangeListener(_forceUpdateListener.get());
511     _yCenterNode = _Instrument->getNode("y-center");
512     if (!_yCenterNode->hasValue()) {
513       _yCenterNode->setDoubleValue(0.5);
514     }
515     _yCenterNode->addChangeListener(_forceUpdateListener.get());
516   
517     // texture name to use in 2D and 3D instruments
518     _texture_path = _Instrument->getStringValue("radar-texture-path",
519         "Aircraft/Instruments/Textures/od_wxradar.rgb");
520     _resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), false);
521
522     string path = _Instrument->getStringValue("symbol-texture-path",
523         "Aircraft/Instruments/Textures/nd-symbols.png");
524     SGPath tpath = globals->resolve_aircraft_path(path);
525     if (!tpath.exists()) {
526       SG_LOG(SG_INSTR, SG_WARN, "ND symbol texture not found:" << path);
527     }
528   
529     // no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
530     _symbolTexture = SGLoadTexture2D(tpath, NULL, false, false);
531
532     FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation");
533     _odg = (FGODGauge *)imgr->get_subsystem("od_gauge");
534     _odg->setSize(_Instrument->getIntValue("texture-size", 512));
535
536     _route = static_cast<FGRouteMgr*>(globals->get_subsystem("route-manager"));
537     
538     _navRadio1Node = fgGetNode("/instrumentation/nav[0]", true);
539     _navRadio2Node = fgGetNode("/instrumentation/nav[1]", true);
540     
541     _excessDataNode = _Instrument->getChild("excess-data", 0, true);
542     _excessDataNode->setBoolValue(false);
543     _testModeNode = _Instrument->getChild("test-mode", 0, true);
544     _testModeNode->setBoolValue(false);
545   
546 // OSG geometry setup
547     _radarGeode = new osg::Geode;
548
549     _geom = new osg::Geometry;
550     _geom->setUseDisplayList(false);
551     
552     osg::StateSet *stateSet = _geom->getOrCreateStateSet();
553     stateSet->setTextureAttributeAndModes(0, _symbolTexture.get());
554     stateSet->setDataVariance(osg::Object::STATIC);
555   
556     // Initially allocate space for 128 quads
557     _vertices = new osg::Vec2Array;
558     _vertices->setDataVariance(osg::Object::DYNAMIC);
559     _vertices->reserve(128 * 4);
560     _geom->setVertexArray(_vertices);
561     _texCoords = new osg::Vec2Array;
562     _texCoords->setDataVariance(osg::Object::DYNAMIC);
563     _texCoords->reserve(128 * 4);
564     _geom->setTexCoordArray(0, _texCoords);
565     
566     _quadColors = new osg::Vec4Array;
567     _quadColors->setDataVariance(osg::Object::DYNAMIC);
568     _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
569     _geom->setColorArray(_quadColors);
570     
571     _symbolPrimSet = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
572     _symbolPrimSet->setDataVariance(osg::Object::DYNAMIC);
573     _geom->addPrimitiveSet(_symbolPrimSet);
574     
575     _geom->setInitialBound(osg::BoundingBox(osg::Vec3f(-256.0f, -256.0f, 0.0f),
576         osg::Vec3f(256.0f, 256.0f, 0.0f)));
577   
578     _radarGeode->addDrawable(_geom);
579     _odg->allocRT();
580     // Texture in the 2D panel system
581     FGTextureManager::addTexture(_texture_path.c_str(), _odg->getTexture());
582
583     _lineGeometry = new osg::Geometry;
584     _lineGeometry->setUseDisplayList(false);
585     stateSet = _lineGeometry->getOrCreateStateSet();    
586     osg::LineWidth *lw = new osg::LineWidth();
587     lw->setWidth(2.0);
588     stateSet->setAttribute(lw);
589     
590     _lineVertices = new osg::Vec2Array;
591     _lineVertices->setDataVariance(osg::Object::DYNAMIC);
592     _lineVertices->reserve(128 * 4);
593     _lineGeometry->setVertexArray(_lineVertices);
594     
595                   
596     _lineColors = new osg::Vec4Array;
597     _lineColors->setDataVariance(osg::Object::DYNAMIC);
598     _lineGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
599     _lineGeometry->setColorArray(_lineColors);
600     
601     _linePrimSet = new osg::DrawArrays(osg::PrimitiveSet::LINES);
602     _linePrimSet->setDataVariance(osg::Object::DYNAMIC);
603     _lineGeometry->addPrimitiveSet(_linePrimSet);
604     
605     _lineGeometry->setInitialBound(osg::BoundingBox(osg::Vec3f(-256.0f, -256.0f, 0.0f),
606                                             osg::Vec3f(256.0f, 256.0f, 0.0f)));
607
608     _radarGeode->addDrawable(_lineGeometry);              
609                   
610     _textGeode = new osg::Geode;
611
612     osg::Camera *camera = _odg->getCamera();
613     camera->addChild(_radarGeode.get());
614     camera->addChild(_textGeode.get());
615     osg::Texture2D* tex = _odg->getTexture();
616     camera->setProjectionMatrixAsOrtho2D(0, tex->getTextureWidth(), 
617         0, tex->getTextureHeight());
618     
619     updateFont();
620 }
621
622 void
623 NavDisplay::update (double delta_time_sec)
624 {
625   if (!fgGetBool("sim/sceneryloaded", false)) {
626     return;
627   }
628
629   if (!_odg || !_serviceable_node->getBoolValue()) {
630     _Instrument->setStringValue("status", "");
631     return;
632   }
633   
634   if (_forceUpdate) {
635     _forceUpdate = false;
636     _time = 0.0;
637   } else {
638     _time += delta_time_sec;
639     if (_time < _updateInterval){
640       return;
641     }
642     _time -= _updateInterval;
643   }
644
645   _rangeNm = _rangeNode->getFloatValue();
646   if (_testModeNode->getBoolValue()) {
647     _view_heading = 90;
648   } else if (_Instrument->getBoolValue("aircraft-heading-up", true)) {
649     _view_heading = fgGetDouble("/orientation/heading-deg");
650   } else {
651     _view_heading = _Instrument->getFloatValue("heading-up-deg", 0.0);
652   }
653   
654   double xCenterFrac = _xCenterNode->getDoubleValue();
655   double yCenterFrac = _yCenterNode->getDoubleValue();
656   int pixelSize = _odg->size();
657   
658   int rangePixels = _Instrument->getIntValue("range-pixels", -1);
659   if (rangePixels < 0) {
660     // hacky - assume (as is very common) that x-frac doesn't vary, and
661     // y-frac is used to position the center at either the top or bottom of
662     // the pixel area. Measure from the center to the furthest edge (top or bottom)
663     rangePixels = pixelSize * std::max(fabs(1.0 - yCenterFrac), fabs(yCenterFrac));
664   }
665   
666   _scale = rangePixels / _rangeNm;
667   _Instrument->setDoubleValue("scale", _scale);
668   
669   
670   _centerTrans = osg::Matrixf::translate(xCenterFrac * pixelSize, 
671       yCenterFrac * pixelSize, 0.0);
672
673 // scale from nm to display units, rotate so aircraft heading is up
674 // (as opposed to north), and compensate for centering
675   _projectMat = osg::Matrixf::scale(_scale, _scale, 1.0) * 
676       degRotation(-_view_heading) * _centerTrans;
677   
678   _pos = globals->get_aircraft_position();
679
680     // invalidate the cache of positioned items, if we travelled more than 1nm
681     if (_cachedItemsValid) {
682         SGVec3d cartNow(SGVec3d::fromGeod(_pos));
683         double movedNm = dist(_cachedPos, cartNow) * SG_METER_TO_NM;
684         _cachedItemsValid = (movedNm < 1.0);
685         if (!_cachedItemsValid) {
686             SG_LOG(SG_INSTR, SG_INFO, "invalidating NavDisplay cache due to moving: " << movedNm);
687         }
688     }
689     
690   _vertices->clear();
691   _lineVertices->clear();
692   _lineColors->clear();
693   _quadColors->clear();
694   _texCoords->clear();
695   _textGeode->removeDrawables(0, _textGeode->getNumDrawables());
696   
697   BOOST_FOREACH(SymbolInstance* si, _symbols) {
698       delete si;
699   }
700   _symbols.clear();
701     
702   BOOST_FOREACH(SymbolRule* r, _rules) {
703       r->checkEnabled();
704   }
705   
706   if (_testModeNode->getBoolValue()) {
707     addTestSymbols();
708   } else {
709     processRoute();
710     processNavRadios();
711     processAI();
712     findItems();
713     limitDisplayedSymbols();
714   }
715
716   addSymbolsToScene();
717   
718   _symbolPrimSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size());
719   _symbolPrimSet->dirty();
720   _linePrimSet->set(osg::PrimitiveSet::LINES, 0, _lineVertices->size());
721   _linePrimSet->dirty();
722 }
723
724
725 void
726 NavDisplay::updateFont()
727 {
728     float red = _font_node->getFloatValue("color/red");
729     float green = _font_node->getFloatValue("color/green");
730     float blue = _font_node->getFloatValue("color/blue");
731     float alpha = _font_node->getFloatValue("color/alpha");
732     _font_color.set(red, green, blue, alpha);
733
734     _font_size = _font_node->getFloatValue("size");
735     _font_spacing = _font_size * _font_node->getFloatValue("line-spacing");
736     string path = _font_node->getStringValue("name", DEFAULT_FONT);
737
738     SGPath tpath;
739     if (path[0] != '/') {
740         tpath = globals->get_fg_root();
741         tpath.append("Fonts");
742         tpath.append(path);
743     } else {
744         tpath = path;
745     }
746
747     osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
748     osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
749
750     if (font != 0) {
751         _font = font;
752         _font->setMinFilterHint(osg::Texture::NEAREST);
753         _font->setMagFilterHint(osg::Texture::NEAREST);
754         _font->setGlyphImageMargin(0);
755         _font->setGlyphImageMarginRatio(0);
756     }
757 }
758
759 void NavDisplay::addSymbolToScene(SymbolInstance* sym)
760 {
761     SymbolDef* def = sym->definition;
762     
763     osg::Vec2 verts[4];
764     verts[0] = def->xy0;
765     verts[1] = osg::Vec2(def->xy1.x(), def->xy0.y());
766     verts[2] = def->xy1;
767     verts[3] = osg::Vec2(def->xy0.x(), def->xy1.y());
768     
769     if (def->rotateToHeading) {
770         osg::Matrixf m(degRotation(sym->headingDeg - _view_heading));
771         for (int i=0; i<4; ++i) {
772             verts[i] = mult(verts[i], m);
773         }
774     }
775     
776     osg::Vec2 pos = sym->pos;
777     if (def->roundPos) {
778         pos = osg::Vec2((int) pos.x(), (int) pos.y());
779     }
780     
781     _texCoords->push_back(def->uv0);
782     _texCoords->push_back(osg::Vec2(def->uv1.x(), def->uv0.y()));
783     _texCoords->push_back(def->uv1);
784     _texCoords->push_back(osg::Vec2(def->uv0.x(), def->uv1.y()));
785
786     for (int i=0; i<4; ++i) {
787         _vertices->push_back(verts[i] + pos);
788         _quadColors->push_back(def->color);
789     }
790     
791     if (def->stretchSymbol) {
792         osg::Vec2 stretchVerts[4];
793         stretchVerts[0] = osg::Vec2(def->xy0.x(), def->stretchY2);
794         stretchVerts[1] = osg::Vec2(def->xy1.x(), def->stretchY2);
795         stretchVerts[2] = osg::Vec2(def->xy1.x(), def->stretchY3);
796         stretchVerts[3] = osg::Vec2(def->xy0.x(), def->stretchY3);
797         
798         osg::Matrixf m(degRotation(sym->headingDeg - _view_heading));
799         for (int i=0; i<4; ++i) {
800             stretchVerts[i] = mult(stretchVerts[i], m);
801         }
802         
803     // stretched quad
804         _vertices->push_back(verts[2] + pos);
805         _vertices->push_back(stretchVerts[1] + sym->endPos);
806         _vertices->push_back(stretchVerts[0] + sym->endPos);
807         _vertices->push_back(verts[3] + pos);
808         
809         _texCoords->push_back(def->uv1);
810         _texCoords->push_back(osg::Vec2(def->uv1.x(), def->stretchV2));
811         _texCoords->push_back(osg::Vec2(def->uv0.x(), def->stretchV2));
812         _texCoords->push_back(osg::Vec2(def->uv0.x(), def->uv1.y()));
813         
814         for (int i=0; i<4; ++i) {
815             _quadColors->push_back(def->color);
816         }
817         
818     // quad three, for the end portion
819         for (int i=0; i<4; ++i) {
820             _vertices->push_back(stretchVerts[i] + sym->endPos);
821             _quadColors->push_back(def->color);
822         }
823         
824         _texCoords->push_back(osg::Vec2(def->uv0.x(), def->stretchV2));
825         _texCoords->push_back(osg::Vec2(def->uv1.x(), def->stretchV2));
826         _texCoords->push_back(osg::Vec2(def->uv1.x(), def->stretchV3));
827         _texCoords->push_back(osg::Vec2(def->uv0.x(), def->stretchV3));
828     }
829     
830     if (def->drawLine) {
831         addLine(sym->pos, sym->endPos, def->lineColor);
832     }
833     
834     if (!def->hasText) {
835         return;
836     }
837     
838     osgText::Text* t = new osgText::Text;
839     t->setFont(_font.get());
840     t->setFontResolution(12, 12);
841     t->setCharacterSize(_font_size);
842     t->setLineSpacing(_font_spacing);
843     t->setColor(def->textColor);
844     t->setAlignment(def->alignment);
845     t->setText(sym->text());
846
847
848     osg::Vec2 textPos = def->textOffset + pos;
849 // ensure we use ints here, or text visual quality goes bad
850     t->setPosition(osg::Vec3((int)textPos.x(), (int)textPos.y(), 0));
851     _textGeode->addDrawable(t);
852 }
853
854 class OrderByPriority
855 {
856 public:
857     bool operator()(SymbolInstance* a, SymbolInstance* b)
858     {
859         return a->definition->priority > b->definition->priority;
860     }    
861 };
862
863 void NavDisplay::limitDisplayedSymbols()
864 {
865     unsigned int maxSymbols = _Instrument->getIntValue("max-symbols", 100);
866     if (_symbols.size() <= maxSymbols) {
867         _excessDataNode->setBoolValue(false);
868         return;
869     }
870     
871     std::sort(_symbols.begin(), _symbols.end(), OrderByPriority());
872     _symbols.resize(maxSymbols);
873     _excessDataNode->setBoolValue(true);
874 }
875
876 class OrderByZ
877 {
878 public:
879     bool operator()(SymbolInstance* a, SymbolInstance* b)
880     {
881         return a->definition->zOrder > b->definition->zOrder;
882     }
883 };
884
885 void NavDisplay::addSymbolsToScene()
886 {
887     std::sort(_symbols.begin(), _symbols.end(), OrderByZ());
888     BOOST_FOREACH(SymbolInstance* sym, _symbols) {
889         addSymbolToScene(sym);
890     }
891 }
892
893 void NavDisplay::addLine(osg::Vec2 a, osg::Vec2 b, const osg::Vec4& color)
894 {    
895     _lineVertices->push_back(a);
896     _lineVertices->push_back(b);
897     _lineColors->push_back(color);
898     _lineColors->push_back(color);
899 }
900
901 osg::Vec2 NavDisplay::projectBearingRange(double bearingDeg, double rangeNm) const
902 {
903     osg::Vec3 p(0, rangeNm, 0.0);
904     p = degRotation(bearingDeg).preMult(p);
905     p = _projectMat.preMult(p);
906     return osg::Vec2(p.x(), p.y());
907 }
908
909 osg::Vec2 NavDisplay::projectGeod(const SGGeod& geod) const
910 {
911     double rangeM, bearing, az2;
912     SGGeodesy::inverse(_pos, geod, bearing, az2, rangeM);
913     return projectBearingRange(bearing, rangeM * SG_METER_TO_NM);
914 }
915
916 class Filter : public FGPositioned::Filter
917 {
918 public:
919     double minRunwayLengthFt;
920   
921     virtual bool pass(FGPositioned* aPos) const
922     {
923         if (aPos->type() == FGPositioned::FIX) {
924             string ident(aPos->ident());
925             // ignore fixes which end in digits
926             if ((ident.size() > 4) && isdigit(ident[3]) && isdigit(ident[4])) {
927                 return false;
928             }
929         }
930
931         if (aPos->type() == FGPositioned::AIRPORT) {
932           FGAirport* apt = (FGAirport*) aPos;
933           if (!apt->hasHardRunwayOfLengthFt(minRunwayLengthFt)) {
934             return false;
935           }
936         }
937       
938         return true;
939     }
940
941     virtual FGPositioned::Type minType() const {
942         return FGPositioned::AIRPORT;
943     }
944
945     virtual FGPositioned::Type maxType() const {
946         return FGPositioned::OBSTACLE;
947     }
948 };
949
950 void NavDisplay::findItems()
951 {
952     if (!_cachedItemsValid) {
953         SG_LOG(SG_INSTR, SG_INFO, "re-validating NavDisplay cache");
954         Filter filt;
955         filt.minRunwayLengthFt = 2000;
956         _itemsInRange = FGPositioned::findWithinRange(_pos, _rangeNm, &filt);
957         _cachedItemsValid = true;
958         _cachedPos = SGVec3d::fromGeod(_pos);
959     }
960     
961     BOOST_FOREACH(FGPositioned* pos, _itemsInRange) {
962         foundPositionedItem(pos);
963     }
964 }
965
966 void NavDisplay::processRoute()
967 {
968     _routeSources.clear();
969     RoutePath path(_route->waypts());
970     int current = _route->currentIndex();
971     
972     for (int w=0; w<_route->numWaypts(); ++w) {
973         flightgear::WayptRef wpt(_route->wayptAtIndex(w));
974         _routeSources.insert(wpt->source());
975         
976         string_set state;
977         state.insert("on-active-route");
978         
979         if (w < current) {
980             state.insert("passed");
981         }
982         
983         if (w == current) {
984             state.insert("current-wp");
985         }
986         
987         if (w > current) {
988             state.insert("future");
989         }
990         
991         if (w == (current + 1)) {
992             state.insert("next-wp");
993         }
994         
995         SymbolRuleVector rules;
996         findRules("waypoint" , state, rules);
997         if (rules.empty()) {
998             return; // no rules matched, we can skip this item
999         }
1000
1001         SGGeod g = path.positionForIndex(w);
1002         SGPropertyNode* vars = _route->wayptNodeAtIndex(w);
1003         double heading;
1004         computeWayptPropsAndHeading(wpt, g, vars, heading);
1005
1006         osg::Vec2 projected = projectGeod(g);
1007         BOOST_FOREACH(SymbolRule* r, rules) {
1008             addSymbolInstance(projected, heading, r->getDefinition(), vars);
1009             
1010             if (r->getDefinition()->drawRouteLeg) {
1011                 SGGeodVec gv(path.pathForIndex(w));
1012                 if (!gv.empty()) {
1013                     osg::Vec2 pr = projectGeod(gv[0]);
1014                     for (unsigned int i=1; i<gv.size(); ++i) {
1015                         osg::Vec2 p = projectGeod(gv[i]);
1016                         addLine(pr, p, r->getDefinition()->lineColor);
1017                         pr = p;
1018                     }
1019                 }
1020             } // of leg drawing enabled
1021         } // of matching rules iteration
1022     } // of waypoints iteration
1023 }
1024
1025 void NavDisplay::computeWayptPropsAndHeading(flightgear::Waypt* wpt, const SGGeod& pos, SGPropertyNode* nd, double& heading)
1026 {
1027     double rangeM, az2;
1028     SGGeodesy::inverse(_pos, pos, heading, az2, rangeM);
1029     nd->setIntValue("radial", heading);
1030     nd->setDoubleValue("distance-nm", rangeM * SG_METER_TO_NM);
1031     
1032     heading = nd->getDoubleValue("leg-bearing-true-deg");
1033 }
1034
1035 void NavDisplay::processNavRadios()
1036 {
1037     _nav1Station = processNavRadio(_navRadio1Node);
1038     _nav2Station = processNavRadio(_navRadio2Node);
1039     
1040     foundPositionedItem(_nav1Station);
1041     foundPositionedItem(_nav2Station);
1042 }
1043
1044 FGNavRecord* NavDisplay::processNavRadio(const SGPropertyNode_ptr& radio)
1045 {
1046     double mhz = radio->getDoubleValue("frequencies/selected-mhz", 0.0);
1047     FGNavRecord* nav = globals->get_navlist()->findByFreq(mhz, _pos);
1048     if (!nav || (nav->ident() != radio->getStringValue("nav-id"))) {
1049         // station was not found
1050         return NULL;
1051     }
1052     
1053     
1054     return nav;
1055 }
1056
1057 bool NavDisplay::anyRuleForType(const string& type) const
1058 {
1059     BOOST_FOREACH(SymbolRule* r, _rules) {
1060         if (!r->enabled) {
1061             continue;
1062         }
1063     
1064         if (r->type == type) {
1065             return true;
1066         }
1067     }
1068     
1069     return false;
1070 }
1071
1072 bool NavDisplay::anyRuleMatches(const string& type, const string_set& states) const
1073 {
1074     BOOST_FOREACH(SymbolRule* r, _rules) {
1075         if (!r->enabled || (r->type != type)) {
1076             continue;
1077         }
1078
1079         if (r->matches(states)) {
1080             return true;
1081         }
1082     } // of rules iteration
1083     
1084     return false;
1085 }
1086
1087 void NavDisplay::findRules(const string& type, const string_set& states, SymbolRuleVector& rules)
1088 {
1089     BOOST_FOREACH(SymbolRule* candidate, _rules) {
1090         if (!candidate->enabled || (candidate->type != type)) {
1091             continue;
1092         }
1093         
1094         if (candidate->matches(states)) {
1095             rules.push_back(candidate);
1096         }
1097     }
1098 }
1099
1100 void NavDisplay::foundPositionedItem(FGPositioned* pos)
1101 {
1102     if (!pos) {
1103         return;
1104     }
1105     
1106     string type = FGPositioned::nameForType(pos->type());
1107     if (!anyRuleForType(type)) {
1108         return; // not diplayed at all, we're done
1109     }
1110     
1111     string_set states;
1112     computePositionedState(pos, states);
1113     
1114     SymbolRuleVector rules;
1115     findRules(type, states, rules);
1116     if (rules.empty()) {
1117         return; // no rules matched, we can skip this item
1118     }
1119     
1120     SGPropertyNode_ptr vars(new SGPropertyNode);
1121     double heading;
1122     computePositionedPropsAndHeading(pos, vars, heading);
1123     
1124     osg::Vec2 projected = projectGeod(pos->geod());
1125     if (pos->type() == FGPositioned::RUNWAY) {
1126         FGRunway* rwy = (FGRunway*) pos;
1127         projected = projectGeod(rwy->threshold());
1128     }
1129     
1130     BOOST_FOREACH(SymbolRule* r, rules) {
1131         SymbolInstance* ins = addSymbolInstance(projected, heading, r->getDefinition(), vars);
1132         if (pos->type() == FGPositioned::RUNWAY) {
1133             FGRunway* rwy = (FGRunway*) pos;
1134             ins->endPos = projectGeod(rwy->end());
1135         }
1136     }
1137 }
1138
1139 void NavDisplay::computePositionedPropsAndHeading(FGPositioned* pos, SGPropertyNode* nd, double& heading)
1140 {
1141     nd->setStringValue("id", pos->ident());
1142     nd->setStringValue("name", pos->name());
1143     nd->setDoubleValue("elevation-ft", pos->elevation());
1144     nd->setIntValue("heading-deg", 0);
1145     heading = 0.0;
1146     
1147     switch (pos->type()) {
1148     case FGPositioned::VOR:
1149     case FGPositioned::LOC: 
1150     case FGPositioned::TACAN: {
1151         FGNavRecord* nav = static_cast<FGNavRecord*>(pos);
1152         nd->setDoubleValue("frequency-mhz", nav->get_freq());
1153         
1154         if (pos == _nav1Station) {
1155             heading = _navRadio1Node->getDoubleValue("radials/target-radial-deg");
1156         } else if (pos == _nav2Station) {
1157             heading = _navRadio2Node->getDoubleValue("radials/target-radial-deg");
1158         }
1159         
1160         nd->setIntValue("heading-deg", heading);
1161         break;
1162     }
1163
1164     case FGPositioned::AIRPORT:
1165     case FGPositioned::SEAPORT:
1166     case FGPositioned::HELIPORT:
1167         
1168         break;
1169         
1170     case FGPositioned::RUNWAY: {
1171         FGRunway* rwy = static_cast<FGRunway*>(pos);
1172         heading = rwy->headingDeg();
1173         nd->setDoubleValue("heading-deg", heading);
1174         nd->setIntValue("length-ft", rwy->lengthFt());
1175         nd->setStringValue("airport", rwy->airport()->ident());
1176         break;
1177     }
1178
1179     default:
1180         break; 
1181     }
1182 }
1183
1184 void NavDisplay::computePositionedState(FGPositioned* pos, string_set& states)
1185 {
1186     if (_routeSources.count(pos) != 0) {
1187         states.insert("on-active-route");
1188     }
1189     
1190     switch (pos->type()) {
1191     case FGPositioned::VOR:
1192     case FGPositioned::LOC:
1193         if (pos == _nav1Station) {
1194             states.insert("tuned");
1195             states.insert("nav1");
1196         }
1197         
1198         if (pos == _nav2Station) {
1199             states.insert("tuned");
1200             states.insert("nav2");
1201         }
1202         break;
1203     
1204     case FGPositioned::AIRPORT:
1205     case FGPositioned::SEAPORT:
1206     case FGPositioned::HELIPORT:
1207         // mark alternates!
1208         // once the FMS system has some way to tell us about them, of course
1209         
1210         if (pos == _route->departureAirport()) {
1211             states.insert("departure");
1212         }
1213         
1214         if (pos == _route->destinationAirport()) {
1215             states.insert("destination");
1216         }
1217         break;
1218     
1219     case FGPositioned::RUNWAY:
1220         if (pos == _route->departureRunway()) {
1221             states.insert("departure");
1222         }
1223         
1224         if (pos == _route->destinationRunway()) {
1225             states.insert("destination");
1226         }
1227         break;
1228     
1229     case FGPositioned::OBSTACLE:
1230     #if 0    
1231         FGObstacle* obs = (FGObstacle*) pos;
1232         if (obj->isLit()) {
1233             states.insert("lit");
1234         }
1235         
1236         if (obj->getHeightAGLFt() >= 1000) {
1237             states.insert("greater-1000-ft");
1238         }
1239     #endif
1240         break;
1241     
1242     default:
1243         break;
1244     } // FGPositioned::Type switch
1245 }
1246
1247 static string mapAINodeToType(SGPropertyNode* model)
1248 {
1249   // assume all multiplayer items are aircraft for the moment. Not ideal.
1250   if (!strcmp(model->getName(), "multiplayer")) {
1251     return "ai-aircraft";
1252   }
1253   
1254   return string("ai-") + model->getName();
1255 }
1256
1257 void NavDisplay::processAI()
1258 {
1259     SGPropertyNode *ai = fgGetNode("/ai/models", true);
1260     for (int i = ai->nChildren() - 1; i >= 0; i--) {
1261         SGPropertyNode *model = ai->getChild(i);
1262         if (!model->nChildren()) {
1263             continue;
1264         }
1265         
1266     // prefix types with 'ai-', to avoid any chance of namespace collisions
1267     // with fg-positioned.
1268         string_set ss;
1269         computeAIStates(model, ss);        
1270         SymbolRuleVector rules;
1271         findRules(mapAINodeToType(model), ss, rules);
1272         if (rules.empty()) {
1273             return; // no rules matched, we can skip this item
1274         }
1275
1276         double heading = model->getDoubleValue("orientation/true-heading-deg");
1277         SGGeod aiModelPos = SGGeod::fromDegFt(model->getDoubleValue("position/longitude-deg"), 
1278                                             model->getDoubleValue("position/latitude-deg"), 
1279                                             model->getDoubleValue("position/altitude-ft"));
1280     // compute some additional props
1281         int fl = (aiModelPos.getElevationFt() / 1000);
1282         model->setIntValue("flight-level", fl * 10);
1283                                             
1284         osg::Vec2 projected = projectGeod(aiModelPos);
1285         BOOST_FOREACH(SymbolRule* r, rules) {
1286             addSymbolInstance(projected, heading, r->getDefinition(), (SGPropertyNode*) model);
1287         }
1288     } // of ai models iteration
1289 }
1290
1291 void NavDisplay::computeAIStates(const SGPropertyNode* ai, string_set& states)
1292 {
1293     int threatLevel = ai->getIntValue("tcas/threat-level",-1);
1294     if (threatLevel < 1)
1295       threatLevel = 0;
1296   
1297     states.insert("tcas");
1298   
1299     std::ostringstream os;
1300     os << "tcas-threat-level-" << threatLevel;
1301     states.insert(os.str());
1302
1303     double vspeed = ai->getDoubleValue("velocities/vertical-speed-fps");
1304     if (vspeed < -3.0) {
1305         states.insert("descending");
1306     } else if (vspeed > 3.0) {
1307         states.insert("climbing");
1308     }
1309 }
1310
1311 SymbolInstance* NavDisplay::addSymbolInstance(const osg::Vec2& proj, double heading, SymbolDef* def, SGPropertyNode* vars)
1312 {
1313     if (isProjectedClipped(proj)) {
1314         return NULL;
1315     }
1316     
1317     SymbolInstance* sym = new SymbolInstance(proj, heading, def, vars);
1318     _symbols.push_back(sym);
1319     return sym;
1320 }
1321
1322 bool NavDisplay::isProjectedClipped(const osg::Vec2& projected) const
1323 {
1324     double size = _odg->size();
1325     return (projected.x() < 0.0) ||
1326         (projected.y() < 0.0) ||
1327         (projected.x() >= size) ||
1328             (projected.y() >= size);
1329 }
1330
1331 void NavDisplay::addTestSymbol(const std::string& type, const std::string& states, const SGGeod& pos, double heading, SGPropertyNode* vars)
1332 {
1333   string_set stateSet;
1334   BOOST_FOREACH(std::string s, simgear::strutils::split(states, ",")) {
1335     stateSet.insert(s);
1336   }
1337   
1338   SymbolRuleVector rules;
1339   findRules(type, stateSet, rules);
1340   if (rules.empty()) {
1341     return; // no rules matched, we can skip this item
1342   }
1343     
1344   osg::Vec2 projected = projectGeod(pos);
1345   BOOST_FOREACH(SymbolRule* r, rules) {
1346     addSymbolInstance(projected, heading, r->getDefinition(), vars);
1347   }
1348 }
1349
1350 void NavDisplay::addTestSymbols()
1351 {
1352   _pos = SGGeod::fromDeg(-122.3748889, 37.6189722); // KSFO
1353   
1354   SGGeod a1;
1355   double dummy;
1356   SGGeodesy::direct(_pos, 45.0, 20.0 * SG_NM_TO_METER, a1, dummy);
1357   
1358   addTestSymbol("airport", "", a1, 0.0, NULL);
1359   
1360   SGGeodesy::direct(_pos, 95.0, 40.0 * SG_NM_TO_METER, a1, dummy);
1361   
1362   addTestSymbol("vor", "", a1, 0.0, NULL);
1363   
1364   SGGeodesy::direct(_pos, 120, 80.0 * SG_NM_TO_METER, a1, dummy);
1365   
1366   addTestSymbol("airport", "destination", a1, 0.0, NULL);
1367   
1368   SGGeodesy::direct(_pos, 80.0, 20.0 * SG_NM_TO_METER, a1, dummy);  
1369   addTestSymbol("fix", "", a1, 0.0, NULL);
1370
1371   
1372   SGGeodesy::direct(_pos, 140.0, 20.0 * SG_NM_TO_METER, a1, dummy);  
1373   addTestSymbol("fix", "", a1, 0.0, NULL);
1374   
1375   SGGeodesy::direct(_pos, 110.0, 10.0 * SG_NM_TO_METER, a1, dummy);  
1376   addTestSymbol("fix", "", a1, 0.0, NULL);
1377   
1378   SGGeodesy::direct(_pos, 110.0, 5.0 * SG_NM_TO_METER, a1, dummy);  
1379   addTestSymbol("fix", "", a1, 0.0, NULL);
1380 }
1381
1382 void NavDisplay::addRule(SymbolRule* r)
1383 {
1384     _rules.push_back(r);
1385 }
1386