fgmapping 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/README CHANGED
@@ -1,39 +1,33 @@
1
- How to run fgmap
2
- ================
1
+ How to run fgmapping
2
+ ====================
3
3
 
4
4
  Requirements:
5
- - ruby of course. Min version 1.8.6
6
- - qtruby4, minimum version 4.4
5
+ - ruby of course. Min version 1.8.6 up to 1.9.2
6
+ - either:qtruby4, minimum version 4.4
7
7
  see: http://rubyforge.org/projects/korundum
8
8
  debian/ubuntu: sudo apt-get install libqt4-ruby
9
- - xml bindings libxml
10
- see: http://libxml.rubyforge.org
11
- debian/ubuntu: sudo apt-get install libxml-ruby
9
+ or: qtbindings, min version 4.6.3.1
10
+ sudo gem install qtbindings
12
11
 
13
12
 
14
13
  Run:
15
- You basically have 3 options:
14
+ You basically have 2 options:
16
15
 
17
16
  1) (you already have ruby and qtruby installed)
18
17
  - unpack the 'fgmap.tar.gz' into any directory
19
18
  - cd into this directory
20
- - on shell type: ruby init.rb
19
+ - on shell type: ruby waypoint.rb
21
20
 
22
21
  2) (you already have ruby and rubygems installed)
23
22
  - type: sudo gem install fgmapping
24
- - make sure /var/lib/gems/1.8/bin is in your standard path ($PATH)
25
- - execute 'flightgear-mapping'
26
-
27
- 3) (you don't have ruby installed, don't even know what this is)
28
- - download "fgmap_linux"
29
- - change permission to 'executable': chmod 774 fgmap_linux
30
- - to run it, just type ./fgmap_linux
23
+ - make sure /var/lib/gems/1.*/bin is in your standard path ($PATH)
24
+ - execute 'fgmapping'
31
25
 
32
26
  In any case you need to launch Flightgear like this:
33
27
  - run Flightgear with additional command line option: --telnet=2948
34
28
 
35
29
 
36
- Develop:
30
+ Development:
37
31
  Download git repository:
38
32
  - git clone git://rubyforge.org/fgmap.git
39
33
  Remarks for development:
@@ -0,0 +1,4 @@
1
+ zum Erstellen eines GEM:
2
+ http://sirupsen.com/create-your-first-ruby-gem-and-release-it-to-gemcutter/
3
+
4
+
@@ -0,0 +1,19 @@
1
+ = fgmap
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to fgmap
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Michael Meltner. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile CHANGED
@@ -1,23 +1,60 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
2
10
  require 'rake'
3
- require 'echoe'
4
11
 
