Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N900 version: Calc tab in Cache Details and Dutch Tools #140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
29 changes: 24 additions & 5 deletions advancedcaching/geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ class GeocacheCoordinate(geo.Coordinate):
ATTRS = ('lat', 'lon', 'title', 'name', 'shortdesc', 'desc', 'hints', 'type', \
'size', 'difficulty', 'terrain', 'owner', 'found', 'waypoints', \
'images', 'notes', 'fieldnotes', 'logas', 'logdate', 'marked', \
'logs', 'status', 'vars', 'alter_lat', 'alter_lon', 'updated', 'user_coordinates', 'attributes')
'logs', 'status', 'vars', 'alter_lat', 'alter_lon', 'updated', 'user_coordinates', 'attributes', 'last_viewed')

# These are the table fields which can safely be updated when
# the geocache is re-downloaded. User data should not be contained
# in them.
NON_USER_ATTRS = ('lat', 'lon', 'title', 'shortdesc', 'desc', 'hints', 'type', \
'size', 'difficulty', 'terrain', 'owner', 'found', 'waypoints', \
'images', 'logs', 'status', 'attributes')
'images', 'logs', 'status', 'attributes', 'updated')

SQLROW = {
'lat': 'REAL',
Expand Down Expand Up @@ -132,6 +132,7 @@ class GeocacheCoordinate(geo.Coordinate):
'updated' : 'INTEGER',
'user_coordinates' : 'TEXT',
'attributes' : 'TEXT',
'last_viewed' : 'INTEGER', # SQLite doesn't have real DATETIME data type
}
def __init__(self, lat, lon=None, name='', data=None):
geo.Coordinate.__init__(self, lat, lon, name)
Expand Down Expand Up @@ -166,18 +167,25 @@ def __init__(self, lat, lon=None, name='', data=None):
self.updated = 0
self.user_coordinates = ''
self.attributes = ''
self.last_viewed = 0

def clone(self):
n = GeocacheCoordinate(self.lat, self.lon)
for k in self.ATTRS:
setattr(n, k, getattr(self, k))
return n

def updated(self):
def touch_updated(self):
self.updated = int(time.mktime(datetime.now().timetuple()))

def get_updated(self):
return datetime.fromtimestamp(self.updated)
return datetime.fromtimestamp(self.updated) if (self.updated != 0) else None

def touch_viewed(self):
self.last_viewed = int(time.mktime(datetime.now().timetuple()))

def get_last_viewed(self):
return datetime.fromtimestamp(self.last_viewed)

def get_difficulty(self):
return "%.1f" % (self.difficulty / 10.0) if self.difficulty != -1 else '?'
Expand Down Expand Up @@ -301,6 +309,14 @@ def get_size_string(self):
else:
return self.SIZES[self.size]

def add_attribute(self, attr):
if not self.attributes:
self.attributes = attr
else:
s = ','.split(self.attributes)
if not attr in s:
s.append(attr)
self.attributes = ','.join(s)

def get_gs_type(self):
if self.TYPE_MAPPING.has_key(self.type):
Expand Down Expand Up @@ -439,9 +455,12 @@ def get_collected_coordinates(self, format, include_unknown = True, htmlcallback
logger.debug("Added coordinate, name=%r, title=%r, user_coordinate_id=%r" % (coord.name, coord.title, coord.user_coordinate_id))

# parsed from notes
# alternative - short! naming of the Notes section, by separate numbering of all coordinates through variable ii
ii = 1
for coord in geo.search_coordinates(self.notes):
coord.title = "From Notes"
coord.display_text = "from notes: %s" % coord.get_latlon(format)
#coord.display_text = "from notes: %s" % coord.get_latlon(format)
coord.display_text = "notes %s" % ii
coord.comment = "This coordinate was manually entered in the notes field."
coord.user_coordinate_id = None
clist[i] = coord
Expand Down
238 changes: 238 additions & 0 deletions advancedcaching/hildon_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import threadpool
import logging
import geo
import math
logger = logging.getLogger('plugins')

class HildonSearchPlace(object):
Expand Down Expand Up @@ -824,6 +825,18 @@ def _on_show_tools(self, caller, data = None):
button.connect("clicked", lambda caller: dialog.hide())
list.pack_start(button)

button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
button.set_label("Dutch Grid RD 2 WGS")
button.connect("clicked", self._show_tool_rd2wgs, None)
button.connect("clicked", lambda caller: dialog.hide())
list.pack_start(button)

button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
button.set_label("WGS 2 Dutch Grid RD")
button.connect("clicked", self._show_tool_wgs2rd, None)
button.connect("clicked", lambda caller: dialog.hide())
list.pack_start(button)

dialog.show_all()
dialog.run()
dialog.hide()
Expand Down Expand Up @@ -899,6 +912,231 @@ def to_arabic(widget):
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)

