[GRASS-SVN] r30834 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Apr 1 13:22:09 EDT 2008
Author: martinl
Date: 2008-04-01 13:22:09 -0400 (Tue, 01 Apr 2008)
New Revision: 30834
Modified:
grass/trunk/gui/wxpython/gui_modules/mapdisp.py
grass/trunk/gui/wxpython/gui_modules/preferences.py
grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxGUI: fixing (partially) 'zoom to computational region does not respect resolution set with g.region', trac #106
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-04-01 15:39:28 UTC (rev 30833)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-04-01 17:22:09 UTC (rev 30834)
@@ -527,9 +527,8 @@
Updates the canvas anytime there is a change to the underlaying images
or to the geometry of the canvas.
- @param render render map layer composition
- @param renderVector render vector map layer (digitizer)
- @param counter reference to layer counter (progress bar)
+ @param render re-render map composition
+ @param renderVector re-render vector map layer enabled for editing (used for digitizer)
"""
start = time.clock()
@@ -557,7 +556,11 @@
#
if render:
self.Map.ChangeMapSize(self.GetClientSize())
- self.mapfile = self.Map.Render(force=True, mapWindow=self.parent)
+ windres = False
+ if self.parent.compResolution.GetValue():
+ # use computation region resolution for rendering
+ windres = True
+ self.mapfile = self.Map.Render(force=True, mapWindow=self.parent, windres=windres)
self.img = self.GetImage() # id=99
#
@@ -632,7 +635,7 @@
#
# update statusbar
#
- self.Map.SetRegion()
+ ### self.Map.SetRegion()
self.parent.StatusbarUpdate()
Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s -> time=%g" % \
@@ -1997,8 +2000,8 @@
else:
return
- self.Map.SetRegion()
- self.Map.AlignExtentFromDisplay()
+ ### self.Map.SetRegion()
+ ### self.Map.AlignExtentFromDisplay()
self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
self.Map.region['e'], self.Map.region['w'])
@@ -2012,9 +2015,8 @@
Set display geometry to match computational
region settings (set with g.region)
"""
-
self.Map.region = self.Map.GetRegion()
- self.Map.SetRegion()
+ ### self.Map.SetRegion(windres=True)
self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
self.Map.region['e'], self.Map.region['w'])
@@ -2248,9 +2250,10 @@
self.toggleStatus = wx.Choice(self.statusbar, wx.ID_ANY,
choices = ["Coordinates",
"Extent",
- "Comp. extent",
"Comp. region",
- "Geometry",
+ "Show comp. extent",
+ "Display mode",
+ "Display geometry",
"Map scale"])
self.statusText = "Coordinates"
self.toggleStatus.SetStringSelection(self.statusText)
@@ -2265,6 +2268,7 @@
self.showRegion = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
label=_("Show computational extent"))
self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleShowRegion, self.showRegion)
+
self.showRegion.SetValue(False)
self.showRegion.Hide()
self.showRegion.SetToolTip(wx.ToolTip (_("Show/hide computational "
@@ -2273,6 +2277,16 @@
"computational region, "
"computational region inside a display region "
"as a red box).")))
+ # set resolution
+ self.compResolution = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
+ label=_("Constrain display resolution to computational settings"))
+ self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.compResolution)
+ self.compResolution.SetValue(UserSettings.Get(group='display', key='compResolution', subkey='enabled'))
+ self.compResolution.Hide()
+ self.compResolution.SetToolTip(wx.ToolTip (_("Constrain display resolution "
+ "to computational region settings. "
+ "Default value for new map displays can "
+ "be set up in 'User GUI settings' dialog.")))
# map scale
self.mapScale = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
value="", style=wx.TE_PROCESS_ENTER,
@@ -2475,8 +2489,8 @@
Track mouse motion and update status bar
"""
# update statusbar if required
- e, n = self.MapWindow.Pixel2Cell(event.GetPositionTuple())
if self.statusText == "Coordinates":
+ e, n = self.MapWindow.Pixel2Cell(event.GetPositionTuple())
self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
event.Skip()
@@ -2501,6 +2515,9 @@
self.Map.DeleteLayer(layer)
self.MapWindow.UpdateMap(render=True)
+ # update statusbar
+ self.StatusbarUpdate()
+
def OnPointer(self, event):
"""Pointer button clicked"""
@@ -2615,7 +2632,13 @@
if self.autoRender.GetValue():
self.OnRender(None)
-
+ def OnToggleResolution(self, event):
+ """Use resolution of computation region settings
+ for redering image instead of display resolution"""
+ # redraw map if auto-rendering is enabled
+ if self.autoRender.GetValue():
+ self.OnRender(None)
+
def OnToggleStatus(self, event):
"""Toggle status text"""
self.statusText = event.GetString()
@@ -2651,6 +2674,7 @@
"""Update statusbar content"""
self.showRegion.Hide()
+ self.compResolution.Hide()
self.mapScale.Hide()
self.mapScaleValue = self.ppm = None
@@ -2662,11 +2686,7 @@
(self.Map.region["w"], self.Map.region["e"],
self.Map.region["s"], self.Map.region["n"]), 0)
- elif self.statusText == "Comp. extent":
- compregion = self.Map.GetRegion()
- # self.statusbar.SetStatusText("%.2f-%.2f,%.2f-%.2f" %
- # (compregion["w"], compregion["e"],
- # compregion["s"], compregion["n"]), 0)
+ elif self.statusText == "Show comp. extent":
self.statusbar.SetStatusText("", 0)
self.showRegion.Show()
@@ -2676,8 +2696,12 @@
(compregion["w"], compregion["e"],
compregion["s"], compregion["n"],
compregion["ewres"], compregion["nsres"]), 0)
+
+ elif self.statusText == "Display mode":
+ self.statusbar.SetStatusText("", 0)
+ self.compResolution.Show()
- elif self.statusText == "Geometry":
+ elif self.statusText == "Display geometry":
self.statusbar.SetStatusText("rows=%d; cols=%d; nsres=%.2f; ewres=%.2f" %
(self.Map.region["rows"], self.Map.region["cols"],
self.Map.region["nsres"], self.Map.region["ewres"]), 0)
@@ -2730,6 +2754,7 @@
"""Reposition checkbox in statusbar"""
# reposition checkbox
widgets = [(0, self.showRegion),
+ (0, self.compResolution),
(0, self.mapScale),
(0, self.onRenderGauge),
(1, self.toggleStatus),
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-04-01 15:39:28 UTC (rev 30833)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-04-01 17:22:09 UTC (rev 30834)
@@ -63,6 +63,7 @@
'display': {
'displayFont' : { 'value' : '' },
'driver': { 'type': 'default' },
+ 'compResolution' : { 'enabled' : False },
},
#
# advanced
@@ -492,8 +493,8 @@
label=_("Set font"), size=(100, -1))
gridSizer.Add(item=fontButton,
flag=wx.ALIGN_RIGHT |
- wx.ALIGN_CENTER_VERTICAL,
- pos=(row, 1))
+ wx.ALIGN_CENTER_VERTICAL,
+ pos=(row, 1))
#
# display driver
@@ -518,9 +519,23 @@
self.winId['display:driver:type'] = driver.GetId()
gridSizer.Add(item=driver,
+ flag=wx.ALIGN_RIGHT,
pos=(row, 1))
+ #
+ # display mode (use computation resolution?)
+ #
+ row += 1
+ compResolution = wx.CheckBox(parent=panel, id=wx.ID_ANY,
+ label=_("Constrain display resolution to computational settings"),
+ name="IsChecked")
+ compResolution.SetValue(self.settings.Get(group='display', key='compResolution', subkey='enabled'))
+ self.winId['display:compResolution:enabled'] = compResolution.GetId()
+
+ gridSizer.Add(item=compResolution,
+ pos=(row, 0), span=(1, 2))
+
sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py 2008-04-01 15:39:28 UTC (rev 30833)
+++ grass/trunk/gui/wxpython/gui_modules/render.py 2008-04-01 17:22:09 UTC (rev 30834)
@@ -353,8 +353,7 @@
return new
def AlignExtentFromDisplay(self):
- """Sets display extents (n,s,e,w) to even multiple of
- current display resolution from center point"""
+ """Align region extent based on display size from center point"""
# calculate new bounding box based on center of display
if self.region["ewres"] > self.region["nsres"]:
@@ -396,9 +395,9 @@
def GetRegion(self, rast=None, vect=None,
n=None, s=None, e=None, w=None, default=False):
"""
- Get region settings
+ Get region settings (g.region -upgc)
- Optionaly raster or vector map layer can be given.
+ Optionaly extent, raster or vector map layer can be given.
@param rast raster name or None
@param vect vector name or None
@@ -471,8 +470,7 @@
Render string for GRASS_REGION env. variable, so that the images will be rendered
from desired zoom level.
- @param windres If windres set to True, uses resolution from
- WIND file rather than display (for modules that require set
+ @param windres uses resolution from WIND file rather than display (for modules that require set
resolution like d.rast.num)
@return String usable for GRASS_REGION variable or None
@@ -480,7 +478,8 @@
grass_region = ""
# adjust region settings to match monitor
- self.region = self.AdjustRegion()
+ if not windres:
+ self.region = self.AdjustRegion()
# newextents = self.AlignResolution()
# self.region['n'] = newextents['n']
@@ -517,11 +516,11 @@
continue
elif key == "cols":
grass_region += 'cols: %d; ' % \
- (self.width)
+ self.region['cols']
continue
elif key == "rows":
grass_region += 'rows: %d; ' % \
- (self.height)
+ self.region['rows']
continue
else:
grass_region += key + ": " + self.wind[key] + "; "
@@ -611,7 +610,7 @@
return selected
- def Render(self, force=False, mapWindow=None):
+ def Render(self, force=False, mapWindow=None, windres=False):
"""
Creates final image composite
@@ -620,6 +619,7 @@
@param force force rendering
@param reference for MapFrame instance (for progress bar)
+ @param windres use region resolution (True) otherwise display resolution
@return name of file with rendered image or None
"""
@@ -631,7 +631,7 @@
opacities = []
tmp_region = os.getenv("GRASS_REGION")
- os.environ["GRASS_REGION"] = self.SetRegion()
+ os.environ["GRASS_REGION"] = self.SetRegion(windres)
os.environ["GRASS_WIDTH"] = str(self.width)
os.environ["GRASS_HEIGHT"] = str(self.height)
if UserSettings.Get(group='display', key='driver', subkey='type') == 'cairo':
More information about the grass-commit
mailing list