OpenCPN Partial API docs
Loading...
Searching...
No Matches
kml.cpp
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Read and write KML Format
5 *(http://en.wikipedia.org/wiki/Keyhole_Markup_Language) Author: Jesper
6 *Weissglas
7 *
8 ***************************************************************************
9 * Copyright (C) 2012 by David S. Register *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************
26 *
27 *
28 */
29
30#include "config.h"
31
32#include <wx/wxprec.h>
33
34#ifndef WX_PRECOMP
35#include <wx/wx.h>
36#endif
37
38#include <vector>
39
40#include <wx/file.h>
41#include <wx/datetime.h>
42#include <wx/clipbrd.h>
43
44#include "model/ocpn_types.h"
45#include "navutil.h"
46#include "tinyxml.h"
47#include "kml.h"
48#include "model/track.h"
49#include "model/route.h"
50#include "ocpn_frame.h"
51#include "model/own_ship.h"
52
53int Kml::seqCounter = 0;
54bool Kml::insertQtVlmExtendedData = false;
55
56int Kml::ParseCoordinates(TiXmlNode* node, dPointList& points) {
57 TiXmlElement* e = node->FirstChildElement("coordinates");
58 if (!e) {
59 wxString msg(_T("KML Parser found no <coordinates> for the element: "));
60 msg << wxString(node->ToElement()->Value(), wxConvUTF8);
61 wxLogMessage(msg);
62 return 0;
63 }
64
65 // Parse "long,lat,z" format.
66
67 dPoint point;
68
69 std::stringstream ss(e->GetText());
70 std::string txtCoord;
71
72 while (1) {
73 if (!std::getline(ss, txtCoord, ',')) break;
74 ;
75 if (txtCoord.length() == 0) break;
76
77 point.x = atof(txtCoord.c_str());
78 std::getline(ss, txtCoord, ',');
79 point.y = atof(txtCoord.c_str());
80 std::getline(ss, txtCoord, ' ');
81 point.z = atof(txtCoord.c_str());
82
83 points.push_back(point);
84 }
85 return points.size();
86}
87
88KmlPastebufferType Kml::ParseTrack(TiXmlNode* node, wxString& name) {
89 parsedTrack = new Track();
90 parsedTrack->SetName(name);
91
92 if (0 == strncmp(node->ToElement()->Value(), "LineString", 10)) {
93 dPointList coordinates;
94 if (ParseCoordinates(node, coordinates) > 2) {
95 TrackPoint* trackpoint = NULL;
96
97 for (unsigned int i = 0; i < coordinates.size(); i++) {
98 trackpoint = new TrackPoint(coordinates[i].y, coordinates[i].x);
99 parsedTrack->AddPoint(trackpoint);
100 }
101 }
102 return KML_PASTE_TRACK;
103 }
104
105 if (0 == strncmp(node->ToElement()->Value(), "gx:Track", 8)) {
106 TrackPoint* trackpoint = NULL;
107 TiXmlElement* point = node->FirstChildElement("gx:coord");
108 int pointCounter = 0;
109
110 for (; point; point = point->NextSiblingElement("gx:coord")) {
111 double lat, lon;
112 std::stringstream ss(point->GetText());
113 std::string txtCoord;
114 std::getline(ss, txtCoord, ' ');
115 lon = atof(txtCoord.c_str());
116 std::getline(ss, txtCoord, ' ');
117 lat = atof(txtCoord.c_str());
118
119 parsedTrack->AddPoint(new TrackPoint(lat, lon));
120 pointCounter++;
121 }
122
123 TiXmlElement* when = node->FirstChildElement("when");
124
125 wxDateTime whenTime;
126
127 int i = 0;
128 for (; when; when = when->NextSiblingElement("when")) {
129 trackpoint = parsedTrack->GetPoint(i);
130 if (!trackpoint) continue;
131 whenTime.ParseFormat(wxString(when->GetText(), wxConvUTF8),
132 _T("%Y-%m-%dT%H:%M:%SZ"));
133 trackpoint->SetCreateTime(whenTime);
134 i++;
135 }
136
137 return KML_PASTE_TRACK;
138 }
139 return KML_PASTE_INVALID;
140}
141
142KmlPastebufferType Kml::ParseOnePlacemarkPoint(TiXmlNode* node,
143 wxString& name) {
144 double newLat = 0., newLon = 0.;
145 dPointList coordinates;
146
147 if (ParseCoordinates(node->ToElement(), coordinates)) {
148 newLat = coordinates[0].y;
149 newLon = coordinates[0].x;
150 }
151
152 if (newLat == 0.0 && newLon == 0.0) {
153 wxString msg(_T("KML Parser failed to convert <Point> coordinates."));
154 wxLogMessage(msg);
155 return KML_PASTE_INVALID;
156 }
157 wxString pointName = wxEmptyString;
158 TiXmlElement* e = node->Parent()->FirstChild("name")->ToElement();
159 if (e) pointName = wxString(e->GetText(), wxConvUTF8);
160
161 wxString pointDescr = wxEmptyString;
162 e = node->Parent()->FirstChildElement("description");
163
164 // If the <description> is an XML element we must convert it to text,
165 // otherwise it gets lost.
166 if (e) {
167 TiXmlNode* n = e->FirstChild();
168 if (n) switch (n->Type()) {
169 case TiXmlNode::TINYXML_TEXT:
170 pointDescr = wxString(e->GetText(), wxConvUTF8);
171 break;
172 case TiXmlNode::TINYXML_ELEMENT:
173 TiXmlPrinter printer;
174 printer.SetIndent("\t");
175 n->Accept(&printer);
176 pointDescr = wxString(printer.CStr(), wxConvUTF8);
177 break;
178 }
179 }
180
181 // Extended data will override description.
182 TiXmlNode* n = node->Parent()->FirstChild("ExtendedData");
183 if (n) {
184 TiXmlPrinter printer;
185 printer.SetIndent("\t");
186 n->Accept(&printer);
187 pointDescr = wxString(printer.CStr(), wxConvUTF8);
188 }
189
190 // XXX leak ?
191 parsedRoutePoint = new RoutePoint();
192 parsedRoutePoint->m_lat = newLat;
193 parsedRoutePoint->m_lon = newLon;
194 parsedRoutePoint->m_bIsolatedMark = true;
195 parsedRoutePoint->m_bPtIsSelected = false;
196 parsedRoutePoint->m_MarkDescription = pointDescr;
197 parsedRoutePoint->SetName(pointName);
198
199 return KML_PASTE_WAYPOINT;
200}
201
202KmlPastebufferType Kml::ParsePasteBuffer() {
203 if (!wxTheClipboard->IsOpened())
204 if (!wxTheClipboard->Open()) return KML_PASTE_INVALID;
205
206 wxTextDataObject data;
207 wxTheClipboard->GetData(data);
208 kmlText = data.GetText();
209 wxTheClipboard->Close();
210
211 if (kmlText.Find(_T("<kml")) == wxNOT_FOUND) return KML_PASTE_INVALID;
212
213 TiXmlDocument doc;
214 if (!doc.Parse(kmlText.mb_str(wxConvUTF8), 0, TIXML_ENCODING_UTF8)) {
215 wxLogError(wxString(doc.ErrorDesc(), wxConvUTF8));
216 return KML_PASTE_INVALID;
217 }
218 if (0 != strncmp(doc.RootElement()->Value(), "kml", 3))
219 return KML_PASTE_INVALID;
220
221 TiXmlHandle docHandle(doc.RootElement());
222
223 // We may or may not have a <document> depending on what the user copied.
224 TiXmlElement* placemark =
225 docHandle.FirstChild("Document").FirstChild("Placemark").ToElement();
226 if (!placemark) {
227 placemark = docHandle.FirstChild("Placemark").ToElement();
228 }
229 if (!placemark) {
230 wxString msg(_T("KML Parser found no <Placemark> tag in the KML."));
231 wxLogMessage(msg);
232 return KML_PASTE_INVALID;
233 }
234
235 int pointCounter = 0;
236 wxString name;
237 for (; placemark; placemark = placemark->NextSiblingElement()) {
238 TiXmlElement* e = placemark->FirstChildElement("name");
239 if (e) name = wxString(e->GetText(), wxConvUTF8);
240 pointCounter++;
241 }
242
243 if (pointCounter == 1) {
244 // Is it a single waypoint?
245 TiXmlNode* element = docHandle.FirstChild("Document")
246 .FirstChild("Placemark")
247 .FirstChild("Point")
248 .ToNode();
249 if (!element)
250 element = docHandle.FirstChild("Placemark").FirstChild("Point").ToNode();
251 if (element) return ParseOnePlacemarkPoint(element, name);
252
253 // Is it a dumb <LineString> track?
254 element = docHandle.FirstChild("Document")
255 .FirstChild("Placemark")
256 .FirstChild("LineString")
257 .ToNode();
258 if (!element)
259 element =
260 docHandle.FirstChild("Placemark").FirstChild("LineString").ToNode();
261 if (element) return ParseTrack(element, name);
262
263 // Is it a smart extended <gx:track> track?
264 element = docHandle.FirstChild("Document")
265 .FirstChild("Placemark")
266 .FirstChild("gx:Track")
267 .ToNode();
268 if (!element)
269 element =
270 docHandle.FirstChild("Placemark").FirstChild("gx:Track").ToNode();
271 if (element) return ParseTrack(element, name);
272
273 wxString msg(
274 _T("KML Parser found a single <Placemark> in the KML, but no useable ")
275 _T("data in it."));
276 wxLogMessage(msg);
277 return KML_PASTE_INVALID;
278 }
279
280 // Here we go with a full route.
281
282 parsedRoute = new Route();
283 bool foundPoints = false;
284 bool foundTrack = false;
285 TiXmlElement* element =
286 docHandle.FirstChild("Document").FirstChild("name").ToElement();
287 if (element)
288 parsedRoute->m_RouteNameString = wxString(element->GetText(), wxConvUTF8);
289
290 placemark =
291 docHandle.FirstChild("Document").FirstChild("Placemark").ToElement();
292 for (; placemark; placemark = placemark->NextSiblingElement()) {
293 TiXmlNode* n = placemark->FirstChild("Point");
294 if (n) {
295 if (ParseOnePlacemarkPoint(n->ToElement(), name) == KML_PASTE_WAYPOINT) {
296 parsedRoute->AddPoint(new RoutePoint(parsedRoutePoint));
297 delete parsedRoutePoint;
298 parsedRoutePoint = 0;
299 foundPoints = true;
300 }
301 }
302
303 n = placemark->FirstChild("LineString");
304 if (n) {
305 ParseTrack(n->ToElement(), name);
306 foundTrack = true;
307 }
308 n = placemark->FirstChild("gx:Track");
309 if (n) {
310 ParseTrack(n->ToElement(), name);
311 foundTrack = true;
312 }
313 }
314
315 if (foundPoints && parsedRoute->GetnPoints() < 2) {
316 wxString msg(
317 _T("KML Parser did not find enough <Point>s to make a route."));
318 wxLogMessage(msg);
319 foundPoints = false;
320 }
321
322 if (foundPoints && !foundTrack) return KML_PASTE_ROUTE;
323 if (foundPoints && foundTrack) return KML_PASTE_ROUTE_TRACK;
324 if (!foundPoints && foundTrack) return KML_PASTE_TRACK;
325 return KML_PASTE_INVALID;
326}
327
328TiXmlElement* Kml::StandardHead(TiXmlDocument& xmlDoc, wxString name) {
329 TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "");
330 xmlDoc.LinkEndChild(decl);
331
332 TiXmlElement* kml = new TiXmlElement("kml");
333 kml->SetAttribute("xmlns:atom", "http://www.w3.org/2005/Atom");
334 kml->SetAttribute("xmlns", "http://www.opengis.net/kml/2.2");
335 kml->SetAttribute("xmlns:gx", "http://www.google.com/kml/ext/2.2");
336 kml->SetAttribute("xmlns:kml", "http://www.opengis.net/kml/2.2");
337
338 if (insertQtVlmExtendedData)
339 kml->SetAttribute("xmlns:vlm", "http://virtual-loup-de-mer.org");
340
341 xmlDoc.LinkEndChild(kml);
342
343 TiXmlElement* document = new TiXmlElement("Document");
344 kml->LinkEndChild(document);
345 TiXmlElement* docName = new TiXmlElement("name");
346 document->LinkEndChild(docName);
347 TiXmlText* docNameVal = new TiXmlText(name.mb_str(wxConvUTF8));
348 docName->LinkEndChild(docNameVal);
349 return document;
350}
351
352std::string Kml::PointPlacemark(TiXmlElement* document,
353 RoutePoint* routepoint) {
354 TiXmlElement* pmPoint = new TiXmlElement("Placemark");
355 document->LinkEndChild(pmPoint);
356 TiXmlElement* pmPointName = new TiXmlElement("name");
357 pmPoint->LinkEndChild(pmPointName);
358 TiXmlText* pmPointNameVal =
359 new TiXmlText(routepoint->GetName().mb_str(wxConvUTF8));
360 pmPointName->LinkEndChild(pmPointNameVal);
361
362 TiXmlElement* pointDescr = new TiXmlElement("description");
363 pmPoint->LinkEndChild(pointDescr);
364
365 bool descrIsPlainText = true;
366 wxCharBuffer descrString = routepoint->m_MarkDescription.mb_str(wxConvUTF8);
367
368 if (insertQtVlmExtendedData) {
369 // Does the RoutePoint description parse as XML with an <ExtendedData> root
370 // tag?
371 TiXmlDocument descrDoc;
372 TiXmlElement* extendedData;
373 if (descrDoc.Parse(descrString, 0, TIXML_ENCODING_UTF8)) {
374 if (0 == strncmp(descrDoc.RootElement()->Value(), "ExtendedData", 12)) {
375 descrIsPlainText = false;
376 extendedData = descrDoc.RootElement();
377 TiXmlHandle docHandle(&descrDoc);
378 TiXmlElement* seq = docHandle.FirstChild("ExtendedData")
379 .FirstChild("vlm:sequence")
380 .ToElement();
381 if (!seq) {
382 seq = new TiXmlElement("vlm:sequence");
383 TiXmlText* snVal = new TiXmlText(
384 wxString::Format(_T("%04d"), seqCounter).mb_str(wxConvUTF8));
385 seq->LinkEndChild(snVal);
386 descrDoc.RootElement()->LinkEndChild(seq);
387 }
388 pmPoint->LinkEndChild(descrDoc.RootElement()->Clone());
389 }
390 }
391 if (descrIsPlainText) {
392 // We want Sequence names but there was some non-parsing stuff in the
393 // description. Push that into a sub-tag of an XML formatted description.
394 extendedData = new TiXmlElement("ExtendedData");
395 pmPoint->LinkEndChild(extendedData);
396 TiXmlElement* seq = new TiXmlElement("vlm:sequence");
397 extendedData->LinkEndChild(seq);
398 TiXmlText* snVal = new TiXmlText(
399 wxString::Format(_T("%04d"), seqCounter).mb_str(wxConvUTF8));
400 seq->LinkEndChild(snVal);
401
402 if (routepoint->m_MarkDescription.Length()) {
403 TiXmlElement* data = new TiXmlElement("Data");
404 data->SetAttribute("name", "Description");
405 extendedData->LinkEndChild(data);
406
407 TiXmlElement* value = new TiXmlElement("value");
408 data->LinkEndChild(value);
409 TiXmlText* txtVal = new TiXmlText(descrString);
410 value->LinkEndChild(txtVal);
411 }
412 }
413 if (extendedData && seqCounter == 0) {
414 const wxCharBuffer ownshipPos =
415 wxString::Format(_T("%f %f"), gLon, gLat).mb_str(wxConvUTF8);
416 TiXmlHandle h(extendedData);
417 TiXmlElement* route = h.FirstChild("vlm:route").ToElement();
418 TiXmlElement* ownship =
419 h.FirstChild("vlm:route").FirstChild("ownship").ToElement();
420 if (route) {
421 if (ownship) {
422 TiXmlText* owns = ownship->FirstChild()->ToText();
423 if (owns) {
424 owns->SetValue(ownshipPos);
425 } else {
426 owns = new TiXmlText(ownshipPos);
427 ownship->LinkEndChild(owns);
428 }
429 } else {
430 ownship = new TiXmlElement("ownship");
431 route->LinkEndChild(ownship);
432 TiXmlText* owns = new TiXmlText(ownshipPos);
433 ownship->LinkEndChild(owns);
434 }
435 } else {
436 route = new TiXmlElement("vlm:route");
437 extendedData->LinkEndChild(route);
438 ownship = new TiXmlElement("ownship");
439 route->LinkEndChild(ownship);
440 TiXmlText* owns = new TiXmlText(ownshipPos);
441 ownship->LinkEndChild(owns);
442 }
443 }
444 }
445
446 else {
447 // Add description as dumb text.
448 TiXmlText* pointDescrVal = new TiXmlText(descrString);
449 pointDescr->LinkEndChild(pointDescrVal);
450 }
451
452 TiXmlElement* point = new TiXmlElement("Point");
453 pmPoint->LinkEndChild(point);
454
455 TiXmlElement* pointCoord = new TiXmlElement("coordinates");
456 point->LinkEndChild(pointCoord);
457
458 std::stringstream pointCoordStr;
459 pointCoordStr << routepoint->m_lon << "," << routepoint->m_lat << ",0. ";
460
461 TiXmlText* pointText = new TiXmlText(pointCoordStr.str());
462 pointCoord->LinkEndChild(pointText);
463
464 return pointCoordStr.str();
465}
466
467wxString Kml::MakeKmlFromRoute(Route* route, bool insertSeq) {
468 insertQtVlmExtendedData = insertSeq;
469 seqCounter = 0;
470 TiXmlDocument xmlDoc;
471 wxString name = _("OpenCPN Route");
472 if (route->m_RouteNameString.Length()) name = route->m_RouteNameString;
473 TiXmlElement* document = StandardHead(xmlDoc, name);
474
475 std::stringstream lineStringCoords;
476
477 RoutePointList* pointList = route->pRoutePointList;
478 wxRoutePointListNode* pointnode = pointList->GetFirst();
479 RoutePoint* routepoint;
480
481 while (pointnode) {
482 routepoint = pointnode->GetData();
483
484 lineStringCoords << PointPlacemark(document, routepoint);
485 seqCounter++;
486 pointnode = pointnode->GetNext();
487 }
488
489 TiXmlElement* pmPath = new TiXmlElement("Placemark");
490 document->LinkEndChild(pmPath);
491
492 TiXmlElement* pmName = new TiXmlElement("name");
493 pmPath->LinkEndChild(pmName);
494 TiXmlText* pmNameVal = new TiXmlText("Path");
495 pmName->LinkEndChild(pmNameVal);
496
497 TiXmlElement* linestring = new TiXmlElement("LineString");
498 pmPath->LinkEndChild(linestring);
499
500 TiXmlElement* coordinates = new TiXmlElement("coordinates");
501 linestring->LinkEndChild(coordinates);
502
503 TiXmlText* text = new TiXmlText(lineStringCoords.str());
504 coordinates->LinkEndChild(text);
505
506 TiXmlPrinter printer;
507 printer.SetIndent(" ");
508 xmlDoc.Accept(&printer);
509
510 return wxString(printer.CStr(), wxConvUTF8);
511}
512
513wxString Kml::MakeKmlFromTrack(Track* track) {
514 TiXmlDocument xmlDoc;
515 wxString name = _("OpenCPN Track");
516 if (track->GetName().Length()) name = track->GetName();
517 TiXmlElement* document = StandardHead(xmlDoc, name);
518
519 TiXmlElement* pmTrack = new TiXmlElement("Placemark");
520 document->LinkEndChild(pmTrack);
521
522 TiXmlElement* pmName = new TiXmlElement("name");
523 pmTrack->LinkEndChild(pmName);
524 TiXmlText* pmNameVal = new TiXmlText(track->GetName().mb_str(wxConvUTF8));
525 pmName->LinkEndChild(pmNameVal);
526
527 TiXmlElement* gxTrack = new TiXmlElement("gx:Track");
528 pmTrack->LinkEndChild(gxTrack);
529
530 std::stringstream lineStringCoords;
531
532 for (int i = 0; i < track->GetnPoints(); i++) {
533 TrackPoint* trackpoint = track->GetPoint(i);
534
535 TiXmlElement* when = new TiXmlElement("when");
536 gxTrack->LinkEndChild(when);
537
538 wxDateTime whenTime(trackpoint->GetCreateTime());
539 TiXmlText* whenVal = new TiXmlText(
540 whenTime.Format(_T("%Y-%m-%dT%H:%M:%SZ")).mb_str(wxConvUTF8));
541 when->LinkEndChild(whenVal);
542 }
543
544 for (int i = 0; i < track->GetnPoints(); i++) {
545 TrackPoint* trackpoint = track->GetPoint(i);
546
547 TiXmlElement* coord = new TiXmlElement("gx:coord");
548 gxTrack->LinkEndChild(coord);
549 wxString coordStr =
550 wxString::Format(_T("%f %f 0.0"), trackpoint->m_lon, trackpoint->m_lat);
551 TiXmlText* coordVal = new TiXmlText(coordStr.mb_str(wxConvUTF8));
552 coord->LinkEndChild(coordVal);
553 }
554
555 TiXmlPrinter printer;
556 printer.SetIndent(" ");
557 xmlDoc.Accept(&printer);
558
559 return wxString(printer.CStr(), wxConvUTF8);
560}
561
562wxString Kml::MakeKmlFromWaypoint(RoutePoint* routepoint) {
563 TiXmlDocument xmlDoc;
564 wxString name = _("OpenCPN Waypoint");
565 if (routepoint->GetName().Length()) name = routepoint->GetName();
566 TiXmlElement* document = StandardHead(xmlDoc, name);
567
568 insertQtVlmExtendedData = false;
569 PointPlacemark(document, routepoint);
570
571 TiXmlPrinter printer;
572 printer.SetIndent(" ");
573 xmlDoc.Accept(&printer);
574
575 return wxString(printer.CStr(), wxConvUTF8);
576}
577
578void Kml::CopyRouteToClipboard(Route* route) {
579 KmlFormatDialog* formatDlg = new KmlFormatDialog(wxTheApp->GetTopWindow());
580 int format = formatDlg->ShowModal();
581
582 if (format != wxID_CANCEL) {
583 format = formatDlg->GetSelectedFormat();
584 bool extradata = (format == KML_COPY_EXTRADATA);
585
586 ::wxBeginBusyCursor();
587 if (wxTheClipboard->Open()) {
588 wxTextDataObject* data = new wxTextDataObject;
589 data->SetText(MakeKmlFromRoute(route, extradata));
590 wxTheClipboard->SetData(data);
591 }
592 ::wxEndBusyCursor();
593 }
594 delete formatDlg;
595}
596
597void Kml::CopyTrackToClipboard(Track* track) {
598 ::wxBeginBusyCursor();
599 if (wxTheClipboard->Open()) {
600 wxTextDataObject* data = new wxTextDataObject;
601 data->SetText(MakeKmlFromTrack(track));
602 wxTheClipboard->SetData(data);
603 }
604 ::wxEndBusyCursor();
605}
606
607void Kml::CopyWaypointToClipboard(RoutePoint* rp) {
608 if (wxTheClipboard->Open()) {
609 wxTextDataObject* data = new wxTextDataObject;
610 data->SetText(MakeKmlFromWaypoint(rp));
611 wxTheClipboard->SetData(data);
612 }
613}
614
615Kml::Kml() {
616 parsedRoute = NULL;
617 parsedTrack = NULL;
618 parsedRoutePoint = NULL;
619}
620
621Kml::~Kml() {
622 delete parsedTrack;
623 if (parsedRoute) {
624 for (int i = 1; i <= parsedRoute->GetnPoints(); i++) {
625 if (parsedRoute->GetPoint(i)) delete parsedRoute->GetPoint(i);
626 }
627 delete parsedRoute;
628 }
629 delete parsedRoutePoint;
630}
631
632//----------------------------------------------------------------------------------
633
634KmlFormatDialog::KmlFormatDialog(wxWindow* parent)
635 : wxDialog(parent, wxID_ANY, _("Choose Format for Copy"), wxDefaultPosition,
636 wxSize(250, 230)) {
637 wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
638
639 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
640 topSizer->Add(sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
641
642 choices.push_back(new wxRadioButton(
643 this, KML_COPY_STANDARD, _("KML Standard (Google Earth and others)"),
644 wxDefaultPosition, wxDefaultSize, wxRB_GROUP));
645
646 choices.push_back(new wxRadioButton(
647 this, KML_COPY_EXTRADATA, _("KML with extended waypoint data (QtVlm)"),
648 wxDefaultPosition));
649
650 wxStdDialogButtonSizer* buttonSizer =
651 CreateStdDialogButtonSizer(wxOK | wxCANCEL);
652
653 sizer->Add(choices[0], 0, wxEXPAND | wxALL, 5);
654 sizer->Add(choices[1], 0, wxEXPAND | wxALL, 5);
655 sizer->Add(buttonSizer, 0, wxEXPAND | wxTOP, 5);
656
657 topSizer->SetSizeHints(this);
658 SetSizer(topSizer);
659}
660
661int KmlFormatDialog::GetSelectedFormat() {
662 for (unsigned int i = 0; i < choices.size(); i++) {
663 if (choices[i]->GetValue()) return choices[i]->GetId();
664 }
665 return 0;
666}
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
Represents a navigational route in the navigation system.
Definition route.h:98
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
Definition route.h:335
wxString m_RouteNameString
User-assigned name for the route.
Definition route.h:246
Represents a single point in a track.
Definition track.h:53
wxDateTime GetCreateTime(void)
Retrieves the creation timestamp of a track point as a wxDateTime object.
Definition track.cpp:139
void SetCreateTime(wxDateTime dt)
Sets the creation timestamp for a track point.
Definition track.cpp:145
Represents a track, which is a series of connected track points.
Definition track.h:111
Definition kml.h:47