# addition rob_kouw
def _show_tool_rd2wgs(self, caller, data = None):
RESULT_WPT, RESULT_TARGET = range(2)
dialog = gtk.Dialog("Dutch Grid RD 2 WGS", self.window, gtk.DIALOG_DESTROY_WITH_PARENT, ("as target", RESULT_TARGET))
if self.current_cache != None:
dialog.add_button("add waypoint", RESULT_WPT)
#dialog.set_size_request(800, 480)

rdx = hildon.Entry(gtk.HILDON_SIZE_AUTO)
rdx.set_property("hildon-input-mode", gtk.HILDON_GTK_INPUT_MODE_NUMERIC)

dialog.vbox.pack_start(hildon.Caption(None, "Dutch Grid X in Meters", rdx, None, 0))

rdy = hildon.Entry(gtk.HILDON_SIZE_AUTO)
rdy.set_property("hildon-input-mode", gtk.HILDON_GTK_INPUT_MODE_NUMERIC)
dialog.vbox.pack_start(hildon.Caption(None, "Dutch Grid Y in Meters", rdy, None, 0))

result = gtk.Label()
result.set_text("-7<X<300 km, 289<Y<629 km")

dialog.vbox.pack_start(hildon.Caption(None, "Resulting Point", result, None, 0))

resulting_coordinate = [None]

def recalc(widget):
resulting_coordinate = rd2wgs(rdx.get_text(), rdy.get_text())
result.set_text(resulting_coordinate[1])

rdx.connect('changed', recalc)
rdy.connect('changed', recalc)

dialog.show_all()
res = dialog.run()
dialog.hide()
if res == RESULT_WPT:
if resulting_coordinate[0] == None:
return
name = "RD X %s, Y %s" % (rdx.get_text(), rdy.get_text())
self.current_cache.get_user_coordinates(None)
self.current_cache.set_user_coordinate(geocaching.GeocacheCoordinate.USER_TYPE_COORDINATE, (resulting_coordinate[0].lat, resulting_coordinate[0].lon), name)
self.core.save_cache_attribute(self.current_cache, 'user_coordinates')
self._on_cache_changed(None, self.current_cache)
#self.update_coords()
elif res == RESULT_TARGET:
if resulting_coordinate[0] == None:
return
self.set_target(resulting_coordinate[0])

def rd2wgs(rdx_text, rdy_text):

#---------------------------------------------------------------------
# Inverse transformation of RD (Dutch Rijksdriehoek) coordinates (X, Y)
# into ellipsoid wgs84 coordinates (φ, λ or lat, lon)
# Intended as an example of how to implement the formulas from the pdf
# : http://www.dekoepel.nl/pdf/Transformatieformules.pdf, page 2
#
# Original Author: Ronald Vogelaar
# Date: March 11, 2010
# License: GNU General Public License Version 3
# http://www.fsf.org/copyleft/gpl.html
#
# Copyright (c) 2010 Ronald Vogelaar ([email protected])
# with permission from:
# Sogeti Nederland BV, Infrastructure Services division
# Ported to a Python library by Erik Romijn <[email protected]> in 2011
# Ported to AGTL/N900 by rob_kouw <geokouw at gmail dot com>
#
# Source of inspiration:
# http://www.dekoepel.nl/pdf/Transformatieformules.pdf
#---------------------------------------------------------------------

