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/structure/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 SG_LOG( SG_GENERAL, SG_DEBUG, "setting " << PresetProperty
65 fgSetString( PresetProperty.c_str(), value );
66 FG_POP_PUI_DIALOG( PresetDialog );
68 // consistancy handling for some specialized cases
69 if ( PresetProperty == "/sim/presets/airport-id" ) {
70 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
71 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
72 } else if ( PresetProperty == "/sim/presets/runway" ) {
73 fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
74 fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
75 } else if ( PresetProperty == "/sim/presets/offset-distance" ) {
76 if ( fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001
77 && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) {
78 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
79 SG_LOG( SG_GENERAL, SG_DEBUG, "nuking altitude" );
81 } else if ( PresetProperty == "/sim/presets/altitude-ft" ) {
82 if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001
83 && fabs(fgGetDouble("/sim/presets/glideslope-deg")) > 0.000001 ) {
84 fgSetDouble("/sim/presets/offset-distance", 0.0);
85 SG_LOG( SG_GENERAL, SG_DEBUG, "nuking offset distance" );
87 } else if ( PresetProperty == "/sim/presets/glideslope-deg" ) {
88 if ( fabs(fgGetDouble("/sim/presets/offset-distance")) > 0.000001
89 && fabs(fgGetDouble("/sim/presets/altitude-ft")) > 0.000001 ) {
90 fgSetDouble("/sim/presets/altitude-ft", -9999.0);
91 SG_LOG( SG_GENERAL, SG_DEBUG, "nuking altitude" );
97 static void PresetDialog_Cancel(puObject *)
99 FG_POP_PUI_DIALOG( PresetDialog );
103 static void PresetDialog_Reset(puObject *)
105 PresetDialogInput->setValue( PresetSavedValue );
106 PresetDialogInput->setCursor( 0 ) ;
110 // Initialize the preset dialog box
113 sprintf( PresetValue, "%s", fgGetString("/sim/presets/airport-id") );
115 - puGetDefaultLabelFont().getStringWidth( PresetLabel ) / 2;
117 PresetDialog = new puDialogBox (150, 50);
119 PresetDialogFrame = new puFrame (0,0,350, 150);
120 PresetDialogMessage = new puText (len, 110);
121 PresetDialogMessage -> setLabel ("");
123 PresetDialogInput = new puInput (50, 70, 300, 100);
124 PresetDialogInput -> setValue ("");
125 PresetDialogInput -> acceptInput();
127 PresetDialogOkButton = new puOneShot (50, 10, 110, 50);
128 PresetDialogOkButton -> setLegend(gui_msg_OK);
129 PresetDialogOkButton -> setCallback (PresetDialog_OK);
130 PresetDialogOkButton -> makeReturnDefault(TRUE);
132 PresetDialogCancelButton = new puOneShot (140, 10, 210, 50);
133 PresetDialogCancelButton -> setLegend (gui_msg_CANCEL);
134 PresetDialogCancelButton -> setCallback (PresetDialog_Cancel);
136 PresetDialogResetButton = new puOneShot (240, 10, 300, 50);
137 PresetDialogResetButton -> setLegend (gui_msg_RESET);
138 PresetDialogResetButton -> setCallback (PresetDialog_Reset);
140 SG_LOG( SG_GENERAL, SG_DEBUG, "PresetInit " << PresetValue );
141 FG_FINALIZE_PUI_DIALOG( PresetDialog );
145 void fgPresetAirport(puObject *cb)
147 PresetDialogMessage -> setLabel( "Enter Airport ID:" );
148 PresetProperty = "/sim/presets/airport-id";
149 snprintf( PresetValue, MAX_VALUE, "%s",
150 fgGetString(PresetProperty.c_str()) );
151 snprintf( PresetSavedValue, MAX_VALUE, "%s",
152 fgGetString(PresetProperty.c_str()) );
153 PresetDialogInput->setValue( PresetValue );
155 FG_PUSH_PUI_DIALOG( PresetDialog );
159 void fgPresetRunway(puObject *cb)
161 PresetDialogMessage -> setLabel( "Enter Runway Number:" );
162 PresetProperty = "/sim/presets/runway";
163 snprintf( PresetValue, MAX_VALUE, "%s",
164 fgGetString(PresetProperty.c_str()) );
165 snprintf( PresetSavedValue, MAX_VALUE, "%s",
166 fgGetString(PresetProperty.c_str()) );
167 PresetDialogInput->setValue( PresetValue );
169 FG_PUSH_PUI_DIALOG( PresetDialog );
173 void fgPresetOffsetDistance(puObject *cb)
175 PresetDialogMessage -> setLabel( "Enter Offset Distance (miles):" );
176 PresetProperty = "/sim/presets/offset-distance";
177 snprintf( PresetValue, MAX_VALUE, "%s",
178 fgGetString(PresetProperty.c_str()) );
179 snprintf( PresetSavedValue, MAX_VALUE, "%s",
180 fgGetString(PresetProperty.c_str()) );
181 PresetDialogInput->setValue( PresetValue );
183 FG_PUSH_PUI_DIALOG( PresetDialog );
187 void fgPresetAltitude(puObject *cb)
189 PresetDialogMessage -> setLabel( "Enter Altitude (feet):" );
190 PresetProperty = "/sim/presets/altitude-ft";
191 snprintf( PresetValue, MAX_VALUE, "%s",
192 fgGetString(PresetProperty.c_str()) );
193 snprintf( PresetSavedValue, MAX_VALUE, "%s",
194 fgGetString(PresetProperty.c_str()) );
195 PresetDialogInput->setValue( PresetValue );
197 FG_PUSH_PUI_DIALOG( PresetDialog );
201 void fgPresetGlideslope(puObject *cb)
203 PresetDialogMessage -> setLabel( "Enter Glideslope (deg):" );
204 PresetProperty = "/sim/presets/glideslope-deg";
205 snprintf( PresetValue, MAX_VALUE, "%s",
206 fgGetString(PresetProperty.c_str()) );
207 snprintf( PresetSavedValue, MAX_VALUE, "%s",
208 fgGetString(PresetProperty.c_str()) );
209 PresetDialogInput->setValue( PresetValue );
211 FG_PUSH_PUI_DIALOG( PresetDialog );
215 void fgPresetAirspeed(puObject *cb)
217 PresetDialogMessage -> setLabel( "Enter Airspeed (kts):" );
218 PresetProperty = "/sim/presets/airspeed-kt";
219 snprintf( PresetValue, MAX_VALUE, "%s",
220 fgGetString(PresetProperty.c_str()) );
221 snprintf( PresetSavedValue, MAX_VALUE, "%s",
222 fgGetString(PresetProperty.c_str()) );
223 PresetDialogInput->setValue( PresetValue );
225 FG_PUSH_PUI_DIALOG( PresetDialog );
229 void fgPresetCommit(puObject *)
232 if ( !globals->get_commands()->execute("presets-commit", &args) )
234 SG_LOG( SG_GENERAL, SG_ALERT, "Command: presets-commit failed.");