[GRASS-SVN] r48052 -
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Sep 1 15:37:37 EDT 2011
Author: martinl
Date: 2011-09-01 12:37:37 -0700 (Thu, 01 Sep 2011)
New Revision: 48052
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_vdigit.py
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_window.py
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxvdigit.py
Log:
wxGUI/vdigit: implement edit line functionality (bug-fix)
(merge r48049 & r48051 from trunk)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_vdigit.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_vdigit.py 2011-09-01 19:27:04 UTC (rev 48051)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_vdigit.py 2011-09-01 19:37:37 UTC (rev 48052)
@@ -292,8 +292,8 @@
# list of ids to modify
self.moveInfo['id'] = list()
+ # set pen
if self.toolbar.GetAction() in ["moveVertex", "editLine"]:
- # set pen
pcolor = UserSettings.Get(group = 'vdigit', key = "symbol",
subkey = ["highlight", "color"])
self.pen = self.polypen = wx.Pen(colour = pcolor,
@@ -425,9 +425,10 @@
if self.mouse["use"] != "pointer" or not self.toolbar:
return
- if (self.toolbar.GetAction() == "addLine" and \
+ action = self.toolbar.GetAction()
+ if (action == "addLine" and \
self.toolbar.GetAction('type') in ["line", "boundary", "area"]) or \
- self.toolbar.GetAction() == "editLine":
+ action == "editLine":
# add line or boundary -> remove last point from the line
try:
removed = self.polycoords.pop()
@@ -437,32 +438,32 @@
except:
pass
- if self.toolbar.GetAction() == "editLine":
+ if action == "editLine":
# remove last vertex & line
if len(self.moveInfo['id']) > 1:
self.moveInfo['id'].pop()
self.UpdateMap(render = False, renderVector = False)
- elif self.toolbar.GetAction() in ["deleteLine", "moveLine", "splitLine",
- "addVertex", "removeVertex", "moveVertex",
- "copyCats", "flipLine", "mergeLine",
- "snapLine", "connectLine", "copyLine",
- "queryLine", "breakLine", "typeConv"]:
+ elif action in ["deleteLine", "moveLine", "splitLine",
+ "addVertex", "removeVertex", "moveVertex",
+ "copyCats", "flipLine", "mergeLine",
+ "snapLine", "connectLine", "copyLine",
+ "queryLine", "breakLine", "typeConv"]:
# varios tools -> unselected selected features
self.digit.GetDisplay().SetSelected([])
- if self.toolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] and \
+ if action in ["moveLine", "moveVertex", "editLine"] and \
hasattr(self, "moveInfo"):
del self.moveInfo
- elif self.toolbar.GetAction() == "copyCats":
+ elif action == "copyCats":
try:
del self.copyCatsList
del self.copyCatsIds
except AttributeError:
pass
- elif self.toolbar.GetAction() == "copyLine":
+ elif action == "copyLine":
del self.copyIds
if self.layerTmp:
self.Map.DeleteLayer(self.layerTmp)
@@ -472,7 +473,7 @@
self.polycoords = []
self.UpdateMap(render = False) # render vector
- elif self.toolbar.GetAction() == "zbulkLine":
+ elif action == "zbulkLine":
# reset polyline
self.polycoords = []
self.digit.GetDisplay().SetSelected([])
@@ -509,10 +510,10 @@
"splitLines"):
# unselect
self.digit.GetDisplay().SetSelected([])
-
+
if action == "addLine":
self.OnLeftDownAddLine(event)
-
+
elif action == "editLine" and \
hasattr(self, "moveInfo"):
self.OnLeftDownEditLine(event)
@@ -543,13 +544,14 @@
pos2 = self.Pixel2Cell(self.mouse['end'])
nselected = 0
+ action = self.toolbar.GetAction()
# -> delete line || move line || move vertex
- if self.toolbar.GetAction() in ("moveVertex",
- "editLine"):
+ if action in ("moveVertex",
+ "editLine"):
if len(self.digit.GetDisplay().GetSelected()) == 0:
nselected = self.digit.GetDisplay().SelectLineByPoint(pos1)['point']
- if self.toolbar.GetAction() == "editLine":
+ if action == "editLine":
try:
selVertex = self.digit.GetDisplay().GetSelectedVertex(pos1)[0]
except IndexError:
@@ -577,8 +579,8 @@
self.UpdateMap(render = False)
- elif self.toolbar.GetAction() in ("copyCats",
- "copyAttrs"):
+ elif action in ("copyCats",
+ "copyAttrs"):
if not hasattr(self, "copyCatsIds"):
# 'from' -> select by point
nselected = self.digit.GetDisplay().SelectLineByPoint(pos1)['point']
@@ -596,7 +598,7 @@
if nselected > 0:
self.copyCatsIds = self.digit.GetDisplay().GetSelected()
- elif self.toolbar.GetAction() == "queryLine":
+ elif action == "queryLine":
selected = self.digit.SelectLinesByQuery(bbox = (pos1, pos2))
nselected = len(selected)
if nselected > 0:
@@ -604,11 +606,11 @@
else:
# -> moveLine || deleteLine, etc. (select by point/box)
- if self.toolbar.GetAction() == 'moveLine' and \
+ if action == 'moveLine' and \
len(self.digit.GetDisplay().GetSelected()) > 0:
nselected = 0
else:
- if self.toolbar.GetAction() == 'moveLine':
+ if action == 'moveLine':
drawSeg = True
else:
drawSeg = False
@@ -620,10 +622,10 @@
nselected = 1
if nselected > 0:
- if self.toolbar.GetAction() in ("moveLine", "moveVertex") and \
+ if action in ("moveLine", "moveVertex") and \
hasattr(self, "moveInfo"):
# get pseudoDC id of objects which should be redrawn
- if self.toolbar.GetAction() == "moveLine":
+ if action == "moveLine":
# -> move line
self.moveInfo['id'] = self.digit.GetDisplay().GetSelected(grassId = False)
else: # moveVertex
@@ -649,12 +651,12 @@
# update selected
self.UpdateMap(render = False)
- if self.toolbar.GetAction() != "editLine":
+ if action != "editLine":
# -> move line || move vertex
self.UpdateMap(render = False)
else: # no vector object found
- if not (self.toolbar.GetAction() in ("moveLine",
+ if not (action in ("moveLine",
"moveVertex") and \
hasattr(self, "moveInfo") and \
len(self.moveInfo['id']) > 0):
@@ -774,34 +776,35 @@
# eliminate initial mouse moving efect
self.mouse['begin'] = self.mouse['end']
- if self.toolbar.GetAction() in ("deleteLine",
- "moveLine",
- "moveVertex",
- "copyCats",
- "copyAttrs",
- "editLine",
- "flipLine",
- "mergeLine",
- "snapLine",
- "queryLine",
- "breakLine",
- "typeConv",
- "connectLine"):
+ action = self.toolbar.GetAction()
+ if action in ("deleteLine",
+ "moveLine",
+ "moveVertex",
+ "copyCats",
+ "copyAttrs",
+ "editLine",
+ "flipLine",
+ "mergeLine",
+ "snapLine",
+ "queryLine",
+ "breakLine",
+ "typeConv",
+ "connectLine"):
self.OnLeftUpVarious(event)
- elif self.toolbar.GetAction() in ("splitLine",
- "addVertex",
- "removeVertex"):
+ elif action in ("splitLine",
+ "addVertex",
+ "removeVertex"):
self.OnLeftUpModifyLine(event)
- elif self.toolbar.GetAction() == "copyLine":
+ elif action == "copyLine":
self.OnLeftUpCopyLine(event)
- elif self.toolbar.GetAction() == "zbulkLine" and \
+ elif action == "zbulkLine" and \
len(self.polycoords) == 2:
self.OnLeftUpBulkLine(event)
- elif self.toolbar.GetAction() == "connectLine":
+ elif action == "connectLine":
self.OnLeftUpConnectLine(event)
if len(self.digit.GetDisplay().GetSelected()) > 0:
@@ -809,7 +812,8 @@
def _onRightDown(self, event):
# digitization tool (confirm action)
- if self.toolbar.GetAction() in ("moveLine", "moveVertex") and \
+ action = self.toolbar.GetAction()
+ if action in ("moveLine", "moveVertex") and \
hasattr(self, "moveInfo"):
pFrom = self.moveInfo['begin']
pTo = self.Pixel2Cell(event.GetPositionTuple())
@@ -817,11 +821,11 @@
move = (pTo[0] - pFrom[0],
pTo[1] - pFrom[1])
- if self.toolbar.GetAction() == "moveLine":
+ if action == "moveLine":
# move line
if self.digit.MoveSelectedLines(move) < 0:
return
- elif self.toolbar.GetAction() == "moveVertex":
+ elif action == "moveVertex":
# move vertex
fid = self.digit.MoveSelectedVertex(pFrom, move)
if fid < 0:
@@ -832,10 +836,10 @@
del self.moveInfo
def _onRightUp(self, event):
- """!Right mouse button released
+ """!Right mouse button released (confirm action)
"""
- # digitization tool (confirm action)
- if self.toolbar.GetAction() == "addLine" and \
+ action = self.toolbar.GetAction()
+ if action == "addLine" and \
self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
# -> add new line / boundary
try:
@@ -864,7 +868,7 @@
self.redrawAll = True
self.Refresh()
- # add new record into atribute table
+ # add new record into atribute table
if UserSettings.Get(group = 'vdigit', key = "addRecord", subkey = 'enabled') and \
(line is True or \
(not line and nfeat > 0)):
@@ -903,29 +907,29 @@
if addRecordDlg.mapDBInfo:
self._updateATM()
- elif self.toolbar.GetAction() == "deleteLine":
+ elif action == "deleteLine":
# -> delete selected vector features
if self.digit.DeleteSelectedLines() < 0:
return
self._updateATM()
- elif self.toolbar.GetAction() == "splitLine":
+ elif action == "splitLine":
# split line
if self.digit.SplitLine(self.Pixel2Cell(self.mouse['begin'])) < 0:
return
- elif self.toolbar.GetAction() == "addVertex":
+ elif action == "addVertex":
# add vertex
fid = self.digit.AddVertex(self.Pixel2Cell(self.mouse['begin']))
if fid < 0:
return
- elif self.toolbar.GetAction() == "removeVertex":
+ elif action == "removeVertex":
# remove vertex
fid = self.digit.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
if fid < 0:
return
self._geomAttrbUpdate([fid,])
- elif self.toolbar.GetAction() in ("copyCats", "copyAttrs"):
+ elif action in ("copyCats", "copyAttrs"):
try:
- if self.toolbar.GetAction() == 'copyCats':
+ if action == 'copyCats':
if self.digit.CopyCats(self.copyCatsList,
self.copyCatsIds, copyAttrb = False) < 0:
return
@@ -941,31 +945,31 @@
self._updateATM()
- elif self.toolbar.GetAction() == "editLine" and \
+ elif action == "editLine" and \
hasattr(self, "moveInfo"):
- line = self.digit.GetDisplay().GetSelected()
+ line = self.digit.GetDisplay().GetSelected()[0]
if self.digit.EditLine(line, self.polycoords) < 0:
return
del self.moveInfo
- elif self.toolbar.GetAction() == "flipLine":
+ elif action == "flipLine":
if self.digit.FlipLine() < 0:
return
- elif self.toolbar.GetAction() == "mergeLine":
+ elif action == "mergeLine":
if self.digit.MergeLine() < 0:
return
- elif self.toolbar.GetAction() == "breakLine":
+ elif action == "breakLine":
if self.digit.BreakLine() < 0:
return
- elif self.toolbar.GetAction() == "snapLine":
+ elif action == "snapLine":
if self.digit.SnapLine() < 0:
return
- elif self.toolbar.GetAction() == "connectLine":
+ elif action == "connectLine":
if len(self.digit.GetDisplay().GetSelected()) > 1:
if self.digit.ConnectLine() < 0:
return
- elif self.toolbar.GetAction() == "copyLine":
+ elif action == "copyLine":
if self.digit.CopyLine(self.copyIds) < 0:
return
del self.copyIds
@@ -974,7 +978,7 @@
self.UpdateMap(render = True, renderVector = False)
del self.layerTmp
- elif self.toolbar.GetAction() == "zbulkLine" and len(self.polycoords) == 2:
+ elif action == "zbulkLine" and len(self.polycoords) == 2:
pos1 = self.polycoords[0]
pos2 = self.polycoords[1]
@@ -985,15 +989,15 @@
if self.digit.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
dlg.step.GetValue()) < 0:
return
- self.UpdateMap(render = False, renderVector = True)
- elif self.toolbar.GetAction() == "typeConv":
+ self.UpdateMap(render = False)
+ elif action == "typeConv":
# -> feature type conversion
# - point <-> centroid
# - line <-> boundary
if self.digit.TypeConvForSelectedLines() < 0:
return
- if self.toolbar.GetAction() != "addLine":
+ if action != "addLine":
# unselect and re-render
self.digit.GetDisplay().SetSelected([])
self.polycoords = []
@@ -1004,60 +1008,56 @@
Debug.msg (5, "BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
(self.mouse['end'][0], self.mouse['end'][1]))
-
- if self.toolbar.GetAction() == "addLine" and \
+
+ action = self.toolbar.GetAction()
+ if action == "addLine" and \
self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
if len(self.polycoords) > 0:
self.MouseDraw(pdc = self.pdcTmp, begin = self.Cell2Pixel(self.polycoords[-1]))
- elif self.toolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] \
+ elif action in ["moveLine", "moveVertex", "editLine"] \
and hasattr(self, "moveInfo"):
dx = self.mouse['end'][0] - self.mouse['begin'][0]
dy = self.mouse['end'][1] - self.mouse['begin'][1]
-
- if len(self.moveInfo['id']) > 0:
- # draw lines on new position
- if self.toolbar.GetAction() == "moveLine":
- # move line
- for id in self.moveInfo['id']:
- self.pdcTmp.TranslateId(id, dx, dy)
- elif self.toolbar.GetAction() in ["moveVertex", "editLine"]:
- # move vertex ->
- # (vertex, left vertex, left line,
- # right vertex, right line)
+
+ # draw lines on new position
+ if action == "moveLine" and \
+ len(self.moveInfo['id']) > 0:
+ # move line
+ for id in self.moveInfo['id']:
+ self.pdcTmp.TranslateId(id, dx, dy)
+ elif action in ["moveVertex", "editLine"]:
+ # move vertex ->
+ # (vertex, left vertex, left line,
+ # right vertex, right line)
+
+ # do not draw static lines
+ if action == "moveVertex" and \
+ len(self.moveInfo['id']) > 0:
+ self.polycoords = []
+ self.pdcTmp.RemoveId(self.moveInfo['id'][0])
+ if self.moveInfo['id'][1] > 0: # previous vertex
+ x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][1])[0:2])
+ self.pdcTmp.RemoveId(self.moveInfo['id'][1] + 1)
+ self.polycoords.append((x, y))
+ self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
+
+ if self.moveInfo['id'][2] > 0: # next vertex
+ x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][2])[0:2])
+ self.pdcTmp.RemoveId(self.moveInfo['id'][2]-1)
+ self.polycoords.append((x, y))
- # do not draw static lines
- if self.toolbar.GetAction() == "moveVertex":
- self.polycoords = []
- ### self.pdcTmp.TranslateId(self.moveInfo['id'][0], dx, dy)
- self.pdcTmp.RemoveId(self.moveInfo['id'][0])
- if self.moveInfo['id'][1] > 0: # previous vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][1])[0:2])
- self.pdcTmp.RemoveId(self.moveInfo['id'][1] + 1)
- self.polycoords.append((x, y))
- ### x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][0])[0:2])
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- if self.moveInfo['id'][2] > 0: # next vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][2])[0:2])
- self.pdcTmp.RemoveId(self.moveInfo['id'][2]-1)
- self.polycoords.append((x, y))
+ self.ClearLines(pdc = self.pdcTmp)
+ self.DrawLines(pdc = self.pdcTmp)
- self.ClearLines(pdc = self.pdcTmp)
- self.DrawLines(pdc = self.pdcTmp)
-
- else: # edit line
- try:
- if self.moveInfo['id'][-1] > 0: # previous vertex
- self.MouseDraw(pdc = self.pdcTmp,
- begin = self.Cell2Pixel(self.polycoords[-1]))
- except: # no line
- self.moveInfo['id'] = []
- self.polycoords = []
+ if action == "editLine":
+ self.MouseDraw(pdc = self.pdcTmp,
+ begin = self.Cell2Pixel(self.polycoords[-1]))
self.Refresh() # TODO: use RefreshRect()
self.mouse['begin'] = self.mouse['end']
- elif self.toolbar.GetAction() == "zbulkLine":
+ elif action == "zbulkLine":
if len(self.polycoords) == 1:
# draw mouse moving
self.MouseDraw(self.pdcTmp)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_window.py 2011-09-01 19:27:04 UTC (rev 48051)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp_window.py 2011-09-01 19:37:37 UTC (rev 48052)
@@ -1106,12 +1106,12 @@
if (self.mouse['use'] == 'pointer' and
not digitToolbar):
return
+
self.mouse['end'] = event.GetPositionTuple()[:]
if (event.LeftIsDown() and
not (digitToolbar and
digitToolbar.GetAction() in ("moveLine",) and
self.digit.GetDisplay().GetSelected() > 0)):
- # draw box only when left mouse button is pressed
self.MouseDraw(pdc = self.pdcTmp)
def OnLeftDown(self, event):
@@ -1505,7 +1505,7 @@
if hasattr(self, "digit") and \
hasattr(self, "moveInfo"):
- self._zoom(event)
+ self._zoom(None)
self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
self.Map.region['e'], self.Map.region['w'])
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxvdigit.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxvdigit.py 2011-09-01 19:27:04 UTC (rev 48051)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxvdigit.py 2011-09-01 19:37:37 UTC (rev 48052)
@@ -709,32 +709,57 @@
def EditLine(self, line, coords):
"""!Edit existing line/boundary
- @param line id of line to be modified
+ @param line feature id to be modified
@param coords list of coordinates of modified line
@return feature id of new line
@return -1 on error
"""
- if self._checkMap():
+ if not self._checkMap():
return -1
- try:
- lineid = line[0]
- except:
- lineid = -1
-
if len(coords) < 2:
self.DeleteSelectedLines()
return 0
- ret = self.digit.RewriteLine(lineid, listCoords,
- bgmap, self._getSnapMode(),
- self._display.GetThreshold())
+ if not Vect_line_alive(self.poMapInfo, line):
+ self._error.DeadLine(line)
+ return -1
- if ret > 0:
+ # read original feature
+ ltype = Vect_read_line(self.poMapInfo, None, self.poCats, line)
+ if ltype < 0:
+ self._error.ReadLine(line)
+ return -1
+
+ # build feature geometry
+ Vect_reset_line(self.poPoints)
+ for p in coords:
+ Vect_append_point(self.poPoints, p[0], p[1], 0.0)
+
+ # apply snapping (node or vertex)
+ snap = self._getSnapMode()
+ if snap != NO_SNAP:
+ modeSnap = not (snap == SNAP)
+ Vedit_snap_line(self.poMapInfo, self.popoBgMapInfo,
+ int(self.poBgMapInfo is not None),
+ -1, self.poPoints, self._display.GetThreshold(), modeSnap)
+
+ 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()
+ else:
+ del self.changesets[changeset]
- return ret
+ if newline > 0 and self._settings['breakLines']:
+ self._breakLineAtIntersection(newline, None, changeset)
+
+ return newline
def FlipLine(self):
"""!Flip selected lines/boundaries
@@ -993,13 +1018,6 @@
return Vect_is_3d(self.poMapInfo)
- def GetLineCats(self, line=-1):
- """!Get layer/category pairs from given (selected) line
-
- @param line feature id (-1 for first selected line)
- """
- return dict(self.digit.GetLineCats(line))
-
def GetLineLength(self, line):
"""!Get line length
@@ -1102,10 +1120,6 @@
return ret
- def GetLayers(self):
- """!Get list of layers"""
- return self.digit.GetLayers()
-
def TypeConvForSelectedLines(self):
"""!Feature type conversion for selected objects.
More information about the grass-commit
mailing list