1 // preset_dlg.cxx -- Preset dialogs and funcitons
3 // Written by Curtis Olson, started November 2002.
5 // Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/compiler.h>
34 // #include <stdlib.h>
36 // #include <simgear/constants.h>
37 // #include <simgear/debug/logstream.hxx>
38 #include <simgear/misc/sg_path.hxx>
40 // #include <Include/general.hxx>
42 // #include <GL/glut.h>
45 #include <Airports/simple.hxx>
46 #include <FDM/flight.hxx>
47 #include <Main/fg_init.hxx>
48 #include <Main/fg_props.hxx>
49 #include <Scenery/tilemgr.hxx>
52 #include "preset_dlg.hxx"
55 static puDialogBox *PresetDialog = 0;
56 static puFrame *PresetDialogFrame = 0;
57 static puText *PresetDialogMessage = 0;
58 static puInput *PresetDialogInput = 0;
60 static const int MAX_VALUE = 16;
61 static char PresetValue[MAX_VALUE];
62 static char PresetSavedValue[MAX_VALUE];
63 static char PresetLabel[] = "Enter New Airport ID";
64 static string PresetProperty = "";
66 static puOneShot *PresetDialogOkButton = 0;
67 static puOneShot *PresetDialogCancelButton = 0;
68 static puOneShot *PresetDialogResetButton = 0;
71 static void PresetDialog_OK(puObject *)
74 PresetDialogInput->getValue(&value);
75 cout << "setting " << PresetProperty << " = " << value << endl;
76 fgSetString( PresetProperty.c_str(), value );
77 FG_POP_PUI_DIALOG( PresetDialog );
79 // consistancy handling for some specialized cases
80 if ( PresetProperty == "/sim/presets/airport-id" ) {
81 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
82 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
83 } else if ( PresetProperty == "/sim/presets/runway" ) {
84 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
85 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
86 } else if ( PresetProperty == "/sim/presets/offset-distance" ) {
87 if ( fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001
88 && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) {
89 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
90 cout << "nuking altitude" << endl;
92 } else if ( PresetProperty == "/sim/presets/altitude-ft" ) {
93 if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001
94 && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) {
95 fgSetDouble("/sim/presets/offset-distance", 0.0);
96 cout << "nuking offset distance" << endl;
98 } else if ( PresetProperty == "/sim/presets/glideslope-deg" ) {
99 if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001
100 && fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001 ) {
101 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
102 cout << "nuking altitude" << endl;
108 static void PresetDialog_Cancel(puObject *)
110 FG_POP_PUI_DIALOG( PresetDialog );
114 static void PresetDialog_Reset(puObject *)
116 PresetDialogInput->setValue( PresetSavedValue );
117 PresetDialogInput->setCursor( 0 ) ;
121 // Initialize the preset dialog box
124 sprintf( PresetValue, "%s", fgGetString("/sim/presets/airport-id") );
126 - puGetDefaultLabelFont().getStringWidth( PresetLabel ) / 2;
128 PresetDialog = new puDialogBox (150, 50);
130 PresetDialogFrame = new puFrame (0,0,350, 150);
131 PresetDialogMessage = new puText (len, 110);
132 PresetDialogMessage -> setLabel ("");
134 PresetDialogInput = new puInput (50, 70, 300, 100);
135 PresetDialogInput -> setValue ("");
136 PresetDialogInput -> acceptInput();
138 PresetDialogOkButton = new puOneShot (50, 10, 110, 50);
139 PresetDialogOkButton -> setLegend(gui_msg_OK);
140 PresetDialogOkButton -> setCallback (PresetDialog_OK);
141 PresetDialogOkButton -> makeReturnDefault(TRUE);
143 PresetDialogCancelButton = new puOneShot (140, 10, 210, 50);
144 PresetDialogCancelButton -> setLegend (gui_msg_CANCEL);
145 PresetDialogCancelButton -> setCallback (PresetDialog_Cancel);
147 PresetDialogResetButton = new puOneShot (240, 10, 300, 50);
148 PresetDialogResetButton -> setLegend (gui_msg_RESET);
149 PresetDialogResetButton -> setCallback (PresetDialog_Reset);
151 cout << "PresetInit " << PresetValue << endl;
152 FG_FINALIZE_PUI_DIALOG( PresetDialog );
156 void fgPresetAirport(puObject *cb)
158 PresetDialogMessage -> setLabel( "Enter Airport ID:" );
159 PresetProperty = "/sim/presets/airport-id";
160 snprintf( PresetValue, MAX_VALUE, "%s",
161 fgGetString(PresetProperty.c_str()) );
162 snprintf( PresetSavedValue, MAX_VALUE, "%s",
163 fgGetString(PresetProperty.c_str()) );
164 PresetDialogInput->setValue( PresetValue );
166 FG_PUSH_PUI_DIALOG( PresetDialog );
170 void fgPresetRunway(puObject *cb)
172 PresetDialogMessage -> setLabel( "Enter Runway Number:" );
173 PresetProperty = "/sim/presets/runway";
174 snprintf( PresetValue, MAX_VALUE, "%s",
175 fgGetString(PresetProperty.c_str()) );
176 snprintf( PresetSavedValue, MAX_VALUE, "%s",
177 fgGetString(PresetProperty.c_str()) );
178 PresetDialogInput->setValue( PresetValue );
180 FG_PUSH_PUI_DIALOG( PresetDialog );
184 void fgPresetOffsetDistance(puObject *cb)
186 PresetDialogMessage -> setLabel( "Enter Offset Distance (miles):" );
187 PresetProperty = "/sim/presets/offset-distance";
188 snprintf( PresetValue, MAX_VALUE, "%s",
189 fgGetString(PresetProperty.c_str()) );
190 snprintf( PresetSavedValue, MAX_VALUE, "%s",
191 fgGetString(PresetProperty.c_str()) );
192 PresetDialogInput->setValue( PresetValue );
194 FG_PUSH_PUI_DIALOG( PresetDialog );
198 void fgPresetAltitude(puObject *cb)
200 PresetDialogMessage -> setLabel( "Enter Altitude (feet):" );
201 PresetProperty = "/sim/presets/altitude-ft";
202 snprintf( PresetValue, MAX_VALUE, "%s",
203 fgGetString(PresetProperty.c_str()) );
204 snprintf( PresetSavedValue, MAX_VALUE, "%s",
205 fgGetString(PresetProperty.c_str()) );
206 PresetDialogInput->setValue( PresetValue );
208 FG_PUSH_PUI_DIALOG( PresetDialog );
212 void fgPresetGlideslope(puObject *cb)
214 PresetDialogMessage -> setLabel( "Enter Glideslope (deg):" );
215 PresetProperty = "/sim/presets/glideslope-deg";
216 snprintf( PresetValue, MAX_VALUE, "%s",
217 fgGetString(PresetProperty.c_str()) );
218 snprintf( PresetSavedValue, MAX_VALUE, "%s",
219 fgGetString(PresetProperty.c_str()) );
220 PresetDialogInput->setValue( PresetValue );
222 FG_PUSH_PUI_DIALOG( PresetDialog );
226 void fgPresetAirspeed(puObject *cb)
228 PresetDialogMessage -> setLabel( "Enter Airspeed (kts):" );
229 PresetProperty = "/sim/presets/airspeed-kt";
230 snprintf( PresetValue, MAX_VALUE, "%s",
231 fgGetString(PresetProperty.c_str()) );
232 snprintf( PresetSavedValue, MAX_VALUE, "%s",
233 fgGetString(PresetProperty.c_str()) );
234 PresetDialogInput->setValue( PresetValue );
236 FG_PUSH_PUI_DIALOG( PresetDialog );
240 void fgPresetCommit(puObject *)
242 static const SGPropertyNode *longitude
243 = fgGetNode("/sim/presets/longitude-deg");
244 static const SGPropertyNode *latitude
245 = fgGetNode("/sim/presets/latitude-deg");
246 static const SGPropertyNode *master_freeze
247 = fgGetNode("/sim/freeze/master");
249 SGPath path( globals->get_fg_root() );
250 path.append( "Airports" );
251 path.append( "simple.mk4" );
252 FGAirports airports( path.c_str() );
256 bool freeze = master_freeze->getBoolValue();
258 fgSetBool("/sim/freeze/master", true);
261 // unbind the current fdm state so property changes
262 // don't get lost when we subsequently delete this fdm
263 // and create a new one.
264 cur_fdm_state->unbind();
266 // invalidate lon/lat if an airport is specified in the presets
267 string apt = fgGetString("/sim/presets/airport-id");
268 if ( !apt.empty() ) {
269 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
270 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
273 // set position from presets
277 fgReInitSubsystems();
279 cout << "before tile_mgr init " << longitude->getDoubleValue() << " "
280 << latitude->getDoubleValue() << endl;
282 double visibility_meters = fgGetDouble("/environment/visibility-m");
283 global_tile_mgr.update( visibility_meters );
287 fgSetBool("/sim/freeze/master", false);