2003-02-13 12:05:19 +00:00
|
|
|
// ATCDialog.cxx - Functions and classes to handle the pop-up ATC dialog
|
|
|
|
//
|
|
|
|
// Written by Alexander Kappes and David Luff, started February 2003.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 Alexander Kappes and David Luff
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2003-10-16 14:14:03 +00:00
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
#include <simgear/structure/commands.hxx>
|
|
|
|
|
2003-02-13 12:05:19 +00:00
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <GUI/gui.h>
|
|
|
|
|
|
|
|
#include "ATCDialog.hxx"
|
|
|
|
#include "ATC.hxx"
|
|
|
|
#include "ATCmgr.hxx"
|
2003-11-05 10:06:57 +00:00
|
|
|
#include "ATCdisplay.hxx"
|
2003-10-10 15:13:16 +00:00
|
|
|
#include "commlist.hxx"
|
|
|
|
#include "ATCutils.hxx"
|
|
|
|
#include <Airports/simple.hxx>
|
2003-02-13 12:05:19 +00:00
|
|
|
|
2003-10-13 11:30:40 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
SG_USING_STD(ostringstream);
|
|
|
|
|
2003-02-13 12:05:19 +00:00
|
|
|
FGATCDialog *current_atcdialog;
|
|
|
|
|
|
|
|
// For the command manager - maybe eventually this should go in the built in command list
|
|
|
|
static bool do_ATC_dialog(const SGPropertyNode* arg) {
|
2003-11-04 11:54:42 +00:00
|
|
|
current_atcdialog->PopupDialog();
|
2003-02-13 12:05:19 +00:00
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2003-10-10 15:13:16 +00:00
|
|
|
static bool do_ATC_freq_search(const SGPropertyNode* arg) {
|
|
|
|
current_atcdialog->FreqDialog();
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
2003-02-13 12:05:19 +00:00
|
|
|
ATCMenuEntry::ATCMenuEntry() {
|
|
|
|
stationid = "";
|
2003-11-04 11:54:42 +00:00
|
|
|
//stationfr = 0;
|
2003-02-13 12:05:19 +00:00
|
|
|
transmission = "";
|
|
|
|
menuentry = "";
|
2003-11-04 11:54:42 +00:00
|
|
|
callback_code = 0;
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ATCMenuEntry::~ATCMenuEntry() {
|
|
|
|
}
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
static void atcUppercase(string &s) {
|
|
|
|
for(unsigned int i=0; i<s.size(); ++i) {
|
|
|
|
s[i] = toupper(s[i]);
|
|
|
|
}
|
|
|
|
}
|
2003-02-13 12:05:19 +00:00
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
// ----------------------- Popup Dialog Statics------------------
|
2003-11-05 10:06:57 +00:00
|
|
|
static puDialogBox* atcDialog;
|
|
|
|
static puFrame* atcDialogFrame;
|
|
|
|
static puText* atcDialogMessage;
|
|
|
|
static puOneShot* atcDialogOkButton;
|
|
|
|
static puOneShot* atcDialogCancelButton;
|
|
|
|
static puButtonBox* atcDialogCommunicationOptions;
|
2003-11-04 11:54:42 +00:00
|
|
|
// --------------------------------------------------------------
|
2003-10-21 11:44:43 +00:00
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
// ----------------------- Freq Dialog Statics-------------------
|
2003-10-21 11:44:43 +00:00
|
|
|
static const int ATC_MAX_FREQ_DISPLAY = 20; // Maximum number of frequencies that can be displayed for any one airport
|
|
|
|
|
|
|
|
static puDialogBox* atcFreqDialog;
|
|
|
|
static puFrame* atcFreqDialogFrame;
|
|
|
|
static puText* atcFreqDialogMessage;
|
|
|
|
static puInput* atcFreqDialogInput;
|
|
|
|
static puOneShot* atcFreqDialogOkButton;
|
|
|
|
static puOneShot* atcFreqDialogCancelButton;
|
|
|
|
|
|
|
|
static puDialogBox* atcFreqDisplay;
|
|
|
|
static puFrame* atcFreqDisplayFrame;
|
|
|
|
static puText* atcFreqDisplayMessage;
|
|
|
|
static puOneShot* atcFreqDisplayOkButton;
|
|
|
|
static puText* atcFreqDisplayText[ATC_MAX_FREQ_DISPLAY];
|
2003-11-04 11:54:42 +00:00
|
|
|
// --------------------------------------------------------------
|
2003-10-21 11:44:43 +00:00
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
//////////////// Popup callbacks ///////////////////
|
2003-11-05 10:06:57 +00:00
|
|
|
static void ATCDialogOK(puObject*) {
|
|
|
|
current_atcdialog->PopupCallback();
|
2003-11-04 11:54:42 +00:00
|
|
|
FG_POP_PUI_DIALOG( atcDialog );
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 10:06:57 +00:00
|
|
|
static void ATCDialogCancel(puObject*) {
|
2003-02-13 12:05:19 +00:00
|
|
|
FG_POP_PUI_DIALOG( atcDialog );
|
|
|
|
}
|
2003-11-04 11:54:42 +00:00
|
|
|
//////////////////////////////////////////////////
|
2003-02-13 12:05:19 +00:00
|
|
|
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
///////////////// Freq search callbacks ///////////
|
|
|
|
static void FreqDialogCancel(puObject*) {
|
|
|
|
FG_POP_PUI_DIALOG(atcFreqDialog);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
static void FreqDialogOK(puObject*) {
|
|
|
|
string tmp = atcFreqDialogInput->getStringValue();
|
|
|
|
FG_POP_PUI_DIALOG(atcFreqDialog);
|
|
|
|
current_atcdialog->FreqDisplay(tmp);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
static void FreqDisplayOK(puObject*) {
|
|
|
|
FG_POP_PUI_DIALOG(atcFreqDisplay);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
2003-11-04 11:54:42 +00:00
|
|
|
//////////////////////////////////////////////////
|
2003-02-13 12:05:19 +00:00
|
|
|
|
|
|
|
|
2003-10-21 11:44:43 +00:00
|
|
|
FGATCDialog::FGATCDialog() {
|
2003-11-05 10:06:57 +00:00
|
|
|
_callbackPending = false;
|
|
|
|
_callbackTimer = 0.0;
|
|
|
|
_callbackWait = 0.0;
|
|
|
|
_callbackPtr = NULL;
|
|
|
|
_callbackCode = 0;
|
2003-10-21 11:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGATCDialog::~FGATCDialog() {
|
2003-11-04 11:54:42 +00:00
|
|
|
if(atcDialog) puDeleteObject(atcDialog);
|
2003-10-22 10:50:11 +00:00
|
|
|
if(atcFreqDialog) puDeleteObject(atcFreqDialog);
|
|
|
|
if(atcFreqDisplay) puDeleteObject(atcFreqDisplay);
|
2003-10-21 11:44:43 +00:00
|
|
|
}
|
|
|
|
|
2003-02-13 12:05:19 +00:00
|
|
|
void FGATCDialog::Init() {
|
2003-11-04 11:54:42 +00:00
|
|
|
// Add ATC-dialog to the command list
|
|
|
|
globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
|
2003-10-10 15:13:16 +00:00
|
|
|
// Add ATC-freq-search to the command list
|
|
|
|
globals->get_commands()->addCommand("ATC-freq-search", do_ATC_freq_search);
|
2003-10-21 11:44:43 +00:00
|
|
|
|
2003-10-22 10:50:11 +00:00
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
|
2003-10-21 11:44:43 +00:00
|
|
|
// Init the freq-search dialog
|
2003-10-22 10:50:11 +00:00
|
|
|
w = 300;
|
|
|
|
h = 150;
|
|
|
|
x = (fgGetInt("/sim/startup/xsize") / 2) - (w / 2);
|
|
|
|
y = 50;
|
2003-10-21 11:44:43 +00:00
|
|
|
char *s;
|
2003-10-22 10:50:11 +00:00
|
|
|
atcFreqDialog = new puDialogBox (x, y);
|
2003-10-21 11:44:43 +00:00
|
|
|
{
|
2003-10-22 10:50:11 +00:00
|
|
|
atcFreqDialogFrame = new puFrame (0, 0, w, h);
|
|
|
|
atcFreqDialogMessage = new puText (40, (h - 30));
|
2003-10-21 11:44:43 +00:00
|
|
|
atcFreqDialogMessage->setDefaultValue ("Enter airport identifier:");
|
|
|
|
atcFreqDialogMessage->getDefaultValue (&s);
|
|
|
|
atcFreqDialogMessage->setLabel(s);
|
|
|
|
|
2003-10-22 10:50:11 +00:00
|
|
|
atcFreqDialogInput = new puInput (50, (h - 75), 150, (h - 45));
|
2003-10-21 11:44:43 +00:00
|
|
|
|
|
|
|
atcFreqDialogOkButton = new puOneShot (50, 10, 110, 50);
|
|
|
|
atcFreqDialogOkButton -> setLegend (gui_msg_OK);
|
|
|
|
atcFreqDialogOkButton -> makeReturnDefault (TRUE);
|
|
|
|
atcFreqDialogOkButton -> setCallback (FreqDialogOK);
|
|
|
|
|
|
|
|
atcFreqDialogCancelButton = new puOneShot (140, 10, 210, 50);
|
|
|
|
atcFreqDialogCancelButton -> setLegend (gui_msg_CANCEL);
|
|
|
|
atcFreqDialogCancelButton -> setCallback (FreqDialogCancel);
|
|
|
|
|
|
|
|
atcFreqDialogInput->acceptInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
FG_FINALIZE_PUI_DIALOG(atcFreqDialog);
|
|
|
|
|
|
|
|
// Init the freq-display dialog
|
2003-10-22 10:50:11 +00:00
|
|
|
w = 400;
|
|
|
|
h = 100;
|
|
|
|
x = (fgGetInt("/sim/startup/xsize") / 2) - (w / 2);
|
|
|
|
y = 50;
|
|
|
|
atcFreqDisplay = new puDialogBox (x, y);
|
2003-10-21 11:44:43 +00:00
|
|
|
{
|
2003-10-22 10:50:11 +00:00
|
|
|
atcFreqDisplayFrame = new puFrame (0, 0, w, h);
|
2003-10-21 11:44:43 +00:00
|
|
|
|
2003-10-22 10:50:11 +00:00
|
|
|
atcFreqDisplayMessage = new puText (40, (h - 30));
|
2003-10-21 11:44:43 +00:00
|
|
|
atcFreqDisplayMessage -> setDefaultValue ("No freqencies found");
|
|
|
|
atcFreqDisplayMessage -> getDefaultValue (&s);
|
|
|
|
atcFreqDisplayMessage -> setLabel (s);
|
|
|
|
|
|
|
|
for(int i=0; i<ATC_MAX_FREQ_DISPLAY; ++i) {
|
2003-10-22 10:50:11 +00:00
|
|
|
atcFreqDisplayText[i] = new puText(40, h - 65 - (30 * i));
|
2003-10-21 11:44:43 +00:00
|
|
|
atcFreqDisplayText[i]->setDefaultValue("");
|
|
|
|
atcFreqDisplayText[i]-> getDefaultValue (&s);
|
|
|
|
atcFreqDisplayText[i]-> setLabel (s);
|
|
|
|
atcFreqDisplayText[i]->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
atcFreqDisplayOkButton = new puOneShot (50, 10, 110, 50);
|
|
|
|
atcFreqDisplayOkButton -> setLegend (gui_msg_OK);
|
|
|
|
atcFreqDisplayOkButton -> makeReturnDefault (TRUE);
|
|
|
|
atcFreqDisplayOkButton -> setCallback (FreqDisplayOK);
|
|
|
|
}
|
|
|
|
FG_FINALIZE_PUI_DIALOG(atcFreqDisplay);
|
2003-10-22 10:50:11 +00:00
|
|
|
|
|
|
|
// Init AK's interactive ATC menus
|
|
|
|
w = 500;
|
|
|
|
h = 110;
|
|
|
|
x = (fgGetInt("/sim/startup/xsize") / 2) - (w / 2);
|
|
|
|
//y = (fgGetInt("/sim/startup/ysize") / 2) - (h / 2);
|
|
|
|
y = 50;
|
2003-11-04 11:54:42 +00:00
|
|
|
atcDialog = new puDialogBox (x, y);
|
2003-10-22 10:50:11 +00:00
|
|
|
{
|
2003-11-04 11:54:42 +00:00
|
|
|
atcDialogFrame = new puFrame (0,0,w,h);
|
|
|
|
atcDialogMessage = new puText (w / 2, h - 30);
|
|
|
|
atcDialogMessage -> setLabel( "No transmission available" );
|
|
|
|
atcDialogMessage -> setLabelPlace(PUPLACE_TOP_CENTERED);
|
|
|
|
atcDialogCommunicationOptions = new puButtonBox (50, 60, 450, 50, NULL, true);
|
|
|
|
atcDialogCommunicationOptions -> hide();
|
2003-10-22 10:50:11 +00:00
|
|
|
atcDialogOkButton = new puOneShot ((w/2)-85, 10, (w/2)-25, 50);
|
|
|
|
atcDialogOkButton -> setLegend (gui_msg_OK);
|
|
|
|
atcDialogOkButton -> makeReturnDefault (TRUE);
|
2003-11-04 11:54:42 +00:00
|
|
|
atcDialogOkButton -> setCallback (ATCDialogOK);
|
2003-10-22 10:50:11 +00:00
|
|
|
|
|
|
|
atcDialogCancelButton = new puOneShot ((w/2)+25, 10, (w/2)+85, 50);
|
|
|
|
atcDialogCancelButton -> setLegend (gui_msg_CANCEL);
|
2003-11-04 11:54:42 +00:00
|
|
|
atcDialogCancelButton -> setCallback (ATCDialogCancel);
|
2003-10-22 10:50:11 +00:00
|
|
|
}
|
2003-11-04 11:54:42 +00:00
|
|
|
FG_FINALIZE_PUI_DIALOG(atcDialog);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 10:06:57 +00:00
|
|
|
void FGATCDialog::Update(double dt) {
|
|
|
|
if(_callbackPending) {
|
|
|
|
if(_callbackTimer > _callbackWait) {
|
|
|
|
_callbackPtr->ReceiveUserCallback(_callbackCode);
|
|
|
|
_callbackPtr->NotifyTransmissionFinished(fgGetString("/sim/user/callsign"));
|
|
|
|
_callbackPending = false;
|
|
|
|
} else {
|
|
|
|
_callbackTimer += dt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-13 12:05:19 +00:00
|
|
|
// Add an entry
|
2003-11-04 11:54:42 +00:00
|
|
|
void FGATCDialog::add_entry(string station, string transmission, string menutext, atc_type type, int code) {
|
|
|
|
|
2003-02-13 12:05:19 +00:00
|
|
|
ATCMenuEntry a;
|
|
|
|
|
|
|
|
a.stationid = station;
|
|
|
|
a.transmission = transmission;
|
|
|
|
a.menuentry = menutext;
|
2003-11-04 11:54:42 +00:00
|
|
|
a.callback_code = code;
|
2003-02-13 12:05:19 +00:00
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
(available_dialog[type])[station.c_str()].push_back(a);
|
2003-02-13 12:05:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
void FGATCDialog::remove_entry( const string &station, const string &trans, atc_type type ) {
|
2003-11-05 17:24:58 +00:00
|
|
|
atcmentry_vec_type* p = &((available_dialog[type])[station]);
|
2004-01-23 17:18:24 +00:00
|
|
|
atcmentry_vec_iterator current = p->begin();
|
2003-11-05 17:24:58 +00:00
|
|
|
while(current != p->end()) {
|
|
|
|
if(current->transmission == trans) current = p->erase(current);
|
2003-11-04 11:54:42 +00:00
|
|
|
else ++current;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGATCDialog::remove_entry( const string &station, int code, atc_type type ) {
|
2003-11-05 17:24:58 +00:00
|
|
|
atcmentry_vec_type* p = &((available_dialog[type])[station]);
|
2004-01-23 17:18:24 +00:00
|
|
|
atcmentry_vec_iterator current = p->begin();
|
2003-11-05 17:24:58 +00:00
|
|
|
while(current != p->end()) {
|
|
|
|
if(current->callback_code == code) current = p->erase(current);
|
2003-11-04 11:54:42 +00:00
|
|
|
else ++current;
|
|
|
|
}
|
|
|
|
}
|
2003-02-13 12:05:19 +00:00
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
// query the database whether the transmission is already registered;
|
|
|
|
bool FGATCDialog::trans_reg( const string &station, const string &trans, atc_type type ) {
|
2003-11-05 17:24:58 +00:00
|
|
|
atcmentry_vec_type* p = &((available_dialog[type])[station]);
|
2004-01-23 17:18:24 +00:00
|
|
|
atcmentry_vec_iterator current = p->begin();
|
2003-11-05 17:24:58 +00:00
|
|
|
for ( ; current != p->end() ; ++current ) {
|
2003-02-13 12:05:19 +00:00
|
|
|
if ( current->transmission == trans ) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
// query the database whether the transmission is already registered;
|
|
|
|
bool FGATCDialog::trans_reg( const string &station, int code, atc_type type ) {
|
2003-11-05 17:24:58 +00:00
|
|
|
atcmentry_vec_type* p = &((available_dialog[type])[station]);
|
2004-01-23 17:18:24 +00:00
|
|
|
atcmentry_vec_iterator current = p->begin();
|
2003-11-05 17:24:58 +00:00
|
|
|
for ( ; current != p->end() ; ++current ) {
|
2003-11-04 11:54:42 +00:00
|
|
|
if ( current->callback_code == code ) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the ATC popup dialog box with options relevant to the users current situation.
|
|
|
|
void FGATCDialog::PopupDialog() {
|
2003-02-13 12:05:19 +00:00
|
|
|
|
|
|
|
static string mentry[10];
|
|
|
|
static string mtrans[10];
|
|
|
|
char buf[10];
|
|
|
|
TransPar TPar;
|
|
|
|
FGATC* atcptr = globals->get_ATC_mgr()->GetComm1ATCPointer(); // Hardwired to comm1 at the moment
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
int w = 500;
|
|
|
|
int h = 100;
|
|
|
|
if(atcptr) {
|
|
|
|
if(atcptr->GetType() == ATIS) {
|
|
|
|
atcDialogCommunicationOptions->hide();
|
|
|
|
atcDialogMessage -> setLabel( "Tuned to ATIS - no communication possible" );
|
|
|
|
atcDialogFrame->setSize(w, h);
|
|
|
|
atcDialogMessage -> setPosition(w / 2, h - 30);
|
2003-02-13 12:05:19 +00:00
|
|
|
} else {
|
|
|
|
|
2003-11-04 11:54:42 +00:00
|
|
|
atcmentry_vec_type atcmlist = (available_dialog[atcptr->GetType()])[atcptr->get_ident()];
|
|
|
|
atcmentry_vec_iterator current = atcmlist.begin();
|
|
|
|
atcmentry_vec_iterator last = atcmlist.end();
|
|
|
|
|
|
|
|
// Set all opt flags to false before displaying box
|
|
|
|
fgSetBool("/sim/atc/opt0",false);
|
|
|
|
fgSetBool("/sim/atc/opt1",false);
|
|
|
|
fgSetBool("/sim/atc/opt2",false);
|
|
|
|
fgSetBool("/sim/atc/opt3",false);
|
|
|
|
fgSetBool("/sim/atc/opt4",false);
|
|
|
|
fgSetBool("/sim/atc/opt5",false);
|
|
|
|
fgSetBool("/sim/atc/opt6",false);
|
|
|
|
fgSetBool("/sim/atc/opt7",false);
|
|
|
|
fgSetBool("/sim/atc/opt8",false);
|
|
|
|
fgSetBool("/sim/atc/opt9",false);
|
|
|
|
|
|
|
|
int k = atcmlist.size();
|
|
|
|
h += k * 25;
|
|
|
|
//cout << "k = " << k << '\n';
|
|
|
|
|
|
|
|
atcDialogFrame->setSize(w, h);
|
|
|
|
|
|
|
|
if(k) {
|
|
|
|
// loop over all entries in atcmentrylist
|
|
|
|
char** optList = new char*[k+1];
|
|
|
|
int kk = 0;
|
|
|
|
for ( ; current != last ; ++current ) {
|
|
|
|
string dum;
|
|
|
|
sprintf( buf, "%i", kk+1 );
|
|
|
|
buf[1] = '\0';
|
|
|
|
dum = buf;
|
|
|
|
mentry[kk] = dum + ". " + current->menuentry;
|
|
|
|
optList[kk] = new char[strlen(mentry[kk].c_str()) + 1];
|
|
|
|
strcpy(optList[kk], mentry[kk].c_str());
|
|
|
|
//cout << "optList[" << kk << "] = " << optList[kk] << endl;
|
|
|
|
mtrans[kk] = current->transmission;
|
|
|
|
++kk;
|
|
|
|
}
|
|
|
|
optList[k] = NULL;
|
|
|
|
atcDialogCommunicationOptions->newList(optList);
|
2003-11-05 17:24:58 +00:00
|
|
|
atcDialogCommunicationOptions->setSize(w-100, h-90);
|
2003-11-04 11:54:42 +00:00
|
|
|
atcDialogCommunicationOptions->reveal();
|
|
|
|
atcDialogMessage -> setLabel( "ATC Menu" );
|
|
|
|
atcDialogMessage -> setPosition(w / 2, h - 30);
|
|
|
|
} else {
|
|
|
|
atcDialogCommunicationOptions->hide();
|
|
|
|
atcDialogMessage -> setLabel( "No transmission available" );
|
|
|
|
atcDialogMessage -> setPosition(w / 2, h - 30);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-04 11:54:42 +00:00
|
|
|
} else {
|
|
|
|
atcDialogCommunicationOptions->hide();
|
|
|
|
atcDialogMessage -> setLabel( "Not currently tuned to any ATC service" );
|
|
|
|
atcDialogFrame->setSize(w, h);
|
|
|
|
atcDialogMessage -> setPosition(w / 2, h - 30);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
2003-11-04 11:54:42 +00:00
|
|
|
|
|
|
|
FG_PUSH_PUI_DIALOG(atcDialog);
|
2003-02-13 12:05:19 +00:00
|
|
|
}
|
|
|
|
|
2003-11-05 10:06:57 +00:00
|
|
|
void FGATCDialog::PopupCallback() {
|
|
|
|
FGATC* atcptr = globals->get_ATC_mgr()->GetComm1ATCPointer(); // FIXME - Hardwired to comm1 at the moment
|
2003-10-20 21:48:57 +00:00
|
|
|
|
2003-11-05 10:06:57 +00:00
|
|
|
if(atcptr) {
|
|
|
|
if(atcptr->GetType() == APPROACH) {
|
|
|
|
switch(atcDialogCommunicationOptions->getValue()) {
|
|
|
|
case 0:
|
|
|
|
fgSetBool("/sim/atc/opt0",true);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fgSetBool("/sim/atc/opt1",true);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
fgSetBool("/sim/atc/opt2",true);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
fgSetBool("/sim/atc/opt3",true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if(atcptr->GetType() == TOWER) {
|
2004-01-23 17:18:24 +00:00
|
|
|
//cout << "TOWER " << endl;
|
|
|
|
//cout << "ident is " << atcptr->get_ident() << endl;
|
|
|
|
atcmentry_vec_type atcmlist = (available_dialog[TOWER])[(string)atcptr->get_ident()];
|
|
|
|
if(atcmlist.size()) {
|
|
|
|
//cout << "Doing callback...\n";
|
|
|
|
ATCMenuEntry a = atcmlist[atcDialogCommunicationOptions->getValue()];
|
|
|
|
atcptr->SetFreqInUse();
|
|
|
|
globals->get_ATC_display()->RegisterSingleMessage(atcptr->GenText(a.transmission, a.callback_code));
|
|
|
|
_callbackPending = true;
|
|
|
|
_callbackTimer = 0.0;
|
|
|
|
_callbackWait = 5.0;
|
|
|
|
_callbackPtr = atcptr;
|
|
|
|
_callbackCode = a.callback_code;
|
|
|
|
} else {
|
|
|
|
//cout << "No options available...\n";
|
|
|
|
}
|
|
|
|
//cout << "Donded" << endl;
|
2003-11-05 10:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-10 15:13:16 +00:00
|
|
|
|
|
|
|
void FGATCDialog::FreqDialog() {
|
|
|
|
|
|
|
|
// Find the ATC stations within a reasonable range (about 40 miles?)
|
|
|
|
//comm_list_type atc_stations;
|
|
|
|
//comm_list_iterator atc_stat_itr;
|
|
|
|
|
|
|
|
//double lon = fgGetDouble("/position/longitude-deg");
|
|
|
|
//double lat = fgGetDouble("/position/latitude-deg");
|
|
|
|
//double elev = fgGetDouble("/position/altitude-ft");
|
|
|
|
|
|
|
|
/*
|
|
|
|
// search stations in range
|
|
|
|
int num_stat = current_commlist->FindByPos(lon, lat, elev, 40.0, &atc_stations);
|
|
|
|
if (num_stat != 0) {
|
|
|
|
} else {
|
|
|
|
// Make up a message saying no things in range
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2003-10-21 11:44:43 +00:00
|
|
|
// TODO - it would be nice to display a drop-down list of airports within the general vicinity of the user
|
|
|
|
// in addition to the general input box (started above).
|
2003-10-10 15:13:16 +00:00
|
|
|
|
2003-10-21 11:44:43 +00:00
|
|
|
atcFreqDialogInput->setValue("");
|
|
|
|
atcFreqDialogInput->acceptInput();
|
2003-10-10 15:13:16 +00:00
|
|
|
FG_PUSH_PUI_DIALOG(atcFreqDialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGATCDialog::FreqDisplay(string ident) {
|
|
|
|
|
|
|
|
atcUppercase(ident);
|
|
|
|
|
2003-10-21 11:44:43 +00:00
|
|
|
string label;
|
2003-10-10 15:13:16 +00:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
int n = 0; // Number of ATC frequencies at this airport
|
2003-10-21 11:44:43 +00:00
|
|
|
string freqs[ATC_MAX_FREQ_DISPLAY];
|
2003-10-10 15:13:16 +00:00
|
|
|
char buf[8];
|
|
|
|
|
|
|
|
FGAirport a;
|
|
|
|
if ( dclFindAirportID( ident, &a ) ) {
|
|
|
|
comm_list_type stations;
|
|
|
|
int found = current_commlist->FindByPos(a.longitude, a.latitude, a.elevation, 20.0, &stations);
|
|
|
|
if(found) {
|
2003-10-13 11:30:40 +00:00
|
|
|
ostringstream ostr;
|
2003-10-10 15:13:16 +00:00
|
|
|
comm_list_iterator itr = stations.begin();
|
|
|
|
while(itr != stations.end()) {
|
|
|
|
if((*itr).ident == ident) {
|
2003-10-13 11:30:40 +00:00
|
|
|
if((*itr).type != INVALID) {
|
|
|
|
ostr << (*itr).type;
|
2003-10-16 14:14:03 +00:00
|
|
|
freqs[n] = ostr.str();
|
|
|
|
freqs[n].append(" - ");
|
2003-10-10 15:13:16 +00:00
|
|
|
sprintf(buf, "%.2f", ((*itr).freq / 100.0)); // Convert from KHz to MHz
|
|
|
|
// Hack alert!
|
|
|
|
if(buf[5] == '3') buf[5] = '2';
|
|
|
|
if(buf[5] == '8') buf[5] = '7';
|
|
|
|
freqs[n] += buf;
|
2003-10-13 11:30:40 +00:00
|
|
|
ostr.seekp(0);
|
2003-10-10 15:13:16 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
}
|
2003-10-21 11:44:43 +00:00
|
|
|
if(n == 0) {
|
|
|
|
label = "No frequencies found for airport ";
|
|
|
|
label += ident;
|
|
|
|
} else {
|
|
|
|
label = "Frequencies for airport ";
|
|
|
|
label += ident;
|
|
|
|
label += ":";
|
|
|
|
}
|
2003-10-10 15:13:16 +00:00
|
|
|
} else {
|
|
|
|
label = "Airport ";
|
|
|
|
label += ident;
|
|
|
|
label += " not found in database.";
|
|
|
|
}
|
2003-10-21 11:44:43 +00:00
|
|
|
|
|
|
|
int hsize = 105 + (n * 30);
|
2003-10-10 15:13:16 +00:00
|
|
|
|
2003-10-21 11:44:43 +00:00
|
|
|
atcFreqDisplayFrame->setSize(400, hsize);
|
|
|
|
|
|
|
|
atcFreqDisplayMessage -> setPosition (40, (hsize - 30));
|
|
|
|
atcFreqDisplayMessage -> setValue (label.c_str());
|
|
|
|
atcFreqDisplayMessage -> getValue (&s);
|
|
|
|
atcFreqDisplayMessage -> setLabel (s);
|
|
|
|
|
|
|
|
for(int i=0; i<n; ++i) {
|
|
|
|
atcFreqDisplayText[i] -> setPosition(40, hsize - 65 - (30 * i));
|
|
|
|
atcFreqDisplayText[i] -> setValue(freqs[i].c_str());
|
|
|
|
atcFreqDisplayText[i] -> getValue (&s);
|
|
|
|
atcFreqDisplayText[i] -> setLabel (s);
|
|
|
|
atcFreqDisplayText[i] -> reveal();
|
2003-10-10 15:13:16 +00:00
|
|
|
}
|
2003-10-21 11:44:43 +00:00
|
|
|
for(int j=n; j<ATC_MAX_FREQ_DISPLAY; ++j) {
|
|
|
|
atcFreqDisplayText[j] -> hide();
|
2003-10-10 15:13:16 +00:00
|
|
|
}
|
|
|
|
|
2003-10-20 21:48:57 +00:00
|
|
|
FG_PUSH_PUI_DIALOG(atcFreqDisplay);
|
2003-10-10 15:13:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|