From df2356050d2101915b9a66aff39d617d4b84bace Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 18 Nov 2002 21:31:33 +0000 Subject: [PATCH] Added a "Presets" menu. --- src/GUI/Makefile.am | 1 + src/GUI/gui.cxx | 4 +- src/GUI/gui_funcs.cxx | 12 +- src/GUI/gui_local.cxx | 3 + src/GUI/preset_dlg.cxx | 294 +++++++++++++++++++++++++++++++++++++++++ src/GUI/preset_dlg.hxx | 10 ++ src/Main/fg_init.cxx | 15 +-- src/Main/fg_init.hxx | 6 +- src/Main/globals.cxx | 40 ++++-- src/Main/options.cxx | 4 +- 10 files changed, 360 insertions(+), 29 deletions(-) create mode 100644 src/GUI/preset_dlg.cxx create mode 100644 src/GUI/preset_dlg.hxx diff --git a/src/GUI/Makefile.am b/src/GUI/Makefile.am index e62874385..2d780faec 100644 --- a/src/GUI/Makefile.am +++ b/src/GUI/Makefile.am @@ -13,6 +13,7 @@ libGUI_a_SOURCES = \ gui_local.cxx gui_local.hxx \ mouse.cxx \ $(NETWORK_SRCS) \ + preset_dlg.cxx preset_dlg.hxx \ prop_picker.cxx prop_picker.hxx \ sgVec3Slider.cxx sgVec3Slider.hxx \ trackball.c trackball.h diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index 4290659eb..a0bc37319 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -47,8 +47,8 @@ #include "gui.h" #include "gui_local.hxx" -#include "apt_dlg.hxx" #include "net_dlg.hxx" +#include "preset_dlg.hxx" // main.cxx hack, should come from an include someplace @@ -229,7 +229,7 @@ void guiInit() // Set up our Dialog Boxes ConfirmExitDialogInit(); - NewAirportInit(); + fgPresetInit(); #ifdef FG_NETWORK_OLK NewNetIdInit(); diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index aaec44362..100d34af7 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -91,10 +91,10 @@ #include "gui.h" #include "gui_local.hxx" -#include "apt_dlg.hxx" #include "net_dlg.hxx" -#include "sgVec3Slider.hxx" +#include "preset_dlg.hxx" #include "prop_picker.hxx" +#include "sgVec3Slider.hxx" SG_USING_STD(string); @@ -172,7 +172,13 @@ const __fg_gui_fn_t __fg_gui_fn[] = { {"prop_pickerView", prop_pickerView}, // Environment - {"NewAirport", NewAirport}, + {"fgPresetAirport", fgPresetAirport}, + {"fgPresetRunway", fgPresetRunway}, + {"fgPresetOffsetDistance", fgPresetOffsetDistance}, + {"fgPresetAltitude", fgPresetAltitude}, + {"fgPresetGlideslope", fgPresetGlideslope}, + {"fgPresetAirspeed", fgPresetAirspeed}, + {"fgPresetCommit", fgPresetCommit}, // Network #ifdef FG_NETWORK_OLK diff --git a/src/GUI/gui_local.cxx b/src/GUI/gui_local.cxx index 1342ce2f8..3d9152bc9 100644 --- a/src/GUI/gui_local.cxx +++ b/src/GUI/gui_local.cxx @@ -73,6 +73,9 @@ void reInit(puObject *cb) globals->restoreInitialState(); + // update our position based on current presets + fgInitPosition(); + SGTime *t = globals->get_time_params(); delete t; t = fgInitTime(); diff --git a/src/GUI/preset_dlg.cxx b/src/GUI/preset_dlg.cxx new file mode 100644 index 000000000..811072692 --- /dev/null +++ b/src/GUI/preset_dlg.cxx @@ -0,0 +1,294 @@ +// preset_dlg.cxx -- Preset dialogs and funcitons +// +// Written by Curtis Olson, started November 2002. +// +// Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#ifdef HAVE_WINDOWS_H +# include +#endif + +// #include + +// #include +// #include +#include + +// #include + +// #include +// #include + +#include +#include +#include
+#include
+#include + +#include "gui.h" +#include "preset_dlg.hxx" + + +static puDialogBox *PresetDialog = 0; +static puFrame *PresetDialogFrame = 0; +static puText *PresetDialogMessage = 0; +static puInput *PresetDialogInput = 0; + +static const int MAX_VALUE = 16; +static char PresetValue[MAX_VALUE]; +static char PresetSavedValue[MAX_VALUE]; +static char PresetLabel[] = "Enter New Airport ID"; +static string PresetProperty = ""; + +static puOneShot *PresetDialogOkButton = 0; +static puOneShot *PresetDialogCancelButton = 0; +static puOneShot *PresetDialogResetButton = 0; + + +static void PresetDialog_OK(puObject *) +{ + char *value; + PresetDialogInput->getValue(&value); + cout << "setting " << PresetProperty << " = " << value << endl; + fgSetString( PresetProperty.c_str(), value ); + FG_POP_PUI_DIALOG( PresetDialog ); + + // consistancy handling for some specialized cases + if ( PresetProperty == "/sim/presets/airport-id" ) { + fgSetDouble("/sim/presets/longitude-deg", -9999.0 ); + fgSetDouble("/sim/presets/latitude-deg", -9999.0 ); + } else if ( PresetProperty == "/sim/presets/runway" ) { + fgSetDouble("/sim/presets/longitude-deg", -9999.0 ); + fgSetDouble("/sim/presets/latitude-deg", -9999.0 ); + } else if ( PresetProperty == "/sim/presets/offset-distance" ) { + if ( fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001 + && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) { + fgSetDouble("/sim/presets/altitude-ft", -9999.0); + cout << "nuking altitude" << endl; + } + } else if ( PresetProperty == "/sim/presets/altitude-ft" ) { + if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001 + && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) { + fgSetDouble("/sim/presets/offset-distance", 0.0); + cout << "nuking offset distance" << endl; + } + } else if ( PresetProperty == "/sim/presets/glideslope-deg" ) { + if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001 + && fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001 ) { + fgSetDouble("/sim/presets/altitude-ft", -9999.0); + cout << "nuking altitude" << endl; + } + } +} + + +static void PresetDialog_Cancel(puObject *) +{ + FG_POP_PUI_DIALOG( PresetDialog ); +} + + +static void PresetDialog_Reset(puObject *) +{ + PresetDialogInput->setValue( PresetSavedValue ); + PresetDialogInput->setCursor( 0 ) ; +} + + +// Initialize the preset dialog box +void fgPresetInit() +{ + sprintf( PresetValue, "%s", fgGetString("/sim/presets/airport-id") ); + int len = 150 + - puGetDefaultLabelFont().getStringWidth( PresetLabel ) / 2; + + PresetDialog = new puDialogBox (150, 50); + { + PresetDialogFrame = new puFrame (0,0,350, 150); + PresetDialogMessage = new puText (len, 110); + PresetDialogMessage -> setLabel (""); + + PresetDialogInput = new puInput (50, 70, 300, 100); + PresetDialogInput -> setValue (""); + PresetDialogInput -> acceptInput(); + + PresetDialogOkButton = new puOneShot (50, 10, 110, 50); + PresetDialogOkButton -> setLegend(gui_msg_OK); + PresetDialogOkButton -> setCallback (PresetDialog_OK); + PresetDialogOkButton -> makeReturnDefault(TRUE); + + PresetDialogCancelButton = new puOneShot (140, 10, 210, 50); + PresetDialogCancelButton -> setLegend (gui_msg_CANCEL); + PresetDialogCancelButton -> setCallback (PresetDialog_Cancel); + + PresetDialogResetButton = new puOneShot (240, 10, 300, 50); + PresetDialogResetButton -> setLegend (gui_msg_RESET); + PresetDialogResetButton -> setCallback (PresetDialog_Reset); + } + cout << "PresetInit " << PresetValue << endl; + FG_FINALIZE_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetAirport(puObject *cb) +{ + PresetDialogMessage -> setLabel( "Enter Airport ID:" ); + PresetProperty = "/sim/presets/airport-id"; + snprintf( PresetValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + snprintf( PresetSavedValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + PresetDialogInput->setValue( PresetValue ); + + FG_PUSH_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetRunway(puObject *cb) +{ + PresetDialogMessage -> setLabel( "Enter Runway Number:" ); + PresetProperty = "/sim/presets/runway"; + snprintf( PresetValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + snprintf( PresetSavedValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + PresetDialogInput->setValue( PresetValue ); + + FG_PUSH_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetOffsetDistance(puObject *cb) +{ + PresetDialogMessage -> setLabel( "Enter Offset Distance (miles):" ); + PresetProperty = "/sim/presets/offset-distance"; + snprintf( PresetValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + snprintf( PresetSavedValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + PresetDialogInput->setValue( PresetValue ); + + FG_PUSH_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetAltitude(puObject *cb) +{ + PresetDialogMessage -> setLabel( "Enter Altitude (feet):" ); + PresetProperty = "/sim/presets/altitude-ft"; + snprintf( PresetValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + snprintf( PresetSavedValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + PresetDialogInput->setValue( PresetValue ); + + FG_PUSH_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetGlideslope(puObject *cb) +{ + PresetDialogMessage -> setLabel( "Enter Glideslope (deg):" ); + PresetProperty = "/sim/presets/glideslope-deg"; + snprintf( PresetValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + snprintf( PresetSavedValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + PresetDialogInput->setValue( PresetValue ); + + FG_PUSH_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetAirspeed(puObject *cb) +{ + PresetDialogMessage -> setLabel( "Enter Airspeed (kts):" ); + PresetProperty = "/sim/presets/airspeed-kt"; + snprintf( PresetValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + snprintf( PresetSavedValue, MAX_VALUE, "%s", + fgGetString(PresetProperty.c_str()) ); + PresetDialogInput->setValue( PresetValue ); + + FG_PUSH_PUI_DIALOG( PresetDialog ); +} + + +void fgPresetCommit(puObject *) +{ + static const SGPropertyNode *longitude + = fgGetNode("/sim/presets/longitude-deg"); + static const SGPropertyNode *latitude + = fgGetNode("/sim/presets/latitude-deg"); + static const SGPropertyNode *master_freeze + = fgGetNode("/sim/freeze/master"); + + SGPath path( globals->get_fg_root() ); + path.append( "Airports" ); + path.append( "simple.mk4" ); + FGAirports airports( path.c_str() ); + + FGAirport a; + + bool freeze = master_freeze->getBoolValue(); + if ( !freeze ) { + fgSetBool("/sim/freeze/master", true); + } + + // unbind the current fdm state so property changes + // don't get lost when we subsequently delete this fdm + // and create a new one. + cur_fdm_state->unbind(); + + // invalidate lon/lat if an airport is specified in the presets + string apt = fgGetString("/sim/presets/airport-id"); + if ( !apt.empty() ) { + fgSetDouble("/sim/presets/longitude-deg", -9999.0 ); + fgSetDouble("/sim/presets/latitude-deg", -9999.0 ); + } + + // set position from presets + fgInitPosition(); + + // BusyCursor(0); + fgReInitSubsystems(); + + cout << "before tile_mgr init " << longitude->getDoubleValue() << " " + << latitude->getDoubleValue() << endl; + + double visibility_meters = + fgGetDouble("/environment/visibility-m"); + global_tile_mgr.update( longitude->getDoubleValue(), + latitude->getDoubleValue(), + visibility_meters ); + // BusyCursor(1); + + if ( !freeze ) { + fgSetBool("/sim/freeze/master", false); + } +} + + diff --git a/src/GUI/preset_dlg.hxx b/src/GUI/preset_dlg.hxx new file mode 100644 index 000000000..fe3e3070a --- /dev/null +++ b/src/GUI/preset_dlg.hxx @@ -0,0 +1,10 @@ +#include + +extern void fgPresetAirport(puObject *cb); +extern void fgPresetRunway(puObject *cb); +extern void fgPresetOffsetDistance(puObject *cb); +extern void fgPresetAltitude(puObject *cb); +extern void fgPresetGlideslope(puObject *cb); +extern void fgPresetAirspeed(puObject *cb); +extern void fgPresetCommit(puObject *cb); +extern void fgPresetInit(); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index e9f2e6dcf..d7b3a6da8 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -895,7 +895,8 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) { static void fgSetDistOrAltFromGlideSlope() { - double gs = fgGetDouble("/sim/presets/glideslope"); + double gs = fgGetDouble("/sim/presets/glideslope-deg") + * SG_DEGREES_TO_RADIANS ; double od = fgGetDouble("/sim/presets/offset-distance"); double alt = fgGetDouble("/sim/presets/altitude-ft"); @@ -917,7 +918,7 @@ static void fgSetDistOrAltFromGlideSlope() { SG_LOG( SG_GENERAL, SG_ALERT, "Glideslope given but not altitude or offset-distance." ); SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" ); - fgSetDouble("/sim/presets/glideslope", 0); + fgSetDouble("/sim/presets/glideslope-deg", 0); } } @@ -1196,7 +1197,7 @@ SGTime *fgInitTime() { // initialization routines. If you are adding a subsystem to flight // gear, its initialization call should located in this routine. // Returns non-zero if a problem encountered. -bool fgInitSubsystems( void ) { +bool fgInitSubsystems() { static const SGPropertyNode *longitude = fgGetNode("/sim/presets/longitude-deg"); static const SGPropertyNode *latitude @@ -1611,7 +1612,7 @@ bool fgInitSubsystems( void ) { } -void fgReInitSubsystems( void ) +void fgReInitSubsystems() { static const SGPropertyNode *longitude = fgGetNode("/sim/presets/longitude-deg"); @@ -1630,12 +1631,8 @@ void fgReInitSubsystems( void ) if ( !freeze ) { fgSetBool("/sim/freeze/master", true); } - - // Initialize the Scenery Management subsystem - // FIXME, what really needs to get initialized here, at the time - // this was commented out, scenery.init() was a noop - // scenery.init(); + // Initialize the FDM fgInitFDM(); // allocates structures so must happen before any of the flight diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index cd529cc6f..fecdab7e2 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -63,17 +63,17 @@ SGPropertyNode *fgInitLocale(const char *language); // General house keeping initializations -bool fgInitGeneral ( void ); +bool fgInitGeneral (); // This is the top level init routine which calls all the other // initialization routines. If you are adding a subsystem to flight // gear, its initialization call should located in this routine. -bool fgInitSubsystems( void ); +bool fgInitSubsystems(); // Reset -void fgReInitSubsystems( void ); +void fgReInitSubsystems(); // find basic airport location info from airport database diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index e28dbce22..b8341e4c7 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -51,9 +51,9 @@ FGGlobals::FGGlobals() : warp_delta( 0 ), props(new SGPropertyNode), initial_state(0), + locale(NULL), commands(new SGCommandMgr), - io(new FGIO), - locale(NULL) + io(new FGIO) { } @@ -84,14 +84,34 @@ FGGlobals::saveInitialState () void FGGlobals::restoreInitialState () { - if (initial_state == 0) { - SG_LOG(SG_GENERAL, SG_ALERT, "No initial state available to restore!!!"); - } else if (!copyProperties(initial_state, props)) { - SG_LOG(SG_GENERAL, SG_INFO, - "Some errors restoring initial state (probably just read-only props)"); - } else { - SG_LOG(SG_GENERAL, SG_INFO, "Initial state restored successfully"); - } + if ( initial_state == 0 ) { + SG_LOG(SG_GENERAL, SG_ALERT, + "No initial state available to restore!!!"); + return; + } + + SGPropertyNode *currentPresets = new SGPropertyNode; + SGPropertyNode *targetNode = fgGetNode( "/sim/presets" ); + + // stash the /sim/presets tree + if ( !copyProperties(targetNode, currentPresets) ) { + SG_LOG( SG_GENERAL, SG_ALERT, "Failed to save /sim/presets subtree" ); + } + + if ( copyProperties(initial_state, props) ) { + SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" ); + } else { + SG_LOG( SG_GENERAL, SG_INFO, + "Some errors restoring initial state (read-only props?)" ); + } + + // recover the /sim/presets tree + if ( !copyProperties(currentPresets, targetNode) ) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Failed to restore /sim/presets subtree" ); + } + + delete currentPresets; } FGViewer * diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 7a7eb7f44..51d52c6a1 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -763,8 +763,8 @@ parse_option (const string& arg) } else if ( arg.find( "--pitch=" ) == 0 ) { fgSetDouble("/sim/presets/pitch-deg", atof(arg.substr(8))); } else if ( arg.find( "--glideslope=" ) == 0 ) { - fgSetDouble("/sim/presets/glideslope", - atof(arg.substr(13)) * SG_DEGREES_TO_RADIANS ); + fgSetDouble("/sim/presets/glideslope-deg", + atof(arg.substr(13))); } else if ( arg.find( "--roc=" ) == 0 ) { fgSetDouble("/velocities/vertical-speed-fps", atof(arg.substr(6))/60); } else if ( arg.find( "--fg-root=" ) == 0 ) {