# X0,Y0 Base RD coordinates Amersfoort
RDX_BASE = 155000.
RDY_BASE = 463000.
# φ0, λ0 Same base, but as wgs84 coordinates
LAT_BASE = 52.15517440
LON_BASE = 5.38720621

Kpq = []
Lpq = []

for p in range(0, 6):
Lpq.append([])
Kpq.append([])
for q in range (0, 5):
Lpq[p].append(0)
Kpq[p].append(0)

#coefficients
Kpq[0][1] = 3235.65389
Kpq[2][0] = -32.58297
Kpq[0][2] = -0.24750
Kpq[2][1] = -0.84978
Kpq[0][3] = -0.06550
Kpq[2][2] = -0.01709
Kpq[1][0] = -0.00738
Kpq[4][0] = 0.00530
Kpq[2][3] = -0.00039
Kpq[4][1] = 0.00033
Kpq[1][1] = -0.00012

Lpq[1][0] = 5260.52916
Lpq[1][1] = 105.94684
Lpq[1][2] = 2.45656
Lpq[3][0] = -0.81885
Lpq[1][3] = 0.05594
Lpq[3][1] = -0.05607
Lpq[0][1] = 0.01199
Lpq[3][2] = -0.00256
Lpq[1][4] = 0.00128
Lpq[0][2] = 0.00022
Lpq[2][0] = -0.00022
Lpq[5][0] = 0.00026

try:
if int(rdx_text) > -7000 and int(rdx_text) < 300000 and int(rdy_text) > 289000 and int(rdy_text) < 629000:
deltaX = (float(rdx_text) - RDX_BASE) * .00001
deltaY = (float(rdy_text) - RDY_BASE) * .00001
reslat = 0.
reslon = 0.

for q in range(0,5):
for p in range(0,6):
reslat = reslat + Kpq[p][q] * math.pow(deltaX, p) * math.pow(deltaY, q)
reslon = reslon + Lpq[p][q] * math.pow(deltaX, p) * math.pow(deltaY, q)

result_coordinate = geo.Coordinate( LAT_BASE + reslat / 3600., LON_BASE + reslon / 3600. )
text = result_coordinate.get_latlon()
else:
result_coordinate = None
text = "-7<X<300 km, 289<Y<629 km"

except Exception, e:
result_coordinate = None
text = "-7<X<300 km, 289<Y<629 km"

return tuple(result_coordinate, text)

