1 // ATCDialog.cxx - Functions and classes to handle the pop-up ATC dialog
3 // Written by Alexander Kappes and David Luff, started February 2003.
5 // Copyright (C) 2003 Alexander Kappes and David Luff
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.
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.
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.
21 #include <simgear/structure/commands.hxx>
23 #include <Main/globals.hxx>
26 #include "ATCDialog.hxx"
30 FGATCDialog *current_atcdialog;
32 // For the command manager - maybe eventually this should go in the built in command list
33 static bool do_ATC_dialog(const SGPropertyNode* arg) {
34 globals->get_ATC_mgr()->doPopupDialog();
38 ATCMenuEntry::ATCMenuEntry() {
45 ATCMenuEntry::~ATCMenuEntry() {
48 static char* t0 = "Contact tower for landing";
49 static char* t1 = "Request departure clearance";
50 static char* t2 = "Report Runway vacated";
51 static char** towerOptions = new char*[4];
53 // ----------------------- DCL ------------------------------------------
54 // For the ATC dialog - copied from the Autopilot new heading dialog code!
55 static puDialogBox* atcDialog;
56 static puFrame* atcDialogFrame;
57 static puText* atcDialogMessage;
58 //static puInput* atcDialogInput;
59 static puOneShot* atcDialogOkButton;
60 static puOneShot* atcDialogCancelButton;
61 static puButtonBox* atcDialogCommunicationOptions;
62 // ----------------------------------------------------------------------
64 // ------------------------ AK ------------------------------------------
65 static puDialogBox *ATCMenuBox = 0;
66 static puFrame *ATCMenuFrame = 0;
67 static puText *ATCMenuBoxMessage = 0;
68 static puButtonBox *ATCOptionsList = 0;
69 // ----------------------------------------------------------------------
72 static void AKATCDialogOK(puObject *)
74 switch(ATCOptionsList->getValue()) {
76 //cout << "Option 0 chosen\n";
77 fgSetBool("/sim/atc/opt0",true);
80 //cout << "Option 1 chosen\n";
81 fgSetBool("/sim/atc/opt1",true);
84 //cout << "Option 2 chosen\n";
85 fgSetBool("/sim/atc/opt2",true);
88 //cout << "Option 2 chosen\n";
89 fgSetBool("/sim/atc/opt3",true);
94 FG_POP_PUI_DIALOG( ATCMenuBox );
98 static void AKATCDialogCancel(puObject *)
100 FG_POP_PUI_DIALOG( ATCMenuBox );
104 static void ATCDialogCancel(puObject *)
106 //ATCDialogInput->rejectInput();
107 FG_POP_PUI_DIALOG( atcDialog );
111 static void ATCDialogOK (puObject *me)
113 // Note that currently the dialog is hardwired to comm1 only here.
114 switch(globals->get_ATC_mgr()->GetComm1ATCType()) {
120 FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetComm1ATCPointer();
121 switch(atcDialogCommunicationOptions->getValue()) {
123 //cout << "Option 0 chosen\n";
124 twr->RequestLandingClearance("charlie foxtrot sierra");
127 //cout << "Option 1 chosen\n";
128 twr->RequestDepartureClearance("charlie foxtrot sierra");
131 //cout << "Option 2 chosen\n";
132 twr->ReportRunwayVacated("charlie foxtrot sierra");
148 //if(error) mkDialog(s.c_str());
152 static void ATCDialog(puObject *cb)
154 //ApHeadingDialogInput -> setValue ( heading );
155 //ApHeadingDialogInput -> acceptInput();
156 FG_PUSH_PUI_DIALOG(atcDialog);
162 char defaultATCLabel[] = "Enter desired option to communicate with ATC:";
165 // Option lists hardwired per ATC type
166 towerOptions[0] = new char[strlen(t0)+1];
167 strcpy(towerOptions[0], t0);
168 towerOptions[1] = new char[strlen(t1)+1];
169 strcpy(towerOptions[1], t1);
170 towerOptions[2] = new char[strlen(t2)+1];
171 strcpy(towerOptions[2], t2);
172 towerOptions[3] = NULL;
174 atcDialog = new puDialogBox (150, 50);
176 atcDialogFrame = new puFrame (0, 0, 500, 250);
178 atcDialogMessage = new puText (250, 220);
179 atcDialogMessage -> setDefaultValue (defaultATCLabel);
180 atcDialogMessage -> getDefaultValue (&s);
181 atcDialogMessage -> setLabel (s);
182 atcDialogMessage -> setLabelPlace (PUPLACE_TOP_CENTERED);
184 atcDialogCommunicationOptions = new puButtonBox (50, 50, 450, 210, NULL, true);
186 atcDialogOkButton = new puOneShot (50, 10, 110, 50);
187 atcDialogOkButton -> setLegend (gui_msg_OK);
188 atcDialogOkButton -> makeReturnDefault (TRUE);
189 atcDialogOkButton -> setCallback (ATCDialogOK);
191 atcDialogCancelButton = new puOneShot (140, 10, 210, 50);
192 atcDialogCancelButton -> setLegend (gui_msg_CANCEL);
193 atcDialogCancelButton -> setCallback (ATCDialogCancel);
196 FG_FINALIZE_PUI_DIALOG(atcDialog);
198 // Add ATC-dialog to the command list
199 globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
202 ///////////////////////////////////////////////////////////////////////
204 // ATCDoDialog is in a state of flux at the moment
205 // Stations other than approach are handled by DCL's simple code
206 // Approach is handled by AK's fancy dynamic-list code
207 // Hopefully all interactive stations should go to AK's code eventually
209 ///////////////////////////////////////////////////////////////////////
210 void ATCDoDialog(atc_type type) {
213 atcDialogCommunicationOptions->newList(NULL);
214 atcDialogMessage->setLabel("Not tuned in to any ATC service.");
217 atcDialogCommunicationOptions->newList(NULL);
218 atcDialogMessage->setLabel("Tuned in to ATIS: no communication possible.");
221 atcDialogCommunicationOptions->newList(towerOptions);
222 atcDialogMessage->setLabel("Tuned in to Tower - select communication to transmit:");
225 atcDialogCommunicationOptions->newList(NULL);
226 atcDialogMessage->setLabel("Tuned in to Ground - select communication to transmit:");
229 current_atcdialog->DoDialog();
232 atcDialogCommunicationOptions->newList(NULL);
233 atcDialogMessage->setLabel("Tuned in to unknown ATC service - enter transmission:");
237 // Third - display the dialog without pausing sim.
238 if(type != APPROACH) {
243 void FGATCDialog::Init() {
248 void FGATCDialog::add_entry(string station, string transmission, string menutext ) {
252 a.stationid = station;
253 a.transmission = transmission;
254 a.menuentry = menutext;
256 atcmentrylist_station[station.c_str()].push_back(a);
261 // query the database whether the transmission is already registered;
262 bool FGATCDialog::trans_reg( const string &station, const string &trans ) {
264 atcmentry_list_type atcmlist = atcmentrylist_station[station];
265 atcmentry_list_iterator current = atcmlist.begin();
266 atcmentry_list_iterator last = atcmlist.end();
268 for ( ; current != last ; ++current ) {
269 if ( current->transmission == trans ) return true;
275 // ===================================================
276 // === Update ATC menue and look for keys pressed ===
277 // ===================================================
278 void FGATCDialog::DoDialog() {
280 static string mentry[10];
281 static string mtrans[10];
284 FGATC* atcptr = globals->get_ATC_mgr()->GetComm1ATCPointer(); // Hardwired to comm1 at the moment
288 atcmentry_list_type atcmlist = atcmentrylist_station[atcptr->get_ident()];
289 //atcmentry_list_type atcmlist = atcmentrylist_station["EGNX"];
290 atcmentry_list_iterator current = atcmlist.begin();
291 atcmentry_list_iterator last = atcmlist.end();
293 // Set all opt flags to false before displaying box
294 fgSetBool("/sim/atc/opt0",false);
295 fgSetBool("/sim/atc/opt1",false);
296 fgSetBool("/sim/atc/opt2",false);
297 fgSetBool("/sim/atc/opt3",false);
298 fgSetBool("/sim/atc/opt4",false);
299 fgSetBool("/sim/atc/opt5",false);
300 fgSetBool("/sim/atc/opt6",false);
301 fgSetBool("/sim/atc/opt7",false);
302 fgSetBool("/sim/atc/opt8",false);
303 fgSetBool("/sim/atc/opt9",false);
309 if ( atcmlist.size() != 0 ){
310 int k=atcmlist.size();
312 //cout << "k = " << k << endl;
313 int y = (fgGetInt("/sim/startup/ysize") - 200 - 20 - k*20);
314 ATCMenuBox = new puDialogBox (100, y);
315 ATCMenuFrame = new puFrame (0,0,xsize,yc+40);
316 // loop over all entries in atcmentrylist
317 ATCOptionsList = new puButtonBox (50, 50, 450, 50+(k*25), NULL, true);
318 char** optList = new char*[k+1];
320 for ( ; current != last ; ++current ) {
322 sprintf( buf, "%i", kk+1 );
325 mentry[kk] = dum + ". " + current->menuentry;
326 optList[kk] = new char[strlen(mentry[kk].c_str()) + 1];
327 strcpy(optList[kk], mentry[kk].c_str());
328 //cout << "optList[" << kk << "] = " << optList[kk] << endl;
329 mtrans[kk] = current->transmission;
330 //ATCMenuBoxMessage = new puText (10, yc);
331 //ATCMenuBoxMessage -> setLabel( mentry[kk].c_str() );
337 ATCOptionsList->newList(optList);
339 int y = (fgGetInt("/sim/startup/ysize") - 100 - 20 );
340 ATCMenuBox = new puDialogBox (10, y);
341 ATCMenuFrame = new puFrame (0,0,xsize,yc+40);
342 ATCMenuBoxMessage = new puText (10, yc-10);
343 ATCMenuBoxMessage -> setLabel( "No transmission available" );
346 ATCMenuBoxMessage = new puText (10, yc+10);
347 ATCMenuBoxMessage -> setLabel( "ATC Menu" );
348 atcDialogOkButton = new puOneShot ((xsize/2)-85, 10, (xsize/2)-25, 50);
349 atcDialogOkButton -> setLegend (gui_msg_OK);
350 atcDialogOkButton -> makeReturnDefault (TRUE);
351 atcDialogOkButton -> setCallback (AKATCDialogOK);
353 atcDialogCancelButton = new puOneShot ((xsize/2)+25, 10, (xsize/2)+85, 50);
354 atcDialogCancelButton -> setLegend (gui_msg_CANCEL);
355 atcDialogCancelButton -> setCallback (AKATCDialogCancel);
356 FG_FINALIZE_PUI_DIALOG( ATCMenuBox );
357 FG_PUSH_PUI_DIALOG( ATCMenuBox );
361 if ( atckey != -1 && TransDisplayed && mtrans[atckey-1].c_str() != "" ) {
362 cout << mtrans[atckey-1].c_str() << endl;
363 TPar = current_transmissionlist->extract_transpar( mtrans[atckey-1].c_str() );
364 current_atcmentrylist->reset = true;
365 current_transparlist->add_entry( TPar );
367 // transpar_list_type test = current_transparlist;
368 // transpar_list_iterator current = test.begin();
369 //for ( ; current != test.end(); ++current ) {
370 // current->tpar.intention;
374 if ( current_atcmentrylist->freq != (int)(comm1_freq*100.0 + 0.5) ) {
375 current_atcmentrylist->reset = true;
378 // reset (delete) ATCmenue list if reset is true
379 if ( current_atcmentrylist->reset == true ) {
380 delete ( current_atcmentrylist );
381 current_atcmentrylist = new FGatcmentryList;
382 current_atcmentrylist->init( (int)(comm1_freq*100.0 + 0.5) );
383 if ( TransDisplayed ) {
384 FG_POP_PUI_DIALOG( ATCMenuBox );
385 TransDisplayed = false;