[GRASS-SVN] r48051 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 1 15:27:04 EDT 2011


Author: martinl
Date: 2011-09-01 12:27:04 -0700 (Thu, 01 Sep 2011)
New Revision: 48051

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
   grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
Log:
wxGUI/vdigit: implement edit line functionality


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py	2011-09-01 17:58:05 UTC (rev 48050)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_vdigit.py	2011-09-01 19:27:04 UTC (rev 48051)
@@ -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,
@@ -510,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)
@@ -836,9 +836,8 @@
             del self.moveInfo
         
     def _onRightUp(self, event):
-        """!Right mouse button released
+        """!Right mouse button released (confirm action)
         """
-        # digitization tool (confirm action)
         action = self.toolbar.GetAction()
         if action == "addLine" and \
                 self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
@@ -869,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)):
@@ -948,7 +947,7 @@
                 
         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
                 
@@ -990,7 +989,7 @@
                 if self.digit.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
                                          dlg.step.GetValue()) < 0:
                     return
-            self.UpdateMap(render = False, renderVector = True)
+            self.UpdateMap(render = False)
         elif action == "typeConv":
             # -> feature type conversion
             # - point <-> centroid
@@ -1020,45 +1019,40 @@
                 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 action == "moveLine":
-                    # 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)
+        
+            # 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 action == "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']

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-09-01 17:58:05 UTC (rev 48050)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-09-01 19:27:04 UTC (rev 48051)
@@ -1221,12 +1221,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):
@@ -1656,7 +1656,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/trunk/gui/wxpython/gui_modules/wxvdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-09-01 17:58:05 UTC (rev 48050)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-09-01 19:27:04 UTC (rev 48051)
@@ -716,32 +716,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
@@ -1000,13 +1025,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
 
@@ -1109,10 +1127,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