diff --git a/sw/ground_segment/cockpit/map2d.ml b/sw/ground_segment/cockpit/map2d.ml index f117235e88..4d1b3387b3 100644 --- a/sw/ground_segment/cockpit/map2d.ml +++ b/sw/ground_segment/cockpit/map2d.ml @@ -448,20 +448,22 @@ let active_gm_auto = fun x -> gm_auto := x let button_press = fun (geomap:MapCanvas.widget) ev -> - if GdkEvent.Button.button ev = 3 then + if GdkEvent.Button.button ev = 3 then begin let xc = GdkEvent.Button.x ev and yc = GdkEvent.Button.y ev in let (xw,yw) = geomap#window_to_world xc yc in let wgs84 = geomap#of_world (xw,yw) in - let (xw',yw') = geomap#world_of wgs84 in - ignore(Thread.create (fun geo -> - try ignore (MapGoogle.display_tile geomap geo) with - Gm.Not_available -> ()) - wgs84); - false - else - false + let display = fun geo -> + if Gdk.Convert.test_modifier `SHIFT (GdkEvent.Button.state ev) then + MapIGN.display_tile geomap geo + else + try ignore (MapGoogle.display_tile geomap geo) with + Gm.Not_available -> () in + + ignore(Thread.create display wgs84) + end; + false let fill_gm_tiles = fun geomap -> ignore (Thread.create MapGoogle.fill_window geomap) @@ -480,6 +482,8 @@ let _ = [ "-b", Arg.String (fun x -> ivy_bus := x), "Bus\tDefault is 127.255.255.25:2010"; "-ref", Arg.Set_string geo_ref, "Geographic ref (default '')"; "-mercator", Arg.Unit (fun () -> projection:=MapCanvas.Mercator),"Switch to (Google Maps) Mercator projection"; + "-lambertIIe", Arg.Unit (fun () -> projection:=MapCanvas.LambertIIe),"Switch to LambertIIe projection"; + "-ign", Arg.Set_string IGN.data_path, "IGN tiles path"; "-m", Arg.String (fun x -> map_file := x), "Map description file"] in Arg.parse (options) (fun x -> Printf.fprintf stderr "Warning: Don't do anythig with %s\n" x) diff --git a/sw/lib/ocaml/Makefile b/sw/lib/ocaml/Makefile index d4993c015f..d1bf61bb8b 100644 --- a/sw/lib/ocaml/Makefile +++ b/sw/lib/ocaml/Makefile @@ -26,11 +26,11 @@ OCAMLC=ocamlc $(INCLUDES) OCAMLOPT=ocamlopt $(INCLUDES) -SRC = debug.ml env.ml serial.ml ocaml_tools.ml extXml.ml xml2h.ml latlong.ml srtm.ml http.ml gm.ml wavecard.ml geometry_2d.ml geometry_3d.ml cserial.o convert.o ubx.ml pprz.ml +SRC = debug.ml env.ml serial.ml ocaml_tools.ml extXml.ml xml2h.ml latlong.ml srtm.ml http.ml gm.ml iGN.ml wavecard.ml geometry_2d.ml geometry_3d.ml cserial.o convert.o ubx.ml pprz.ml CMO = $(SRC:.ml=.cmo) CMX = $(SRC:.ml=.cmx) -XSRC = platform.ml gtkgl_Hack.ml ml_gtkgl_hack.o gtk_image.ml gtk_tools_icons.ml gtk_tools.ml gtk_draw.ml gtk_tools_GL.ml gtk_3d.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml ml_gtk_drag.o xmlEdit.ml +XSRC = platform.ml gtkgl_Hack.ml ml_gtkgl_hack.o gtk_image.ml gtk_tools_icons.ml gtk_tools.ml gtk_draw.ml gtk_tools_GL.ml gtk_3d.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml mapIGN.ml ml_gtk_drag.o xmlEdit.ml XCMO = $(XSRC:.ml=.cmo) XCMX = $(XSRC:.ml=.cmx) diff --git a/sw/lib/ocaml/iGN.ml b/sw/lib/ocaml/iGN.ml new file mode 100644 index 0000000000..9e87c1d8ac --- /dev/null +++ b/sw/lib/ocaml/iGN.ml @@ -0,0 +1,69 @@ +(* + * $Id$ + * + * Handling IGN tiles + * + * Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +let (//) = Filename.concat + +module LL = Latlong + +type tile_t = { + key : int * int; (* LambertIIe meters / size_m *) + sw_corner : Latlong.geographic; + ne_corner : Latlong.geographic + };; + +let size_px = 250 +let size_m = (size_px * 25) / 10 + +let tile_size = size_px , size_px + +let data_path = ref "/path_to_ign_files" + +let tile_of_geo = fun wgs84 -> + let lbt = LL.lambertIIe_of wgs84 in + let kx = lbt.LL.lbt_x / size_m + and ky = lbt.LL.lbt_y / size_m in + let x0 = kx * size_m and y0 = ky * size_m in + let x1 = x0 + size_m and y1 = y0 + size_m in + let sw_corner= LL.of_lambertIIe {LL.lbt_x=x0; lbt_y=y0} + and ne_corner = LL.of_lambertIIe {LL.lbt_x=x1; lbt_y=y1} in + { key = (kx, ky); + sw_corner = sw_corner; + ne_corner = ne_corner } + +let get_tile = fun tile -> + let (kx, ky) = tile.key in + let dalle_x = (kx * size_m) / 10000 + and dalle_y = 267 - ((ky*size_m) / 10000) in + let file = !data_path // Printf.sprintf "F%03d_%03d.png" dalle_x dalle_y in + let tmp_file = Filename.temp_file "ign" ".png" in + let ix = (kx mod (10000 / size_m)) * size_px + and iy = 4000 - size_px - ((ky mod (10000 / size_m)) * size_px) in + let sub_tile = Printf.sprintf "convert -crop %dx%d+%d+%d %s %s" size_px size_px ix iy file tmp_file in + let x = Sys.command sub_tile in + if x <> 0 then failwith sub_tile; + tmp_file + + diff --git a/sw/lib/ocaml/iGN.mli b/sw/lib/ocaml/iGN.mli new file mode 100644 index 0000000000..09abe3a538 --- /dev/null +++ b/sw/lib/ocaml/iGN.mli @@ -0,0 +1,41 @@ +(* + * $Id$ + * + * Handling IGN tiles + * + * Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +val tile_size : int * int (** Pixels *) + +type tile_t = { + key : int * int; (* LambertIIe meters / size *) + sw_corner : Latlong.geographic; + ne_corner : Latlong.geographic + };; + +val data_path : string ref +(** Where to find the original tiles *) + +val tile_of_geo : Latlong.geographic -> tile_t + +val get_tile : tile_t -> string +(** Returns the filename of the given tile *) diff --git a/sw/lib/ocaml/latlong.ml b/sw/lib/ocaml/latlong.ml index f2c854e7c3..07c156e8b9 100644 --- a/sw/lib/ocaml/latlong.ml +++ b/sw/lib/ocaml/latlong.ml @@ -352,7 +352,7 @@ let lambertIIe_of = fun wgs84 -> let lbt_add = fun {lbt_x=x; lbt_y=y} (dx, dy) -> {lbt_x = x + truncate dx; lbt_y = y + truncate dy } let lbt_sub = fun {lbt_x=x1; lbt_y=y1} {lbt_x=x2; lbt_y=y2} -> - (float (x2-x1), float (y2-y1)) + (float (x1-x2), float (y1-y2)) let space = Str.regexp "[ \t]+" let fos = float_of_string diff --git a/sw/lib/ocaml/mapGoogle.ml b/sw/lib/ocaml/mapGoogle.ml index b7338b29a1..af53f3c913 100644 --- a/sw/lib/ocaml/mapGoogle.ml +++ b/sw/lib/ocaml/mapGoogle.ml @@ -81,7 +81,8 @@ let display_the_tile = fun geomap tile jpg_file -> and east_long = west_long +. tile.Gm.width in let ne = { LL.posn_lat = north_lat; posn_long = east_long } in - let map = geomap#display_pixbuf ((0,256), tile.Gm.sw_corner) ((256,0),ne) (GdkPixbuf.from_file jpg_file) in + let (tx, ty) = Gm.tile_size in + let map = geomap#display_pixbuf ((0,tx), tile.Gm.sw_corner) ((ty,0),ne) (GdkPixbuf.from_file jpg_file) in map#raise 1; add_tile tile.Gm.key diff --git a/sw/lib/ocaml/mapIGN.ml b/sw/lib/ocaml/mapIGN.ml new file mode 100644 index 0000000000..f868e5c324 --- /dev/null +++ b/sw/lib/ocaml/mapIGN.ml @@ -0,0 +1,43 @@ +(* + * $Id$ + * + * Displaying IGN Maps on a MapCanvas object + * + * Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +module LL = Latlong + +let displayed_tiles = Hashtbl.create 41 +let mem_tile = fun t -> Hashtbl.mem displayed_tiles t.IGN.key +let add_tile = fun t -> Hashtbl.add displayed_tiles t.IGN.key () + +(** Displaying the tile around the given point *) +let display_tile = fun (geomap:MapCanvas.widget) wgs84 -> + let tile = IGN.tile_of_geo wgs84 in + + if not (mem_tile tile) then + let jpg_file = IGN.get_tile tile in + + let (sx,sy) = IGN.tile_size in + let map = geomap#display_pixbuf ((0,sx), tile.IGN.sw_corner) ((sy,0),tile.IGN.ne_corner) (GdkPixbuf.from_file jpg_file) in + map#raise 1; + add_tile tile diff --git a/sw/lib/ocaml/mapIGN.mli b/sw/lib/ocaml/mapIGN.mli new file mode 100644 index 0000000000..e6fc88fe97 --- /dev/null +++ b/sw/lib/ocaml/mapIGN.mli @@ -0,0 +1,27 @@ +(* + * $Id$ + * + * Displaying IGN Maps on a MapCanvas object + * + * Copyright (C) 2004-2006 ENAC, Pascal Brisset, Antoine Drouin + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + *) + +val display_tile : MapCanvas.widget -> Latlong.geographic -> unit