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"
41 GetName(TaskPointType type
, bool mode_optional_start
)
44 case TaskPointType::UNORDERED
:
47 case TaskPointType::START
:
48 return mode_optional_start
? _T("OptionalStart") : _T("Start");
50 case TaskPointType::AST
:
53 case TaskPointType::AAT
:
56 case TaskPointType::FINISH
:
65 GetName(const OrderedTaskPoint
&tp
, bool mode_optional_start
)
67 return GetName(tp
.GetType(), mode_optional_start
);
71 Serialiser::Serialise(const OrderedTaskPoint
&data
, const TCHAR
* name
)
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());
87 Serialiser::Serialise(const OrderedTaskPoint
&tp
)
89 const TCHAR
*name
= GetName(tp
, mode_optional_start
);
90 assert(name
!= nullptr);
95 Serialiser::Serialise(const ObservationZonePoint
&data
)
97 switch (data
.GetShape()) {
98 case ObservationZone::Shape::FAI_SECTOR
:
99 node
.SetAttribute(_T("type"), _T("FAISector"));
102 case ObservationZone::Shape::SECTOR
:
103 Visit((const SectorZone
&)data
);
106 case ObservationZone::Shape::LINE
:
107 Visit((const LineSectorZone
&)data
);
110 case ObservationZone::Shape::MAT_CYLINDER
:
111 node
.SetAttribute(_T("type"), _T("MatCylinder"));
114 case ObservationZone::Shape::CYLINDER
:
115 Visit((const CylinderZone
&)data
);
118 case ObservationZone::Shape::CUSTOM_KEYHOLE
:
119 node
.SetAttribute(_T("type"), _T("CustomKeyhole"));
122 case ObservationZone::Shape::DAEC_KEYHOLE
:
123 node
.SetAttribute(_T("type"), _T("Keyhole"));
126 case ObservationZone::Shape::BGAFIXEDCOURSE
:
127 node
.SetAttribute(_T("type"), _T("BGAFixedCourse"));
130 case ObservationZone::Shape::BGAENHANCEDOPTION
:
131 node
.SetAttribute(_T("type"), _T("BGAEnhancedOption"));
134 case ObservationZone::Shape::BGA_START
:
135 node
.SetAttribute(_T("type"), _T("BGAStartSector"));
138 case ObservationZone::Shape::ANNULAR_SECTOR
:
139 Visit((const AnnularSectorZone
&)data
);
142 case ObservationZone::Shape::SYMMETRIC_QUADRANT
:
143 Visit((const SymmetricSectorZone
&)data
);
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());
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());
166 Serialiser::Visit(const AnnularSectorZone
&data
)
168 Visit((const SectorZone
&)data
);
169 node
.SetAttribute(_T("inner_radius"), data
.GetInnerRadius());
173 Serialiser::Visit(const LineSectorZone
&data
)
175 node
.SetAttribute(_T("type"), _T("Line"));
176 node
.SetAttribute(_T("length"), data
.GetLength());
180 Serialiser::Visit(const CylinderZone
&data
)
182 node
.SetAttribute(_T("type"), _T("Cylinder"));
183 node
.SetAttribute(_T("radius"), data
.GetRadius());
187 Serialiser::Serialise(const GeoPoint
&data
)
189 node
.SetAttribute(_T("longitude"), data
.longitude
);
190 node
.SetAttribute(_T("latitude"), data
.latitude
);
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
);
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
);
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())
235 mode_optional_start
= true;
236 for (const auto &tp
: task
.GetOptionalStartPoints())
241 Serialiser::GetHeightRef(AltitudeReference height_ref
) const
244 case AltitudeReference::AGL
:
246 case AltitudeReference::MSL
:
249 case AltitudeReference::STD
:
250 case AltitudeReference::NONE
:
251 /* not applicable here */
258 Serialiser::GetTaskFactoryType(TaskFactoryType type
) const
261 case TaskFactoryType::FAI_GENERAL
:
262 return _T("FAIGeneral");
263 case TaskFactoryType::FAI_TRIANGLE
:
264 return _T("FAITriangle");
265 case TaskFactoryType::FAI_OR
:
267 case TaskFactoryType::FAI_GOAL
:
268 return _T("FAIGoal");
269 case TaskFactoryType::RACING
:
271 case TaskFactoryType::AAT
:
273 case TaskFactoryType::MAT
:
275 case TaskFactoryType::MIXED
:
277 case TaskFactoryType::TOURING
:
278 return _T("Touring");
279 case TaskFactoryType::COUNT
: