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 = "No communication currently available";
49 //static char* t1 = "Request departure clearance";
50 //static char* t2 = "Report Runway vacated";
51 static char** towerOptions = new char*[2];
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()) {
121 FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetComm1ATCPointer();
122 switch(atcDialogCommunicationOptions->getValue()) {
124 //cout << "Option 0 chosen\n";
125 twr->RequestLandingClearance("charlie foxtrot sierra");
128 //cout << "Option 1 chosen\n";
129 twr->RequestDepartureClearance("charlie foxtrot sierra");
132 //cout << "Option 2 chosen\n";
133 twr->ReportRunwayVacated("charlie foxtrot sierra");
150 //if(error) mkDialog(s.c_str());
154 static void ATCDialog(puObject *cb)
156 //ApHeadingDialogInput -> setValue ( heading );
157 //ApHeadingDialogInput -> acceptInput();
158 FG_PUSH_PUI_DIALOG(atcDialog);
164 char defaultATCLabel[] = "Enter desired option to communicate with ATC:";
167 // Option lists hardwired per ATC type
168 towerOptions[0] = new char[strlen(t0)+1];
169 strcpy(towerOptions[0], t0);
170 //towerOptions[1] = new char[strlen(t1)+1];
171 //strcpy(towerOptions[1], t1);
172 //towerOptions[2] = new char[strlen(t2)+1];
173 //strcpy(towerOptions[2], t2);
174 towerOptions[1] = NULL;
176 atcDialog = new puDialogBox (150, 50);
178 atcDialogFrame = new puFrame (0, 0, 500, 250);
180 atcDialogMessage = new puText (250, 220);
181 atcDialogMessage -> setDefaultValue (defaultATCLabel);
182 atcDialogMessage -> getDefaultValue (&s);
183 atcDialogMessage -> setLabel (s);
184 atcDialogMessage -> setLabelPlace (PUPLACE_TOP_CENTERED);
186 atcDialogCommunicationOptions = new puButtonBox (50, 50, 450, 210, NULL, true);
188 atcDialogOkButton = new puOneShot (50, 10, 110, 50);
189 atcDialogOkButton -> setLegend (gui_msg_OK);
190 atcDialogOkButton -> makeReturnDefault (TRUE);
191 atcDialogOkButton -> setCallback (ATCDialogOK);
193 atcDialogCancelButton = new puOneShot (140, 10, 210, 50);
194 atcDialogCancelButton -> setLegend (gui_msg_CANCEL);
195 atcDialogCancelButton -> setCallback (ATCDialogCancel);
198 FG_FINALIZE_PUI_DIALOG(atcDialog);
200 // Add ATC-dialog to the command list
201 globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
204 ///////////////////////////////////////////////////////////////////////
206 // ATCDoDialog is in a state of flux at the moment
207 // Stations other than approach are handled by DCL's simple code
208 // Approach is handled by AK's fancy dynamic-list code
209 // Hopefully all interactive stations should go to AK's code eventually
211 ///////////////////////////////////////////////////////////////////////
212 void ATCDoDialog(atc_type type) {
215 atcDialogCommunicationOptions->newList(NULL);
216 atcDialogMessage->setLabel("Not tuned in to any ATC service.");
219 atcDialogCommunicationOptions->newList(NULL);
220 atcDialogMessage->setLabel("Tuned in to ATIS: no communication possible.");
223 atcDialogCommunicationOptions->newList(towerOptions);
224 atcDialogMessage->setLabel("Tuned in to Tower - select communication to transmit:");
227 atcDialogCommunicationOptions->newList(NULL);
228 atcDialogMessage->setLabel("Tuned in to Ground - select communication to transmit:");
231 current_atcdialog->DoDialog();
234 atcDialogCommunicationOptions->newList(NULL);
235 atcDialogMessage->setLabel("Tuned in to unknown ATC service - enter transmission:");
239 // Third - display the dialog without pausing sim.
240 if(type != APPROACH) {
245 void FGATCDialog::Init() {
250 void FGATCDialog::add_entry(string station, string transmission, string menutext ) {
254 a.stationid = station;
255 a.transmission = transmission;
256 a.menuentry = menutext;
258 atcmentrylist_station[station.c_str()].push_back(a);
263 // query the database whether the transmission is already registered;
264 bool FGATCDialog::trans_reg( const string &station, const string &trans ) {
266 atcmentry_list_type atcmlist = atcmentrylist_station[station];
267 atcmentry_list_iterator current = atcmlist.begin();
268 atcmentry_list_iterator last = atcmlist.end();
270 for ( ; current != last ; ++current ) {
271 if ( current->transmission == trans ) return true;
277 // ===================================================
278 // === Update ATC menue and look for keys pressed ===
279 // ===================================================
280 void FGATCDialog::DoDialog() {
282 static string mentry[10];
283 static string mtrans[10];
286 FGATC* atcptr = globals->get_ATC_mgr()->GetComm1ATCPointer(); // Hardwired to comm1 at the moment
290 atcmentry_list_type atcmlist = atcmentrylist_station[atcptr->get_ident()];
291 //atcmentry_list_type atcmlist = atcmentrylist_station["EGNX"];
292 atcmentry_list_iterator current = atcmlist.begin();
293 atcmentry_list_iterator last = atcmlist.end();
295 // Set all opt flags to false before displaying box
296 fgSetBool("/sim/atc/opt0",false);
297 fgSetBool("/sim/atc/opt1",false);
298 fgSetBool("/sim/atc/opt2",false);
299 fgSetBool("/sim/atc/opt3",false);
300 fgSetBool("/sim/atc/opt4",false);
301 fgSetBool("/sim/atc/opt5",false);
302 fgSetBool("/sim/atc/opt6",false);
303 fgSetBool("/sim/atc/opt7",false);
304 fgSetBool("/sim/atc/opt8",false);
305 fgSetBool("/sim/atc/opt9",false);
311 if ( atcmlist.size() != 0 ){
312 int k=atcmlist.size();
314 //cout << "k = " << k << endl;
315 int y = (fgGetInt("/sim/startup/ysize") - 200 - 20 - k*20);
316 ATCMenuBox = new puDialogBox (100, y);
317 ATCMenuFrame = new puFrame (0,0,xsize,yc+40);
318 // loop over all entries in atcmentrylist
319 ATCOptionsList = new puButtonBox (50, 50, 450, 50+(k*25), NULL, true);
320 char** optList = new char*[k+1];
322 for ( ; current != last ; ++current ) {
324 sprintf( buf, "%i", kk+1 );
327 mentry[kk] = dum + ". " + current->menuentry;
328 optList[kk] = new char[strlen(mentry[kk].c_str()) + 1];
329 strcpy(optList[kk], mentry[kk].c_str());
330 //cout << "optList[" << kk << "] = " << optList[kk] << endl;
331 mtrans[kk] = current->transmission;
332 //ATCMenuBoxMessage = new puText (10, yc);
333 //ATCMenuBoxMessage -> setLabel( mentry[kk].c_str() );
339 ATCOptionsList->newList(optList);
341 int y = (fgGetInt("/sim/startup/ysize") - 100 - 20 );
342 ATCMenuBox = new puDialogBox (10, y);
343 ATCMenuFrame = new puFrame (0,0,xsize,yc+40);
344 ATCMenuBoxMessage = new puText (10, yc-10);
345 ATCMenuBoxMessage -> setLabel( "No transmission available" );
348 ATCMenuBoxMessage = new puText (10, yc+10);
349 ATCMenuBoxMessage -> setLabel( "ATC Menu" );
350 atcDialogOkButton = new puOneShot ((xsize/2)-85, 10, (xsize/2)-25, 50);
351 atcDialogOkButton -> setLegend (gui_msg_OK);
352 atcDialogOkButton -> makeReturnDefault (TRUE);
353 atcDialogOkButton -> setCallback (AKATCDialogOK);
355 atcDialogCancelButton = new puOneShot ((xsize/2)+25, 10, (xsize/2)+85, 50);
356 atcDialogCancelButton -> setLegend (gui_msg_CANCEL);
357 atcDialogCancelButton -> setCallback (AKATCDialogCancel);
358 FG_FINALIZE_PUI_DIALOG( ATCMenuBox );
359 FG_PUSH_PUI_DIALOG( ATCMenuBox );
363 if ( atckey != -1 && TransDisplayed && mtrans[atckey-1].c_str() != "" ) {
364 cout << mtrans[atckey-1].c_str() << endl;
365 TPar = current_transmissionlist->extract_transpar( mtrans[atckey-1].c_str() );
366 current_atcmentrylist->reset = true;
367 current_transparlist->add_entry( TPar );
369 // transpar_list_type test = current_transparlist;
370 // transpar_list_iterator current = test.begin();
371 //for ( ; current != test.end(); ++current ) {
372 // current->tpar.intention;
376 if ( current_atcmentrylist->freq != (int)(comm1_freq*100.0 + 0.5) ) {
377 current_atcmentrylist->reset = true;
380 // reset (delete) ATCmenue list if reset is true
381 if ( current_atcmentrylist->reset == true ) {
382 delete ( current_atcmentrylist );
383 current_atcmentrylist = new FGatcmentryList;
384 current_atcmentrylist->init( (int)(comm1_freq*100.0 + 0.5) );
385 if ( TransDisplayed ) {
386 FG_POP_PUI_DIALOG( ATCMenuBox );
387 TransDisplayed = false;