]> git.mxchange.org Git - flightgear.git/blob - src/GUI/preset_dlg.cxx
Exposed the fg_commands though the httpd interface.
[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     cout << "setting " << PresetProperty << " = " << value << endl;
64     fgSetString( PresetProperty.c_str(), value );
65     FG_POP_PUI_DIALOG( PresetDialog );
66
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;
79         }
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;
85         }
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;
91         }
92     }
93 }
94
95
96 static void PresetDialog_Cancel(puObject *)
97 {
98     FG_POP_PUI_DIALOG( PresetDialog );
99 }
100
101
102 static void PresetDialog_Reset(puObject *)
103 {
104     PresetDialogInput->setValue( PresetSavedValue );
105     PresetDialogInput->setCursor( 0 ) ;
106 }
107
108
109 // Initialize the preset dialog box
110 void fgPresetInit()
111 {
112     sprintf( PresetValue, "%s", fgGetString("/sim/presets/airport-id") );
113     int len = 150
114         - puGetDefaultLabelFont().getStringWidth( PresetLabel ) / 2;
115
116     PresetDialog = new puDialogBox (150, 50);
117     {
118         PresetDialogFrame = new puFrame           (0,0,350, 150);
119         PresetDialogMessage = new puText            (len, 110);
120         PresetDialogMessage -> setLabel          ("");
121
122         PresetDialogInput = new puInput           (50, 70, 300, 100);
123         PresetDialogInput -> setValue          ("");
124         PresetDialogInput -> acceptInput();
125
126         PresetDialogOkButton = new puOneShot   (50, 10, 110, 50);
127         PresetDialogOkButton -> setLegend(gui_msg_OK);
128         PresetDialogOkButton -> setCallback (PresetDialog_OK);
129         PresetDialogOkButton -> makeReturnDefault(TRUE);
130
131         PresetDialogCancelButton =  new puOneShot (140, 10, 210, 50);
132         PresetDialogCancelButton -> setLegend (gui_msg_CANCEL);
133         PresetDialogCancelButton -> setCallback (PresetDialog_Cancel);
134
135         PresetDialogResetButton =  new puOneShot (240, 10, 300, 50);
136         PresetDialogResetButton -> setLegend (gui_msg_RESET);
137         PresetDialogResetButton -> setCallback (PresetDialog_Reset);
138     }
139     cout << "PresetInit " << PresetValue << endl;
140     FG_FINALIZE_PUI_DIALOG( PresetDialog );
141 }
142
143
144 void fgPresetAirport(puObject *cb)
145 {
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 );
153
154     FG_PUSH_PUI_DIALOG( PresetDialog );
155 }
156
157
158 void fgPresetRunway(puObject *cb)
159 {
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 );
167
168     FG_PUSH_PUI_DIALOG( PresetDialog );
169 }
170
171
172 void fgPresetOffsetDistance(puObject *cb)
173 {
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 );
181
182     FG_PUSH_PUI_DIALOG( PresetDialog );
183 }
184
185
186 void fgPresetAltitude(puObject *cb)
187 {
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 );
195
196     FG_PUSH_PUI_DIALOG( PresetDialog );
197 }
198
199
200 void fgPresetGlideslope(puObject *cb)
201 {
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 );
209
210     FG_PUSH_PUI_DIALOG( PresetDialog );
211 }
212
213
214 void fgPresetAirspeed(puObject *cb)
215 {
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 );
223
224     FG_PUSH_PUI_DIALOG( PresetDialog );
225 }
226
227
228 void fgPresetCommit(puObject *)
229 {
230     SGPropertyNode args;
231     if ( !globals->get_commands()->execute("presets_commit", &args) )
232     {
233         SG_LOG( SG_GENERAL, SG_ALERT, "Command: presets_commit failed.");
234     }
235 }
236
237