2 @package gui_core.mapwindow
4 @brief Map display canvas - base class for buffered window.
9 (C) 2006-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
16 @author Jachym Cepicky
24 """!Abstract map display window class
26 Superclass for BufferedWindow class (2D display mode), and GLWindow
29 Subclasses have to define
30 - _bindMouseEvents method which binds MouseEvent handlers
32 - Cell2Pixel (if it is possible)
35 def __init__(self, parent, id = wx.ID_ANY,
36 Map =
None, tree =
None, lmgr =
None, **kwargs):
57 """!Binds event handler
59 Call event.Skip() in handler to allow default processing in MapWindow.
63 def OnButton(self, event):
64 # current map display's map window
65 # expects LayerManager to be the parent
66 self.mapwin = self.parent.GetLayerTree().GetMapDisplay().GetWindow()
67 if self.mapwin.RegisterMouseEventHandler(wx.EVT_LEFT_DOWN, self.OnMouseAction,
68 wx.StockCursor(wx.CURSOR_CROSS)):
69 self.parent.GetLayerTree().GetMapDisplay().Raise()
71 # handle that you cannot get coordinates
73 def OnMouseAction(self, event):
74 # get real world coordinates of mouse click
75 coor = self.mapwin.Pixel2Cell(event.GetPositionTuple()[:])
76 self.text.SetLabel('Coor: ' + str(coor))
77 self.mapwin.UnregisterMouseEventHandler(wx.EVT_LEFT_DOWN)
81 @param event one of mouse events
82 @param handler function to handle event
83 @param cursor cursor which temporary overrides current cursor
85 @return True if successful
86 @return False if event cannot be bind
91 if hasattr(self,
"digit"):
94 self.Bind(event, handler)
95 self.
mouse[
'useBeforeGenericEvent'] = self.
mouse[
'use']
96 self.
mouse[
'use'] =
'genericEvent'
100 self.SetCursor(cursor)
106 """!Unbinds event handler a restores previous state
108 You should unbind to restore normal MapWindow behaviour.
109 Note that this operation will unbind any other external (non-MapWindow) handlers.
111 @param event event to unbind
113 @return True if successful
114 @return False if event cannot be unbind
116 if hasattr(self,
"digit"):
120 ret = self.Unbind(event)
123 self._bindMouseEvents()
126 self.
mouse[
'use'] = self.
mouse[
'useBeforeGenericEvent']
135 raise NotImplementedError()
138 raise NotImplementedError()
141 """!Tracks mouse motion and update statusbar
150 if self.parent.statusbarManager.GetMode() == 0:
152 if hasattr(self,
"digit"):
153 precision = int(UserSettings.Get(group =
'projection', key =
'format',
154 subkey =
'precision'))
155 updated = self._onMotion(self.
lastEN, precision)
158 self.parent.CoordinatesChanged()
163 """!Returns last coordinates of mouse cursor.
170 """!Get layer from layer tree by nam
172 @param name layer name
173 @param type 'item' / 'layer' / 'nviz'
175 @return layer / map layer properties / nviz properties
182 mapLayer = self.Map.GetListOfLayers(l_type = mapType, l_name = name)[0]
186 if dataType ==
'layer':
188 item = self.tree.FindItemByData(
'maplayer', mapLayer)
191 if dataType ==
'nviz':
192 return self.tree.GetPyData(item)[0][
'nviz']
197 """!Get selected layer from layer tree
199 @param type 'item' / 'layer' / 'nviz'
200 @param multi return first selected layer or all
202 @return layer / map layer properties / nviz properties
203 @return None / [] on failure
206 if not self.
tree or \
207 not self.tree.GetSelection():
215 return self.tree.GetSelections()
217 for item
in self.tree.GetSelections():
218 if not item.IsChecked():
229 layer = self.tree.GetPyData(item)[0][
'nviz']
231 layer = self.tree.GetPyData(item)[0][
'maplayer']