[GRASS-SVN] r48054 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Sep 1 16:17:44 EDT 2011
Author: martinl
Date: 2011-09-01 13:17:43 -0700 (Thu, 01 Sep 2011)
New Revision: 48054
Modified:
grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py
grass/trunk/gui/wxpython/gui_modules/vdigit.py
grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
Log:
wxGUI/vdigit: fix 'update categories', implement SetLineCats()
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py 2011-09-01 19:38:43 UTC (rev 48053)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py 2011-09-01 20:17:43 UTC (rev 48054)
@@ -363,7 +363,7 @@
if self.parent.dialogs['category'] is None:
# open new dialog
dlg = VDigitCategoryDialog(parent = self,
- map = mapLayer,
+ vectorName = mapLayer,
cats = cats,
pos = posWindow,
title = _("Update categories"))
Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py 2011-09-01 19:38:43 UTC (rev 48053)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py 2011-09-01 20:17:43 UTC (rev 48054)
@@ -816,25 +816,22 @@
class VDigitCategoryDialog(wx.Dialog, listmix.ColumnSorterMixin):
def __init__(self, parent, title,
- map, query = None, cats = None,
- pos = wx.DefaultPosition,
- style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
+ vectorName, query = None, cats = None,
+ style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
"""!Dialog used to display/modify categories of vector objects
@param parent
@param title dialog title
@param query {coordinates, qdist} - used by v.edit/v.what
@param cats directory of lines (layer/categories) - used by vdigit
- @param pos
- @param style
+ @param style dialog style
"""
- # parent
- self.parent = parent # mapdisplay.BufferedWindow class instance
+ self.parent = parent # mapdisplay.BufferedWindow class instance
self.digit = parent.digit
# map name
- self.map = map
-
+ self.vectorName = vectorName
+
# line : {layer: [categories]}
self.cats = {}
@@ -856,7 +853,7 @@
self.cats_orig = copy.deepcopy(self.cats)
wx.Dialog.__init__(self, parent = self.parent, id = wx.ID_ANY, title = title,
- style = style, pos = pos)
+ style = style, **kwargs)
# list of categories
box = wx.StaticBox(parent = self, id = wx.ID_ANY,
@@ -1122,7 +1119,7 @@
ret = gcmd.RunCommand('v.what',
parent = self,
quiet = True,
- map = self.map,
+ map = self.vectorName,
east_north = '%f,%f' % \
(float(coords[0]), float(coords[1])),
distance = qdist)
@@ -1172,7 +1169,7 @@
"""
for fid in self.cats.keys():
newfid = self.ApplyChanges(fid)
- if fid == self.fid:
+ if fid == self.fid and newfid > 0:
self.fid = newfid
def ApplyChanges(self, fid):
@@ -1240,28 +1237,26 @@
if layer <= 0:
raise ValueError
except ValueError:
- dlg = wx.MessageDialog(self, _("Unable to add new layer/category <%(layer)s/%(category)s>.\n"
- "Layer and category number must be integer.\n"
- "Layer number must be greater then zero.") %
- {'layer' : str(self.layerNew.GetValue()),
- 'category' : str(self.catNew.GetValue())},
- _("Error"), wx.OK | wx.ICON_ERROR)
- dlg.ShowModal()
- dlg.Destroy()
+ gcmd.GError(parent = self,
+ message = _("Unable to add new layer/category <%(layer)s/%(category)s>.\n"
+ "Layer and category number must be integer.\n"
+ "Layer number must be greater then zero.") %
+ {'layer' : str(self.layerNew.GetValue()),
+ 'category' : str(self.catNew.GetValue())})
return False
-
+
if layer not in self.cats[self.fid].keys():
self.cats[self.fid][layer] = []
-
+
self.cats[self.fid][layer].append(cat)
-
+
# reload list
self.itemDataMap = self.list.Populate(self.cats[self.fid],
update = True)
-
+
# update category number for add
self.catNew.SetValue(cat + 1)
-
+
event.Skip()
return True
Modified: grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdigit.py 2011-09-01 19:38:43 UTC (rev 48053)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdigit.py 2011-09-01 20:17:43 UTC (rev 48054)
@@ -1109,7 +1109,7 @@
return perimeter
- def SetLineCats(self, line, layer, cats, add=True):
+ def SetLineCats(self, line, layer, cats, add = True):
"""!Set categories for given line and layer
@param line feature id
@@ -1120,13 +1120,46 @@
@return new feature id (feature need to be rewritten)
@return -1 on error
"""
- ret = self.digit.SetLineCats(line, layer, cats, add)
-
- if ret > 0:
+ if not self._checkMap():
+ return -1
+
+ if line < 1 and len(self._display.selected['ids']) < 1:
+ return -1
+
+ update = False
+ if line == -1:
+ update = True
+ line = self._display.selected['ids'][0]
+
+ if not Vect_line_alive(self.poMapInfo, line):
+ return -1
+
+ ltype = Vect_read_line(self.poMapInfo, self.poPoints, self.poCats, line)
+ if ltype < 0:
+ self._error.ReadLine(line)
+ return -1
+
+ for c in cats:
+ if add:
+ Vect_cat_set(self.poCats, layer, c)
+ else:
+ Vect_field_cat_del(self.poCats, layer, c)
+
+ nlines = Vect_get_num_lines(self.poMapInfo)
+ changeset = self._addActionsBefore()
+ newline = Vect_rewrite_line(self.poMapInfo, line, ltype,
+ self.poPoints, self.poCats)
+
+ if newline > 0:
+ self._addActionsAfter(changeset, nlines)
self.toolbar.EnableUndo()
+
+ if update:
+ # update line id since the line was rewritten
+ self._display.selected['ids'][0] = newline
+
+ return newline
- return ret
-
def TypeConvForSelectedLines(self):
"""!Feature type conversion for selected objects.
More information about the grass-commit
mailing list