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