SectorZone: add attribute arc_boundary
[xcsoar.git] / src / Task / Serialiser.cpp
blob62181f0d4efecd9a3d1ffd79fbfbc05b6271b5ab
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Serialiser.hpp"
24 #include "Task/Ordered/OrderedTaskBehaviour.hpp"
25 #include "Task/Ordered/OrderedTask.hpp"
26 #include "Task/Ordered/Points/StartPoint.hpp"
27 #include "Task/Ordered/Points/FinishPoint.hpp"
28 #include "Task/Ordered/Points/AATPoint.hpp"
29 #include "Task/Ordered/Points/ASTPoint.hpp"
30 #include "Task/ObservationZones/LineSectorZone.hpp"
31 #include "Task/ObservationZones/AnnularSectorZone.hpp"
32 #include "Task/Factory/AbstractTaskFactory.hpp"
33 #include "XML/DataNode.hpp"
35 #include "Compiler.h"
36 #include <assert.h>
37 #include <memory>
39 gcc_const
40 static const TCHAR *
41 GetName(TaskPointType type, bool mode_optional_start)
43 switch (type) {
44 case TaskPointType::UNORDERED:
45 gcc_unreachable();
47 case TaskPointType::START:
48 return mode_optional_start ? _T("OptionalStart") : _T("Start");
50 case TaskPointType::AST:
51 return _T("Turn");
53 case TaskPointType::AAT:
54 return _T("Area");
56 case TaskPointType::FINISH:
57 return _T("Finish");
60 gcc_unreachable();
63 gcc_pure
64 static const TCHAR *
65 GetName(const OrderedTaskPoint &tp, bool mode_optional_start)
67 return GetName(tp.GetType(), mode_optional_start);
70 void
71 Serialiser::Serialise(const OrderedTaskPoint &data, const TCHAR* name)
73 // do nothing
74 std::unique_ptr<DataNode> child(node.AppendChild(_T("Point")));
75 child->SetAttribute(_T("type"), name);
77 std::unique_ptr<DataNode> wchild(child->AppendChild(_T("Waypoint")));
78 Serialiser wser(*wchild);
79 wser.Serialise(data.GetWaypoint());
81 std::unique_ptr<DataNode> ochild(child->AppendChild(_T("ObservationZone")));
82 Serialiser oser(*ochild);
83 oser.Serialise(data.GetObservationZone());
86 void
87 Serialiser::Serialise(const OrderedTaskPoint &tp)
89 const TCHAR *name = GetName(tp, mode_optional_start);
90 assert(name != nullptr);
91 Serialise(tp, name);
94 void
95 Serialiser::Serialise(const ObservationZonePoint &data)
97 switch (data.GetShape()) {
98 case ObservationZone::Shape::FAI_SECTOR:
99 node.SetAttribute(_T("type"), _T("FAISector"));
100 break;
102 case ObservationZone::Shape::SECTOR:
103 Visit((const SectorZone &)data);
104 break;
106 case ObservationZone::Shape::LINE:
107 Visit((const LineSectorZone &)data);
108 break;
110 case ObservationZone::Shape::MAT_CYLINDER:
111 node.SetAttribute(_T("type"), _T("MatCylinder"));
112 break;
114 case ObservationZone::Shape::CYLINDER:
115 Visit((const CylinderZone &)data);
116 break;
118 case ObservationZone::Shape::CUSTOM_KEYHOLE:
119 node.SetAttribute(_T("type"), _T("CustomKeyhole"));
120 break;
122 case ObservationZone::Shape::DAEC_KEYHOLE:
123 node.SetAttribute(_T("type"), _T("Keyhole"));
124 break;
126 case ObservationZone::Shape::BGAFIXEDCOURSE:
127 node.SetAttribute(_T("type"), _T("BGAFixedCourse"));
128 break;
130 case ObservationZone::Shape::BGAENHANCEDOPTION:
131 node.SetAttribute(_T("type"), _T("BGAEnhancedOption"));
132 break;
134 case ObservationZone::Shape::BGA_START:
135 node.SetAttribute(_T("type"), _T("BGAStartSector"));
136 break;
138 case ObservationZone::Shape::ANNULAR_SECTOR:
139 Visit((const AnnularSectorZone &)data);
140 break;
142 case ObservationZone::Shape::SYMMETRIC_QUADRANT:
143 Visit((const SymmetricSectorZone &)data);
144 break;
148 void
149 Serialiser::Visit(const SectorZone &data)
151 node.SetAttribute(_T("type"), _T("Sector"));
152 node.SetAttribute(_T("radius"), data.GetRadius());
153 node.SetAttribute(_T("start_radial"), data.GetStartRadial());
154 node.SetAttribute(_T("end_radial"), data.GetEndRadial());
157 void
158 Serialiser::Visit(const SymmetricSectorZone &data)
160 node.SetAttribute(_T("type"), _T("SymmetricQuadrant"));
161 node.SetAttribute(_T("radius"), data.GetRadius());
162 node.SetAttribute(_T("angle"), data.GetSectorAngle());
165 void
166 Serialiser::Visit(const AnnularSectorZone &data)
168 Visit((const SectorZone&)data);
169 node.SetAttribute(_T("inner_radius"), data.GetInnerRadius());
172 void
173 Serialiser::Visit(const LineSectorZone &data)
175 node.SetAttribute(_T("type"), _T("Line"));
176 node.SetAttribute(_T("length"), data.GetLength());
179 void
180 Serialiser::Visit(const CylinderZone &data)
182 node.SetAttribute(_T("type"), _T("Cylinder"));
183 node.SetAttribute(_T("radius"), data.GetRadius());
186 void
187 Serialiser::Serialise(const GeoPoint &data)
189 node.SetAttribute(_T("longitude"), data.longitude);
190 node.SetAttribute(_T("latitude"), data.latitude);
193 void
194 Serialiser::Serialise(const Waypoint &data)
196 node.SetAttribute(_T("name"), data.name.c_str());
197 node.SetAttribute(_T("id"), data.id);
198 node.SetAttribute(_T("comment"), data.comment.c_str());
199 node.SetAttribute(_T("altitude"), data.elevation);
201 std::unique_ptr<DataNode> child(node.AppendChild(_T("Location")));
202 Serialiser ser(*child);
203 ser.Serialise(data.location);
206 void
207 Serialiser::Serialise(const OrderedTaskBehaviour &data)
209 node.SetAttribute(_T("aat_min_time"), data.aat_min_time);
210 node.SetAttribute(_T("start_max_speed"), data.start_constraints.max_speed);
211 node.SetAttribute(_T("start_max_height"), data.start_constraints.max_height);
212 node.SetAttribute(_T("start_max_height_ref"),
213 GetHeightRef(data.start_constraints.max_height_ref));
214 node.SetAttribute(_T("start_open_time"),
215 data.start_constraints.open_time_span.GetStart());
216 node.SetAttribute(_T("start_close_time"),
217 data.start_constraints.open_time_span.GetEnd());
218 node.SetAttribute(_T("finish_min_height"),
219 data.finish_constraints.min_height);
220 node.SetAttribute(_T("finish_min_height_ref"),
221 GetHeightRef(data.finish_constraints.min_height_ref));
222 node.SetAttribute(_T("fai_finish"), data.finish_constraints.fai_finish);
225 void
226 Serialiser::Serialise(const OrderedTask &task)
228 node.SetAttribute(_T("type"), GetTaskFactoryType(task.GetFactoryType()));
229 Serialise(task.GetOrderedTaskBehaviour());
230 mode_optional_start = false;
232 for (const auto &tp : task.GetPoints())
233 Serialise(tp);
235 mode_optional_start = true;
236 for (const auto &tp : task.GetOptionalStartPoints())
237 Serialise(tp);
240 const TCHAR*
241 Serialiser::GetHeightRef(AltitudeReference height_ref) const
243 switch(height_ref) {
244 case AltitudeReference::AGL:
245 return _T("AGL");
246 case AltitudeReference::MSL:
247 return _T("MSL");
249 case AltitudeReference::STD:
250 case AltitudeReference::NONE:
251 /* not applicable here */
252 break;
254 return NULL;
257 const TCHAR*
258 Serialiser::GetTaskFactoryType(TaskFactoryType type) const
260 switch(type) {
261 case TaskFactoryType::FAI_GENERAL:
262 return _T("FAIGeneral");
263 case TaskFactoryType::FAI_TRIANGLE:
264 return _T("FAITriangle");
265 case TaskFactoryType::FAI_OR:
266 return _T("FAIOR");
267 case TaskFactoryType::FAI_GOAL:
268 return _T("FAIGoal");
269 case TaskFactoryType::RACING:
270 return _T("RT");
271 case TaskFactoryType::AAT:
272 return _T("AAT");
273 case TaskFactoryType::MAT:
274 return _T("MAT");
275 case TaskFactoryType::MIXED:
276 return _T("Mixed");
277 case TaskFactoryType::TOURING:
278 return _T("Touring");
279 case TaskFactoryType::COUNT:
280 gcc_unreachable();
283 gcc_unreachable();