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

Last change on this file since 67 was 67, checked in by Sanahuja Guillaume, 6 years ago

corrections bugs checkpoint map

File size: 4.9 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 <cmath>
24#include <string.h>
25#include <sstream>
26
27using std::string;
28using std::ostringstream;
29
30namespace flair {
31namespace gui {
32
33using namespace core;
34
35Map::Map(const LayoutPosition *position, string name)
36 : SendData(position, name, "Map", 1000) {
37 size_t i = 0;
38 while (1) {
39 double latitude, longitude;
40 double altitude = 0;
41 ostringstream lat_prop, long_prop, alt_prop;
42 lat_prop << "lat" << i;
43 long_prop << "long" << i;
44 alt_prop << "alt" << i;
45 if (GetPersistentXmlProp(lat_prop.str(), latitude) &&
46 GetPersistentXmlProp(long_prop.str(), longitude)) {
47 SetVolatileXmlProp(lat_prop.str(), latitude);
48 SetVolatileXmlProp(long_prop.str(), longitude);
49 if (GetPersistentXmlProp(alt_prop.str(), altitude))
50 SetVolatileXmlProp(alt_prop.str(), altitude);
51 GeoCoordinate *checkpoint =
52 new GeoCoordinate(this, "checkpoint", latitude, longitude, altitude);
53 checkpoints.push_back(checkpoint);
54 } else {
55 break;
56 }
57 i++;
58 }
59 for (size_t i = 0; i < checkpoints.size(); i++) {
60 double latitude, longitude, altitude;
61 checkpoints.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
62 // printf("%i %f %f\n",i,latitude,longitude);
63 }
64
65 SendXml();
66 /*
67 //update value from xml file
68 XmlEvent(XmlFileNode());
69 if(checkpoints_node.size()!=0) SendXml();//pour les checkpoints
70
71 //on enleve les checkpoints du xml
72 for(size_t i=0;i<checkpoints_node.size();i++)
73 {
74 xmlUnlinkNode(checkpoints_node.at(i));
75 xmlFreeNode(checkpoints_node.at(i));
76 }*/
77}
78
79Map::~Map() {}
80
81void Map::ExtraXmlEvent(void) {
82
83 // attention pas rt safe (creation/destruction checkpoint)
84 size_t i = 0;
85 while (1) {
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
93 if (GetPersistentXmlProp(lat_prop.str(), latitude) &&
94 GetPersistentXmlProp(long_prop.str(), longitude)) {
95 GetPersistentXmlProp(alt_prop.str(), altitude);
96
97 if (i >= checkpoints.size()) {
98 //add checkpoint
99 GeoCoordinate *checkpoint = new GeoCoordinate(
100 this, "checkpoint", latitude, longitude, altitude);
101 checkpoints.push_back(checkpoint);
102 } else if(isnan(latitude) || isnan(longitude)) {
103 //delete checkpoint
104 removeCheckpoint(i);
105 break;//si delete, la station sol n'envoit que cette info
106 } else {
107 //move checkpoint
108 checkpoints.at(i)->SetCoordinates(latitude, longitude, altitude);
109 }
110 } else {
111 if (i == checkpoints.size())
112 break;
113 }
114 i++;
115 }
116/*
117 for (size_t i = 0; i < checkpoints.size(); i++) {
118 double latitude, longitude, altitude;
119 checkpoints.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
120 printf("%i %f %f\n",i,latitude,longitude);
121 }*/
122}
123
124void Map::removeCheckpoint(size_t index) {
125 //left shift
126 for (size_t i = index; i < checkpoints.size()-1; i++) {
127 double latitude, longitude, altitude;
128 checkpoints.at(i+1)->GetCoordinates(&latitude, &longitude, &altitude);
129 checkpoints.at(i)->SetCoordinates(latitude,longitude,altitude);
130 }
131
132 //remove last one
133 delete checkpoints.back();
134 checkpoints.pop_back();
135
136 //remove last one in xml
137 ostringstream lat_prop, long_prop, alt_prop;
138 lat_prop << "lat" << checkpoints.size();
139 long_prop << "long" << checkpoints.size();
140 alt_prop << "alt" << checkpoints.size();
141 UnsetPersistentXmlProp(lat_prop.str());
142 UnsetPersistentXmlProp(long_prop.str());
143 UnsetPersistentXmlProp(alt_prop.str());
144}
145
146void Map::AddPoint(const GeoCoordinate *point, string name) {
147 SetVolatileXmlProp("point", name);
148 SendXml();
149
150 to_draw.push_back(point);
151 SetSendSize(to_draw.size() * 3 * sizeof(double)); // lat,long,alt
152}
153
154void Map::CopyDatas(char *buf) const {
155 for (size_t i = 0; i < to_draw.size(); i++) {
156 double latitude, longitude, altitude;
157 to_draw.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
158 memcpy(buf + i * 3 * sizeof(double), &latitude, sizeof(double));
159 memcpy(buf + sizeof(double) + i * 3 * sizeof(double), &longitude,
160 sizeof(double));
161 memcpy(buf + 2 * sizeof(double) + i * 3 * sizeof(double), &altitude,
162 sizeof(double));
163 }
164}
165
166} // end namespace gui
167} // end namespace flair
Note: See TracBrowser for help on using the repository browser.