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.
238 // Stop sound on a pause
239 FGSoundMgr *s = globals->get_soundmgr();
251 * Return the current aircraft directory (UIUC) as a string.
256 return aircraft_dir.c_str();
261 * Set the current aircraft directory (UIUC).
264 setAircraftDir (const char * dir)
271 * Return the number of milliseconds elapsed since simulation started.
274 getElapsedTime_sec ()
276 return globals->get_sim_time_sec();
281 * Return the current Zulu time.
286 static char buf[64]; // FIXME
287 struct tm * t = globals->get_time_params()->getGmt();
288 sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
289 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
290 t->tm_hour, t->tm_min, t->tm_sec);
296 * Set the current Zulu time.
299 setDateString (const char * date_string)
301 static const SGPropertyNode *cur_time_override
302 = fgGetNode("/sim/time/cur-time-override", true);
304 SGTime * st = globals->get_time_params();
305 struct tm * current_time = st->getGmt();
308 // Scan for basic ISO format
309 // YYYY-MM-DDTHH:MM:SS
310 int ret = sscanf(date_string, "%d-%d-%dT%d:%d:%d",
311 &(new_time.tm_year), &(new_time.tm_mon),
312 &(new_time.tm_mday), &(new_time.tm_hour),
313 &(new_time.tm_min), &(new_time.tm_sec));
315 // Be pretty picky about this, so
316 // that strange things don't happen
317 // if the save file has been edited
320 SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
321 << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
325 // OK, it looks like we got six
326 // values, one way or another.
327 new_time.tm_year -= 1900;
328 new_time.tm_mon -= 1;
330 // Now, tell flight gear to use
331 // the new time. This was far
332 // too difficult, by the way.
334 mktime(&new_time) - mktime(current_time) + globals->get_warp();
335 double lon = current_aircraft.fdm_state->get_Longitude();
336 double lat = current_aircraft.fdm_state->get_Latitude();
337 globals->set_warp(warp);
338 st->update(lon, lat, cur_time_override->getLongValue(), warp);
339 fgUpdateSkyAndLightingParams();
343 * Return the GMT as a string.
348 static char buf[16]; // FIXME
349 struct tm *t = globals->get_time_params()->getGmt();
350 sprintf(buf, " %.2d:%.2d:%.2d",
351 t->tm_hour, t->tm_min, t->tm_sec);
352 // cout << t << " " << buf << endl;
358 * Get the texture rendering state.
363 return (material_lib.get_step() == 0);
368 * Set the texture rendering state.
371 setTextures (bool textures)
374 material_lib.set_step(0);
376 material_lib.set_step(1);
381 * Return the magnetic variation
386 return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
391 * Return the magnetic dip
396 return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
401 * Return the current heading in degrees.
406 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
413 * Get the current visibility (meters).
418 return WeatherDatabase->getWeatherVisibility();
423 * Set the current visibility (meters).
426 setVisibility (double visibility)
428 WeatherDatabase->setWeatherVisibility(visibility);
432 * Get the current wind north velocity (feet/second).
437 return current_aircraft.fdm_state->get_V_north_airmass();
442 * Set the current wind north velocity (feet/second).
445 setWindNorth (double speed)
447 current_aircraft.fdm_state
448 ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
453 * Get the current wind east velocity (feet/second).
458 return current_aircraft.fdm_state->get_V_east_airmass();
463 * Set the current wind east velocity (feet/second).
466 setWindEast (double speed)
468 cout << "Set wind-east to " << speed << endl;
469 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
476 * Get the current wind down velocity (feet/second).
481 return current_aircraft.fdm_state->get_V_down_airmass();
486 * Set the current wind down velocity (feet/second).
489 setWindDown (double speed)
491 current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
496 #endif // FG_WEATHERCM
501 return globals->get_warp();
507 globals->set_warp(warp);
513 return globals->get_warp_delta();
517 setWarpDelta (long delta)
519 globals->set_warp_delta(delta);
529 setWindingCCW (bool state)
533 glFrontFace ( GL_CCW );
535 glFrontFace ( GL_CW );
541 #if defined(FX) && !defined(WIN32)
542 return globals->get_fullscreen();
549 setFullScreen (bool state)
551 #if defined(FX) && !defined(WIN32)
552 globals->set_fullscreen(state);
553 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
554 XMesaSetFXmode( state ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
562 return fdm_data_logging;
566 setFDMDataLogging (bool state)
568 // kludge; no getter or setter available
569 if (state != fdm_data_logging) {
570 fgToggleFDMdataLogging();
571 fdm_data_logging = state;
576 ////////////////////////////////////////////////////////////////////////
577 // Tie the properties.
578 ////////////////////////////////////////////////////////////////////////
583 cout << "start of fgInitProps()" << endl;
585 fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
586 fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
587 fgTie("/sim/freeze/master", getFreeze, setFreeze);
588 fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
590 fgTie("/sim/time/elapsed-sec", getElapsedTime_sec);
591 fgTie("/sim/time/gmt", getDateString, setDateString);
592 fgSetArchivable("/sim/time/gmt");
593 fgTie("/sim/time/gmt-string", getGMTString);
594 fgTie("/sim/rendering/textures", getTextures, setTextures);
597 fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
601 fgTie("/environment/visibility-m", getVisibility, setVisibility);
602 fgSetArchivable("/environment/visibility-m");
603 fgTie("/environment/wind-from-north-fps", getWindNorth, setWindNorth);
604 fgSetArchivable("/environment/wind-from-north-fps");
605 fgTie("/environment/wind-from-east-fps", getWindEast, setWindEast);
606 fgSetArchivable("/environment/wind-from-east-fps");
607 fgTie("/environment/wind-from-down-fps", getWindDown, setWindDown);
608 fgSetArchivable("/environment/wind-from-down-fps");
611 fgTie("/environment/magnetic-variation-deg", getMagVar);
612 fgTie("/environment/magnetic-dip-deg", getMagDip);
614 fgTie("/sim/time/warp", getWarp, setWarp, false);
615 fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
617 // Misc. Temporary junk.
618 fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
619 fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
620 fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
622 cout << "end of fgInitProps()" << endl;
633 ////////////////////////////////////////////////////////////////////////
635 ////////////////////////////////////////////////////////////////////////
639 * Save the current state of the simulator to a stream.
642 fgSaveFlight (ostream &output, bool write_all)
645 fgSetBool("/sim/presets/onground", false);
646 fgSetArchivable("/sim/presets/onground");
647 fgSetBool("/sim/presets/trim", false);
648 fgSetArchivable("/sim/presets/trim");
649 fgSetString("/sim/presets/speed-set", "UVW");
650 fgSetArchivable("/sim/presets/speed-set");
653 writeProperties(output, globals->get_props(), write_all);
654 } catch (const sg_exception &e) {
655 guiErrorMessage("Error saving flight: ", e);
663 * Restore the current state of the simulator from a stream.
666 fgLoadFlight (istream &input)
668 SGPropertyNode props;
670 readProperties(input, &props);
671 } catch (const sg_exception &e) {
672 guiErrorMessage("Error reading saved flight: ", e);
676 fgSetBool("/sim/presets/onground", false);
677 fgSetBool("/sim/presets/trim", false);
678 fgSetString("/sim/presets/speed-set", "UVW");
680 copyProperties(&props, globals->get_props());
681 // When loading a flight, make it the
682 // new initial state.
683 globals->saveInitialState();
689 fgLoadProps (const char * path, SGPropertyNode * props)
691 SGPath loadpath(globals->get_fg_root());
692 loadpath.append(path);
693 readProperties(loadpath.c_str(), props);
698 ////////////////////////////////////////////////////////////////////////
699 // Property convenience functions.
700 ////////////////////////////////////////////////////////////////////////
703 fgGetNode (const char * path, bool create)
705 return globals->get_props()->getNode(path, create);
709 fgGetNode (const char * path, int index, bool create)
711 return globals->get_props()->getNode(path, index, create);
715 fgHasNode (const char * path)
717 return (fgGetNode(path, false) != 0);
721 fgAddChangeListener (SGPropertyChangeListener * listener, const char * path)
723 fgGetNode(path, true)->addChangeListener(listener);
727 fgAddChangeListener (SGPropertyChangeListener * listener,
728 const char * path, int index)
730 fgGetNode(path, index, true)->addChangeListener(listener);
734 fgGetBool (const char * name, bool defaultValue)
736 return globals->get_props()->getBoolValue(name, defaultValue);
740 fgGetInt (const char * name, int defaultValue)
742 return globals->get_props()->getIntValue(name, defaultValue);
746 fgGetLong (const char * name, long defaultValue)
748 return globals->get_props()->getLongValue(name, defaultValue);
752 fgGetFloat (const char * name, float defaultValue)
754 return globals->get_props()->getFloatValue(name, defaultValue);
758 fgGetDouble (const char * name, double defaultValue)
760 return globals->get_props()->getDoubleValue(name, defaultValue);
764 fgGetString (const char * name, const char * defaultValue)
766 return globals->get_props()->getStringValue(name, defaultValue);
770 fgSetBool (const char * name, bool val)
772 return globals->get_props()->setBoolValue(name, val);
776 fgSetInt (const char * name, int val)
778 return globals->get_props()->setIntValue(name, val);
782 fgSetLong (const char * name, long val)
784 return globals->get_props()->setLongValue(name, val);
788 fgSetFloat (const char * name, float val)
790 return globals->get_props()->setFloatValue(name, val);
794 fgSetDouble (const char * name, double val)
796 return globals->get_props()->setDoubleValue(name, val);
800 fgSetString (const char * name, const char * val)
802 return globals->get_props()->setStringValue(name, val);
806 fgSetArchivable (const char * name, bool state)
808 SGPropertyNode * node = globals->get_props()->getNode(name);
810 SG_LOG(SG_GENERAL, SG_ALERT,
811 "Attempt to set archive flag for non-existant property "
814 node->setAttribute(SGPropertyNode::ARCHIVE, state);
818 fgSetReadable (const char * name, bool state)
820 SGPropertyNode * node = globals->get_props()->getNode(name);
822 SG_LOG(SG_GENERAL, SG_ALERT,
823 "Attempt to set read flag for non-existant property "
826 node->setAttribute(SGPropertyNode::READ, state);
830 fgSetWritable (const char * name, bool state)
832 SGPropertyNode * node = globals->get_props()->getNode(name);
834 SG_LOG(SG_GENERAL, SG_ALERT,
835 "Attempt to set write flag for non-existant property "
838 node->setAttribute(SGPropertyNode::WRITE, state);
842 fgUntie (const char * name)
844 if (!globals->get_props()->untie(name))
845 SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
851 ////////////////////////////////////////////////////////////////////////
852 // Implementation of FGCondition.
853 ////////////////////////////////////////////////////////////////////////
855 FGCondition::FGCondition ()
859 FGCondition::~FGCondition ()
865 ////////////////////////////////////////////////////////////////////////
866 // Implementation of FGPropertyCondition.
867 ////////////////////////////////////////////////////////////////////////
869 FGPropertyCondition::FGPropertyCondition (const char * propname)
870 : _node(fgGetNode(propname, true))
874 FGPropertyCondition::~FGPropertyCondition ()
880 ////////////////////////////////////////////////////////////////////////
881 // Implementation of FGNotCondition.
882 ////////////////////////////////////////////////////////////////////////
884 FGNotCondition::FGNotCondition (FGCondition * condition)
885 : _condition(condition)
889 FGNotCondition::~FGNotCondition ()
895 FGNotCondition::test () const
897 return !(_condition->test());
902 ////////////////////////////////////////////////////////////////////////
903 // Implementation of FGAndCondition.
904 ////////////////////////////////////////////////////////////////////////
906 FGAndCondition::FGAndCondition ()
910 FGAndCondition::~FGAndCondition ()
912 for (unsigned int i = 0; i < _conditions.size(); i++)
913 delete _conditions[i];
917 FGAndCondition::test () const
919 int nConditions = _conditions.size();
920 for (int i = 0; i < nConditions; i++) {
921 if (!_conditions[i]->test())
928 FGAndCondition::addCondition (FGCondition * condition)
930 _conditions.push_back(condition);
935 ////////////////////////////////////////////////////////////////////////
936 // Implementation of FGOrCondition.
937 ////////////////////////////////////////////////////////////////////////
939 FGOrCondition::FGOrCondition ()
943 FGOrCondition::~FGOrCondition ()
945 for (unsigned int i = 0; i < _conditions.size(); i++)
946 delete _conditions[i];
950 FGOrCondition::test () const
952 int nConditions = _conditions.size();
953 for (int i = 0; i < nConditions; i++) {
954 if (_conditions[i]->test())
961 FGOrCondition::addCondition (FGCondition * condition)
963 _conditions.push_back(condition);
968 ////////////////////////////////////////////////////////////////////////
969 // Implementation of FGComparisonCondition.
970 ////////////////////////////////////////////////////////////////////////
973 doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
975 switch (left->getType()) {
976 case SGPropertyNode::BOOL: {
977 bool v1 = left->getBoolValue();
978 bool v2 = right->getBoolValue();
980 return FGComparisonCondition::LESS_THAN;
982 return FGComparisonCondition::GREATER_THAN;
984 return FGComparisonCondition::EQUALS;
987 case SGPropertyNode::INT: {
988 int v1 = left->getIntValue();
989 int v2 = right->getIntValue();
991 return FGComparisonCondition::LESS_THAN;
993 return FGComparisonCondition::GREATER_THAN;
995 return FGComparisonCondition::EQUALS;
998 case SGPropertyNode::LONG: {
999 long v1 = left->getLongValue();
1000 long v2 = right->getLongValue();
1002 return FGComparisonCondition::LESS_THAN;
1004 return FGComparisonCondition::GREATER_THAN;
1006 return FGComparisonCondition::EQUALS;
1009 case SGPropertyNode::FLOAT: {
1010 float v1 = left->getFloatValue();
1011 float v2 = right->getFloatValue();
1013 return FGComparisonCondition::LESS_THAN;
1015 return FGComparisonCondition::GREATER_THAN;
1017 return FGComparisonCondition::EQUALS;
1020 case SGPropertyNode::DOUBLE: {
1021 double v1 = left->getDoubleValue();
1022 double v2 = right->getDoubleValue();
1024 return FGComparisonCondition::LESS_THAN;
1026 return FGComparisonCondition::GREATER_THAN;
1028 return FGComparisonCondition::EQUALS;
1031 case SGPropertyNode::STRING:
1032 case SGPropertyNode::NONE:
1033 case SGPropertyNode::UNSPECIFIED: {
1034 string v1 = left->getStringValue();
1035 string v2 = right->getStringValue();
1037 return FGComparisonCondition::LESS_THAN;
1039 return FGComparisonCondition::GREATER_THAN;
1041 return FGComparisonCondition::EQUALS;
1045 throw sg_exception("Unrecognized node type");
1050 FGComparisonCondition::FGComparisonCondition (Type type, bool reverse)
1059 FGComparisonCondition::~FGComparisonCondition ()
1061 delete _right_value;
1065 FGComparisonCondition::test () const
1067 // Always fail if incompletely specified
1068 if (_left_property == 0 ||
1069 (_right_property == 0 && _right_value == 0))
1072 // Get LESS_THAN, EQUALS, or GREATER_THAN
1074 doComparison(_left_property,
1075 (_right_property != 0 ? _right_property : _right_value));
1077 return (cmp == _type);
1079 return (cmp != _type);
1083 FGComparisonCondition::setLeftProperty (const char * propname)
1085 _left_property = fgGetNode(propname, true);
1089 FGComparisonCondition::setRightProperty (const char * propname)
1091 delete _right_value;
1093 _right_property = fgGetNode(propname, true);
1097 FGComparisonCondition::setRightValue (const SGPropertyNode *node)
1099 _right_property = 0;
1100 delete _right_value;
1101 _right_value = new SGPropertyNode(*node);
1106 ////////////////////////////////////////////////////////////////////////
1107 // Read a condition and use it if necessary.
1108 ////////////////////////////////////////////////////////////////////////
1110 // Forward declaration
1111 static FGCondition * readCondition (const SGPropertyNode * node);
1113 static FGCondition *
1114 readPropertyCondition (const SGPropertyNode * node)
1116 return new FGPropertyCondition(node->getStringValue());
1119 static FGCondition *
1120 readNotCondition (const SGPropertyNode * node)
1122 int nChildren = node->nChildren();
1123 for (int i = 0; i < nChildren; i++) {
1124 const SGPropertyNode * child = node->getChild(i);
1125 FGCondition * condition = readCondition(child);
1127 return new FGNotCondition(condition);
1129 SG_LOG(SG_COCKPIT, SG_ALERT, "Panel: empty 'not' condition");
1133 static FGCondition *
1134 readAndConditions (const SGPropertyNode * node)
1136 FGAndCondition * andCondition = new FGAndCondition;
1137 int nChildren = node->nChildren();
1138 for (int i = 0; i < nChildren; i++) {
1139 const SGPropertyNode * child = node->getChild(i);
1140 FGCondition * condition = readCondition(child);
1142 andCondition->addCondition(condition);
1144 return andCondition;
1147 static FGCondition *
1148 readOrConditions (const SGPropertyNode * node)
1150 FGOrCondition * orCondition = new FGOrCondition;
1151 int nChildren = node->nChildren();
1152 for (int i = 0; i < nChildren; i++) {
1153 const SGPropertyNode * child = node->getChild(i);
1154 FGCondition * condition = readCondition(child);
1156 orCondition->addCondition(condition);
1161 static FGCondition *
1162 readComparison (const SGPropertyNode * node,
1163 FGComparisonCondition::Type type,
1166 FGComparisonCondition * condition = new FGComparisonCondition(type, reverse);
1167 condition->setLeftProperty(node->getStringValue("property[0]"));
1168 if (node->hasValue("property[1]"))
1169 condition->setRightProperty(node->getStringValue("property[1]"));
1171 condition->setRightValue(node->getChild("value", 0));
1176 static FGCondition *
1177 readCondition (const SGPropertyNode * node)
1179 const string &name = node->getName();
1180 if (name == "property")
1181 return readPropertyCondition(node);
1182 else if (name == "not")
1183 return readNotCondition(node);
1184 else if (name == "and")
1185 return readAndConditions(node);
1186 else if (name == "or")
1187 return readOrConditions(node);
1188 else if (name == "less-than")
1189 return readComparison(node, FGComparisonCondition::LESS_THAN, false);
1190 else if (name == "less-than-equals")
1191 return readComparison(node, FGComparisonCondition::GREATER_THAN, true);
1192 else if (name == "greater-than")
1193 return readComparison(node, FGComparisonCondition::GREATER_THAN, false);
1194 else if (name == "greater-than-equals")
1195 return readComparison(node, FGComparisonCondition::LESS_THAN, true);
1196 else if (name == "equals")
1197 return readComparison(node, FGComparisonCondition::EQUALS, false);
1198 else if (name == "not-equals")
1199 return readComparison(node, FGComparisonCondition::EQUALS, true);
1206 ////////////////////////////////////////////////////////////////////////
1207 // Implementation of FGConditional.
1208 ////////////////////////////////////////////////////////////////////////
1210 FGConditional::FGConditional ()
1215 FGConditional::~FGConditional ()
1221 FGConditional::setCondition (FGCondition * condition)
1224 _condition = condition;
1228 FGConditional::test () const
1230 return ((_condition == 0) || _condition->test());
1235 // The top-level is always an implicit 'and' group
1237 fgReadCondition (const SGPropertyNode * node)
1239 return readAndConditions(node);
1243 // end of fg_props.cxx