1 // transmissionlist.cxx -- transmission management class
3 // Written by Alexander Kappes, started March 2002.
4 // Based on navlist.cxx by Curtis Olson, started April 2000.
6 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <simgear/debug/logstream.hxx>
30 #include <simgear/misc/sgstream.hxx>
31 #include <simgear/math/sg_geodesy.hxx>
33 #include "transmissionlist.hxx"
37 static puDialogBox *ATCMenuBox = 0;
38 static puFrame *ATCMenuFrame = 0;
39 static puText *ATCMenuBoxMessage = 0;
41 FGTransmissionList *current_transmissionlist;
45 FGTransmissionList::FGTransmissionList( void ) {
50 FGTransmissionList::~FGTransmissionList( void ) {
54 // ============================================================================
56 // ============================================================================
57 void mkATCMenuInit (void)
61 int y = (fgGetInt("/sim/startup/ysize") - 10 - dy);
62 ATCMenuBox = new puDialogBox (10, y);
64 ATCMenuFrame = new puFrame (0,0,400,100);
65 ATCMenuBoxMessage = new puText (10, 70);
66 ATCMenuBoxMessage -> setLabel ("");
68 fgSetBool("/sim/atc/menu",false);
69 fgSetBool("/sim/atc/opt1",false);
70 fgSetBool("/sim/atc/opt2",false);
71 fgSetBool("/sim/atc/opt3",false);
72 fgSetBool("/sim/atc/opt4",false);
73 fgSetBool("/sim/atc/opt5",false);
74 fgSetBool("/sim/atc/opt6",false);
75 fgSetBool("/sim/atc/opt7",false);
76 fgSetBool("/sim/atc/opt8",false);
77 fgSetBool("/sim/atc/opt9",false);
78 fgSetBool("/sim/atc/opt0",false);
81 // ATC Menu Message Box
82 void mkATCMenu ( const char *txt )
84 ATCMenuBoxMessage = new puText (10, 70);
85 ATCMenuBoxMessage->setLabel( txt );
87 FG_PUSH_PUI_DIALOG( ATCMenuBox );
91 // load default.transmissions
92 bool FGTransmissionList::init( SGPath path ) {
95 transmissionlist_station.erase( transmissionlist_station.begin(), transmissionlist_station.end() );
97 sg_gzifstream in( path.str() );
98 if ( !in.is_open() ) {
99 SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << path.str() );
103 // read in each line of the file
106 // in >> skipcomment;
111 while ( in.get(c) && c != '\0' ) {
114 if ( a.get_type() != '[' ) {
115 transmissionlist_code[a.get_station()].push_back(a);
125 while ( ! in.eof() ) {
127 transmissionlist_station[a.get_station()].push_back(a);
131 if ( a.get_station() < min ) {
132 min = a.get_station();
134 if ( a.get_station() > max ) {
135 max = a.get_station();
137 cout << a.get_station() << " " << a.get_code().c1 << " " << a.get_code().c2 << " "
138 << a.get_code().c3 << " " << a.get_transtext()
139 << " " << a.get_menutext() << endl;
145 fgSetBool("/sim/atc/menu",false);
150 // query the database for the specified station type;
151 // for station see FlightGear/ATC/default.transmissions
152 bool FGTransmissionList::query_station( const int &station, FGTransmission *t,
153 int max_trans, int &num_trans )
155 transmission_list_type tmissions = transmissionlist_station[station];
156 transmission_list_iterator current = tmissions.begin();
157 transmission_list_iterator last = tmissions.end();
159 for ( ; current != last ; ++current ) {
160 if (num_trans < max_trans) {
161 t[num_trans] = *current;
165 cout << "Transmissionlist error: Too many transmissions" << endl;
169 if ( num_trans != 0 ) return true;
171 cout << "No transmission with station " << station << "found." << endl;
177 string FGTransmissionList::gen_text(const int &station, const TransCode code,
178 const TransPar &tpars, const bool ttext )
180 const int cmax = 100;
191 // if (current_transmissionlist->query_station( station, &t ) ) {
192 transmission_list_type tmissions = transmissionlist_station[station];
193 transmission_list_iterator current = tmissions.begin();
194 transmission_list_iterator last = tmissions.end();
196 for ( ; current != last ; ++current ) {
197 if ( current->get_code().c1 == code.c1 &&
198 current->get_code().c2 == code.c2 &&
199 current->get_code().c3 == code.c3 ) {
201 if ( ttext ) message = current->get_transtext();
202 else message = current->get_menutext();
203 strcpy( &mes[0], message.c_str() );
205 while ( strchr(&mes[0], crej) != NULL ) {
206 pos = strchr( &mes[0], crej );
211 for ( i=0; i<cmax; i++ ) {
212 if ( mes[i] == crej ) {
217 strncpy( &dum[0], &mes[0], len );
220 if ( strcmp ( tag, "@ST" ) == 0 )
221 strcat( &dum[0], tpars.station.c_str() );
222 else if ( strcmp ( tag, "@AP" ) == 0 )
223 strcat( &dum[0], tpars.airport.c_str() );
224 else if ( strcmp ( tag, "@CS" ) == 0 )
225 strcat( &dum[0], tpars.callsign.c_str() );
226 else if ( strcmp ( tag, "@TD" ) == 0 ) {
227 if ( tpars.tdir == 1 ) {
229 strcat( &dum[0], &buf[0] );
232 char buf[] = "right";
233 strcat( &dum[0], &buf[0] );
236 else if ( strcmp ( tag, "@HE" ) == 0 ) {
238 sprintf( buf, "%i", (int)(tpars.heading) );
239 strcat( &dum[0], &buf[0] );
241 else if ( strcmp ( tag, "@VD" ) == 0 ) {
242 if ( tpars.VDir == 1 ) {
243 char buf[] = "Descent and maintain";
244 strcat( &dum[0], &buf[0] );
246 else if ( tpars.VDir == 2 ) {
247 char buf[] = "Maintain";
248 strcat( &dum[0], &buf[0] );
250 else if ( tpars.VDir == 3 ) {
251 char buf[] = "Climb and maintain";
252 strcat( &dum[0], &buf[0] );
255 else if ( strcmp ( tag, "@AL" ) == 0 ) {
257 sprintf( buf, "%i", (int)(tpars.alt) );
258 strcat( &dum[0], &buf[0] );
260 else if ( strcmp ( tag, "@MI" ) == 0 ) {
262 sprintf( buf, "%3.1f", tpars.miles );
263 strcat( &dum[0], &buf[0] );
265 else if ( strcmp ( tag, "@FR" ) == 0 ) {
267 sprintf( buf, "%6.2f", tpars.freq );
268 strcat( &dum[0], &buf[0] );
270 else if ( strcmp ( tag, "@RW" ) == 0 )
271 strcat( &dum[0], tpars.runway.c_str() );
273 cout << "Tag " << tag << " not found" << endl;
276 strcat( &dum[0], &mes[len+3] );
277 strcpy( &mes[0], &dum[0] );
280 //cout << mes << endl;
284 if ( mes != "" ) return mes;
285 else return "No transmission found";