]> git.mxchange.org Git - flightgear.git/blob - src/GUI/preset_dlg.cxx
Added support for reinit(), to reload the configuration files without
[flightgear.git] / src / GUI / preset_dlg.cxx
1 // preset_dlg.cxx -- Preset dialogs and funcitons
2 //
3 // Written by Curtis Olson, started November 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson  - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <simgear/compiler.h>
29
30 #ifdef HAVE_WINDOWS_H
31 #  include <windows.h>
32 #endif
33
34 #include <simgear/misc/commands.hxx>
35 #include <simgear/misc/sg_path.hxx>
36
37 #include <Main/fg_props.hxx>
38
39 #include "gui.h"
40 #include "preset_dlg.hxx"
41
42
43 static puDialogBox *PresetDialog = 0;
44 static puFrame     *PresetDialogFrame = 0;
45 static puText      *PresetDialogMessage = 0;
46 static puInput     *PresetDialogInput = 0;
47
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 = "";
53
54 static puOneShot *PresetDialogOkButton = 0;
55 static puOneShot *PresetDialogCancelButton = 0;
56 static puOneShot *PresetDialogResetButton = 0;
57
58
59 static void PresetDialog_OK(puObject *)
60 {
61     char *value;
62     PresetDialogInput->getValue(&value);
63     SG_LOG( SG_GENERAL, SG_DEBUG, "setting " << PresetProperty
64             << " = " << value );
65     fgSetString( PresetProperty.c_str(), value );
66     FG_POP_PUI_DIALOG( PresetDialog );
67
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" );
80         }
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" );
86         }
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" );
92         }
93     }
94 }
95
96
97 static void PresetDialog_Cancel(puObject *)
98 {
99     FG_POP_PUI_DIALOG( PresetDialog );
100 }
101
102
103 static void PresetDialog_Reset(puObject *)
104 {
105     PresetDialogInput->setValue( PresetSavedValue );
106     PresetDialogInput->setCursor( 0 ) ;
107 }
108
109
110 // Initialize the preset dialog box
111 void fgPresetInit()
112 {
113     sprintf( PresetValue, "%s", fgGetString("/sim/presets/airport-id") );
114     int len = 150
115         - puGetDefaultLabelFont().getStringWidth( PresetLabel ) / 2;
116
117     PresetDialog = new puDialogBox (150, 50);
118     {
119         PresetDialogFrame = new puFrame           (0,0,350, 150);
120         PresetDialogMessage = new puText            (len, 110);
121         PresetDialogMessage -> setLabel          ("");
122
123         PresetDialogInput = new puInput           (50, 70, 300, 100);
124         PresetDialogInput -> setValue          ("");
125         PresetDialogInput -> acceptInput();
126
127         PresetDialogOkButton = new puOneShot   (50, 10, 110, 50);
128         PresetDialogOkButton -> setLegend(gui_msg_OK);
129         PresetDialogOkButton -> setCallback (PresetDialog_OK);
130         PresetDialogOkButton -> makeReturnDefault(TRUE);
131
132         PresetDialogCancelButton =  new puOneShot (140, 10, 210, 50);
133         PresetDialogCancelButton -> setLegend (gui_msg_CANCEL);
134         PresetDialogCancelButton -> setCallback (PresetDialog_Cancel);
135
136         PresetDialogResetButton =  new puOneShot (240, 10, 300, 50);
137         PresetDialogResetButton -> setLegend (gui_msg_RESET);
138         PresetDialogResetButton -> setCallback (PresetDialog_Reset);
139     }
140     SG_LOG( SG_GENERAL, SG_DEBUG, "PresetInit " << PresetValue );
141     FG_FINALIZE_PUI_DIALOG( PresetDialog );
142 }
143
144
145 void fgPresetAirport(puObject *cb)
146 {
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 );
154
155     FG_PUSH_PUI_DIALOG( PresetDialog );
156 }
157
158
159 void fgPresetRunway(puObject *cb)
160 {
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 );
168
169     FG_PUSH_PUI_DIALOG( PresetDialog );
170 }
171
172
173 void fgPresetOffsetDistance(puObject *cb)
174 {
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 );
182
183     FG_PUSH_PUI_DIALOG( PresetDialog );
184 }
185
186
187 void fgPresetAltitude(puObject *cb)
188 {
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 );
196
197     FG_PUSH_PUI_DIALOG( PresetDialog );
198 }
199
200
201 void fgPresetGlideslope(puObject *cb)
202 {
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 );
210
211     FG_PUSH_PUI_DIALOG( PresetDialog );
212 }
213
214
215 void fgPresetAirspeed(puObject *cb)
216 {
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 );
224
225     FG_PUSH_PUI_DIALOG( PresetDialog );
226 }
227
228
229 void fgPresetCommit(puObject *)
230 {
231     SGPropertyNode args;
232     if ( !globals->get_commands()->execute("presets-commit", &args) )
233     {
234         SG_LOG( SG_GENERAL, SG_ALERT, "Command: presets-commit failed.");
235     }
236 }
237
238