1 #ifndef __FREQUENCY_FORMATTER_HXX
2 #define __FREQUENCY_FORMATTER_HXX
4 /* ------------- A NAV/COMM Frequency formatter ---------------------- */
6 class FrequencyFormatter : public SGPropertyChangeListener {
8 FrequencyFormatter( SGPropertyNode_ptr freqNode, SGPropertyNode_ptr fmtFreqNode, double channelSpacing, double min, double max ) :
10 _fmtFreqNode( fmtFreqNode ),
11 _channelSpacing(channelSpacing),
15 _freqNode->addChangeListener( this );
16 valueChanged(_freqNode);
20 _freqNode->removeChangeListener( this );
23 void valueChanged (SGPropertyNode * prop)
25 // format as fixed decimal "nnn.nn"
26 std::ostringstream buf;
30 << std::setprecision(2)
32 _fmtFreqNode->setStringValue( buf.str() );
35 double getFrequency() const
37 double d = SGMiscd::roundToInt(_freqNode->getDoubleValue() / _channelSpacing) * _channelSpacing;
38 // strip last digit, do not round
39 double f = ((int)(d*100))/100.0;
40 if( f < _min ) return _min;
41 if( f >= _max ) return _max;
46 SGPropertyNode_ptr _freqNode;
47 SGPropertyNode_ptr _fmtFreqNode;
48 double _channelSpacing;
54 #endif //__FREQUENCY_FORMATTER_HXX