]> git.mxchange.org Git - flightgear.git/blob - src/GUI/apt_dlg.cxx
Modifications to coordinate with recent changes in simgear.
[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     SGPath path( globals->get_fg_root() );
55     path.append( "Airports" );
56     path.append( "simple.mk4" );
57     FGAirports airports( path.c_str() );
58
59     FGAirport a;
60
61     int freeze = globals->get_freeze();
62     if(!freeze)
63         globals->set_freeze( true );
64
65     char *s;
66     AptDialogInput->getValue(&s);
67     string AptId(s);
68
69     cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
70
71     AptDialog_Cancel( NULL );
72
73     if ( AptId.length() ) {
74         // set initial position from airport id
75         SG_LOG( SG_GENERAL, SG_INFO,
76                 "Attempting to set starting position from airport code "
77                 << AptId );
78
79         if ( airports.search( AptId, &a ) )
80             {
81                 fgSetString("/sim/startup/airport-id",  AptId.c_str() );
82                 // fgSetDouble("/position/altitude", -9999.0 );
83                 // fgSetPosFromAirportID( AptId );
84                 fgSetPosFromAirportIDandHdg( AptId, 
85                                              cur_fdm_state->get_Psi() *
86                                              SGD_RADIANS_TO_DEGREES);
87                 BusyCursor(0);
88                 fgReInitSubsystems();
89                 if ( global_tile_mgr.init() ) {
90                     // Load the local scenery data
91                     global_tile_mgr.update( 
92                                            cur_fdm_state->get_Longitude()
93                                            * SGD_RADIANS_TO_DEGREES,
94                                            cur_fdm_state->get_Latitude()
95                                            * SGD_RADIANS_TO_DEGREES );
96                 } else {
97                     SG_LOG( SG_GENERAL, SG_ALERT, 
98                             "Error in Tile Manager initialization!" );
99                     exit(-1);
100                 }
101                 BusyCursor(1);
102             } else {
103                 AptId  += " not in database.";
104                 mkDialog(AptId.c_str());
105             }
106     }
107     if(!freeze)
108         globals->set_freeze( false );
109 }
110
111
112 void AptDialog_Reset(puObject *)
113 {
114     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
115     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
116     AptDialogInput->setValue ( NewAirportId );
117     AptDialogInput->setCursor( 0 ) ;
118 }
119
120 void NewAirport(puObject *cb)
121 {
122     //  strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
123     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
124     //  cout << "NewAirport " << NewAirportId << endl;
125     AptDialogInput->setValue( NewAirportId );
126
127     FG_PUSH_PUI_DIALOG( AptDialog );
128 }
129
130 void NewAirportInit(void)
131 {
132     sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
133     int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
134                                       NewAirportLabel ) / 2;
135
136     AptDialog = new puDialogBox (150, 50);
137     {
138         AptDialogFrame   = new puFrame           (0,0,350, 150);
139         AptDialogMessage = new puText            (len, 110);
140         AptDialogMessage ->    setLabel          (NewAirportLabel);
141
142         AptDialogInput   = new puInput           (50, 70, 300, 100);
143         AptDialogInput   ->    setValue          (NewAirportId);
144         AptDialogInput   ->    acceptInput();
145
146         AptDialogOkButton     =  new puOneShot   (50, 10, 110, 50);
147         AptDialogOkButton     ->     setLegend   (gui_msg_OK);
148         AptDialogOkButton     ->     setCallback (AptDialog_OK);
149         AptDialogOkButton     ->     makeReturnDefault(TRUE);
150
151         AptDialogCancelButton =  new puOneShot   (140, 10, 210, 50);
152         AptDialogCancelButton ->     setLegend   (gui_msg_CANCEL);
153         AptDialogCancelButton ->     setCallback (AptDialog_Cancel);
154
155         AptDialogResetButton  =  new puOneShot   (240, 10, 300, 50);
156         AptDialogResetButton  ->     setLegend   (gui_msg_RESET);
157         AptDialogResetButton  ->     setCallback (AptDialog_Reset);
158     }
159     cout << "NewAirportInit " << NewAirportId << endl;
160     FG_FINALIZE_PUI_DIALOG( AptDialog );
161 }