1
0
Fork 0

For the agRadar, initialize property nodes with defaults.

Introduce a convenience member function in wxRadarBg for creating an
SGPropertyNode and initializing it in one step. Use this in
agRadar. This eliminates buggy behavior when the necessary radar
properties aren't defined.
This commit is contained in:
timoore 2008-03-22 09:19:21 +00:00
parent 7800918499
commit 662ea715e8
3 changed files with 96 additions and 40 deletions

View file

@ -71,25 +71,28 @@ agRadar::init ()
_Instrument->setBoolValue("stabilisation/roll", false); _Instrument->setBoolValue("stabilisation/roll", false);
_Instrument->setBoolValue("stabilisation/pitch", false); _Instrument->setBoolValue("stabilisation/pitch", false);
_Instrument->getNode("antenna/x-offset-m", true); _xOffsetMNode = getInstrumentNode("antenna/x-offset-m", 0.0);
_Instrument->getNode("antenna/y-offset-m", true); _yOffsetMNode = getInstrumentNode("antenna/y-offset-m", 0.0);
_Instrument->getNode("antenna/z-offset-m", true); _zOffsetMNode = getInstrumentNode("antenna/z-offset-m", 0.0);
_Instrument->getNode("terrain-warning/elev-limit-deg", true); _elevLimitDegNode = getInstrumentNode("terrain-warning/elev-limit-deg", 2.0);
_Instrument->getNode("terrain-warning/elev-step-deg", true); _elevStepDegNode = getInstrumentNode("terrain-warning/elev-step-deg", 1.0);
_Instrument->getNode("terrain-warning/az-limit-deg", true); _azLimitDegNode = getInstrumentNode("terrain-warning/az-limit-deg", 1.0);
_Instrument->getNode("terrain-warning/az-step-deg", true); _azStepDegNode = getInstrumentNode("terrain-warning/az-step-deg", 1.5);
_Instrument->getNode("terrain-warning/max-range-m", true); _maxRangeMNode = getInstrumentNode("terrain-warning/max-range-m", 4000.0);
_Instrument->getNode("terrain-warning/min-range-m", true); _minRangeMNode = getInstrumentNode("terrain-warning/min-range-m", 250.0);
_Instrument->getNode("terrain-warning/tilt",true); _tiltNode = getInstrumentNode("terrain-warning/tilt", -2.0);
_Instrument->getNode("terrain-warning/hit/brg-deg", true); _brgDegNode = getInstrumentNode("terrain-warning/hit/brg-deg", 0.0);
_Instrument->getNode("terrain-warning/hit/range-m", true); _rangeMNode = getInstrumentNode("terrain-warning/hit/range-m", 0.0);
_Instrument->getNode("terrain-warning/hit/material", true); _elevationMNode = getInstrumentNode("terrain-warning/hit/elevation-m", 0.0);
_Instrument->getNode("terrain-warning/hit/bumpiness", true); _materialNode = getInstrumentNode("terrain-warning/hit/material", "");
_bumpinessNode = getInstrumentNode("terrain-warning/hit/bumpiness", 0.0);
_Instrument->getNode("terrain-warning/stabilisation/roll", true); _rollStabNode = getInstrumentNode("terrain-warning/stabilisation/roll",
_Instrument->getNode("terrain-warning/stabilisation/pitch", true); true);
_pitchStabNode = getInstrumentNode("terrain-warning/stabilisation/pitch",
false);
// cout << "init done" << endl; // cout << "init done" << endl;
} }
@ -143,9 +146,9 @@ agRadar::getCartAntennaPos() const {
float pitch = _user_pitch_deg_node->getDoubleValue(); float pitch = _user_pitch_deg_node->getDoubleValue();
float roll = _user_roll_deg_node->getDoubleValue(); float roll = _user_roll_deg_node->getDoubleValue();
double x_offset_m =_Instrument->getDoubleValue("antenna/x-offset-m", 0); double x_offset_m =_xOffsetMNode->getDoubleValue();
double y_offset_m =_Instrument->getDoubleValue("antenna/y-offset-m", 0); double y_offset_m =_yOffsetMNode->getDoubleValue();
double z_offset_m =_Instrument->getDoubleValue("antenna/y-offset-m", 0); double z_offset_m =_zOffsetMNode->getDoubleValue();
// convert geodetic positions to geocentered // convert geodetic positions to geocentered
SGVec3d cartuserPos = getCartUserPos(); SGVec3d cartuserPos = getCartUserPos();
@ -253,8 +256,8 @@ agRadar::update_terrain()
double max_range = 40000; double max_range = 40000;
double min_range = 250; double min_range = 250;
double tilt = -2.5; double tilt = -2.5;
bool roll_stab = _Instrument->getBoolValue("stabilisation/roll"); bool roll_stab = _rollStabNode->getBoolValue();
bool pitch_stab = _Instrument->getBoolValue("stabilisation/pitch"); bool pitch_stab = _pitchStabNode->getBoolValue();
//string status = ""; //string status = "";
const char* status; const char* status;
bool hdg_mkr = true; bool hdg_mkr = true;
@ -262,15 +265,13 @@ agRadar::update_terrain()
if (mode == 5){ if (mode == 5){
status = "TW"; status = "TW";
hdg_mkr = false; hdg_mkr = false;
roll_stab = _Instrument->getBoolValue("terrain-warning/stabilisation/roll", true); tilt = _tiltNode->getDoubleValue();
pitch_stab = _Instrument->getBoolValue("terrain-warning/stabilisation/pitch", false); el_limit = _elevLimitDegNode->getDoubleValue();
tilt = _Instrument->getDoubleValue("terrain-warning/tilt", -2); el_step = _elevStepDegNode->getDoubleValue();
el_limit = _Instrument->getDoubleValue("terrain-warning/elev-limit-deg", 2); az_limit = _azLimitDegNode->getDoubleValue();
el_step = _Instrument->getDoubleValue("terrain-warning/elev-step-deg", 1); az_step = _azStepDegNode->getDoubleValue();
az_limit = _Instrument->getDoubleValue("terrain-warning/az-limit-deg", 1); max_range = _maxRangeMNode->getDoubleValue();
az_step = _Instrument->getDoubleValue("terrain-warning/az-step-deg", 1.5); min_range = _minRangeMNode->getDoubleValue();
max_range = _Instrument->getDoubleValue("terrain-warning/max-range-m", 4000);
min_range = _Instrument->getDoubleValue("terrain-warning/min-range-m", 250);
} }
_Instrument->setDoubleValue("tilt", tilt); _Instrument->setDoubleValue("tilt", tilt);
@ -297,18 +298,18 @@ agRadar::update_terrain()
if (distance >= min_range && distance <= max_range) { if (distance >= min_range && distance <= max_range) {
_terrain_warning_node->setBoolValue(true); _terrain_warning_node->setBoolValue(true);
getMaterial(); getMaterial();
_Instrument->setDoubleValue("terrain-warning/hit/brg-deg", course2); _brgDegNode->setDoubleValue(course2);
_Instrument->setDoubleValue("terrain-warning/hit/range-m", distance); _rangeMNode->setDoubleValue(distance);
_Instrument->setStringValue("terrain-warning/hit/material", _mat_name.c_str()); _materialNode->setStringValue(_mat_name.c_str());
_Instrument->setDoubleValue("terrain-warning/hit/bumpiness", _bumpinessFactor); _bumpinessNode->setDoubleValue(_bumpinessFactor);
_Instrument->setDoubleValue("terrain-warning/hit/elevation-m", _elevation_m); _elevationMNode->setDoubleValue(_elevation_m);
} else { } else {
_terrain_warning_node->setBoolValue(false); _terrain_warning_node->setBoolValue(false);
_Instrument->setDoubleValue("terrain-warning/hit/brg-deg", 0); _brgDegNode->setDoubleValue(0);
_Instrument->setDoubleValue("terrain-warning/hit/range-m", 0); _rangeMNode->setDoubleValue(0);
_Instrument->setStringValue("terrain-warning/hit/material", ""); _materialNode->setStringValue("");
_Instrument->setDoubleValue("terrain-warning/hit/bumpiness", 0); _bumpinessNode->setDoubleValue(0);
_Instrument->setDoubleValue("terrain-warning/hit/elevation-m",0); _elevationMNode->setDoubleValue(0);
} }
//cout << "usr hdg " << _user_hdg_deg_node->getDoubleValue() //cout << "usr hdg " << _user_hdg_deg_node->getDoubleValue()

View file

@ -67,6 +67,27 @@ public:
SGPropertyNode_ptr _user_pitch_deg_node; SGPropertyNode_ptr _user_pitch_deg_node;
SGPropertyNode_ptr _terrain_warning_node; SGPropertyNode_ptr _terrain_warning_node;
SGPropertyNode_ptr _xOffsetMNode;
SGPropertyNode_ptr _yOffsetMNode;
SGPropertyNode_ptr _zOffsetMNode;
SGPropertyNode_ptr _elevLimitDegNode;
SGPropertyNode_ptr _elevStepDegNode;
SGPropertyNode_ptr _azLimitDegNode;
SGPropertyNode_ptr _azStepDegNode;
SGPropertyNode_ptr _maxRangeMNode;
SGPropertyNode_ptr _minRangeMNode;
SGPropertyNode_ptr _tiltNode;
SGPropertyNode_ptr _brgDegNode;
SGPropertyNode_ptr _rangeMNode;
SGPropertyNode_ptr _elevationMNode;
SGPropertyNode_ptr _materialNode;
SGPropertyNode_ptr _bumpinessNode;
SGPropertyNode_ptr _rollStabNode;
SGPropertyNode_ptr _pitchStabNode;
SGGeod userpos; SGGeod userpos;
SGGeod hitpos; SGGeod hitpos;
SGGeod antennapos; SGGeod antennapos;

View file

@ -76,6 +76,11 @@ public:
FGODGauge *_odg; FGODGauge *_odg;
// Convenience function for creating a property node with a
// default value
template<typename DefaultType>
SGPropertyNode* getInstrumentNode(const char* name, DefaultType value);
private: private:
string _texture_path; string _texture_path;
@ -152,4 +157,33 @@ private:
}; };
template<> inline
SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, bool value)
{
SGPropertyNode* result = _Instrument->getNode(name, true);
if (result->getType() == SGPropertyNode::NONE)
result->setBoolValue(value);
return result;
}
template<> inline
SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, double value)
{
SGPropertyNode* result = _Instrument->getNode(name, true);
if (result->getType() == SGPropertyNode::NONE)
result->setDoubleValue(value);
return result;
}
template<> inline
SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name,
const char* value)
{
SGPropertyNode* result = _Instrument->getNode(name, true);
if (result->getType() == SGPropertyNode::NONE)
result->setStringValue(value);
return result;
}
#endif // _INST_WXRADAR_HXX #endif // _INST_WXRADAR_HXX