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"
42 GetName(TaskPointType type
, bool mode_optional_start
)
45 case TaskPointType::UNORDERED
:
48 case TaskPointType::START
:
49 return mode_optional_start
? _T("OptionalStart") : _T("Start");
51 case TaskPointType::AST
:
54 case TaskPointType::AAT
:
57 case TaskPointType::FINISH
:
66 GetName(const OrderedTaskPoint
&tp
, bool mode_optional_start
)
68 return GetName(tp
.GetType(), mode_optional_start
);
72 Serialiser::Serialise(const OrderedTaskPoint
&data
, const TCHAR
* name
)
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);
94 Serialiser::Serialise(const OrderedTaskPoint
&tp
)
96 const TCHAR
*name
= GetName(tp
, mode_optional_start
);
97 assert(name
!= nullptr);
102 Serialiser::Serialise(const ObservationZonePoint
&data
)
104 switch (data
.GetShape()) {
105 case ObservationZone::Shape::FAI_SECTOR
:
106 node
.SetAttribute(_T("type"), _T("FAISector"));
109 case ObservationZone::Shape::SECTOR
:
110 Visit((const SectorZone
&)data
);
113 case ObservationZone::Shape::LINE
:
114 Visit((const LineSectorZone
&)data
);
117 case ObservationZone::Shape::MAT_CYLINDER
:
118 node
.SetAttribute(_T("type"), _T("MatCylinder"));
121 case ObservationZone::Shape::CYLINDER
:
122 Visit((const CylinderZone
&)data
);
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());
132 case ObservationZone::Shape::DAEC_KEYHOLE
:
133 node
.SetAttribute(_T("type"), _T("Keyhole"));
136 case ObservationZone::Shape::BGAFIXEDCOURSE
:
137 node
.SetAttribute(_T("type"), _T("BGAFixedCourse"));
140 case ObservationZone::Shape::BGAENHANCEDOPTION
:
141 node
.SetAttribute(_T("type"), _T("BGAEnhancedOption"));
144 case ObservationZone::Shape::BGA_START
:
145 node
.SetAttribute(_T("type"), _T("BGAStartSector"));
148 case ObservationZone::Shape::ANNULAR_SECTOR
:
149 Visit((const AnnularSectorZone
&)data
);
152 case ObservationZone::Shape::SYMMETRIC_QUADRANT
:
153 Visit((const SymmetricSectorZone
&)data
);
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());
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());
176 Serialiser::Visit(const AnnularSectorZone
&data
)
178 Visit((const SectorZone
&)data
);
179 node
.SetAttribute(_T("inner_radius"), data
.GetInnerRadius());
183 Serialiser::Visit(const LineSectorZone
&data
)
185 node
.SetAttribute(_T("type"), _T("Line"));
186 node
.SetAttribute(_T("length"), data
.GetLength());
190 Serialiser::Visit(const CylinderZone
&data
)
192 node
.SetAttribute(_T("type"), _T("Cylinder"));
193 node
.SetAttribute(_T("radius"), data
.GetRadius());
197 Serialiser::Serialise(const GeoPoint
&data
)
199 node
.SetAttribute(_T("longitude"), data
.longitude
);
200 node
.SetAttribute(_T("latitude"), data
.latitude
);
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
);
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
);
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())
245 mode_optional_start
= true;
246 for (const auto &tp
: task
.GetOptionalStartPoints())
251 Serialiser::GetHeightRef(AltitudeReference height_ref
) const
254 case AltitudeReference::AGL
:
256 case AltitudeReference::MSL
:
259 case AltitudeReference::STD
:
260 case AltitudeReference::NONE
:
261 /* not applicable here */
268 Serialiser::GetTaskFactoryType(TaskFactoryType type
) const
271 case TaskFactoryType::FAI_GENERAL
:
272 return _T("FAIGeneral");
273 case TaskFactoryType::FAI_TRIANGLE
:
274 return _T("FAITriangle");
275 case TaskFactoryType::FAI_OR
:
277 case TaskFactoryType::FAI_GOAL
:
278 return _T("FAIGoal");
279 case TaskFactoryType::RACING
:
281 case TaskFactoryType::AAT
:
283 case TaskFactoryType::MAT
:
285 case TaskFactoryType::MIXED
:
287 case TaskFactoryType::TOURING
:
288 return _T("Touring");
289 case TaskFactoryType::COUNT
: