TaskStats: remove unused attribute "Time"
[xcsoar.git] / test / src / RunRenderOZ.cpp
blob70e3e94082655df1f0a0f6d2341a58e558ef1a06
1 /*
2 Copyright_License {
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.
25 * This program demonstrates the OZRenderer library. It
26 * shows a list of shapes, and draws the selected shape on the right.
30 #define ENABLE_DIALOG_LOOK
32 #include "Main.hpp"
33 #include "Screen/SingleWindow.hpp"
34 #include "Screen/ButtonWindow.hpp"
35 #include "Screen/BufferCanvas.hpp"
36 #include "Look/AirspaceLook.hpp"
37 #include "Look/TaskLook.hpp"
38 #include "Form/List.hpp"
39 #include "InfoBoxes/InfoBoxLayout.hpp"
40 #include "Renderer/OZRenderer.hpp"
41 #include "Engine/Task/ObservationZones/LineSectorZone.hpp"
42 #include "Engine/Task/ObservationZones/KeyholeZone.hpp"
43 #include "Engine/Task/ObservationZones/AnnularSectorZone.hpp"
44 #include "Engine/Task/ObservationZones/Boundary.hpp"
45 #include "Projection/Projection.hpp"
46 #include "Renderer/AirspaceRendererSettings.hpp"
48 enum {
49 NUM_OZ_TYPES = 12,
52 static const TCHAR *const oz_type_names[NUM_OZ_TYPES] = {
53 _T("Line"),
54 _T("Cylinder"),
55 _T("MAT Cylinder"),
56 _T("Sector"),
57 _T("FAI Sector"),
58 _T("DAeC Keyhole"),
59 _T("BGA Fixed Course"),
60 _T("BGA Enhanced Option"),
61 _T("BGA Start"),
62 _T("Annular sector"),
63 _T("Symmetric quadrant"),
64 _T("Custom Keyhole"),
67 static GeoPoint location(Angle::Degrees(7.7061111111111114),
68 Angle::Degrees(51.051944444444445));
70 static GeoPoint previous(Angle::Degrees(10.6),
71 Angle::Degrees(49));
73 static GeoPoint next(Angle::Degrees(10.2),
74 Angle::Degrees(51.4));
76 static AirspaceRendererSettings airspace_renderer_settings;
78 class OZWindow : public PaintWindow {
79 OZRenderer roz;
80 ObservationZonePoint *oz;
81 Projection projection;
83 public:
84 OZWindow(const TaskLook &task_look, const AirspaceLook &airspace_look)
85 :roz(task_look, airspace_look, airspace_renderer_settings), oz(NULL) {
86 projection.SetGeoLocation(location);
87 set_shape(ObservationZone::Shape::LINE);
90 ~OZWindow() {
91 delete oz;
94 void set_shape(ObservationZone::Shape shape) {
95 if (oz != NULL && shape == oz->GetShape())
96 return;
98 delete oz;
99 oz = NULL;
101 fixed radius(10000);
103 switch (shape) {
104 case ObservationZone::Shape::LINE:
105 oz = new LineSectorZone(location, 2 * radius);
106 break;
108 case ObservationZone::Shape::CYLINDER:
109 oz = new CylinderZone(location, radius);
110 break;
112 case ObservationZone::Shape::MAT_CYLINDER:
113 oz = CylinderZone::CreateMatCylinderZone(location);
114 break;
116 case ObservationZone::Shape::SECTOR:
117 oz = new SectorZone(location, radius,
118 Angle::Degrees(0), Angle::Degrees(70));
119 break;
121 case ObservationZone::Shape::ANNULAR_SECTOR:
122 oz = new AnnularSectorZone(location, radius,
123 Angle::Degrees(0), Angle::Degrees(70),
124 Half(radius));
125 break;
127 case ObservationZone::Shape::FAI_SECTOR:
128 oz = SymmetricSectorZone::CreateFAISectorZone(location);
129 break;
131 case ObservationZone::Shape::CUSTOM_KEYHOLE:
132 oz = KeyholeZone::CreateCustomKeyholeZone(location, fixed(10000),
133 Angle::QuarterCircle());
134 break;
136 case ObservationZone::Shape::DAEC_KEYHOLE:
137 oz = KeyholeZone::CreateDAeCKeyholeZone(location);
138 break;
140 case ObservationZone::Shape::BGAFIXEDCOURSE:
141 oz = KeyholeZone::CreateBGAFixedCourseZone(location);
142 break;
144 case ObservationZone::Shape::BGAENHANCEDOPTION:
145 oz = KeyholeZone::CreateBGAEnhancedOptionZone(location);
146 break;
148 case ObservationZone::Shape::BGA_START:
149 oz = KeyholeZone::CreateBGAStartSectorZone(location);
150 break;
152 case ObservationZone::Shape::SYMMETRIC_QUADRANT:
153 oz = new SymmetricSectorZone(location);
154 break;
157 if (oz != NULL)
158 oz->SetLegs(&previous, &next);
160 if (IsDefined())
161 Invalidate();
164 protected:
165 virtual void OnPaint(Canvas &canvas) override;
167 virtual void OnResize(PixelSize new_size) override {
168 PaintWindow::OnResize(new_size);
169 projection.SetScale(fixed(new_size.cx) / 21000);
170 projection.SetScreenOrigin(new_size.cx / 2, new_size.cy / 2);
174 void
175 OZWindow::OnPaint(Canvas &canvas)
177 canvas.ClearWhite();
178 if (oz == NULL)
179 return;
181 const int offset = 0;
183 roz.Draw(canvas, OZRenderer::LAYER_SHADE, projection, *oz, offset);
184 roz.Draw(canvas, OZRenderer::LAYER_INACTIVE, projection, *oz, offset);
185 roz.Draw(canvas, OZRenderer::LAYER_ACTIVE, projection, *oz, offset);
187 /* debugging for ObservationZone::GetBoundary() */
188 Pen pen(1, COLOR_RED);
189 canvas.Select(pen);
190 const OZBoundary boundary = oz->GetBoundary();
191 for (auto i = boundary.begin(), end = boundary.end(); i != end; ++i) {
192 RasterPoint p = projection.GeoToScreen(*i);
193 canvas.DrawLine(p.x - 3, p.y - 3, p.x + 3, p.y + 3);
194 canvas.DrawLine(p.x + 3, p.y - 3, p.x - 3, p.y + 3);
198 class TestWindow : public SingleWindow,
199 ListItemRenderer, ListCursorHandler {
200 ButtonWindow close_button;
201 ListControl *type_list;
202 OZWindow oz;
204 enum {
205 ID_START = 100,
206 ID_CLOSE
209 public:
210 TestWindow(const TaskLook &task_look, const AirspaceLook &airspace_look)
211 :type_list(NULL), oz(task_look, airspace_look) {}
212 ~TestWindow() {
213 delete type_list;
216 void Create(const DialogLook &look, PixelSize size) {
217 SingleWindow::Create(_T("RunRenderOZ"), size);
219 const PixelRect rc = GetClientRect();
221 WindowStyle with_border;
222 with_border.Border();
224 PixelRect oz_rc = rc;
225 oz_rc.left = oz_rc.right / 2;
226 oz.Create(*this, oz_rc, with_border);
228 const PixelRect list_rc(0, 0, rc.right / 2, rc.bottom - 30);
230 type_list = new ListControl(*this, look, list_rc,
231 with_border, 25);
233 type_list->SetItemRenderer(this);
234 type_list->SetCursorHandler(this);
235 type_list->SetLength(NUM_OZ_TYPES);
237 PixelRect button_rc = rc;
238 button_rc.right = (rc.left + rc.right) / 2;
239 button_rc.top = button_rc.bottom - 30;
240 close_button.Create(*this, _T("Close"), ID_CLOSE, button_rc);
242 oz.set_shape(ObservationZone::Shape::LINE);
244 type_list->SetFocus();
247 protected:
248 virtual bool OnCommand(unsigned id, unsigned code) override {
249 switch (id) {
250 case ID_CLOSE:
251 Close();
252 return true;
255 return SingleWindow::OnCommand(id, code);
258 /* virtual methods from ListItemRenderer */
259 virtual void OnPaintItem(Canvas &canvas, const PixelRect rc,
260 unsigned idx) override {
261 canvas.DrawText(rc.left + 2, rc.top + 2, oz_type_names[idx]);
264 /* virtual methods from ListCursorHandler */
265 virtual void OnCursorMoved(unsigned idx) override {
266 assert(idx < NUM_OZ_TYPES);
268 oz.set_shape((ObservationZone::Shape)idx);
272 static void
273 Main()
275 airspace_renderer_settings.SetDefaults();
277 TaskLook *task_look = new TaskLook();
278 task_look->Initialise();
280 AirspaceLook *airspace_look = new AirspaceLook();
281 airspace_look->Initialise(airspace_renderer_settings, normal_font);
283 TestWindow window(*task_look, *airspace_look);
284 window.Create(*dialog_look, {480, 480});
286 window.Show();
287 window.RunEventLoop();
289 delete airspace_look;
290 delete task_look;