5
- l=""
6
- File.open("CHANGELOG", "r") do |f|
7
- while l=f.gets
8
- break if l !~ /\s*#/
9
- end
12
+ exclude_me = ['*.ui', '*.png', '*.svg', '*.qrc', 'Makefile', 'compress-resource.rb']
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fgmapping"
18
+ gem.homepage = "http://rubyforge.org/frs/?group_id=9572"
19
+ gem.license = "GPL2"
20
+ gem.summary = %Q{Real-time mapping for Flightgear}
21
+ gem.description = %Q{Provide a real-time map of flight position in Flightgear. It is based on tiles from Openstreetmap with elevation shading, provides navigation aids and runways, allows setting of waypoints, sends these to Flightgear's route-manager and tracks the flight.}
22
+ gem.email = "mmeltner@gmail.com"
23
+ gem.authors = ["Michael Meltner"]
24
+ gem.rubyforge_project = "fgmap"
25
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
26
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
27
+ # gem.add_runtime_dependency 'qtbindings', '>= 4.6.3.1'
28
+
29
+ exclude_me.each do |excl|
30
+ gem.files.exclude "lib/**/#{excl}"
31
+ end
10
32
  end
11
- l =~ /v\d+\.\d+\.\d+\s/
12
- version = $&[1..-2]
13
- puts "Version = #{version}"
14
-
15
- Echoe.new('fgmapping', version) do |p|
16
- p.description = "Flightgear live mapping"
17
- p.url = "http://rubyforge.org/projects/fgmap"
18
- p.author = "Michael Meltner"
19
- p.email = "mmeltner @nospamplease@ gmail.com"
20
- p.ignore_pattern = ["tmp/*", "script/*", "develop/*", "README.build_gem", "*.gz"]
21
- p.development_dependencies = []
33
+ Jeweler::GemcutterTasks.new
34
+ Jeweler::RubygemsDotOrgTasks.new
35
+
36
+ require 'rake/testtask'
37
+ Rake::TestTask.new(:test) do |test|
38
+ test.libs << 'lib' << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
22
41
  end
23
42
 
43
+ require 'rcov/rcovtask'
44
+ Rcov::RcovTask.new do |test|
45
+ test.libs << 'test'
46
+ test.pattern = 'test/**/test_*.rb'
47
+ test.verbose = true
48
+ end
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
+
56
+ rdoc.rdoc_dir = 'rdoc'
57
+ rdoc.title = "fgmap #{version}"
58
+ rdoc.rdoc_files.include('README*')
59
+ rdoc.rdoc_files.include('lib/**/*.rb')
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -19,5 +19,5 @@ if File.lstat(myself).symlink? then
19
19
  end
20
20
  Dir.chdir(File.dirname(myself))
21
21
 
22
- load "waypoint.rb"
22
+ load "fgmapping.rb"
23
23
 
@@ -12,7 +12,12 @@
12
12
  # Author Michael Meltner (mmeltner@gmail.com)
13
13
  ##################################################
14
14
 
15
- Dir.chdir(File.dirname(__FILE__))
15
+ # check if we were launched via symlink, then resolve it
16
+ myself = __FILE__
17
+ if File.lstat(myself).symlink? then
18
+ myself = File.readlink(__FILE__)
19
+ end
20
+ Dir.chdir(File.dirname(myself))
16
21
 
17
- load "waypoint.rb"
22
+ load "./fgmap/waypoint.rb"
18
23
 
File without changes
@@ -0,0 +1,110 @@
1
+ # coding: utf-8
2
+ ##################################################
3
+ # Flightgear Mapping
4
+ #
5
+ # Provide a real-time map of flight position in Flightgear. It is based on tiles from Openstreetmap,
6
+ # downloads them in the background, provides navigation aids and runways, allows setting of waypoints
7
+ # and tracks the flight.
8
+ #
9
+ # License
10
+ # GPL V2
11
+ #
12
+ # Author Michael Meltner (mmeltner@gmail.com)
13
+ ##################################################
14
+
15
+ class TileGraphicsItemGroup < Qt::GraphicsItemGroup
16
+ def contextMenuEvent(contextEvent)
17
+ dlg=contextEvent.widget.parent.parent
18
+ # list of menu entries
19
+ # if it is itself an array then it is a checkbox menu entry and the 2nd item in this array is its boolean
20
+ entries=["Set Waypoint", "Delete Waypoint", "Waypoints to Route-Mgr", "Set Origin", "-", "Save Waypoints", "Save Track", "Load Waypoints",
21
+ "Load Track", ["Metric Units", dlg.metricUnit]]
22
+ menu=Qt::Menu.new
23
+ entries.each{|e|
24
+ if e.kind_of? Array then
25
+ action = Qt::Action.new(e[0], nil)
26
+ action.setCheckable(true)
27
+ action.setChecked(e[1])
28
+ menu.addAction(action)
29
+ else
30
+ # if array entry is "-" then just display a separator to make it more nice
31
+ if e=="-" then
32
+ menu.addSeparator
33
+ else
34
+ action = Qt::Action.new(e, nil)
35
+ if e =~ /(Delete Waypoint|Waypoints to)/ then
36
+ action.setEnabled(false) if dlg.waypoints.nodes.empty?
37
+ end
38
+ menu.addAction(action)
39
+ end
40
+ end
41
+ }
42
+ sel=menu.exec(contextEvent.screenPos)
43
+ sel=sel.text if !sel.nil?
44
+ lon=dlg.node.tolon(dlg.node.xtile + contextEvent.scenePos.x / 256.0)
45
+ lat=dlg.node.tolat(dlg.node.ytile + contextEvent.scenePos.y / 256.0)
46
+
47
+ # now the selected item is handled, order is the same as defined in the array "entries" previously
48
+ case sel
49
+ when entries[0]
50
+ i=dlg.waypoints << Node.new(nil, Time.now, lon, lat)
51
+ dlg.putflag(contextEvent.scenePos.x, contextEvent.scenePos.y, i, dlg.waypoints.nodes.last)
52
+ if i==1 and dlg.waypoints.nodes.length == 1 then
53
+ dlg.w.lBcurrentwp.text="1"
54
+ dlg.waypoints.currentwp=1
55
+ end
56
+
57
+ when entries[1]
58
+ d=dlg.waypoints.del(lon,lat)
59
+ if dlg.w.lBcurrentwp.text.to_i == d then
60
+ dlg.w.lBcurrentwp.text="-"
61
+ end
62
+ dlg.movemap(dlg.node, true)
63
+
64
+ when entries[2]
65
+ Thread.new {
66
+ dlg.waypoints.nodes.each do |n|
67
+ dlg.writeFlightsim("set /autopilot/route-manager/input @INSERT-1:#{n.lon.to_s.gsub(",",".")},#{n.lat.to_s.gsub(",",".")}")
68
+ end
69
+ }
70
+
71
+ when entries[3]
72
+ dlg.node = Node.new(1, Time.now, lon, lat)
73
+ dlg.offset_x = 0
74
+ dlg.offset_y = 0
75
+ dlg.movemap(dlg.node, true)
76
+
77
+ when entries[5]
78
+ dlg.saveWaypoints([dlg.waypoints])
79
+
80
+ when entries[6]
81
+ dlg.savetrack(dlg.mytracks)
82
+
83
+ when entries[7]
84
+ savecurrent = dlg.waypoints.currentwp
85
+ if dlg.loadwaypoint("Load Waypoints") then
86
+ dlg.waypoints.currentwp = nil
87
+ else
88
+ dlg.waypoints.currentwp = savecurrent
89
+ end
90
+
91
+ when entries[8]
92
+ dlg.mytrack_current += (dlg.w.pBrecordTrack.isChecked ? 0 : 1)
93
+ savewp=dlg.mytracks[dlg.mytrack_current]
94
+ if dlg.mytracks[dlg.mytrack_current].nil? then
95
+ dlg.mytracks[dlg.mytrack_current] = Way.new(1, 'user', Time.now, dlg.nextcolor)
96
+ @prev_track_node = nil
97
+ end
98
+ if dlg.loadtrack("Load Track") then
99
+ dlg.w.pBrecordTrack.text = "Record Track #{dlg.mytrack_current + 2}"
100
+ dlg.w.pBrecordTrack.setChecked(false)
101
+ else
102
+ dlg.mytracks[dlg.mytrack_current]=savewp
103
+ end
104
+
105
+ when entries[9][0]
106
+ dlg.metricUnit = !dlg.metricUnit
107
+
108
+ end #case
109
+ end
110
+ end
@@ -1,4 +1,4 @@
1
- require "hud-widget"
1
+ require "./hud-widget"
2
2
 
3
3
  # Class MainDlg ############################################
4
4
  class HudWidget < Qt::Widget
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  ##################################################
2
3
  # Flightgear Mapping
3
4
  #
@@ -11,23 +12,31 @@
11
12
  # Author Michael Meltner (mmeltner@gmail.com)
12
13
  ##################################################
13
14
 
15
+
14
16
  require 'net/http'
15
- require "main-dlg"
16
- require "tile"
17
- require "resources"
18
17
  require 'socket'
19
- require "hud-impl"
20
- require "nodeinfo-impl"
21
- require 'navaid.rb'
22
- require "xml"
18
+ require 'rexml/document'
19
+ require './main-dlg'
20
+ require './tile'
21
+ require './resources'
22
+ require './hud-impl'
23
+ require './nodeinfo-impl'
24
+ require './navaid.rb'
25
+ require './context_menu.rb'
23
26
  begin
24
- require "ap"
27
+ require 'ap'
25
28
  rescue LoadError
26
29
  def ap(*k)
27
30
  p k
28
31
  end
29
32
  end
30
33
 
34
+ if RUBY_VERSION =~ /^1\.8/ then
35
+ class Net::HTTP
36
+ alias request_get get
37
+ end
38
+ end
39
+
31
40
  OFFSET_FLAG_X = 3
32
41
  OFFSET_FLAG_Y = 21
33
42
  OFFSET_PIN_X = 1
@@ -79,6 +88,14 @@ MAPSDIR = ENV['HOME'] + "/.OpenstreetmapTiles"
79
88
  #Thread.abort_on_exception = true
80
89
  #GC.disable
81
90
 
91
+ class REXML::Element
92
+ def add_text_element(nodename, text)
93
+ e = REXML::Element.new(nodename)
94
+ e.add_text(text)
95
+ self.add_element(e)
96
+ end
97
+ end
98
+
82
99
  # Class MainDlg ############################################
83
100
  class MainDlg < Qt::Widget
84
101
  attr_reader :node, :scene_tiles, :scene, :toffset_x, :offset_y, :menu, :waypoints, \
@@ -99,12 +116,12 @@ class MainDlg < Qt::Widget
99
116
  @cfg=Qt::Settings.new("MMeltnerSoft", "fg_map")
100
117
  @metricUnit = @cfg.value("metricUnit",Qt::Variant.new(true)).toBool
101
118
  @zoom = @cfg.value("zoom",Qt::Variant.new(13)).toInt
102
- @lat = @cfg.value("lat",Qt::Variant.new(LATSTARTUP)).toDouble
103
- @lon = @cfg.value("lon",Qt::Variant.new(LONSTARTUP)).toDouble
119
+ @lat = @cfg.value("lat",Qt::Variant.new(LATSTARTUP.to_s)).toDouble
120
+ @lon = @cfg.value("lon",Qt::Variant.new(LONSTARTUP.to_s)).toDouble
104
121
  @w.cBrw.setChecked(@cfg.value("rwChecked",Qt::Variant.new(false)).toBool)
105
122
  @w.cBndb.setChecked(@cfg.value("nbdChecked",Qt::Variant.new(false)).toBool)
106
123
  @w.cBvor.setChecked(@cfg.value("vorChecked",Qt::Variant.new(true)).toBool)
107
- @opacity = @cfg.value("opacity",Qt::Variant.new(1.0)).toFloat
124
+ @opacity = @cfg.value("opacity",Qt::Variant.new((1.0).to_s)).toFloat
108
125
 
109
126
  @flag=Qt::Pixmap.new(":/icons/flag-blue.png")
110
127
  @pin=Qt::Pixmap.new(":/icons/wpttemp-red.png")
@@ -204,8 +221,8 @@ class MainDlg < Qt::Widget
204
221
  r=@fs_ans.reverse.detect do |f|
205
222
  f.include?(path)
206
223
  end
207
- r =~ /-?\d+\.\d+/
208
- return $&.to_f
224
+ r =~ /'(-?\d+\.\d+)' \(double\)/
225
+ return $1.to_f
209
226
  end
210
227
 
211
228
  def putflag(x,y,i,node)
@@ -244,31 +261,36 @@ class MainDlg < Qt::Widget
244
261
  end
245
262
 
246
263
  ap "generating xml-doc"
247
- doc = XML::Document.new()
248
- doc.root = XML::Node.new('gpx')
249
- doc.root["xmlns"] = "http://www.topografix.com/GPX/1/1"
250
- doc.root["creator"] = "ruby-tracker"
251
- doc.root["version"] = "1.1"
252
- doc.root["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
253
- doc.root["xsi:schemaLocation"] = "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
254
-
255
- tracknode = XML::Node.new("trk")
256
- doc.root << tracknode
264
+ doc = REXML::Document.new
265
+ doc << REXML::XMLDecl.new(REXML::XMLDecl::DEFAULT_VERSION, REXML::XMLDecl::DEFAULT_ENCODING)
266
+
267
+ doc.add_element('gpx')
268
+
269
+ node=REXML::XPath.first(doc, "//gpx")
270
+ node.add_namespace("http://www.topografix.com/GPX/1/1")
271
+ node.add_attributes({'creator'=>"ruby-tracker", "version"=>"1.1"} )
272
+ node.add_namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
273
+
274
+ tracknode = REXML::Element.new("trk")
275
+ node.add_element(tracknode)
257
276
  items.each{|track|
258
- segnode = XML::Node.new("trkseg")
259
- tracknode << segnode
277
+ segnode = REXML::Element.new("trkseg")
278
+ tracknode.add_element(segnode)
260
279
  track.nodes.each{|n|
261
- trackpoint = XML::Node.new("trkpt")
262
- trackpoint["lat"] = n.lat.to_s.gsub(",",".")
263
- trackpoint["lon"] = n.lon.to_s.gsub(",",".")
264
- trackpoint << XML::Node.new("ele", n.elevation.to_s.gsub(",","."))
265
- trackpoint << XML::Node.new("time", n.toGPStime)
266
- trackpoint << XML::Node.new("time_us", n.timestamp.usec.to_s)
267
- segnode << trackpoint
280
+ trackpoint = REXML::Element.new("trkpt")
281
+ trackpoint.add_attributes({"lat" => n.lat.to_s.gsub(",","."), "lon" => n.lon.to_s.gsub(",",".")})
282
+ trackpoint.add_text_element("ele", n.elevation.to_s.gsub(",","."))
283
+ trackpoint.add_text_element("time", n.toGPStime)
284
+ trackpoint.add_text_element("time_us", n.timestamp.usec.to_s)
285
+ segnode.add_element(trackpoint)
268
286
  }
269
287
  }
270
288
  File.open($MAPSHOME + "/tracks/" + items.first.nodes.first.toGPStime + ".gpx", "w+"){|f|
271
- f.puts doc.inspect
289
+ begin
290
+ doc.write(f, 2)
291
+ rescue Errno::EISDIR
292
+ Qt::MessageBox::warning(nil, "Warning", "You selected a directory, not a file. Nothing saved.")
293
+ end
272
294
  }
273
295
  ap "xml-file written"
274
296
  end
@@ -278,31 +300,35 @@ class MainDlg < Qt::Widget
278
300
  fn=Qt::FileDialog::getOpenFileName(nil, title, $MAPSHOME + "/tracks/", "Track-Data (*.gpx *.log);;All (*)")
279
301
  if !fn.nil? then
280
302
  success = false
281
- doc = XML::Document.file(fn)
282
- doc.find('/ns:gpx/ns:trk', "ns:http://www.topografix.com/GPX/1/1").each{|trk|
283
- @mytrack_current -= 1
284
- trk.find("ns:trkseg", "ns:http://www.topografix.com/GPX/1/1").each{|seg|
285
- ns = XML::Namespace.new(seg, 'ns', 'http://www.topografix.com/GPX/1/1')
286
- seg.namespaces.namespace=ns
287
- @mytrack_current += 1
288
- if @mytracks[@mytrack_current].nil? then
289
- @mytracks[@mytrack_current] = Way.new(1, 'user', Time.now, nextcolor)
290
- @prev_track_node = nil
303
+ file=File.new(fn)
304
+ begin
305
+ doc = REXML::Document.new(file)
306
+
307
+ doc.elements.each("/gpx/trk") do |trk|
308
+ @mytrack_current -= 1
309
+ trk.elements.each("trkseg") do |seg|
310
+ @mytrack_current += 1
311
+ if @mytracks[@mytrack_current].nil? then
312
+ @mytracks[@mytrack_current] = Way.new(1, 'user', Time.now, nextcolor)
313
+ @prev_track_node = nil
314
+ end
315
+ track=@mytracks[@mytrack_current]
316
+ track.nodes.clear
317
+ seg.elements.each("trkpt") do |tpt|
318
+ usec = tpt.elements["time_us"].text.strip
319
+ usec = (usec.nil? ? "0" : usec)
320
+ loc = tpt.attributes # lon and lat as a hash
321
+ track << Node.new(nil, tpt.elements["time"].text.strip + usec, \
322
+ loc["lon"].to_f, loc["lat"].to_f, \
323
+ tpt.elements["ele"].text.to_f)
324
+ success = true
325
+ end
291
326
  end
292
- track=@mytracks[@mytrack_current]
293
- track.nodes.clear
294
- xpat_time = XML::XPath::Expression.new("ns:time")
295
- xpat_time_us = XML::XPath::Expression.new("ns:time_us")
296
- xpat_elevation = XML::XPath::Expression.new("ns:ele")
297
- seg.find("ns:trkpt", "ns:http://www.topografix.com/GPX/1/1").each{|tpt|
298
- usec = tpt.find_first(xpat_time_us)
299
- usec = (usec.nil? ? "0" : usec.content)
300
- track << Node.new(nil, tpt.find_first(xpat_time).content + usec, \
301
- tpt["lon"].to_f, tpt["lat"].to_f, tpt.find_first(xpat_elevation).content.to_f)
302
- success = true
303
- }
304
- }
305
- }
327
+ end
328
+ rescue Errno::EISDIR
329
+ # swallow error, "success" is false anyway
330
+ end
331
+
306
332
  if success then
307
333
  movemap(@node, true)
308
334
  else
@@ -316,23 +342,28 @@ class MainDlg < Qt::Widget
316
342
  fn=Qt::FileDialog::getOpenFileName(nil, title, $MAPSHOME + "/waypoints/", "Waypoint-Data (*.gpx *.log);;All (*)")
317
343
  if !fn.nil? then
318
344
  success = false
319
- doc = XML::Document.file(fn)
320
- @waypoints = Way.new(nil,'user', Time.now, "Blue")
321
- doc.find("/ns:gpx/ns:wpt", "ns:http://www.topografix.com/GPX/1/1").each{ |wpt|
322
- ns = XML::Namespace.new(wpt, 'ns', 'http://www.topografix.com/GPX/1/1')
323
- wpt.namespaces.namespace = ns
324
- xpat_time = XML::XPath::Expression.new("ns:time")
325
- xpat_elevation = XML::XPath::Expression.new("ns:ele")
326
- @waypoints << Node.new(nil, wpt.find_first(xpat_time).content, wpt["lon"].to_f, \
327
- wpt["lat"].to_f, wpt.find_first(xpat_elevation).content.to_f)
328
- success = true
329
- }
330
- if success then
331
- movemap(@node, true)
332
- else
333
- Qt::MessageBox::warning(nil, "Warning", "No data found in file.")
345
+ file=File.new(fn)
346
+ begin
347
+ doc = REXML::Document.new(file)
348
+ @waypoints = Way.new(nil,'user', Time.now, "Blue")
349
+ doc.elements.each("/gpx/wpt") do |wpt|
350
+ loc = wpt.attributes # lon and lat as a hash
351
+ @waypoints << Node.new(nil, wpt.elements["time"].text.strip,
352
+ loc["lon"].to_f, loc["lat"].to_f, \
353
+ wpt.elements["ele"].text.to_f)
354
+ success = true
355
+ end
356
+ file.close
357
+ if success then
358
+ movemap(@node, true)
359
+ else
360
+ Qt::MessageBox::warning(nil, "Warning", "No data found in file.")
361
+ end
362
+ return success
363
+ rescue Errno::EISDIR
364
+ Qt::MessageBox::warning(nil, "Warning", "You selected a directory, not a file. Nothing loaded.")
365
+ return success
334
366
  end
335
- return success
336
367
  end
337
368
  end
338
369
 
@@ -346,32 +377,36 @@ class MainDlg < Qt::Widget
346
377
  # just swallow error
347
378
  end
348
379
 
349
- doc = XML::Document.new()
350
- doc.root = XML::Node.new('gpx')
351
- doc.root["xmlns"] = "http://www.topografix.com/GPX/1/1"
352
- doc.root["creator"] = "ruby-tracker"
353
- doc.root["version"] = "1.1"
354
- doc.root["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance"
355
- doc.root["xsi:schemaLocation"] = "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
380
+ doc = REXML::Document.new
381
+ doc << REXML::XMLDecl.new(REXML::XMLDecl::DEFAULT_VERSION, REXML::XMLDecl::DEFAULT_ENCODING)
382
+
383
+ doc.add_element('gpx')
384
+ root=REXML::XPath.first(doc, "//gpx")
385
+ root.add_namespace("http://www.topografix.com/GPX/1/1")
386
+ root.add_attributes({'creator'=>"ruby-tracker", "version"=>"1.1"} )
387
+ root.add_namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
356
388
 
357
389
  waypoints[0].nodes.each{|n|
358
390
  if !n.nil? then
359
- wpnode = XML::Node.new("wpt")
360
- doc.root << wpnode
361
- wpnode["lat"] = n.lat.to_s.gsub(",",".")
362
- wpnode["lon"] = n.lon.to_s.gsub(",",".")
363
- wpnode << XML::Node.new("ele", n.elevation.to_s.gsub(",","."))
364
- wpnode << XML::Node.new("time", n.toGPStime)
391
+ wpnode = REXML::Element.new("wpt")
392
+ root.add_element(wpnode)
393
+ wpnode.add_attributes({"lat" => n.lat.to_s.gsub(",","."), "lon" => n.lon.to_s.gsub(",",".")})
394
+ wpnode.add_text_element("ele", n.elevation.to_s.gsub(",","."))
395
+ wpnode.add_text_element("time", n.toGPStime)
365
396
  end
366
397
  }
367
- fn=Qt::FileDialog::getSaveFileName(nil, "Save Waypoint File", $MAPSHOME + "/waypoints/", "Waypoint-Data (*.gpx *.log);;All (*)","*.gpx")
368
398
 
399
+ fn=Qt::FileDialog::getSaveFileName(nil, "Save Waypoint File", $MAPSHOME + "/waypoints/", "Waypoint-Data (*.gpx *.log);;All (*)","*.gpx")
369
400
  if !fn.nil? then
370
401
  if fn !~ /\.gpx$/ then
371
402
  fn += ".gpx"
372
403
  end
373
404
  File.open(fn, "w+"){|f|
374
- f.puts doc.inspect
405
+ begin
406
+ doc.write(f, 2)
407
+ rescue Errno::EISDIR
408
+ Qt::MessageBox::warning(nil, "Warning", "You selected a directory, not a file. Nothing saved.")
409
+ end
375
410
  }
376
411
  end
377
412
  end
@@ -427,10 +462,10 @@ class MainDlg < Qt::Widget
427
462
  # we can not add the tiles to the scene within this thread directly. It crosses thread
428
463
  # bounderies which crashes QT badly
429
464
  @tilesToAddMutex.synchronize {
430
- @tilesToAdd << [f, (x - origin_x)*256, (y - origin_y)*256, OPENSTREETMAP_TILE]
465
+ @tilesToAdd << [f+".png", (x - origin_x)*256, (y - origin_y)*256, OPENSTREETMAP_TILE]
431
466
  }
432
467
  else # add immediately, we are not in a different thread
433
- pmi=Qt::GraphicsPixmapItem.new(Qt::Pixmap.new(f), @openstreetmapLayer)
468
+ pmi=Qt::GraphicsPixmapItem.new(Qt::Pixmap.new(f+".png"), @openstreetmapLayer)
434
469
  pmi.setOffset((x - origin_x)*256, (y - origin_y)*256)
435
470
  end
436
471
 
@@ -458,12 +493,12 @@ class MainDlg < Qt::Widget
458
493
  filename =~ /\/\d+\/\d+\/\d+$/
459
494
  fn = $&
460
495
  begin
461
- resp, data = h.get("/~cmarqu/hill" + fn + ".png", nil)
496
+ resp, data = h.request_get("/~cmarqu/hill" + fn + ".png", nil)
462
497
  if resp.kind_of?(Net::HTTPOK) then
463
498
  # check here again as in the meantime another thread might already have added the tile
464
499
  if !FileTest.exist?($MAPSHOME + fn + "-elevation.png") then
465
500
  File.open($MAPSHOME + fn + "-elevation.png", "w") do |file|
466
- file.write(data)
501
+ file.syswrite(data)
467
502
  end
468
503
  @tilesToAddMutex.synchronize {
469
504
  @tilesToAdd << [$MAPSHOME + fn + "-elevation.png", (x - origin_x)*256, (y - origin_y)*256, ELEVATION_TILE]
@@ -610,7 +645,7 @@ class MainDlg < Qt::Widget
610
645
  filename =~ /\/\d+\/\d+\/\d+$/
611
646
  fn = $&
612
647
  begin
613
- resp, data = h.get(fn + ".png", nil)
648
+ resp, data = h.request_get(fn + ".png", nil)
614
649
  if resp.kind_of?(Net::HTTPOK) then
615
650
  maindir = Dir.pwd
616
651
  Dir.chdir($MAPSHOME)
@@ -626,7 +661,7 @@ class MainDlg < Qt::Widget
626
661
  end
627
662
  Dir.chdir(maindir)
628
663
  File.open($MAPSHOME + fn + ".png", "w") do |file|
629
- file.write(data)
664
+ file.syswrite(data)
630
665
  end
631
666
  # we call from within a thread, signal this to the subroutine
632
667
  addTileToScene($MAPSHOME + fn, origin_x, origin_y, true)
@@ -759,10 +794,10 @@ class MainDlg < Qt::Widget
759
794
  @fs_queries.each do |q|
760
795
  @fs_socket.print("get " + q + "\r\n")
761
796
  s=""
762
- while select([@fs_socket], nil, nil, 0.3) do
797
+ while select([@fs_socket], nil, nil, 0.8) do
763
798
  s += @fs_socket.read(1)
764
799
  # check for end of line characterized by this string: "\r\n/>"
765
- # break if s[-4..-1] == "\r\n/>" and s.include?(q)
800
+ break if s[-4..-1] == "\r\n/>" and s.include?(q)
766
801
  end
767
802
  if s.include?(q) then
768
803
  @fs_ans << s.split("\n")
@@ -1213,97 +1248,6 @@ class TileGraphicsItemGroup < Qt::GraphicsItemGroup
1213
1248
 
1214
1249
  end # case
1215
1250
  end
1216
-
1217
- def contextMenuEvent(contextEvent)
1218
- dlg=contextEvent.widget.parent.parent
1219
- entries=["Set Waypoint", "Delete Waypoint", "Waypoints to Route-Mgr", "Set Origin", "-", "Save Waypoints", "Save Track", "Load Waypoints",
1220
- "Load Track", ["Metric Units", dlg.metricUnit]]
1221
- menu=Qt::Menu.new
1222
- entries.each{|e|
1223
- if e.kind_of? Array then
1224
- action = Qt::Action.new(e[0], nil)
1225
- action.setCheckable(true)
1226
- action.setChecked(e[1])
1227
- menu.addAction(action)
1228
- else
1229
- if e=="-" then
1230
- menu.addSeparator
1231
- else
1232
- action = Qt::Action.new(e, nil)
1233
- if e =~ /(Delete Waypoint|Waypoints to)/ then
1234
- action.setEnabled(false) if dlg.waypoints.nodes.empty?
1235
- end
1236
- menu.addAction(action)
1237
- end
1238
- end
1239
- }
1240
- sel=menu.exec(contextEvent.screenPos)
1241
- sel=sel.text if !sel.nil?
1242
- lon=dlg.node.tolon(dlg.node.xtile + contextEvent.scenePos.x / 256.0)
1243
- lat=dlg.node.tolat(dlg.node.ytile + contextEvent.scenePos.y / 256.0)
1244
- case sel
1245
- when entries[0]
1246
- i=dlg.waypoints << Node.new(nil, Time.now, lon, lat)
1247
- dlg.putflag(contextEvent.scenePos.x, contextEvent.scenePos.y, i, dlg.waypoints.nodes.last)
1248
- if i==1 and dlg.waypoints.nodes.length == 1 then
1249
- dlg.w.lBcurrentwp.text="1"
1250
- dlg.waypoints.currentwp=1
1251
- end
1252
-
1253
- when entries[1]
1254
- d=dlg.waypoints.del(lon,lat)
1255
- if dlg.w.lBcurrentwp.text.to_i == d then
1256
- dlg.w.lBcurrentwp.text="-"
1257
- end
1258
- dlg.movemap(dlg.node, true)
1259
-
1260
- when entries[2]
1261
- Thread.new {
1262
- dlg.waypoints.nodes.each do |n|
1263
- dlg.writeFlightsim("set /autopilot/route-manager/input @INSERT-1:#{n.lon.to_s.gsub(",",".")},#{n.lat.to_s.gsub(",",".")}")
1264
- end
1265
- }
1266
-
1267
-
1268
- when entries[3]
1269
- dlg.node = Node.new(1, Time.now, lon, lat)
1270
- dlg.offset_x = 0
1271
- dlg.offset_y = 0
1272
- dlg.movemap(dlg.node, true)
1273
-
1274
- when entries[5]
1275
- dlg.saveWaypoints([dlg.waypoints])
1276
-
1277
- when entries[6]
1278
- dlg.savetrack(dlg.mytracks)
1279
-
1280
- when entries[7]
1281
- savecurrent = dlg.waypoints.currentwp
1282
- if dlg.loadwaypoint("Load Waypoints") then
1283
- dlg.waypoints.currentwp = nil
1284
- else
1285
- dlg.waypoints.currentwp = savecurrent
1286
- end
1287
-
1288
- when entries[8]
1289
- dlg.mytrack_current += (dlg.w.pBrecordTrack.isChecked ? 0 : 1)
1290
- savewp=dlg.mytracks[dlg.mytrack_current]
1291
- if dlg.mytracks[dlg.mytrack_current].nil? then
1292
- dlg.mytracks[dlg.mytrack_current] = Way.new(1, 'user', Time.now, dlg.nextcolor)
1293
- @prev_track_node = nil
1294
- end
1295
- if dlg.loadtrack("Load Track") then
1296
- dlg.w.pBrecordTrack.text = "Record Track #{dlg.mytrack_current + 2}"
1297
- dlg.w.pBrecordTrack.setChecked(false)
1298
- else
1299
- dlg.mytracks[dlg.mytrack_current]=savewp
1300
- end
1301
-
1302
- when entries[9][0]
1303
- dlg.metricUnit = !dlg.metricUnit
1304
-
1305
- end #case
1306
- end
1307
1251
  end
1308
1252
 
1309
1253