]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Merge /u/edauvergne/flightgear/ branch lat_lon_precision_fix_v3 into next
[flightgear.git] / src / Main / fg_commands.cxx
1 // fg_commands.cxx - internal FGFS commands.
2
3 #ifdef HAVE_CONFIG_H
4 #  include "config.h"
5 #endif
6
7 #include <string.h>             // strcmp()
8
9 #include <simgear/compiler.h>
10
11 #include <string>
12 #include <fstream>
13
14 #include <simgear/sg_inlines.h>
15 #include <simgear/debug/logstream.hxx>
16 #include <simgear/math/sg_random.h>
17 #include <simgear/scene/material/mat.hxx>
18 #include <simgear/scene/material/matlib.hxx>
19 #include <simgear/structure/exception.hxx>
20 #include <simgear/structure/commands.hxx>
21 #include <simgear/props/props.hxx>
22 #include <simgear/props/props_io.hxx>
23 #include <simgear/structure/event_mgr.hxx>
24 #include <simgear/sound/soundmgr_openal.hxx>
25 #include <simgear/timing/sg_time.hxx>
26 #include <Network/RemoteXMLRequest.hxx>
27
28 #include <FDM/flight.hxx>
29 #include <GUI/gui.h>
30 #include <GUI/new_gui.hxx>
31 #include <GUI/dialog.hxx>
32 #include <Aircraft/replay.hxx>
33 #include <Scenery/scenery.hxx>
34 #include <Scenery/tilemgr.hxx>
35 #include <Scripting/NasalSys.hxx>
36 #include <Sound/sample_queue.hxx>
37 #include <Airports/xmlloader.hxx>
38 #include <Network/HTTPClient.hxx>
39 #include <Viewer/viewmgr.hxx>
40 #include <Viewer/viewer.hxx>
41 #include <Environment/presets.hxx>
42 #include <Navaids/NavDataCache.hxx>
43
44 #include "fg_init.hxx"
45 #include "fg_io.hxx"
46 #include "fg_os.hxx"
47 #include "fg_commands.hxx"
48 #include "fg_props.hxx"
49 #include "globals.hxx"
50 #include "logger.hxx"
51 #include "util.hxx"
52 #include "main.hxx"
53 #include "positioninit.hxx"
54
55 #include <boost/scoped_array.hpp>
56
57 #if FG_HAVE_GPERFTOOLS
58 # include <google/profiler.h>
59 #endif
60
61 #if defined(HAVE_QT)
62 #include <GUI/QtLauncher.hxx>
63 #endif
64
65 using std::string;
66 using std::ifstream;
67 using std::ofstream;
68
69
70 ////////////////////////////////////////////////////////////////////////
71 // Static helper functions.
72 ////////////////////////////////////////////////////////////////////////
73
74
75 static inline SGPropertyNode *
76 get_prop (const SGPropertyNode * arg)
77 {
78     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
79 }
80
81 static inline SGPropertyNode *
82 get_prop2 (const SGPropertyNode * arg)
83 {
84     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
85 }
86
87
88 /**
89  * Get a double value and split it as required.
90  */
91 static void
92 split_value (double full_value, const char * mask,
93              double * unmodifiable, double * modifiable)
94 {
95     if (!strcmp("integer", mask)) {
96         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
97         *unmodifiable = full_value - *modifiable;
98     } else if (!strcmp("decimal", mask)) {
99         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
100         *modifiable = full_value - *unmodifiable;
101     } else {
102         if (strcmp("all", mask))
103             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
104                    << " assuming 'all'");
105         *unmodifiable = 0;
106         *modifiable = full_value;
107     }
108 }
109
110
111 /**
112  * Clamp or wrap a value as specified.
113  */
114 static void
115 limit_value (double * value, const SGPropertyNode * arg)
116 {
117     const SGPropertyNode * min_node = arg->getChild("min");
118     const SGPropertyNode * max_node = arg->getChild("max");
119
120     bool wrap = arg->getBoolValue("wrap");
121
122     if (min_node == 0 || max_node == 0)
123         wrap = false;
124   
125     if (wrap) {                 // wrap such that min <= x < max
126         double min_val = min_node->getDoubleValue();
127         double max_val = max_node->getDoubleValue();
128         double resolution = arg->getDoubleValue("resolution");
129         if (resolution > 0.0) {
130             // snap to (min + N*resolution), taking special care to handle imprecision
131             int n = (int)floor((*value - min_val) / resolution + 0.5);
132             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
133             SG_NORMALIZE_RANGE(n, 0, steps);
134             *value = min_val + resolution * n;
135         } else {
136             // plain circular wrapping
137             SG_NORMALIZE_RANGE(*value, min_val, max_val);
138         }
139     } else {                    // clamp such that min <= x <= max
140         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
141             *value = min_node->getDoubleValue();
142         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
143             *value = max_node->getDoubleValue();
144     }
145 }
146
147 static bool
148 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
149 {
150     switch (value1->getType()) {
151     case simgear::props::BOOL:
152         return (value1->getBoolValue() == value2->getBoolValue());
153     case simgear::props::INT:
154         return (value1->getIntValue() == value2->getIntValue());
155     case simgear::props::LONG:
156         return (value1->getLongValue() == value2->getLongValue());
157     case simgear::props::FLOAT:
158         return (value1->getFloatValue() == value2->getFloatValue());
159     case simgear::props::DOUBLE:
160         return (value1->getDoubleValue() == value2->getDoubleValue());
161     default:
162         return !strcmp(value1->getStringValue(), value2->getStringValue());
163     }
164 }
165
166
167
168 ////////////////////////////////////////////////////////////////////////
169 // Command implementations.
170 ////////////////////////////////////////////////////////////////////////
171
172
173 /**
174  * Built-in command: do nothing.
175  */
176 static bool
177 do_null (const SGPropertyNode * arg)
178 {
179   return true;
180 }
181
182 /**
183  * Built-in command: run a Nasal script.
184  */
185 static bool
186 do_nasal (const SGPropertyNode * arg)
187 {
188     return ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(arg);
189 }
190
191 /**
192  * Built-in command: exit FlightGear.
193  *
194  * status: the exit status to return to the operating system (defaults to 0)
195  */
196 static bool
197 do_exit (const SGPropertyNode * arg)
198 {
199     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
200     fgSetBool("/sim/signals/exit", true);
201     globals->saveUserSettings();
202     fgOSExit(arg->getIntValue("status", 0));
203     return true;
204 }
205
206
207 /**
208  * Reset FlightGear (Shift-Escape or Menu->File->Reset)
209  */
210 static bool
211 do_reset (const SGPropertyNode * arg)
212 {
213     fgResetIdleState();
214     return true;
215 }
216
217
218 /**
219  * Change aircraft
220  */
221 static bool
222 do_switch_aircraft (const SGPropertyNode * arg)
223 {
224     fgSetString("/sim/aircraft", arg->getStringValue("aircraft"));
225     // start a reset
226     fgResetIdleState();
227     return true;
228 }
229
230 /**
231  */
232 static bool
233 do_reposition (const SGPropertyNode * arg)
234 {
235   fgStartReposition();
236   return true;
237 }
238
239 /**
240  * Built-in command: replay the FDR buffer
241  */
242 static bool
243 do_replay (const SGPropertyNode * arg)
244 {
245     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
246     return r->start();
247 }
248
249 /**
250  * Built-in command: pause/unpause the sim
251  */
252 static bool
253 do_pause (const SGPropertyNode * arg)
254 {
255     bool forcePause = arg->getBoolValue("force-pause", false );
256     bool forcePlay = arg->getBoolValue("force-play", false );
257
258     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
259
260     if(forcePause) paused = false;
261     if(forcePlay) paused = true;
262
263     if (paused && (fgGetInt("/sim/freeze/replay-state",0)>0))
264     {
265         do_replay(NULL);
266     }
267     else
268     {
269         fgSetBool("/sim/freeze/master",!paused);
270         fgSetBool("/sim/freeze/clock",!paused);
271     }
272   
273     syncPausePopupState();
274     return true;
275 }
276
277 /**
278  * Built-in command: load flight.
279  *
280  * file (optional): the name of the file to load (relative to current
281  *   directory).  Defaults to "fgfs.sav"
282  */
283 static bool
284 do_load (const SGPropertyNode * arg)
285 {
286     SGPath file(arg->getStringValue("file", "fgfs.sav"));
287
288     if (file.extension() != "sav")
289         file.concat(".sav");
290
291     std::string validated_path = fgValidatePath(file, false);
292     if (validated_path.empty()) {
293         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
294                 "(unauthorized access)");
295         return false;
296     }
297
298     ifstream input(validated_path.c_str());
299     if (input.good() && fgLoadFlight(input)) {
300         input.close();
301         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
302         return true;
303     } else {
304         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
305         return false;
306     }
307 }
308
309
310 /**
311  * Built-in command: save flight.
312  *
313  * file (optional): the name of the file to save (relative to the
314  * current directory).  Defaults to "fgfs.sav".
315  */
316 static bool
317 do_save (const SGPropertyNode * arg)
318 {
319     SGPath file(arg->getStringValue("file", "fgfs.sav"));
320
321     if (file.extension() != "sav")
322         file.concat(".sav");
323
324     std::string validated_path = fgValidatePath(file, true);
325     if (validated_path.empty()) {
326         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
327                 "(unauthorized access)");
328         return false;
329     }
330
331     bool write_all = arg->getBoolValue("write-all", false);
332     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
333     ofstream output(validated_path.c_str());
334     if (output.good() && fgSaveFlight(output, write_all)) {
335         output.close();
336         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
337         return true;
338     } else {
339         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
340         return false;
341     }
342 }
343
344 /**
345  * Built-in command: save flight recorder tape.
346  *
347  */
348 static bool
349 do_save_tape (const SGPropertyNode * arg)
350 {
351     FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
352     replay->saveTape(arg);
353
354     return true;
355 }
356 /**
357  * Built-in command: load flight recorder tape.
358  *
359  */
360 static bool
361 do_load_tape (const SGPropertyNode * arg)
362 {
363     FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
364     replay->loadTape(arg);
365
366     return true;
367 }
368
369 /**
370  * Built-in command: (re)load the panel.
371  *
372  * path (optional): the file name to load the panel from 
373  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
374  * and if that's unspecified, to "Panels/Default/default.xml".
375  */
376 static bool
377 do_panel_load (const SGPropertyNode * arg)
378 {
379   string panel_path = arg->getStringValue("path");
380   if (!panel_path.empty()) {
381     // write to the standard property, which will force a load
382     fgSetString("/sim/panel/path", panel_path.c_str());
383   }
384   
385   return true;
386 }
387
388 /**
389  * Built-in command: (re)load preferences.
390  *
391  * path (optional): the file name to load the panel from (relative
392  * to FG_ROOT). Defaults to "preferences.xml".
393  */
394 static bool
395 do_preferences_load (const SGPropertyNode * arg)
396 {
397   try {
398     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
399                 globals->get_props());
400   } catch (const sg_exception &e) {
401     guiErrorMessage("Error reading global preferences: ", e);
402     return false;
403   }
404   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
405   return true;
406 }
407
408 static void
409 do_view_next(bool do_it)
410 {
411   // Only switch view if really requested to do so (and not for example while
412   // reset/reposition where /command/view/next is set to false)
413   if( do_it )
414   {
415     globals->get_current_view()->setHeadingOffset_deg(0.0);
416     globals->get_viewmgr()->next_view();
417   }
418 }
419
420 static void
421 do_view_prev(bool do_it)
422 {
423   if( do_it )
424   {
425     globals->get_current_view()->setHeadingOffset_deg(0.0);
426     globals->get_viewmgr()->prev_view();
427   }
428 }
429
430 /**
431  * An fgcommand to toggle fullscreen mode.
432  * No parameters.
433  */
434 static bool
435 do_toggle_fullscreen(const SGPropertyNode *arg)
436 {
437     fgOSFullScreen();
438     return true;
439 }
440
441 /**
442  * Built-in command: cycle view.
443  */
444 static bool
445 do_view_cycle (const SGPropertyNode * arg)
446 {
447   globals->get_current_view()->setHeadingOffset_deg(0.0);
448   globals->get_viewmgr()->next_view();
449   return true;
450 }
451
452 /**
453  * Built-in command: capture screen.
454  */
455 static bool
456 do_screen_capture (const SGPropertyNode * arg)
457 {
458   return fgDumpSnapShot();
459 }
460
461 static bool
462 do_reload_shaders (const SGPropertyNode*)
463 {
464     simgear::reload_shaders();
465     return true;
466 }
467
468 static bool
469 do_dump_scene_graph (const SGPropertyNode*)
470 {
471     fgDumpSceneGraph();
472     return true;
473 }
474
475 static bool
476 do_dump_terrain_branch (const SGPropertyNode*)
477 {
478     fgDumpTerrainBranch();
479
480     double lon_deg = fgGetDouble("/position/longitude-deg");
481     double lat_deg = fgGetDouble("/position/latitude-deg");
482     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
483     SGVec3d zero = SGVec3d::fromGeod(geodPos);
484
485     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
486     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
487     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
488
489     return true;
490 }
491
492 static bool
493 do_print_visible_scene_info(const SGPropertyNode*)
494 {
495     fgPrintVisibleSceneInfoCommand();
496     return true;
497 }
498
499 /**
500  * Built-in command: hires capture screen.
501  */
502 static bool
503 do_hires_screen_capture (const SGPropertyNode * arg)
504 {
505   fgHiResDump();
506   return true;
507 }
508
509
510 /**
511  * Reload the tile cache.
512  */
513 static bool
514 do_tile_cache_reload (const SGPropertyNode * arg)
515 {
516     SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
517     bool freeze = master_freeze->getBoolValue();
518     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
519     if ( !freeze ) {
520         master_freeze->setBoolValue(true);
521     }
522
523     globals->get_subsystem("tile-manager")->reinit();
524
525     if ( !freeze ) {
526         master_freeze->setBoolValue(false);
527     }
528     return true;
529 }
530
531 /**
532  * Reload the materials definition
533  */
534 static bool
535 do_materials_reload (const SGPropertyNode * arg)
536 {
537     SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
538     SGMaterialLib* new_matlib =  new SGMaterialLib;
539     SGPath mpath( globals->get_fg_root() );
540     mpath.append( fgGetString("/sim/rendering/materials-file") );
541     bool loaded = new_matlib->load(globals->get_fg_root(), 
542                                   mpath.str(), 
543                                   globals->get_props());
544
545     if ( ! loaded ) {
546        SG_LOG( SG_GENERAL, SG_ALERT,
547                "Error loading materials file " << mpath.str() );
548        return false;
549     }  
550
551     globals->set_matlib(new_matlib);    
552     FGTileMgr* tileManager = static_cast<FGTileMgr*>(globals->get_subsystem("tile-manager"));
553     tileManager->materialLibChanged();
554     
555     return true;
556 }
557
558 /**
559  * Built-in command: toggle a bool property value.
560  *
561  * property: The name of the property to toggle.
562  */
563 static bool
564 do_property_toggle (const SGPropertyNode * arg)
565 {
566   SGPropertyNode * prop = get_prop(arg);
567   return prop->setBoolValue(!prop->getBoolValue());
568 }
569
570
571 /**
572  * Built-in command: assign a value to a property.
573  *
574  * property: the name of the property to assign.
575  * value: the value to assign; or
576  * property[1]: the property to copy from.
577  */
578 static bool
579 do_property_assign (const SGPropertyNode * arg)
580 {
581   SGPropertyNode * prop = get_prop(arg);
582   const SGPropertyNode * value = arg->getNode("value");
583
584   if (value != 0)
585       return prop->setUnspecifiedValue(value->getStringValue());
586   else
587   {
588       const SGPropertyNode * prop2 = get_prop2(arg);
589       if (prop2)
590           return prop->setUnspecifiedValue(prop2->getStringValue());
591       else
592           return false;
593   }
594 }
595
596
597 /**
598  * Built-in command: increment or decrement a property value.
599  *
600  * If the 'step' argument is present, it will be used; otherwise,
601  * the command uses 'offset' and 'factor', usually from the mouse.
602  *
603  * property: the name of the property to increment or decrement.
604  * step: the amount of the increment or decrement (default: 0).
605  * offset: offset from the current setting (used for the mouse; multiplied 
606  *         by factor)
607  * factor: scaling amount for the offset (defaults to 1).
608  * min: the minimum allowed value (default: no minimum).
609  * max: the maximum allowed value (default: no maximum).
610  * mask: 'integer' to apply only to the left of the decimal point, 
611  *       'decimal' to apply only to the right of the decimal point,
612  *       or 'all' to apply to the whole number (the default).
613  * wrap: true if the value should be wrapped when it passes min or max;
614  *       both min and max must be present for this to work (default:
615  *       false).
616  */
617 static bool
618 do_property_adjust (const SGPropertyNode * arg)
619 {
620   SGPropertyNode * prop = get_prop(arg);
621
622   double amount = 0;
623   if (arg->hasValue("step"))
624       amount = arg->getDoubleValue("step");
625   else
626       amount = (arg->getDoubleValue("factor", 1)
627                 * arg->getDoubleValue("offset"));
628           
629   double unmodifiable, modifiable;
630   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
631               &unmodifiable, &modifiable);
632   modifiable += amount;
633   limit_value(&modifiable, arg);
634
635   prop->setDoubleValue(unmodifiable + modifiable);
636
637   return true;
638 }
639
640
641 /**
642  * Built-in command: multiply a property value.
643  *
644  * property: the name of the property to multiply.
645  * factor: the amount by which to multiply.
646  * min: the minimum allowed value (default: no minimum).
647  * max: the maximum allowed value (default: no maximum).
648  * mask: 'integer' to apply only to the left of the decimal point, 
649  *       'decimal' to apply only to the right of the decimal point,
650  *       or 'all' to apply to the whole number (the default).
651  * wrap: true if the value should be wrapped when it passes min or max;
652  *       both min and max must be present for this to work (default:
653  *       false).
654  */
655 static bool
656 do_property_multiply (const SGPropertyNode * arg)
657 {
658   SGPropertyNode * prop = get_prop(arg);
659   double factor = arg->getDoubleValue("factor", 1);
660
661   double unmodifiable, modifiable;
662   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
663               &unmodifiable, &modifiable);
664   modifiable *= factor;
665   limit_value(&modifiable, arg);
666
667   prop->setDoubleValue(unmodifiable + modifiable);
668
669   return true;
670 }
671
672
673 /**
674  * Built-in command: swap two property values.
675  *
676  * property[0]: the name of the first property.
677  * property[1]: the name of the second property.
678  */
679 static bool
680 do_property_swap (const SGPropertyNode * arg)
681 {
682   SGPropertyNode * prop1 = get_prop(arg);
683   SGPropertyNode * prop2 = get_prop2(arg);
684
685                                 // FIXME: inefficient
686   const string & tmp = prop1->getStringValue();
687   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
688           prop2->setUnspecifiedValue(tmp.c_str()));
689 }
690
691
692 /**
693  * Built-in command: Set a property to an axis or other moving input.
694  *
695  * property: the name of the property to set.
696  * setting: the current input setting, usually between -1.0 and 1.0.
697  * offset: the offset to shift by, before applying the factor.
698  * factor: the factor to multiply by (use negative to reverse).
699  */
700 static bool
701 do_property_scale (const SGPropertyNode * arg)
702 {
703   SGPropertyNode * prop = get_prop(arg);
704   double setting = arg->getDoubleValue("setting");
705   double offset = arg->getDoubleValue("offset", 0.0);
706   double factor = arg->getDoubleValue("factor", 1.0);
707   bool squared = arg->getBoolValue("squared", false);
708   int power = arg->getIntValue("power", (squared ? 2 : 1));
709
710   int sign = (setting < 0 ? -1 : 1);
711
712   switch (power) {
713   case 1:
714       break;
715   case 2:
716       setting = setting * setting * sign;
717       break;
718   case 3:
719       setting = setting * setting * setting;
720       break;
721   case 4:
722       setting = setting * setting * setting * setting * sign;
723       break;
724   default:
725       setting =  pow(setting, power);
726       if ((power % 2) == 0)
727           setting *= sign;
728       break;
729   }
730
731   return prop->setDoubleValue((setting + offset) * factor);
732 }
733
734
735 /**
736  * Built-in command: cycle a property through a set of values.
737  *
738  * If the current value isn't in the list, the cycle will
739  * (re)start from the beginning.
740  *
741  * property: the name of the property to cycle.
742  * value[*]: the list of values to cycle through.
743  */
744 static bool
745 do_property_cycle (const SGPropertyNode * arg)
746 {
747     SGPropertyNode * prop = get_prop(arg);
748     std::vector<SGPropertyNode_ptr> values = arg->getChildren("value");
749     
750     bool wrap = arg->getBoolValue("wrap", true);
751     // compatible with knob/pick animations
752     int offset = arg->getIntValue("offset", 1);
753     
754     int selection = -1;
755     int nSelections = values.size();
756
757     if (nSelections < 1) {
758         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
759         return false;
760     }
761
762                                 // Try to find the current selection
763     for (int i = 0; i < nSelections; i++) {
764         if (compare_values(prop, values[i])) {
765             selection = i;
766             break;
767         }
768     }
769
770     if (selection < 0) { // default to first selection
771         selection = 0;
772     } else {
773         selection += offset;
774         if (wrap) {
775             selection = (selection + nSelections) % nSelections;
776         } else {
777             SG_CLAMP_RANGE(selection, 0, nSelections - 1);
778         }
779     }
780     
781     prop->setUnspecifiedValue(values[selection]->getStringValue());
782     return true;
783 }
784
785
786 /**
787  * Built-in command: randomize a numeric property value.
788  *
789  * property: the name of the property value to randomize.
790  * min: the minimum allowed value.
791  * max: the maximum allowed value.
792  */
793 static bool
794 do_property_randomize (const SGPropertyNode * arg)
795 {
796     SGPropertyNode * prop = get_prop(arg);
797     double min = arg->getDoubleValue("min", DBL_MIN);
798     double max = arg->getDoubleValue("max", DBL_MAX);
799     prop->setDoubleValue(sg_random() * (max - min) + min);
800     return true;
801 }
802
803 /**
804  * Built-in command: interpolate a property value over time
805  *
806  * property:        the name of the property value to interpolate.
807  * type:            the interpolation type ("numeric", "color", etc.)
808  * easing:          name of easing function (see http://easings.net/)
809  * value[0..n]      any number of constant values to interpolate
810  * time/rate[0..n]  time between each value, number of time elements must
811  *                  match those of value elements. Instead of time also rate can
812  *                  be used which automatically calculates the time to change
813  *                  the property value at the given speed.
814  * -or-
815  * property[1..n+1] any number of target values taken from named properties
816  * time/rate[0..n]  time between each value, number of time elements must
817  *                  match those of value elements. Instead of time also rate can
818  *                  be used which automatically calculates the time to change
819  *                  the property value at the given speed.
820  */
821 static bool
822 do_property_interpolate (const SGPropertyNode * arg)
823 {
824   SGPropertyNode * prop = get_prop(arg);
825   if( !prop )
826     return false;
827
828   simgear::PropertyList time_nodes = arg->getChildren("time");
829   simgear::PropertyList rate_nodes = arg->getChildren("rate");
830
831   if( !time_nodes.empty() && !rate_nodes.empty() )
832     // mustn't specify time and rate
833     return false;
834
835   simgear::PropertyList::size_type num_times = time_nodes.empty()
836                                              ? rate_nodes.size()
837                                              : time_nodes.size();
838
839   simgear::PropertyList value_nodes = arg->getChildren("value");
840   if( value_nodes.empty() )
841   {
842     simgear::PropertyList prop_nodes = arg->getChildren("property");
843
844     // must have one more property node
845     if( prop_nodes.size() != num_times + 1 )
846       return false;
847
848     value_nodes.reserve(num_times);
849     for( size_t i = 1; i < prop_nodes.size(); ++i )
850       value_nodes.push_back( fgGetNode(prop_nodes[i]->getStringValue()) );
851   }
852
853   // must match
854   if( value_nodes.size() != num_times )
855     return false;
856
857   double_list deltas;
858   deltas.reserve(num_times);
859
860   if( !time_nodes.empty() )
861   {
862     for( size_t i = 0; i < num_times; ++i )
863       deltas.push_back( time_nodes[i]->getDoubleValue() );
864   }
865   else
866   {
867     for( size_t i = 0; i < num_times; ++i )
868     {
869       // TODO calculate delta based on property type
870       double delta = value_nodes[i]->getDoubleValue()
871                    - ( i > 0
872                      ? value_nodes[i - 1]->getDoubleValue()
873                      : prop->getDoubleValue()
874                      );
875       deltas.push_back( fabs(delta / rate_nodes[i]->getDoubleValue()) );
876     }
877   }
878
879   return prop->interpolate
880   (
881     arg->getStringValue("type", "numeric"),
882     value_nodes,
883     deltas,
884     arg->getStringValue("easing", "linear")
885   );
886 }
887
888 /**
889  * Built-in command: reinit the data logging system based on the
890  * current contents of the /logger tree.
891  */
892 static bool
893 do_data_logging_commit (const SGPropertyNode * arg)
894 {
895     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
896     log->reinit();
897     return true;
898 }
899
900 /**
901  * Built-in command: Add a dialog to the GUI system.  Does *not*
902  * display the dialog.  The property node should have the same format
903  * as a dialog XML configuration.  It must include:
904  *
905  * name: the name of the GUI dialog for future reference.
906  */
907 static bool
908 do_dialog_new (const SGPropertyNode * arg)
909 {
910     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
911     if (!gui) {
912       return false;
913     }
914   
915     // Note the casting away of const: this is *real*.  Doing a
916     // "dialog-apply" command later on will mutate this property node.
917     // I'm not convinced that this isn't the Right Thing though; it
918     // allows client to create a node, pass it to dialog-new, and get
919     // the values back from the dialog by reading the same node.
920     // Perhaps command arguments are not as "const" as they would
921     // seem?
922     gui->newDialog((SGPropertyNode*)arg);
923     return true;
924 }
925
926 /**
927  * Built-in command: Show an XML-configured dialog.
928  *
929  * dialog-name: the name of the GUI dialog to display.
930  */
931 static bool
932 do_dialog_show (const SGPropertyNode * arg)
933 {
934     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
935     gui->showDialog(arg->getStringValue("dialog-name"));
936     return true;
937 }
938
939
940 /**
941  * Built-in Command: Hide the active XML-configured dialog.
942  */
943 static bool
944 do_dialog_close (const SGPropertyNode * arg)
945 {
946     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
947     if(arg->hasValue("dialog-name"))
948         return gui->closeDialog(arg->getStringValue("dialog-name"));
949     return gui->closeActiveDialog();
950 }
951
952
953 /**
954  * Update a value in the active XML-configured dialog.
955  *
956  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
957  */
958 static bool
959 do_dialog_update (const SGPropertyNode * arg)
960 {
961     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
962     FGDialog * dialog;
963     if (arg->hasValue("dialog-name"))
964         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
965     else
966         dialog = gui->getActiveDialog();
967
968     if (dialog != 0) {
969         dialog->updateValues(arg->getStringValue("object-name"));
970         return true;
971     } else {
972         return false;
973     }
974 }
975
976 static bool
977 do_open_browser (const SGPropertyNode * arg)
978 {
979     string path;
980     if (arg->hasValue("path"))
981         path = arg->getStringValue("path");
982     else
983     if (arg->hasValue("url"))
984         path = arg->getStringValue("url");
985     else
986         return false;
987
988     return openBrowser(path);
989 }
990
991 static bool
992 do_open_launcher(const SGPropertyNode *)
993 {
994 #if defined(HAVE_QT)
995     bool ok = flightgear::runInAppLauncherDialog();
996     if (ok) {
997         // start a full reset
998         fgResetIdleState();
999     }
1000     return ok;
1001 #else
1002     return false;
1003 #endif
1004 }
1005
1006 /**
1007  * Apply a value in the active XML-configured dialog.
1008  *
1009  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1010  */
1011 static bool
1012 do_dialog_apply (const SGPropertyNode * arg)
1013 {
1014     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1015     FGDialog * dialog;
1016     if (arg->hasValue("dialog-name"))
1017         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1018     else
1019         dialog = gui->getActiveDialog();
1020
1021     if (dialog != 0) {
1022         dialog->applyValues(arg->getStringValue("object-name"));
1023         return true;
1024     } else {
1025         return false;
1026     }
1027 }
1028
1029
1030 /**
1031  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1032  * unlike reinit().
1033  */
1034 static bool
1035 do_gui_redraw (const SGPropertyNode * arg)
1036 {
1037     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1038     gui->redraw();
1039     return true;
1040 }
1041
1042
1043 /**
1044  * Adds model to the scenery. The path to the added branch (/models/model[*])
1045  * is returned in property "property".
1046  */
1047 static bool
1048 do_add_model (const SGPropertyNode * arg)
1049 {
1050     SGPropertyNode * model = fgGetNode("models", true);
1051     int i;
1052     for (i = 0; model->hasChild("model",i); i++);
1053     model = model->getChild("model", i, true);
1054     copyProperties(arg, model);
1055     if (model->hasValue("elevation-m"))
1056         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1057                 * SG_METER_TO_FEET);
1058     model->getNode("load", true);
1059     model->removeChildren("load");
1060     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1061     return true;
1062 }
1063
1064 /**
1065  * Built-in command: play an audio message (i.e. a wav file) This is
1066  * fire and forget.  Call this once per message and it will get dumped
1067  * into a queue.  Messages are played sequentially so they do not
1068  * overlap.
1069  */
1070 static bool
1071 do_play_audio_sample (const SGPropertyNode * arg)
1072 {
1073     SGSoundMgr *smgr = globals->get_soundmgr();
1074     if (!smgr) {
1075         SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
1076         return false;
1077     }
1078   
1079     string path = arg->getStringValue("path");
1080     string file = arg->getStringValue("file");
1081     float volume = arg->getFloatValue("volume");
1082     // cout << "playing " << path << " / " << file << endl;
1083     try {
1084         FGSampleQueue *queue = globals->get_chatter_queue();
1085         if ( !queue ) {
1086             queue = new FGSampleQueue(smgr, "chatter");
1087             queue->tie_to_listener();
1088             globals->set_chatter_queue(queue);
1089         }
1090
1091         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1092         msg->set_volume( volume );
1093         queue->add( msg );
1094
1095         return true;
1096
1097     } catch (const sg_io_exception&) {
1098         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1099                 "failed to load" << path << '/' << file);
1100         return false;
1101     }
1102 }
1103
1104 /**
1105  * Built-in command: commit presets (read from in /sim/presets/)
1106  */
1107 static bool
1108 do_presets_commit (const SGPropertyNode * arg)
1109 {
1110     if (fgGetBool("/sim/initialized", false)) {
1111       fgResetIdleState();
1112     } else {
1113       // Nasal can trigger this during initial init, which confuses
1114       // the logic in ReInitSubsystems, since initial state has not been
1115       // saved at that time. Short-circuit everything here.
1116       flightgear::initPosition();
1117     }
1118     
1119     return true;
1120 }
1121
1122 /**
1123  * Built-in command: set log level (0 ... 7)
1124  */
1125 static bool
1126 do_log_level (const SGPropertyNode * arg)
1127 {
1128    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1129
1130    return true;
1131 }
1132
1133 /*
1134 static bool
1135 do_decrease_visibility (const SGPropertyNode * arg)
1136 {
1137     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1138     return true;
1139 }
1140  
1141 static bool
1142 do_increase_visibility (const SGPropertyNode * arg)
1143 {
1144     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1145     return true;
1146 }
1147 */
1148 /**
1149  * An fgcommand to allow loading of xml files via nasal,
1150  * the xml file's structure will be made available within
1151  * a property tree node defined under argument "targetnode",
1152  * or in the given argument tree under "data" otherwise.
1153  *
1154  * @param filename a string to hold the complete path & filename of an XML file
1155  * @param targetnode a string pointing to a location within the property tree
1156  * where to store the parsed XML file. If <targetnode> is undefined, then the
1157  * file contents are stored under a node <data> in the argument tree.
1158  */
1159
1160 static bool
1161 do_load_xml_to_proptree(const SGPropertyNode * arg)
1162 {
1163     SGPath file(arg->getStringValue("filename"));
1164     if (file.str().empty())
1165         return false;
1166
1167     if (file.extension() != "xml")
1168         file.concat(".xml");
1169     
1170     std::string icao = arg->getStringValue("icao");
1171     if (icao.empty()) {
1172         if (file.isRelative()) {
1173           SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
1174           if (!absPath.isNull())
1175               file = absPath;
1176           else
1177           {
1178               SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"  
1179                           << file.str() << "'.");
1180               return false;
1181           }
1182         }
1183     } else {
1184         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
1185           SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
1186             << file.str() << " at ICAO:" << icao);
1187           return false;
1188         }
1189     }
1190     
1191     std::string validated_path = fgValidatePath(file, false);
1192     if (validated_path.empty()) {
1193         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1194                 "(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, add them to --fg-aircraft)");
1195         return false;
1196     }
1197
1198     SGPropertyNode *targetnode;
1199     if (arg->hasValue("targetnode"))
1200         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1201     else
1202         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1203
1204     try {
1205         readProperties(validated_path.c_str(), targetnode, true);
1206     } catch (const sg_exception &e) {
1207         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1208         return false;
1209     }
1210
1211     return true;
1212 }
1213
1214 static bool
1215 do_load_xml_from_url(const SGPropertyNode * arg)
1216 {
1217     FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
1218     if (!http) {
1219         SG_LOG(SG_IO, SG_ALERT, "xmlhttprequest: HTTP client not running");
1220         return false;
1221     }
1222   
1223     std::string url(arg->getStringValue("url"));
1224     if (url.empty())
1225         return false;
1226         
1227     SGPropertyNode *targetnode;
1228     if (arg->hasValue("targetnode"))
1229         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1230     else
1231         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1232     
1233     RemoteXMLRequest* req = new RemoteXMLRequest(url, targetnode);
1234     
1235     if (arg->hasChild("body"))
1236         req->setBodyData(arg->getChild("body"));
1237     
1238 // connect up optional reporting properties
1239     if (arg->hasValue("complete")) 
1240         req->setCompletionProp(fgGetNode(arg->getStringValue("complete"), true));
1241     if (arg->hasValue("failure")) 
1242         req->setFailedProp(fgGetNode(arg->getStringValue("failure"), true));
1243     if (arg->hasValue("status")) 
1244         req->setStatusProp(fgGetNode(arg->getStringValue("status"), true));
1245         
1246     http->makeRequest(req);
1247     return true;
1248 }
1249
1250
1251 /**
1252  * An fgcommand to allow saving of xml files via nasal,
1253  * the file's structure will be determined based on what's
1254  * encountered in the passed (source) property tree node
1255  *
1256  * @param filename a string to hold the complete path & filename of the (new)
1257  * XML file
1258  * @param sourcenode a string pointing to a location within the property tree
1259  * where to find the nodes that should be written recursively into an XML file
1260  * @param data if no sourcenode is given, then the file contents are taken from
1261  * the argument tree's "data" node.
1262  */
1263
1264 static bool
1265 do_save_xml_from_proptree(const SGPropertyNode * arg)
1266 {
1267     SGPath file(arg->getStringValue("filename"));
1268     if (file.str().empty())
1269         return false;
1270
1271     if (file.extension() != "xml")
1272         file.concat(".xml");
1273
1274     std::string validated_path = fgValidatePath(file, true);
1275     if (validated_path.empty()) {
1276         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1277                 "(unauthorized directory - authorization no longer follows symlinks)");
1278         return false;
1279     }
1280
1281     SGPropertyNode *sourcenode;
1282     if (arg->hasValue("sourcenode"))
1283         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1284     else if (arg->getNode("data", false))
1285         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1286     else
1287         return false;
1288
1289     try {
1290         writeProperties (validated_path.c_str(), sourcenode, true);
1291     } catch (const sg_exception &e) {
1292         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1293         return false;
1294     }
1295
1296     return true;
1297 }
1298
1299 static bool
1300 do_press_cockpit_button (const SGPropertyNode *arg)
1301 {
1302   const char *prefix = arg->getStringValue("prefix");
1303
1304   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1305     return true;
1306
1307   string prop = string(prefix) + "-button";
1308   double value;
1309
1310   if (arg->getBoolValue("latching"))
1311     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1312   else
1313     value = 1;
1314
1315   fgSetDouble(prop.c_str(), value);
1316   fgSetBool(arg->getStringValue("discrete"), value > 0);
1317
1318   return true;
1319 }
1320
1321 static bool
1322 do_release_cockpit_button (const SGPropertyNode *arg)
1323 {
1324   const char *prefix = arg->getStringValue("prefix");
1325
1326   if (arg->getBoolValue("guarded")) {
1327     string prop = string(prefix) + "-guard";
1328     if (fgGetDouble(prop.c_str()) < 1) {
1329       fgSetDouble(prop.c_str(), 1);
1330       return true;
1331     }
1332   }
1333
1334   if (! arg->getBoolValue("latching")) {
1335     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1336     fgSetBool(arg->getStringValue("discrete"), false);
1337   }
1338
1339   return true;
1340 }
1341
1342 // Optional profiling commands using gperftools:
1343 // http://code.google.com/p/gperftools/
1344
1345 #if !FG_HAVE_GPERFTOOLS
1346 static void
1347 no_profiling_support()
1348 {
1349   SG_LOG
1350   (
1351     SG_GENERAL,
1352     SG_WARN,
1353     "No profiling support! Install gperftools and reconfigure/rebuild fgfs."
1354   );
1355 }
1356 #endif
1357
1358 static bool
1359 do_profiler_start(const SGPropertyNode *arg)
1360 {
1361 #if FG_HAVE_GPERFTOOLS
1362   const char *filename = arg->getStringValue("filename", "fgfs.profile");
1363   ProfilerStart(filename);
1364   return true;
1365 #else
1366   no_profiling_support();
1367   return false;
1368 #endif
1369 }
1370
1371 static bool
1372 do_profiler_stop(const SGPropertyNode *arg)
1373 {
1374 #if FG_HAVE_GPERFTOOLS
1375   ProfilerStop();
1376   return true;
1377 #else
1378   no_profiling_support();
1379   return false;
1380 #endif
1381 }
1382
1383
1384 static bool
1385 do_set_scenery_paths(const SGPropertyNode* arg)
1386 {
1387   globals->clear_fg_scenery();
1388   
1389   std::string terrasyncPath(fgGetString("/sim/terrasync/scenery-dir"));
1390   bool seenTerrasyncPath = false;
1391   
1392   simgear::PropertyList paths = arg->getChildren("path");
1393   for (size_t i = 0; i < paths.size(); ++i) {
1394     std::string s = paths[i]->getStringValue();
1395     if (s == terrasyncPath) {
1396       seenTerrasyncPath = true;
1397     }
1398     
1399     globals->append_fg_scenery(s);
1400   }
1401   
1402   if (fgGetBool("/sim/terrasync/enabled") && !seenTerrasyncPath) {
1403     globals->append_fg_scenery(terrasyncPath);
1404   }
1405   
1406   if (paths.empty()) {
1407     // no scenery paths set *at all*, use the data in FG_ROOT
1408     SGPath root(globals->get_fg_root());
1409     root.append("Scenery");
1410     globals->append_fg_scenery(root.str());
1411   }
1412
1413   return true;
1414 }
1415
1416 ////////////////////////////////////////////////////////////////////////
1417 // Command setup.
1418 ////////////////////////////////////////////////////////////////////////
1419
1420
1421 /**
1422  * Table of built-in commands.
1423  *
1424  * New commands do not have to be added here; any module in the application
1425  * can add a new command using globals->get_commands()->addCommand(...).
1426  */
1427 static struct {
1428   const char * name;
1429   SGCommandMgr::command_t command;
1430 } built_ins [] = {
1431     { "null", do_null },
1432     { "nasal", do_nasal },
1433     { "exit", do_exit },
1434     { "reset", do_reset },
1435     { "reposition", do_reposition },
1436     { "switch-aircraft", do_switch_aircraft },
1437     { "pause", do_pause },
1438     { "load", do_load },
1439     { "save", do_save },
1440     { "save-tape", do_save_tape },
1441     { "load-tape", do_load_tape },
1442     { "panel-load", do_panel_load },
1443     { "preferences-load", do_preferences_load },
1444     { "toggle-fullscreen", do_toggle_fullscreen },
1445     { "view-cycle", do_view_cycle },
1446     { "screen-capture", do_screen_capture },
1447     { "hires-screen-capture", do_hires_screen_capture },
1448     { "tile-cache-reload", do_tile_cache_reload },
1449     /*
1450     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1451     { "set-outside-air-temp-degc", do_set_oat_degc },
1452     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1453     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1454     */
1455     { "property-toggle", do_property_toggle },
1456     { "property-assign", do_property_assign },
1457     { "property-adjust", do_property_adjust },
1458     { "property-multiply", do_property_multiply },
1459     { "property-swap", do_property_swap },
1460     { "property-scale", do_property_scale },
1461     { "property-cycle", do_property_cycle },
1462     { "property-randomize", do_property_randomize },
1463     { "property-interpolate", do_property_interpolate },
1464     { "data-logging-commit", do_data_logging_commit },
1465     { "dialog-new", do_dialog_new },
1466     { "dialog-show", do_dialog_show },
1467     { "dialog-close", do_dialog_close },
1468     { "dialog-update", do_dialog_update },
1469     { "dialog-apply", do_dialog_apply },
1470     { "open-browser", do_open_browser },
1471     { "gui-redraw", do_gui_redraw },
1472     { "add-model", do_add_model },
1473     { "play-audio-sample", do_play_audio_sample },
1474     { "presets-commit", do_presets_commit },
1475     { "log-level", do_log_level },
1476     { "replay", do_replay },
1477     { "open-launcher", do_open_launcher },
1478     /*
1479     { "decrease-visibility", do_decrease_visibility },
1480     { "increase-visibility", do_increase_visibility },
1481     */
1482     { "loadxml", do_load_xml_to_proptree},
1483     { "savexml", do_save_xml_from_proptree },
1484     { "xmlhttprequest", do_load_xml_from_url },
1485     { "press-cockpit-button", do_press_cockpit_button },
1486     { "release-cockpit-button", do_release_cockpit_button },
1487     { "dump-scenegraph", do_dump_scene_graph },
1488     { "dump-terrainbranch", do_dump_terrain_branch },
1489     { "print-visible-scene", do_print_visible_scene_info },
1490     { "reload-shaders", do_reload_shaders },
1491     { "reload-materials", do_materials_reload },
1492     { "set-scenery-paths", do_set_scenery_paths },
1493   
1494     { "profiler-start", do_profiler_start },
1495     { "profiler-stop",  do_profiler_stop },
1496
1497     { 0, 0 }                    // zero-terminated
1498 };
1499
1500
1501 /**
1502  * Initialize the default built-in commands.
1503  *
1504  * Other commands may be added by other parts of the application.
1505  */
1506 void
1507 fgInitCommands ()
1508 {
1509   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1510   for (int i = 0; built_ins[i].name != 0; i++) {
1511     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1512     globals->get_commands()->addCommand(built_ins[i].name,
1513                                         built_ins[i].command);
1514   }
1515
1516   typedef bool (*dummy)();
1517   fgTie( "/command/view/next", dummy(0), do_view_next );
1518   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1519
1520   globals->get_props()->setValueReadOnly( "/sim/debug/profiler-available",
1521                                           bool(FG_HAVE_GPERFTOOLS) );
1522 }
1523
1524 // end of fg_commands.cxx