瀏覽代碼

wxGUI/vdigit: fix deleting areas

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58419 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 年之前
父節點
當前提交
a40b612dfc
共有 2 個文件被更改,包括 65 次插入30 次删除
  1. 23 17
      gui/wxpython/vdigit/mapwindow.py
  2. 42 13
      gui/wxpython/vdigit/wxdisplay.py

+ 23 - 17
gui/wxpython/vdigit/mapwindow.py

@@ -6,7 +6,7 @@
 Classes:
 Classes:
  - mapwindow::VDigitWindow
  - mapwindow::VDigitWindow
 
 
-(C) 2011 by the GRASS Development Team
+(C) 2011-2013 by the GRASS Development Team
 
 
 This program is free software under the GNU General Public License
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -28,6 +28,7 @@ from core.utils     import ListOfCatsToRange, _
 from core.globalvar import QUERYLAYER
 from core.globalvar import QUERYLAYER
 from vdigit.dialogs import VDigitCategoryDialog, VDigitZBulkDialog, VDigitDuplicatesDialog
 from vdigit.dialogs import VDigitCategoryDialog, VDigitZBulkDialog, VDigitDuplicatesDialog
 from gui_core       import gselect
 from gui_core       import gselect
+from vdigit.wxdigit import GV_CENTROID
 
 
 class VDigitWindow(BufferedMapWindow):
 class VDigitWindow(BufferedMapWindow):
     """!A Buffered window extended for vector digitizer.
     """!A Buffered window extended for vector digitizer.
@@ -493,6 +494,7 @@ class VDigitWindow(BufferedMapWindow):
                         "queryLine", "breakLine", "typeConv"]:
                         "queryLine", "breakLine", "typeConv"]:
             # various tools -> unselected selected features
             # various tools -> unselected selected features
             self.digit.GetDisplay().SetSelected([])
             self.digit.GetDisplay().SetSelected([])
+            
             if action in ["moveLine", "moveVertex", "editLine"] and \
             if action in ["moveLine", "moveVertex", "editLine"] and \
                     hasattr(self, "moveInfo"):
                     hasattr(self, "moveInfo"):
                 del self.moveInfo
                 del self.moveInfo
@@ -599,7 +601,7 @@ class VDigitWindow(BufferedMapWindow):
         if action in ("moveVertex",
         if action in ("moveVertex",
                       "editLine"):
                       "editLine"):
             if len(self.digit.GetDisplay().GetSelected()) == 0:
             if len(self.digit.GetDisplay().GetSelected()) == 0:
-                nselected = self.digit.GetDisplay().SelectLineByPoint(pos1)['point']
+                nselected = int(self.digit.GetDisplay().SelectLineByPoint(pos1)['line'] != -1)
                 
                 
                 if action == "editLine":
                 if action == "editLine":
                     try:
                     try:
@@ -633,7 +635,7 @@ class VDigitWindow(BufferedMapWindow):
                         "copyAttrs"):
                         "copyAttrs"):
             if not hasattr(self, "copyCatsIds"):
             if not hasattr(self, "copyCatsIds"):
                 # 'from' -> select by point
                 # 'from' -> select by point
-                nselected = self.digit.GetDisplay().SelectLineByPoint(pos1)['point']
+                nselected = int(self.digit.GetDisplay().SelectLineByPoint(pos1)['line'] != -1)
                 if nselected:
                 if nselected:
                     self.copyCatsList = self.digit.GetDisplay().GetSelected()
                     self.copyCatsList = self.digit.GetDisplay().GetSelected()
             else:
             else:
@@ -642,8 +644,7 @@ class VDigitWindow(BufferedMapWindow):
                 # return number of selected features (by box/point)
                 # return number of selected features (by box/point)
                 nselected = self.digit.GetDisplay().SelectLinesByBox((pos1, pos2))
                 nselected = self.digit.GetDisplay().SelectLinesByBox((pos1, pos2))
                 if nselected == 0:
                 if nselected == 0:
-                    if self.digit.GetDisplay().SelectLineByPoint(pos1) is not None:
-                        nselected = 1
+                    nselected = int(self.digit.GetDisplay().SelectLineByPoint(pos1)['line'] != -1)
                         
                         
                 if nselected > 0:
                 if nselected > 0:
                     self.copyCatsIds = self.digit.GetDisplay().GetSelected()
                     self.copyCatsIds = self.digit.GetDisplay().GetSelected()
@@ -660,17 +661,19 @@ class VDigitWindow(BufferedMapWindow):
                     len(self.digit.GetDisplay().GetSelected()) > 0:
                     len(self.digit.GetDisplay().GetSelected()) > 0:
                 nselected = 0
                 nselected = 0
             else:
             else:
