CirclingWind: eliminate attributes min_vector, max_vector
[xcsoar.git] / src / Task / Serialiser.cpp
blob02435060f5af26a939c1982140ba403559e7a118
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/KeyholeZone.hpp"
32 #include "Task/ObservationZones/AnnularSectorZone.hpp"
33 #include "Task/Factory/AbstractTaskFactory.hpp"
34 #include "XML/DataNode.hpp"
36 #include "Compiler.h"
37 #include <assert.h>
38 #include <memory>
40 gcc_const
41 static const TCHAR *
42 GetName(TaskPointType type, bool mode_optional_start)
44 switch (type) {
45 case TaskPointType::UNORDERED:
46 gcc_unreachable();
48 case TaskPointType::START:
49 return mode_optional_start ? _T("OptionalStart") : _T("Start");
51 case TaskPointType::AST:
52 return _T("Turn");
54 case TaskPointType::AAT:
55 return _T("Area");
57 case TaskPointType::FINISH:
58 return _T("Finish");
61 gcc_unreachable();
64 gcc_pure
65 static const TCHAR *
66 GetName(const OrderedTaskPoint &tp, bool mode_optional_start)
68 return GetName(tp.GetType(), mode_optional_start);
71 void
72 Serialiser::Serialise(const OrderedTaskPoint &data, const TCHAR* name)
74 // do nothing
75 std::unique_ptr<DataNode> child(node.AppendChild(_T("Point")));
76 child->SetAttribute(_T("type"), name);
78 std::unique_ptr<DataNode> wchild(child->AppendChild(_T("Waypoint")));
79 Serialiser wser(*wchild);
80 wser.Serialise(data.GetWaypoint());
82 std::unique_ptr<DataNode> ochild(child->AppendChild(_T("ObservationZone")));
83 Serialiser oser(*ochild);
84 oser.Serialise(data.GetObservationZone());
86 if (data.GetType() == TaskPointType::AST) {
87 const ASTPoint &ast = (const ASTPoint &)data;
88 if (ast.GetScoreExit())
89 child->SetAttribute(_T("score_exit"), true);
93 void
94 Serialiser::Serialise(const OrderedTaskPoint &tp)
96 const TCHAR *name = GetName(tp, mode_optional_start);
97 assert(name != nullptr);
98 Serialise(tp, name);
101 void
102 Serialiser::Serialise(const ObservationZonePoint &data)
104 switch (data.GetShape()) {
105 case ObservationZone::Shape::FAI_SECTOR:
106 node.SetAttribute(_T("type"), _T("FAISector"));
107 break;
109 case ObservationZone::Shape::SECTOR:
110 Visit((const SectorZone &)data);
111 break;
113 case ObservationZone::Shape::LINE:
114 Visit((const LineSectorZone &)data);
115 break;
117 case ObservationZone::Shape::MAT_CYLINDER:
118 node.SetAttribute(_T("type"), _T("MatCylinder"));
119 break;
121 case ObservationZone::Shape::CYLINDER:
122 Visit((const CylinderZone &)data);
123 break;
125 case ObservationZone::Shape::CUSTOM_KEYHOLE: {
126 const KeyholeZone &keyhole = (const KeyholeZone &)data;
127 node.SetAttribute(_T("type"), _T("CustomKeyhole"));
128 node.SetAttribute(_T("inner_radius"), keyhole.GetInnerRadius());
129 break;
132 case ObservationZone::Shape::DAEC_KEYHOLE:
133 node.SetAttribute(_T("type"), _T("Keyhole"));
134 break;
136 case ObservationZone::Shape::BGAFIXEDCOURSE:
137 node.SetAttribute(_T("type"), _T("BGAFixedCourse"));
138 break;
140 case ObservationZone::Shape::BGAENHANCEDOPTION:
141 node.SetAttribute(_T("type"), _T("BGAEnhancedOption"));
142 break;
144 case ObservationZone::Shape::BGA_START:
145 node.SetAttribute(_T("type"), _T("BGAStartSector"));
146 break;
148 case ObservationZone::Shape::ANNULAR_SECTOR:
149 Visit((const AnnularSectorZone &)data);
150 break;
152 case ObservationZone::Shape::SYMMETRIC_QUADRANT:
153 Visit((const SymmetricSectorZone &)data);
154 break;
158 void
159 Serialiser::Visit(const SectorZone &data)
161 node.SetAttribute(_T("type"), _T("Sector"));
162 node.SetAttribute(_T("radius"), data.GetRadius());
163 node.SetAttribute(_T("start_radial"), data.GetStartRadial());
164 node.SetAttribute(_T("end_radial"), data.GetEndRadial());
167 void
168 Serialiser::Visit(const SymmetricSectorZone &data)
170 node.SetAttribute(_T("type"), _T("SymmetricQuadrant"));
171 node.SetAttribute(_T("radius"), data.GetRadius());
172 node.SetAttribute(_T("angle"), data.GetSectorAngle());
175 void
176 Serialiser::Visit(const AnnularSectorZone &data)
178 Visit((const SectorZone&)data);
179 node.SetAttribute(_T("inner_radius"), data.GetInnerRadius());
182 void
183 Serialiser::Visit(const LineSectorZone &data)
185 node.SetAttribute(_T("type"), _T("Line"));
186 node.SetAttribute(_T("length"), data.GetLength());
189 void
190 Serialiser::Visit(const CylinderZone &data)
192 node.SetAttribute(_T("type"), _T("Cylinder"));
193 node.SetAttribute(_T("radius"), data.GetRadius());
196 void
197 Serialiser::Serialise(const GeoPoint &data)
199 node.SetAttribute(_T("longitude"), data.longitude);
200 node.SetAttribute(_T("latitude"), data.latitude);
203 void
204 Serialiser::Serialise(const Waypoint &data)
206 node.SetAttribute(_T("name"), data.name.c_str());
207 node.SetAttribute(_T("id"), data.id);
208 node.SetAttribute(_T("comment"), data.comment.c_str());
209 node.SetAttribute(_T("altitude"), data.elevation);
211 std::unique_ptr<DataNode> child(node.AppendChild(_T("Location")));
212 Serialiser ser(*child);
213 ser.Serialise(data.location);
216 void
217 Serialiser::Serialise(const OrderedTaskBehaviour &data)
219 node.SetAttribute(_T("aat_min_time"), data.aat_min_time);
220 node.SetAttribute(_T("start_max_speed"), data.start_constraints.max_speed);
221 node.SetAttribute(_T("start_max_height"), data.start_constraints.max_height);
222 node.SetAttribute(_T("start_max_height_ref"),
223 GetHeightRef(data.start_constraints.max_height_ref));
224 node.SetAttribute(_T("start_open_time"),
225 data.start_constraints.open_time_span.GetStart());
226 node.SetAttribute(_T("start_close_time"),
227 data.start_constraints.open_time_span.GetEnd());
228 node.SetAttribute(_T("finish_min_height"),
229 data.finish_constraints.min_height);
230 node.SetAttribute(_T("finish_min_height_ref"),
231 GetHeightRef(data.finish_constraints.min_height_ref));
232 node.SetAttribute(_T("fai_finish"), data.finish_constraints.fai_finish);
235 void
236 Serialiser::Serialise(const OrderedTask &task)
238 node.SetAttribute(_T("type"), GetTaskFactoryType(task.GetFactoryType()));
239 Serialise(task.GetOrderedTaskBehaviour());
240 mode_optional_start = false;
242 for (const auto &tp : task.GetPoints())
243 Serialise(tp);
245 mode_optional_start = true;
246 for (const auto &tp : task.GetOptionalStartPoints())
247 Serialise(tp);
250 const TCHAR*
251 Serialiser::GetHeightRef(AltitudeReference height_ref) const
253 switch(height_ref) {
254 case AltitudeReference::AGL:
255 return _T("AGL");
256 case AltitudeReference::MSL:
257 return _T("MSL");
259 case AltitudeReference::STD:
260 case AltitudeReference::NONE:
261 /* not applicable here */
262 break;
264 return NULL;
267 const TCHAR*
268 Serialiser::GetTaskFactoryType(TaskFactoryType type) const
270 switch(type) {
271 case TaskFactoryType::FAI_GENERAL:
272 return _T("FAIGeneral");
273 case TaskFactoryType::FAI_TRIANGLE:
274 return _T("FAITriangle");
275 case TaskFactoryType::FAI_OR:
276 return _T("FAIOR");
277 case TaskFactoryType::FAI_GOAL:
278 return _T("FAIGoal");
279 case TaskFactoryType::RACING:
280 return _T("RT");
281 case TaskFactoryType::AAT:
282 return _T("AAT");
283 case TaskFactoryType::MAT:
284 return _T("MAT");
285 case TaskFactoryType::MIXED:
286 return _T("Mixed");
287 case TaskFactoryType::TOURING:
288 return _T("Touring");
289 case TaskFactoryType::COUNT:
290 gcc_unreachable();
293 gcc_unreachable();