├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── Resources └── plugins │ └── BasicFMC │ └── fmc.bmp ├── exports.txt ├── screenshot.png └── src ├── AirwayReader.h ├── Bitmap.cpp ├── Bitmap.h ├── Flight.h ├── FreeNavProcedureReader.cpp ├── FreeNavProcedureReader.h ├── GNSProcedureReader.cpp ├── GNSProcedureReader.h ├── InputHandler.cpp ├── InputHandler.h ├── Main.cpp ├── Main.h ├── Navigation.h ├── Page.cpp ├── Page.h ├── Page_Airport.cpp ├── Page_Airport.h ├── Page_Init.cpp ├── Page_Init.h ├── Page_Legs.cpp ├── Page_Legs.h ├── Page_Navaid.cpp ├── Page_Navaid.h ├── Page_Progress.cpp ├── Page_Progress.h ├── Page_Route.cpp ├── Page_Route.h ├── Pages.cpp ├── Pages.h ├── ProcedureReader.cpp ├── ProcedureReader.h ├── Utils.cpp └── Utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | SDK/* 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for BasicFMC (based on ExampleGauge code from Sandy Barbour 2 | 3 | BUILDDIR := ./build 4 | SRC_BASE := ./src 5 | SDK_BASE := ./SDK 6 | TARGET := BasicFMC 7 | 8 | SOURCES = \ 9 | Bitmap.cpp \ 10 | Page.cpp \ 11 | Page_Init.cpp \ 12 | Page_Legs.cpp \ 13 | Page_Airport.cpp \ 14 | Page_Progress.cpp \ 15 | Page_Route.cpp \ 16 | Page_Navaid.cpp \ 17 | Pages.cpp \ 18 | InputHandler.cpp \ 19 | Utils.cpp \ 20 | ProcedureReader.cpp \ 21 | FreeNavProcedureReader.cpp \ 22 | GNSProcedureReader.cpp \ 23 | Main.cpp 24 | 25 | LIBS = 26 | 27 | INCLUDES = \ 28 | -I$(SDK_BASE)/CHeaders/XPLM \ 29 | -I$(SDK_BASE)/CHeaders/Widgets 30 | 31 | DEFINES = -DAPL=0 -DIBM=0 -DLIN=1 -DXPLM200 -ggdb 32 | 33 | VPATH = $(SRC_BASE) 34 | CSOURCES := $(filter %.c, $(SOURCES)) 35 | CXXSOURCES := $(filter %.cpp, $(SOURCES)) 36 | 37 | CDEPS := $(patsubst %.c, $(BUILDDIR)/obj32/%.cdep, $(CSOURCES)) 38 | CXXDEPS := $(patsubst %.cpp, $(BUILDDIR)/obj32/%.cppdep, $(CXXSOURCES)) 39 | COBJECTS := $(patsubst %.c, $(BUILDDIR)/obj32/%.o, $(CSOURCES)) 40 | CXXOBJECTS := $(patsubst %.cpp, $(BUILDDIR)/obj32/%.o, $(CXXSOURCES)) 41 | ALL_DEPS := $(sort $(CDEPS) $(CXXDEPS)) 42 | ALL_OBJECTS := $(sort $(COBJECTS) $(CXXOBJECTS)) 43 | 44 | CDEPS64 := $(patsubst %.c, $(BUILDDIR)/obj64/%.cdep, $(CSOURCES)) 45 | CXXDEPS64 := $(patsubst %.cpp, $(BUILDDIR)/obj64/%.cppdep, $(CXXSOURCES)) 46 | COBJECTS64 := $(patsubst %.c, $(BUILDDIR)/obj64/%.o, $(CSOURCES)) 47 | CXXOBJECTS64 := $(patsubst %.cpp, $(BUILDDIR)/obj64/%.o, $(CXXSOURCES)) 48 | ALL_DEPS64 := $(sort $(CDEPS64) $(CXXDEPS64)) 49 | ALL_OBJECTS64 := $(sort $(COBJECTS64) $(CXXOBJECTS64)) 50 | 51 | CFLAGS := $(DEFINES) $(INCLUDES) -fPIC -fvisibility=hidden -Wall 52 | 53 | .PHONY: all clean $(TARGET) 54 | .SECONDARY: $(ALL_OBJECTS) $(ALL_OBJECTS64) $(ALL_DEPS) 55 | 56 | $(TARGET): $(BUILDDIR)/$(TARGET)/32/lin.xpl $(BUILDDIR)/$(TARGET)/64/lin.xpl 57 | 58 | $(BUILDDIR)/$(TARGET)/64/lin.xpl: $(ALL_OBJECTS64) 59 | @echo Linking $@ 60 | mkdir -p $(dir $@) 61 | gcc -m64 -static-libgcc -shared -Wl,--version-script=exports.txt -o $@ $(ALL_OBJECTS64) $(LIBS) 62 | 63 | $(BUILDDIR)/$(TARGET)/32/lin.xpl: $(ALL_OBJECTS) 64 | @echo Linking $@ 65 | mkdir -p $(dir $@) 66 | gcc -m32 -static-libgcc -shared -Wl,--version-script=exports.txt -o $@ $(ALL_OBJECTS) $(LIBS) 67 | 68 | $(BUILDDIR)/obj32/%.o : %.c 69 | mkdir -p $(dir $@) 70 | g++ $(CFLAGS) -m32 -c $< -o $@ 71 | g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cdep) $< 72 | 73 | $(BUILDDIR)/obj32/%.o : %.cpp 74 | mkdir -p $(dir $@) 75 | g++ $(CFLAGS) -m32 -c $< -o $@ 76 | g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cppdep) $< 77 | 78 | $(BUILDDIR)/obj64/%.o : %.c 79 | mkdir -p $(dir $@) 80 | g++ $(CFLAGS) -m64 -c $< -o $@ 81 | g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cdep) $< 82 | 83 | $(BUILDDIR)/obj64/%.o : %.cpp 84 | mkdir -p $(dir $@) 85 | g++ $(CFLAGS) -m64 -c $< -o $@ 86 | g++ $(CFLAGS) -MM -MT $@ -o $(@:.o=.cppdep) $< 87 | 88 | clean: 89 | @echo Cleaning out everything. 90 | rm -rf $(BUILDDIR) 91 | 92 | install: 93 | cp -r $(BUILDDIR)/$(TARGET)/32 /data/bo/X-Plane\ 10/Resources/plugins/$(TARGET)/ 94 | cp -r $(BUILDDIR)/$(TARGET)/64 /data/bo/X-Plane\ 10/Resources/plugins/$(TARGET)/ 95 | 96 | # Include any dependency turds, but don't error out if they don't exist. 97 | # On the first build, every .c is dirty anyway. On future builds, if the 98 | # .c changes, it is rebuilt (as is its dep) so who cares if dependencies 99 | # are stale. If the .c is the same but a header has changed, this 100 | # declares the header to be changed. If a primary header includes a 101 | # utility header and the primary header is changed, the dependency 102 | # needs a rebuild because EVERY header is included. And if the secondary 103 | # header is changed, the primary header had it before (and is unchanged) 104 | # so that is in the dependency file too. 105 | -include $(ALL_DEPS) 106 | -include $(ALL_DEPS64) 107 | 108 | 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BasicFMC 2 | ======== 3 | 4 | What is BasicFMC? 5 | ----------------- 6 | 7 | BasicFMC is a very very simple FMC for X-Plane. Since the only 8 | Open-Source FMC available for X-Plane used to be vasFMC there was 9 | no real starting point if one wanted to create their own FMC, the 10 | reasons for that is: 11 | 12 | * vasFMC was never written for X-Plane but written to be a standalone 13 | FMC for particular MSFS. This means a lot of code is redudant for X-Plane 14 | users, and it is hard to understand the complete structure 15 | * vasFMC is no longer maintained which means no changes from upstream. 16 | 17 | The reason why I created BasicFMC was to get a minimal FMC and provide 18 | a starting point for aircraft designers. I decided to publish it was 19 | GPLv3 to ensure these authors would also publish the source code. 20 | 21 | BasicFMC is unfortunately not maintained anymore by me, since I have 22 | sort of lost my interest in the project, but the code will remain 23 | in this repository. 24 | 25 | How to compile? 26 | --------------- 27 | 28 | You need the X-Plane SDK. Download from 29 | [here](http://www.xsquawkbox.net/xpsdk/mediawiki/Main_Page) and place 30 | it within the repository. 31 | 32 | You will need the GCC compiler (with C++ support to compile) and also 33 | various development packages. Here is what you need for openSUSE 34 | 35 | # zypper in gcc gcc-c++ gcc-32bit gcc-c++-32bit 36 | # zypper in glibc-devel glibc-devel-32bit 37 | # zypper in Mesa-devel freeglut-devel 38 | 39 | Then just compile 40 | 41 | $ make 42 | 43 | The X-Plane plugins are placed in `build/BasicFMC/32/lin.xpl` and 44 | `build/BasicFMC/64/lin.xpl`. Copy the `build/BasicFMC` folder to 45 | `X-Plane/Resources/plugins/BasicFMC` and also copy over the fmc.bmp to 46 | that folder (the file is placed within this repository). 47 | 48 | How does it look? 49 | ----------------- 50 | 51 | ![screenshot](screenshot.png) 52 | 53 | Author 54 | ------ 55 | 56 | * Bo Simonsen 57 | -------------------------------------------------------------------------------- /Resources/plugins/BasicFMC/fmc.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosim/BasicFMC/0da9ce12d4a7a1880eea60f1eac0b60033dd3790/Resources/plugins/BasicFMC/fmc.bmp -------------------------------------------------------------------------------- /exports.txt: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | _init; 4 | _fini; 5 | XPluginStart; 6 | XPluginStop; 7 | XPluginEnable; 8 | XPluginDisable; 9 | XPluginReceiveMessage; 10 | local: 11 | *; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bosim/BasicFMC/0da9ce12d4a7a1880eea60f1eac0b60033dd3790/screenshot.png -------------------------------------------------------------------------------- /src/AirwayReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef AIRWAYREADER_H 20 | #define AIRWAYREADER_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class AirwaySegment { 34 | public: 35 | std::string source; 36 | float source_lon; 37 | float source_lat; 38 | std::string dest; 39 | float dest_lon; 40 | float dest_lat; 41 | bool upper; 42 | int lower_level; 43 | int higher_level; 44 | std::string name; 45 | 46 | AirwaySegment() { } 47 | AirwaySegment(std::string source, float source_lon, float source_lat, std::string dest, float dest_lon, float dest_lat, 48 | bool upper, int lower_level, int higher_level, std::string name) : 49 | source(source), source_lon(source_lon), source_lat(source_lat), dest(dest), dest_lon(dest_lon), dest_lat(dest_lat), upper(upper), 50 | lower_level(lower_level), higher_level(higher_level), name(name) { 51 | 52 | } 53 | 54 | void dump() { 55 | std::cout << "Source " << this->source << "(" << this->source_lon << "," << this->source_lat << ")"; 56 | std::cout << "Dest " << this->dest << "(" << this->dest_lon << "," << this->dest_lat << ")"; 57 | std::cout << "Upper " << this->upper << " " << this->lower_level << " " << this->higher_level << " " << this->name << std::endl; 58 | } 59 | }; 60 | 61 | class AirwayReader { 62 | public: 63 | AirwayReader(std::string Filename) : Filename(Filename) {} 64 | 65 | void FindSegment(std::string airway, std::string source, std::string dest, std::vector& result) { 66 | std::ifstream filehandle(this->Filename.c_str()); 67 | std::string line; 68 | std::vector temp_result; 69 | 70 | if(filehandle.is_open()) { 71 | while(getline(filehandle, line)) { 72 | 73 | if(line.find(airway) == std::string::npos) 74 | continue; 75 | 76 | std::vector tokens; 77 | std::stringstream ss(line); 78 | std::string buf; 79 | 80 | while (ss >> buf) { 81 | if(buf != "") { 82 | tokens.push_back(buf); 83 | } 84 | } 85 | 86 | if(tokens.size() != 10) 87 | continue; 88 | 89 | AirwaySegment segment = AirwaySegment(tokens[0], atof(tokens[2].c_str()), atof(tokens[1].c_str()), 90 | tokens[3], atof(tokens[5].c_str()), atof(tokens[4].c_str()), 91 | tokens[6] == "1" ? true : false, atoi(tokens[7].c_str()), 92 | atoi(tokens[8].c_str()), tokens[9]); 93 | if(segment.name == airway) { 94 | temp_result.push_back(segment); 95 | } 96 | } 97 | } 98 | 99 | std::vector > paths; 100 | for(size_t i=0; i < temp_result.size(); ++i) { 101 | if(temp_result[i].source == source) { 102 | paths.push_back(std::pair(temp_result[i].dest, i)); 103 | } 104 | else if(temp_result[i].dest == source) { 105 | paths.push_back(std::pair(temp_result[i].source, i)); 106 | } 107 | } 108 | 109 | std::vector found_result; 110 | std::set visited; 111 | 112 | for(size_t i=0; i < paths.size(); ++i) { 113 | found_result.clear(); 114 | visited.clear(); 115 | 116 | std::string tmp = paths[i].first; 117 | found_result.push_back(temp_result[paths[i].second]); 118 | visited.insert(source); 119 | bool found = true; 120 | 121 | while(found) { 122 | found = false; 123 | for(size_t j=0; j < temp_result.size(); j++) { 124 | if(temp_result[j].source == tmp && visited.find(temp_result[j].dest) == visited.end()) { 125 | visited.insert(tmp); 126 | tmp = temp_result[j].dest; 127 | found_result.push_back(temp_result[j]); 128 | found = true; 129 | } 130 | else if(temp_result[j].dest == tmp && visited.find(temp_result[j].source) == visited.end()) { 131 | visited.insert(tmp); 132 | tmp = temp_result[j].source; 133 | found_result.push_back(temp_result[j]); 134 | found = true; 135 | } 136 | } 137 | } 138 | 139 | size_t q; 140 | 141 | for(q=0; q < found_result.size(); q++) { 142 | if((q == 0 && found_result[q].source != source) || 143 | (q > 0 && found_result[q-1].dest != found_result[q].source)) { 144 | std::swap(found_result[q].source, found_result[q].dest); 145 | std::swap(found_result[q].source_lon, found_result[q].dest_lon); 146 | std::swap(found_result[q].source_lat, found_result[q].dest_lat); 147 | } 148 | if(found_result[q].dest == dest) { 149 | break; 150 | } 151 | } 152 | 153 | NavAidInfo navaid; 154 | if(q < found_result.size()) { 155 | for(size_t z = 0; z < q + 1; z++) { 156 | if(z == q) { 157 | navaid = Navigation::FindNavAidIdLonLat(found_result[z].source, found_result[z].source_lon, found_result[z].source_lat); 158 | navaid.fmc_airway = airway; 159 | result.push_back(navaid); 160 | navaid = Navigation::FindNavAidIdLonLat(found_result[z].dest, found_result[z].dest_lon, found_result[z].dest_lat); 161 | navaid.fmc_airway = airway; 162 | result.push_back(navaid); 163 | } 164 | else { 165 | navaid = Navigation::FindNavAidIdLonLat(found_result[z].source, found_result[z].source_lon, found_result[z].source_lat); 166 | navaid.fmc_airway = airway; 167 | result.push_back(navaid); 168 | } 169 | } 170 | break; 171 | } 172 | } 173 | } 174 | private: 175 | std::string Filename; 176 | }; 177 | 178 | 179 | #endif 180 | 181 | -------------------------------------------------------------------------------- /src/Bitmap.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008, Sandy Barbour and Ben Supnik 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | * Neither the names of the authors nor that of X-Plane or Laminar Research 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission from the authors or 16 | Laminar Research, respectively. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #include "XPLMDefs.h" 37 | #include "XPLMDisplay.h" 38 | #include "XPLMDataAccess.h" 39 | #include "XPLMGraphics.h" 40 | #include "XPLMUtilities.h" 41 | 42 | #include "Bitmap.h" 43 | #include "Utils.h" 44 | 45 | extern XPLMTextureID Texture[MAX_TEXTURES]; 46 | 47 | /// Loads one texture 48 | int LoadGLTexture(std::string FileName, int TextureId) 49 | { 50 | int Status=FALSE; 51 | std::string TextureFileName = GetPluginDir() + FileName; 52 | 53 | void *pImageData = 0; 54 | int sWidth, sHeight; 55 | IMAGEDATA sImageData; 56 | /// Get the bitmap from the file 57 | if (BitmapLoader(TextureFileName.c_str(), &sImageData)) { 58 | Status=TRUE; 59 | 60 | SwapRedBlue(&sImageData); 61 | pImageData = sImageData.pData; 62 | 63 | /// Do the opengl stuff using XPLM functions for a friendly Xplane existence. 64 | sWidth=sImageData.Width; 65 | sHeight=sImageData.Height; 66 | XPLMGenerateTextureNumbers(&Texture[TextureId], 1); 67 | XPLMBindTexture2d(Texture[TextureId], 0); 68 | gluBuild2DMipmaps(GL_TEXTURE_2D, 3, sWidth, sHeight, GL_RGB, GL_UNSIGNED_BYTE, pImageData); 69 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 70 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 71 | } 72 | if (pImageData != NULL) 73 | free(pImageData); 74 | 75 | return Status; 76 | } 77 | 78 | /// Swap the red and blue pixels. 79 | void SwapRedBlue(IMAGEDATA *ImageData) { 80 | unsigned char* srcPixel; 81 | int x,y; 82 | unsigned char sTemp; 83 | 84 | /// Does not support 4 channels. 85 | if (ImageData->Channels == 4) 86 | return; 87 | 88 | /// Do the swap 89 | srcPixel = ImageData->pData; 90 | for (y = 0; y < ImageData->Height; ++y) { 91 | for (x = 0; x < ImageData->Width; ++x) { 92 | sTemp = srcPixel[0]; 93 | srcPixel[0] = srcPixel[2]; 94 | srcPixel[2] = sTemp; 95 | 96 | srcPixel += 3; 97 | if (x == (ImageData->Width - 1)) 98 | srcPixel += ImageData->Padding; 99 | } 100 | } 101 | } 102 | 103 | 104 | /// Generic bitmap loader to handle all platforms 105 | int BitmapLoader(const char * FilePath, IMAGEDATA * ImageData) { 106 | BMPFILEHEADER Header; 107 | BMPINFOHEADER ImageInfo; 108 | int Padding; 109 | FILE * BitmapFile = NULL; 110 | int RetCode = 0; 111 | 112 | ImageData->pData = NULL; 113 | 114 | BitmapFile = fopen(FilePath, "rb"); 115 | if (BitmapFile != NULL) { 116 | if (fread(&Header, sizeof(Header), 1, BitmapFile) == 1) { 117 | if (fread(&ImageInfo, sizeof(ImageInfo), 1, BitmapFile) == 1) { 118 | 119 | /// Make sure that it is a bitmap. 120 | if (((Header.bfType & 0xff) == 'B') && 121 | (((Header.bfType >> 8) & 0xff) == 'M') && 122 | (ImageInfo.biBitCount == 24) && 123 | (ImageInfo.biWidth > 0) && 124 | (ImageInfo.biHeight > 0)) { 125 | /// Sandy Barbour - I have found that "Header.bfSize" does not always agree 126 | /// with the actual file size and can sometimes be "ImageInfo.biSize" smaller. 127 | /// So add it in for good measure 128 | if ((Header.bfSize + ImageInfo.biSize - Header.bfOffBits) >= (ImageInfo.biWidth * ImageInfo.biHeight * 3)) { 129 | Padding = (ImageInfo.biWidth * 3 + 3) & ~3; 130 | Padding -= ImageInfo.biWidth * 3; 131 | ImageData->Width = ImageInfo.biWidth; 132 | ImageData->Height = ImageInfo.biHeight; 133 | ImageData->Padding = Padding; 134 | 135 | /// Allocate memory for the actual image. 136 | ImageData->Channels = 3; 137 | ImageData->pData = (unsigned char *) malloc(ImageInfo.biWidth * ImageInfo.biHeight * ImageData->Channels + ImageInfo.biHeight * Padding); 138 | 139 | if (ImageData->pData != NULL) { 140 | /// Get the actual image. 141 | if (fread(ImageData->pData, ImageInfo.biWidth * ImageInfo.biHeight * ImageData->Channels + ImageInfo.biHeight * Padding, 1, BitmapFile) == 1) { 142 | RetCode = 1; 143 | } 144 | } 145 | } 146 | } 147 | } 148 | } 149 | } 150 | if (BitmapFile != NULL) 151 | fclose(BitmapFile); 152 | return RetCode; 153 | } 154 | -------------------------------------------------------------------------------- /src/Bitmap.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008, Sandy Barbour and Ben Supnik 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | * Neither the names of the authors nor that of X-Plane or Laminar Research 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission from the authors or 16 | Laminar Research, respectively. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /// Handle cross platform differences 31 | #if IBM 32 | #include 33 | #include 34 | #elif LIN 35 | #define TRUE 1 36 | #define FALSE 0 37 | #include 38 | #include 39 | #else 40 | #define TRUE 1 41 | #define FALSE 0 42 | #if __GNUC__ 43 | #include 44 | #include 45 | #else 46 | #include 47 | #include 48 | #endif 49 | #include 50 | #include 51 | #endif 52 | 53 | /// Texture stuff 54 | #define MAX_TEXTURES 1 55 | #define FMC_FILENAME "fmc.bmp" 56 | #define FMC_TEXTURE 0 57 | 58 | 59 | /// Cross Platform Bitmap functions and bitmap data structures - Sandy Barbour 2003 60 | /// These need to be aligned 61 | 62 | #pragma pack(push, ident, 2) 63 | typedef struct tagBMPFILEHEADER 64 | { 65 | short bfType; 66 | int bfSize; 67 | short bfReserved1; 68 | short bfReserved2; 69 | int bfOffBits; 70 | } BMPFILEHEADER; 71 | 72 | typedef struct tagBMPINFOHEADER 73 | { 74 | int biSize; 75 | int biWidth; 76 | int biHeight; 77 | short biPlanes; 78 | short biBitCount; 79 | int biCompression; 80 | int biSizeImage; 81 | int biXPelsPerMeter; 82 | int biYPelsPerMeter; 83 | int biClrUsed; 84 | int biClrImportant; 85 | } BMPINFOHEADER; 86 | 87 | typedef struct tagIMAGEDATA 88 | { 89 | unsigned char * pData; 90 | int Width; 91 | int Height; 92 | int Padding; 93 | short Channels; 94 | } IMAGEDATA; 95 | #pragma pack(pop, ident) 96 | 97 | int BitmapLoader(const char *FilePath, IMAGEDATA *ImageData); 98 | void SwapEndian(short *Data); 99 | void SwapEndian(int *Data); 100 | void SwapRedBlue(IMAGEDATA *ImageData); 101 | int LoadGLTexture(std::string, int TextureId); 102 | 103 | #if APL && __MACH__ 104 | int ConvertPath(const char * inPath, char * outPath, int outPathMaxLen); 105 | #endif 106 | -------------------------------------------------------------------------------- /src/Flight.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef FLIGHT_H 20 | #define FLIGHT_H 21 | 22 | #include "Navigation.h" 23 | #include "ProcedureReader.h" 24 | 25 | #include "XPLMDataAccess.h" 26 | 27 | #include 28 | 29 | class Flight { 30 | 31 | public: 32 | NavAidInfo dep_airport; 33 | NavAidInfo dest_airport; 34 | std::string flightno; 35 | std::vector flightplan; 36 | std::vector sids; 37 | std::vector sids_runways; 38 | std::vector stars; 39 | std::vector stars_runways; 40 | 41 | /* Temp variables for passing data between legs/rte page and 42 | navaid */ 43 | std::vector temp_navaids; 44 | unsigned int temp_navaid_insert; 45 | std::string temp_navaid_came_from; 46 | 47 | void SetDepAirport(std::string Airport) { 48 | this->dep_airport = Navigation::FindAirport(Airport); 49 | this->sids.clear(); 50 | this->sids_runways.clear(); 51 | this->procedure_reader.ReadSidFile(Airport, this->sids); 52 | this->procedure_reader.GetRunways(this->sids, this->sids_runways); 53 | } 54 | 55 | void SetDestAirport(std::string Airport) { 56 | this->dest_airport = Navigation::FindAirport(Airport); 57 | this->stars.clear(); 58 | this->stars_runways.clear(); 59 | this->procedure_reader.ReadStarFile(Airport, this->stars); 60 | this->procedure_reader.GetRunways(this->stars, this->stars_runways); 61 | } 62 | 63 | void SyncToXPFMC() { 64 | size_t i; 65 | 66 | for(i=0; i < this->flightplan.size(); i++) { 67 | if(this->flightplan[i].type >= 0) { 68 | XPLMSetFMSEntryInfo(i+1, this->flightplan[i].ref, 69 | this->flightplan[i].ComputedAltitude()); 70 | } else { 71 | XPLMSetFMSEntryLatLon(i+1, this->flightplan[i].lat, 72 | this->flightplan[i].lon, 73 | this->flightplan[i].ComputedAltitude()); 74 | } 75 | } 76 | for(; i < 99; i++) { 77 | XPLMClearFMSEntry(i+1); 78 | } 79 | 80 | XPLMSetDestinationFMSEntry(1); 81 | 82 | } 83 | 84 | void CalcDistances() { 85 | XPLMDataRef lat_ref = XPLMFindDataRef("sim/flightmodel/position/latitude"); 86 | XPLMDataRef lon_ref = XPLMFindDataRef("sim/flightmodel/position/longitude"); 87 | 88 | float lat = XPLMGetDataf(lat_ref); 89 | float lon = XPLMGetDataf(lon_ref); 90 | 91 | for(size_t i=0; i < this->flightplan.size(); i++) { 92 | if(i==0) { 93 | this->flightplan[0].fmc_distance = distance(lat, lon, this->flightplan[0].lat, this->flightplan[0].lon); 94 | } 95 | else { 96 | this->flightplan[i].fmc_distance = this->flightplan[i-1].fmc_distance; 97 | this->flightplan[i].fmc_distance += distance(this->flightplan[i-1].lat, 98 | this->flightplan[i-1].lon, 99 | this->flightplan[i].lat, 100 | this->flightplan[i].lon); 101 | } 102 | } 103 | } 104 | private: 105 | ProcedureReader procedure_reader; 106 | }; 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /src/FreeNavProcedureReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "FreeNavProcedureReader.h" 20 | 21 | Procedure FreeNavProcedureReader::ReadProcedureLine(std::vector const& elements, bool star) { 22 | Procedure procedure; 23 | 24 | procedure.runway = elements[0]; 25 | procedure.name = elements[1]; 26 | procedure.star = star; 27 | 28 | return procedure; 29 | } 30 | 31 | void FreeNavProcedureReader::ReadSidWaypoint(std::vector const& elements, 32 | Procedure& procedure, size_t offset) { 33 | ProcedureWaypoint waypoint; 34 | 35 | if(offset + 6 < elements.size()) { 36 | waypoint.id = elements[offset+4]; 37 | waypoint.lat = atof(elements[offset+5].c_str()); 38 | waypoint.lon = atof(elements[offset+6].c_str()); 39 | waypoint.altitude = 0; 40 | waypoint.speed = 0; 41 | 42 | procedure.waypoints.push_back(waypoint); 43 | } 44 | } 45 | 46 | void FreeNavProcedureReader::ReadSidFile(std::string Filename, std::vector& procedures) { 47 | std::ifstream filehandle(Filename.c_str()); 48 | std::string line; 49 | 50 | if(filehandle.is_open()) { 51 | while(getline(filehandle, line)) { 52 | std::vector elements; 53 | SplitLine(line, elements, ','); 54 | 55 | if(elements.size() > 1) { 56 | 57 | Procedure procedure = this->ReadProcedureLine(elements, false); 58 | 59 | for(size_t i=10; i < elements.size(); i = i+7) { 60 | this->ReadSidWaypoint(elements, procedure, i); 61 | } 62 | 63 | procedures.push_back(procedure); 64 | } 65 | } 66 | } 67 | } 68 | 69 | void FreeNavProcedureReader::ReadStarWaypoint(std::vector const& elements, 70 | Procedure& procedure, size_t offset) { 71 | ProcedureWaypoint waypoint; 72 | 73 | if(offset + 9 < elements.size()) { 74 | 75 | waypoint.id = elements[offset+4]; 76 | waypoint.lat = atof(elements[offset+5].c_str()); 77 | waypoint.lon = atof(elements[offset+6].c_str()); 78 | waypoint.altitude = atoi(elements[offset+8].c_str()); 79 | waypoint.speed = atoi(elements[offset+9].c_str()); 80 | 81 | procedure.waypoints.push_back(waypoint); 82 | } 83 | } 84 | 85 | void FreeNavProcedureReader::ReadStarFile(std::string Filename, std::vector& procedures) { 86 | std::ifstream filehandle(Filename.c_str()); 87 | std::string line; 88 | 89 | if(filehandle.is_open()) { 90 | while(getline(filehandle, line)) { 91 | std::vector elements; 92 | SplitLine(line, elements, ','); 93 | 94 | if(elements.size() > 1) { 95 | 96 | Procedure procedure = this->ReadProcedureLine(elements, true); 97 | 98 | for(size_t i=4; i < elements.size(); i = i+15) { 99 | this->ReadStarWaypoint(elements, procedure, i); 100 | } 101 | 102 | procedures.push_back(procedure); 103 | } 104 | } 105 | } 106 | } 107 | 108 | -------------------------------------------------------------------------------- /src/FreeNavProcedureReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef FREENAVPROCEDUREREADER_H 20 | #define FREENAVPROCEDUREREADER_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "ProcedureReader.h" 30 | 31 | #include "Utils.h" 32 | 33 | class Procedure; 34 | 35 | class FreeNavProcedureReader { 36 | public: 37 | Procedure ReadProcedureLine(std::vector const& elements, bool star); 38 | 39 | void ReadSidWaypoint(std::vector const& elements, 40 | Procedure& procedure, size_t offset); 41 | void ReadSidFile(std::string Filename, std::vector& procedures); 42 | 43 | void ReadStarWaypoint(std::vector const& elements, 44 | Procedure& procedure, size_t offset); 45 | void ReadStarFile(std::string Filename, std::vector& procedures); 46 | }; 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /src/GNSProcedureReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "GNSProcedureReader.h" 20 | 21 | void GNSProcedureReader::ReadProcedures(std::string Filename, std::vector& procedures, bool star) { 22 | std::ifstream filehandle(Filename.c_str()); 23 | std::string line; 24 | std::vector elements; 25 | Procedure procedure; 26 | ProcedureWaypoint waypoint; 27 | bool got_procedure = false; 28 | 29 | if(filehandle.is_open()) { 30 | while(getline(filehandle, line)) { 31 | elements.clear(); 32 | 33 | SplitLine(line, elements, ','); 34 | 35 | if(elements.size() > 1) { 36 | if((!star && elements[0] == "SID") || (star && elements[0] == "STAR")) { 37 | procedure = Procedure(); 38 | 39 | procedure.name = elements[1]; 40 | procedure.runway = elements[2]; 41 | procedure.star = elements[0] == "STAR"; 42 | 43 | procedures.push_back(procedure); 44 | 45 | got_procedure = true; 46 | } 47 | else if(got_procedure && procedures.size() > 0 && 48 | (elements[0] == "DF" || elements[0] == "TF" || 49 | elements[0] == "CF" || elements[0] == "IF")) { 50 | waypoint = ProcedureWaypoint(); 51 | 52 | waypoint.id = elements[1]; 53 | waypoint.lat = atof(elements[2].c_str()); 54 | waypoint.lon = atof(elements[3].c_str()); 55 | waypoint.speed = 0; 56 | waypoint.altitude = 0; 57 | 58 | procedures[procedures.size()-1].waypoints.push_back(waypoint); 59 | } 60 | } 61 | else { 62 | got_procedure = false; 63 | } 64 | } 65 | } 66 | } 67 | 68 | void GNSProcedureReader::ReadSidFile(std::string Filename, std::vector& procedures) { 69 | this->ReadProcedures(Filename, procedures, false); 70 | } 71 | 72 | void GNSProcedureReader::ReadStarFile(std::string Filename, std::vector& procedures) { 73 | this->ReadProcedures(Filename, procedures, true); 74 | } 75 | -------------------------------------------------------------------------------- /src/GNSProcedureReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef GNSPROCEDUREREADER_H 20 | #define GNSPROCEDUREREADER_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "ProcedureReader.h" 30 | 31 | #include "Utils.h" 32 | 33 | class Procedure; 34 | 35 | class GNSProcedureReader { 36 | public: 37 | void ReadProcedures(std::string Filename, std::vector& procedures, bool star); 38 | void ReadSidFile(std::string Filename, std::vector& procedures); 39 | void ReadStarFile(std::string Filename, std::vector& procedures); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/InputHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "XPLMDefs.h" 20 | #include "XPLMDisplay.h" 21 | #include "XPLMDataAccess.h" 22 | #include "XPLMGraphics.h" 23 | #include "XPLMUtilities.h" 24 | 25 | #include "Utils.h" 26 | #include "Pages.h" 27 | #include "Page.h" 28 | #include "InputHandler.h" 29 | 30 | extern Pages* pages; 31 | extern Flight* flight; 32 | extern XPLMWindowID FMCWindow; 33 | extern bool FMCKeyboardInput; 34 | 35 | void ToggleKeyboard() { 36 | 37 | FMCKeyboardInput = !FMCKeyboardInput; 38 | 39 | if(FMCKeyboardInput) { 40 | XPLMBringWindowToFront(FMCWindow); 41 | XPLMTakeKeyboardFocus(FMCWindow); 42 | } 43 | else { 44 | XPLMTakeKeyboardFocus(0); 45 | } 46 | } 47 | 48 | void InputHandler(int &dX, int &dY) { 49 | Page* page = pages->CurrentPage(); 50 | 51 | if(CoordInRect(dX, dY, 152, -337, 174, -359)) { 52 | page->HandleInput('A'); 53 | } 54 | else if(CoordInRect(dX, dY, 187, -337, 209, -359)) { 55 | page->HandleInput('B'); 56 | } 57 | else if(CoordInRect(dX, dY, 221, -337, 245, -359)) { 58 | page->HandleInput('C'); 59 | } 60 | else if(CoordInRect(dX, dY, 257, -337, 280, -359)) { 61 | page->HandleInput('D'); 62 | } 63 | else if(CoordInRect(dX, dY, 292, -337, 317, -359)) { 64 | page->HandleInput('E'); 65 | } 66 | else if(CoordInRect(dX, dY, 152, -372, 174, -392)) { 67 | page->HandleInput('F'); 68 | } 69 | else if(CoordInRect(dX, dY, 187, -372, 209, -392)) { 70 | page->HandleInput('G'); 71 | } 72 | else if(CoordInRect(dX, dY, 221, -372, 245, -392)) { 73 | page->HandleInput('H'); 74 | } 75 | else if(CoordInRect(dX, dY, 257, -372, 280, -392)) { 76 | page->HandleInput('I'); 77 | } 78 | else if(CoordInRect(dX, dY, 292, -372, 317, -392)) { 79 | page->HandleInput('J'); 80 | } 81 | else if(CoordInRect(dX, dY, 152, -407, 174, -428)) { 82 | page->HandleInput('K'); 83 | } 84 | else if(CoordInRect(dX, dY, 187, -407, 209, -428)) { 85 | page->HandleInput('L'); 86 | } 87 | else if(CoordInRect(dX, dY, 221, -407, 245, -428)) { 88 | page->HandleInput('M'); 89 | } 90 | else if(CoordInRect(dX, dY, 257, -407, 280, -428)) { 91 | page->HandleInput('N'); 92 | } 93 | else if(CoordInRect(dX, dY, 292, -407, 317, -428)) { 94 | page->HandleInput('O'); 95 | } 96 | else if(CoordInRect(dX, dY, 152, -441, 174, -463)) { 97 | page->HandleInput('P'); 98 | } 99 | else if(CoordInRect(dX, dY, 187, -441, 209, -463)) { 100 | page->HandleInput('Q'); 101 | } 102 | else if(CoordInRect(dX, dY, 221, -441, 245, -463)) { 103 | page->HandleInput('R'); 104 | } 105 | else if(CoordInRect(dX, dY, 257, -441, 280, -463)) { 106 | page->HandleInput('S'); 107 | } 108 | else if(CoordInRect(dX, dY, 292, -441, 317, -463)) { 109 | page->HandleInput('T'); 110 | } 111 | else if(CoordInRect(dX, dY, 152, -476, 174, -498)) { 112 | page->HandleInput('U'); 113 | } 114 | else if(CoordInRect(dX, dY, 187, -476, 209, -498)) { 115 | page->HandleInput('V'); 116 | } 117 | else if(CoordInRect(dX, dY, 221, -476, 245, -498)) { 118 | page->HandleInput('W'); 119 | } 120 | else if(CoordInRect(dX, dY, 257, -476, 280, -498)) { 121 | page->HandleInput('X'); 122 | } 123 | else if(CoordInRect(dX, dY, 292, -476, 317, -498)) { 124 | page->HandleInput('Y'); 125 | } 126 | else if(CoordInRect(dX, dY, 152, -511, 174, -532)) { 127 | page->HandleInput('Z'); 128 | } 129 | else if(CoordInRect(dX, dY, 187, -511, 209, -532)) { 130 | page->HandleInput(' '); 131 | } 132 | else if(CoordInRect(dX, dY, 221, -511, 245, -532)) { 133 | page->HandleDelete(); 134 | } 135 | else if(CoordInRect(dX, dY, 257, -511, 280, -532)) { 136 | page->HandleInput('/'); 137 | } 138 | else if(CoordInRect(dX, dY, 292, -511, 317, -532)) { 139 | // TODO handle clear 140 | } 141 | else if(CoordInRect(dX, dY, 43, -403, 71, -428)) { 142 | page->HandleInput('1'); 143 | } 144 | else if(CoordInRect(dX, dY, 79, -403, 107, -428)) { 145 | page->HandleInput('2'); 146 | } 147 | else if(CoordInRect(dX, dY, 112, -403, 141, -428)) { 148 | page->HandleInput('3'); 149 | } 150 | else if(CoordInRect(dX, dY, 43, -439, 71, -463)) { 151 | page->HandleInput('4'); 152 | } 153 | else if(CoordInRect(dX, dY, 79, -439, 107, -463)) { 154 | page->HandleInput('5'); 155 | } 156 | else if(CoordInRect(dX, dY, 112, -439, 141, -463)) { 157 | page->HandleInput('6'); 158 | } 159 | else if(CoordInRect(dX, dY, 43, -474, 71, -499)) { 160 | page->HandleInput('7'); 161 | } 162 | else if(CoordInRect(dX, dY, 79, -474, 107, -499)) { 163 | page->HandleInput('8'); 164 | } 165 | else if(CoordInRect(dX, dY, 112, -474, 141, -499)) { 166 | page->HandleInput('9'); 167 | } 168 | else if(CoordInRect(dX, dY, 43, -509, 71, -533)) { 169 | page->HandleInput('.'); 170 | } 171 | else if(CoordInRect(dX, dY, 79, -509, 107, -533)) { 172 | page->HandleInput('0'); 173 | } 174 | else if(CoordInRect(dX, dY, 112, -509, 141, -533)) { 175 | page->HandleInput('+'); 176 | } 177 | else if(CoordInRect(dX, dY, 5, -64, 25, -77)) { 178 | page->HandleSK(LSK1); 179 | } 180 | else if(CoordInRect(dX, dY, 5, -92, 25, -107)) { 181 | page->HandleSK(LSK2); 182 | } 183 | else if(CoordInRect(dX, dY, 5, -120, 25, -136)) { 184 | page->HandleSK(LSK3); 185 | } 186 | else if(CoordInRect(dX, dY, 5, -149, 25, -165)) { 187 | page->HandleSK(LSK4); 188 | } 189 | else if(CoordInRect(dX, dY, 5, -178, 25, -193)) { 190 | page->HandleSK(LSK5); 191 | } 192 | else if(CoordInRect(dX, dY, 5, -205, 25, -223)) { 193 | page->HandleSK(LSK6); 194 | } 195 | else if(CoordInRect(dX, dY, 335, -64, 356, -77)) { 196 | page->HandleSK(RSK1); 197 | } 198 | else if(CoordInRect(dX, dY, 335, -92, 356, -107)) { 199 | page->HandleSK(RSK2); 200 | } 201 | else if(CoordInRect(dX, dY, 335, -120, 356, -136)) { 202 | page->HandleSK(RSK3); 203 | } 204 | else if(CoordInRect(dX, dY, 335, -149, 356, -165)) { 205 | page->HandleSK(RSK4); 206 | } 207 | else if(CoordInRect(dX, dY, 335, -178, 356, -193)) { 208 | page->HandleSK(RSK5); 209 | } 210 | else if(CoordInRect(dX, dY, 335, -205, 356, -223)) { 211 | page->HandleSK(RSK6); 212 | } 213 | else if(CoordInRect(dX, dY, 47, -263, 81, -286)) { 214 | pages->SwitchPage("init"); 215 | } 216 | else if(CoordInRect(dX, dY, 92, -299, 126, -321)) { 217 | pages->SwitchPage("legs"); 218 | } 219 | else if(CoordInRect(dX, dY, 139, -264, 171, -286)) { 220 | pages->SwitchPage("airport"); 221 | } 222 | else if(CoordInRect(dX, dY, 229, -297, 263, -321)) { 223 | pages->SwitchPage("progress"); 224 | } 225 | else if(CoordInRect(dX, dY, 92, -264, 126, -286)) { 226 | pages->SwitchPage("route"); 227 | } 228 | else if(CoordInRect(dX, dY, 47, -369, 80, -390)) { 229 | page->HandleSK(BUTTON_UP); 230 | } 231 | else if(CoordInRect(dX, dY, 93, -370, 126, -391)) { 232 | page->HandleSK(BUTTON_DOWN); 233 | } 234 | else if(CoordInRect(dX, dY, 0, -18, 24, -44)) { 235 | ToggleKeyboard(); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /src/InputHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef INPUTHANDLER_H 20 | #define INPUTHANDLER_H 21 | 22 | void InputHandler(int &dX, int &dY); 23 | void ToggleKeyboard(); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #if IBM 20 | #include 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "XPLMDefs.h" 32 | #include "XPLMDisplay.h" 33 | #include "XPLMDataAccess.h" 34 | #include "XPLMGraphics.h" 35 | #include "XPLMUtilities.h" 36 | #include "XPLMPlugin.h" 37 | #include "XPLMProcessing.h" 38 | 39 | #include "Bitmap.h" 40 | #include "Pages.h" 41 | #include "Page.h" 42 | #include "Page_Init.h" 43 | #include "Page_Legs.h" 44 | #include "Page_Airport.h" 45 | #include "Page_Progress.h" 46 | #include "Page_Route.h" 47 | #include "Page_Navaid.h" 48 | #include "Flight.h" 49 | #include "Main.h" 50 | #include "InputHandler.h" 51 | #include "Utils.h" 52 | 53 | XPLMWindowID FMCWindow = NULL; 54 | XPLMHotKeyID FMCToggleHotKey = NULL; 55 | 56 | bool FMCDisplayWindow = false; 57 | bool FMCKeyboardInput = false; 58 | 59 | XPLMTextureID Texture[MAX_TEXTURES]; 60 | 61 | Pages* pages; 62 | Flight* flight; 63 | 64 | /* Required code for compiling on Windows, thanks to Pikitanga / Duncan */ 65 | #if IBM 66 | BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { 67 | switch (ul_reason_for_call) { 68 | case DLL_PROCESS_ATTACH: 69 | case DLL_THREAD_ATTACH: 70 | case DLL_THREAD_DETACH: 71 | case DLL_PROCESS_DETACH: 72 | break; 73 | } 74 | 75 | return TRUE; 76 | } 77 | #endif 78 | 79 | PLUGIN_API int XPluginStart(char * outName, char * outSig, char * outDesc) { 80 | int x = 0; int y = 720; 81 | int width = 360; int height = 557; 82 | 83 | Page * page; 84 | 85 | XPLMEnableFeature("XPLM_USE_NATIVE_PATHS",1); 86 | 87 | strcpy(outName, "BasicFMC"); 88 | strcpy(outSig, "BasicFMC"); 89 | strcpy(outDesc, "BasicFMC by Bo Simonsen."); 90 | 91 | FMCWindow = XPLMCreateWindow(x, y, x + width, y - height, 1, 92 | FMCWindowCallback, FMCKeyCallback, 93 | FMCMouseClickCallback, NULL); 94 | 95 | FMCToggleHotKey = XPLMRegisterHotKey(XPLM_VK_F8, xplm_DownFlag, 96 | "F8", FMCToggleHotKeyHandler, NULL); 97 | 98 | XPLMRegisterFlightLoopCallback(FMCLoopCallback, 1.0, NULL); 99 | 100 | int result = LoadGLTexture(std::string("fmc.bmp"), 0); 101 | 102 | if(!result) { 103 | XPLMDebugString("Could not load FMC texture"); 104 | } 105 | 106 | flight = new Flight(); 107 | pages = new Pages(); 108 | 109 | page = new InitPage(flight); pages->RegisterPage("init", page); 110 | page = new LegsPage(flight); pages->RegisterPage("legs", page); 111 | page = new AirportPage(flight); pages->RegisterPage("airport", page); 112 | page = new DepPage(flight); pages->RegisterPage("airport_dep", page); 113 | page = new ArrPage(flight); pages->RegisterPage("airport_arr", page); 114 | page = new ProgressPage(flight); pages->RegisterPage("progress", page); 115 | page = new RoutePage(flight); pages->RegisterPage("route", page); 116 | page = new NavaidPage(flight); pages->RegisterPage("navaid", page); 117 | 118 | pages->SwitchPage("init"); 119 | 120 | return 1; 121 | } 122 | 123 | PLUGIN_API void XPluginStop(void) { 124 | XPLMUnregisterHotKey(FMCToggleHotKey); 125 | XPLMDestroyWindow(FMCWindow); 126 | XPLMUnregisterFlightLoopCallback(FMCLoopCallback, NULL); 127 | 128 | /* Cleaning up */ 129 | Pages::PageMapIterators iter_pair = pages->PagesIterator(); 130 | 131 | for(Pages::PageMap::iterator iter = iter_pair.first; 132 | iter != iter_pair.second; 133 | iter++) { 134 | delete iter->second; 135 | } 136 | 137 | delete pages; 138 | delete flight; 139 | } 140 | 141 | PLUGIN_API void XPluginDisable(void) { 142 | 143 | } 144 | 145 | PLUGIN_API int XPluginEnable(void) { 146 | return 1; 147 | } 148 | 149 | PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFromWho, int inMessage, void * inParam) { 150 | 151 | } 152 | 153 | void FMCWindowCallback(XPLMWindowID inWindowID, void * inRefcon) { 154 | int PanelWindowLeft, PanelWindowRight, PanelWindowBottom, PanelWindowTop; 155 | float PanelLeft, PanelRight, PanelBottom, PanelTop; 156 | 157 | if (FMCDisplayWindow) { 158 | XPLMGetWindowGeometry(FMCWindow, &PanelWindowLeft, 159 | &PanelWindowTop, &PanelWindowRight, 160 | &PanelWindowBottom); 161 | 162 | PanelLeft = PanelWindowLeft; 163 | PanelRight = PanelWindowRight; 164 | PanelBottom = PanelWindowBottom; 165 | PanelTop = PanelWindowTop; 166 | 167 | XPLMSetGraphicsState(0, 1, 0, 0, 0, 0, 0); 168 | 169 | XPLMBindTexture2d(Texture[FMC_TEXTURE], 0); 170 | 171 | glPushMatrix(); 172 | glBegin(GL_QUADS); 173 | 174 | glTexCoord2f(1, 0.0f); glVertex2f(PanelRight, PanelBottom); 175 | glTexCoord2f(0, 0.0f); glVertex2f(PanelLeft, PanelBottom); 176 | glTexCoord2f(0, 1.0f); glVertex2f(PanelLeft, PanelTop); 177 | glTexCoord2f(1, 1.0f); glVertex2f(PanelRight, PanelTop); 178 | 179 | glEnd(); 180 | glPopMatrix(); 181 | 182 | XPLMSetGraphicsState(0, 0, 0, 0, 0, 0, 0); 183 | 184 | glFlush(); 185 | 186 | Page * page = pages->CurrentPage(); 187 | page->SetCoordinates(&PanelLeft, &PanelTop); 188 | page->Update(); 189 | } 190 | } 191 | 192 | void FMCKeyCallback(XPLMWindowID inWindowID, char inKey, XPLMKeyFlags inFlags, char inVirtualKey, void * inRefcon, int losingFocus) { 193 | 194 | if(!FMCKeyboardInput) { 195 | return; 196 | } 197 | 198 | Page* page = pages->CurrentPage(); 199 | 200 | // accept key event if key is pressed down or held down (from X-Ivap) 201 | if(((inFlags & xplm_DownFlag) != 0) || 202 | ((inFlags & xplm_DownFlag) == 0 && 203 | (inFlags & xplm_UpFlag) == 0)) { 204 | 205 | switch(inKey) { 206 | case 8: 207 | page->HandleDelete(); 208 | break; 209 | default: 210 | page->HandleInput(inKey); 211 | break; 212 | } 213 | } 214 | } 215 | 216 | int FMCMouseClickCallback(XPLMWindowID inWindowID, int x, int y, XPLMMouseStatus inMouse, void * inRefcon) { 217 | static int dX = 0, dY = 0; 218 | static int Weight = 0, Height = 0; 219 | int Left, Top, Right, Bottom; 220 | static int gDragging = 0; 221 | 222 | if (!FMCDisplayWindow) 223 | return 0; 224 | 225 | /// Get the windows current position 226 | XPLMGetWindowGeometry(inWindowID, &Left, &Top, &Right, &Bottom); 227 | 228 | switch(inMouse) { 229 | case xplm_MouseDown: 230 | dX = x - Left; 231 | dY = y - Top; 232 | /// Test for the mouse in the top part of the window 233 | if (CoordInRect(x, y, Left, Top, Right, Top-15)) { 234 | Weight = Right - Left; 235 | Height = Bottom - Top; 236 | gDragging = 1; 237 | } 238 | else { 239 | InputHandler(dX, dY); 240 | } 241 | break; 242 | case xplm_MouseDrag: 243 | /// We are dragging so update the window position 244 | if (gDragging) { 245 | Left = (x - dX); Right = Left + Weight; 246 | Top = (y - dY); Bottom = Top + Height; 247 | XPLMSetWindowGeometry(inWindowID, Left, Top, Right, Bottom); 248 | } 249 | break; 250 | case xplm_MouseUp: 251 | gDragging = 0; 252 | break; 253 | } 254 | 255 | return 1; 256 | } 257 | 258 | void FMCToggleHotKeyHandler(void * refCon) { 259 | FMCDisplayWindow = !FMCDisplayWindow; 260 | } 261 | 262 | float FMCLoopCallback(float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void *inRefcon) { 263 | int destination = XPLMGetDestinationFMSEntry(); 264 | 265 | XPLMDataRef lat_ref = XPLMFindDataRef("sim/flightmodel/position/latitude"); 266 | XPLMDataRef lon_ref = XPLMFindDataRef("sim/flightmodel/position/longitude"); 267 | 268 | float lat = XPLMGetDataf(lat_ref); 269 | float lon = XPLMGetDataf(lon_ref); 270 | 271 | XPLMSetFMSEntryLatLon(0, lat, lon, 0); 272 | 273 | if(destination > 1) { 274 | while(destination > 1 && flight->flightplan.size() > 0) { 275 | flight->flightplan.erase(flight->flightplan.begin()); 276 | destination--; 277 | } 278 | 279 | flight->SyncToXPFMC(); 280 | } 281 | 282 | flight->CalcDistances(); 283 | 284 | return 0.5; 285 | } 286 | 287 | 288 | 289 | 290 | -------------------------------------------------------------------------------- /src/Main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | void FMCToggleHotKeyHandler(void * refCon); 22 | void FMCWindowCallback(XPLMWindowID inWindowID, void * inRefcon); 23 | void FMCKeyCallback(XPLMWindowID inWindowID, char inKey, XPLMKeyFlags inFlags, char inVirtualKey, void * inRefcon, int losingFocus); 24 | int FMCMouseClickCallback(XPLMWindowID inWindowID, int x, int y, XPLMMouseStatus inMouse, void * inRefcon); 25 | float FMCLoopCallback(float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop, int inCounter, void *inRefcon); 26 | -------------------------------------------------------------------------------- /src/Navigation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "XPLMDefs.h" 20 | #include "XPLMNavigation.h" 21 | #include "XPLMUtilities.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | class NavAidNotFoundException : public std::logic_error { 31 | public: 32 | NavAidNotFoundException(const std::string& what_arg) : 33 | std::logic_error(what_arg) { 34 | 35 | } 36 | }; 37 | 38 | class NavAidInfo { 39 | public: 40 | XPLMNavRef ref; 41 | int type; 42 | float lat; 43 | float lon; 44 | float height; 45 | int freq; 46 | float heading; 47 | std::string id; /* ~ 32 */ 48 | std::string name /* ~ 256 */; 49 | 50 | /* internal variables */ 51 | int fmc_forced_speed; 52 | int fmc_forced_altitude; 53 | bool fmc_star; 54 | bool fmc_sid; 55 | float fmc_distance; 56 | 57 | std::string fmc_airway; 58 | 59 | NavAidInfo() : ref(0), type(0), lat(0.0), lon(0.0), height(0.0), freq(0), 60 | heading(0), id(""), name(""), fmc_forced_speed(0), fmc_forced_altitude(0), 61 | fmc_star(false), fmc_sid(false), fmc_airway("") { 62 | } 63 | NavAidInfo(XPLMNavRef& ref, int& type, float& lat, float& lon, 64 | float& height, int& freq, float& heading, char id[], 65 | char name[]) : 66 | ref(ref), type(type), lat(lat), lon(lon), height(height), 67 | freq(freq), heading(heading), id(id), name(name), fmc_forced_speed(0), 68 | fmc_forced_altitude(0), fmc_star(false), fmc_sid(false), fmc_airway("") { 69 | } 70 | 71 | bool isEmpty() { 72 | if(this->type == 0 && this->ref == 0) { 73 | return true; 74 | } 75 | 76 | return false; 77 | } 78 | 79 | int ComputedAltitude() { 80 | return fmc_forced_altitude; 81 | } 82 | }; 83 | 84 | class Navigation { 85 | public: 86 | static NavAidInfo FindAirport(std::string Airport) { 87 | XPLMNavRef ref; 88 | 89 | /* Temp variables */ 90 | int type, freq; 91 | float lat, lon, height, heading; 92 | char id[32]; 93 | char name[256]; 94 | 95 | ref = XPLMFindNavAid(NULL, Airport.c_str(), NULL, 96 | NULL, NULL, xplm_Nav_Airport); 97 | 98 | if(ref == XPLM_NAV_NOT_FOUND) { 99 | throw NavAidNotFoundException("Airport not found"); 100 | } 101 | 102 | XPLMGetNavAidInfo(ref, &type, &lat, &lon, &height, 103 | &freq, &heading, id, name, NULL); 104 | 105 | return NavAidInfo(ref, type, lat, lon, height, freq, heading, id, name); 106 | } 107 | 108 | static NavAidInfo FindNavAidIdLonLat(std::string NavAid, float lon, float lat) { 109 | /* Temp variables */ 110 | int type, freq; 111 | float height, heading; 112 | char id[32]; 113 | char name[256]; 114 | XPLMNavRef ref; 115 | 116 | ref = XPLMFindNavAid(NULL, NavAid.c_str(), &lat, &lon, NULL, 117 | xplm_Nav_NDB | xplm_Nav_VOR); 118 | 119 | if(ref == XPLM_NAV_NOT_FOUND) { 120 | ref = XPLMFindNavAid(NULL, NavAid.c_str(), &lat, &lon, NULL, 121 | xplm_Nav_Fix); 122 | } 123 | 124 | if(ref == XPLM_NAV_NOT_FOUND) { 125 | throw NavAidNotFoundException("Navaid not found"); 126 | } 127 | 128 | XPLMGetNavAidInfo(ref, &type, &lat, &lon, &height, 129 | &freq, &heading, id, name, NULL); 130 | 131 | return NavAidInfo(ref, type, lat, lon, height, freq, heading, id, name); 132 | } 133 | 134 | static void FindNavAid(std::string NavAid, std::vector& Result) { 135 | 136 | /* Temp variables */ 137 | int type, freq; 138 | float lat, lon, height, heading; 139 | char id[32]; 140 | char name[256]; 141 | 142 | for(XPLMNavRef ref = XPLMGetFirstNavAid(); 143 | ref != XPLM_NAV_NOT_FOUND; 144 | ref = XPLMGetNextNavAid(ref)) { 145 | 146 | XPLMGetNavAidInfo(ref, &type, &lat, &lon, &height, 147 | &freq, &heading, id, name, NULL); 148 | 149 | if(!strcmp(id, NavAid.c_str())) { 150 | Result.push_back(NavAidInfo(ref, type, lat, lon, height, freq, heading, id, name)); 151 | } 152 | } 153 | } 154 | }; 155 | -------------------------------------------------------------------------------- /src/Page.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "XPLMDefs.h" 25 | #include "XPLMDisplay.h" 26 | #include "XPLMDataAccess.h" 27 | #include "XPLMGraphics.h" 28 | #include "XPLMUtilities.h" 29 | 30 | #include "Page.h" 31 | 32 | extern bool FMCKeyboardInput; 33 | 34 | Page::Page(Flight* flight) { 35 | this->flight = flight; 36 | } 37 | 38 | void Page::SetCoordinates(float* left, float* top) { 39 | this->left = left; 40 | this->top = top; 41 | } 42 | 43 | void Page::DrawString(float x, float y, std::string& str) { 44 | char* c_string = (char*) str.c_str(); 45 | XPLMDrawString((float*) color_green, x, y, c_string, NULL, xplmFont_Basic); 46 | } 47 | 48 | std::string Page::FormatString(std::string left, std::string right) { 49 | std::stringstream ss; 50 | 51 | std::transform(left.begin(), left.end(), left.begin(), ::toupper); 52 | std::transform(right.begin(), right.end(), right.begin(), ::toupper); 53 | 54 | ss << std::setw(17) << std::left << left; 55 | ss << std::setw(17) << std::right << right; 56 | 57 | return ss.str(); 58 | } 59 | 60 | std::string Page::GenerateHeading(std::string heading, unsigned int current_page, unsigned int total_pages) { 61 | std::stringstream ss; 62 | 63 | ss << current_page << "/" << total_pages; 64 | 65 | return this->FormatString(heading, ss.str()); 66 | } 67 | 68 | void Page::Clear() { 69 | this->heading.clear(); 70 | 71 | this->line1_h.clear(); 72 | this->line2_h.clear(); 73 | this->line3_h.clear(); 74 | this->line4_h.clear(); 75 | this->line5_h.clear(); 76 | this->line6_h.clear(); 77 | 78 | this->line1.clear(); 79 | this->line2.clear(); 80 | this->line3.clear(); 81 | this->line4.clear(); 82 | this->line5.clear(); 83 | this->line6.clear(); 84 | } 85 | 86 | void Page::Draw() { 87 | float x; 88 | float y; 89 | 90 | x = *this->left; 91 | y = *this->top; 92 | 93 | this->DrawString(x+70, y-40, this->heading); 94 | 95 | this->DrawString(x+70, y-55, this->line1_h); 96 | this->DrawString(x+70, y-70, this->line1); 97 | 98 | this->DrawString(x+70, y-85, this->line2_h); 99 | this->DrawString(x+70, y-100, this->line2); 100 | 101 | this->DrawString(x+70, y-115, this->line3_h); 102 | this->DrawString(x+70, y-130, this->line3); 103 | 104 | this->DrawString(x+70, y-145, this->line4_h); 105 | this->DrawString(x+70, y-160, this->line4); 106 | 107 | this->DrawString(x+70, y-175, this->line5_h); 108 | this->DrawString(x+70, y-190, this->line5); 109 | 110 | this->DrawString(x+70, y-205, this->line6_h); 111 | this->DrawString(x+70, y-220, this->line6); 112 | 113 | std::string end_line; 114 | if(this->error.length() > 0) { 115 | end_line = this->error; 116 | } 117 | else { 118 | end_line = this->FormatString(this->input, this->GetStatus()); 119 | } 120 | 121 | this->DrawString(x+70, y-240, end_line); 122 | } 123 | 124 | void Page::HandleInput(char input_char) { 125 | if(this->error.length() == 0) { 126 | this->input += toupper(input_char); 127 | } 128 | } 129 | 130 | bool Page::HandleDelete() { 131 | if(this->error.length() > 0) { 132 | this->error.clear(); 133 | return true; 134 | } 135 | else if(this->input.length() > 0) { 136 | this->input.erase(this->input.end() - 1); 137 | return true; 138 | } 139 | 140 | return false; 141 | } 142 | 143 | std::string Page::GetStatus() { 144 | std::string status; 145 | 146 | if(this->error.length() > 0) { 147 | status = "ERR"; 148 | } 149 | if(FMCKeyboardInput) { 150 | if(status.length() > 0) { 151 | status += ",KEY"; 152 | } 153 | else { 154 | status = "KEY"; 155 | } 156 | } 157 | return status; 158 | } 159 | -------------------------------------------------------------------------------- /src/Page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGE_H 20 | #define PAGE_H 21 | 22 | #include 23 | 24 | #include "Flight.h" 25 | 26 | const float color_green[] = { 0.0, 1.0, 0.0 }; 27 | 28 | const int LSK1 = 1; 29 | const int LSK2 = 2; 30 | const int LSK3 = 3; 31 | const int LSK4 = 4; 32 | const int LSK5 = 5; 33 | const int LSK6 = 6; 34 | const int RSK1 = 7; 35 | const int RSK2 = 8; 36 | const int RSK3 = 9; 37 | const int RSK4 = 10; 38 | const int RSK5 = 11; 39 | const int RSK6 = 12; 40 | 41 | const int BUTTON_UP = 20; 42 | const int BUTTON_DOWN = 21; 43 | 44 | class Page { 45 | 46 | public: 47 | Page(Flight* flight); 48 | virtual ~Page() { 49 | } 50 | 51 | void SetCoordinates(float* left, float* top); 52 | void DrawString(float x, float y, std::string& str); 53 | std::string FormatString(std::string left, std::string right); 54 | std::string GenerateHeading(std::string heading, unsigned int current_page, 55 | unsigned int total_pages); 56 | void Clear(); 57 | void Draw(); 58 | void HandleInput(char input_char); 59 | 60 | virtual bool HandleDelete(); 61 | virtual std::string GetStatus(); 62 | 63 | virtual void Update() { 64 | throw std::logic_error("Not implemented"); 65 | } 66 | 67 | virtual void HandleSK(const int key) { 68 | throw std::logic_error("Not implemented"); 69 | } 70 | 71 | virtual bool OnSwitch() { 72 | return true; 73 | } 74 | 75 | protected: 76 | Flight* flight; 77 | 78 | float* left; 79 | float* top; 80 | 81 | std::string heading; 82 | 83 | std::string line1_h; 84 | std::string line1; 85 | std::string line2_h; 86 | std::string line2; 87 | std::string line3_h; 88 | std::string line3; 89 | std::string line4_h; 90 | std::string line4; 91 | std::string line5_h; 92 | std::string line5; 93 | std::string line6_h; 94 | std::string line6; 95 | 96 | std::string input; 97 | std::string error; 98 | }; 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src/Page_Airport.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include 20 | 21 | #include "Page_Airport.h" 22 | 23 | #include "Pages.h" 24 | 25 | extern Pages* pages; 26 | 27 | void DepArrPage::PrintLine(unsigned int offset, std::string* line, std::vector* runways, std::vector* procedures) { 28 | std::string left_column = ""; 29 | std::string right_column = ""; 30 | 31 | if(offset < (*runways).size()) { 32 | left_column = (*runways)[offset]; 33 | 34 | if(offset == this->selected_runway) { 35 | left_column += "*"; 36 | } 37 | } 38 | if(offset < (*procedures).size()) { 39 | right_column = (*procedures)[offset]; 40 | } 41 | 42 | if(left_column.length() > 0 || right_column.length() > 0) { 43 | (*line) = this->FormatString(left_column, right_column); 44 | } 45 | else { 46 | (*line).clear(); 47 | } 48 | } 49 | 50 | void DepArrPage::Update() { 51 | std::vector* runways = this->runways; 52 | std::vector* procedures = &this->procedures_labels; 53 | 54 | this->PrintLine(this->offset, &this->line1, runways, procedures); 55 | this->PrintLine(this->offset + 1, &this->line2, runways, procedures); 56 | this->PrintLine(this->offset + 2, &this->line3, runways, procedures); 57 | this->PrintLine(this->offset + 3, &this->line4, runways, procedures); 58 | this->PrintLine(this->offset + 4, &this->line5, runways, procedures); 59 | 60 | this->Draw(); 61 | 62 | } 63 | 64 | void DepArrPage::HandleSK(int key) { 65 | int runway_index = -1; 66 | int procedure_index = -1; 67 | 68 | switch(key) { 69 | case BUTTON_UP: 70 | if(static_cast(this->offset) - 5 > 0) { 71 | this->offset = this->offset - 5; 72 | } 73 | else { 74 | this->offset = 0; 75 | } 76 | return; 77 | case BUTTON_DOWN: 78 | if(this->offset + 5 < std::max((*this->runways).size(), 79 | this->procedures_labels.size())) { 80 | this->offset = this->offset + 5; 81 | } 82 | return; 83 | case LSK1: runway_index = 0; break; 84 | case LSK2: runway_index = 1; break; 85 | case LSK3: runway_index = 2; break; 86 | case LSK4: runway_index = 3; break; 87 | case LSK5: runway_index = 4; break; 88 | //case LSK6: runway_index = 5; break; 89 | case RSK1: procedure_index = 0; break; 90 | case RSK2: procedure_index = 1; break; 91 | case RSK3: procedure_index = 2; break; 92 | case RSK4: procedure_index = 3; break; 93 | case RSK5: procedure_index = 4; break; 94 | //case RSK6: procedure_index = 5; break; 95 | default: 96 | return; 97 | } 98 | 99 | if(this->selected_runway >= 0 && procedure_index >= 0) { 100 | unsigned int selected_procedure = this->offset + procedure_index; 101 | std::string procedure_label = this->procedures_labels[selected_procedure]; 102 | std::string runway = (*this->runways)[this->selected_runway]; 103 | 104 | Procedure* found_procedure = NULL; 105 | 106 | for(size_t i=0; i < (*this->procedures).size(); i++) { 107 | Procedure* procedure = &(*this->procedures)[i]; 108 | if(procedure->name == procedure_label && procedure->runway == runway) { 109 | found_procedure = procedure; 110 | } 111 | } 112 | 113 | if(found_procedure != NULL) { 114 | int count = 0; 115 | int start = -1; 116 | int end = -1; 117 | 118 | /* Clean existing procedures */ 119 | if(this->flight->flightplan.size() > 0) { 120 | for(size_t i=0; i < this->flight->flightplan.size(); i++) { 121 | if((this->sid && this->flight->flightplan[i].fmc_sid) || 122 | (!this->sid && this->flight->flightplan[i].fmc_star)) { 123 | 124 | start = i; 125 | break; 126 | } 127 | } 128 | 129 | for(size_t i=this->flight->flightplan.size() - 1; i >= 0; i--) { 130 | if((this->sid && this->flight->flightplan[i].fmc_sid) || 131 | (!this->sid && this->flight->flightplan[i].fmc_star)) { 132 | 133 | end = i; 134 | break; 135 | } 136 | } 137 | 138 | if(start >= 0 && end >= 0) { 139 | this->flight->flightplan.erase(this->flight->flightplan.begin() + start, 140 | this->flight->flightplan.begin() + end + 1); 141 | } 142 | } 143 | 144 | for(size_t i=0; i < (*found_procedure).waypoints.size(); i++) { 145 | ProcedureWaypoint waypoint = (*found_procedure).waypoints[i]; 146 | NavAidInfo navaid_info; 147 | float lat, lon; 148 | 149 | /* IF procedure provides lat/lon, it is fine */ 150 | if(waypoint.lon && waypoint.lat) { 151 | lon = waypoint.lon; 152 | lat = waypoint.lat; 153 | } 154 | else { 155 | /* Otherwise we will use dep/dest airport to find the nearest 156 | waypoint in the database */ 157 | if(this->sid) { 158 | lon = this->flight->dep_airport.lon; 159 | lat = this->flight->dep_airport.lat; 160 | } 161 | else { 162 | lon = this->flight->dest_airport.lon; 163 | lat = this->flight->dest_airport.lat; 164 | } 165 | } 166 | 167 | try { 168 | navaid_info = Navigation::FindNavAidIdLonLat(waypoint.id, lon, lat); 169 | } 170 | catch(NavAidNotFoundException e) { 171 | navaid_info = NavAidInfo(); 172 | navaid_info.ref = 0; 173 | navaid_info.type = -1; 174 | navaid_info.lat = waypoint.lat; 175 | navaid_info.lon = waypoint.lon; 176 | navaid_info.id = waypoint.id; 177 | navaid_info.name = waypoint.id; 178 | } 179 | 180 | if(waypoint.speed) { 181 | navaid_info.fmc_forced_speed = waypoint.speed; 182 | } 183 | 184 | if(waypoint.altitude) { 185 | navaid_info.fmc_forced_altitude = waypoint.altitude; 186 | } 187 | 188 | if(navaid_info.lat && navaid_info.lon) { 189 | if(this->sid) { 190 | navaid_info.fmc_sid = true; 191 | this->flight->flightplan.insert(this->flight->flightplan.begin() + count, navaid_info); 192 | count++; 193 | } else { 194 | navaid_info.fmc_star = true; 195 | this->flight->flightplan.push_back(navaid_info); 196 | } 197 | } 198 | else { 199 | XPLMDebugString("Could not find "); 200 | XPLMDebugString(navaid_info.id.c_str()); 201 | XPLMDebugString("\n"); 202 | } 203 | } 204 | this->flight->SyncToXPFMC(); 205 | 206 | pages->SwitchPage("legs"); 207 | } 208 | } 209 | else if(runway_index >= 0) { 210 | procedures_labels.clear(); 211 | 212 | this->selected_runway = this->offset + runway_index; 213 | std::string runway = (*this->runways)[this->selected_runway]; 214 | 215 | for(size_t i=0; i < (*this->procedures).size(); i++) { 216 | Procedure* procedure = &(*this->procedures)[i]; 217 | if(procedure->runway == runway) { 218 | this->procedures_labels.push_back(procedure->name); 219 | } 220 | } 221 | } 222 | 223 | } 224 | 225 | bool DepArrPage::OnSwitch() { 226 | this->procedures_labels.clear(); 227 | this->selected_runway = -1; 228 | return true; 229 | } 230 | 231 | DepPage::DepPage(Flight* flight) : DepArrPage(flight) { 232 | this->sid = true; 233 | this->runways = &this->flight->sids_runways; 234 | this->procedures = &this->flight->sids; 235 | } 236 | 237 | void DepPage::Update() { 238 | unsigned int total_elements = std::max((*this->runways).size(), this->procedures_labels.size()); 239 | 240 | unsigned int current_page = ceil(float(this->offset) / 5) + 1; 241 | unsigned int total_pages = floor(float(total_elements) / 5) + 1; 242 | 243 | this->Clear(); 244 | this->heading = this->GenerateHeading("Departures", current_page, total_pages); 245 | 246 | DepArrPage::Update(); 247 | } 248 | 249 | ArrPage::ArrPage(Flight* flight) : DepArrPage(flight) { 250 | this->sid = false; 251 | this->runways = &this->flight->stars_runways; 252 | this->procedures = &this->flight->stars; 253 | } 254 | 255 | void ArrPage::Update() { 256 | unsigned int total_elements = std::max((*this->runways).size(), this->procedures_labels.size()); 257 | 258 | unsigned int current_page = ceil(float(this->offset) / 5) + 1; 259 | unsigned int total_pages = floor(float(total_elements) / 5) + 1; 260 | 261 | this->Clear(); 262 | this->heading = this->GenerateHeading("Arrivals", current_page, total_pages); 263 | 264 | DepArrPage::Update(); 265 | } 266 | 267 | AirportPage::AirportPage(Flight* flight) : Page(flight) { 268 | } 269 | 270 | void AirportPage::Update() { 271 | this->Clear(); 272 | 273 | this->heading = this->FormatString(std::string("Airport"), 274 | std::string("1/1")); 275 | 276 | this->line1 = this->FormatString(this->flight->dep_airport.id, 277 | std::string("DEP >")); 278 | this->line2 = this->FormatString(this->flight->dest_airport.id, 279 | std::string("ARR >")); 280 | 281 | this->Draw(); 282 | } 283 | 284 | void AirportPage::HandleSK(int key) { 285 | switch(key) { 286 | case RSK1: 287 | if(this->flight->sids.size() > 0) { 288 | pages->SwitchPage("airport_dep"); 289 | } 290 | else { 291 | this->error = "No SIDS"; 292 | } 293 | break; 294 | case RSK2: 295 | if(this->flight->stars.size() > 0) { 296 | pages->SwitchPage("airport_arr"); 297 | } 298 | else { 299 | this->error = "No STARS"; 300 | } 301 | break; 302 | } 303 | } 304 | 305 | bool AirportPage::OnSwitch() { 306 | if(this->flight->dep_airport.isEmpty() || 307 | this->flight->dest_airport.isEmpty()) { 308 | return false; 309 | } 310 | 311 | return true; 312 | } 313 | -------------------------------------------------------------------------------- /src/Page_Airport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGE_AIRPORT_H 20 | #define PAGE_AIRPORT_H 21 | 22 | #include 23 | 24 | #include "Page.h" 25 | #include "Flight.h" 26 | 27 | class DepArrPage : public Page { 28 | public: 29 | DepArrPage(Flight* flight) : Page(flight), offset(0), selected_runway(-1) { } 30 | void PrintLine(unsigned int offset, std::string* line, std::vector* runways, std::vector* procedures); 31 | void Update(); 32 | void HandleSK(int key); 33 | virtual bool OnSwitch(); 34 | protected: 35 | unsigned int offset; 36 | unsigned int selected_runway; 37 | bool sid; 38 | std::vector* runways; 39 | std::vector* procedures; 40 | std::vector procedures_labels; 41 | }; 42 | 43 | class DepPage : public DepArrPage { 44 | public: 45 | DepPage(Flight* flight); 46 | void Update(); 47 | }; 48 | 49 | class ArrPage : public DepArrPage { 50 | public: 51 | ArrPage(Flight* flight); 52 | void Update(); 53 | }; 54 | 55 | class AirportPage : public Page { 56 | 57 | public: 58 | AirportPage(Flight* flight); 59 | void Update(); 60 | void HandleSK(int key); 61 | bool OnSwitch(); 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/Page_Init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Page_Init.h" 20 | #include "Utils.h" 21 | 22 | InitPage::InitPage(Flight* flight) : Page(flight) { 23 | 24 | this->heading = this->FormatString(std::string("Init"), 25 | std::string("1/1")); 26 | this->line1_h = this->FormatString(std::string("Dep Airport"), 27 | std::string("Dest Airport")); 28 | this->line2_h = this->FormatString(std::string(""), 29 | std::string("Flight No")); 30 | } 31 | 32 | void InitPage::Update() { 33 | std::string dep_airport = this->flight->dep_airport.type > 0 ? 34 | this->flight->dep_airport.id : std::string("----"); 35 | std::string dest_airport = this->flight->dest_airport.type > 0 ? 36 | this->flight->dest_airport.id : std::string("----"); 37 | std::string flightno = this->flight->flightno.length() > 0 ? 38 | this->flight->flightno : std::string("----"); 39 | 40 | this->line1 = this->FormatString(dep_airport, dest_airport); 41 | this->line2 = this->FormatString("", flightno); 42 | 43 | this->Draw(); 44 | } 45 | 46 | void InitPage::HandleSK(int key) { 47 | switch(key) { 48 | case LSK1: 49 | try { 50 | this->flight->SetDepAirport(this->input); 51 | } 52 | catch(NavAidNotFoundException e) { 53 | this->error = e.what(); 54 | } 55 | this->input.clear(); 56 | break; 57 | case RSK1: 58 | try { 59 | this->flight->SetDestAirport(this->input); 60 | } 61 | catch(NavAidNotFoundException e) { 62 | this->error = e.what(); 63 | } 64 | this->input.clear(); 65 | break; 66 | case RSK2: 67 | this->flight->flightno = this->input; 68 | this->input.clear(); 69 | break; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Page_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGE_INIT_H 20 | #define PAGE_INIT_H 21 | 22 | #include 23 | 24 | #include "Page.h" 25 | #include "Flight.h" 26 | 27 | class InitPage : public Page { 28 | 29 | public: 30 | InitPage(Flight* flight); 31 | void Update(); 32 | void HandleSK(int key); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/Page_Legs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Pages.h" 20 | #include "Page_Legs.h" 21 | 22 | #include 23 | #include 24 | 25 | extern Pages* pages; 26 | 27 | LegsPage::LegsPage(Flight* flight) : Page(flight) { 28 | this->offset = 0; 29 | this->delete_mode = false; 30 | } 31 | 32 | void LegsPage::PrintLine(unsigned int offset, std::string* line, 33 | std::vector* flightplan) { 34 | 35 | std::stringstream ss; 36 | std::string right_column; 37 | 38 | if(offset < (*flightplan).size()) { 39 | ss.str(""); 40 | 41 | if((*flightplan)[offset].fmc_forced_speed) { 42 | ss << (*flightplan)[offset].fmc_forced_speed; 43 | } 44 | else { 45 | ss << "---"; 46 | } 47 | 48 | ss << " / "; 49 | 50 | if((*flightplan)[offset].fmc_forced_altitude) { 51 | ss << (*flightplan)[offset].fmc_forced_altitude; 52 | } 53 | else { 54 | ss << "-----"; 55 | } 56 | right_column = ss.str(); 57 | (*line) = this->FormatString((*flightplan)[offset].id, 58 | right_column); 59 | } 60 | 61 | } 62 | 63 | void LegsPage::Update() { 64 | std::vector* flightplan; 65 | 66 | flightplan = &this->flight->flightplan; 67 | 68 | unsigned int current_page = ceil(float(this->offset) / 5) + 1; 69 | unsigned int total_pages = floor(float((*flightplan).size()) / 5) + 1; 70 | 71 | this->Clear(); 72 | 73 | this->heading = this->GenerateHeading("Legs", current_page, total_pages); 74 | 75 | this->PrintLine(this->offset, &this->line1, flightplan); 76 | this->PrintLine(this->offset + 1, &this->line2, flightplan); 77 | this->PrintLine(this->offset + 2, &this->line3, flightplan); 78 | this->PrintLine(this->offset + 3, &this->line4, flightplan); 79 | this->PrintLine(this->offset + 4, &this->line5, flightplan); 80 | 81 | this->Draw(); 82 | } 83 | 84 | 85 | void LegsPage::HandleSK(int key) { 86 | int index; 87 | std::vector* flightplan; 88 | 89 | flightplan = &this->flight->flightplan; 90 | 91 | switch(key) { 92 | case BUTTON_UP: 93 | if(static_cast(this->offset) - 5 > 0) { 94 | this->offset = this->offset - 5; 95 | } else { 96 | this->offset = 0; 97 | } 98 | return; 99 | case BUTTON_DOWN: 100 | if(this->offset + 5 <= (*flightplan).size()) { 101 | this->offset = this->offset + 5; 102 | } 103 | return; 104 | case LSK1: index = 0; break; 105 | case LSK2: index = 1; break; 106 | case LSK3: index = 2; break; 107 | case LSK4: index = 3; break; 108 | case LSK5: index = 4; break; 109 | //case LSK6: index = 5; break; 110 | default: 111 | return; 112 | } 113 | 114 | unsigned int operation_index = this->offset + index; 115 | 116 | if(!this->delete_mode) { 117 | /* We can press LSK and if no input the current navaid is copied to input */ 118 | if(this->input.size() == 0 && operation_index < this->flight->flightplan.size()) { 119 | this->input = this->flight->flightplan[operation_index].id; 120 | return; 121 | } 122 | else if(this->input.size() == 0) { 123 | return; 124 | } 125 | 126 | int found_index = -1; 127 | 128 | for(size_t i = 0; i < this->flight->flightplan.size(); i++) { 129 | if(this->flight->flightplan[i].id == this->input) { 130 | if(found_index > 0) { 131 | this->error = "Duplicate waypoint aborting"; 132 | return; 133 | } 134 | 135 | found_index = i; 136 | } 137 | } 138 | 139 | if(found_index > 0) { 140 | this->flight->flightplan.erase(this->flight->flightplan.begin() + operation_index, 141 | this->flight->flightplan.begin() + found_index); 142 | this->input.clear(); 143 | return; 144 | } 145 | 146 | /* Clear navaids storage to ensure consistency */ 147 | this->flight->temp_navaids.clear(); 148 | 149 | Navigation::FindNavAid(this->input, this->flight->temp_navaids); 150 | 151 | if(this->flight->temp_navaids.size() == 0) { 152 | this->error = "Navaid could not be found"; 153 | return; 154 | } 155 | 156 | if(this->flight->temp_navaids.size() > 1) { 157 | this->input.clear(); 158 | this->flight->temp_navaid_insert = operation_index; 159 | this->flight->temp_navaid_came_from = "legs"; 160 | pages->SwitchPage("navaid"); 161 | return; 162 | } 163 | 164 | if(operation_index + 1 <= (*flightplan).size()) { 165 | (*flightplan).insert((*flightplan).begin() + operation_index + 1, 166 | this->flight->temp_navaids[0]); 167 | } else { 168 | (*flightplan).push_back(this->flight->temp_navaids[0]); 169 | } 170 | 171 | this->input.clear(); 172 | } 173 | else { 174 | if(operation_index < (*flightplan).size()) { 175 | (*flightplan).erase((*flightplan).begin() + operation_index); 176 | } 177 | 178 | this->delete_mode = false; 179 | } 180 | 181 | this->flight->SyncToXPFMC(); 182 | } 183 | 184 | bool LegsPage::HandleDelete() { 185 | bool action = Page::HandleDelete(); 186 | if(!action) { 187 | this->delete_mode = !this->delete_mode; 188 | } 189 | return true; 190 | } 191 | 192 | std::string LegsPage::GetStatus() { 193 | std::string status = Page::GetStatus(); 194 | if(this->delete_mode) { 195 | if(status.length() > 0) { 196 | status += ", DEL"; 197 | } 198 | else { 199 | status = "DEL"; 200 | } 201 | } 202 | return status; 203 | } 204 | -------------------------------------------------------------------------------- /src/Page_Legs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Page.h" 20 | #include "Flight.h" 21 | #include "Utils.h" 22 | #include "AirwayReader.h" 23 | 24 | const int MODE_LEGS = 0; 25 | const int MODE_NAVAID = 1; 26 | 27 | class LegsPage : public Page { 28 | 29 | public: 30 | LegsPage(Flight* flight); 31 | void PrintLine(unsigned int offset, std::string* line, 32 | std::vector* flightplan); 33 | void Update(); 34 | void HandleSK(int key); 35 | bool HandleDelete(); 36 | std::string GetStatus(); 37 | private: 38 | unsigned int offset; 39 | unsigned int operation_index; 40 | bool delete_mode; 41 | }; 42 | -------------------------------------------------------------------------------- /src/Page_Navaid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Pages.h" 20 | #include "Page_Navaid.h" 21 | 22 | #include 23 | #include 24 | 25 | extern Pages * pages; 26 | 27 | NavaidPage::NavaidPage(Flight* flight) : Page(flight), offset(0) { 28 | 29 | } 30 | 31 | void NavaidPage::PrintLine(unsigned int offset, std::string* line, 32 | std::vector* flightplan) { 33 | std::stringstream ss; 34 | std::string right_column; 35 | 36 | if(offset < (*flightplan).size()) { 37 | ss << (*flightplan)[offset].lat << " , " << (*flightplan)[offset].lon; 38 | 39 | right_column = ss.str(); 40 | (*line) = this->FormatString((*flightplan)[offset].id, 41 | right_column); 42 | } 43 | } 44 | 45 | void NavaidPage::Update() { 46 | std::vector* navaids; 47 | 48 | navaids = &this->flight->temp_navaids; 49 | 50 | unsigned int current_page = ceil(float(this->offset) / 5) + 1; 51 | unsigned int total_pages = ceil(float((*navaids).size()) / 5); 52 | 53 | this->Clear(); 54 | 55 | this->heading = this->GenerateHeading("Select navaids", current_page, total_pages); 56 | 57 | this->PrintLine(this->offset, &this->line1, navaids); 58 | this->PrintLine(this->offset + 1, &this->line2, navaids); 59 | this->PrintLine(this->offset + 2, &this->line3, navaids); 60 | this->PrintLine(this->offset + 3, &this->line4, navaids); 61 | this->PrintLine(this->offset + 4, &this->line5, navaids); 62 | 63 | this->Draw(); 64 | 65 | } 66 | 67 | void NavaidPage::HandleSK(int key) { 68 | int index; 69 | 70 | switch(key) { 71 | case BUTTON_UP: 72 | if(static_cast(this->offset) - 5 > 0) { 73 | this->offset = this->offset - 5; 74 | } 75 | else { 76 | this->offset = 0; 77 | } 78 | return; 79 | case BUTTON_DOWN: 80 | if(this->offset + 5 < this->flight->temp_navaids.size()) { 81 | this->offset = this->offset + 5; 82 | } 83 | return; 84 | case LSK1: index = 0; break; 85 | case LSK2: index = 1; break; 86 | case LSK3: index = 2; break; 87 | case LSK4: index = 3; break; 88 | case LSK5: index = 4; break; 89 | //case LSK6: index = 5; break; 90 | default: 91 | return; 92 | } 93 | 94 | unsigned int navaid_index = this->offset + index; 95 | 96 | std::vector* flightplan = &this->flight->flightplan; 97 | 98 | if(this->flight->temp_navaid_insert + 1 <= (*flightplan).size()) { 99 | (*flightplan).insert((*flightplan).begin() + this->flight->temp_navaid_insert + 1, this->flight->temp_navaids[navaid_index]); 100 | } else { 101 | (*flightplan).push_back(this->flight->temp_navaids[navaid_index]); 102 | } 103 | 104 | this->input.clear(); 105 | this->flight->SyncToXPFMC(); 106 | 107 | /* Let us change mode to LEGS when the waypoint was successfully added */ 108 | pages->SwitchPage(this->flight->temp_navaid_came_from); 109 | } 110 | 111 | bool NavaidPage::OnSwitch() { 112 | this->offset = 0; 113 | return true; 114 | } 115 | -------------------------------------------------------------------------------- /src/Page_Navaid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGE_NAVAID_H 20 | #define PAGE_NAVAID_H 21 | 22 | #include "Page.h" 23 | #include "Flight.h" 24 | 25 | class NavaidPage : public Page { 26 | public: 27 | NavaidPage(Flight* flight); 28 | void PrintLine(unsigned int offset, std::string* line, 29 | std::vector* flightplan); 30 | void Update(); 31 | void HandleSK(int key); 32 | bool OnSwitch(); 33 | private: 34 | unsigned int offset; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/Page_Progress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Page_Progress.h" 20 | #include "Utils.h" 21 | 22 | #include 23 | #include 24 | 25 | ProgressPage::ProgressPage(Flight* flight) : Page(flight) { 26 | 27 | this->heading = this->FormatString(std::string("Progress"), 28 | std::string("1/1")); 29 | this->line1_h = this->FormatString(std::string("Next waypoint"), 30 | std::string("")); 31 | this->line2_h = this->FormatString(std::string("Next waypoint after"), 32 | std::string("")); 33 | this->line3_h = this->FormatString(std::string("Destination"), 34 | std::string("")); 35 | } 36 | 37 | void ProgressPage::Update() { 38 | 39 | std::stringstream ss; 40 | 41 | if(this->flight->flightplan.size() > 0) { 42 | ss.str(""); 43 | ss << std::fixed << std::setprecision(0) 44 | << this->flight->flightplan[0].fmc_distance; 45 | ss << " " << "nm"; 46 | 47 | this->line1 = this->FormatString(this->flight->flightplan[0].id, 48 | ss.str()); 49 | } 50 | if(this->flight->flightplan.size() > 1) { 51 | ss.str(""); 52 | ss << std::fixed << std::setprecision(0) 53 | << this->flight->flightplan[1].fmc_distance; 54 | ss << " " << "nm"; 55 | 56 | this->line2 = this->FormatString(this->flight->flightplan[1].id, 57 | ss.str()); 58 | } 59 | 60 | if(this->flight->flightplan.size() > 0) { 61 | NavAidInfo* last_waypoint = &this->flight->flightplan[this->flight->flightplan.size()-1]; 62 | NavAidInfo* dest_airport = &this->flight->dest_airport; 63 | 64 | double distance_to_last = last_waypoint->fmc_distance; 65 | double distance_to_airport = distance(last_waypoint->lat, last_waypoint->lon, dest_airport->lat, dest_airport->lon); 66 | double distance_to_dest = distance_to_last + distance_to_airport; 67 | 68 | ss.str(""); 69 | ss << std::fixed << std::setprecision(0) << distance_to_dest; 70 | ss << " " << "nm"; 71 | this->line3 = this->FormatString(dest_airport->id, 72 | ss.str()); 73 | 74 | } 75 | 76 | this->Draw(); 77 | } 78 | 79 | void ProgressPage::HandleSK(int key) { 80 | } 81 | -------------------------------------------------------------------------------- /src/Page_Progress.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGE_PROGRESS_H 20 | #define PAGE_PROGRESS_H 21 | 22 | #include 23 | 24 | #include "Page.h" 25 | #include "Flight.h" 26 | 27 | class ProgressPage : public Page { 28 | 29 | public: 30 | ProgressPage(Flight* flight); 31 | void Update(); 32 | void HandleSK(int key); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/Page_Route.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Pages.h" 20 | 21 | #include "Page_Route.h" 22 | #include "Utils.h" 23 | 24 | #include 25 | 26 | extern Pages * pages; 27 | 28 | RoutePage::RoutePage(Flight* flight) : Page(flight), offset(0), delete_mode(false), airway_reader(AirwayReader(GetAirwayFilename())) { 29 | } 30 | 31 | void RoutePage::PrintLine(unsigned int offset, std::string* line) { 32 | if(offset < this->routes.size()) { 33 | 34 | std::string left_column, right_column; 35 | 36 | if(this->routes[offset].sid) { 37 | left_column = "SID"; 38 | } 39 | else if(this->routes[offset].star) { 40 | left_column = "STAR"; 41 | } 42 | else if(this->routes[offset].airway.size() > 0) { 43 | left_column = this->routes[offset].airway; 44 | } 45 | else { 46 | left_column = "DCT"; 47 | } 48 | 49 | right_column = this->routes[offset].dest; 50 | 51 | (*line) = this->FormatString(left_column, right_column); 52 | } 53 | else { 54 | (*line).clear(); 55 | } 56 | } 57 | 58 | void RoutePage::Update() { 59 | 60 | unsigned int current_page = ceil(float(this->offset) / 5) + 1; 61 | unsigned int total_pages = floor(float(this->routes.size()) / 5) + 1; 62 | 63 | this->Clear(); 64 | 65 | this->heading = this->GenerateHeading("ROUTE", current_page, total_pages); 66 | 67 | this->PrintLine(this->offset, &this->line1); 68 | this->PrintLine(this->offset + 1, &this->line2); 69 | this->PrintLine(this->offset + 2, &this->line3); 70 | this->PrintLine(this->offset + 3, &this->line4); 71 | this->PrintLine(this->offset + 4, &this->line5); 72 | 73 | this->Draw(); 74 | } 75 | 76 | void RoutePage::HandleSK(int key) { 77 | int airway_index = -1; 78 | int dest_index = -1; 79 | switch(key) { 80 | case BUTTON_UP: 81 | if(static_cast(this->offset) - 5 > 0) { 82 | this->offset = this->offset - 5; 83 | } else { 84 | this->offset = 0; 85 | } 86 | return; 87 | case BUTTON_DOWN: 88 | if(this->offset + 5 <= this->routes.size()) { 89 | this->offset = this->offset + 5; 90 | } 91 | return; 92 | case LSK1: airway_index = 0; break; 93 | case LSK2: airway_index = 1; break; 94 | case LSK3: airway_index = 2; break; 95 | case LSK4: airway_index = 3; break; 96 | case LSK5: airway_index = 4; break; 97 | case RSK1: dest_index = 0; break; 98 | case RSK2: dest_index = 1; break; 99 | case RSK3: dest_index = 2; break; 100 | case RSK4: dest_index = 3; break; 101 | case RSK5: dest_index = 4; break; 102 | default: return; 103 | } 104 | 105 | if(!this->delete_mode) { 106 | if(airway_index >= 0) { 107 | unsigned int operation_index = this->offset + airway_index; 108 | if(operation_index < this->routes.size()) { 109 | /* Todo */ 110 | } 111 | else { 112 | RouteItem item; 113 | item.airway = this->input; 114 | this->routes.push_back(item); 115 | this->input.clear(); 116 | } 117 | } 118 | else if(dest_index >= 0) { 119 | unsigned int operation_index = this->offset + dest_index; 120 | 121 | if(operation_index >= this->routes.size()) { 122 | RouteItem item; 123 | 124 | this->routes.push_back(item); 125 | 126 | operation_index = this->routes.size() - 1; 127 | } 128 | 129 | std::string source = ""; 130 | if(this->routes.size() > 1) { 131 | source = this->routes[operation_index-1].dest; 132 | } 133 | 134 | std::string airway = this->routes[operation_index].airway; 135 | std::string dest = this->input; 136 | 137 | std::vector* flightplan = &this->flight->flightplan; 138 | 139 | if(airway.size() > 0) { 140 | std::vector waypoints; 141 | 142 | this->airway_reader.FindSegment(airway, source, dest, waypoints); 143 | 144 | if(waypoints.size() == 0) { 145 | this->error = "Airway not found"; 146 | return; 147 | } 148 | 149 | if(this->routes[operation_index].inserted) { 150 | RouteItem item; 151 | item = this->routes[operation_index]; 152 | 153 | this->flight->flightplan.erase(this->flight->flightplan.begin() + item.start_index, this->flight->flightplan.begin() + item.end_index + 1); 154 | } 155 | 156 | this->routes[operation_index].dest = this->input; 157 | 158 | unsigned int insert_index = this->routes[operation_index-1].end_index; 159 | 160 | if(insert_index + 1 <= (*flightplan).size()) { 161 | for(size_t i=waypoints.size()-1; i > 0; i--) { 162 | (*flightplan).insert((*flightplan).begin() + insert_index + 1, 163 | waypoints[i]); 164 | } 165 | } else { 166 | for(size_t i=1; i < waypoints.size(); i++) { 167 | (*flightplan).push_back(waypoints[i]); 168 | } 169 | } 170 | } 171 | else { 172 | unsigned int insert_index = 0; 173 | if(this->routes.size() > 1) { 174 | insert_index = this->routes[operation_index-1].end_index; 175 | } 176 | 177 | /* Clear navaids storage to ensure consistency */ 178 | this->flight->temp_navaids.clear(); 179 | 180 | Navigation::FindNavAid(this->input, this->flight->temp_navaids); 181 | 182 | if(this->flight->temp_navaids.size() == 0) { 183 | this->error = "Navaid could not be found"; 184 | return; 185 | } 186 | 187 | if(this->flight->temp_navaids.size() > 1) { 188 | this->input.clear(); 189 | this->flight->temp_navaid_insert = insert_index; 190 | this->flight->temp_navaid_came_from = "route"; 191 | pages->SwitchPage("navaid"); 192 | return; 193 | } 194 | 195 | if(insert_index + 1 <= (*flightplan).size()) { 196 | (*flightplan).insert((*flightplan).begin() + insert_index + 1, 197 | this->flight->temp_navaids[0]); 198 | } else { 199 | (*flightplan).push_back(this->flight->temp_navaids[0]); 200 | } 201 | 202 | } 203 | this->input.clear(); 204 | this->GenerateRoutes(); 205 | this->flight->SyncToXPFMC(); 206 | } 207 | } 208 | else { 209 | unsigned int operation_index = this->offset + airway_index; 210 | 211 | if(airway_index >= 0 && operation_index < this->routes.size()) { 212 | 213 | RouteItem item = this->routes[operation_index]; 214 | 215 | if(item.inserted) { 216 | this->flight->flightplan.erase(this->flight->flightplan.begin() + item.start_index, this->flight->flightplan.begin() + item.end_index + 1); 217 | this->GenerateRoutes(); 218 | this->flight->SyncToXPFMC(); 219 | } 220 | else { 221 | this->routes.erase(this->routes.begin() + operation_index); 222 | } 223 | } 224 | 225 | this->delete_mode = false; 226 | } 227 | } 228 | 229 | bool RoutePage::HandleDelete() { 230 | bool action = Page::HandleDelete(); 231 | if(!action) { 232 | this->delete_mode = !this->delete_mode; 233 | } 234 | return true; 235 | } 236 | 237 | bool RoutePage::OnSwitch() { 238 | this->GenerateRoutes(); 239 | return true; 240 | } 241 | 242 | std::string RoutePage::GetStatus() { 243 | std::string status = Page::GetStatus(); 244 | if(this->delete_mode) { 245 | if(status.length() > 0) { 246 | status += ", DEL"; 247 | } 248 | else { 249 | status = "DEL"; 250 | } 251 | } 252 | return status; 253 | } 254 | 255 | void RoutePage::GenerateRoutes() { 256 | this->routes.clear(); 257 | std::vector* flightplan = &this->flight->flightplan; 258 | 259 | for(size_t i=0; i < flightplan->size();) { 260 | if((*flightplan)[i].fmc_sid) { 261 | RouteItem item; 262 | 263 | item.airway = ""; 264 | item.dest = (*flightplan)[i].id; 265 | item.start_index = i; 266 | item.end_index = i; 267 | item.sid = true; 268 | item.inserted = true; 269 | 270 | for(i++; i < flightplan->size(); i++) { 271 | if((*flightplan)[i].fmc_sid) { 272 | item.dest = (*flightplan)[i].id; 273 | item.end_index = i; 274 | } 275 | else { 276 | break; 277 | } 278 | } 279 | this->routes.push_back(item); 280 | 281 | } 282 | else if((*flightplan)[i].fmc_star) { 283 | RouteItem item; 284 | 285 | item.airway = ""; 286 | item.dest = (*flightplan)[i].id; 287 | item.start_index = i; 288 | item.end_index = i; 289 | item.star = true; 290 | item.inserted = true; 291 | 292 | for(i++; i < flightplan->size(); i++) { 293 | if((*flightplan)[i].fmc_star) { 294 | item.dest = (*flightplan)[i].id; 295 | item.end_index = i; 296 | } 297 | else { 298 | break; 299 | } 300 | } 301 | 302 | this->routes.push_back(item); 303 | } 304 | else if((*flightplan)[i].fmc_airway.size() > 0) { 305 | RouteItem item; 306 | int airway_start = i; 307 | 308 | item.airway = (*flightplan)[airway_start].fmc_airway; 309 | item.dest = (*flightplan)[i].id; 310 | item.start_index = i; 311 | item.end_index = i; 312 | item.inserted = true; 313 | 314 | for(i++; i < flightplan->size(); i++) { 315 | if((*flightplan)[airway_start].fmc_airway == (*flightplan)[i].fmc_airway) { 316 | item.dest = (*flightplan)[i].id; 317 | item.end_index = i; 318 | } 319 | else { 320 | break; 321 | } 322 | } 323 | 324 | this->routes.push_back(item); 325 | } 326 | else if((*flightplan)[i].fmc_airway.size() == 0) { 327 | RouteItem item; 328 | item.airway = ""; 329 | item.dest = (*flightplan)[i].id; 330 | item.start_index = i; 331 | item.end_index = i; 332 | item.inserted = true; 333 | this->routes.push_back(item); 334 | i++; 335 | } 336 | } 337 | } 338 | -------------------------------------------------------------------------------- /src/Page_Route.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGE_ROUTE_H 20 | #define PAGE_ROUTE_H 21 | 22 | #include 23 | 24 | #include "Page.h" 25 | #include "Flight.h" 26 | #include "AirwayReader.h" 27 | 28 | class RouteItem { 29 | public: 30 | RouteItem() : airway(), dest(), start_index(0), end_index(0), 31 | inserted(false), sid(false), star(false) { } 32 | std::string airway; 33 | std::string dest; 34 | unsigned int start_index; 35 | unsigned int end_index; 36 | bool inserted; 37 | bool sid; 38 | bool star; 39 | }; 40 | 41 | class RoutePage : public Page { 42 | 43 | public: 44 | RoutePage(Flight* flight); 45 | void Update(); 46 | void HandleSK(int key); 47 | bool HandleDelete(); 48 | bool OnSwitch(); 49 | std::string GetStatus(); 50 | private: 51 | void PrintLine(unsigned int offset, std::string* line); 52 | void GenerateRoutes(); 53 | std::vector routes; 54 | unsigned int offset; 55 | bool delete_mode; 56 | AirwayReader airway_reader; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/Pages.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "Pages.h" 20 | 21 | Pages::Pages() { 22 | this->page = NULL; 23 | } 24 | 25 | void Pages::RegisterPage(std::string name, Page* page) { 26 | this->pages.insert(PageMap::value_type(name, page)); 27 | } 28 | 29 | bool Pages::SwitchPage(std::string name) { 30 | PageMap::iterator iter; 31 | PageMap::value_type value; 32 | 33 | iter = this->pages.find(name); 34 | if(iter == pages.end()) { 35 | return false; 36 | } 37 | 38 | Page* page = iter->second; 39 | if(page->OnSwitch()) { 40 | this->page = page; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | Page* Pages::CurrentPage() { 47 | return this->page; 48 | } 49 | 50 | Pages::PageMapIterators Pages::PagesIterator() { 51 | return PageMapIterators(this->pages.begin(), this->pages.end()); 52 | } 53 | -------------------------------------------------------------------------------- /src/Pages.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PAGES_H 20 | #define PAGES_H 21 | 22 | #include 23 | #include 24 | 25 | #include "Page.h" 26 | 27 | 28 | class Pages { 29 | public: 30 | typedef std::map PageMap; 31 | typedef std::pair PageMapIterators; 32 | 33 | Pages(); 34 | 35 | void RegisterPage(std::string name, Page* page); 36 | bool SwitchPage(std::string name); 37 | Page* CurrentPage(); 38 | PageMapIterators PagesIterator(); 39 | 40 | private: 41 | PageMap pages; 42 | Page* page; 43 | 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/ProcedureReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include "ProcedureReader.h" 20 | #include "FreeNavProcedureReader.h" 21 | #include "GNSProcedureReader.h" 22 | 23 | #include 24 | #include 25 | 26 | ProcedureWaypoint::ProcedureWaypoint() : id(""), lon(0), lat(0) { 27 | } 28 | 29 | Procedure::Procedure() : runway(""), name(""), star(false), waypoints() { 30 | } 31 | 32 | void Procedure::dump() { 33 | std::cout << this->runway << "," << this->name << std::endl; 34 | for(size_t i=0; i < waypoints.size(); i++) { 35 | std::cout << waypoints[i].id << " " << 36 | waypoints[i].lon << "," << 37 | waypoints[i].lat << " Speed " << 38 | waypoints[i].speed << " Altitude " << 39 | waypoints[i].altitude << std::endl; 40 | } 41 | } 42 | 43 | void ProcedureReader::ReadSidFile(std::string Airport, std::vector& procedures) { 44 | FreeNavProcedureReader freenav_pr; 45 | GNSProcedureReader gns_pr; 46 | 47 | std::string freenav_filename = GetFreeNavProcedureFilename(Airport); 48 | std::ifstream freenav_handle(freenav_filename.c_str()); 49 | if(freenav_handle.good()) { 50 | freenav_pr.ReadSidFile(freenav_filename, procedures); 51 | } 52 | else { 53 | std::string gns_filename = GetGNSProcedureFilename(Airport); 54 | gns_pr.ReadSidFile(gns_filename, procedures); 55 | } 56 | } 57 | 58 | void ProcedureReader::ReadStarFile(std::string Airport, std::vector& procedures) { 59 | FreeNavProcedureReader freenav_pr; 60 | GNSProcedureReader gns_pr; 61 | 62 | std::string freenav_filename = GetFreeNavProcedureFilename(Airport, true); 63 | std::ifstream freenav_handle(freenav_filename.c_str()); 64 | if(freenav_handle.good()) { 65 | freenav_pr.ReadStarFile(freenav_filename, procedures); 66 | } 67 | else { 68 | std::string gns_filename = GetGNSProcedureFilename(Airport); 69 | gns_pr.ReadStarFile(gns_filename, procedures); 70 | } 71 | } 72 | 73 | 74 | void ProcedureReader::GetRunways(std::vector& procedures, std::vector& result) { 75 | std::set set; 76 | 77 | for(size_t i=0; i < procedures.size(); i++) { 78 | if(set.find(procedures[i].runway) == set.end()) { 79 | set.insert(procedures[i].runway); 80 | } 81 | } 82 | 83 | for(std::set::iterator it = set.begin(); 84 | it != set.end(); 85 | ++it) { 86 | result.push_back(*it); 87 | } 88 | } 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/ProcedureReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #ifndef PROCEDUREREADER_H 20 | #define PROCEDUREREADER_H 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "Utils.h" 30 | 31 | class ProcedureWaypoint { 32 | public: 33 | ProcedureWaypoint(); 34 | 35 | std::string id; 36 | float lon; 37 | float lat; 38 | int speed; 39 | int altitude; 40 | }; 41 | 42 | class Procedure { 43 | public: 44 | std::string runway; 45 | std::string name; 46 | bool star; 47 | std::vector waypoints; 48 | 49 | Procedure(); 50 | void dump(); 51 | }; 52 | 53 | 54 | class ProcedureReader { 55 | public: 56 | void ReadSidFile(std::string Airport, std::vector& procedures); 57 | void ReadStarFile(std::string Airport, std::vector& procedures); 58 | void GetRunways(std::vector& procedures, std::vector& result); 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/Utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include "XPLMDefs.h" 24 | #include "XPLMDataAccess.h" 25 | #include "XPLMUtilities.h" 26 | 27 | #include "Utils.h" 28 | 29 | std::string GetPluginDir() { 30 | char buf[256]; 31 | std::string PluginDir; 32 | std::string Delimiter = std::string(XPLMGetDirectorySeparator()); 33 | 34 | XPLMGetSystemPath(buf); 35 | PluginDir = std::string(buf) + "Resources" + Delimiter + "plugins" + Delimiter + "BasicFMC" + Delimiter; 36 | 37 | return PluginDir; 38 | } 39 | 40 | std::string GetAirwayFilename() { 41 | char buf[256]; 42 | std::string AwyFileCustom, AwyFileDefault; 43 | std::string Delimiter = std::string(XPLMGetDirectorySeparator()); 44 | 45 | XPLMGetSystemPath(buf); 46 | AwyFileCustom = std::string(buf) + "Custom Data" + Delimiter + "earth_awy.dat"; 47 | AwyFileDefault = std::string(buf) + "Resources" + Delimiter + 48 | "default data" + Delimiter + "earth_awy.dat"; 49 | 50 | std::ifstream file_handle(AwyFileCustom.c_str()); 51 | if(file_handle.good()) { 52 | XPLMDebugString("Using custom data airway file\n"); 53 | return AwyFileCustom; 54 | } 55 | 56 | XPLMDebugString("Using default airway file\n"); 57 | return AwyFileDefault; 58 | } 59 | 60 | std::string GetGNSProcedureFilename(std::string Airport) { 61 | char buf[256]; 62 | XPLMGetSystemPath(buf); 63 | std::string Delimiter = std::string(XPLMGetDirectorySeparator()); 64 | std::string ProcedureFilenameCustom = std::string(buf) + "Custom Data" + Delimiter + "GNS430" + Delimiter + "navdata" + Delimiter + "Proc" + Delimiter + Airport + ".txt"; 65 | std::string ProcedureFilenameDefault = std::string(buf) + "Resources" + Delimiter + "GNS430" + Delimiter + "navdata" + Delimiter + "Proc" + Delimiter + Airport + ".txt"; 66 | 67 | std::ifstream file_handle(ProcedureFilenameCustom.c_str()); 68 | if(file_handle.good()) { 69 | XPLMDebugString("Using GNS430 custom data procedure\n"); 70 | return ProcedureFilenameCustom; 71 | } 72 | 73 | XPLMDebugString("Using GNS430 default data procedure\n"); 74 | return ProcedureFilenameDefault; 75 | } 76 | 77 | std::string GetFreeNavProcedureFilename(std::string Airport, bool star) { 78 | std::string PluginDir = GetPluginDir(); 79 | std::string Delimiter = std::string(XPLMGetDirectorySeparator()); 80 | std::string ProcedureFilename = PluginDir + "FD_FMC" + Delimiter + Airport + Delimiter + (star ? "STAR_data.csv" : "SID_data.csv"); 81 | 82 | return ProcedureFilename; 83 | } 84 | 85 | int CoordInRect(float x, float y, float l, float t, float r, float b) { 86 | return ((x >= l) && (x < r) && (y < t) && (y >= b)); 87 | } 88 | 89 | void SplitLine(std::string s, std::vector& l, char delim, size_t times) { 90 | std::string::size_type i = 0; 91 | std::string::size_type last = 0; 92 | 93 | bool ignore = false; 94 | 95 | while(i < s.size()) { 96 | if(s[i] == '"') { 97 | 98 | if(!ignore) { 99 | ignore = true; 100 | last = i + 1; 101 | } 102 | else { 103 | std::string new_str = s.substr(last, i-last); 104 | l.push_back(new_str); 105 | last = i + 2; 106 | i += 2; 107 | ignore = false; 108 | } 109 | } 110 | else if(s[i] == delim && !ignore) { 111 | std::string new_str = s.substr(last, i - last); 112 | l.push_back(new_str); 113 | last = i+1; 114 | } 115 | 116 | ++i; 117 | 118 | if(times > 0 && l.size() >= times) { 119 | break; 120 | } 121 | } 122 | if(s.size() - last > 0) { 123 | std::string new_str = s.substr(last, s.size() - last); 124 | l.push_back(new_str); 125 | } 126 | } 127 | 128 | static double toRad(double degrees) { return (pi * degrees) / 180.0; } 129 | static double toDeg(double radiant) { return (radiant * 180.0) / pi; } 130 | 131 | double distance(double lat1d, double lon1d, double lat2d, double lon2d) { 132 | if (lat1d == lat2d && lon1d == lon2d) return 0.0; 133 | 134 | double rad_lat1 = toRad(lat1d); 135 | double rad_lon1 = toRad(lon1d); 136 | double rad_lat2 = toRad(lat2d); 137 | double rad_lon2 = toRad(lon2d); 138 | 139 | double sin_lat1 = sin(rad_lat1); 140 | double sin_lat2 = sin(rad_lat2); 141 | double cos_lat1 = cos(rad_lat1); 142 | double cos_lat2 = cos(rad_lat2); 143 | double lon1_min_lon2 = rad_lon1-rad_lon2; 144 | 145 | return toDeg(acos(sin_lat1*sin_lat2 + cos_lat1*cos_lat2*cos(lon1_min_lon2))) * 60.0; 146 | } 147 | -------------------------------------------------------------------------------- /src/Utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BasicFMC - A very basic FMC for X-Plane 3 | * Copyright (C) 2015 Bo Simonsen, 4 | * 5 | * This program is free software: you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License as published by the Free 7 | * Software Foundation, either version 3 of the License, or (at your option) 8 | * any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program. If not, see . 17 | */ 18 | 19 | 20 | #ifndef UTILS_H 21 | #define UTILS_H 22 | 23 | #include 24 | #include 25 | 26 | #define pi 3.14159265358979323846 27 | 28 | /* Filenames */ 29 | std::string GetPluginDir(); 30 | std::string GetAirwayFilename(); 31 | std::string GetFreeNavProcedureFilename(std::string Airport, bool star=false); 32 | std::string GetGNSProcedureFilename(std::string Airport); 33 | 34 | /* Misc functions */ 35 | int CoordInRect(float x, float y, float l, float t, float r, float b); 36 | void SplitLine(std::string s, std::vector& l, char delim, size_t times = 0); 37 | double distance(double lat1d, double lon1d, double lat2d, double lon2d); 38 | 39 | #endif 40 | --------------------------------------------------------------------------------