]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_props.cxx
e2fd5fc9f64d8fe944af7b932359c6828bc65e5a
[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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <simgear/compiler.h>
25 #endif
26
27 #include <simgear/misc/exception.hxx>
28
29 #include STL_IOSTREAM
30
31 #include <Autopilot/newauto.hxx>
32 #include <Aircraft/aircraft.hxx>
33 #include <Time/tmp.hxx>
34 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
35 #ifndef FG_OLD_WEATHER
36 #  include <WeatherCM/FGLocalWeatherDatabase.h>
37 #else
38 #  include <Weather/weather.hxx>
39 #endif
40 #include <Objects/matlib.hxx>
41
42 #include <GUI/gui.h>
43
44 #include "fgfs.hxx"
45 #include "fg_props.hxx"
46 #include "viewmgr.hxx"
47
48 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
49 SG_USING_STD(istream);
50 SG_USING_STD(ostream);
51 #endif
52
53 static double getWindNorth ();
54 static double getWindEast ();
55 static double getWindDown ();
56
57 // Allow the view to be set from two axes (i.e. a joystick hat)
58 // This needs to be in FGViewer itself, somehow.
59 static double axisLong = 0.0;
60 static double axisLat = 0.0;
61
62 static bool winding_ccw = false; // FIXME: temporary
63
64 static bool fdm_data_logging = false; // FIXME: temporary
65
66
67 /**
68  * Utility function.
69  */
70 static inline void
71 _set_view_from_axes ()
72 {
73                                 // Take no action when hat is centered
74   if ( ( axisLong <  0.01 ) &&
75        ( axisLong > -0.01 ) &&
76        ( axisLat  <  0.01 ) &&
77        ( axisLat  > -0.01 )
78      )
79     return;
80
81   double viewDir = 999;
82
83   /* Do all the quick and easy cases */
84   if (axisLong < 0) {           // Longitudinal axis forward
85     if (axisLat == axisLong)
86       viewDir = 45;
87     else if (axisLat == - axisLong)
88       viewDir = 315;
89     else if (axisLat == 0)
90       viewDir = 0;
91   } else if (axisLong > 0) {    // Longitudinal axis backward
92     if (axisLat == - axisLong)
93       viewDir = 135;
94     else if (axisLat == axisLong)
95       viewDir = 225;
96     else if (axisLat == 0)
97       viewDir = 180;
98   } else if (axisLong == 0) {   // Longitudinal axis neutral
99     if (axisLat < 0)
100       viewDir = 90;
101     else if (axisLat > 0)
102       viewDir = 270;
103     else return; /* And assertion failure maybe? */
104   }
105
106   /* Do all the difficult cases */
107   if ( viewDir > 900 )
108     viewDir = SGD_RADIANS_TO_DEGREES * atan2 ( -axisLat, -axisLong );
109   if ( viewDir < -1 ) viewDir += 360;
110
111 //  SG_LOG(SG_INPUT, SG_ALERT, "Joystick Lat=" << axisLat << "   and Long="
112 //      << axisLong << "  gave angle=" << viewDir );
113
114   globals->get_current_view()->set_goal_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
115 //   globals->get_current_view()->set_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
116 }
117
118 \f
119 ////////////////////////////////////////////////////////////////////////
120 // Default property bindings (not yet handled by any module).
121 ////////////////////////////////////////////////////////////////////////
122
123
124 /**
125  * Get the pause state of the sim.
126  */
127 static bool
128 getFreeze ()
129 {
130   return globals->get_freeze();
131 }
132
133
134 /**
135  * Set the pause state of the sim.
136  */
137 static void
138 setFreeze (bool freeze)
139 {
140   globals->set_freeze(freeze);
141 }
142
143 /**
144  * Return the current aircraft directory (UIUC) as a string.
145  */
146 static string 
147 getAircraftDir ()
148 {
149   return aircraft_dir;
150 }
151
152
153 /**
154  * Set the current aircraft directory (UIUC).
155  */
156 static void
157 setAircraftDir (string dir)
158 {
159   if (getAircraftDir() != dir) {
160     aircraft_dir = dir;
161 //     needReinit(); FIXME!!
162   }
163 }
164
165
166 /**
167  * Get the current view offset in degrees.
168  */
169 static double
170 getViewOffset ()
171 {
172   return (globals->get_current_view()
173           ->get_view_offset() * SGD_RADIANS_TO_DEGREES);
174 }
175
176
177 static void
178 setViewOffset (double offset)
179 {
180   globals->get_current_view()->set_view_offset(offset * SGD_DEGREES_TO_RADIANS);
181 }
182
183 static double
184 getGoalViewOffset ()
185 {
186   return (globals->get_current_view()
187           ->get_goal_view_offset() * SGD_RADIANS_TO_DEGREES);
188 }
189
190 static void
191 setGoalViewOffset (double offset)
192 {
193     while ( offset < 0 ) {
194         offset += 360.0;
195     }
196     while ( offset > 360.0 ) {
197         offset -= 360.0;
198     }
199     // Snap to center if we are close
200     if ( fabs(offset) < 1.0 ||  fabs(offset) > 359.0 ) {
201         offset = 0.0;
202     }
203
204     globals->get_current_view()
205         ->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS);
206 }
207
208
209 /**
210  * Pilot position offset from CG.
211  */
212 static float
213 getPilotPositionXOffset ()
214 {
215   FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
216   float * offset = pilot_view->get_pilot_offset();
217   return offset[0];
218 }
219
220 static void
221 setPilotPositionXOffset (float x)
222 {
223   FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
224   float * offset = pilot_view->get_pilot_offset();
225   pilot_view->set_pilot_offset(x, offset[1], offset[2]);
226 }
227
228 static float
229 getPilotPositionYOffset ()
230 {
231   FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
232   float * offset = pilot_view->get_pilot_offset();
233   return offset[1];
234 }
235
236 static void
237 setPilotPositionYOffset (float y)
238 {
239   FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
240   float * offset = pilot_view->get_pilot_offset();
241   pilot_view->set_pilot_offset(offset[0], y, offset[2]);
242 }
243
244 static float
245 getPilotPositionZOffset ()
246 {
247   FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
248   float * offset = pilot_view->get_pilot_offset();
249   return offset[2];
250 }
251
252 static void
253 setPilotPositionZOffset (float z)
254 {
255   FGViewer * pilot_view = globals->get_viewmgr()->get_view(0);
256   float * offset = pilot_view->get_pilot_offset();
257   pilot_view->set_pilot_offset(offset[0], offset[1], z);
258 }
259
260
261 /**
262  * Return the current Zulu time.
263  */
264 static string 
265 getDateString ()
266 {
267   string out;
268   char buf[64];
269   struct tm * t = globals->get_time_params()->getGmt();
270   sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
271           t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
272           t->tm_hour, t->tm_min, t->tm_sec);
273   out = buf;
274   return out;
275 }
276
277
278 /**
279  * Set the current Zulu time.
280  */
281 static void
282 setDateString (string date_string)
283 {
284   SGTime * st = globals->get_time_params();
285   struct tm * current_time = st->getGmt();
286   struct tm new_time;
287
288                                 // Scan for basic ISO format
289                                 // YYYY-MM-DDTHH:MM:SS
290   int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
291                    &(new_time.tm_year), &(new_time.tm_mon),
292                    &(new_time.tm_mday), &(new_time.tm_hour),
293                    &(new_time.tm_min), &(new_time.tm_sec));
294
295                                 // Be pretty picky about this, so
296                                 // that strange things don't happen
297                                 // if the save file has been edited
298                                 // by hand.
299   if (ret != 6) {
300     SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
301            << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
302     return;
303   }
304
305                                 // OK, it looks like we got six
306                                 // values, one way or another.
307   new_time.tm_year -= 1900;
308   new_time.tm_mon -= 1;
309
310                                 // Now, tell flight gear to use
311                                 // the new time.  This was far
312                                 // too difficult, by the way.
313   long int warp =
314     mktime(&new_time) - mktime(current_time) + globals->get_warp();
315   double lon = current_aircraft.fdm_state->get_Longitude();
316   double lat = current_aircraft.fdm_state->get_Latitude();
317   globals->set_warp(warp);
318   st->update(lon, lat, warp);
319   fgUpdateSkyAndLightingParams();
320 }
321
322 /**
323  * Return the GMT as a string.
324  */
325 static string 
326 getGMTString ()
327 {
328   string out;
329   char buf[16];
330   struct tm * t = globals->get_time_params()->getGmt();
331   sprintf(buf, " %.2d:%.2d:%.2d",
332           t->tm_hour, t->tm_min, t->tm_sec);
333   out = buf;
334   return out;
335 }
336
337
338 /**
339  * Get the texture rendering state.
340  */
341 static bool
342 getTextures ()
343 {
344   return (material_lib.get_step() == 0);
345 }
346
347
348 /**
349  * Set the texture rendering state.
350  */
351 static void
352 setTextures (bool textures)
353 {
354   if (textures)
355     material_lib.set_step(0);
356   else
357     material_lib.set_step(1);
358 }
359
360
361 /**
362  * Return the magnetic variation
363  */
364 static double
365 getMagVar ()
366 {
367   return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
368 }
369
370
371 /**
372  * Return the magnetic dip
373  */
374 static double
375 getMagDip ()
376 {
377   return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
378 }
379
380
381 /**
382  * Return the current heading in degrees.
383  */
384 static double
385 getHeadingMag ()
386 {
387   return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
388 }
389
390
391 /**
392  * Return the current engine0 rpm
393  */
394 static double
395 getRPM ()
396 {
397   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
398       return current_aircraft.fdm_state->get_engine(0)->get_RPM();
399   } else {
400       return 0.0;
401   }
402 }
403
404
405 /**
406  * Return the current engine0 EGT.
407  */
408 static double
409 getEGT ()
410 {
411   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
412       return current_aircraft.fdm_state->get_engine(0)->get_EGT();
413   } else {
414       return 0.0;
415   }
416 }
417
418 /**
419  * Return the current engine0 CHT.
420  */
421 static double
422 getCHT ()
423 {
424   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
425       return current_aircraft.fdm_state->get_engine(0)->get_CHT();
426   } else {
427       return 0.0;
428   }
429 }
430
431 /**
432  * Return the current engine0 Manifold Pressure.
433  */
434 static double
435 getMP ()
436 {
437   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
438       return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
439   } else {
440       return 0.0;
441   }
442 }
443
444
445 /**
446  * Return the current engine0 fuel flow
447  */
448 static double
449 getFuelFlow ()
450 {
451   if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
452       return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow();
453   } else {
454       return 0.0;
455   }
456 }
457
458 /**
459  * Return the fuel level in tank 1
460  */
461 static double
462 getTank1Fuel ()
463 {
464   return current_aircraft.fdm_state->get_Tank1Fuel();
465 }
466
467 static void
468 setTank1Fuel ( double gals )
469 {
470   current_aircraft.fdm_state->set_Tank1Fuel( gals );
471 }
472
473 /**
474  * Return the fuel level in tank 2
475  */
476 static double
477 getTank2Fuel ()
478 {
479   return current_aircraft.fdm_state->get_Tank2Fuel();
480 }
481
482 static void
483 setTank2Fuel ( double gals )
484 {
485   current_aircraft.fdm_state->set_Tank2Fuel( gals );
486 }
487
488
489 /**
490  * Get the autopilot altitude lock (true=on).
491  */
492 static bool
493 getAPAltitudeLock ()
494 {
495     return (current_autopilot->get_AltitudeEnabled() &&
496             current_autopilot->get_AltitudeMode()
497             == FGAutopilot::FG_ALTITUDE_LOCK);
498 }
499
500
501 /**
502  * Set the autopilot altitude lock (true=on).
503  */
504 static void
505 setAPAltitudeLock (bool lock)
506 {
507   current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
508   current_autopilot->set_AltitudeEnabled(lock);
509 }
510
511
512 /**
513  * Get the autopilot target altitude in feet.
514  */
515 static double
516 getAPAltitude ()
517 {
518   return current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
519 }
520
521
522 /**
523  * Set the autopilot target altitude in feet.
524  */
525 static void
526 setAPAltitude (double altitude)
527 {
528     current_autopilot->set_TargetAltitude( altitude * SG_FEET_TO_METER );
529 }
530
531 /**
532  * Get the autopilot altitude lock (true=on).
533  */
534 static bool
535 getAPGSLock ()
536 {
537     return (current_autopilot->get_AltitudeEnabled() &&
538             (current_autopilot->get_AltitudeMode()
539              == FGAutopilot::FG_ALTITUDE_GS1));
540 }
541
542
543 /**
544  * Set the autopilot altitude lock (true=on).
545  */
546 static void
547 setAPGSLock (bool lock)
548 {
549   current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
550   current_autopilot->set_AltitudeEnabled(lock);
551 }
552
553
554 /**
555  * Get the autopilot terrain lock (true=on).
556  */
557 static bool
558 getAPTerrainLock ()
559 {
560     return (current_autopilot->get_AltitudeEnabled() &&
561             (current_autopilot->get_AltitudeMode()
562              == FGAutopilot::FG_ALTITUDE_TERRAIN));
563 }
564
565
566 /**
567  * Set the autopilot terrain lock (true=on).
568  */
569 static void
570 setAPTerrainLock (bool lock)
571 {
572   current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_TERRAIN);
573   current_autopilot->set_AltitudeEnabled(lock);
574 }
575
576
577 /**
578  * Get the autopilot target altitude in feet.
579  */
580 static double
581 getAPClimb ()
582 {
583   return current_autopilot->get_TargetClimbRate() * SG_METER_TO_FEET;
584 }
585
586
587 /**
588  * Set the autopilot target altitude in feet.
589  */
590 static void
591 setAPClimb (double rate)
592 {
593     current_autopilot->set_TargetClimbRate( rate * SG_FEET_TO_METER );
594 }
595
596
597 /**
598  * Get the autopilot heading lock (true=on).
599  */
600 static bool
601 getAPHeadingLock ()
602 {
603     return
604       (current_autopilot->get_HeadingEnabled() &&
605        current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
606 }
607
608
609 /**
610  * Set the autopilot heading lock (true=on).
611  */
612 static void
613 setAPHeadingLock (bool lock)
614 {
615     if (lock) {
616         current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
617         current_autopilot->set_HeadingEnabled(true);
618     } else {
619         current_autopilot->set_HeadingEnabled(false);
620     }
621 }
622
623
624 /**
625  * Get the autopilot heading bug in degrees.
626  */
627 static double
628 getAPHeadingBug ()
629 {
630   return current_autopilot->get_DGTargetHeading();
631 }
632
633
634 /**
635  * Set the autopilot heading bug in degrees.
636  */
637 static void
638 setAPHeadingBug (double heading)
639 {
640   current_autopilot->set_DGTargetHeading( heading );
641 }
642
643
644 /**
645  * Get the autopilot wing leveler lock (true=on).
646  */
647 static bool
648 getAPWingLeveler ()
649 {
650     return
651       (current_autopilot->get_HeadingEnabled() &&
652        current_autopilot->get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK);
653 }
654
655
656 /**
657  * Set the autopilot wing leveler lock (true=on).
658  */
659 static void
660 setAPWingLeveler (bool lock)
661 {
662     if (lock) {
663         current_autopilot->set_HeadingMode(FGAutopilot::FG_TC_HEADING_LOCK);
664         current_autopilot->set_HeadingEnabled(true);
665     } else {
666         current_autopilot->set_HeadingEnabled(false);
667     }
668 }
669
670 /**
671  * Return true if the autopilot is locked to NAV1.
672  */
673 static bool
674 getAPNAV1Lock ()
675 {
676   return
677     (current_autopilot->get_HeadingEnabled() &&
678      current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
679 }
680
681
682 /**
683  * Set the autopilot NAV1 lock.
684  */
685 static void
686 setAPNAV1Lock (bool lock)
687 {
688   if (lock) {
689     current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
690     current_autopilot->set_HeadingEnabled(true);
691   } else if (current_autopilot->get_HeadingMode() ==
692              FGAutopilot::FG_HEADING_NAV1) {
693     current_autopilot->set_HeadingEnabled(false);
694   }
695 }
696
697 /**
698  * Get the autopilot autothrottle lock.
699  */
700 static bool
701 getAPAutoThrottleLock ()
702 {
703   return current_autopilot->get_AutoThrottleEnabled();
704 }
705
706
707 /**
708  * Set the autothrottle lock.
709  */
710 static void
711 setAPAutoThrottleLock (bool lock)
712 {
713   current_autopilot->set_AutoThrottleEnabled(lock);
714 }
715
716
717 // kludge
718 static double
719 getAPRudderControl ()
720 {
721     if (getAPHeadingLock())
722         return current_autopilot->get_TargetHeading();
723     else
724         return globals->get_controls()->get_rudder();
725 }
726
727 // kludge
728 static void
729 setAPRudderControl (double value)
730 {
731     if (getAPHeadingLock()) {
732         SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value );
733         value -= current_autopilot->get_TargetHeading();
734         current_autopilot->HeadingAdjust(value < 0.0 ? -1.0 : 1.0);
735     } else {
736         globals->get_controls()->set_rudder(value);
737     }
738 }
739
740 // kludge
741 static double
742 getAPElevatorControl ()
743 {
744   if (getAPAltitudeLock())
745       return current_autopilot->get_TargetAltitude();
746   else
747     return globals->get_controls()->get_elevator();
748 }
749
750 // kludge
751 static void
752 setAPElevatorControl (double value)
753 {
754     if (getAPAltitudeLock()) {
755         SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value );
756         value -= current_autopilot->get_TargetAltitude();
757         current_autopilot->AltitudeAdjust(value < 0.0 ? 100.0 : -100.0);
758     } else {
759         globals->get_controls()->set_elevator(value);
760     }
761 }
762
763 // kludge
764 static double
765 getAPThrottleControl ()
766 {
767   if (getAPAutoThrottleLock())
768     return 0.0;                 // always resets
769   else
770     return globals->get_controls()->get_throttle(0);
771 }
772
773 // kludge
774 static void
775 setAPThrottleControl (double value)
776 {
777   if (getAPAutoThrottleLock())
778     current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
779   else
780     globals->get_controls()->set_throttle(0, value);
781 }
782
783
784 /**
785  * Get the current visibility (meters).
786  */
787 static double
788 getVisibility ()
789 {
790 #ifndef FG_OLD_WEATHER
791   return WeatherDatabase->getWeatherVisibility();
792 #else
793   return current_weather.get_visibility();
794 #endif
795 }
796
797
798 /**
799  * Set the current visibility (meters).
800  */
801 static void
802 setVisibility (double visibility)
803 {
804 #ifndef FG_OLD_WEATHER
805   WeatherDatabase->setWeatherVisibility(visibility);
806 #else
807   current_weather.set_visibility(visibility);
808 #endif
809 }
810
811 /**
812  * Get the current wind north velocity (feet/second).
813  */
814 static double
815 getWindNorth ()
816 {
817   return current_aircraft.fdm_state->get_V_north_airmass();
818 }
819
820
821 /**
822  * Set the current wind north velocity (feet/second).
823  */
824 static void
825 setWindNorth (double speed)
826 {
827   current_aircraft.fdm_state
828     ->set_Velocities_Local_Airmass(speed, getWindEast(), getWindDown());
829 }
830
831
832 /**
833  * Get the current wind east velocity (feet/second).
834  */
835 static double
836 getWindEast ()
837 {
838   return current_aircraft.fdm_state->get_V_east_airmass();
839 }
840
841
842 /**
843  * Set the current wind east velocity (feet/second).
844  */
845 static void
846 setWindEast (double speed)
847 {
848   cout << "Set wind-east to " << speed << endl;
849   current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
850                                                            speed,
851                                                            getWindDown());
852 }
853
854
855 /**
856  * Get the current wind down velocity (feet/second).
857  */
858 static double
859 getWindDown ()
860 {
861   return current_aircraft.fdm_state->get_V_down_airmass();
862 }
863
864
865 /**
866  * Set the current wind down velocity (feet/second).
867  */
868 static void
869 setWindDown (double speed)
870 {
871   current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
872                                                            getWindEast(),
873                                                            speed);
874 }
875
876 static double
877 getFOV ()
878 {
879   return globals->get_current_view()->get_fov();
880 }
881
882 static void
883 setFOV (double fov)
884 {
885   globals->get_current_view()->set_fov( fov );
886 }
887
888 static long
889 getWarp ()
890 {
891   return globals->get_warp();
892 }
893
894 static void
895 setWarp (long warp)
896 {
897   globals->set_warp(warp);
898 }
899
900 static long
901 getWarpDelta ()
902 {
903   return globals->get_warp_delta();
904 }
905
906 static void
907 setWarpDelta (long delta)
908 {
909   globals->set_warp_delta(delta);
910 }
911
912 static void
913 setViewAxisLong (double axis)
914 {
915   axisLong = axis;
916 }
917
918 static void
919 setViewAxisLat (double axis)
920 {
921   axisLat = axis;
922 }
923
924 static bool
925 getWindingCCW ()
926 {
927   return winding_ccw;
928 }
929
930 static void
931 setWindingCCW (bool state)
932 {
933   winding_ccw = state;
934   if ( winding_ccw )
935     glFrontFace ( GL_CCW );
936   else
937     glFrontFace ( GL_CW );
938 }
939
940 static bool
941 getFullScreen ()
942 {
943 #if defined(FX) && !defined(WIN32)
944   return global_fullscreen;
945 #else
946   return false;
947 #endif
948 }
949
950 static void
951 setFullScreen (bool state)
952 {
953 #if defined(FX) && !defined(WIN32)
954   global_fullscreen = state;
955 #  if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
956   XMesaSetFXmode( global_fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
957 #  endif
958 #endif
959 }
960
961 static bool
962 getFDMDataLogging ()
963 {
964   return fdm_data_logging;
965 }
966
967 static void
968 setFDMDataLogging (bool state)
969 {
970                                 // kludge; no getter or setter available
971   if (state != fdm_data_logging) {
972     fgToggleFDMdataLogging();
973     fdm_data_logging = state;
974   }
975 }
976
977 \f
978 ////////////////////////////////////////////////////////////////////////
979 // Tie the properties.
980 ////////////////////////////////////////////////////////////////////////
981
982 void
983 fgInitProps ()
984 {
985                                 // Simulation
986   fgTie("/sim/freeze", getFreeze, setFreeze);
987   fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
988   fgTie("/sim/view/offset-deg", getViewOffset, setViewOffset);
989   fgSetArchivable("/sim/view/offset-deg");
990   fgTie("/sim/view/goal-offset-deg", getGoalViewOffset, setGoalViewOffset);
991   fgSetArchivable("/sim/view/goal-offset-deg");
992   fgTie("/sim/view/pilot/x-offset-m",
993         getPilotPositionXOffset, setPilotPositionXOffset);
994   fgSetArchivable("/sim/view/pilot/x-offset-m");
995   fgTie("/sim/view/pilot/y-offset-m",
996         getPilotPositionYOffset, setPilotPositionYOffset);
997   fgSetArchivable("/sim/view/pilot/y-offset-m");
998   fgTie("/sim/view/pilot/z-offset-m",
999         getPilotPositionZOffset, setPilotPositionZOffset);
1000   fgSetArchivable("/sim/view/pilot/z-offset-m");
1001   fgTie("/sim/time/gmt", getDateString, setDateString);
1002   fgSetArchivable("/sim/time/gmt");
1003   fgTie("/sim/time/gmt-string", getGMTString);
1004   fgTie("/sim/rendering/textures", getTextures, setTextures);
1005
1006                                 // Orientation
1007   fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
1008
1009                                 // Engine
1010   fgTie("/engines/engine[0]/rpm", getRPM);
1011   fgTie("/engines/engine[0]/egt-degf", getEGT);
1012   fgTie("/engines/engine[0]/cht-degf", getCHT);
1013   fgTie("/engines/engine[0]/mp-osi", getMP);
1014   fgTie("/engines/engine[0]/fuel-flow-gph", getFuelFlow);
1015
1016   //consumables
1017   fgTie("/consumables/fuel/tank[0]/level-gal_us",
1018         getTank1Fuel, setTank1Fuel, false);
1019   fgSetArchivable("/consumables/fuel/tank[0]/level-gal_us");
1020   fgTie("/consumables/fuel/tank[1]/level-gal_us",
1021         getTank2Fuel, setTank2Fuel, false);
1022   fgSetArchivable("/consumables/fuel/tank[1]/level-gal_us");
1023
1024                                 // Autopilot
1025   fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
1026   fgSetArchivable("/autopilot/locks/altitude");
1027   fgTie("/autopilot/settings/altitude-ft", getAPAltitude, setAPAltitude);
1028   fgSetArchivable("/autopilot/settings/altitude-ft");
1029   fgTie("/autopilot/locks/glide-slope", getAPGSLock, setAPGSLock);
1030   fgSetArchivable("/autopilot/locks/glide-slope");
1031   fgTie("/autopilot/locks/terrain", getAPTerrainLock, setAPTerrainLock);
1032   fgSetArchivable("/autopilot/locks/terrain");
1033   fgTie("/autopilot/settings/climb-rate-fpm", getAPClimb, setAPClimb, false);
1034   fgSetArchivable("/autopilot/settings/climb-rate-fpm");
1035   fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
1036   fgSetArchivable("/autopilot/locks/heading");
1037   fgTie("/autopilot/settings/heading-bug-deg",
1038         getAPHeadingBug, setAPHeadingBug, false);
1039   fgSetArchivable("/autopilot/settings/heading-bug-deg");
1040   fgTie("/autopilot/locks/wing-leveler", getAPWingLeveler, setAPWingLeveler);
1041   fgSetArchivable("/autopilot/locks/wing-leveler");
1042   fgTie("/autopilot/locks/nav[0]", getAPNAV1Lock, setAPNAV1Lock);
1043   fgSetArchivable("/autopilot/locks/nav[0]");
1044   fgTie("/autopilot/locks/auto-throttle",
1045         getAPAutoThrottleLock, setAPAutoThrottleLock);
1046   fgSetArchivable("/autopilot/locks/auto-throttle");
1047   fgTie("/autopilot/control-overrides/rudder",
1048         getAPRudderControl, setAPRudderControl);
1049   fgSetArchivable("/autopilot/control-overrides/rudder");
1050   fgTie("/autopilot/control-overrides/elevator",
1051         getAPElevatorControl, setAPElevatorControl);
1052   fgSetArchivable("/autopilot/control-overrides/elevator");
1053   fgTie("/autopilot/control-overrides/throttle",
1054         getAPThrottleControl, setAPThrottleControl);
1055   fgSetArchivable("/autopilot/control-overrides/throttle");
1056
1057                                 // Environment
1058   fgTie("/environment/visibility-m", getVisibility, setVisibility);
1059   fgSetArchivable("/environment/visibility-m");
1060   fgTie("/environment/wind-north-fps", getWindNorth, setWindNorth);
1061   fgSetArchivable("/environment/wind-north-fps");
1062   fgTie("/environment/wind-east-fps", getWindEast, setWindEast);
1063   fgSetArchivable("/environment/wind-east-fps");
1064   fgTie("/environment/wind-down-fps", getWindDown, setWindDown);
1065   fgSetArchivable("/environment/wind-down-fps");
1066
1067   fgTie("/environment/magnetic-variation-deg", getMagVar);
1068   fgTie("/environment/magnetic-dip-deg", getMagDip);
1069
1070                                 // View
1071   fgTie("/sim/field-of-view", getFOV, setFOV);
1072   fgSetArchivable("/sim/field-of-view");
1073   fgTie("/sim/time/warp", getWarp, setWarp, false);
1074   fgTie("/sim/time/warp-delta", getWarpDelta, setWarpDelta);
1075   fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
1076   fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
1077
1078                                 // Misc. Temporary junk.
1079   fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW);
1080   fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
1081   fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
1082         
1083 }
1084
1085
1086 void
1087 fgUpdateProps ()
1088 {
1089   _set_view_from_axes();
1090 }
1091
1092
1093 \f
1094 ////////////////////////////////////////////////////////////////////////
1095 // Save and restore.
1096 ////////////////////////////////////////////////////////////////////////
1097
1098
1099 /**
1100  * Save the current state of the simulator to a stream.
1101  */
1102 bool
1103 fgSaveFlight (ostream &output)
1104 {
1105   try {
1106     writeProperties(output, globals->get_props());
1107   } catch (const sg_exception &e) {
1108     guiErrorMessage("Error saving flight: ", e);
1109     return false;
1110   }
1111   return true;
1112 }
1113
1114
1115 /**
1116  * Restore the current state of the simulator from a stream.
1117  */
1118 bool
1119 fgLoadFlight (istream &input)
1120 {
1121   SGPropertyNode props;
1122   try {
1123     readProperties(input, &props);
1124   } catch (const sg_exception &e) {
1125     guiErrorMessage("Error reading saved flight: ", e);
1126     return false;
1127   }
1128   copyProperties(&props, globals->get_props());
1129   // When loading a flight, make it the
1130   // new initial state.
1131   globals->saveInitialState();
1132   return true;
1133 }
1134
1135 // end of fg_props.cxx