You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pocketfms_fp.cc 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. Read PocketFMS flightplan files.
  3. Copyright (C) 2009 Tobias Kretschmar, tobias.kretschmar@gmx.de
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  15. */
  16. #include "defs.h"
  17. #include "xmlgeneric.h"
  18. #include <QtCore/QXmlStreamAttributes>
  19. static int isFirst = 1;
  20. static route_head* route = NULL;
  21. static Waypoint* wpt_to, *wpt_from;
  22. static double dest_altitude;
  23. #define MYNAME "PocketFMS FlightPlan"
  24. static xg_callback wpt_s, wpt_from_lat, wpt_from_lon, wpt_from_name, wpt_from_elev;
  25. static xg_callback wpt_e, wpt_to_lat, wpt_to_lon, wpt_to_name, wpt_to_elev, wpt_altitude;
  26. static xg_tag_mapping gl_map[] = {
  27. { wpt_s, cb_start, "/PocketFMSFlightplan/LIB" },
  28. { wpt_from_lat, cb_cdata, "/PocketFMSFlightplan/LIB/FromPoint/Latitude" },
  29. { wpt_from_lon, cb_cdata, "/PocketFMSFlightplan/LIB/FromPoint/Longitude" },
  30. { wpt_from_elev, cb_cdata, "/PocketFMSFlightplan/LIB/FromPoint/Elevation" },
  31. { wpt_from_name, cb_cdata, "/PocketFMSFlightplan/LIB/FromPoint/FriendlyShortname" },
  32. { wpt_to_lat, cb_cdata, "/PocketFMSFlightplan/LIB/ToPoint/Latitude" },
  33. { wpt_to_lon, cb_cdata, "/PocketFMSFlightplan/LIB/ToPoint/Longitude" },
  34. { wpt_to_name, cb_cdata, "/PocketFMSFlightplan/LIB/ToPoint/FriendlyShortname" },
  35. { wpt_to_elev, cb_cdata, "/PocketFMSFlightplan/LIB/ToPoint/Elevation" },
  36. { wpt_altitude, cb_start, "/PocketFMSFlightplan/LIB/PlannedAltitude" },
  37. { wpt_e, cb_end, "/PocketFMSFlightplan/LIB" },
  38. { NULL, (xg_cb_type)0, NULL}
  39. };
  40. static void
  41. rd_init(const QString& fname)
  42. {
  43. xml_init(fname, gl_map, NULL);
  44. }
  45. static void
  46. data_read(void)
  47. {
  48. xml_read();
  49. }
  50. static void
  51. rd_deinit(void)
  52. {
  53. if (route != NULL) {
  54. Waypoint* head = (Waypoint*) QUEUE_FIRST(&route->waypoint_list);
  55. Waypoint* tail = (Waypoint*) QUEUE_LAST(&route->waypoint_list);
  56. if (head != NULL) {
  57. route->rte_name = head->shortname;
  58. }
  59. route->rte_name += " - ";
  60. if (tail != NULL) {
  61. route->rte_name += tail->shortname;
  62. tail->altitude = dest_altitude;
  63. }
  64. }
  65. xml_deinit();
  66. }
  67. static void
  68. wr_init(const QString& fname)
  69. {
  70. fatal("Writing file of type %s is not supported\n", MYNAME);
  71. }
  72. void wpt_s(xg_string args, const QXmlStreamAttributes*)
  73. {
  74. if (isFirst == 1) {
  75. wpt_from = new Waypoint;
  76. route = route_head_alloc();
  77. route->rte_desc="PocketFMS flightplan";
  78. route_add_head(route);
  79. }
  80. wpt_to = new Waypoint;
  81. }
  82. void wpt_e(xg_string args, const QXmlStreamAttributes*)
  83. {
  84. if (isFirst == 1) {
  85. route_add_wpt(route, wpt_from);
  86. if (doing_wpts) {
  87. waypt_add(new Waypoint(*wpt_from));
  88. }
  89. wpt_from = NULL;
  90. isFirst = 0;
  91. }
  92. route_add_wpt(route, wpt_to);
  93. if (doing_wpts) {
  94. waypt_add(new Waypoint(*wpt_to));
  95. }
  96. wpt_to = NULL;
  97. }
  98. void wpt_from_lat(xg_string args, const QXmlStreamAttributes*)
  99. {
  100. if (wpt_from != NULL) {
  101. wpt_from->latitude = args.toDouble();
  102. }
  103. }
  104. void wpt_from_lon(xg_string args, const QXmlStreamAttributes*)
  105. {
  106. if (wpt_from != NULL) {
  107. wpt_from->longitude = args.toDouble();
  108. }
  109. }
  110. void wpt_from_name(xg_string args, const QXmlStreamAttributes*)
  111. {
  112. if (wpt_from != NULL) {
  113. wpt_from->shortname += args;
  114. }
  115. }
  116. void wpt_from_elev(xg_string args, const QXmlStreamAttributes*)
  117. {
  118. if (wpt_from != NULL) {
  119. wpt_from->altitude = FEET_TO_METERS(args.toDouble());
  120. }
  121. }
  122. void wpt_to_lat(xg_string args, const QXmlStreamAttributes*)
  123. {
  124. wpt_to->latitude = args.toDouble();
  125. }
  126. void wpt_to_lon(xg_string args, const QXmlStreamAttributes*)
  127. {
  128. wpt_to->longitude = args.toDouble();
  129. }
  130. void wpt_to_name(xg_string args, const QXmlStreamAttributes*)
  131. {
  132. wpt_to->shortname += args;
  133. }
  134. void wpt_to_elev(xg_string args, const QXmlStreamAttributes*)
  135. {
  136. dest_altitude = FEET_TO_METERS(args.toDouble());
  137. }
  138. void wpt_altitude(xg_string args, const QXmlStreamAttributes* attrv)
  139. {
  140. int isFeet = 0;
  141. if (attrv->hasAttribute("Value")) {
  142. wpt_to->altitude = attrv->value("Value").toString().toDouble();
  143. }
  144. if (attrv->hasAttribute("Unit")) {
  145. isFeet = (attrv->value("Unit") == "ft");
  146. }
  147. if (isFeet) {
  148. wpt_to->altitude = FEET_TO_METERS(wpt_to->altitude);
  149. }
  150. }
  151. ff_vecs_t pocketfms_fp_vecs = {
  152. ff_type_file,
  153. {
  154. ff_cap_read /* waypoints */,
  155. ff_cap_none /* tracks */,
  156. ff_cap_read /* routes */
  157. },
  158. rd_init,
  159. wr_init,
  160. rd_deinit,
  161. NULL,
  162. data_read,
  163. NULL,
  164. NULL,
  165. NULL,
  166. CET_CHARSET_ASCII, 0 /* CET-REVIEW */
  167. };