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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 30 11:48:01 EDT 2008


Author: martinl
Date: 2008-03-30 11:48:00 -0400 (Sun, 30 Mar 2008)
New Revision: 30816

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxGUI (mapdisplay): Display region drawn as a blue box inside the computational region, computational region inside a display region as a red box. Related to trac #106.


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-30 14:48:26 UTC (rev 30815)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-30 15:48:00 UTC (rev 30816)
@@ -538,8 +538,8 @@
 
         self.resize = False
 
-        if len(self.Map.GetListOfLayers()) == 0:
-            return False
+        # if len(self.Map.GetListOfLayers()) == 0:
+        #    return False
 
         if self.img is None:
             render = True
@@ -616,20 +616,7 @@
                 self.Draw(self.pdc, img=self.textdict[id], drawid=id,
                           pdctype='text', coords=self.ovlcoords[id])
 
-        #
-        # render region border (to self.pdcTmp)
-        #
-        if hasattr(self, "regionCoords"):
-            reg = self.Map.GetWindow()
-            self.polypen = wx.Pen(colour='red', width=2, style=wx.SOLID)
-            self.regionCoords = []
-            self.regionCoords.append((reg['west'], reg['north']))
-            self.regionCoords.append((reg['east'], reg['north']))
-            self.regionCoords.append((reg['east'], reg['south']))
-            self.regionCoords.append((reg['west'], reg['south']))
-            self.regionCoords.append((reg['west'], reg['north']))
-            # draw region extent
-            self.DrawLines(pdc=self.pdcTmp, polycoords=self.regionCoords)
+        self.DrawCompRegionExtent()
 
         # redraw pdcTmp if needed
         if len(self.polycoords) > 0:
@@ -655,6 +642,49 @@
 
         return True
 
+    def DrawCompRegionExtent(self):
+        """Draw computational region extent in the display
+        
+        Display region is drawn as a blue box inside the computational region,
+        computational region inside a display region as a red box).
+        """
+        if hasattr(self, "regionCoords"):
+            compReg = self.Map.GetRegion()
+            dispReg = self.Map.GetCurrentRegion()
+            reg = None
+            if self.IsInRegion(dispReg, compReg):
+                self.polypen = wx.Pen(colour='blue', width=3, style=wx.SOLID)
+                reg = dispReg
+            else:
+                self.polypen = wx.Pen(colour='red', width=3, style=wx.SOLID)
+                reg = compReg
+            
+            self.regionCoords = []
+            self.regionCoords.append((reg['w'], reg['n']))
+            self.regionCoords.append((reg['e'], reg['n']))
+            self.regionCoords.append((reg['e'], reg['s']))
+            self.regionCoords.append((reg['w'], reg['s']))
+            self.regionCoords.append((reg['w'], reg['n']))
+            # draw region extent
+            self.DrawLines(pdc=self.pdcTmp, polycoords=self.regionCoords)
+
+    def IsInRegion(self, region, refRegion):
+        """Test if 'region' is inside of 'refRegion'
+
+        @param region input region
+        @param refRegion reference region (e.g. computational region)
+
+        @return True if region is inside of refRegion
+        @return False 
+        """
+        if region['s'] >= refRegion['s'] and \
+                region['n'] <= refRegion['n'] and \
+                region['w'] >= refRegion['w'] and \
+                region['e'] <= refRegion['e']:
+            return True
+
+        return False
+
     def EraseMap(self):
         """
         Erase the map display
@@ -2240,7 +2270,11 @@
         self.showRegion.SetValue(False)
         self.showRegion.Hide()
         self.showRegion.SetToolTip(wx.ToolTip (_("Show/hide computational "
-                                                 "region extent (set with g.region)")))
+                                                 "region extent (set with g.region). "
+                                                 "Display region drawn as a blue box inside the "
+                                                 "computational region, "
+                                                 "computational region inside a display region "
+                                                 "as a red box).")))
         # map scale
         self.mapScale = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
                                     value="", style=wx.TE_PROCESS_ENTER,

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-30 14:48:26 UTC (rev 30815)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-30 15:48:00 UTC (rev 30816)
@@ -459,9 +459,13 @@
             os.environ["GRASS_REGION"] = tmpreg
 
         Debug.msg (3, "Map.GetRegion(): %s" % region)
-
+        
         return region
 
+    def GetCurrentRegion(self):
+        """Get current display region settings"""
+        return self.region
+
     def SetRegion(self, windres=False):
         """
         Render string for GRASS_REGION env. variable, so that the images will be rendered



More information about the grass-commit mailing list