Browse Source

wxGUI: set computational region extent interactiverly (https://trac.osgeo.org/grass/ticket/2277)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60055 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 years ago
parent
commit
37140a0b5e
3 changed files with 40 additions and 4 deletions
  1. 7 2
      gui/wxpython/mapdisp/frame.py
  2. 7 1
      gui/wxpython/mapwin/base.py
  3. 26 1
      gui/wxpython/mapwin/buffered.py

+ 7 - 2
gui/wxpython/mapdisp/frame.py

@@ -1231,6 +1231,10 @@ class MapFrame(SingleMapFrame):
         """
         self.MapWindow.SetRegion(zoomOnly=False)
  
+    def OnSetExtentToWind(self, event):
+        """!Set compulational region extent interactively"""
+        self.MapWindow.SetModeDrawRegion()
+
     def OnSaveDisplayRegion(self, event):
         """!Save display extents to named region file.
         """
@@ -1249,8 +1253,9 @@ class MapFrame(SingleMapFrame):
         for label, handler in ((_('Zoom to default region'), self.OnZoomToDefault),
                                (_('Zoom to saved region'), self.OnZoomToSaved),
                                (None, None),
-                               (_('Set computational region from display extent'), self.OnSetDisplayToWind),
-                               (_('Set computational region from named region'), self.OnSetWindToRegion),
+                               (_('Set computational region extent from display'), self.OnSetDisplayToWind),
+                               (_('Set computational region extent iteractively'), self.OnSetExtentToWind),
+                               (_('Set computational region from named region'),   self.OnSetWindToRegion),
                                (None, None),
                                (_('Save display geometry to named region'), self.OnSaveDisplayRegion),
                                (_('Save computational region to named region'), self.OnSaveWindRegion)):

+ 7 - 1
gui/wxpython/mapwin/base.py

@@ -378,9 +378,15 @@ class MapWindowBase(object):
         self._setModeZoom(zoomType=-1)
 
     def _setModeZoom(self, zoomType):
+        self.zoomtype = zoomType
         self.mouse['use'] = "zoom"
         self.mouse['box'] = "box"
-        self.zoomtype = zoomType
+        self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
+        self.SetNamedCursor('cross')
+
+    def SetModeDrawRegion(self):
+        self.mouse['use'] = 'drawRegion'
+        self.mouse['box'] = "box"
         self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
         self.SetNamedCursor('cross')
 

+ 26 - 1
gui/wxpython/mapwin/buffered.py

@@ -1380,7 +1380,30 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
             self.dragid = None
 
             self.mouseLeftUpPointer.emit(x=coordinates[0], y=coordinates[1])
-
+        
+        elif self.mouse['use'] == 'drawRegion':
+            coordinatesBegin = self.Pixel2Cell(self.mouse['begin'])
+            
+            if coordinatesBegin[0] < coordinates[0]:
+                west = coordinatesBegin[0]
+                east = coordinates[0]
+            else:
+                west = coordinates[0]
+                east = coordinatesBegin[0]
+            if coordinatesBegin[1] < coordinates[1]:
+                south = coordinatesBegin[1]
+                north = coordinates[1]
+            else:
+                south = coordinates[1]
+                north = coordinatesBegin[1]
+                
+            RunCommand('g.region',
+                       parent = self,
+                       n = north, s = south, e = east, w = west)
+            
+            # redraw map
+            self.UpdateMap(render = False)
+        
        # TODO: decide which coordinates to send (e, n, mouse['begin'], mouse['end'])
         self.mouseLeftUp.emit(x=coordinates[0], y=coordinates[1])
 
@@ -1821,6 +1844,8 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
         if tmpreg:
             os.environ["GRASS_REGION"] = tmpreg
         
+        self.UpdateMap(render = False)
+        
     def SetRegion(self, zoomOnly=True):
         """!Set display extents/compulational region from named region
         file.