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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 7 14:01:43 EDT 2011


Author: martinl
Date: 2011-09-07 11:01:43 -0700 (Wed, 07 Sep 2011)
New Revision: 48192

Modified:
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
   grass/trunk/gui/wxpython/gui_modules/wxvdriver.py
Log:
wxGUI/vdigit: restrict tools for editing OGR layers


Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-09-07 18:00:52 UTC (rev 48191)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-09-07 18:01:43 UTC (rev 48192)
@@ -39,12 +39,12 @@
 import wx
 
 import globalvar
-import gcmd
-import gdialogs
-from vdigit import VDigitSettingsDialog, haveVDigit, VDigit
-from debug import Debug
+from gdialogs    import CreateNewVector
+from vdigit      import VDigitSettingsDialog, haveVDigit, VDigit
+from debug       import Debug
 from preferences import globalSettings as UserSettings
-from nviz import haveNviz
+from gcmd        import RunCommand, GError
+from nviz        import haveNviz
 from nviz_preferences import NvizPreferencesDialog
 
 sys.path.append(os.path.join(globalvar.ETCWXDIR, "icons"))
@@ -163,7 +163,7 @@
             self.SetSize((size[0] + width, size[1]))
 
     def Enable(self, tool, enable = True):
-        """!Enable defined tool
+        """!Enable/Disable defined tool
         
         @param tool name
         @param enable True to enable otherwise disable tool
@@ -174,7 +174,17 @@
             return
         
         self.EnableTool(id, enable)
+
+    def EnableAll(self, enable = True):
+        """!Enable/Disable all tools
         
+        @param enable True to enable otherwise disable tool
+        """
+        for item in self._toolbarData():
+            if not item[0]:
+                continue
+            self.Enable(item[0], enable)
+        
     def _getToolbarData(self, data):
         """!Define tool
         """
@@ -747,7 +757,7 @@
         
         event.Skip()
 
-    def EnableUndo(self, enable=True):
+    def EnableUndo(self, enable = True):
         """!Enable 'Undo' in toolbar
         
         @param enable False for disable
@@ -955,8 +965,8 @@
     def OnZBulk(self, event):
         """!Z bulk-labeling selected lines/boundaries"""
         if not self.digit.IsVector3D():
-            gcmd.GError(parent = self.parent,
-                        message = _("Vector map is not 3D. Operation canceled."))
+            GError(parent = self.parent,
+                   message = _("Vector map is not 3D. Operation canceled."))
             return
         
         if self.action['desc'] == 'zbulkLine': # select previous action
@@ -1000,12 +1010,12 @@
                 openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
             else:
                 openVectorMap = None
-            dlg = gdialogs.CreateNewVector(self.parent,
-                                           exceptMap = openVectorMap, log = self.log,
-                                           cmd = (('v.edit',
-                                                   { 'tool' : 'create' },
-                                                   'map')),
-                                           disableAdd = True)
+            dlg = CreateNewVector(self.parent,
+                                  exceptMap = openVectorMap, log = self.log,
+                                  cmd = (('v.edit',
+                                          { 'tool' : 'create' },
+                                          'map')),
+                                  disableAdd = True)
             
             if dlg and dlg.GetName():
                 # add layer to map layer tree
@@ -1078,6 +1088,31 @@
             self.StopEditing()
             return False
         
+        # check feature type (only for OGR layers)
+        fType = self.digit.GetFeatureType()
+        self.EnableAll()
+        self.EnableUndo(False)
+        if fType == 'Point':
+            for tool in (self.addLine, self.addBoundary, self.addCentroid,
+                         self.addArea, self.moveVertex, self.addVertex,
+                         self.removeVertex, self.editLine):
+                self.EnableTool(tool, False)
+        elif fType == 'Line String':
+            for tool in (self.addPoint, self.addBoundary, self.addCentroid,
+                         self.addArea):
+                self.EnableTool(tool, False)
+        elif fType == 'Polygon':
+            for tool in (self.addPoint, self.addLine):
+                self.EnableTool(tool, False)
+        elif fType:
+            GError(parent = self,
+                   message = _("Unsupported feature type '%s'. Unable to edit "
+                               "OGR layer <%s>.") % (fType, mapLayer.GetName()))
+            self.digit.CloseMap()
+            self.mapLayer = None
+            self.StopEditing()
+            return False
+        
         # update toolbar
         self.combo.SetValue(mapLayer.GetName())
         self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
@@ -1286,8 +1321,8 @@
     def OnHelp(self, event):
         """!Show 3D view mode help"""
         if not self.lmgr:
-            gcmd.RunCommand('g.manual',
-                            entry = 'wxGUI.Nviz')
+            RunCommand('g.manual',
+                       entry = 'wxGUI.Nviz')
         else:
             log = self.lmgr.GetLogWindow()
             log.RunCmd(['g.manual',

Modified: grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-09-07 18:00:52 UTC (rev 48191)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-09-07 18:01:43 UTC (rev 48192)
@@ -1745,3 +1745,11 @@
         """
         return self.changesetCurrent
     
+    def GetFeatureType(self):
+        """!Get feature type for OGR layers
+
+        @return feature type as string (Point, Line String, Polygon)
+        @return None for native format
+        """
+        return Vect_get_ogr_geometry_type(self.poMapInfo)
+        

Modified: grass/trunk/gui/wxpython/gui_modules/wxvdriver.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdriver.py	2011-09-07 18:00:52 UTC (rev 48191)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdriver.py	2011-09-07 18:01:43 UTC (rev 48192)
@@ -445,10 +445,13 @@
         if not self.poMapInfo or not self.dc or not self.dcTmp:
             return -1
         
-        rlist = Vedit_render_map(self.poMapInfo, byref(self._getRegionBox()), self._getDrawFlag(),
-                                 self.region['center_easting'], self.region['center_northing'],
-                                 self.mapObj.width, self.mapObj.height,
-                                 max(self.region['nsres'], self.region['ewres'])).contents
+        try:
+            rlist = Vedit_render_map(self.poMapInfo, byref(self._getRegionBox()), self._getDrawFlag(),
+                                     self.region['center_easting'], self.region['center_northing'],
+                                     self.mapObj.width, self.mapObj.height,
+                                     max(self.region['nsres'], self.region['ewres'])).contents
+        except SystemExit:
+            pass
         
         self._resetTopology()
         



More information about the grass-commit mailing list