-                if action == 'moveLine':
-                    drawSeg = True
+                if action == 'deleteArea':
+                    nselected = int(self.digit.GetDisplay().SelectAreaByPoint(pos1)['area'] != -1)
                 else:
                 else:
-                    drawSeg = False
-                
-                nselected = self.digit.GetDisplay().SelectLinesByBox(bbox = (pos1, pos2),
-                                                                     drawSeg = drawSeg)
-                if nselected == 0:
-                    if self.digit.GetDisplay().SelectLineByPoint(pos1) is not None:
-                        nselected = 1
-        
+                    if action == 'moveLine':
+                        drawSeg = True
+                    else:
+                        drawSeg = False
+                        
+                    nselected = self.digit.GetDisplay().SelectLinesByBox(bbox = (pos1, pos2),
+                                                                         drawSeg = drawSeg)
+                    if nselected == 0:
+                        nselected = int(self.digit.GetDisplay().SelectLineByPoint(pos1)['line'] != -1)
+
         if nselected > 0:
         if nselected > 0:
             if action in ("moveLine", "moveVertex") and \
             if action in ("moveLine", "moveVertex") and \
                     hasattr(self, "moveInfo"):
                     hasattr(self, "moveInfo"):
@@ -707,7 +710,7 @@ class VDigitWindow(BufferedMapWindow):
         
         
         else: # no vector object found
         else: # no vector object found
             if not (action in ("moveLine",
             if not (action in ("moveLine",
-                                                 "moveVertex") and \
+                               "moveVertex") and \
                         hasattr(self, "moveInfo") and \
                         hasattr(self, "moveInfo") and \
                         len(self.moveInfo['id']) > 0):
                         len(self.moveInfo['id']) > 0):
                 # avoid left-click when features are already selected
                 # avoid left-click when features are already selected
@@ -720,7 +723,7 @@ class VDigitWindow(BufferedMapWindow):
         pos1 = self.Pixel2Cell(self.mouse['begin'])
         pos1 = self.Pixel2Cell(self.mouse['begin'])
         
         
         pointOnLine = self.digit.GetDisplay().SelectLineByPoint(pos1)['point']
         pointOnLine = self.digit.GetDisplay().SelectLineByPoint(pos1)['point']
-        if not pointOnLine:
+        if pointOnLine['line'] == -1:
             return
             return
         
         
         if self.toolbar.GetAction() in ["splitLine", "addVertex"]:
         if self.toolbar.GetAction() in ["splitLine", "addVertex"]:
@@ -817,6 +820,9 @@ class VDigitWindow(BufferedMapWindow):
         
         
     def _onLeftUp(self, event):
     def _onLeftUp(self, event):
         """!Left mouse button released"""
         """!Left mouse button released"""
+        if event.ControlDown():
+            return
+        
         if hasattr(self, "moveInfo"):
         if hasattr(self, "moveInfo"):
             if len(self.digit.GetDisplay().GetSelected()) == 0:
             if len(self.digit.GetDisplay().GetSelected()) == 0:
                 self.moveInfo['begin'] = self.Pixel2Cell(self.mouse['begin']) # left down
                 self.moveInfo['begin'] = self.Pixel2Cell(self.mouse['begin']) # left down

+ 42 - 13
gui/wxpython/vdigit/wxdisplay.py

@@ -243,17 +243,14 @@ class DisplayDriver:
         if not self.dc or not self.dcTmp:
         if not self.dc or not self.dcTmp:
             return -1
             return -1
         
         
-        Debug.msg(3, "_drawObject(): line=%d type=%d npoints=%d", robj.fid, robj.type, robj.npoints)
+        Debug.msg(1, "_drawObject(): line=%d type=%d npoints=%d", robj.fid, robj.type, robj.npoints)
         brush = None
         brush = None
         if self._isSelected(robj.fid):
         if self._isSelected(robj.fid):
             pdc = self.dcTmp
             pdc = self.dcTmp
-            if robj.type == TYPE_AREA:
-                return 1
-            else:
-                if self.settings['highlightDupl']['enabled'] and self._isDuplicated(robj.fid):
-                    pen = wx.Pen(self.settings['highlightDupl']['color'], self.settings['lineWidth'], wx.SOLID)
-                else:            
-                    pen = wx.Pen(self.settings['highlight'], self.settings['lineWidth'], wx.SOLID)
+            if self.settings['highlightDupl']['enabled'] and self._isDuplicated(robj.fid):
+                pen = wx.Pen(self.settings['highlightDupl']['color'], self.settings['lineWidth'], wx.SOLID)
+            else:            
+                pen = wx.Pen(self.settings['highlight'], self.settings['lineWidth'], wx.SOLID)
                     
                     
             dcId = 1
             dcId = 1
             self.topology['highlight'] += 1
             self.topology['highlight'] += 1
