]> git.mxchange.org Git - flightgear.git/blob - src/ATC/transmission.hxx
First draft of work by Alexander Kappes to add dynamically driven menu entries to...
[flightgear.git] / src / ATC / transmission.hxx
1 // transmission.hxx -- Transmission class\r
2 //\r
3 // Written by Alexander Kappes, started March 2002.\r
4 // Based on nav.hxx by Curtis Olson, started April 2000.\r
5 //\r
6 // Copyright (C) 2001  David C. Luff - david.luff@nottingham.ac.uk\r
7 //\r
8 // This program is free software; you can redistribute it and/or\r
9 // modify it under the terms of the GNU General Public License as\r
10 // published by the Free Software Foundation; either version 2 of the\r
11 // License, or (at your option) any later version.\r
12 //\r
13 // This program is distributed in the hope that it will be useful, but\r
14 // WITHOUT ANY WARRANTY; without even the implied warranty of\r
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
16 // General Public License for more details.\r
17 //\r
18 // You should have received a copy of the GNU General Public License\r
19 // along with this program; if not, write to the Free Software\r
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
21 \r
22 \r
23 #ifndef _FG_TRANSMISSION_HXX\r
24 #define _FG_TRANSMISSION_HXX\r
25 \r
26 #include <stdio.h>\r
27 \r
28 #include <simgear/compiler.h>\r
29 #include <simgear/math/sg_geodesy.hxx>\r
30 #include <simgear/misc/sgstream.hxx>\r
31 #include <simgear/magvar/magvar.hxx>\r
32 #include <simgear/timing/sg_time.hxx>\r
33 #include <simgear/bucket/newbucket.hxx>\r
34 \r
35 #include <Main/fg_props.hxx>\r
36 \r
37 #ifdef SG_HAVE_STD_INCLUDES\r
38 #  include <istream>\r
39 #include <iomanip>\r
40 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )\r
41 #  include <iostream.h>\r
42 #elif defined( __BORLANDC__ )\r
43 #  include <iostream>\r
44 #else\r
45 #  include <istream.h>\r
46 #include <iomanip.h>\r
47 #endif\r
48 \r
49 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )\r
50 SG_USING_STD(istream);\r
51 #endif\r
52 \r
53 SG_USING_STD(string);\r
54 \r
55 struct TransCode {\r
56   int c1;\r
57   int c2;\r
58   int c3;\r
59 };\r
60 \r
61 // TransPar - a representation of the logic of a parsed speech transmission\r
62 struct TransPar {\r
63   string  station;\r
64   string  callsign;\r
65   string  airport;\r
66   string  intention;      // landing, crossing\r
67   string  intid;          // (airport) ID for intention\r
68   bool    request;        // is the transmission a request or an answer?\r
69   int     tdir;           // turning direction: 1=left, 2=right\r
70   double  heading;\r
71   int     VDir;           // vertical direction: 1=descent, 2=maintain, 3=climb\r
72   double  alt;\r
73   double  miles;\r
74   string  runway;\r
75   double  freq;\r
76   double  time;\r
77 };\r
78 \r
79 // FGTransmission - a class to encapsulate a speech transmission\r
80 class FGTransmission {\r
81 \r
82   int       StationType;             // Type of ATC station: 1 Approach\r
83   TransCode Code;\r
84   string    TransText;\r
85   string    MenuText;\r
86 \r
87 public:\r
88 \r
89   FGTransmission(void);\r
90   ~FGTransmission(void);\r
91 \r
92   void Init();\r
93 \r
94   inline int       get_station()   const { return StationType; }\r
95   inline TransCode get_code()     { return Code; }\r
96   inline string    get_transtext() { return TransText; }\r
97   inline string    get_menutext()  { return MenuText; }\r
98 \r
99   // Return the parsed logic of the transmission  \r
100   TransPar Parse();\r
101 \r
102 private:\r
103 \r
104   friend istream& operator>> ( istream&, FGTransmission& );\r
105 \r
106 };\r
107 \r
108 \r
109 inline istream&\r
110 operator >> ( istream& in, FGTransmission& a ) {\r
111         char ch;\r
112         \r
113         static bool first_time = true;\r
114         static double julian_date = 0;\r
115         static const double MJD0    = 2415020.0;\r
116         if ( first_time ) {\r
117                 julian_date = sgTimeCurrentMJD(0, 0) + MJD0;\r
118                 first_time = false;\r
119         }\r
120         in >> a.StationType;\r
121         in >> a.Code.c1;\r
122         in >> a.Code.c2;\r
123         in >> a.Code.c3;\r
124         a.TransText = "";\r
125         in >> ch;\r
126         if ( ch != '"' ) a.TransText += ch;\r
127         while(1) {\r
128                 //in >> noskipws\r
129                 in.unsetf(ios::skipws);\r
130                 in >> ch;\r
131                 if ( ch != '"' ) a.TransText += ch;\r
132                 if((ch == '"') || (ch == 0x0A)) {\r
133                         break;\r
134                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "\r
135         }\r
136         in.setf(ios::skipws);\r
137         \r
138         a.MenuText = "";\r
139         in >> ch;\r
140         if ( ch != '"' ) a.MenuText += ch;\r
141         while(1) {\r
142                 //in >> noskipws\r
143                 in.unsetf(ios::skipws);\r
144                 in >> ch;\r
145                 if ( ch != '"' ) a.MenuText += ch;\r
146                 if((ch == '"') || (ch == 0x0A)) {\r
147                         break;\r
148                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "\r
149         }\r
150         in.setf(ios::skipws);\r
151         \r
152         //cout << "Code = " << a.Code << "   Transmission text = " << a.TransText \r
153         //     << "   Menu text = " << a.MenuText << endl;\r
154         \r
155         return in >> skipeol;\r
156 }\r
157 \r
158 \r
159 #endif // _FG_TRANSMISSION_HXX\r