]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCDialog.cxx
Remove unimplemented options from the ATC dialog for now
[flightgear.git] / src / ATC / ATCDialog.cxx
1 // ATCDialog.cxx - Functions and classes to handle the pop-up ATC dialog
2 //
3 // Written by Alexander Kappes and David Luff, started February 2003.
4 //
5 // Copyright (C) 2003  Alexander Kappes and David Luff
6 //
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.
11 //
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.
16 //
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.
20
21 #include <simgear/structure/commands.hxx>
22
23 #include <Main/globals.hxx>
24 #include <GUI/gui.h>
25
26 #include "ATCDialog.hxx"
27 #include "ATC.hxx"
28 #include "ATCmgr.hxx"
29
30 FGATCDialog *current_atcdialog;
31
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();
35         return(true);
36 }
37
38 ATCMenuEntry::ATCMenuEntry() {
39   stationid    = "";
40   stationfr    = 0;
41   transmission = "";
42   menuentry    = "";
43 }
44
45 ATCMenuEntry::~ATCMenuEntry() {
46 }
47
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];
52
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 // ----------------------------------------------------------------------
63
64 // ------------------------ AK ------------------------------------------
65 static puDialogBox  *ATCMenuBox = 0;
66 static puFrame      *ATCMenuFrame = 0;
67 static puText       *ATCMenuBoxMessage = 0;
68 static puButtonBox      *ATCOptionsList = 0;
69 // ----------------------------------------------------------------------
70
71 // AK
72 static void AKATCDialogOK(puObject *)
73 {
74         switch(ATCOptionsList->getValue()) {
75         case 0:
76                 //cout << "Option 0 chosen\n";
77                 fgSetBool("/sim/atc/opt0",true);
78                 break;
79         case 1:
80                 //cout << "Option 1 chosen\n";
81                 fgSetBool("/sim/atc/opt1",true);
82                 break;
83         case 2:
84                 //cout << "Option 2 chosen\n";
85                 fgSetBool("/sim/atc/opt2",true);
86                 break;
87         case 3:
88                 //cout << "Option 2 chosen\n";
89                 fgSetBool("/sim/atc/opt3",true);
90                 break;
91         default:
92                 break;
93         }
94         FG_POP_PUI_DIALOG( ATCMenuBox );
95 }
96
97 // AK
98 static void AKATCDialogCancel(puObject *)
99 {
100     FG_POP_PUI_DIALOG( ATCMenuBox );
101 }
102
103 // DCL
104 static void ATCDialogCancel(puObject *)
105 {
106     //ATCDialogInput->rejectInput();
107     FG_POP_PUI_DIALOG( atcDialog );
108 }
109
110 // DCL
111 static void ATCDialogOK (puObject *me)
112 {
113         // Note that currently the dialog is hardwired to comm1 only here.
114         switch(globals->get_ATC_mgr()->GetComm1ATCType()) {
115         case INVALID:
116                 break;
117         case ATIS:
118                 break;
119         case TOWER: {
120                 /*
121                 FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetComm1ATCPointer();
122                 switch(atcDialogCommunicationOptions->getValue()) {
123                 case 0:
124                         //cout << "Option 0 chosen\n";
125                         twr->RequestLandingClearance("charlie foxtrot sierra");
126                         break;
127                 case 1:
128                         //cout << "Option 1 chosen\n";
129                         twr->RequestDepartureClearance("charlie foxtrot sierra");
130                         break;
131                 case 2:
132                         //cout << "Option 2 chosen\n";
133                         twr->ReportRunwayVacated("charlie foxtrot sierra");
134                         break;
135                 default:
136                         break;
137                 }
138                 */
139                 break;
140         }
141         case GROUND:
142                 break;
143         case APPROACH:
144                 break;
145         default:
146                 break;
147         }
148
149     ATCDialogCancel(me);
150     //if(error) mkDialog(s.c_str());
151 }
152
153 // DCL
154 static void ATCDialog(puObject *cb)
155 {
156     //ApHeadingDialogInput   ->    setValue ( heading );
157     //ApHeadingDialogInput    -> acceptInput();
158     FG_PUSH_PUI_DIALOG(atcDialog);
159 }
160
161 // DCL
162 void ATCDialogInit()
163 {
164         char defaultATCLabel[] = "Enter desired option to communicate with ATC:";
165         char *s;
166
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;
175         
176         atcDialog = new puDialogBox (150, 50);
177         {
178                 atcDialogFrame   = new puFrame (0, 0, 500, 250);
179                 
180                 atcDialogMessage = new puText          (250, 220);
181                 atcDialogMessage    -> setDefaultValue (defaultATCLabel);
182                 atcDialogMessage    -> getDefaultValue (&s);
183                 atcDialogMessage    -> setLabel        (s);
184                 atcDialogMessage    -> setLabelPlace   (PUPLACE_TOP_CENTERED);
185
186                 atcDialogCommunicationOptions = new puButtonBox (50, 50, 450, 210, NULL, true);
187                 
188                 atcDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
189                 atcDialogOkButton     ->     setLegend         (gui_msg_OK);
190                 atcDialogOkButton     ->     makeReturnDefault (TRUE);
191                 atcDialogOkButton     ->     setCallback       (ATCDialogOK);
192                 
193                 atcDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
194                 atcDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
195                 atcDialogCancelButton ->     setCallback       (ATCDialogCancel);
196                 
197         }
198         FG_FINALIZE_PUI_DIALOG(atcDialog);
199         
200         // Add ATC-dialog to the command list
201         globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
202 }
203
204 ///////////////////////////////////////////////////////////////////////
205 //
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
210 //
211 ///////////////////////////////////////////////////////////////////////
212 void ATCDoDialog(atc_type type) {
213         switch(type) {
214         case INVALID:
215                 atcDialogCommunicationOptions->newList(NULL);
216                 atcDialogMessage->setLabel("Not tuned in to any ATC service.");
217                 break;
218         case ATIS:
219                 atcDialogCommunicationOptions->newList(NULL);
220                 atcDialogMessage->setLabel("Tuned in to ATIS: no communication possible.");
221                 break;
222         case TOWER: 
223                 atcDialogCommunicationOptions->newList(towerOptions);
224                 atcDialogMessage->setLabel("Tuned in to Tower - select communication to transmit:");
225                 break;
226         case GROUND:
227                 atcDialogCommunicationOptions->newList(NULL);
228                 atcDialogMessage->setLabel("Tuned in to Ground - select communication to transmit:");
229                 break;
230         case APPROACH:
231                 current_atcdialog->DoDialog();
232                 break;
233         default:
234                 atcDialogCommunicationOptions->newList(NULL);
235                 atcDialogMessage->setLabel("Tuned in to unknown ATC service - enter transmission:");
236                 break;
237         }
238
239         // Third - display the dialog without pausing sim.
240         if(type != APPROACH) {  
241                 ATCDialog(NULL);
242         }
243 }
244
245 void FGATCDialog::Init() {
246 }
247
248 // AK
249 // Add an entry
250 void FGATCDialog::add_entry(string station, string transmission, string menutext ) {
251   
252   ATCMenuEntry a;
253
254   a.stationid = station;
255   a.transmission = transmission;
256   a.menuentry = menutext;
257
258   atcmentrylist_station[station.c_str()].push_back(a);
259
260 }
261
262 // AK
263 // query the database whether the transmission is already registered; 
264 bool FGATCDialog::trans_reg( const string &station, const string &trans ) {
265
266   atcmentry_list_type     atcmlist = atcmentrylist_station[station];
267   atcmentry_list_iterator current  = atcmlist.begin();
268   atcmentry_list_iterator last     = atcmlist.end();
269   
270   for ( ; current != last ; ++current ) {
271     if ( current->transmission == trans ) return true;
272   }
273   return false;
274 }
275
276 // AK
277 // ===================================================
278 // ===  Update ATC menue and look for keys pressed ===
279 // ===================================================
280 void FGATCDialog::DoDialog() {
281         
282         static string mentry[10];
283         static string mtrans[10];
284         char   buf[10];
285         TransPar TPar;
286         FGATC* atcptr = globals->get_ATC_mgr()->GetComm1ATCPointer();   // Hardwired to comm1 at the moment
287         
288         if(atcptr != NULL) {
289                 
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();
294                 
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);
306                 
307                 //int yc = 10;
308                 int yc = 70;
309                 int xsize = 600;
310                 
311                 if ( atcmlist.size() != 0 ){ 
312                         int k=atcmlist.size();
313                         //int k = 3;
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];
321                         int kk = 0;
322                         for ( ; current != last ; ++current ) {
323                                 string dum;
324                                 sprintf( buf, "%i", kk+1 );
325                                 buf[1] = '\0';
326                                 dum = (string)(buf);
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() );
334                                 yc += 20;
335                                 ++kk;
336                         } 
337                         yc += 2*20;
338                         optList[k] = NULL;
339                         ATCOptionsList->newList(optList);
340                 } else {
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" );
346                 }
347                 
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);
354                 
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 );
360                 
361                 
362                 /*      
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 );
368                         
369                         //    transpar_list_type test = current_transparlist;
370                         // transpar_list_iterator current = test.begin();
371                         //for ( ; current != test.end(); ++current ) {
372                                 // current->tpar.intention;
373                         //}
374                 }
375                 
376                 if ( current_atcmentrylist->freq != (int)(comm1_freq*100.0 + 0.5) ) {
377                         current_atcmentrylist->reset = true;
378                 }
379                 
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;
388                         }
389                 }
390                 */      
391         }
392 }
393