5 #include <simgear/compiler.h>
13 #include <simgear/constants.h>
14 #include <simgear/debug/logstream.hxx>
15 #include <simgear/misc/fgpath.hxx>
17 #include <Include/general.hxx>
20 #include <simgear/xgl/xgl.h>
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 <Time/fg_time.hxx>
30 #include "gui_local.hxx"
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;
40 static char NewAirportId[16];
41 static char NewAirportLabel[] = "Enter New Airport ID";
43 static puOneShot *AptDialogOkButton = 0;
44 static puOneShot *AptDialogCancelButton = 0;
45 static puOneShot *AptDialogResetButton = 0;
47 void AptDialog_Cancel(puObject *)
49 FG_POP_PUI_DIALOG( AptDialog );
52 void AptDialog_OK (puObject *)
54 FGPath path( globals->get_fg_root() );
55 path.append( "Airports" );
56 path.append( "simple.mk4" );
57 FGAirports airports( path.c_str() );
61 int freeze = globals->get_freeze();
63 globals->set_freeze( true );
66 AptDialogInput->getValue(&s);
69 cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
71 AptDialog_Cancel( NULL );
73 if ( AptId.length() ) {
74 // set initial position from airport id
75 FG_LOG( FG_GENERAL, FG_INFO,
76 "Attempting to set starting position from airport code "
79 if ( airports.search( AptId, &a ) )
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() *
91 AptId += " not in database.";
92 mkDialog(AptId.c_str());
96 globals->set_freeze( false );
99 void AptDialog_Reset(puObject *)
101 // strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
102 sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
103 AptDialogInput->setValue ( NewAirportId );
104 AptDialogInput->setCursor( 0 ) ;
107 void NewAirport(puObject *cb)
109 // strncpy( NewAirportId, fgGetString("/sim/startup/airport-id").c_str(), 16 );
110 sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
111 // cout << "NewAirport " << NewAirportId << endl;
112 AptDialogInput->setValue( NewAirportId );
114 FG_PUSH_PUI_DIALOG( AptDialog );
117 void NewAirportInit(void)
119 sprintf( NewAirportId, "%s", fgGetString("/sim/startup/airport-id").c_str() );
120 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
121 NewAirportLabel ) / 2;
123 AptDialog = new puDialogBox (150, 50);
125 AptDialogFrame = new puFrame (0,0,350, 150);
126 AptDialogMessage = new puText (len, 110);
127 AptDialogMessage -> setLabel (NewAirportLabel);
129 AptDialogInput = new puInput (50, 70, 300, 100);
130 AptDialogInput -> setValue (NewAirportId);
131 AptDialogInput -> acceptInput();
133 AptDialogOkButton = new puOneShot (50, 10, 110, 50);
134 AptDialogOkButton -> setLegend (gui_msg_OK);
135 AptDialogOkButton -> setCallback (AptDialog_OK);
136 AptDialogOkButton -> makeReturnDefault(TRUE);
138 AptDialogCancelButton = new puOneShot (140, 10, 210, 50);
139 AptDialogCancelButton -> setLegend (gui_msg_CANCEL);
140 AptDialogCancelButton -> setCallback (AptDialog_Cancel);
142 AptDialogResetButton = new puOneShot (240, 10, 300, 50);
143 AptDialogResetButton -> setLegend (gui_msg_RESET);
144 AptDialogResetButton -> setCallback (AptDialog_Reset);
146 cout << "NewAirportInit " << NewAirportId << endl;
147 FG_FINALIZE_PUI_DIALOG( AptDialog );