GRASS Programmer's Manual  6.4.4(2014)-r
mapdisp/toolbars.py
Go to the documentation of this file.
1 """!
2 @package mapdisp.toolbars
3 
4 @brief Map display frame - toolbars
5 
6 Classes:
7  - toolbars::MapToolbar
8 
9 (C) 2007-2011 by the GRASS Development Team
10 
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
13 
14 @author Michael Barton
15 @author Jachym Cepicky
16 @author Martin Landa <landa.martin gmail.com>
17 """
18 
19 import wx
20 
21 from gui_core.toolbars import BaseToolbar, BaseIcons
22 from nviz.main import haveNviz
23 from vdigit.main import haveVDigit
24 from icons.icon import MetaIcon
25 
26 MapIcons = {
27  'query' : MetaIcon(img = 'info',
28  label = _('Query raster/vector map(s)'),
29  desc = _('Query selected raster/vector map(s)')),
30  'addBarscale': MetaIcon(img = 'scalebar-add',
31  label = _('Add scalebar and north arrow')),
32  'addLegend' : MetaIcon(img = 'legend-add',
33  label = _('Add legend')),
34  'addNorthArrow': MetaIcon(img = 'north-arrow-add',
35  label = _('North Arrow')),
36  'analyze' : MetaIcon(img = 'layer-raster-analyze',
37  label = _('Analyze map'),
38  desc = _('Measuring, profiling, histogramming, ...')),
39  'measure' : MetaIcon(img = 'measure-length',
40  label = _('Measure distance')),
41  'profile' : MetaIcon(img = 'layer-raster-profile',
42  label = _('Profile surface map')),
43  'scatter' : MetaIcon(img = 'layer-raster-profile',
44  label = _("Create bivariate scatterplot of raster maps")),
45  'addText' : MetaIcon(img = 'text-add',
46  label = _('Add text layer')),
47  'histogram' : MetaIcon(img = 'layer-raster-histogram',
48  label = _('Create histogram of raster map')),
49  }
50 
51 NvizIcons = {
52  'rotate' : MetaIcon(img = '3d-rotate',
53  label = _('Rotate 3D scene'),
54  desc = _('Drag with mouse to rotate 3D scene')),
55  'flyThrough': MetaIcon(img = 'flythrough',
56  label = _('Fly-through mode'),
57  desc = _('Drag with mouse, hold Ctrl down for different mode'
58  ' or Shift to accelerate')),
59  'zoomIn' : BaseIcons['zoomIn'].SetLabel(desc = _('Click mouse to zoom')),
60  'zoomOut' : BaseIcons['zoomOut'].SetLabel(desc = _('Click mouse to unzoom'))
61  }
62 
64  """!Map Display toolbar
65  """
66  def __init__(self, parent, mapcontent):
67  """!Map Display constructor
68 
69  @param parent reference to MapFrame
70  @param mapcontent reference to render.Map (registred by MapFrame)
71  """
72  self.mapcontent = mapcontent # render.Map
73  BaseToolbar.__init__(self, parent = parent) # MapFrame
74 
75  self.InitToolbar(self._toolbarData())
76 
77  # optional tools
78  choices = [ _('2D view'), ]
79  self.toolId = { '2d' : 0 }
80  if self.parent.GetLayerManager():
81  log = self.parent.GetLayerManager().GetLogWindow()
82 
83  if haveNviz:
84  choices.append(_('3D view'))
85  self.toolId['3d'] = 1
86  else:
87  from nviz.main import errorMsg
88  log.WriteCmdLog(_('3D view mode not available'))
89  log.WriteWarning(_('Reason: %s') % str(errorMsg))
90  log.WriteLog(_('Note that the wxGUI\'s 3D view mode is currently disabled '
91  'on MS Windows (hopefully this will be fixed soon). '
92  'Please keep an eye out for updated versions of GRASS. '
93  'In the meantime you can use "NVIZ" from the File menu.'), wrap = 60)
94 
95  self.toolId['3d'] = -1
96 
97  if haveVDigit:
98  choices.append(_('Digitize'))
99  if self.toolId['3d'] > -1:
100  self.toolId['vdigit'] = 2
101  else:
102  self.toolId['vdigit'] = 1
103  else:
104  from vdigit.main import errorMsg
105  log.WriteCmdLog(_('Vector digitizer not available'))
106  log.WriteWarning(_('Reason: %s') % errorMsg)
107  log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled '
108  '(hopefully this will be fixed soon). '
109  'Please keep an eye out for updated versions of GRASS. '
110  'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60)
111 
112  self.toolId['vdigit'] = -1
113 
114  self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
115  choices = choices,
116  style = wx.CB_READONLY, size = (110, -1))
117  self.combo.SetSelection(0)
118 
119  self.comboid = self.AddControl(self.combo)
120  self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
121 
122  # realize the toolbar
123  self.Realize()
124 
125  # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
126  self.combo.Hide()
127  self.combo.Show()
128 
129  self.action = { 'id' : self.pointer }
130  self.defaultAction = { 'id' : self.pointer,
131  'bind' : self.parent.OnPointer }
132 
133  self.OnTool(None)
134 
135  self.EnableTool(self.zoomBack, False)
136 
137  self.FixSize(width = 90)
138 
139  def _toolbarData(self):
140  """!Toolbar data"""
141  return self._getToolbarData((('displayMap', BaseIcons['display'],
142  self.parent.OnDraw),
143  ('renderMap', BaseIcons['render'],
144  self.parent.OnRender),
145  ('erase', BaseIcons['erase'],
146  self.parent.OnErase),
147  (None, ),
148  ('pointer', BaseIcons['pointer'],
149  self.parent.OnPointer,
150  wx.ITEM_CHECK),
151  ('query', MapIcons['query'],
152  self.parent.OnQuery,
153  wx.ITEM_CHECK),
154  ('pan', BaseIcons['pan'],
155  self.parent.OnPan,
156  wx.ITEM_CHECK),
157  ('zoomIn', BaseIcons['zoomIn'],
158  self.parent.OnZoomIn,
159  wx.ITEM_CHECK),
160  ('zoomOut', BaseIcons['zoomOut'],
161  self.parent.OnZoomOut,
162  wx.ITEM_CHECK),
163  ('zoomExtent', BaseIcons['zoomExtent'],
164  self.parent.OnZoomToMap),
165  ('zoomBack', BaseIcons['zoomBack'],
166  self.parent.OnZoomBack),
167  ('zoomMenu', BaseIcons['zoomMenu'],
168  self.parent.OnZoomMenu),
169  (None, ),
170  ('analyze', MapIcons['analyze'],
171  self.OnAnalyze),
172  (None, ),
173  ('overlay', BaseIcons['overlay'],
174  self.OnDecoration),
175  (None, ),
176  ('saveFile', BaseIcons['saveFile'],
177  self.parent.SaveToFile),
178  ('printMap', BaseIcons['print'],
179  self.parent.PrintMenu),
180  (None, ))
181  )
182  def InsertTool(self, data):
183  """!Insert tool to toolbar
184 
185  @param data toolbar data"""
186  data = self._getToolbarData(data)
187  for tool in data:
188  self.CreateTool(*tool)
189  self.Realize()
190 
191  self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
192  self.parent._mgr.Update()
193 
194  def RemoveTool(self, tool):
195  """!Remove tool from toolbar
196 
197  @param tool tool id"""
198  self.DeleteTool(tool)
199 
200  self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
201  self.parent._mgr.Update()
202 
203  def ChangeToolsDesc(self, mode2d):
204  """!Change description of zoom tools for 2D/3D view"""
205  if mode2d:
206  icons = BaseIcons
207  else:
208  icons = NvizIcons
209  for i, data in enumerate(self._data):
210  for tool in (('zoomIn', 'zoomOut')):
211  if data[0] == tool:
212  tmp = list(data)
213  tmp[4] = icons[tool].GetDesc()
214  self._data[i] = tuple(tmp)
215 
216  def OnSelectTool(self, event):
217  """!Select / enable tool available in tools list
218  """
219  tool = event.GetSelection()
220 
221  if tool == self.toolId['2d']:
222  self.ExitToolbars()
223  self.Enable2D(True)
224  self.ChangeToolsDesc(mode2d = True)
225 
226  elif tool == self.toolId['3d'] and \
227  not (self.parent.MapWindow3D and self.parent.IsPaneShown('3d')):
228  self.ExitToolbars()
229  self.parent.AddNviz()
230 
231  elif tool == self.toolId['vdigit'] and \
232  not self.parent.GetToolbar('vdigit'):
233  self.ExitToolbars()
234  self.parent.AddToolbar("vdigit")
235  self.parent.MapWindow.SetFocus()
236 
237  def OnAnalyze(self, event):
238  """!Analysis tools menu
239  """
240  self._onMenu(((MapIcons["measure"], self.parent.OnMeasure),
241  (MapIcons["profile"], self.parent.OnProfile),
242  (MapIcons["histogram"], self.parent.OnHistogram)))
243 
244  def OnDecoration(self, event):
245  """!Decorations overlay menu
246  """
247  if self.parent.IsPaneShown('3d'):
248  self._onMenu(((MapIcons["addNorthArrow"], self.parent.OnAddArrow),
249  (MapIcons["addLegend"], lambda evt: self.parent.AddLegend()),
250  (MapIcons["addText"], self.parent.OnAddText)))
251  else:
252  self._onMenu(((MapIcons["addBarscale"], lambda evt: self.parent.AddBarscale()),
253  (MapIcons["addLegend"], lambda evt: self.parent.AddLegend()),
254  (MapIcons["addText"], self.parent.OnAddText)))
255 
256  def ExitToolbars(self):
257  if self.parent.GetToolbar('vdigit'):
258  self.parent.toolbars['vdigit'].OnExit()
259  if self.parent.GetLayerManager().IsPaneShown('toolbarNviz'):
260  self.parent.RemoveNviz()
261 
262  def Enable2D(self, enabled):
263  """!Enable/Disable 2D display mode specific tools"""
264  for tool in (self.zoomMenu,
265  self.analyze,
266  self.printMap):
267  self.EnableTool(tool, enabled)
def OnTool(self, event)
Tool selected.
def OnSelectTool(self, event)
Select / enable tool available in tools list.
def InitToolbar(self, toolData)
Initialize toolbar, add tools to the toolbar.
wxGUI vector digitizer
def Enable2D(self, enabled)
Enable/Disable 2D display mode specific tools.
def ChangeToolsDesc(self, mode2d)
Change description of zoom tools for 2D/3D view.
def RemoveTool(self, tool)
Remove tool from toolbar.
Nviz (3D view) module.
def FixSize(self, width)
Fix toolbar width on Windows.
def _getToolbarData(self, data)
Define tool.
def InsertTool(self, data)
Insert tool to toolbar.
def CreateTool
Add tool to the toolbar.
Abstract toolbar class.
def __init__(self, parent, mapcontent)
Map Display constructor.
Base classes toolbar widgets.
def _onMenu(self, data)
Toolbar pop-up menu.
Map Display toolbar.
def _toolbarData(self)
Toolbar data (virtual)
def OnAnalyze(self, event)
Analysis tools menu.
def OnDecoration(self, event)
Decorations overlay menu.