def _show_tool_wgs2rd(self, widget, data):
dialog = gtk.Dialog("WGS 2 Dutch Grid RD", None, gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

# for now: the easy way, just converting current target into Dutch RD coordinate system
origin = [self.core.current_target]

(wsg_text, rd_text) = wgs2rd(origin)

res_text = hildon.TextView()
res_text.get_buffer().set_text(rd_text)
dialog.vbox.pack_start(res_text)
l = gtk.Label()
l.set_alignment(0, 0.5)
l.set_markup(wsg_text)

dialog.vbox.pack_start(l)
dialog.show_all()
result = dialog.run()
dialog.hide()

def wgs2rd(origin):
#---------------------------------------------------------------------
# Transformation of ellipsoid wgs84 coordinates (φ, λ or lat, lon)
# into RD (Dutch Rijksdriehoek) coordinates (X, Y)
# See above for copyright etc.
#---------------------------------------------------------------------

# X0,Y0 Base RD coordinates Amersfoort
RDX_BASE = 155000.
RDY_BASE = 463000.
# φ0, λ0 Same base, but as wgs84 coordinates
LAT_BASE = 52.15517440
LON_BASE = 5.38720621

Rpq = []
Spq = []

for p in range(0, 6):
Rpq.append([])
Spq.append([])
for q in range (0, 5):
Rpq[p].append(0)
Spq[p].append(0)

#coefficients
Rpq[0][1] = 190094.945
Rpq[1][1] = -11832.228
Rpq[2][1] = -114.221
Rpq[0][3] = -32.391
Rpq[1][0] = -0.705
Rpq[3][1] = -2.340
Rpq[1][3] = -0.608
Rpq[0][2] = -0.008
Rpq[2][3] = 0.148

Spq[1][0] = 309056.544
Spq[0][2] = 3638.893
Spq[2][0] = 73.077
Spq[1][2] = -157.984
Spq[3][0] = 59.788
Spq[0][1] = 0.433
Spq[2][2] = -6.439
Spq[1][1] = -0.032
Spq[0][4] = 0.092
Spq[1][4] = -0.054

#Calculate X, Y of origin
dlat = 0.36 * (origin[0].lat - LAT_BASE)
dlon = 0.36 * (origin[0].lon - LON_BASE)
Xorigin = 0
Yorigin = 0

for q in range(0,5):
for p in range(0,6):
Xorigin = Xorigin + Rpq[p][q] * math.pow(dlat, p) * math.pow(dlon, q)
Yorigin = Yorigin + Spq[p][q] * math.pow(dlat, p) * math.pow(dlon, q)

Xorigin = int(Xorigin + RDX_BASE)
Yorigin = int(Yorigin + RDY_BASE)

wsg_text = "Current target:\n" + origin[0].get_latlon()
rd_text = "RD X %s, Y %s" % (Xorigin, Yorigin)

return tuple(wsg_text, rd_text)

# end addition rob_kouw

def _show_tool_heading(self, caller, data = None):
RESULT_WPT, RESULT_TARGET = range(2)
dialog = gtk.Dialog("Coordinate Projection", self.window, gtk.DIALOG_DESTROY_WITH_PARENT, ("as target", RESULT_TARGET))
Expand Down
27 changes: 13 additions & 14 deletions advancedcaching/hildongui.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,12 @@ def show_cache(self, cache, select=True):

notebook.append_page(p, gtk.Label("Info"))

# Description
p = hildon.PannableArea()
notebook.append_page(p, gtk.Label("Description"))
text_longdesc = re.sub(r'(?i)<img[^>]+?>', ' [to get all images, re-download description] ', re.sub(r'\[\[img:([^\]]+)\]\]', lambda a: self._replace_image_callback(a, cache), cache.desc))

if cache.was_downloaded():
# Description
p = hildon.PannableArea()
notebook.append_page(p, gtk.Label("Description"))
text_longdesc = re.sub(r'(?i)<img[^>]+?>', ' [to get all images, re-download description] ', re.sub(r'\[\[img:([^\]]+)\]\]', lambda a: self._replace_image_callback(a, cache), cache.desc))
if not self.settings['options_show_html_description']:

widget_description = gtk.Label()
Expand Down Expand Up @@ -1020,18 +1021,16 @@ def show_hints(widget):
# images
self.build_cache_images(cache, notebook)

# calculated coords
cache_calc_box = gtk.VBox()
notebook.append_page(cache_calc_box, gtk.Label("Calc"))

def rebuild_cache_calc():
cache.start_calc(self._strip_html(text_longdesc))
self.build_cache_calc(cache, cache_calc_box)

rebuild_cache_calc()
self.rebuild_cache_calc = rebuild_cache_calc
# calculated coords
cache_calc_box = gtk.VBox()
notebook.append_page(cache_calc_box, gtk.Label("Calc"))

def rebuild_cache_calc():
cache.start_calc(self._strip_html(text_longdesc))
self.build_cache_calc(cache, cache_calc_box)

rebuild_cache_calc()
self.rebuild_cache_calc = rebuild_cache_calc

# coords
p = gtk.VBox()
Expand Down