toolbars.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. log.WriteCmdLog(_('3D view mode not available'))
  77. log.WriteWarning(_('Reason: %s') % str(errorMsg))
  78. self.toolId['3d'] = -1
  79. if haveVDigit:
  80. choices.append(_('Digitize'))
  81. if self.toolId['3d'] > -1:
  82. self.toolId['vdigit'] = 2
  83. else:
  84. self.toolId['vdigit'] = 1
  85. else:
  86. from vdigit.main import errorMsg
  87. log.WriteCmdLog(_('Vector digitizer not available'))
  88. log.WriteWarning(_('Reason: %s') % errorMsg)
  89. log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled '
  90. '(hopefully this will be fixed soon). '
  91. 'Please keep an eye out for updated versions of GRASS. '
  92. 'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60)
  93. self.toolId['vdigit'] = -1
  94. self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
  95. choices = choices,
  96. style = wx.CB_READONLY, size = (110, -1))
  97. self.combo.SetSelection(0)
  98. self.comboid = self.AddControl(self.combo)
  99. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  100. # realize the toolbar
  101. self.Realize()
  102. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  103. self.combo.Hide()
  104. self.combo.Show()
  105. self.action = { 'id' : self.pointer }
  106. self.defaultAction = { 'id' : self.pointer,
  107. 'bind' : self.parent.OnPointer }
  108. self.OnTool(None)
  109. self.EnableTool(self.zoomBack, False)
  110. self.FixSize(width = 90)
  111. def _toolbarData(self):
  112. """!Toolbar data"""
  113. return self._getToolbarData((('displayMap', BaseIcons['display'],
  114. self.parent.OnDraw),
  115. ('renderMap', BaseIcons['render'],
  116. self.parent.OnRender),
  117. ('erase', BaseIcons['erase'],
  118. self.parent.OnErase),
  119. (None, ),
  120. ('pointer', BaseIcons['pointer'],
  121. self.parent.OnPointer,
  122. wx.ITEM_CHECK),
  123. ('query', MapIcons['query'],
  124. self.parent.OnQuery,
  125. wx.ITEM_CHECK),
  126. ('pan', BaseIcons['pan'],
  127. self.parent.OnPan,
  128. wx.ITEM_CHECK),
  129. ('zoomIn', BaseIcons['zoomIn'],
  130. self.parent.OnZoomIn,
  131. wx.ITEM_CHECK),
  132. ('zoomOut', BaseIcons['zoomOut'],
  133. self.parent.OnZoomOut,
  134. wx.ITEM_CHECK),
  135. ('zoomExtent', BaseIcons['zoomExtent'],
  136. self.parent.OnZoomToMap),
  137. ('zoomBack', BaseIcons['zoomBack'],
  138. self.parent.OnZoomBack),
  139. ('zoomMenu', BaseIcons['zoomMenu'],
  140. self.parent.OnZoomMenu),
  141. (None, ),
  142. ('analyze', MapIcons['analyze'],
  143. self.OnAnalyze),
  144. (None, ),
  145. ('overlay', BaseIcons['overlay'],
  146. self.OnDecoration),
  147. (None, ),
  148. ('saveFile', BaseIcons['saveFile'],
  149. self.parent.SaveToFile),
  150. ('printMap', BaseIcons['print'],
  151. self.parent.PrintMenu),
  152. (None, ))
  153. )
  154. def InsertTool(self, data):
  155. """!Insert tool to toolbar
  156. @param data toolbar data"""
  157. data = self._getToolbarData(data)
  158. for tool in data:
  159. self.CreateTool(*tool)
  160. self.Realize()
  161. self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
  162. self.parent._mgr.Update()
  163. def RemoveTool(self, tool):
  164. """!Remove tool from toolbar
  165. @param tool tool id"""
  166. self.DeleteTool(tool)
  167. self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
  168. self.parent._mgr.Update()
  169. def ChangeToolsDesc(self, mode2d):
  170. """!Change description of zoom tools for 2D/3D view"""
  171. if mode2d:
  172. icons = BaseIcons
  173. else:
  174. icons = NvizIcons
  175. for i, data in enumerate(self._data):
  176. for tool in (('zoomIn', 'zoomOut')):
  177. if data[0] == tool:
  178. tmp = list(data)
  179. tmp[4] = icons[tool].GetDesc()
  180. self._data[i] = tuple(tmp)
  181. def OnSelectTool(self, event):
  182. """!Select / enable tool available in tools list
  183. """
  184. tool = event.GetSelection()
  185. if tool == self.toolId['2d']:
  186. self.ExitToolbars()
  187. self.Enable2D(True)
  188. self.ChangeToolsDesc(mode2d = True)
  189. elif tool == self.toolId['3d'] and \
  190. not (self.parent.MapWindow3D and self.parent.IsPaneShown('3d')):
  191. self.ExitToolbars()
  192. self.parent.AddNviz()
  193. elif tool == self.toolId['vdigit'] and \
  194. not self.parent.GetToolbar('vdigit'):
  195. self.ExitToolbars()
  196. self.parent.AddToolbar("vdigit")
  197. self.parent.MapWindow.SetFocus()
  198. def OnAnalyze(self, event):
  199. """!Analysis tools menu
  200. """
  201. self._onMenu(((MapIcons["measure"], self.parent.OnMeasure),
  202. (MapIcons["profile"], self.parent.OnProfile),
  203. (MapIcons["scatter"], self.parent.OnScatterplot),
  204. (MapIcons["histogram"], self.parent.OnHistogramPyPlot),
  205. (BaseIcons["histogramD"], self.parent.OnHistogram),
  206. (MapIcons["vnet"], self.parent.OnVNet)))
  207. def OnDecoration(self, event):
  208. """!Decorations overlay menu
  209. """
  210. if self.parent.IsPaneShown('3d'):
  211. self._onMenu(((MapIcons["addNorthArrow"], self.parent.OnAddArrow),
  212. (MapIcons["addLegend"], self.parent.OnAddLegend),
  213. (MapIcons["addText"], self.parent.OnAddText)))
  214. else:
  215. self._onMenu(((MapIcons["addBarscale"], self.parent.OnAddBarscale),
  216. (MapIcons["addLegend"], self.parent.OnAddLegend),
  217. (MapIcons["addText"], self.parent.OnAddText)))
  218. def ExitToolbars(self):
  219. if self.parent.GetToolbar('vdigit'):
  220. self.parent.toolbars['vdigit'].OnExit()
  221. if self.parent.GetLayerManager() and \
  222. self.parent.GetLayerManager().IsPaneShown('toolbarNviz'):
  223. self.parent.RemoveNviz()
  224. def Enable2D(self, enabled):
  225. """!Enable/Disable 2D display mode specific tools"""
  226. for tool in (self.zoomMenu,
  227. self.analyze,
  228. self.printMap):
  229. self.EnableTool(tool, enabled)