Package viewer :: Module sim_viewer :: Class SimViewer
[hide private]
[frames] | no frames]

Class SimViewer

source code


A tool for displaying mosp-simulations.


Author: P. Tute

Instance Methods [hide private]
 
__init__(self, lat=0, lon=0, zoom=15, host='localhost', port=60001, ugly_drag=False, **kwargs)
Initialize the viewer.
source code
 
receive(self, dt)
Receive data from a given port and parse it to create drawable objects.
source code
 
update_coordinates(self, points=None, rects=None, circles=None, triangles=None, texts=None, hms=None, all=False)
Calculate all coordinates necessary for drawing received points, rectangles and circles.
source code
 
update_vertex_lists(self)
Add offsets to coordinates and update the used VertexLists.
source code
 
reload_tiles(self, dt)
Loads newly downloaded tiles from file
source code
 
get_image(self, x, y, z, layer='mapnik')
Load an image from the cache folder or download it.
source code
 
on_resize(self, width, height)
Recalculate drawing_offset and number_of_tiles if necessary, update tiles.
source code
 
update_tiles(self)
Update the self.tiles and self.tiles_used dicts after changes.
source code
int
meters_to_pixels(self, m)
Calculate the number of pixels that equal the given distance in.
source code
 
on_draw(self, dt=0)
Draw the screen.
source code
 
change_zoom(self, factor)
Zooms in or out of map by given factor.
source code
 
on_key_press(self, symbol, modifiers)
This is called by pyglet whenever a key is pressed.
source code
 
take_screenshot(self)
Take a screenshot of the current simulation and save it with the current timestamp as it's name.
source code
 
on_mouse_drag(self, x, y, dx, dy, buttons, modifiers)
Called, when mouse-dragging is recognized.
source code
 
on_mouse_release(self, x, y, buttons, modifiers)
This is called by pyglet when a mouse button is released.
source code
 
on_mouse_scroll(self, x, y, scroll_x, scroll_y)
This is called by pyglet when the mouse-wheel is scrolled.
source code
 
handle_offset(self, update_tiles=True)
Check, if new tiles need to be loaded because of the current offset.
source code
 
remove_drawing(self, dt, type, id)
Remove a drawing-object from the viewer.
source code
 
reset_drawings(self)
Empty all vertex lists and set up new ones.
source code
 
reconnect(self)
Try to establish a new connection to the host and ports used when initialising.
source code
 
close(self)
This is called by pyglet when the viewer is closed.
source code
Method Details [hide private]

__init__(self, lat=0, lon=0, zoom=15, host='localhost', port=60001, ugly_drag=False, **kwargs)
(Constructor)

source code 

Initialize the viewer.

Parameters:
  • lat (float) - Latitude to center view on (default 0).
  • lon (float) - Longitude to center view on (default 0).
  • zoom (int in range [0, 18]) - OSM-zomm-level to start with (default 16).
  • host (string) - The host running the simulation (default 'localhost').
  • port (int) - The port used by the simulation (default 60001).
  • ugly_drag - If set to True, dragging the map with the mouse will look uglier, but run faster (default False).
  • kwargs - @see http://pyglet.org/doc/api/pyglet.window.Window-class.html#__init__

receive(self, dt)

source code 

Receive data from a given port and parse it to create drawable objects.

Parameters:
  • dt - Time since last call. Necessary for pyglet-scheduling, ignored here.

Author: P. Tute

update_coordinates(self, points=None, rects=None, circles=None, triangles=None, texts=None, hms=None, all=False)

source code 

Calculate all coordinates necessary for drawing received points, rectangles and circles.

Parameters:
  • points (dict) - Points whose coordinates need to be calculated
  • rects (dict) - Rectangles whose coordinates need to be calculated
  • circles (dict) - Circles whose coordinates need to be calculated
  • texts (dict) - Texts whose coordinates need to be calculated
  • hms (list) - Heatmap-blips whose coordinates need to be calculated
  • all (boolean) - If all is True, all known coordinates will be redrawn. Other passed arguments will be ignored.

Author: P. Tute

get_image(self, x, y, z, layer='mapnik')

source code 

Load an image from the cache folder or download it.

Try to load from cache-folder first, download and cache if no image was found. The image is placed in self.tiles by this method or by the TileLoader.load_images() after downloading.

Parameters:
  • x (int) - OSM-tile number in x-direction
  • y (int) - OSM-tile number in y-direction
  • z (int in range [0, 18]) - OSM-zoom
  • layer (string (one of 'tah', 'oam' and 'mapnik')) - The used map layer (default 'mapnik')

on_resize(self, width, height)

source code 

Recalculate drawing_offset and number_of_tiles if necessary, update tiles.

This is called by pyglet when the viewer is started or resized.

See Also: http://pyglet.org/doc/api/pyglet.window.Window-class.html#on_resize

update_tiles(self)

source code 

Update the self.tiles and self.tiles_used dicts after changes.

When necessary load new images and delete old ones. This should not be called to often since it causes all coordinates of all drawings to be recalculated.

meters_to_pixels(self, m)

source code 

Calculate the number of pixels that equal the given distance in.

Parameters:
  • m (int) - Distance in meter
Returns: int
Distance in pixels

See Also: http://wiki.openstreetmap.org/wiki/Zoom_levels

on_draw(self, dt=0)

source code 

Draw the screen.

This is periodically called by pyglet.

Parameters:
  • dt - Time since last call. Necessary for scheduling but ignored here.

change_zoom(self, factor)

source code 

Zooms in or out of map by given factor.

Parameters:
  • factor (int) - The factor to zoom by in OSM-zoom levels.

on_key_press(self, symbol, modifiers)

source code 

This is called by pyglet whenever a key is pressed.

See Also: http://pyglet.org/doc/api/pyglet.window.Window-class.html#on_key_press

on_mouse_drag(self, x, y, dx, dy, buttons, modifiers)

source code 

Called, when mouse-dragging is recognized.

See Also: http://pyglet.org/doc/api/pyglet.window.Window-class.html#on_mouse_drag

on_mouse_release(self, x, y, buttons, modifiers)

source code 

This is called by pyglet when a mouse button is released.

See Also: http://pyglet.org/doc/api/pyglet.window.Window-class.html#on_mouse_release

on_mouse_scroll(self, x, y, scroll_x, scroll_y)

source code 

This is called by pyglet when the mouse-wheel is scrolled.

See Also: http://pyglet.org/doc/api/pyglet.window.Window-class.html#on_mouse_scroll

handle_offset(self, update_tiles=True)

source code 

Check, if new tiles need to be loaded because of the current offset.

If the offset is bigger than one tile, the appropriate tile will become the new center and the offset is changed accordingly.

Parameters:
  • update_tiles - If True, self.update_tiles() will be called after adjusting for offset (default).

remove_drawing(self, dt, type, id)

source code 

Remove a drawing-object from the viewer.

The object is specified by it's type (in hexadecimal, see MESSAGE_TYPES) and it's unique id.

Parameters:
  • dt (int) - Necessary for scheduling, ignored here
  • type (string) - Specifies which kind of object should be removed. Must be one of the types in MESSAGE_TYPES (in hexadecimal).
  • id (int) - ID of the removed object

reconnect(self)

source code 

Try to establish a new connection to the host and ports used when initialising.

This is mainly used when a new simulation was started and the viewer is supposed to be restarted.

close(self)

source code 

This is called by pyglet when the viewer is closed.

The screenshot folder is deleted, if no screenshots were taken.