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.

ik3d.cc 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. Support for "MagicMaps" project files (.ikt)
  3. Copyright (C) 2008 Olaf Klein, o.b.klein@gpsbabel.org
  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 arglist_t ikt_args[] = {
  20. ARG_TERMINATOR
  21. };
  22. #define MYNAME "ikt"
  23. static QString name, text;
  24. static route_head* track;
  25. static Waypoint* waypt;
  26. static xg_callback iktobj_waypt, iktobj_type, iktobj_name, iktobj_trkpt, iktobj_text;
  27. #define IKTOBJ "/Root/Content/MMGeoObjects/MMGeoObject"
  28. /* Here we are working with wildcards in the tag list.
  29. Please ensure that the longest entries comes first */
  30. static
  31. xg_tag_mapping ikt_map[] = {
  32. { iktobj_trkpt, cb_start, IKTOBJ "_*/PathPoints/Point_*/GeoPosition" },
  33. { iktobj_type, cb_cdata, IKTOBJ "_*/GeoObjectType" },
  34. { iktobj_waypt, cb_start, IKTOBJ "_*/GeoPosition" },
  35. { iktobj_name, cb_cdata, IKTOBJ "_*/Name" },
  36. { iktobj_text, cb_cdata, IKTOBJ "_*/POIDrawable2D/Text" },
  37. { NULL, (xg_cb_type)0, NULL }
  38. };
  39. static void
  40. ikt_object_end(void)
  41. {
  42. if (track) {
  43. track->rte_name = name;
  44. track_add_head(track);
  45. } else if (waypt) {
  46. waypt->shortname = name;
  47. waypt->description = text;
  48. waypt_add(waypt);
  49. }
  50. name = QString();
  51. text = QString();
  52. track = NULL;
  53. waypt = NULL;
  54. }
  55. static void
  56. iktobj_waypt(xg_string args, const QXmlStreamAttributes* attrv)
  57. {
  58. if (attrv->hasAttribute("X")) {
  59. waypt->longitude = attrv->value("X").toString().toDouble();
  60. }
  61. if (attrv->hasAttribute("Y")) {
  62. waypt->latitude = attrv->value("Y").toString().toDouble();
  63. }
  64. }
  65. static void
  66. iktobj_trkpt(xg_string args, const QXmlStreamAttributes* attrv)
  67. {
  68. waypt = new Waypoint;
  69. iktobj_waypt(args, attrv);
  70. track_add_wpt(track, waypt);
  71. waypt = NULL;
  72. }
  73. static void
  74. iktobj_name(xg_string args, const QXmlStreamAttributes*)
  75. {
  76. name = args;
  77. }
  78. static void
  79. iktobj_text(xg_string args, const QXmlStreamAttributes*)
  80. {
  81. text = args;
  82. }
  83. static void
  84. iktobj_type(xg_string args, const QXmlStreamAttributes*)
  85. {
  86. ikt_object_end();
  87. switch (args.toInt()) {
  88. case 0:
  89. waypt = new Waypoint;
  90. break;
  91. case 1:
  92. track = route_head_alloc();
  93. break;
  94. default:
  95. fatal(MYNAME ": Unknown object type %s!\n", qPrintable(args));
  96. }
  97. }
  98. static void
  99. ikt_rd_init(const QString& fname)
  100. {
  101. xml_init(fname, ikt_map, NULL);
  102. track = NULL;
  103. waypt = NULL;
  104. name = QString();
  105. text = QString();
  106. }
  107. static void
  108. ikt_read(void)
  109. {
  110. xml_read();
  111. }
  112. static void
  113. ikt_rd_deinit(void)
  114. {
  115. ikt_object_end();
  116. xml_deinit();
  117. }
  118. ff_vecs_t ik3d_vecs = {
  119. ff_type_file,
  120. {
  121. ff_cap_read, /* waypoints */
  122. ff_cap_read, /* tracks */
  123. ff_cap_none /* routes */
  124. },
  125. ikt_rd_init,
  126. NULL,
  127. ikt_rd_deinit,
  128. NULL,
  129. ikt_read,
  130. NULL,
  131. NULL,
  132. ikt_args,
  133. CET_CHARSET_UTF8, 1
  134. };