toolbars.py 11 KB

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