toolbars.py 11 KB

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