@@ -262,6 +259,7 @@ class DisplayDriver:
         else:
         else:
             pdc = self.dc
             pdc = self.dc
             pen, brush = self._definePen(robj.type)
             pen, brush = self._definePen(robj.type)
+
             dcId = 0
             dcId = 0
         
         
         pdc.SetPen(pen)        
         pdc.SetPen(pen)        
@@ -508,13 +506,14 @@ class DisplayDriver:
         
         
         return False
         return False
     
     
-    def SelectLinesByBox(self, bbox, drawSeg = False, poMapInfo = None):
+    def SelectLinesByBox(self, bbox, ltype = None, drawSeg = False, poMapInfo = None):
         """!Select vector objects by given bounding box
         """!Select vector objects by given bounding box
         
         
         If line id is already in the list of selected lines, then it will
         If line id is already in the list of selected lines, then it will
         be excluded from this list.
         be excluded from this list.
         
         
         @param bbox bounding box definition
         @param bbox bounding box definition
+        @param ltype feature type or None for default
         @param drawSeg True to draw segments of line
         @param drawSeg True to draw segments of line
         @param poMapInfo use external Map_info, None for self.poMapInfo
         @param poMapInfo use external Map_info, None for self.poMapInfo
 
 
@@ -545,9 +544,11 @@ class DisplayDriver:
         Vect_append_point(poBbox, x1, y2, 0.0)
         Vect_append_point(poBbox, x1, y2, 0.0)
         Vect_append_point(poBbox, x1, y1, 0.0)
         Vect_append_point(poBbox, x1, y1, 0.0)
         
         
+        if not ltype:
+            ltype = self._getSelectType()
         Vect_select_lines_by_polygon(poMapInfo, poBbox,
         Vect_select_lines_by_polygon(poMapInfo, poBbox,
                                      0, None, # isles
                                      0, None, # isles
-                                     self._getSelectType(), poList)
+                                     ltype, poList)
         
         
         flist = poList.contents
         flist = poList.contents
         nlines = flist.n_values
         nlines = flist.n_values
@@ -580,7 +581,32 @@ class DisplayDriver:
         
         
         return nlines
         return nlines
 
 
-    def SelectLineByPoint(self, point, poMapInfo = None):
+    def SelectAreaByPoint(self, point, poMapInfo = None):
+        thisMapInfo = poMapInfo is None
+        if not poMapInfo:
+            poMapInfo = self.poMapInfo
+        
+        if not poMapInfo:
+            return { 'area' : -1, 'centroid': -1 }
+        
+        if thisMapInfo:
+            self._drawSelected = True
+
+        box = bound_box()
+        for area in range(1, Vect_get_num_areas(poMapInfo)+1):
+            Vect_get_area_box(poMapInfo, area, byref(box))
+            if Vect_point_in_area(point[0], point[1], poMapInfo, area, byref(box)) == 1:
+                centroid = Vect_get_area_centroid(poMapInfo, area)
+                if not self._isSelected(centroid):
+                    self.selected['ids'].append(centroid)
+                else:
+                    self.selected['ids'].remove(centroid)
+                
+                return { 'area' : area, 'centroid' : centroid}
+        
+        return { 'area' : -1, 'centroid': -1 }
+            
+    def SelectLineByPoint(self, point, ltype = None, poMapInfo = None):
         """!Select vector feature by given point in given
         """!Select vector feature by given point in given
         threshold
         threshold
    
    
@@ -588,6 +614,7 @@ class DisplayDriver:
         all segments are stores.
         all segments are stores.
         
         
         @param point points coordinates (x, y)
         @param point points coordinates (x, y)
+        @param ltype feature type or None for default
         @param poMapInfo use external Map_info, None for self.poMapInfo
         @param poMapInfo use external Map_info, None for self.poMapInfo
 
 
         @return dict {'line' : feature id, 'point' : point on line}
         @return dict {'line' : feature id, 'point' : point on line}
@@ -606,9 +633,11 @@ class DisplayDriver:
         
         
         poFound = Vect_new_list()
         poFound = Vect_new_list()
         
         
+        if ltype is None:
+            ltype  = self._getSelectType()
         lineNearest = Vect_find_line_list(poMapInfo, point[0], point[1], 0,
         lineNearest = Vect_find_line_list(poMapInfo, point[0], point[1], 0,
-                                           self._getSelectType(), self.GetThreshold(), self.is3D,
-                                           None, poFound)
+                                          ltype, self.GetThreshold(), self.is3D,
+                                          None, poFound)
         Debug.msg(1, "DisplayDriver.SelectLineByPoint() found = %d", lineNearest)
         Debug.msg(1, "DisplayDriver.SelectLineByPoint() found = %d", lineNearest)
         
         
         if lineNearest > 0:
         if lineNearest > 0: