1 // fg_props.cxx -- support for FlightGear properties.
3 // Written by David Megginson, started 2000.
5 // Copyright (C) 2000, 2001 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 # include <simgear/compiler.h>
27 #include <simgear/misc/exception.hxx>
28 #include <simgear/magvar/magvar.hxx>
29 #include <simgear/timing/sg_time.hxx>
30 #include <simgear/misc/sg_path.hxx>
34 #include <ATC/ATCdisplay.hxx>
35 #include <Aircraft/aircraft.hxx>
36 #include <Time/tmp.hxx>
37 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
39 # include <WeatherCM/FGLocalWeatherDatabase.h>
41 # include <Environment/environment.hxx>
42 #endif // FG_WEATHERCM
43 #include <Objects/matlib.hxx>
46 #include <Sound/soundmgr.hxx>
48 #include "globals.hxx"
50 #include "fg_props.hxx"
52 SG_USING_STD(istream);
53 SG_USING_STD(ostream);
56 static double getWindNorth ();
57 static double getWindEast ();
58 static double getWindDown ();
59 #endif // FG_WEATHERCM
61 static bool winding_ccw = true; // FIXME: temporary
63 static bool fdm_data_logging = false; // FIXME: temporary
65 static bool frozen = false; // FIXME: temporary
69 ////////////////////////////////////////////////////////////////////////
70 // Default property bindings (not yet handled by any module).
71 ////////////////////////////////////////////////////////////////////////
73 struct LogClassMapping {
76 LogClassMapping(sgDebugClass cc, string nname) { c = cc; name = nname; }
79 LogClassMapping log_class_mappings [] = {
80 LogClassMapping(SG_NONE, "none"),
81 LogClassMapping(SG_TERRAIN, "terrain"),
82 LogClassMapping(SG_ASTRO, "astro"),
83 LogClassMapping(SG_FLIGHT, "flight"),
84 LogClassMapping(SG_INPUT, "input"),
85 LogClassMapping(SG_GL, "gl"),
86 LogClassMapping(SG_VIEW, "view"),
87 LogClassMapping(SG_COCKPIT, "cockpit"),
88 LogClassMapping(SG_GENERAL, "general"),
89 LogClassMapping(SG_MATH, "math"),
90 LogClassMapping(SG_EVENT, "event"),
91 LogClassMapping(SG_AIRCRAFT, "aircraft"),
92 LogClassMapping(SG_AUTOPILOT, "autopilot"),
93 LogClassMapping(SG_IO, "io"),
94 LogClassMapping(SG_CLIPPER, "clipper"),
95 LogClassMapping(SG_NETWORK, "network"),
96 LogClassMapping(SG_UNDEFD, "")
101 * Get the logging classes.
106 sgDebugClass classes = logbuf::get_log_classes();
107 static string result = ""; // FIXME
108 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
109 if ((classes&log_class_mappings[i].c) > 0) {
112 result += log_class_mappings[i].name;
115 return result.c_str();
120 addLoggingClass (const string &name)
122 sgDebugClass classes = logbuf::get_log_classes();
123 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
124 if (name == log_class_mappings[i].name) {
125 logbuf::set_log_classes(sgDebugClass(classes|log_class_mappings[i].c));
129 SG_LOG(SG_GENERAL, SG_ALERT, "Unknown logging class: " << name);
134 * Set the logging classes.
137 setLoggingClasses (const char * c)
140 logbuf::set_log_classes(SG_NONE);
142 if (classes == "none") {
143 SG_LOG(SG_GENERAL, SG_INFO, "Disabled all logging classes");
147 if (classes.empty() || classes == "all") { // default
148 logbuf::set_log_classes(SG_ALL);
149 SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
150 << getLoggingClasses());
154 string rest = classes;
156 int sep = rest.find('|');
158 name = rest.substr(0, sep);
159 rest = rest.substr(sep+1);
160 addLoggingClass(name);
161 sep = rest.find('|');
163 addLoggingClass(rest);
164 SG_LOG(SG_GENERAL, SG_INFO, "Set logging classes to "
165 << getLoggingClasses());
170 * Get the logging priority.
173 getLoggingPriority ()
175 switch (logbuf::get_log_priority()) {
187 SG_LOG(SG_GENERAL, SG_WARN, "Internal: Unknown logging priority number: "
188 << logbuf::get_log_priority());
195 * Set the logging priority.
198 setLoggingPriority (const char * p)
201 if (priority == "bulk") {
202 logbuf::set_log_priority(SG_BULK);
203 } else if (priority == "debug") {
204 logbuf::set_log_priority(SG_DEBUG);
205 } else if (priority.empty() || priority == "info") { // default
206 logbuf::set_log_priority(SG_INFO);
207 } else if (priority == "warn") {
208 logbuf::set_log_priority(SG_WARN);
209 } else if (priority == "alert") {
210 logbuf::set_log_priority(SG_ALERT);
212 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
214 SG_LOG(SG_GENERAL, SG_INFO, "Logging priority is " << getLoggingPriority());
219 * Return the current frozen state.
229 * Set the current frozen state.
236 // Stop sound on a pause
237 FGSoundMgr *s = globals->get_soundmgr();
249 * Return the current aircraft directory (UIUC) as a string.
254 return aircraft_dir.c_str();
259 * Set the current aircraft directory (UIUC).
262 setAircraftDir (const char * dir)
269 * Return the number of milliseconds elapsed since simulation started.
272 getElapsedTime_sec ()
274 return globals->get_sim_time_sec();
279 * Return the current Zulu time.
284 static char buf[64]; // FIXME
285 struct tm * t = globals->get_time_params()->getGmt();
286 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
287 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
288 t->tm_hour, t->tm_min, t->tm_sec);
294 * Set the current Zulu time.
297 setDateString (const char * date_string)
299 static const SGPropertyNode *cur_time_override
300 = fgGetNode("/sim/time/cur-time-override", true);
302 SGTime * st = globals->get_time_params();
303 struct tm * current_time = st->getGmt();
306 // Scan for basic ISO format
307 // YYYY-MM-DDTHH:MM:SS
308 int ret = sscanf(date_string, "%d-%d-%dT%d:%d:%d",
309 &(new_time.tm_year), &(new_time.tm_mon),
310 &(new_time.tm_mday), &(new_time.tm_hour),
311 &(new_time.tm_min), &(new_time.tm_sec));
313 // Be pretty picky about this, so
314 // that strange things don't happen
315 // if the save file has been edited
318 SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
319 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
323 // OK, it looks like we got six
324 // values, one way or another.
325 new_time.tm_year -= 1900;
326 new_time.tm_mon -= 1;
328 // Now, tell flight gear to use
329 // the new time. This was far
330 // too difficult, by the way.
332 mktime(&new_time) - mktime(current_time) + globals->get_warp();
333 double lon = current_aircraft.fdm_state->get_Longitude();
334 double lat = current_aircraft.fdm_state->get_Latitude();
335 globals->set_warp(warp);
336 st->update(lon, lat, cur_time_override->getLongValue(), warp);
337 fgUpdateSkyAndLightingParams();
341 * Return the GMT as a string.
346 static char buf[16]; // FIXME
347 struct tm *t = globals->get_time_params()->getGmt();
348 sprintf(buf, " %.2d:%.2d:%.2d",
349 t->tm_hour, t->tm_min, t->tm_sec);
350 // cout << t << " " << buf << endl;
356 * Get the texture rendering state.
361 return (material_lib.get_step() == 0);
366 * Set the texture rendering state.
369 setTextures (bool textures)
372 material_lib.set_step(0);
374 material_lib.set_step(1);
379 * Return the magnetic variation
384 return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
389 * Return the magnetic dip
394 return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
399 * Return the current heading in degrees.
404 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
411 * Get the current visibility (meters).
416 return WeatherDatabase->getWeatherVisibility();
421 * Set the current visibility (meters).
424 setVisibility (double visibility)
426 WeatherDatabase->setWeatherVisibility(visibility);
430 * Get the current wind north velocity (feet/second).
435 return current_aircraft.fdm_state->get_V_north_airmass();
440 * Set the current wind north velocity (feet/second).
443 setWindNorth (double speed)
445 current_aircraft.fdm_state
446 ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
451 * Get the current wind east velocity (feet/second).
456 return current_aircraft.fdm_state->get_V_east_airmass();
461 * Set the current wind east velocity (feet/second).
464 setWindEast (double speed)
466 cout << "Set wind-east to " << speed << endl;
467 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
474 * Get the current wind down velocity (feet/second).
479 return current_aircraft.fdm_state->get_V_down_airmass();
484 * Set the current wind down velocity (feet/second).
487 setWindDown (double speed)
489 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
494 #endif // FG_WEATHERCM
499 return globals->get_warp();
505 globals->set_warp(warp);
511 return globals->get_warp_delta();
515 setWarpDelta (long delta)
517 globals->set_warp_delta(delta);
527 setWindingCCW (bool state)
531 glFrontFace ( GL_CCW );
533 glFrontFace ( GL_CW );
539 #if defined(FX) && !defined(WIN32)
540 return globals->get_fullscreen();
547 setFullScreen (bool state)
549 #if defined(FX) && !defined(WIN32)
550 globals->set_fullscreen(state);
551 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
552 XMesaSetFXmode( state ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
560 return fdm_data_logging;
564 setFDMDataLogging (bool state)
566 // kludge; no getter or setter available
567 if (state != fdm_data_logging) {
568 fgToggleFDMdataLogging();
569 fdm_data_logging = state;
574 ////////////////////////////////////////////////////////////////////////
575 // Tie the properties.
576 ////////////////////////////////////////////////////////////////////////
581 cout << "start of fgInitProps()" << endl;
583 fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
584 fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
585 fgTie("/sim/freeze/master", getFreeze, setFreeze);
586 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
588 fgTie("/sim/time/elapsed-sec", getElapsedTime_sec);
589 fgTie("/sim/time/gmt", getDateString, setDateString);
590 fgSetArchivable("/sim/time/gmt");
591 fgTie("/sim/time/gmt-string", getGMTString);
592 fgTie("/sim/rendering/textures", getTextures, setTextures);
595 fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
599 fgTie("/environment/visibility-m", getVisibility, setVisibility);
600 fgSetArchivable("/environment/visibility-m");
601 fgTie("/environment/wind-from-north-fps", getWindNorth, setWindNorth);
602 fgSetArchivable("/environment/wind-from-north-fps");
603 fgTie("/environment/wind-from-east-fps", getWindEast, setWindEast);
604 fgSetArchivable("/environment/wind-from-east-fps");
605 fgTie("/environment/wind-from-down-fps", getWindDown, setWindDown);
606 fgSetArchivable("/environment/wind-from-down-fps");
609 fgTie("/environment/magnetic-variation-deg", getMagVar);
610 fgTie("/environment/magnetic-dip-deg", getMagDip);
612 fgTie("/sim/time/warp", getWarp, setWarp, false);
613 fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
615 // Misc. Temporary junk.
616 fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
617 fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
618 fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
620 cout << "end of fgInitProps()" << endl;
631 ////////////////////////////////////////////////////////////////////////
633 ////////////////////////////////////////////////////////////////////////
637 * Save the current state of the simulator to a stream.
640 fgSaveFlight (ostream &output, bool write_all)
643 fgSetBool("/sim/presets/onground", false);
644 fgSetArchivable("/sim/presets/onground");
645 fgSetBool("/sim/presets/trim", false);
646 fgSetArchivable("/sim/presets/trim");
647 fgSetString("/sim/presets/speed-set", "UVW");
648 fgSetArchivable("/sim/presets/speed-set");
651 writeProperties(output, globals->get_props(), write_all);
652 } catch (const sg_exception &e) {
653 guiErrorMessage("Error saving flight: ", e);
661 * Restore the current state of the simulator from a stream.
664 fgLoadFlight (istream &input)
666 SGPropertyNode props;
668 readProperties(input, &props);
669 } catch (const sg_exception &e) {
670 guiErrorMessage("Error reading saved flight: ", e);
674 fgSetBool("/sim/presets/onground", false);
675 fgSetBool("/sim/presets/trim", false);
676 fgSetString("/sim/presets/speed-set", "UVW");
678 copyProperties(&props, globals->get_props());
679 // When loading a flight, make it the
680 // new initial state.
681 globals->saveInitialState();
687 fgLoadProps (const char * path, SGPropertyNode * props)
689 SGPath loadpath(globals->get_fg_root());
690 loadpath.append(path);
691 readProperties(loadpath.c_str(), props);
696 ////////////////////////////////////////////////////////////////////////
697 // Property convenience functions.
698 ////////////////////////////////////////////////////////////////////////
701 fgGetNode (const char * path, bool create)
703 return globals->get_props()->getNode(path, create);
707 fgGetNode (const char * path, int index, bool create)
709 return globals->get_props()->getNode(path, index, create);
713 fgHasNode (const char * path)
715 return (fgGetNode(path, false) != 0);
719 fgAddChangeListener (SGPropertyChangeListener * listener, const char * path)
721 fgGetNode(path, true)->addChangeListener(listener);
725 fgAddChangeListener (SGPropertyChangeListener * listener,
726 const char * path, int index)
728 fgGetNode(path, index, true)->addChangeListener(listener);
732 fgGetBool (const char * name, bool defaultValue)
734 return globals->get_props()->getBoolValue(name, defaultValue);
738 fgGetInt (const char * name, int defaultValue)
740 return globals->get_props()->getIntValue(name, defaultValue);
744 fgGetLong (const char * name, long defaultValue)
746 return globals->get_props()->getLongValue(name, defaultValue);
750 fgGetFloat (const char * name, float defaultValue)
752 return globals->get_props()->getFloatValue(name, defaultValue);
756 fgGetDouble (const char * name, double defaultValue)
758 return globals->get_props()->getDoubleValue(name, defaultValue);
762 fgGetString (const char * name, const char * defaultValue)
764 return globals->get_props()->getStringValue(name, defaultValue);
768 fgSetBool (const char * name, bool val)
770 return globals->get_props()->setBoolValue(name, val);
774 fgSetInt (const char * name, int val)
776 return globals->get_props()->setIntValue(name, val);
780 fgSetLong (const char * name, long val)
782 return globals->get_props()->setLongValue(name, val);
786 fgSetFloat (const char * name, float val)
788 return globals->get_props()->setFloatValue(name, val);
792 fgSetDouble (const char * name, double val)
794 return globals->get_props()->setDoubleValue(name, val);
798 fgSetString (const char * name, const char * val)
800 return globals->get_props()->setStringValue(name, val);
804 fgSetArchivable (const char * name, bool state)
806 SGPropertyNode * node = globals->get_props()->getNode(name);
808 SG_LOG(SG_GENERAL, SG_ALERT,
809 "Attempt to set archive flag for non-existant property "
812 node->setAttribute(SGPropertyNode::ARCHIVE, state);
816 fgSetReadable (const char * name, bool state)
818 SGPropertyNode * node = globals->get_props()->getNode(name);
820 SG_LOG(SG_GENERAL, SG_ALERT,
821 "Attempt to set read flag for non-existant property "
824 node->setAttribute(SGPropertyNode::READ, state);
828 fgSetWritable (const char * name, bool state)
830 SGPropertyNode * node = globals->get_props()->getNode(name);
832 SG_LOG(SG_GENERAL, SG_ALERT,
833 "Attempt to set write flag for non-existant property "
836 node->setAttribute(SGPropertyNode::WRITE, state);
840 fgUntie (const char * name)
842 if (!globals->get_props()->untie(name))
843 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
849 ////////////////////////////////////////////////////////////////////////
850 // Implementation of FGCondition.
851 ////////////////////////////////////////////////////////////////////////
853 FGCondition::FGCondition ()
857 FGCondition::~FGCondition ()
863 ////////////////////////////////////////////////////////////////////////
864 // Implementation of FGPropertyCondition.
865 ////////////////////////////////////////////////////////////////////////
867 FGPropertyCondition::FGPropertyCondition (const char * propname)
868 : _node(fgGetNode(propname, true))
872 FGPropertyCondition::~FGPropertyCondition ()
878 ////////////////////////////////////////////////////////////////////////
879 // Implementation of FGNotCondition.
880 ////////////////////////////////////////////////////////////////////////
882 FGNotCondition::FGNotCondition (FGCondition * condition)
883 : _condition(condition)
887 FGNotCondition::~FGNotCondition ()
893 FGNotCondition::test () const
895 return !(_condition->test());
900 ////////////////////////////////////////////////////////////////////////
901 // Implementation of FGAndCondition.
902 ////////////////////////////////////////////////////////////////////////
904 FGAndCondition::FGAndCondition ()
908 FGAndCondition::~FGAndCondition ()
910 for (unsigned int i = 0; i < _conditions.size(); i++)
911 delete _conditions[i];
915 FGAndCondition::test () const
917 int nConditions = _conditions.size();
918 for (int i = 0; i < nConditions; i++) {
919 if (!_conditions[i]->test())
926 FGAndCondition::addCondition (FGCondition * condition)
928 _conditions.push_back(condition);
933 ////////////////////////////////////////////////////////////////////////
934 // Implementation of FGOrCondition.
935 ////////////////////////////////////////////////////////////////////////
937 FGOrCondition::FGOrCondition ()
941 FGOrCondition::~FGOrCondition ()
943 for (unsigned int i = 0; i < _conditions.size(); i++)
944 delete _conditions[i];
948 FGOrCondition::test () const
950 int nConditions = _conditions.size();
951 for (int i = 0; i < nConditions; i++) {
952 if (_conditions[i]->test())
959 FGOrCondition::addCondition (FGCondition * condition)
961 _conditions.push_back(condition);
966 ////////////////////////////////////////////////////////////////////////
967 // Implementation of FGComparisonCondition.
968 ////////////////////////////////////////////////////////////////////////
971 doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
973 switch (left->getType()) {
974 case SGPropertyNode::BOOL: {
975 bool v1 = left->getBoolValue();
976 bool v2 = right->getBoolValue();
978 return FGComparisonCondition::LESS_THAN;
980 return FGComparisonCondition::GREATER_THAN;
982 return FGComparisonCondition::EQUALS;
985 case SGPropertyNode::INT: {
986 int v1 = left->getIntValue();
987 int v2 = right->getIntValue();
989 return FGComparisonCondition::LESS_THAN;
991 return FGComparisonCondition::GREATER_THAN;
993 return FGComparisonCondition::EQUALS;
996 case SGPropertyNode::LONG: {
997 long v1 = left->getLongValue();
998 long v2 = right->getLongValue();
1000 return FGComparisonCondition::LESS_THAN;
1002 return FGComparisonCondition::GREATER_THAN;
1004 return FGComparisonCondition::EQUALS;
1007 case SGPropertyNode::FLOAT: {
1008 float v1 = left->getFloatValue();
1009 float v2 = right->getFloatValue();
1011 return FGComparisonCondition::LESS_THAN;
1013 return FGComparisonCondition::GREATER_THAN;
1015 return FGComparisonCondition::EQUALS;
1018 case SGPropertyNode::DOUBLE: {
1019 double v1 = left->getDoubleValue();
1020 double v2 = right->getDoubleValue();
1022 return FGComparisonCondition::LESS_THAN;
1024 return FGComparisonCondition::GREATER_THAN;
1026 return FGComparisonCondition::EQUALS;
1029 case SGPropertyNode::STRING:
1030 case SGPropertyNode::NONE:
1031 case SGPropertyNode::UNSPECIFIED: {
1032 string v1 = left->getStringValue();
1033 string v2 = right->getStringValue();
1035 return FGComparisonCondition::LESS_THAN;
1037 return FGComparisonCondition::GREATER_THAN;
1039 return FGComparisonCondition::EQUALS;
1043 throw sg_exception("Unrecognized node type");
1048 FGComparisonCondition::FGComparisonCondition (Type type, bool reverse)
1057 FGComparisonCondition::~FGComparisonCondition ()
1059 delete _right_value;
1063 FGComparisonCondition::test () const
1065 // Always fail if incompletely specified
1066 if (_left_property == 0 ||
1067 (_right_property == 0 && _right_value == 0))
1070 // Get LESS_THAN, EQUALS, or GREATER_THAN
1072 doComparison(_left_property,
1073 (_right_property != 0 ? _right_property : _right_value));
1075 return (cmp == _type);
1077 return (cmp != _type);
1081 FGComparisonCondition::setLeftProperty (const char * propname)
1083 _left_property = fgGetNode(propname, true);
1087 FGComparisonCondition::setRightProperty (const char * propname)
1089 delete _right_value;
1091 _right_property = fgGetNode(propname, true);
1095 FGComparisonCondition::setRightValue (const SGPropertyNode *node)
1097 _right_property = 0;
1098 delete _right_value;
1099 _right_value = new SGPropertyNode(*node);
1104 ////////////////////////////////////////////////////////////////////////
1105 // Read a condition and use it if necessary.
1106 ////////////////////////////////////////////////////////////////////////
1108 // Forward declaration
1109 static FGCondition * readCondition (const SGPropertyNode * node);
1111 static FGCondition *
1112 readPropertyCondition (const SGPropertyNode * node)
1114 return new FGPropertyCondition(node->getStringValue());
1117 static FGCondition *
1118 readNotCondition (const SGPropertyNode * node)
1120 int nChildren = node->nChildren();
1121 for (int i = 0; i < nChildren; i++) {
1122 const SGPropertyNode * child = node->getChild(i);
1123 FGCondition * condition = readCondition(child);
1125 return new FGNotCondition(condition);
1127 SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition");
1131 static FGCondition *
1132 readAndConditions (const SGPropertyNode * node)
1134 FGAndCondition * andCondition = new FGAndCondition;
1135 int nChildren = node->nChildren();
1136 for (int i = 0; i < nChildren; i++) {
1137 const SGPropertyNode * child = node->getChild(i);
1138 FGCondition * condition = readCondition(child);
1140 andCondition->addCondition(condition);
1142 return andCondition;
1145 static FGCondition *
1146 readOrConditions (const SGPropertyNode * node)
1148 FGOrCondition * orCondition = new FGOrCondition;
1149 int nChildren = node->nChildren();
1150 for (int i = 0; i < nChildren; i++) {
1151 const SGPropertyNode * child = node->getChild(i);
1152 FGCondition * condition = readCondition(child);
1154 orCondition->addCondition(condition);
1159 static FGCondition *
1160 readComparison (const SGPropertyNode * node,
1161 FGComparisonCondition::Type type,
1164 FGComparisonCondition * condition = new FGComparisonCondition(type, reverse);
1165 condition->setLeftProperty(node->getStringValue("property[0]"));
1166 if (node->hasValue("property[1]"))
1167 condition->setRightProperty(node->getStringValue("property[1]"));
1169 condition->setRightValue(node->getChild("value", 0));
1174 static FGCondition *
1175 readCondition (const SGPropertyNode * node)
1177 const string &name = node->getName();
1178 if (name == "property")
1179 return readPropertyCondition(node);
1180 else if (name == "not")
1181 return readNotCondition(node);
1182 else if (name == "and")
1183 return readAndConditions(node);
1184 else if (name == "or")
1185 return readOrConditions(node);
1186 else if (name == "less-than")
1187 return readComparison(node, FGComparisonCondition::LESS_THAN, false);
1188 else if (name == "less-than-equals")
1189 return readComparison(node, FGComparisonCondition::GREATER_THAN, true);
1190 else if (name == "greater-than")
1191 return readComparison(node, FGComparisonCondition::GREATER_THAN, false);
1192 else if (name == "greater-than-equals")
1193 return readComparison(node, FGComparisonCondition::LESS_THAN, true);
1194 else if (name == "equals")
1195 return readComparison(node, FGComparisonCondition::EQUALS, false);
1196 else if (name == "not-equals")
1197 return readComparison(node, FGComparisonCondition::EQUALS, true);
1204 ////////////////////////////////////////////////////////////////////////
1205 // Implementation of FGConditional.
1206 ////////////////////////////////////////////////////////////////////////
1208 FGConditional::FGConditional ()
1213 FGConditional::~FGConditional ()
1219 FGConditional::setCondition (FGCondition * condition)
1222 _condition = condition;
1226 FGConditional::test () const
1228 return ((_condition == 0) || _condition->test());
1233 // The top-level is always an implicit 'and' group
1235 fgReadCondition (const SGPropertyNode * node)
1237 return readAndConditions(node);
1241 // end of fg_props.cxx