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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 2 07:56:11 EST 2011


Author: martinl
Date: 2011-02-02 04:56:11 -0800 (Wed, 02 Feb 2011)
New Revision: 45288

Modified:
   grass/trunk/gui/wxpython/gui_modules/dbm.py
   grass/trunk/gui/wxpython/gui_modules/layertree.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
   grass/trunk/gui/wxpython/gui_modules/vdigit.py
   grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
   grass/trunk/gui/wxpython/gui_modules/wxvdriver.py
Log:
wxGUI/vdigit: geometry attributes reimplemented in Python


Modified: grass/trunk/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/dbm.py	2011-02-01 23:21:26 UTC (rev 45287)
+++ grass/trunk/gui/wxpython/gui_modules/dbm.py	2011-02-02 12:56:11 UTC (rev 45288)
@@ -2568,10 +2568,10 @@
     def __createDeletePage(self):
         """!Delete layer"""
         self.deletePanel = wx.Panel(parent=self, id=wx.ID_ANY)
-        self.AddPage(page=self.deletePanel, text=_("Delete layer"))
+        self.AddPage(page=self.deletePanel, text=_("Remove layer"))
 
         label = wx.StaticText(parent=self.deletePanel, id=wx.ID_ANY,
-                              label='%s:' % _("Layer to detele"))
+                              label='%s:' % _("Layer to remove"))
 
         self.deleteLayer = wx.ComboBox(parent=self.deletePanel, id=wx.ID_ANY, size=(100, -1),
                                        style=wx.CB_SIMPLE | wx.CB_READONLY,
@@ -2592,7 +2592,7 @@
             self.deleteLayer.Enable(False)
             self.deleteTable.Enable(False)
             
-        btnDelete   = wx.Button(self.deletePanel, wx.ID_DELETE, _("&Delete layer"),
+        btnDelete   = wx.Button(self.deletePanel, wx.ID_DELETE, _("&Remove layer"),
                                 size=(125,-1))
         btnDelete.Bind(wx.EVT_BUTTON, self.OnDeleteLayer)
 

Modified: grass/trunk/gui/wxpython/gui_modules/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/layertree.py	2011-02-01 23:21:26 UTC (rev 45287)
+++ grass/trunk/gui/wxpython/gui_modules/layertree.py	2011-02-02 12:56:11 UTC (rev 45288)
@@ -961,13 +961,12 @@
             menuform.GUI().ParseCommand(['d.rast.num'], completed = (self.GetOptData,layer,params),
                                         parentframe = self, centreOnParent = False)
         elif ltype == 'vector':
-            types = ''
-            for type in UserSettings.Get(group = 'cmd', key = 'showType').keys():
+            types = list()
+            for ftype in ['point', 'line', 'boundary', 'centroid', 'area', 'face']:
                 if UserSettings.Get(group = 'cmd', key = 'showType', subkey = [type, 'enabled']):
-                    types += type + ','
-            types = types.rstrip(',')
+                    types.append(ftype)
             
-            menuform.GUI().ParseCommand(['d.vect', 'type=%s' % types],
+            menuform.GUI().ParseCommand(['d.vect', 'type=%s' % ','.join(types)],
                                          completed = (self.GetOptData,layer,params),
                                          parentframe = self, centreOnParent = False)
         elif ltype == 'thememap':

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-02-01 23:21:26 UTC (rev 45287)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-02-02 12:56:11 UTC (rev 45288)
@@ -1251,8 +1251,8 @@
         if digitToolbar.GetAction('type') in ['point', 'centroid']:
             # add new point / centroiud
             east, north = self.Pixel2Cell(self.mouse['begin'])
-            fid = digitClass.AddFeature(digitToolbar.GetAction('type'), [(east, north)])
-            if fid < 0:
+            nfeat, fids = digitClass.AddFeature(digitToolbar.GetAction('type'), [(east, north)])
+            if nfeat < 1:
                 return
             
             self.UpdateMap(render = False) # redraw map
@@ -1260,7 +1260,7 @@
             # add new record into atribute table
             if UserSettings.Get(group = 'vdigit', key = "addRecord", subkey = 'enabled'):
                 # select attributes based on layer and category
-                cats = { fid : {
+                cats = { fids[0] : {
                         UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value') :
                             (UserSettings.Get(group = 'vdigit', key = "category", subkey = 'value'), )
                         }}
@@ -1273,12 +1273,13 @@
                                                                    pos = posWindow,
                                                                    action = "add")
 
-                if not point:
-                    self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
-                                     digitToolbar.GetLayer())
-                    self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
-                                     digitToolbar.GetLayer())
-
+                if digitToolbar.GetAction('type') == 'centroid':
+                    for fid in fids:
+                        self._geomAttrb(fid, addRecordDlg, 'area', digitClass,
+                                        digitToolbar.GetLayer())
+                        self._geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
+                                        digitToolbar.GetLayer())
+                    
                 if addRecordDlg.mapDBInfo and \
                         addRecordDlg.ShowModal() == wx.ID_OK:
                     sqlfile = tempfile.NamedTemporaryFile(mode = "w")
@@ -1299,7 +1300,7 @@
             self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
             self.DrawLines(pdc = self.pdcTmp)
     
-    def __geomAttrb(self, fid, dialog, attrb, digit, mapLayer):
+    def _geomAttrb(self, fid, dialog, attrb, digit, mapLayer):
         """!Trac geometry attributes?"""
         item = self.tree.FindItemByData('maplayer', mapLayer)
         vdigit = self.tree.GetPyData(item)[0]['vdigit']
@@ -1324,7 +1325,7 @@
                 dialog.SetColumnValue(layer, column, val)
                 dialog.OnReset()
         
-    def __geomAttrbUpdate(self, fids):
+    def _geomAttrbUpdate(self, fids):
         """!Update geometry atrributes of currently selected features
 
         @param fid list feature id
@@ -2158,7 +2159,7 @@
                     if fid < 0:
                         return
 
-                    self.__geomAttrbUpdate([fid,])
+                    self._geomAttrbUpdate([fid,])
                 
                 del self.vdigitMove
                 
@@ -2178,19 +2179,24 @@
                     digitToolbar.GetAction('type') in ["line", "boundary", "area"]:
                 # -> add new line / boundary
                 try:
-                    map = digitToolbar.GetLayer().GetName()
+                    mapName = digitToolbar.GetLayer().GetName()
                 except:
-                    map = None
+                    mapName = None
                     wx.MessageBox(parent = self,
                                   message = _("No vector map selected for editing."),
                                   caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
                     
-                if map:
+                if mapName:
+                    if digitToolbar.GetAction('type') == 'line':
+                        line = True
+                    else:
+                        line = False
+                    
                     if len(self.polycoords) < 2: # ignore 'one-point' lines
                         return
                     
-                    fid = digitClass.AddFeature(digitToolbar.GetAction('type'), self.polycoords)
-                    if fid < 0:
+                    nfeat, fids = digitClass.AddFeature(digitToolbar.GetAction('type'), self.polycoords)
+                    if nfeat < 0:
                         return
                     
                     position = self.Cell2Pixel(self.polycoords[-1])
@@ -2202,29 +2208,30 @@
                     # add new record into atribute table
                     if UserSettings.Get(group = 'vdigit', key = "addRecord", subkey = 'enabled') and \
                             (line is True or \
-                                 (not line and fid > 0)):
+                                 (not line and nfeat > 0)):
                         posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
                                                          position[1] + self.dialogOffset))
-
+                        
                         # select attributes based on layer and category
-                        cats = { fid : {
+                        cats = { fids[0] : {
                                 UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value') :
                                     (UserSettings.Get(group = 'vdigit', key = "category", subkey = 'value'), )
                                 }}
                         
-                        addRecordDlg = dbm_dialogs.DisplayAttributesDialog(parent = self, map = map,
+                        addRecordDlg = dbm_dialogs.DisplayAttributesDialog(parent = self, map = mapName,
                                                                            cats = cats,
                                                                            pos = posWindow,
                                                                            action = "add")
 
-                        self.__geomAttrb(fid, addRecordDlg, 'length', digitClass,
-                                         digitToolbar.GetLayer())
-                        # auto-placing centroid
-                        self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
-                                         digitToolbar.GetLayer())
-                        self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
-                                         digitToolbar.GetLayer())
-
+                        for fid in fids:
+                            self._geomAttrb(fid, addRecordDlg, 'length', digitClass,
+                                            digitToolbar.GetLayer())
+                            # auto-placing centroid
+                            self._geomAttrb(fid, addRecordDlg, 'area', digitClass,
+                                            digitToolbar.GetLayer())
+                            self._geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
+                                            digitToolbar.GetLayer())
+                        
                         if addRecordDlg.mapDBInfo and \
                                addRecordDlg.ShowModal() == wx.ID_OK:
                             sqlfile = tempfile.NamedTemporaryFile(mode = "w")
@@ -2258,7 +2265,7 @@
                 fid = digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
                 if fid < 0:
                     return
-                self.__geomAttrbUpdate([fid,])
+                self._geomAttrbUpdate([fid,])
             elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
                 try:
                     if digitToolbar.GetAction() == 'copyCats':

Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py	2011-02-01 23:21:26 UTC (rev 45287)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py	2011-02-02 12:56:11 UTC (rev 45288)
@@ -514,7 +514,7 @@
             row += 1
         
         note = '\n'.join(textwrap.wrap(_("Note: These settings are stored "
-                                         " in the workspace not in the vector digitizer "
+                                         "in the workspace not in the vector digitizer "
                                          "preferences."), 55))
         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
                                            label = note),
@@ -704,6 +704,7 @@
     def UpdateSettings(self):
         """!Update digitizer settings
         """
+        self.parent.GetLayerManager().WorkspaceChanged() # geometry attributes
         # symbology
         for key, (enabled, color) in self.symbology.iteritems():
             if enabled:

Modified: grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-02-01 23:21:26 UTC (rev 45287)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-02-02 12:56:11 UTC (rev 45288)
@@ -431,7 +431,7 @@
         @param ftype feature type (point, line, centroid, boundary)
         @param points tuple of points ((x, y), (x, y), ...)
         
-        @return new feature id
+        @return tuple (number of added features, feature ids)
         """
         if UserSettings.Get(group = 'vdigit', key = "categoryMode", subkey = 'selection') == 2:
             layer = -1 # -> no category
@@ -453,12 +453,12 @@
         else:
             GError(parent = self.mapWindow,
                    message = _("Unknown feature type '%s'") % ftype)
-            return
+            return (-1, None)
         
         if vtype & GV_LINES and len(points) < 2:
             GError(parent = self.mapWindow,
                    message = _("Not enough points for line"))
-            return
+            return (-1, None)
         
         self.toolbar.EnableUndo()
         
@@ -1007,7 +1007,22 @@
         @return line length
         @return -1 on error
         """
-        return self.digit.GetLineLength(line)
+        if not self._checkMap():
+            return -1
+        
+        if not Vect_line_alive(self.poMapInfo, line):
+            return -1
+    
+        ltype = Vect_read_line(self.poMapInfo, self.poPoints, None, line)
+        if ltype < 0:
+            self._error.ReadLine(line)
+            return ret
+        
+        length = -1
+        if ltype & GV_LINES: # lines & boundaries
+            length = Vect_line_length(self.poPoints)
+        
+        return length
 
     def GetAreaSize(self, centroid):
         """!Get area size
@@ -1017,18 +1032,57 @@
         @return area size
         @return -1 on error
         """
-        return self.digit.GetAreaSize(centroid)
+        if not self._checkMap():
+            return -1
         
+        ltype = Vect_read_line(self.poMapInfo, None, None, centroid)
+        if ltype < 0:
+            self._error.ReadLine(line)
+            return ret
+        
+        if ltype != GV_CENTROID:
+            return -1
+        
+        area = Vect_get_centroid_area(self.poMapInfo, centroid)
+        size = -1
+        if area > 0:
+            if not Vect_area_alive(self.poMapInfo, area):
+                return size
+            
+            size = Vect_get_area_area(self.poMapInfo, area)
+        
+        return size
+        
     def GetAreaPerimeter(self, centroid):
         """!Get area perimeter
-
+        
         @param centroid centroid id
-
+        
         @return area size
         @return -1 on error
         """
-        return self.digit.GetAreaPerimeter(centroid)
-
+        if not self._checkMap():
+            return -1
+        
+        ltype = Vect_read_line(self.poMapInfo, None, None, centroid)
+        if ltype < 0:
+            self._error.ReadLine(line)
+            return ret
+        
+        if ltype != GV_CENTROID:
+            return -1
+        
+        area = Vect_get_centroid_area(self.poMapInfo, centroid)
+        perimeter = -1
+        if area > 0:
+            if not Vect_area_alive(self,poMapInfo, area):
+                return -1
+            
+            Vect_get_area_points(self.poMapInfo, area, self.poPoints)
+            perimeter = Vect_area_perimeter(self.poPoints)
+        
+        return perimeter
+    
     def SetLineCats(self, line, layer, cats, add=True):
         """!Set categories for given line and layer
 
@@ -1246,7 +1300,7 @@
         return True
 
     def _addFeature(self, ftype, coords, layer, cat, snap, threshold):
-        """!Add new feature to the vector map
+        """!Add new feature(s) to the vector map
 
         @param ftype feature type (GV_POINT, GV_LINE, GV_BOUNDARY, ...)
         @coords tuple of coordinates ((x, y), (x, y), ...)
@@ -1255,11 +1309,12 @@
         @param snap snap to node/vertex
         @param threshold threshold for snapping
         
-        @return -1 on error
-        @return feature id of new feature
+        @return tuple (number of added features, list of fids)
+        @return number of features -1 on error
         """
+        fids = list()
         if not self._checkMap():
-            return -1
+            return (-1, None)
         
         is3D = bool(Vect_is_3d(self.poMapInfo))
         
@@ -1268,7 +1323,7 @@
         
         if not (ftype & (GV_POINTS | GV_LINES | GV_AREA)): # TODO: 3D
             self._error.FeatureType(ftype)
-            return -1
+            return (-1, None)
         
         # set category
         Vect_reset_cats(self.poCats)
@@ -1305,7 +1360,9 @@
         newline = Vect_write_line(self.poMapInfo, ltype, self.poPoints, self.poCats)
         if newline < 0:
             self._error.WriteLine()
-            return -1
+            return (-1, None)
+        else:
+            fids.append(newline)
         
         left = right = -1
         if ftype & GV_AREA:
@@ -1332,21 +1389,28 @@
                         Vect_find_poly_centroid(bpoints, byref(x), byref(y)) == 0:
                     Vect_reset_line(bpoints)
                     Vect_append_point(bpoints, x.value, y.value, 0.0)
-                    if Vect_write_line(self.poMapInfo, GV_CENTROID,
-                                       bpoints, self.poCats) < 0:
+                    newline = Vect_write_line(self.poMapInfo, GV_CENTROID,
+                                              bpoints, self.poCats)
+                    if newline < 0:
                         self._error.WriteLine()
-                        return -1
-            
+                        return (len(fids), fids)
+                    else:
+                        fids.append(newline)
+                    
             if right > 0 and \
                     Vect_get_area_centroid(self.poMapInfo, right) == 0:
                 if Vect_get_area_points(byref(self.poMapInfo), right, bpoints) > 0 and \
                         Vect_find_poly_centroid(bpoints, byref(x), byref(y)) == 0:
                     Vect_reset_line(bpoints)
                     Vect_append_point(bpoints, x.value, y.value, 0.0)
-                    if Vect_write_line(byref(self.poMapInfo), GV_CENTROID,
-                                       bpoints, self.poCats) < 0:
+                    newline =  Vect_write_line(byref(self.poMapInfo), GV_CENTROID,
+                                               bpoints, self.poCats)
+                    if newline < 0:
                         self._error.WriteLine()
-                        return -1
+                        return (len(fids, fids))
+                    else:
+                        fids.append(newline)
+                    
             Vect_destroy_line_struct(bpoints)
         
         # register changeset
@@ -1357,7 +1421,7 @@
         if self._settings['breakLines']:
             self._breakLineAtIntersection(newline, self.poPoints, changeset)
         
-        return newline
+        return (len(fids), fids)
     
     def _ModifyLineVertex(self, coords, add = True):
         """!Add or remove vertex

Modified: grass/trunk/gui/wxpython/gui_modules/wxvdriver.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdriver.py	2011-02-01 23:21:26 UTC (rev 45287)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdriver.py	2011-02-02 12:56:11 UTC (rev 45288)
@@ -390,10 +390,10 @@
     def _isDuplicated(self, line):
         """!Check for already marked duplicates
         
-        \param line feature id
+        @param line feature id
 
-        \return True line already marked as duplicated
-        \return False not duplicated
+        @return True line already marked as duplicated
+        @return False not duplicated
         """
         return line in self.selected['idsDupl']
     



More information about the grass-commit mailing list