Revert "Device/Driver/LX: Add small delay after baud rate change"
[xcsoar.git] / test / src / RunMapWindow.cpp
blobf5a2d8b3120599a2052e5ebfc92160e2bb03c490
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.
24 #include "MapWindow/MapWindow.hpp"
25 #include "Screen/SingleWindow.hpp"
26 #include "Screen/ButtonWindow.hpp"
27 #include "Screen/Init.hpp"
28 #include "ResourceLoader.hpp"
29 #include "Terrain/RasterWeather.hpp"
30 #include "Terrain/RasterTerrain.hpp"
31 #include "Profile/ProfileKeys.hpp"
32 #include "Profile/ComputerProfile.hpp"
33 #include "Profile/MapProfile.hpp"
34 #include "LocalPath.hpp"
35 #include "Waypoint/WaypointGlue.hpp"
36 #include "Topography/TopographyStore.hpp"
37 #include "Topography/TopographyGlue.hpp"
38 #include "Blackboard/DeviceBlackboard.hpp"
39 #include "Airspace/AirspaceParser.hpp"
40 #include "Profile/Profile.hpp"
41 #include "Engine/Waypoint/Waypoints.hpp"
42 #include "Engine/Airspace/Airspaces.hpp"
43 #include "LogFile.hpp"
44 #include "IO/ConfiguredFile.hpp"
45 #include "Operation/Operation.hpp"
46 #include "Look/MapLook.hpp"
47 #include "Look/TrafficLook.hpp"
48 #include "Look/Fonts.hpp"
49 #include "Thread/Debug.hpp"
51 void
52 DeviceBlackboard::SetStartupLocation(const GeoPoint &loc, const fixed alt) {}
54 #ifndef NDEBUG
56 bool
57 InDrawThread()
59 return InMainThread();
62 #endif
64 static Waypoints way_points;
66 static Airspaces airspace_database;
68 static TopographyStore *topography;
69 static RasterTerrain *terrain;
71 class DrawThread {
72 public:
73 #ifndef ENABLE_OPENGL
74 static void Draw(MapWindow &map) {
75 map.Repaint();
76 map.UpdateAll();
77 map.Repaint();
79 #else
80 static void UpdateAll(MapWindow &map) {
81 map.UpdateAll();
83 #endif
86 class TestWindow : public SingleWindow {
87 public:
88 MapWindow map;
89 ButtonWindow close_button;
91 #ifndef ENABLE_OPENGL
92 bool initialised;
93 #endif
95 enum {
96 ID_START = 100,
97 ID_CLOSE,
100 public:
101 TestWindow(const MapLook &map_look,
102 const TrafficLook &traffic_look)
103 :map(map_look, traffic_look)
104 #ifndef ENABLE_OPENGL
105 , initialised(false)
106 #endif
110 void Create(PixelSize size) {
111 TopWindowStyle style;
112 style.Resizable();
114 SingleWindow::Create(_T("RunMapWindow"), size, style);
116 PixelRect rc = GetClientRect();
117 map.Create(*this, rc);
118 map.SetWaypoints(&way_points);
119 map.SetAirspaces(&airspace_database);
120 map.SetTopography(topography);
121 map.SetTerrain(terrain);
122 if (terrain != NULL)
123 map.SetLocation(terrain->GetTerrainCenter());
125 rc.left = 5;
126 rc.top = 5;
127 rc.right = rc.left + 60;
128 rc.bottom = rc.top + 20;
129 close_button.Create(*this, _T("Close"), ID_CLOSE, rc);
130 close_button.SetFont(Fonts::map);
131 close_button.BringToTop();
134 protected:
135 virtual bool OnCommand(unsigned id, unsigned code) override {
136 switch (id) {
137 case ID_CLOSE:
138 Close();
139 return true;
142 return TopWindow::OnCommand(id, code);
145 virtual void OnResize(PixelSize new_size) override {
146 SingleWindow::OnResize(new_size);
148 if (map.IsDefined())
149 map.Resize(new_size);
151 #ifndef ENABLE_OPENGL
152 if (initialised)
153 DrawThread::Draw(map);
154 #endif
158 static void
159 LoadFiles(PlacesOfInterestSettings &poi_settings,
160 TeamCodeSettings &team_code_settings)
162 NullOperationEnvironment operation;
164 topography = new TopographyStore();
165 LoadConfiguredTopography(*topography, operation);
167 terrain = RasterTerrain::OpenTerrain(NULL, operation);
169 WaypointGlue::LoadWaypoints(way_points, terrain, operation);
170 WaypointGlue::SetHome(way_points, terrain, poi_settings, team_code_settings,
171 NULL, false);
173 std::unique_ptr<TLineReader> reader(OpenConfiguredTextFile(ProfileKeys::AirspaceFile,
174 ConvertLineReader::AUTO));
175 if (reader) {
176 AirspaceParser parser(airspace_database);
177 parser.Parse(*reader, operation);
178 airspace_database.Optimise();
182 static void
183 GenerateBlackboard(MapWindow &map, const ComputerSettings &settings_computer,
184 const MapSettings &settings_map)
186 MoreData nmea_info;
187 DerivedInfo derived_info;
189 nmea_info.Reset();
190 nmea_info.clock = fixed(1);
191 nmea_info.time = fixed(1297230000);
192 nmea_info.alive.Update(nmea_info.clock);
194 if (settings_computer.poi.home_location_available)
195 nmea_info.location = settings_computer.poi.home_location;
196 else {
197 nmea_info.location.latitude = Angle::Degrees(51.2);
198 nmea_info.location.longitude = Angle::Degrees(7.7);
201 nmea_info.location_available.Update(nmea_info.clock);
202 nmea_info.track = Angle::Degrees(90);
203 nmea_info.track_available.Update(nmea_info.clock);
204 nmea_info.ground_speed = fixed(50);
205 nmea_info.ground_speed_available.Update(nmea_info.clock);
206 nmea_info.gps_altitude = fixed(1500);
207 nmea_info.gps_altitude_available.Update(nmea_info.clock);
209 derived_info.Reset();
210 derived_info.terrain_valid = true;
212 if (terrain != NULL) {
213 RasterTerrain::UnprotectedLease lease(*terrain);
214 do {
215 lease->SetViewCenter(nmea_info.location, fixed(50000));
216 } while (lease->IsDirty());
219 map.ReadBlackboard(nmea_info, derived_info, settings_computer,
220 settings_map);
221 map.SetLocation(nmea_info.location);
224 #ifndef WIN32
225 int main(int argc, char **argv)
226 #else
227 int WINAPI
228 WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
229 #ifdef _WIN32_WCE
230 LPWSTR lpCmdLine,
231 #else
232 LPSTR lpCmdLine2,
233 #endif
234 int nCmdShow)
235 #endif
237 InitialiseDataPath();
238 Profile::SetFiles(_T(""));
239 Profile::Load();
241 ComputerSettings settings_computer;
242 settings_computer.SetDefaults();
243 Profile::Load(settings_computer);
245 MapSettings settings_map;
246 settings_map.SetDefaults();
247 Profile::Load(settings_map);
249 LoadFiles(settings_computer.poi, settings_computer.team_code);
251 ScreenGlobalInit screen_init;
253 #ifdef WIN32
254 ResourceLoader::Init(hInstance);
255 #endif
257 MapLook *map_look = new MapLook();
258 map_look->Initialise(settings_map, Fonts::map, Fonts::map_bold);
260 TrafficLook *traffic_look = new TrafficLook();
261 traffic_look->Initialise();
263 TestWindow window(*map_look, *traffic_look);
264 window.Create({640, 480});
266 GenerateBlackboard(window.map, settings_computer, settings_map);
267 Fonts::Initialize();
268 #ifdef ENABLE_OPENGL
269 DrawThread::UpdateAll(window.map);
270 #else
271 DrawThread::Draw(window.map);
272 window.initialised = true;
273 #endif
274 window.Show();
276 window.RunEventLoop();
277 window.Destroy();
279 Fonts::Deinitialize();
281 delete terrain;
282 delete topography;
283 delete traffic_look;
284 delete map_look;
286 DeinitialiseDataPath();
288 return 0;