2 @package gui_core.mapdisp
4 @brief Base classes for Map display window
7 - mapdisp::MapFrameBase
9 (C) 2009-2011 by the GRASS Development Team
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
14 @author Martin Landa <landa.martin gmail.com>
15 @author Michael Barton <michael.barton@asu.edu>
23 from core
import globalvar
29 """!Base class for map display window
31 Derived class must use statusbarManager or override
32 GetProperty, SetProperty and HasProperty methods.
33 If derived class enables and disables auto-rendering,
34 it should override IsAutoRendered method.
36 def __init__(self, parent = None, id = wx.ID_ANY, title = None,
37 style = wx.DEFAULT_FRAME_STYLE, toolbars =
None,
38 Map =
None, auimgr =
None, name =
None, **kwargs):
40 @param toolbars array of activated toolbars, e.g. ['map', 'digit']
41 @param Map instance of render.Map
42 @param auimgs AUI manager
43 @param name frame name
44 @param kwargs wx.Frame attributes
51 wx.Frame.__init__(self, parent, id, title, style = style, name = name, **kwargs)
57 "default" : wx.StockCursor(wx.CURSOR_ARROW),
58 "cross" : wx.StockCursor(wx.CURSOR_CROSS),
59 "hand" : wx.StockCursor(wx.CURSOR_HAND),
60 "pencil" : wx.StockCursor(wx.CURSOR_PENCIL),
61 "sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE)
67 self.SetClientSize(self.GetSize())
70 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
'grass_map.ico'), wx.BITMAP_TYPE_ICO))
78 self.
_mgr = wx.aui.AuiManager(self)
80 def _initMap(self, map):
81 """!Initialize map display, set dimensions and map region
83 if not grass.find_program(
'g.region', [
'--help']):
84 sys.exit(_(
"GRASS module '%s' not found. Unable to start map "
85 "display window.") %
'g.region')
87 self.width, self.
height = self.GetClientSize()
89 Debug.msg(2,
"MapFrame._initMap():")
90 map.ChangeMapSize(self.GetClientSize())
91 map.region = map.GetRegion()
96 self.statusbarManager.SetProperty(name, value)
99 """!Returns property"""
100 return self.statusbarManager.GetProperty(name)
103 """!Checks whether object has property"""
104 return self.statusbarManager.HasProperty(name)
107 """! Get pixel per meter
109 @todo now computed every time, is it necessary?
110 @todo enable user to specify ppm (and store it in UserSettings)
116 dpSizePx = wx.DisplaySize()
117 dpSizeMM = wx.DisplaySizeMM()
118 dpSizeIn = (dpSizeMM[0] / 25.4, dpSizeMM[1] / 25.4)
120 comPpi = (dpSizePx[0] / dpSizeIn[0],
121 dpSizePx[1] / dpSizeIn[1])
124 ppm = ((ppi[0] / 2.54) * 100,
125 (ppi[1] / 2.54) * 100)
127 Debug.msg(4,
"MapFrameBase.GetPPM(): size: px=%d,%d mm=%f,%f "
128 "in=%f,%f ppi: sys=%d,%d com=%d,%d; ppm=%f,%f" % \
129 (dpSizePx[0], dpSizePx[1], dpSizeMM[0], dpSizeMM[1],
130 dpSizeIn[0], dpSizeIn[1],
131 sysPpi[0], sysPpi[1], comPpi[0], comPpi[1],
137 """! Set current map scale
139 @param value scale value (n if scale is 1:n)
140 @param map Map instance (if none self.Map is used)
145 region = self.Map.region
146 dEW = value * (region[
'cols'] / self.
GetPPM()[0])
147 dNS = value * (region[
'rows'] / self.
GetPPM()[1])
148 region[
'n'] = region[
'center_northing'] + dNS / 2.
149 region[
's'] = region[
'center_northing'] - dNS / 2.
150 region[
'w'] = region[
'center_easting'] - dEW / 2.
151 region[
'e'] = region[
'center_easting'] + dEW / 2.
154 self.
GetWindow().ZoomHistory(region[
'n'], region[
's'],
155 region[
'e'], region[
'w'])
158 """! Get current map scale
160 @param map Map instance (if none self.Map is used)
168 heightCm = region[
'rows'] / ppm[1] * 100
169 widthCm = region[
'cols'] / ppm[0] * 100
171 Debug.msg(4,
"MapFrame.GetMapScale(): width_cm=%f, height_cm=%f" %
174 xscale = (region[
'e'] - region[
'w']) / (region[
'cols'] / ppm[0])
175 yscale = (region[
'n'] - region[
's']) / (region[
'rows'] / ppm[1])
176 scale = (xscale + yscale) / 2.
178 Debug.msg(3,
"MapFrame.GetMapScale(): xscale=%f, yscale=%f -> scale=%f" % \
179 (xscale, yscale, scale))
184 """!Returns progress bar
186 Progress bar can be used by other classes.
188 return self.statusbarManager.GetProgressBar()
191 """!Returns current Map instance
196 """!Get map window"""
197 return self.MapWindow
200 """!Returns toolbar with zooming tools"""
201 raise NotImplementedError()
204 """!Returns toolbar if exists else None.
206 Toolbars dictionary contains currently used toolbars only.
214 """!Update statusbar content"""
215 self.statusbarManager.Update()
218 """!Check if auto-rendering is enabled"""
222 """!Shows current coordinates on statusbar.
224 Used in BufferedWindow to report change of map coordinates (under mouse cursor).
226 self.statusbarManager.ShowItem(
'coordinates')
229 """!Reposition items in statusbar"""
230 self.statusbarManager.Reposition()
233 """!Enable/disable toolbars long help"""
234 for toolbar
in self.toolbars.itervalues():
235 toolbar.EnableLongHelp(enable)
238 """!Check if Map display is standalone"""
239 raise NotImplementedError(
"IsStandalone")
242 """!Re-render map composition (each map layer)
244 raise NotImplementedError(
"OnRender")
247 """!Re-display current map composition
249 self.MapWindow.UpdateMap(render =
False)
254 self.MapWindow.EraseMap()
258 Set mouse cursor, zoombox attributes, and zoom direction
267 """!Zoom out the map.
268 Set mouse cursor, zoombox attributes, and zoom direction
276 def _prepareZoom(self, mapWindow, zoomType):
277 """!Prepares MapWindow for zoom, toggles toolbar
279 @param mapWindow MapWindow to prepare
280 @param zoomType 1 for zoom in, -1 for zoom out
282 mapWindow.mouse[
'use'] =
"zoom"
283 mapWindow.mouse[
'box'] =
"box"
284 mapWindow.zoomtype = zoomType
285 mapWindow.pen = wx.Pen(colour =
'Red', width = 2, style = wx.SHORT_DASH)
288 mapWindow.SetCursor(self.
cursors[
"cross"])
290 def _switchTool(self, toolbar, event):
291 """!Helper function to switch tools"""
293 toolbar.OnTool(event)
294 toolbar.action[
'desc'] =
''
297 """!Sets mouse mode to pointer."""
298 self.MapWindow.mouse[
'use'] =
'pointer'
301 """!Panning, set mouse to drag
309 def _preparePan(self, mapWindow):
310 """!Prepares MapWindow for pan, toggles toolbar
312 @param mapWindow MapWindow to prepare
314 mapWindow.mouse[
'use'] =
"pan"
315 mapWindow.mouse[
'box'] =
"pan"
316 mapWindow.zoomtype = 0
319 mapWindow.SetCursor(self.
cursors[
"hand"])
322 """!Zoom last (previously stored position)
324 self.MapWindow.ZoomBack()
328 Set display extents to match selected raster (including NULLs)
331 self.MapWindow.ZoomToMap(layers = self.Map.GetListOfLayers())
334 """!Set display geometry to match computational region
335 settings (set with g.region)
337 self.MapWindow.ZoomToWind()
340 """!Set display geometry to match default region settings
342 self.MapWindow.ZoomToDefault()
def OnRender
Re-render map composition (each map layer)
def OnZoomBack
Zoom last (previously stored position)
def StatusbarUpdate
Update statusbar content.
Base class for map display window.
def GetPPM
Get pixel per meter.
def GetWindow
Get map window.
def HasProperty
Checks whether object has property.
def OnZoomToWind
Set display geometry to match computational region settings (set with g.region)
def OnDraw
Re-display current map composition.
def OnZoomOut
Zoom out the map.
def CoordinatesChanged
Shows current coordinates on statusbar.
def GetMapToolbar
Returns toolbar with zooming tools.
def OnZoomIn
Zoom in the map.
def OnPointer
Sets mouse mode to pointer.
def _preparePan
Prepares MapWindow for pan, toggles toolbar.
def GetMapScale
Get current map scale.
def OnZoomToMap
Set display extents to match selected raster (including NULLs) or vector map.
def GetToolbar
Returns toolbar if exists else None.
def SetProperty
Sets property.
def OnPan
Panning, set mouse to drag.
def SetMapScale
Set current map scale.
def StatusbarEnableLongHelp
Enable/disable toolbars long help.
def GetProgressBar
Returns progress bar.
def GetMap
Returns current Map instance.
def _switchTool
Helper function to switch tools.
def IsAutoRendered
Check if auto-rendering is enabled.
def IsStandalone
Check if Map display is standalone.
def _prepareZoom
Prepares MapWindow for zoom, toggles toolbar.
def OnZoomToDefault
Set display geometry to match default region settings.
def GetProperty
Returns property.
def StatusbarReposition
Reposition items in statusbar.
def OnErase
Erase the canvas.