[GRASS-SVN] r37973 - in grass/branches/develbranch_6/gui/wxpython:
gui_modules xml
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 19 15:07:31 EDT 2009
Author: martinl
Date: 2009-06-19 15:07:31 -0400 (Fri, 19 Jun 2009)
New Revision: 37973
Added:
grass/branches/develbranch_6/gui/wxpython/gui_modules/units.py
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py
grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd
Log:
wxGUI/vdigit: units for geometry attributes
(merge from trunk, r37971)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py 2009-06-19 18:54:03 UTC (rev 37972)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py 2009-06-19 19:07:31 UTC (rev 37973)
@@ -28,6 +28,7 @@
"rules.py",
"sqlbuilder.py",
"toolbars.py",
+ "units.py",
"utils.py",
"vdigit.py",
"workspace.py",
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2009-06-19 18:54:03 UTC (rev 37972)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2009-06-19 19:07:31 UTC (rev 37973)
@@ -32,6 +32,7 @@
import globalvar
from debug import Debug
from preferences import globalSettings as UserSettings
+from units import ConvertValue as UnitsConvertValue
from vdigit import GV_LINES as VDigit_Lines_Type
from vdigit import VDigitCategoryDialog
from vdigit import VDigitZBulkDialog
@@ -1180,14 +1181,18 @@
val = -1
if attrb == 'length':
val = digit.GetLineLength(fid)
+ type = attrb
elif attrb == 'area':
val = digit.GetAreaSize(fid)
+ type = attrb
elif attrb == 'perimeter':
val = digit.GetAreaPerimeter(fid)
+ type = 'length'
if val > 0:
layer = int(UserSettings.Get(group='vdigit', key="layer", subkey='value'))
- column = vdigit['geomAttr'][attrb]
+ column = vdigit['geomAttr'][attrb]['column']
+ val = UnitsConvertValue(val, type, vdigit['geomAttr'][attrb]['units'])
dialog.SetColumnValue(layer, column, val)
dialog.OnReset()
Property changes on: grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:keywords
+ Author Date Id
Name: svn:eol-style
+ native
Copied: grass/branches/develbranch_6/gui/wxpython/gui_modules/units.py (from rev 37971, grass/trunk/gui/wxpython/gui_modules/units.py)
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/units.py (rev 0)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/units.py 2009-06-19 19:07:31 UTC (rev 37973)
@@ -0,0 +1,118 @@
+"""!
+ at package units
+
+ at brief Units management
+
+Probably will be replaced by Python SWIG fns in the near future(?)
+
+Usage:
+
+ at code
+from units import Units
+ at endcode
+
+Classes:
+ - BaseUnits
+
+(C) 2009 by the GRASS Development Team
+
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+class BaseUnits:
+ def __init__(self):
+ self._units = dict()
+ self._units['length'] = { 0 : { 'key' : 'mu', 'label' : _('map units') },
+ 1 : { 'key' : 'me', 'label' : _('meters') },
+ 2 : { 'key' : 'km', 'label' : _('kilometers') },
+ 3 : { 'key' : 'mi', 'label' : _('miles') },
+ 4 : { 'key' : 'ft', 'label' : _('feet') } }
+
+ self._units['area'] = { 0 : { 'key' : 'mu', 'label' : _('sq map units') },
+ 1 : { 'key' : 'me', 'label' : _('sq meters') },
+ 2 : { 'key' : 'km', 'label' : _('sq kilometers') },
+ 3 : { 'key' : 'ar', 'label' : _('acres') },
+ 4 : { 'key' : 'ht', 'label' : _('hectares') } }
+
+ def GetUnitsList(self, type):
+ """!Get list of units (their labels)
+
+ @param type units type ('length' or 'area')
+
+ @return list of units labels
+ """
+ result = list()
+ try:
+ keys = self._units[type].keys()
+ keys.sort()
+ for idx in keys:
+ result.append(self._units[type][idx]['label'])
+ except KeyError:
+ pass
+
+ return result
+
+ def GetUnitsKey(self, type, index):
+ """!Get units key based on index
+
+ @param type units type ('length' or 'area')
+ @param index units index
+ """
+ return self._units[type][index]['key']
+
+ def GetUnitsIndex(self, type, key):
+ """!Get units index based on key
+
+ @param type units type ('length' or 'area')
+ @param key units key, e.g. 'me' for meters
+
+ @return index
+ """
+ for k, u in self._units[type].iteritems():
+ if u['key'] == key:
+ return k
+ return 0
+
+Units = BaseUnits()
+
+def ConvertValue(value, type, units):
+ """!Convert value from map units to given units
+
+ Inspired by vector/v.to.db/units.c
+
+ @param value value to be converted
+ @param type units type ('length', 'area')
+ @param unit destination units
+ """
+ # get map units
+ # TODO
+
+ f = 1
+ if type == 'length':
+ if units == 'me':
+ f = 1.0
+ elif units == 'km':
+ f = 1.0e-3
+ elif units == 'mi':
+ f = 6.21371192237334e-4
+ elif units == 'ft':
+ f = 3.28083989501312
+ else: # -> area
+ if units == 'me':
+ f = 1.0
+ elif units == 'km':
+ f = 1.0e-6
+ elif units == 'mi':
+ f = 3.86102158542446e-7
+ elif units == 'ft':
+ f = 10.7639104167097
+ elif units == 'ar':
+ f = 2.47105381467165e-4
+ elif units == 'ht':
+ f = 1.0e-4
+
+ return f * value
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2009-06-19 18:54:03 UTC (rev 37972)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2009-06-19 19:07:31 UTC (rev 37973)
@@ -46,6 +46,7 @@
from debug import Debug as Debug
import gselect
import globalvar
+from units import Units
from preferences import globalSettings as UserSettings
try:
digitPath = os.path.join(globalvar.ETCWXDIR, "vdigit")
@@ -1542,19 +1543,28 @@
layer = layer, excludeKey = True,
type = ['integer', 'double precision'])
# units
- ### TODO: more units
- units = wx.Choice(parent = panel, id = wx.ID_ANY,
- choices = [_("map units")])
+ if attrb == 'area':
+ choices = Units.GetUnitsList('area')
+ else:
+ choices = Units.GetUnitsList('length')
+ win_units = wx.Choice(parent = panel, id = wx.ID_ANY,
+ choices = choices, size=(120, -1))
# default values
check.SetValue(False)
-
if item and tree.GetPyData(item)[0]['vdigit'] and \
tree.GetPyData(item)[0]['vdigit'].has_key('geomAttr') and \
tree.GetPyData(item)[0]['vdigit']['geomAttr'].has_key(attrb):
check.SetValue(True)
- column.SetStringSelection(tree.GetPyData(item)[0]['vdigit']['geomAttr'][attrb])
-
+ column.SetStringSelection(tree.GetPyData(item)[0]['vdigit']['geomAttr'][attrb]['column'])
+ if attrb == 'area':
+ type = 'area'
+ else:
+ type = 'length'
+ unitsIdx = Units.GetUnitsIndex(type,
+ tree.GetPyData(item)[0]['vdigit']['geomAttr'][attrb]['units'])
+ win_units.SetSelection(unitsIdx)
+
if not vectorName:
check.Enable(False)
column.Enable(False)
@@ -1564,14 +1574,14 @@
self.geomAttrb[attrb]['check'] = check.GetId()
self.geomAttrb[attrb]['column'] = column.GetId()
- self.geomAttrb[attrb]['units'] = units.GetId()
+ self.geomAttrb[attrb]['units'] = win_units.GetId()
gridSizer.Add(item = check,
flag = wx.ALIGN_CENTER_VERTICAL,
pos = (row, 0))
gridSizer.Add(item = column,
pos = (row, 1))
- gridSizer.Add(item = units,
+ gridSizer.Add(item = win_units,
pos = (row, 2))
row += 1
@@ -1810,13 +1820,21 @@
for key, val in self.geomAttrb.iteritems():
checked = self.FindWindowById(val['check']).IsChecked()
column = self.FindWindowById(val['column']).GetValue()
- if not tree.GetPyData(item)[0]['vdigit']:
+ unitsIdx = self.FindWindowById(val['units']).GetSelection()
+ if item and not tree.GetPyData(item)[0]['vdigit']:
tree.GetPyData(item)[0]['vdigit'] = { 'geomAttr' : dict() }
if checked: # enable
- tree.GetPyData(item)[0]['vdigit']['geomAttr'][key] = column
+ if key == 'area':
+ type = key
+ else:
+ type = 'length'
+ unitsKey = Units.GetUnitsKey(type, unitsIdx)
+ tree.GetPyData(item)[0]['vdigit']['geomAttr'][key] = { 'column' : column,
+ 'units' : unitsKey }
else:
- if tree.GetPyData(item)[0]['vdigit']['geomAttr'].has_key(key):
+ if item and tree.GetPyData(item)[0]['vdigit'] and \
+ tree.GetPyData(item)[0]['vdigit']['geomAttr'].has_key(key):
del tree.GetPyData(item)[0]['vdigit']['geomAttr'][key]
# snapping threshold
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py 2009-06-19 18:54:03 UTC (rev 37972)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py 2009-06-19 19:07:31 UTC (rev 37973)
@@ -240,7 +240,11 @@
for node in node_vdigit.findall('geometryAttribute'):
if not vdigit.has_key('geomAttr'):
vdigit['geomAttr'] = dict()
- vdigit['geomAttr'][node.get('type')] = node.get('column')
+ type = node.get('type')
+ vdigit['geomAttr'][type] = dict()
+ vdigit['geomAttr'][type]['column'] = node.get('column') # required
+ # default map units
+ vdigit['geomAttr'][type]['units'] = node.get('units', 'mu')
return vdigit
@@ -771,9 +775,12 @@
self.file.write('%s<vdigit>\n' % (' ' * self.indent))
if vdigit.has_key('geomAttr'):
self.indent += 4
- for type, column in vdigit['geomAttr'].iteritems():
- self.file.write('%s<geometryAttribute type="%s" column="%s" />\n' % \
- (' ' * self.indent, type, column))
+ for type, val in vdigit['geomAttr'].iteritems():
+ units = ''
+ if val['units'] != 'mu':
+ units = ' units="%s"' % val['units']
+ self.file.write('%s<geometryAttribute type="%s" column="%s"%s />\n' % \
+ (' ' * self.indent, type, val['column'], units))
self.indent -= 4
self.file.write('%s</vdigit>\n' % (' ' * self.indent))
# nviz
Modified: grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd 2009-06-19 18:54:03 UTC (rev 37972)
+++ grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd 2009-06-19 19:07:31 UTC (rev 37973)
@@ -88,6 +88,7 @@
<!ELEMENT geometryAttribute EMPTY>
<!ATTLIST parameter type (length | area | perimeter) #REQUIRED>
<!ATTLIST parameter column CDATA #REQUIRED>
+<!ATTLIST parameter units CDATA #IMPLIED>
<!-- *********************** Nviz *********************** -->
More information about the grass-commit
mailing list