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 <simgear/misc/commands.hxx>
35 #include <simgear/misc/sg_path.hxx>
37 #include <Main/fg_props.hxx>
40 #include "preset_dlg.hxx"
43 static puDialogBox *PresetDialog = 0;
44 static puFrame *PresetDialogFrame = 0;
45 static puText *PresetDialogMessage = 0;
46 static puInput *PresetDialogInput = 0;
48 static const int MAX_VALUE = 16;
49 static char PresetValue[MAX_VALUE];
50 static char PresetSavedValue[MAX_VALUE];
51 static char PresetLabel[] = "Enter New Airport ID";
52 static string PresetProperty = "";
54 static puOneShot *PresetDialogOkButton = 0;
55 static puOneShot *PresetDialogCancelButton = 0;
56 static puOneShot *PresetDialogResetButton = 0;
59 static void PresetDialog_OK(puObject *)
62 PresetDialogInput->getValue(&value);
63 cout << "setting " << PresetProperty << " = " << value << endl;
64 fgSetString( PresetProperty.c_str(), value );
65 FG_POP_PUI_DIALOG( PresetDialog );
67 // consistancy handling for some specialized cases
68 if ( PresetProperty == "/sim/presets/airport-id" ) {
69 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
70 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
71 } else if ( PresetProperty == "/sim/presets/runway" ) {
72 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
73 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
74 } else if ( PresetProperty == "/sim/presets/offset-distance" ) {
75 if ( fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001
76 && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) {
77 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
78 cout << "nuking altitude" << endl;
80 } else if ( PresetProperty == "/sim/presets/altitude-ft" ) {
81 if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001
82 && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) {
83 fgSetDouble("/sim/presets/offset-distance", 0.0);
84 cout << "nuking offset distance" << endl;
86 } else if ( PresetProperty == "/sim/presets/glideslope-deg" ) {
87 if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001
88 && fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001 ) {
89 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
90 cout << "nuking altitude" << endl;
96 static void PresetDialog_Cancel(puObject *)
98 FG_POP_PUI_DIALOG( PresetDialog );
102 static void PresetDialog_Reset(puObject *)
104 PresetDialogInput->setValue( PresetSavedValue );
105 PresetDialogInput->setCursor( 0 ) ;
109 // Initialize the preset dialog box
112 sprintf( PresetValue, "%s", fgGetString("/sim/presets/airport-id") );
114 - puGetDefaultLabelFont().getStringWidth( PresetLabel ) / 2;
116 PresetDialog = new puDialogBox (150, 50);
118 PresetDialogFrame = new puFrame (0,0,350, 150);
119 PresetDialogMessage = new puText (len, 110);
120 PresetDialogMessage -> setLabel ("");
122 PresetDialogInput = new puInput (50, 70, 300, 100);
123 PresetDialogInput -> setValue ("");
124 PresetDialogInput -> acceptInput();
126 PresetDialogOkButton = new puOneShot (50, 10, 110, 50);
127 PresetDialogOkButton -> setLegend(gui_msg_OK);
128 PresetDialogOkButton -> setCallback (PresetDialog_OK);
129 PresetDialogOkButton -> makeReturnDefault(TRUE);
131 PresetDialogCancelButton = new puOneShot (140, 10, 210, 50);
132 PresetDialogCancelButton -> setLegend (gui_msg_CANCEL);
133 PresetDialogCancelButton -> setCallback (PresetDialog_Cancel);
135 PresetDialogResetButton = new puOneShot (240, 10, 300, 50);
136 PresetDialogResetButton -> setLegend (gui_msg_RESET);
137 PresetDialogResetButton -> setCallback (PresetDialog_Reset);
139 cout << "PresetInit " << PresetValue << endl;
140 FG_FINALIZE_PUI_DIALOG( PresetDialog );
144 void fgPresetAirport(puObject *cb)
146 PresetDialogMessage -> setLabel( "Enter Airport ID:" );
147 PresetProperty = "/sim/presets/airport-id";
148 snprintf( PresetValue, MAX_VALUE, "%s",
149 fgGetString(PresetProperty.c_str()) );
150 snprintf( PresetSavedValue, MAX_VALUE, "%s",
151 fgGetString(PresetProperty.c_str()) );
152 PresetDialogInput->setValue( PresetValue );
154 FG_PUSH_PUI_DIALOG( PresetDialog );
158 void fgPresetRunway(puObject *cb)
160 PresetDialogMessage -> setLabel( "Enter Runway Number:" );
161 PresetProperty = "/sim/presets/runway";
162 snprintf( PresetValue, MAX_VALUE, "%s",
163 fgGetString(PresetProperty.c_str()) );
164 snprintf( PresetSavedValue, MAX_VALUE, "%s",
165 fgGetString(PresetProperty.c_str()) );
166 PresetDialogInput->setValue( PresetValue );
168 FG_PUSH_PUI_DIALOG( PresetDialog );
172 void fgPresetOffsetDistance(puObject *cb)
174 PresetDialogMessage -> setLabel( "Enter Offset Distance (miles):" );
175 PresetProperty = "/sim/presets/offset-distance";
176 snprintf( PresetValue, MAX_VALUE, "%s",
177 fgGetString(PresetProperty.c_str()) );
178 snprintf( PresetSavedValue, MAX_VALUE, "%s",
179 fgGetString(PresetProperty.c_str()) );
180 PresetDialogInput->setValue( PresetValue );
182 FG_PUSH_PUI_DIALOG( PresetDialog );
186 void fgPresetAltitude(puObject *cb)
188 PresetDialogMessage -> setLabel( "Enter Altitude (feet):" );
189 PresetProperty = "/sim/presets/altitude-ft";
190 snprintf( PresetValue, MAX_VALUE, "%s",
191 fgGetString(PresetProperty.c_str()) );
192 snprintf( PresetSavedValue, MAX_VALUE, "%s",
193 fgGetString(PresetProperty.c_str()) );
194 PresetDialogInput->setValue( PresetValue );
196 FG_PUSH_PUI_DIALOG( PresetDialog );
200 void fgPresetGlideslope(puObject *cb)
202 PresetDialogMessage -> setLabel( "Enter Glideslope (deg):" );
203 PresetProperty = "/sim/presets/glideslope-deg";
204 snprintf( PresetValue, MAX_VALUE, "%s",
205 fgGetString(PresetProperty.c_str()) );
206 snprintf( PresetSavedValue, MAX_VALUE, "%s",
207 fgGetString(PresetProperty.c_str()) );
208 PresetDialogInput->setValue( PresetValue );
210 FG_PUSH_PUI_DIALOG( PresetDialog );
214 void fgPresetAirspeed(puObject *cb)
216 PresetDialogMessage -> setLabel( "Enter Airspeed (kts):" );
217 PresetProperty = "/sim/presets/airspeed-kt";
218 snprintf( PresetValue, MAX_VALUE, "%s",
219 fgGetString(PresetProperty.c_str()) );
220 snprintf( PresetSavedValue, MAX_VALUE, "%s",
221 fgGetString(PresetProperty.c_str()) );
222 PresetDialogInput->setValue( PresetValue );
224 FG_PUSH_PUI_DIALOG( PresetDialog );
228 void fgPresetCommit(puObject *)
231 if ( !globals->get_commands()->execute("presets_commit", &args) )
233 SG_LOG( SG_GENERAL, SG_ALERT, "Command: presets_commit failed.");