]> git.mxchange.org Git - flightgear.git/blob - src/GUI/apt_dlg.cxx
Patch from Julian Foad:
[flightgear.git] / src / GUI / apt_dlg.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include <simgear/compiler.h>
6
7 #ifdef HAVE_WINDOWS_H
8 #  include <windows.h>
9 #endif
10
11 #include <stdlib.h>
12
13 #include <simgear/constants.h>
14 #include <simgear/debug/logstream.hxx>
15 #include <simgear/misc/sg_path.hxx>
16
17 #include <Include/general.hxx>
18
19 #include <GL/glut.h>
20 #include <GL/gl.h>
21
22 #include <Airports/simple.hxx>
23 #include <FDM/flight.hxx>
24 #include <Main/fg_init.hxx>
25 #include <Main/fg_props.hxx>
26 #include <Main/globals.hxx>
27 #include <Scenery/tilemgr.hxx>
28
29 #include "gui.h"
30 #include "gui_local.hxx"
31
32 /// The beginnings of teleportation :-)
33 //  Needs cleaning up but works
34 //  These statics should disapear when this is a class
35 static puDialogBox     *AptDialog = 0;
36 static puFrame         *AptDialogFrame = 0;
37 static puText          *AptDialogMessage = 0;
38 static puInput         *AptDialogInput = 0;
39
40 static char NewAirportId[16];
41 static char NewAirportLabel[] = "Enter New Airport ID"; 
42
43 static puOneShot       *AptDialogOkButton = 0;
44 static puOneShot       *AptDialogCancelButton = 0;
45 static puOneShot       *AptDialogResetButton = 0;
46
47 void AptDialog_Cancel(puObject *)
48 {
49     FG_POP_PUI_DIALOG( AptDialog );
50 }
51
52 void AptDialog_OK (puObject *)
53 {
54     static const SGPropertyNode *longitude
55         = fgGetNode("/position/longitude-deg");
56     static const SGPropertyNode *latitude
57         = fgGetNode("/position/latitude-deg");
58     static const SGPropertyNode *master_freeze
59         = fgGetNode("/sim/freeze/master");
60
61     SGPath path( globals->get_fg_root() );
62     path.append( "Airports" );
63     path.append( "simple.mk4" );
64     FGAirports airports( path.c_str() );
65
66     FGAirport a;
67
68     bool freeze = master_freeze->getBoolValue();
69     if ( !freeze ) {
70         fgSetBool("/sim/freeze/master", true);
71     }
72
73     char *s;
74     AptDialogInput->getValue(&s);
75     string AptId(s);
76
77     cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
78
79     AptDialog_Cancel( NULL );
80
81     if ( AptId.length() ) {
82         // set initial position from airport id
83         SG_LOG( SG_GENERAL, SG_INFO,
84                 "Attempting to set starting position from airport code "
85                 << AptId );
86
87         if ( airports.search( AptId, &a ) )
88         {
89             // unbind the current fdm state so property changes
90             // don't get lost when we subsequently delete this fdm
91             // and create a new one.
92             cur_fdm_state->unbind();
93         
94             AptId = a.id.c_str();  /// NHV fix wrong case crash
95             fgSetString("/sim/startup/airport-id",  AptId.c_str() );
96             // fgSetDouble("/position/altitude-ft", -9999.0 );
97             // fgSetPosFromAirportID( AptId );
98             fgSetPosFromAirportIDandHdg( AptId, 
99                                          cur_fdm_state->get_Psi() *
100                                          SGD_RADIANS_TO_DEGREES);
101             fgSetTowerPosFromAirportID( AptId, 
102                                         cur_fdm_state->get_Psi() *
103                                         SGD_RADIANS_TO_DEGREES);
104             // BusyCursor(0);
105             fgReInitSubsystems();
106             double visibility_meters =
107               fgGetDouble("/environment/visibility-m");
108             global_tile_mgr.update( longitude->getDoubleValue(),
109                                     latitude->getDoubleValue(),visibility_meters );
110             // BusyCursor(1);
111         } else {
112             AptId  += " not in database.";
113             mkDialog(AptId.c_str());
114         }
115     }
116     if ( !freeze ) {
117         fgSetBool("/sim/freeze/master", false);
118     }
119 }
120
121
122 void AptDialog_Reset(puObject *)
123 {
124     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
125     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id") );
126     AptDialogInput->setValue ( NewAirportId );
127     AptDialogInput->setCursor( 0 ) ;
128 }
129
130 void NewAirport(puObject *cb)
131 {
132     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
133     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id") );
134     // cout << "NewAirport " << NewAirportId << endl;
135     AptDialogInput->setValue( NewAirportId );
136
137     FG_PUSH_PUI_DIALOG( AptDialog );
138 }
139
140 void NewAirportInit(void)
141 {
142     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id") );
143     int len = 150
144         - puGetDefaultLabelFont().getStringWidth( NewAirportLabel ) / 2;
145
146     AptDialog = new puDialogBox (150, 50);
147     {
148         AptDialogFrame   = new puFrame           (0,0,350, 150);
149         AptDialogMessage = new puText            (len, 110);
150         AptDialogMessage ->    setLabel          (NewAirportLabel);
151
152         AptDialogInput   = new puInput           (50, 70, 300, 100);
153         AptDialogInput   ->    setValue          (NewAirportId);
154         AptDialogInput   ->    acceptInput();
155
156         AptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
157         AptDialogOkButton     ->     setLegend   (gui_msg_OK);
158         AptDialogOkButton     ->     setCallback (AptDialog_OK);
159         AptDialogOkButton     ->     makeReturnDefault(TRUE);
160
161         AptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
162         AptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
163         AptDialogCancelButton ->     setCallback (AptDialog_Cancel);
164
165         AptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
166         AptDialogResetButton  ->     setLegend   (gui_msg_RESET);
167         AptDialogResetButton  ->     setCallback (AptDialog_Reset);
168     }
169     cout << "NewAirportInit " << NewAirportId << endl;
170     FG_FINALIZE_PUI_DIALOG( AptDialog );
171 }