source: flair-src/trunk/lib/FlairCore/src/Map.cpp@ 26

Last change on this file since 26 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

File size: 4.0 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2013/07/23
6// filename: Map.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Class displaying a GPS map on the ground station
14//
15//
16/*********************************************************************/
17
18#include "Map.h"
19#include "LayoutPosition.h"
20#include "Layout.h"
21#include "GeoCoordinate.h"
22#include "FrameworkManager.h"
23#include <string.h>
24#include <sstream>
25
26using std::string;
27using std::ostringstream;
28
29namespace flair {
30namespace gui {
31
32using namespace core;
33
34Map::Map(const LayoutPosition *position, string name)
35 : SendData(position, name, "Map", 1000) {
36 size_t i = 0;
37 while (1) {
38 double latitude, longitude;
39 double altitude = 0;
40 ostringstream lat_prop, long_prop, alt_prop;
41 lat_prop << "lat" << i;
42 long_prop << "long" << i;
43 alt_prop << "alt" << i;
44 if (GetPersistentXmlProp(lat_prop.str(), latitude) &&
45 GetPersistentXmlProp(long_prop.str(), longitude)) {
46 SetVolatileXmlProp(lat_prop.str(), latitude);
47 SetVolatileXmlProp(long_prop.str(), longitude);
48 if (GetPersistentXmlProp(alt_prop.str(), altitude))
49 SetVolatileXmlProp(alt_prop.str(), altitude);
50 GeoCoordinate *checkpoint =
51 new GeoCoordinate(this, "checkpoint", latitude, longitude, altitude);
52 checkpoints.push_back(checkpoint);
53 } else {
54 break;
55 }
56 i++;
57 }
58 for (size_t i = 0; i < checkpoints.size(); i++) {
59 double latitude, longitude, altitude;
60 checkpoints.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
61 // printf("%i %f %f\n",i,latitude,longitude);
62 }
63
64 SendXml();
65 /*
66 //update value from xml file
67 XmlEvent(XmlFileNode());
68 if(checkpoints_node.size()!=0) SendXml();//pour les checkpoints
69
70 //on enleve les checkpoints du xml
71 for(size_t i=0;i<checkpoints_node.size();i++)
72 {
73 xmlUnlinkNode(checkpoints_node.at(i));
74 xmlFreeNode(checkpoints_node.at(i));
75 }*/
76}
77
78Map::~Map() {}
79
80void Map::ExtraXmlEvent(void) {
81
82 // attention pas rt safe (creation checkpoint)
83 size_t i = 0;
84 while (1) {
85 // printf("test %i\n",i);
86 double latitude, longitude;
87 double altitude = 0;
88 ostringstream lat_prop, long_prop, alt_prop;
89 lat_prop << "lat" << i;
90 long_prop << "long" << i;
91 alt_prop << "alt" << i;
92 if (GetPersistentXmlProp(lat_prop.str(), latitude) &&
93 GetPersistentXmlProp(long_prop.str(), longitude)) {
94 GetPersistentXmlProp(alt_prop.str(), altitude);
95 if (i >= checkpoints.size()) {
96 GeoCoordinate *checkpoint = new GeoCoordinate(
97 this, "checkpoint", latitude, longitude, altitude);
98 checkpoints.push_back(checkpoint);
99 // printf("add %i\n",i);
100 } else {
101 checkpoints.at(i)->SetCoordinates(latitude, longitude, altitude);
102 }
103 } else {
104 if (i == checkpoints.size())
105 break;
106 }
107 i++;
108 }
109
110 for (size_t i = 0; i < checkpoints.size(); i++) {
111 double latitude, longitude, altitude;
112 checkpoints.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
113 // printf("%i %f %f\n",i,latitude,longitude);
114 }
115}
116
117void Map::AddPoint(const GeoCoordinate *point, string name) {
118 SetVolatileXmlProp("point", name);
119 SendXml();
120
121 to_draw.push_back(point);
122 SetSendSize(to_draw.size() * 3 * sizeof(double)); // lat,long,alt
123}
124
125void Map::CopyDatas(char *buf) const {
126 for (size_t i = 0; i < to_draw.size(); i++) {
127 double latitude, longitude, altitude;
128 to_draw.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
129 memcpy(buf + i * 3 * sizeof(double), &latitude, sizeof(double));
130 memcpy(buf + sizeof(double) + i * 3 * sizeof(double), &longitude,
131 sizeof(double));
132 memcpy(buf + 2 * sizeof(double) + i * 3 * sizeof(double), &altitude,
133 sizeof(double));
134 }
135}
136
137} // end namespace gui
138} // end namespace flair
Note: See TracBrowser for help on using the repository browser.