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"
52 DeviceBlackboard::SetStartupLocation(const GeoPoint
&loc
, const fixed alt
) {}
59 return InMainThread();
64 static Waypoints way_points
;
66 static Airspaces airspace_database
;
68 static TopographyStore
*topography
;
69 static RasterTerrain
*terrain
;
74 static void Draw(MapWindow
&map
) {
80 static void UpdateAll(MapWindow
&map
) {
86 class TestWindow
: public SingleWindow
{
89 ButtonWindow close_button
;
101 TestWindow(const MapLook
&map_look
,
102 const TrafficLook
&traffic_look
)
103 :map(map_look
, traffic_look
)
104 #ifndef ENABLE_OPENGL
110 void Create(PixelSize size
) {
111 TopWindowStyle style
;
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
);
123 map
.SetLocation(terrain
->GetTerrainCenter());
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();
135 virtual bool OnCommand(unsigned id
, unsigned code
) override
{
142 return TopWindow::OnCommand(id
, code
);
145 virtual void OnResize(PixelSize new_size
) override
{
146 SingleWindow::OnResize(new_size
);
149 map
.Resize(new_size
);
151 #ifndef ENABLE_OPENGL
153 DrawThread::Draw(map
);
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
,
173 std::unique_ptr
<TLineReader
> reader(OpenConfiguredTextFile(ProfileKeys::AirspaceFile
,
174 ConvertLineReader::AUTO
));
176 AirspaceParser
parser(airspace_database
);
177 parser
.Parse(*reader
, operation
);
178 airspace_database
.Optimise();
183 GenerateBlackboard(MapWindow
&map
, const ComputerSettings
&settings_computer
,
184 const MapSettings
&settings_map
)
187 DerivedInfo derived_info
;
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
;
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
);
215 lease
->SetViewCenter(nmea_info
.location
, fixed(50000));
216 } while (lease
->IsDirty());
219 map
.ReadBlackboard(nmea_info
, derived_info
, settings_computer
,
221 map
.SetLocation(nmea_info
.location
);
225 int main(int argc
, char **argv
)
228 WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
237 InitialiseDataPath();
238 Profile::SetFiles(_T(""));
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
;
254 ResourceLoader::Init(hInstance
);
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
);
269 DrawThread::UpdateAll(window
.map
);
271 DrawThread::Draw(window
.map
);
272 window
.initialised
= true;
276 window
.RunEventLoop();
279 Fonts::Deinitialize();
286 DeinitialiseDataPath();