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

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

change opencv include dir for testing new toolchain

File size: 4.8 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 <cmath>
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/destruction checkpoint)
83 size_t i = 0;
84 while (1) {
85 double latitude, longitude;
86 double altitude = 0;
87 ostringstream lat_prop, long_prop, alt_prop;
88 lat_prop << "lat" << i;
89 long_prop << "long" << i;
90 alt_prop << "alt" << i;
91
92 if (GetPersistentXmlProp(lat_prop.str(), latitude) &&
93 GetPersistentXmlProp(long_prop.str(), longitude)) {
94 GetPersistentXmlProp(alt_prop.str(), altitude);
95
96 if (i >= checkpoints.size()) {
97 //add checkpoint
98 GeoCoordinate *checkpoint = new GeoCoordinate(
99 this, "checkpoint", latitude, longitude, altitude);
100 checkpoints.push_back(checkpoint);
101 } else if(std::isnan(latitude) || std::isnan(longitude)) {
102 //delete checkpoint
103 removeCheckpoint(i);
104 break;//si delete, la station sol n'envoit que cette info
105 } else {
106 //move checkpoint
107 checkpoints.at(i)->SetCoordinates(latitude, longitude, altitude);
108 }
109 } else {
110 if (i == checkpoints.size())
111 break;
112 }
113 i++;
114 }
115/*
116 for (size_t i = 0; i < checkpoints.size(); i++) {
117 double latitude, longitude, altitude;
118 checkpoints.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
119 printf("%i %f %f\n",i,latitude,longitude);
120 }*/
121}
122
123void Map::removeCheckpoint(size_t index) {
124 //left shift
125 for (size_t i = index; i < checkpoints.size()-1; i++) {
126 double latitude, longitude, altitude;
127 checkpoints.at(i+1)->GetCoordinates(&latitude, &longitude, &altitude);
128 checkpoints.at(i)->SetCoordinates(latitude,longitude,altitude);
129 }
130
131 //remove last one
132 delete checkpoints.back();
133 checkpoints.pop_back();
134
135 //remove last one in xml
136 ostringstream lat_prop, long_prop, alt_prop;
137 lat_prop << "lat" << checkpoints.size();
138 long_prop << "long" << checkpoints.size();
139 alt_prop << "alt" << checkpoints.size();
140 UnsetPersistentXmlProp(lat_prop.str());
141 UnsetPersistentXmlProp(long_prop.str());
142 UnsetPersistentXmlProp(alt_prop.str());
143}
144
145void Map::AddPoint(const GeoCoordinate *point, string name) {
146 SetVolatileXmlProp("point", name);
147 SendXml();
148
149 to_draw.push_back(point);
150 SetSendSize(to_draw.size() * 3 * sizeof(double)); // lat,long,alt
151}
152
153void Map::CopyDatas(char *buf) const {
154 for (size_t i = 0; i < to_draw.size(); i++) {
155 double latitude, longitude, altitude;
156 to_draw.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
157 memcpy(buf + i * 3 * sizeof(double), &latitude, sizeof(double));
158 memcpy(buf + sizeof(double) + i * 3 * sizeof(double), &longitude,
159 sizeof(double));
160 memcpy(buf + 2 * sizeof(double) + i * 3 * sizeof(double), &altitude,
161 sizeof(double));
162 }
163}
164
165} // end namespace gui
166} // end namespace flair
Note: See TracBrowser for help on using the repository browser.