]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_props.cxx
#561: keep magnetic heading within limits when mag-variation is negative
[flightgear.git] / src / Main / fg_props.cxx
1 // fg_props.cxx -- support for FlightGear properties.
2 //
3 // Written by David Megginson, started 2000.
4 //
5 // Copyright (C) 2000, 2001 David Megginson - david@megginson.com
6 //
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.
11 //
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.
16 //
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <simgear/compiler.h>
28 #include <simgear/structure/exception.hxx>
29 #include <simgear/props/props_io.hxx>
30
31 #include <simgear/magvar/magvar.hxx>
32 #include <simgear/timing/sg_time.hxx>
33 #include <simgear/misc/sg_path.hxx>
34 #include <simgear/scene/model/particles.hxx>
35 #include <simgear/sound/soundmgr_openal.hxx>
36
37 #include <GUI/gui.h>
38
39 #include "globals.hxx"
40 #include "fg_props.hxx"
41
42
43 static bool winding_ccw = true; // FIXME: temporary
44
45 static bool frozen = false;     // FIXME: temporary
46
47 using std::string;
48 \f
49 ////////////////////////////////////////////////////////////////////////
50 // Default property bindings (not yet handled by any module).
51 ////////////////////////////////////////////////////////////////////////
52
53 struct LogClassMapping {
54   sgDebugClass c;
55   string name;
56   LogClassMapping(sgDebugClass cc, string nname) { c = cc; name = nname; }
57 };
58
59 LogClassMapping log_class_mappings [] = {
60   LogClassMapping(SG_NONE, "none"),
61   LogClassMapping(SG_TERRAIN, "terrain"),
62   LogClassMapping(SG_ASTRO, "astro"),
63   LogClassMapping(SG_FLIGHT, "flight"),
64   LogClassMapping(SG_INPUT, "input"),
65   LogClassMapping(SG_GL, "gl"),
66   LogClassMapping(SG_VIEW, "view"),
67   LogClassMapping(SG_COCKPIT, "cockpit"),
68   LogClassMapping(SG_GENERAL, "general"),
69   LogClassMapping(SG_MATH, "math"),
70   LogClassMapping(SG_EVENT, "event"),
71   LogClassMapping(SG_AIRCRAFT, "aircraft"),
72   LogClassMapping(SG_AUTOPILOT, "autopilot"),
73   LogClassMapping(SG_IO, "io"),
74   LogClassMapping(SG_CLIPPER, "clipper"),
75   LogClassMapping(SG_NETWORK, "network"),
76   LogClassMapping(SG_INSTR, "instrumentation"),
77   LogClassMapping(SG_ATC, "atc"),
78   LogClassMapping(SG_NASAL, "nasal"),
79   LogClassMapping(SG_SYSTEMS, "systems"),
80   LogClassMapping(SG_AI, "ai"),
81   LogClassMapping(SG_ENVIRONMENT, "environment"),
82   LogClassMapping(SG_SOUND, "sound"),
83   LogClassMapping(SG_UNDEFD, "")
84 };
85
86
87 /**
88  * Get the logging classes.
89  */
90 // XXX Making the result buffer be global is a band-aid that hopefully
91 // delays its destruction 'til after its last use.
92 namespace
93 {
94 string loggingResult;
95 }
96
97 static const char *
98 getLoggingClasses ()
99 {
100   sgDebugClass classes = logbuf::get_log_classes();
101   loggingResult.clear();
102   for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
103     if ((classes&log_class_mappings[i].c) > 0) {
104       if (!loggingResult.empty())
105         loggingResult += '|';
106       loggingResult += log_class_mappings[i].name;
107     }
108   }
109   return loggingResult.c_str();
110 }
111
112
113 static void
114 addLoggingClass (const string &name)
115 {
116   sgDebugClass classes = logbuf::get_log_classes();
117   for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
118     if (name == log_class_mappings[i].name) {
119       logbuf::set_log_classes(sgDebugClass(classes|log_class_mappings[i].c));
120       return;
121     }
122   }
123   SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging class: " << name);
124 }
125
126
127 /**
128  * Set the logging classes.
129  */
130 void
131 setLoggingClasses (const char * c)
132 {
133   string classes = c;
134   logbuf::set_log_classes(SG_NONE);
135
136   if (classes == "none") {
137     SG_LOG(SG_GENERAL, SG_INFO, "Disabled all logging classes");
138     return;
139   }
140
141   if (classes.empty() || classes == "all") { // default
142     logbuf::set_log_classes(SG_ALL);
143     SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
144            << getLoggingClasses());
145     return;
146   }
147
148   string rest = classes;
149   string name = "";
150   string::size_type sep = rest.find('|');
151   if (sep == string::npos)
152     sep = rest.find(',');
153   while (sep != string::npos) {
154     name = rest.substr(0, sep);
155     rest = rest.substr(sep+1);
156     addLoggingClass(name);
157     sep = rest.find('|');
158     if (sep == string::npos)
159       sep = rest.find(',');
160   }
161   addLoggingClass(rest);
162   SG_LOG(SG_GENERAL, SG_INFO, "Set logging classes to "
163          << getLoggingClasses());
164 }
165
166
167 /**
168  * Get the logging priority.
169  */
170 static const char *
171 getLoggingPriority ()
172 {
173   switch (logbuf::get_log_priority()) {
174   case SG_BULK:
175     return "bulk";
176   case SG_DEBUG:
177     return "debug";
178   case SG_INFO:
179     return "info";
180   case SG_WARN:
181     return "warn";
182   case SG_ALERT:
183     return "alert";
184   default:
185     SG_LOG(SG_GENERAL, SG_WARN, "Internal: Unknown logging priority number: "
186            << logbuf::get_log_priority());
187     return "unknown";
188   }
189 }
190
191
192 /**
193  * Set the logging priority.
194  */
195 void
196 setLoggingPriority (const char * p)
197 {
198   if (p == 0)
199       return;
200   string priority = 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);
211   } else {
212     SG_LOG(SG_GENERAL, SG_WARN, "Unknown logging priority " << priority);
213   }
214   SG_LOG(SG_GENERAL, SG_DEBUG, "Logging priority is " << getLoggingPriority());
215 }
216
217
218 /**
219  * Return the current frozen state.
220  */
221 static bool
222 getFreeze ()
223 {
224   return frozen;
225 }
226
227
228 /**
229  * Set the current frozen state.
230  */
231 static void
232 setFreeze (bool f)
233 {
234     frozen = f;
235
236     // Stop sound on a pause
237     SGSoundMgr *smgr = globals->get_soundmgr();
238     if ( smgr != NULL ) {
239         if ( f ) {
240             smgr->suspend();
241         } else if (fgGetBool("/sim/sound/working")) {
242             smgr->resume();
243         }
244     }
245
246     // Pause the particle system
247     simgear::Particles::setFrozen(f);
248 }
249
250
251 /**
252  * Return the number of milliseconds elapsed since simulation started.
253  */
254 static double
255 getElapsedTime_sec ()
256 {
257   return globals->get_sim_time_sec();
258 }
259
260
261 /**
262  * Return the current Zulu time.
263  */
264 static const char *
265 getDateString ()
266 {
267   static char buf[64];          // FIXME
268   
269   SGTime * st = globals->get_time_params();
270   if (!st) {
271     buf[0] = 0;
272     return buf;
273   }
274   
275   struct tm * t = st->getGmt();
276   sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
277           t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
278           t->tm_hour, t->tm_min, t->tm_sec);
279   return buf;
280 }
281
282
283 /**
284  * Set the current Zulu time.
285  */
286 static void
287 setDateString (const char * date_string)
288 {
289   SGTime * st = globals->get_time_params();
290   struct tm * current_time = st->getGmt();
291   struct tm new_time;
292
293                                 // Scan for basic ISO format
294                                 // YYYY-MM-DDTHH:MM:SS
295   int ret = sscanf(date_string, "%d-%d-%dT%d:%d:%d",
296                    &(new_time.tm_year), &(new_time.tm_mon),
297                    &(new_time.tm_mday), &(new_time.tm_hour),
298                    &(new_time.tm_min), &(new_time.tm_sec));
299
300                                 // Be pretty picky about this, so
301                                 // that strange things don't happen
302                                 // if the save file has been edited
303                                 // by hand.
304   if (ret != 6) {
305     SG_LOG(SG_INPUT, SG_WARN, "Date/time string " << date_string
306            << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
307     return;
308   }
309
310                                 // OK, it looks like we got six
311                                 // values, one way or another.
312   new_time.tm_year -= 1900;
313   new_time.tm_mon -= 1;
314                                 // Now, tell flight gear to use
315                                 // the new time.  This was far
316                                 // too difficult, by the way.
317   long int warp =
318     mktime(&new_time) - mktime(current_time) + globals->get_warp();
319     
320   fgSetInt("/sim/time/warp", warp);
321 }
322
323 /**
324  * Return the GMT as a string.
325  */
326 static const char *
327 getGMTString ()
328 {
329   static char buf[16];
330   SGTime * st = globals->get_time_params();
331   if (!st) {
332     buf[0] = 0;
333     return buf;
334   }
335   
336   struct tm *t = st->getGmt();
337   snprintf(buf, 16, "%.2d:%.2d:%.2d",
338       t->tm_hour, t->tm_min, t->tm_sec);
339   return buf;
340 }
341
342 /**
343  * Return the magnetic variation
344  */
345 static double
346 getMagVar ()
347 {
348   return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
349 }
350
351
352 /**
353  * Return the magnetic dip
354  */
355 static double
356 getMagDip ()
357 {
358   return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
359 }
360
361
362 /**
363  * Return the current heading in degrees.
364  */
365 static double
366 getHeadingMag ()
367 {
368   double magheading;
369   magheading = fgGetDouble("/orientation/heading-deg") - getMagVar();
370   if (magheading <= 0) magheading += 360;
371   else if (magheading > 360) magheading -= 360;
372   return magheading;
373 }
374
375 /**
376  * Return the current track in degrees.
377  */
378 static double
379 getTrackMag ()
380 {
381   double magtrack;
382   magtrack = fgGetDouble("/orientation/track-deg") - getMagVar();
383   if (magtrack <= 0) magtrack += 360;
384   else if (magtrack > 360) magtrack -= 360;
385   return magtrack;
386 }
387
388 static bool
389 getWindingCCW ()
390 {
391   return winding_ccw;
392 }
393
394 static void
395 setWindingCCW (bool state)
396 {
397   winding_ccw = state;
398   if ( winding_ccw )
399     glFrontFace ( GL_CCW );
400   else
401     glFrontFace ( GL_CW );
402 }
403
404 static const char *
405 getLongitudeString ()
406 {
407   static SGConstPropertyNode_ptr n = fgGetNode("/position/longitude-deg", true);
408   static SGConstPropertyNode_ptr f = fgGetNode("/sim/lon-lat-format", true);
409   static char buf[32];
410   double d = n->getDoubleValue();
411   int format = f->getIntValue();
412   char c = d < 0.0 ? 'W' : 'E';
413
414   if (format == 0) {
415     snprintf(buf, 32, "%3.6f%c", d, c);
416
417   } else if (format == 1) {
418     // dd mm.mmm' (DMM-Format) -- uses a round-off factor tailored to the
419     // required precision of the minutes field (three decimal places),
420     // preventing minute values of 60.
421     double deg = fabs(d) + 5.0E-4 / 60.0;
422     double min = fabs(deg - int(deg)) * 60.0 - 4.999E-4;
423     snprintf(buf, 32, "%d*%06.3f%c", int(d < 0.0 ? -deg : deg), min, c);
424
425   } else {
426     // mm'ss.s'' (DMS-Format) -- uses a round-off factor tailored to the
427     // required precision of the seconds field (one decimal place),
428     // preventing second values of 60.
429     double deg = fabs(d) + 0.05 / 3600.0;
430     double min = (deg - int(deg)) * 60.0;
431     double sec = (min - int(min)) * 60.0 - 0.049;
432     snprintf(buf, 32, "%d*%02d %04.1f%c", int(d < 0.0 ? -deg : deg),
433         int(min), fabs(sec), c);
434   }
435   buf[31] = '\0';
436   return buf;
437 }
438
439 static const char *
440 getLatitudeString ()
441 {
442   static SGConstPropertyNode_ptr n = fgGetNode("/position/latitude-deg", true);
443   static SGConstPropertyNode_ptr f = fgGetNode("/sim/lon-lat-format", true);
444   static char buf[32];
445   double d = n->getDoubleValue();
446   int format = f->getIntValue();
447   char c = d < 0.0 ? 'S' : 'N';
448
449   if (format == 0) {
450     snprintf(buf, 32, "%3.6f%c", d, c);
451
452   } else if (format == 1) {
453     double deg = fabs(d) + 5.0E-4 / 60.0;
454     double min = fabs(deg - int(deg)) * 60.0 - 4.999E-4;
455     snprintf(buf, 32, "%d*%06.3f%c", int(d < 0.0 ? -deg : deg), min, c);
456
457   } else {
458     double deg = fabs(d) + 0.05 / 3600.0;
459     double min = (deg - int(deg)) * 60.0;
460     double sec = (min - int(min)) * 60.0 - 0.049;
461     snprintf(buf, 32, "%d*%02d %04.1f%c", int(d < 0.0 ? -deg : deg),
462         int(min), fabs(sec), c);
463   }
464   buf[31] = '\0';
465   return buf;
466 }
467
468
469
470 \f
471 ////////////////////////////////////////////////////////////////////////
472 // Tie the properties.
473 ////////////////////////////////////////////////////////////////////////
474
475 FGProperties::FGProperties ()
476 {
477 }
478
479 FGProperties::~FGProperties ()
480 {
481 }
482
483 void
484 FGProperties::init ()
485 {
486 }
487
488 void
489 FGProperties::bind ()
490 {
491                                 // Simulation
492   fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
493   fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
494   fgTie("/sim/freeze/master", getFreeze, setFreeze);
495
496   fgTie("/sim/time/elapsed-sec", getElapsedTime_sec);
497   fgTie("/sim/time/gmt", getDateString, setDateString);
498   fgSetArchivable("/sim/time/gmt");
499   fgTie("/sim/time/gmt-string", getGMTString);
500
501                                 // Position
502   fgTie("/position/latitude-string", getLatitudeString);
503   fgTie("/position/longitude-string", getLongitudeString);
504
505                                 // Orientation
506   fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
507   fgTie("/orientation/track-magnetic-deg", getTrackMag);
508
509   fgTie("/environment/magnetic-variation-deg", getMagVar);
510   fgTie("/environment/magnetic-dip-deg", getMagDip);
511
512                                 // Misc. Temporary junk.
513   fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
514 }
515
516 void
517 FGProperties::unbind ()
518 {
519                                 // Simulation
520   fgUntie("/sim/logging/priority");
521   fgUntie("/sim/logging/classes");
522   fgUntie("/sim/freeze/master");
523
524   fgUntie("/sim/time/elapsed-sec");
525   fgUntie("/sim/time/gmt");
526   fgUntie("/sim/time/gmt-string");
527                                 // Position
528   fgUntie("/position/latitude-string");
529   fgUntie("/position/longitude-string");
530
531                                 // Orientation
532   fgUntie("/orientation/heading-magnetic-deg");
533   fgUntie("/orientation/track-magnetic-deg");
534
535                                 // Environment
536   fgUntie("/environment/magnetic-variation-deg");
537   fgUntie("/environment/magnetic-dip-deg");
538
539                                 // Misc. Temporary junk.
540   fgUntie("/sim/temp/winding-ccw");
541 //  fgUntie("/sim/temp/full-screen");
542 //  fgUntie("/sim/temp/fdm-data-logging");
543 }
544
545 void
546 FGProperties::update (double dt)
547 {
548     static SGPropertyNode_ptr offset = fgGetNode("/sim/time/local-offset", true);
549     offset->setIntValue(globals->get_time_params()->get_local_offset());
550
551
552     // utc date/time
553     static SGPropertyNode_ptr uyear = fgGetNode("/sim/time/utc/year", true);
554     static SGPropertyNode_ptr umonth = fgGetNode("/sim/time/utc/month", true);
555     static SGPropertyNode_ptr uday = fgGetNode("/sim/time/utc/day", true);
556     static SGPropertyNode_ptr uhour = fgGetNode("/sim/time/utc/hour", true);
557     static SGPropertyNode_ptr umin = fgGetNode("/sim/time/utc/minute", true);
558     static SGPropertyNode_ptr usec = fgGetNode("/sim/time/utc/second", true);
559     static SGPropertyNode_ptr uwday = fgGetNode("/sim/time/utc/weekday", true);
560     static SGPropertyNode_ptr udsec = fgGetNode("/sim/time/utc/day-seconds", true);
561
562     struct tm *u = globals->get_time_params()->getGmt();
563     uyear->setIntValue(u->tm_year + 1900);
564     umonth->setIntValue(u->tm_mon + 1);
565     uday->setIntValue(u->tm_mday);
566     uhour->setIntValue(u->tm_hour);
567     umin->setIntValue(u->tm_min);
568     usec->setIntValue(u->tm_sec);
569     uwday->setIntValue(u->tm_wday);
570
571     udsec->setIntValue(u->tm_hour * 3600 + u->tm_min * 60 + u->tm_sec);
572
573
574     // real local date/time
575     static SGPropertyNode_ptr ryear = fgGetNode("/sim/time/real/year", true);
576     static SGPropertyNode_ptr rmonth = fgGetNode("/sim/time/real/month", true);
577     static SGPropertyNode_ptr rday = fgGetNode("/sim/time/real/day", true);
578     static SGPropertyNode_ptr rhour = fgGetNode("/sim/time/real/hour", true);
579     static SGPropertyNode_ptr rmin = fgGetNode("/sim/time/real/minute", true);
580     static SGPropertyNode_ptr rsec = fgGetNode("/sim/time/real/second", true);
581     static SGPropertyNode_ptr rwday = fgGetNode("/sim/time/real/weekday", true);
582
583     time_t real = time(0);
584     struct tm *r = localtime(&real);
585     ryear->setIntValue(r->tm_year + 1900);
586     rmonth->setIntValue(r->tm_mon + 1);
587     rday->setIntValue(r->tm_mday);
588     rhour->setIntValue(r->tm_hour);
589     rmin->setIntValue(r->tm_min);
590     rsec->setIntValue(r->tm_sec);
591     rwday->setIntValue(r->tm_wday);
592 }
593
594
595 \f
596 ////////////////////////////////////////////////////////////////////////
597 // Save and restore.
598 ////////////////////////////////////////////////////////////////////////
599
600
601 /**
602  * Save the current state of the simulator to a stream.
603  */
604 bool
605 fgSaveFlight (std::ostream &output, bool write_all)
606 {
607
608   fgSetBool("/sim/presets/onground", false);
609   fgSetArchivable("/sim/presets/onground");
610   fgSetBool("/sim/presets/trim", false);
611   fgSetArchivable("/sim/presets/trim");
612   fgSetString("/sim/presets/speed-set", "UVW");
613   fgSetArchivable("/sim/presets/speed-set");
614
615   try {
616     writeProperties(output, globals->get_props(), write_all);
617   } catch (const sg_exception &e) {
618     guiErrorMessage("Error saving flight: ", e);
619     return false;
620   }
621   return true;
622 }
623
624
625 /**
626  * Restore the current state of the simulator from a stream.
627  */
628 bool
629 fgLoadFlight (std::istream &input)
630 {
631   SGPropertyNode props;
632   try {
633     readProperties(input, &props);
634   } catch (const sg_exception &e) {
635     guiErrorMessage("Error reading saved flight: ", e);
636     return false;
637   }
638
639   fgSetBool("/sim/presets/onground", false);
640   fgSetBool("/sim/presets/trim", false);
641   fgSetString("/sim/presets/speed-set", "UVW");
642
643   copyProperties(&props, globals->get_props());
644   // When loading a flight, make it the
645   // new initial state.
646   globals->saveInitialState();
647   return true;
648 }
649
650
651 bool
652 fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root, int default_mode)
653 {
654     string fullpath;
655     if (in_fg_root) {
656         SGPath loadpath(globals->get_fg_root());
657         loadpath.append(path);
658         fullpath = loadpath.str();
659     } else {
660         fullpath = path;
661     }
662
663     try {
664         readProperties(fullpath, props, default_mode);
665     } catch (const sg_exception &e) {
666         guiErrorMessage("Error reading properties: ", e);
667         return false;
668     }
669     return true;
670 }
671
672
673 \f
674 ////////////////////////////////////////////////////////////////////////
675 // Property convenience functions.
676 ////////////////////////////////////////////////////////////////////////
677
678 SGPropertyNode *
679 fgGetNode (const char * path, bool create)
680 {
681   return globals->get_props()->getNode(path, create);
682 }
683
684 SGPropertyNode * 
685 fgGetNode (const char * path, int index, bool create)
686 {
687   return globals->get_props()->getNode(path, index, create);
688 }
689
690 bool
691 fgHasNode (const char * path)
692 {
693   return (fgGetNode(path, false) != 0);
694 }
695
696 void
697 fgAddChangeListener (SGPropertyChangeListener * listener, const char * path)
698 {
699   fgGetNode(path, true)->addChangeListener(listener);
700 }
701
702 void
703 fgAddChangeListener (SGPropertyChangeListener * listener,
704                      const char * path, int index)
705 {
706   fgGetNode(path, index, true)->addChangeListener(listener);
707 }
708
709 bool
710 fgGetBool (const char * name, bool defaultValue)
711 {
712   return globals->get_props()->getBoolValue(name, defaultValue);
713 }
714
715 int
716 fgGetInt (const char * name, int defaultValue)
717 {
718   return globals->get_props()->getIntValue(name, defaultValue);
719 }
720
721 int
722 fgGetLong (const char * name, long defaultValue)
723 {
724   return globals->get_props()->getLongValue(name, defaultValue);
725 }
726
727 float
728 fgGetFloat (const char * name, float defaultValue)
729 {
730   return globals->get_props()->getFloatValue(name, defaultValue);
731 }
732
733 double
734 fgGetDouble (const char * name, double defaultValue)
735 {
736   return globals->get_props()->getDoubleValue(name, defaultValue);
737 }
738
739 const char *
740 fgGetString (const char * name, const char * defaultValue)
741 {
742   return globals->get_props()->getStringValue(name, defaultValue);
743 }
744
745 bool
746 fgSetBool (const char * name, bool val)
747 {
748   return globals->get_props()->setBoolValue(name, val);
749 }
750
751 bool
752 fgSetInt (const char * name, int val)
753 {
754   return globals->get_props()->setIntValue(name, val);
755 }
756
757 bool
758 fgSetLong (const char * name, long val)
759 {
760   return globals->get_props()->setLongValue(name, val);
761 }
762
763 bool
764 fgSetFloat (const char * name, float val)
765 {
766   return globals->get_props()->setFloatValue(name, val);
767 }
768
769 bool
770 fgSetDouble (const char * name, double val)
771 {
772   return globals->get_props()->setDoubleValue(name, val);
773 }
774
775 bool
776 fgSetString (const char * name, const char * val)
777 {
778   return globals->get_props()->setStringValue(name, val);
779 }
780
781 void
782 fgSetArchivable (const char * name, bool state)
783 {
784   SGPropertyNode * node = globals->get_props()->getNode(name);
785   if (node == 0)
786     SG_LOG(SG_GENERAL, SG_DEBUG,
787            "Attempt to set archive flag for non-existant property "
788            << name);
789   else
790     node->setAttribute(SGPropertyNode::ARCHIVE, state);
791 }
792
793 void
794 fgSetReadable (const char * name, bool state)
795 {
796   SGPropertyNode * node = globals->get_props()->getNode(name);
797   if (node == 0)
798     SG_LOG(SG_GENERAL, SG_DEBUG,
799            "Attempt to set read flag for non-existant property "
800            << name);
801   else
802     node->setAttribute(SGPropertyNode::READ, state);
803 }
804
805 void
806 fgSetWritable (const char * name, bool state)
807 {
808   SGPropertyNode * node = globals->get_props()->getNode(name);
809   if (node == 0)
810     SG_LOG(SG_GENERAL, SG_DEBUG,
811            "Attempt to set write flag for non-existant property "
812            << name);
813   else
814     node->setAttribute(SGPropertyNode::WRITE, state);
815 }
816
817 void
818 fgUntie(const char * name)
819 {
820   SGPropertyNode* node = globals->get_props()->getNode(name);
821   if (!node) {
822     SG_LOG(SG_GENERAL, SG_WARN, "fgUntie: unknown property " << name);
823     return;
824   }
825   
826   if (!node->isTied()) {
827     return;
828   }
829   
830   if (!node->untie()) {
831     SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
832   }
833 }
834
835
836 // end of fg_props.cxx