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 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
53 SG_USING_STD(istream);
54 SG_USING_STD(ostream);
58 static double getWindNorth ();
59 static double getWindEast ();
60 static double getWindDown ();
61 #endif // FG_WEATHERCM
63 static bool winding_ccw = true; // FIXME: temporary
65 static bool fdm_data_logging = false; // FIXME: temporary
67 static bool frozen = false; // FIXME: temporary
71 ////////////////////////////////////////////////////////////////////////
72 // Default property bindings (not yet handled by any module).
73 ////////////////////////////////////////////////////////////////////////
75 struct LogClassMapping {
78 LogClassMapping(sgDebugClass cc, string nname) { c = cc; name = nname; }
81 LogClassMapping log_class_mappings [] = {
82 LogClassMapping(SG_NONE, "none"),
83 LogClassMapping(SG_TERRAIN, "terrain"),
84 LogClassMapping(SG_ASTRO, "astro"),
85 LogClassMapping(SG_FLIGHT, "flight"),
86 LogClassMapping(SG_INPUT, "input"),
87 LogClassMapping(SG_GL, "gl"),
88 LogClassMapping(SG_VIEW, "view"),
89 LogClassMapping(SG_COCKPIT, "cockpit"),
90 LogClassMapping(SG_GENERAL, "general"),
91 LogClassMapping(SG_MATH, "math"),
92 LogClassMapping(SG_EVENT, "event"),
93 LogClassMapping(SG_AIRCRAFT, "aircraft"),
94 LogClassMapping(SG_AUTOPILOT, "autopilot"),
95 LogClassMapping(SG_IO, "io"),
96 LogClassMapping(SG_CLIPPER, "clipper"),
97 LogClassMapping(SG_NETWORK, "network"),
98 LogClassMapping(SG_UNDEFD, "")
103 * Get the logging classes.
108 sgDebugClass classes = logbuf::get_log_classes();
109 static string result = ""; // FIXME
110 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
111 if ((classes&log_class_mappings[i].c) > 0) {
114 result += log_class_mappings[i].name;
117 return result.c_str();
122 addLoggingClass (const string &name)
124 sgDebugClass classes = logbuf::get_log_classes();
125 for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
126 if (name == log_class_mappings[i].name) {
127 logbuf::set_log_classes(sgDebugClass(classes|log_class_mappings[i].c));
131 SG_LOG(SG_GENERAL, SG_ALERT, "Unknown logging class: " << name);
136 * Set the logging classes.
139 setLoggingClasses (const char * c)
142 logbuf::set_log_classes(SG_NONE);
144 if (classes == "none") {
145 SG_LOG(SG_GENERAL, SG_INFO, "Disabled all logging classes");
149 if (classes.empty() || classes == "all") { // default
150 logbuf::set_log_classes(SG_ALL);
151 SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
152 << getLoggingClasses());
156 string rest = classes;
158 int sep = rest.find('|');
160 name = rest.substr(0, sep);
161 rest = rest.substr(sep+1);
162 addLoggingClass(name);
163 sep = rest.find('|');
165 addLoggingClass(rest);
166 SG_LOG(SG_GENERAL, SG_INFO, "Set logging classes to "
167 << getLoggingClasses());
172 * Get the logging priority.
175 getLoggingPriority ()
177 switch (logbuf::get_log_priority()) {
189 SG_LOG(SG_GENERAL, SG_WARN, "Internal: Unknown logging priority number: "
190 << logbuf::get_log_priority());
197 * Set the logging priority.
200 setLoggingPriority (const char * p)
203 if (priority == "bulk") {
204 logbuf::set_log_priority(SG_BULK);
205 } else if (priority == "debug") {
206 logbuf::set_log_priority(SG_DEBUG);
207 } else if (priority.empty() || priority == "info") { // default
208 logbuf::set_log_priority(SG_INFO);
209 } else if (priority == "warn") {
210 logbuf::set_log_priority(SG_WARN);
211 } else if (priority == "alert") {
212 logbuf::set_log_priority(SG_ALERT);
214 SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
216 SG_LOG(SG_GENERAL, SG_INFO, "Logging priority is " << getLoggingPriority());
221 * Return the current frozen state.
231 * Set the current frozen state.
237 // Stop sound on a pause
239 globals->get_soundmgr()->pause();
241 globals->get_soundmgr()->resume();
246 * Return the current aircraft directory (UIUC) as a string.
251 return aircraft_dir.c_str();
256 * Set the current aircraft directory (UIUC).
259 setAircraftDir (const char * dir)
266 * Return the number of milliseconds elapsed since simulation started.
269 getElapsedTime_sec ()
271 return globals->get_sim_time_sec();
276 * Return the current Zulu time.
281 static char buf[64]; // FIXME
282 struct tm * t = globals->get_time_params()->getGmt();
283 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
284 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
285 t->tm_hour, t->tm_min, t->tm_sec);
291 * Set the current Zulu time.
294 setDateString (const char * date_string)
296 static const SGPropertyNode *cur_time_override
297 = fgGetNode("/sim/time/cur-time-override", true);
299 SGTime * st = globals->get_time_params();
300 struct tm * current_time = st->getGmt();
303 // Scan for basic ISO format
304 // YYYY-MM-DDTHH:MM:SS
305 int ret = sscanf(date_string, "%d-%d-%dT%d:%d:%d",
306 &(new_time.tm_year), &(new_time.tm_mon),
307 &(new_time.tm_mday), &(new_time.tm_hour),
308 &(new_time.tm_min), &(new_time.tm_sec));
310 // Be pretty picky about this, so
311 // that strange things don't happen
312 // if the save file has been edited
315 SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
316 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
320 // OK, it looks like we got six
321 // values, one way or another.
322 new_time.tm_year -= 1900;
323 new_time.tm_mon -= 1;
325 // Now, tell flight gear to use
326 // the new time. This was far
327 // too difficult, by the way.
329 mktime(&new_time) - mktime(current_time) + globals->get_warp();
330 double lon = current_aircraft.fdm_state->get_Longitude();
331 double lat = current_aircraft.fdm_state->get_Latitude();
332 globals->set_warp(warp);
333 st->update(lon, lat, cur_time_override->getLongValue(), warp);
334 fgUpdateSkyAndLightingParams();
338 * Return the GMT as a string.
343 static char buf[16]; // FIXME
344 struct tm *t = globals->get_time_params()->getGmt();
345 sprintf(buf, " %.2d:%.2d:%.2d",
346 t->tm_hour, t->tm_min, t->tm_sec);
347 // cout << t << " " << buf << endl;
353 * Get the texture rendering state.
358 return (material_lib.get_step() == 0);
363 * Set the texture rendering state.
366 setTextures (bool textures)
369 material_lib.set_step(0);
371 material_lib.set_step(1);
376 * Return the magnetic variation
381 return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
386 * Return the magnetic dip
391 return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
396 * Return the current heading in degrees.
401 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
408 * Get the current visibility (meters).
413 return WeatherDatabase->getWeatherVisibility();
418 * Set the current visibility (meters).
421 setVisibility (double visibility)
423 WeatherDatabase->setWeatherVisibility(visibility);
427 * Get the current wind north velocity (feet/second).
432 return current_aircraft.fdm_state->get_V_north_airmass();
437 * Set the current wind north velocity (feet/second).
440 setWindNorth (double speed)
442 current_aircraft.fdm_state
443 ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
448 * Get the current wind east velocity (feet/second).
453 return current_aircraft.fdm_state->get_V_east_airmass();
458 * Set the current wind east velocity (feet/second).
461 setWindEast (double speed)
463 cout << "Set wind-east to " << speed << endl;
464 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
471 * Get the current wind down velocity (feet/second).
476 return current_aircraft.fdm_state->get_V_down_airmass();
481 * Set the current wind down velocity (feet/second).
484 setWindDown (double speed)
486 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
491 #endif // FG_WEATHERCM
496 return globals->get_warp();
502 globals->set_warp(warp);
508 return globals->get_warp_delta();
512 setWarpDelta (long delta)
514 globals->set_warp_delta(delta);
524 setWindingCCW (bool state)
528 glFrontFace ( GL_CCW );
530 glFrontFace ( GL_CW );
536 #if defined(FX) && !defined(WIN32)
537 return globals->get_fullscreen();
544 setFullScreen (bool state)
546 #if defined(FX) && !defined(WIN32)
547 globals->set_fullscreen(state);
548 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
549 XMesaSetFXmode( state ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
557 return fdm_data_logging;
561 setFDMDataLogging (bool state)
563 // kludge; no getter or setter available
564 if (state != fdm_data_logging) {
565 fgToggleFDMdataLogging();
566 fdm_data_logging = state;
571 ////////////////////////////////////////////////////////////////////////
572 // Tie the properties.
573 ////////////////////////////////////////////////////////////////////////
578 cout << "start of fgInitProps()" << endl;
580 fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
581 fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
582 fgTie("/sim/freeze/master", getFreeze, setFreeze);
583 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
585 fgTie("/sim/time/elapsed-sec", getElapsedTime_sec);
586 fgTie("/sim/time/gmt", getDateString, setDateString);
587 fgSetArchivable("/sim/time/gmt");
588 fgTie("/sim/time/gmt-string", getGMTString);
589 fgTie("/sim/rendering/textures", getTextures, setTextures);
592 fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
596 fgTie("/environment/visibility-m", getVisibility, setVisibility);
597 fgSetArchivable("/environment/visibility-m");
598 fgTie("/environment/wind-from-north-fps", getWindNorth, setWindNorth);
599 fgSetArchivable("/environment/wind-from-north-fps");
600 fgTie("/environment/wind-from-east-fps", getWindEast, setWindEast);
601 fgSetArchivable("/environment/wind-from-east-fps");
602 fgTie("/environment/wind-from-down-fps", getWindDown, setWindDown);
603 fgSetArchivable("/environment/wind-from-down-fps");
606 fgTie("/environment/magnetic-variation-deg", getMagVar);
607 fgTie("/environment/magnetic-dip-deg", getMagDip);
609 fgTie("/sim/time/warp", getWarp, setWarp, false);
610 fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
612 // Misc. Temporary junk.
613 fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
614 fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
615 fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
617 cout << "end of fgInitProps()" << endl;
628 ////////////////////////////////////////////////////////////////////////
630 ////////////////////////////////////////////////////////////////////////
634 * Save the current state of the simulator to a stream.
637 fgSaveFlight (ostream &output, bool write_all)
640 fgSetBool("/sim/startup/onground", false);
641 fgSetArchivable("/sim/startup/onground");
642 fgSetBool("/sim/startup/trim", false);
643 fgSetArchivable("/sim/startup/trim");
644 fgSetString("/sim/startup/speed-set", "UVW");
645 fgSetArchivable("/sim/startup/speed-set");
648 writeProperties(output, globals->get_props(), write_all);
649 } catch (const sg_exception &e) {
650 guiErrorMessage("Error saving flight: ", e);
658 * Restore the current state of the simulator from a stream.
661 fgLoadFlight (istream &input)
663 SGPropertyNode props;
665 readProperties(input, &props);
666 } catch (const sg_exception &e) {
667 guiErrorMessage("Error reading saved flight: ", e);
671 fgSetBool("/sim/startup/onground", false);
672 fgSetBool("/sim/startup/trim", false);
673 fgSetString("/sim/startup/speed-set", "UVW");
675 copyProperties(&props, globals->get_props());
676 // When loading a flight, make it the
677 // new initial state.
678 globals->saveInitialState();
684 fgLoadProps (const char * path, SGPropertyNode * props)
686 SGPath loadpath(globals->get_fg_root());
687 loadpath.append(path);
688 readProperties(loadpath.c_str(), props);
693 ////////////////////////////////////////////////////////////////////////
694 // Property convenience functions.
695 ////////////////////////////////////////////////////////////////////////
698 fgGetNode (const char * path, bool create)
700 return globals->get_props()->getNode(path, create);
704 fgGetNode (const char * path, int index, bool create)
706 return globals->get_props()->getNode(path, index, create);
710 fgHasNode (const char * path)
712 return (fgGetNode(path, false) != 0);
716 fgAddChangeListener (SGPropertyChangeListener * listener, const char * path)
718 fgGetNode(path, true)->addChangeListener(listener);
722 fgAddChangeListener (SGPropertyChangeListener * listener,
723 const char * path, int index)
725 fgGetNode(path, index, true)->addChangeListener(listener);
729 fgGetBool (const char * name, bool defaultValue)
731 return globals->get_props()->getBoolValue(name, defaultValue);
735 fgGetInt (const char * name, int defaultValue)
737 return globals->get_props()->getIntValue(name, defaultValue);
741 fgGetLong (const char * name, long defaultValue)
743 return globals->get_props()->getLongValue(name, defaultValue);
747 fgGetFloat (const char * name, float defaultValue)
749 return globals->get_props()->getFloatValue(name, defaultValue);
753 fgGetDouble (const char * name, double defaultValue)
755 return globals->get_props()->getDoubleValue(name, defaultValue);
759 fgGetString (const char * name, const char * defaultValue)
761 return globals->get_props()->getStringValue(name, defaultValue);
765 fgSetBool (const char * name, bool val)
767 return globals->get_props()->setBoolValue(name, val);
771 fgSetInt (const char * name, int val)
773 return globals->get_props()->setIntValue(name, val);
777 fgSetLong (const char * name, long val)
779 return globals->get_props()->setLongValue(name, val);
783 fgSetFloat (const char * name, float val)
785 return globals->get_props()->setFloatValue(name, val);
789 fgSetDouble (const char * name, double val)
791 return globals->get_props()->setDoubleValue(name, val);
795 fgSetString (const char * name, const char * val)
797 return globals->get_props()->setStringValue(name, val);
801 fgSetArchivable (const char * name, bool state)
803 SGPropertyNode * node = globals->get_props()->getNode(name);
805 SG_LOG(SG_GENERAL, SG_ALERT,
806 "Attempt to set archive flag for non-existant property "
809 node->setAttribute(SGPropertyNode::ARCHIVE, state);
813 fgSetReadable (const char * name, bool state)
815 SGPropertyNode * node = globals->get_props()->getNode(name);
817 SG_LOG(SG_GENERAL, SG_ALERT,
818 "Attempt to set read flag for non-existant property "
821 node->setAttribute(SGPropertyNode::READ, state);
825 fgSetWritable (const char * name, bool state)
827 SGPropertyNode * node = globals->get_props()->getNode(name);
829 SG_LOG(SG_GENERAL, SG_ALERT,
830 "Attempt to set write flag for non-existant property "
833 node->setAttribute(SGPropertyNode::WRITE, state);
837 fgUntie (const char * name)
839 if (!globals->get_props()->untie(name))
840 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
846 ////////////////////////////////////////////////////////////////////////
847 // Implementation of FGCondition.
848 ////////////////////////////////////////////////////////////////////////
850 FGCondition::FGCondition ()
854 FGCondition::~FGCondition ()
860 ////////////////////////////////////////////////////////////////////////
861 // Implementation of FGPropertyCondition.
862 ////////////////////////////////////////////////////////////////////////
864 FGPropertyCondition::FGPropertyCondition (const char * propname)
865 : _node(fgGetNode(propname, true))
869 FGPropertyCondition::~FGPropertyCondition ()
875 ////////////////////////////////////////////////////////////////////////
876 // Implementation of FGNotCondition.
877 ////////////////////////////////////////////////////////////////////////
879 FGNotCondition::FGNotCondition (FGCondition * condition)
880 : _condition(condition)
884 FGNotCondition::~FGNotCondition ()
890 FGNotCondition::test () const
892 return !(_condition->test());
897 ////////////////////////////////////////////////////////////////////////
898 // Implementation of FGAndCondition.
899 ////////////////////////////////////////////////////////////////////////
901 FGAndCondition::FGAndCondition ()
905 FGAndCondition::~FGAndCondition ()
907 for (unsigned int i = 0; i < _conditions.size(); i++)
908 delete _conditions[i];
912 FGAndCondition::test () const
914 int nConditions = _conditions.size();
915 for (int i = 0; i < nConditions; i++) {
916 if (!_conditions[i]->test())
923 FGAndCondition::addCondition (FGCondition * condition)
925 _conditions.push_back(condition);
930 ////////////////////////////////////////////////////////////////////////
931 // Implementation of FGOrCondition.
932 ////////////////////////////////////////////////////////////////////////
934 FGOrCondition::FGOrCondition ()
938 FGOrCondition::~FGOrCondition ()
940 for (unsigned int i = 0; i < _conditions.size(); i++)
941 delete _conditions[i];
945 FGOrCondition::test () const
947 int nConditions = _conditions.size();
948 for (int i = 0; i < nConditions; i++) {
949 if (_conditions[i]->test())
956 FGOrCondition::addCondition (FGCondition * condition)
958 _conditions.push_back(condition);
963 ////////////////////////////////////////////////////////////////////////
964 // Implementation of FGComparisonCondition.
965 ////////////////////////////////////////////////////////////////////////
968 doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
970 switch (left->getType()) {
971 case SGPropertyNode::BOOL: {
972 bool v1 = left->getBoolValue();
973 bool v2 = right->getBoolValue();
975 return FGComparisonCondition::LESS_THAN;
977 return FGComparisonCondition::GREATER_THAN;
979 return FGComparisonCondition::EQUALS;
982 case SGPropertyNode::INT: {
983 int v1 = left->getIntValue();
984 int v2 = right->getIntValue();
986 return FGComparisonCondition::LESS_THAN;
988 return FGComparisonCondition::GREATER_THAN;
990 return FGComparisonCondition::EQUALS;
993 case SGPropertyNode::LONG: {
994 long v1 = left->getLongValue();
995 long v2 = right->getLongValue();
997 return FGComparisonCondition::LESS_THAN;
999 return FGComparisonCondition::GREATER_THAN;
1001 return FGComparisonCondition::EQUALS;
1004 case SGPropertyNode::FLOAT: {
1005 float v1 = left->getFloatValue();
1006 float v2 = right->getFloatValue();
1008 return FGComparisonCondition::LESS_THAN;
1010 return FGComparisonCondition::GREATER_THAN;
1012 return FGComparisonCondition::EQUALS;
1015 case SGPropertyNode::DOUBLE: {
1016 double v1 = left->getDoubleValue();
1017 double v2 = right->getDoubleValue();
1019 return FGComparisonCondition::LESS_THAN;
1021 return FGComparisonCondition::GREATER_THAN;
1023 return FGComparisonCondition::EQUALS;
1026 case SGPropertyNode::STRING:
1027 case SGPropertyNode::NONE:
1028 case SGPropertyNode::UNSPECIFIED: {
1029 string v1 = left->getStringValue();
1030 string v2 = right->getStringValue();
1032 return FGComparisonCondition::LESS_THAN;
1034 return FGComparisonCondition::GREATER_THAN;
1036 return FGComparisonCondition::EQUALS;
1040 throw sg_exception("Unrecognized node type");
1045 FGComparisonCondition::FGComparisonCondition (Type type, bool reverse)
1054 FGComparisonCondition::~FGComparisonCondition ()
1056 delete _right_value;
1060 FGComparisonCondition::test () const
1062 // Always fail if incompletely specified
1063 if (_left_property == 0 ||
1064 (_right_property == 0 && _right_value == 0))
1067 // Get LESS_THAN, EQUALS, or GREATER_THAN
1069 doComparison(_left_property,
1070 (_right_property != 0 ? _right_property : _right_value));
1072 return (cmp == _type);
1074 return (cmp != _type);
1078 FGComparisonCondition::setLeftProperty (const char * propname)
1080 _left_property = fgGetNode(propname, true);
1084 FGComparisonCondition::setRightProperty (const char * propname)
1086 delete _right_value;
1088 _right_property = fgGetNode(propname, true);
1092 FGComparisonCondition::setRightValue (const SGPropertyNode *node)
1094 _right_property = 0;
1095 delete _right_value;
1096 _right_value = new SGPropertyNode(*node);
1101 ////////////////////////////////////////////////////////////////////////
1102 // Read a condition and use it if necessary.
1103 ////////////////////////////////////////////////////////////////////////
1105 // Forward declaration
1106 static FGCondition * readCondition (const SGPropertyNode * node);
1108 static FGCondition *
1109 readPropertyCondition (const SGPropertyNode * node)
1111 return new FGPropertyCondition(node->getStringValue());
1114 static FGCondition *
1115 readNotCondition (const SGPropertyNode * node)
1117 int nChildren = node->nChildren();
1118 for (int i = 0; i < nChildren; i++) {
1119 const SGPropertyNode * child = node->getChild(i);
1120 FGCondition * condition = readCondition(child);
1122 return new FGNotCondition(condition);
1124 SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition");
1128 static FGCondition *
1129 readAndConditions (const SGPropertyNode * node)
1131 FGAndCondition * andCondition = new FGAndCondition;
1132 int nChildren = node->nChildren();
1133 for (int i = 0; i < nChildren; i++) {
1134 const SGPropertyNode * child = node->getChild(i);
1135 FGCondition * condition = readCondition(child);
1137 andCondition->addCondition(condition);
1139 return andCondition;
1142 static FGCondition *
1143 readOrConditions (const SGPropertyNode * node)
1145 FGOrCondition * orCondition = new FGOrCondition;
1146 int nChildren = node->nChildren();
1147 for (int i = 0; i < nChildren; i++) {
1148 const SGPropertyNode * child = node->getChild(i);
1149 FGCondition * condition = readCondition(child);
1151 orCondition->addCondition(condition);
1156 static FGCondition *
1157 readComparison (const SGPropertyNode * node,
1158 FGComparisonCondition::Type type,
1161 FGComparisonCondition * condition = new FGComparisonCondition(type, reverse);
1162 condition->setLeftProperty(node->getStringValue("property[0]"));
1163 if (node->hasValue("property[1]"))
1164 condition->setRightProperty(node->getStringValue("property[1]"));
1166 condition->setRightValue(node->getChild("value", 0));
1171 static FGCondition *
1172 readCondition (const SGPropertyNode * node)
1174 const string &name = node->getName();
1175 if (name == "property")
1176 return readPropertyCondition(node);
1177 else if (name == "not")
1178 return readNotCondition(node);
1179 else if (name == "and")
1180 return readAndConditions(node);
1181 else if (name == "or")
1182 return readOrConditions(node);
1183 else if (name == "less-than")
1184 return readComparison(node, FGComparisonCondition::LESS_THAN, false);
1185 else if (name == "less-than-equals")
1186 return readComparison(node, FGComparisonCondition::GREATER_THAN, true);
1187 else if (name == "greater-than")
1188 return readComparison(node, FGComparisonCondition::GREATER_THAN, false);
1189 else if (name == "greater-than-equals")
1190 return readComparison(node, FGComparisonCondition::LESS_THAN, true);
1191 else if (name == "equals")
1192 return readComparison(node, FGComparisonCondition::EQUALS, false);
1193 else if (name == "not-equals")
1194 return readComparison(node, FGComparisonCondition::EQUALS, true);
1201 ////////////////////////////////////////////////////////////////////////
1202 // Implementation of FGConditional.
1203 ////////////////////////////////////////////////////////////////////////
1205 FGConditional::FGConditional ()
1210 FGConditional::~FGConditional ()
1216 FGConditional::setCondition (FGCondition * condition)
1219 _condition = condition;
1223 FGConditional::test () const
1225 return ((_condition == 0) || _condition->test());
1230 // The top-level is always an implicit 'and' group
1232 fgReadCondition (const SGPropertyNode * node)
1234 return readAndConditions(node);
1238 // end of fg_props.cxx