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

Last change on this file since 4 was 2, checked in by Sanahuja Guillaume, 8 years ago

flaircore

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
30{
31namespace gui
32{
33
34using namespace core;
35
36Map::Map(const LayoutPosition* position,string name):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) && GetPersistentXmlProp(long_prop.str(),longitude)) {
46 SetVolatileXmlProp(lat_prop.str(),latitude);
47 SetVolatileXmlProp(long_prop.str(),longitude);
48 if(GetPersistentXmlProp(alt_prop.str(),altitude)) SetVolatileXmlProp(alt_prop.str(),altitude);
49 GeoCoordinate *checkpoint=new GeoCoordinate(this,"checkpoint",latitude,longitude,altitude);
50 checkpoints.push_back(checkpoint);
51 } else {
52 break;
53 }
54 i++;
55 }
56 for(size_t i=0;i<checkpoints.size();i++) {
57 double latitude,longitude,altitude;
58 checkpoints.at(i)->GetCoordinates(&latitude,&longitude,&altitude);
59 //printf("%i %f %f\n",i,latitude,longitude);
60 }
61
62 SendXml();
63/*
64 //update value from xml file
65 XmlEvent(XmlFileNode());
66 if(checkpoints_node.size()!=0) SendXml();//pour les checkpoints
67
68 //on enleve les checkpoints du xml
69 for(size_t i=0;i<checkpoints_node.size();i++)
70 {
71 xmlUnlinkNode(checkpoints_node.at(i));
72 xmlFreeNode(checkpoints_node.at(i));
73 }*/
74}
75
76Map::~Map() {
77
78}
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) && GetPersistentXmlProp(long_prop.str(),longitude)) {
93 GetPersistentXmlProp(alt_prop.str(),altitude);
94 if(i>=checkpoints.size()) {
95 GeoCoordinate *checkpoint=new GeoCoordinate(this,"checkpoint",latitude,longitude,altitude);
96 checkpoints.push_back(checkpoint);
97 //printf("add %i\n",i);
98 } else {
99 checkpoints.at(i)->SetCoordinates(latitude,longitude,altitude);
100 }
101 } else {
102 if(i==checkpoints.size()) break;
103 }
104 i++;
105 }
106
107 for(size_t i=0;i<checkpoints.size();i++) {
108 double latitude,longitude,altitude;
109 checkpoints.at(i)->GetCoordinates(&latitude,&longitude,&altitude);
110 //printf("%i %f %f\n",i,latitude,longitude);
111 }
112}
113
114void Map::AddPoint(const GeoCoordinate* point,string name) {
115 SetVolatileXmlProp("point",name);
116 SendXml();
117
118 to_draw.push_back(point);
119 SetSendSize(to_draw.size()*3*sizeof(double));//lat,long,alt
120}
121
122void Map::CopyDatas(char* buf) const {
123 for(size_t i=0;i<to_draw.size();i++) {
124 double latitude,longitude,altitude;
125 to_draw.at(i)->GetCoordinates(&latitude,&longitude,&altitude);
126 memcpy(buf+i*3*sizeof(double),&latitude,sizeof(double));
127 memcpy(buf+sizeof(double)+i*3*sizeof(double),&longitude,sizeof(double));
128 memcpy(buf+2*sizeof(double)+i*3*sizeof(double),&altitude,sizeof(double));
129 }
130}
131
132} // end namespace gui
133} // end namespace flair
Note: See TracBrowser for help on using the repository browser.