4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "TargetMapWindow.hpp"
25 #include "Screen/Layout.hpp"
26 #include "Topography/TopographyStore.hpp"
27 #include "Topography/TopographyRenderer.hpp"
28 #include "Terrain/RasterTerrain.hpp"
29 #include "Terrain/RasterWeather.hpp"
30 #include "Look/TaskLook.hpp"
31 #include "Renderer/TaskRenderer.hpp"
32 #include "Renderer/TaskPointRenderer.hpp"
33 #include "Renderer/OZRenderer.hpp"
34 #include "Renderer/AircraftRenderer.hpp"
35 #include "Renderer/TrailRenderer.hpp"
36 #include "Task/ProtectedTaskManager.hpp"
37 #include "Units/Units.hpp"
38 #include "Interface.hpp"
39 #include "Computer/GlideComputer.hpp"
41 #include "Engine/Task/Ordered/OrderedTask.hpp"
42 #include "Engine/Task/Ordered/Points/OrderedTaskPoint.hpp"
43 #include "Engine/Task/ObservationZones/ObservationZonePoint.hpp"
44 #include "Engine/Task/ObservationZones/CylinderZone.hpp"
47 #include "Screen/OpenGL/Scissor.hpp"
49 #include "Screen/WindowCanvas.hpp"
54 static const ComputerSettings
&
57 return CommonInterface::GetComputerSettings();
60 static const MapSettings
&
63 return CommonInterface::GetMapSettings();
66 static const MoreData
&
69 return CommonInterface::Basic();
72 static const DerivedInfo
&
75 return CommonInterface::Calculated();
79 * Constructor of the MapWindow class
81 TargetMapWindow::TargetMapWindow(const WaypointLook
&waypoint_look
,
82 const AirspaceLook
&_airspace_look
,
83 const TrailLook
&_trail_look
,
84 const TaskLook
&_task_look
,
85 const AircraftLook
&_aircraft_look
)
86 :task_look(_task_look
),
87 aircraft_look(_aircraft_look
),
88 topography_renderer(NULL
),
89 airspace_renderer(_airspace_look
),
90 way_point_renderer(NULL
, waypoint_look
),
91 trail_renderer(_trail_look
),
96 TargetMapWindow::~TargetMapWindow()
98 delete topography_renderer
;
102 TargetMapWindow::Create(ContainerWindow
&parent
, PixelRect rc
,
105 projection
.SetScale(fixed(0.01));
107 BufferWindow::Create(parent
, rc
, style
);
111 TargetMapWindow::RenderTerrain(Canvas
&canvas
)
113 background
.SetShadingAngle(projection
, GetMapSettings().terrain
,
115 background
.Draw(canvas
, projection
, GetMapSettings().terrain
);
119 TargetMapWindow::RenderTopography(Canvas
&canvas
)
121 if (topography_renderer
!= NULL
&& GetMapSettings().topography_enabled
)
122 topography_renderer
->Draw(canvas
, projection
);
126 TargetMapWindow::RenderTopographyLabels(Canvas
&canvas
)
128 if (topography_renderer
!= NULL
&& GetMapSettings().topography_enabled
)
129 topography_renderer
->DrawLabels(canvas
, projection
, label_block
);
133 TargetMapWindow::RenderAirspace(Canvas
&canvas
)
135 if (GetMapSettings().airspace
.enable
)
136 airspace_renderer
.Draw(canvas
,
137 #ifndef ENABLE_OPENGL
138 buffer_canvas
, stencil_canvas
,
141 Basic(), Calculated(),
142 GetComputerSettings().airspace
,
143 GetMapSettings().airspace
);
147 TargetMapWindow::DrawTask(Canvas
&canvas
)
152 ProtectedTaskManager::Lease
task_manager(*task
);
153 const AbstractTask
*task
= task_manager
->GetActiveTask();
154 if (task
&& task
->CheckTask()) {
155 OZRenderer
ozv(task_look
, airspace_renderer
.GetLook(),
156 GetMapSettings().airspace
);
157 TaskPointRenderer
tpv(canvas
, projection
, task_look
,
158 /* we're accessing the OrderedTask here,
159 which may be invalid at this point, but it
160 will be used only if active, so it's ok */
161 task_manager
->GetOrderedTask().GetTaskProjection(),
162 ozv
, false, TaskPointRenderer::ALL
,
163 Basic().location_available
, Basic().location
);
164 TaskRenderer
dv(tpv
, projection
.GetScreenBounds());
170 TargetMapWindow::DrawWaypoints(Canvas
&canvas
)
172 const MapSettings
&settings_map
= GetMapSettings();
173 WaypointRendererSettings settings
= settings_map
.waypoint
;
174 settings
.display_text_type
= WaypointRendererSettings::DisplayTextType::NAME
;
176 way_point_renderer
.render(canvas
, label_block
,
177 projection
, settings
,
178 GetComputerSettings().polar
,
179 GetComputerSettings().task
,
180 Basic(), Calculated(),
185 TargetMapWindow::RenderTrail(Canvas
&canvas
)
187 if (glide_computer
== NULL
)
190 unsigned min_time
= std::max(0, (int)Basic().time
- 600);
191 trail_renderer
.Draw(canvas
, glide_computer
->GetTraceComputer(),
192 projection
, min_time
);
196 TargetMapWindow::OnPaintBuffer(Canvas
&canvas
)
199 /* enable clipping */
200 GLCanvasScissor
scissor(canvas
);
203 // Calculate screen position of the aircraft
204 const RasterPoint aircraft_pos
= projection
.GeoToScreen(Basic().location
);
206 // reset label over-write preventer
209 // Render terrain, groundline and topography
210 RenderTerrain(canvas
);
211 RenderTopography(canvas
);
214 RenderAirspace(canvas
);
217 /* desaturate the map background, to focus on the task */
218 canvas
.FadeToWhite(0x80);
221 // Render task, waypoints
223 DrawWaypoints(canvas
);
225 // Render the snail trail
228 // Render topography on top of airspace, to keep the text readable
229 RenderTopographyLabels(canvas
);
231 // Finally, draw you!
233 AircraftRenderer::Draw(canvas
, GetMapSettings(), aircraft_look
,
234 Basic().attitude
.heading
- projection
.GetScreenAngle(),
239 TargetMapWindow::OnPaint(Canvas
&canvas
)
241 BufferWindow::OnPaint(canvas
);
243 if (drag_mode
== DRAG_TARGET
|| drag_mode
== DRAG_OZ
)
244 TargetPaintDrag(canvas
, drag_last
);
248 TargetMapWindow::SetTerrain(RasterTerrain
*terrain
)
250 background
.SetTerrain(terrain
);
254 TargetMapWindow::SetTopograpgy(TopographyStore
*topography
)
256 delete topography_renderer
;
257 topography_renderer
= topography
!= NULL
258 ? new TopographyRenderer(*topography
)
263 GetRadius(const ObservationZonePoint
&oz
)
265 switch (oz
.GetShape()) {
266 case ObservationZone::Shape::LINE
:
267 case ObservationZone::Shape::MAT_CYLINDER
:
268 case ObservationZone::Shape::CYLINDER
:
269 case ObservationZone::Shape::SECTOR
:
270 case ObservationZone::Shape::FAI_SECTOR
:
271 case ObservationZone::Shape::CUSTOM_KEYHOLE
:
272 case ObservationZone::Shape::DAEC_KEYHOLE
:
273 case ObservationZone::Shape::BGAFIXEDCOURSE
:
274 case ObservationZone::Shape::BGAENHANCEDOPTION
:
275 case ObservationZone::Shape::BGA_START
:
276 case ObservationZone::Shape::ANNULAR_SECTOR
:
277 case ObservationZone::Shape::SYMMETRIC_QUADRANT
:
278 const CylinderZone
&cz
= (const CylinderZone
&)oz
;
279 return cz
.GetRadius();
286 GetRadius(const OrderedTaskPoint
&tp
)
288 return GetRadius(tp
.GetObservationZone());
292 TargetMapWindow::SetTarget(unsigned index
)
298 ProtectedTaskManager::Lease
lease(*task
);
299 const OrderedTask
&o_task
= lease
->GetOrderedTask();
300 if (!o_task
.IsValidIndex(index
))
303 const OrderedTaskPoint
&tp
= o_task
.GetTaskPoint(index
);
304 location
= tp
.GetLocation();
305 radius
= std::max(GetRadius(tp
) * fixed(1.3), fixed(2000));
308 projection
.SetGeoLocation(location
);
309 projection
.SetScaleFromRadius(radius
);
310 projection
.SetScreenAngle(Angle::Zero());
311 projection
.UpdateScreenBounds();
313 target_index
= index
;
319 TargetMapWindow::OnResize(PixelSize new_size
)
321 BufferWindow::OnResize(new_size
);
323 #ifndef ENABLE_OPENGL
324 buffer_canvas
.Grow(new_size
);
326 if (!IsAncientHardware())
327 stencil_canvas
.Grow(new_size
);
330 projection
.SetScreenSize(new_size
);
331 projection
.SetScreenOrigin(new_size
.cx
/ 2, new_size
.cy
/ 2);
332 projection
.UpdateScreenBounds();
336 TargetMapWindow::OnCreate()
338 BufferWindow::OnCreate();
340 drag_mode
= DRAG_NONE
;
342 #ifndef ENABLE_OPENGL
343 WindowCanvas
canvas(*this);
344 buffer_canvas
.Create(canvas
);
346 if (!IsAncientHardware())
347 stencil_canvas
.Create(canvas
);
352 TargetMapWindow::OnDestroy()
359 #ifndef ENABLE_OPENGL
360 buffer_canvas
.Destroy();
362 if (!IsAncientHardware())
363 stencil_canvas
.Destroy();
366 BufferWindow::OnDestroy();