toolbars.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. """!
  2. @package mapdisp.toolbars
  3. @brief Map display frame - toolbars
  4. Classes:
  5. - 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
  15. from icons.icon import Icons
  16. from nviz.main import haveNviz
  17. from vdigit.main import haveVDigit
  18. class MapToolbar(BaseToolbar):
  19. """!Map Display toolbar
  20. """
  21. def __init__(self, parent, mapcontent):
  22. """!Map Display constructor
  23. @param parent reference to MapFrame
  24. @param mapcontent reference to render.Map (registred by MapFrame)
  25. """
  26. self.mapcontent = mapcontent # render.Map
  27. BaseToolbar.__init__(self, parent = parent) # MapFrame
  28. self.InitToolbar(self._toolbarData())
  29. # optional tools
  30. choices = [ _('2D view'), ]
  31. self.toolId = { '2d' : 0 }
  32. if self.parent.GetLayerManager():
  33. log = self.parent.GetLayerManager().GetLogWindow()
  34. if haveNviz:
  35. choices.append(_('3D view'))
  36. self.toolId['3d'] = 1
  37. else:
  38. from nviz.main import errorMsg
  39. log.WriteCmdLog(_('3D view mode not available'))
  40. log.WriteWarning(_('Reason: %s') % str(errorMsg))
  41. log.WriteLog(_('Note that the wxGUI\'s 3D view mode is currently disabled '
  42. 'on MS Windows (hopefully this will be fixed soon). '
  43. 'Please keep an eye out for updated versions of GRASS. '
  44. 'In the meantime you can use "NVIZ" from the File menu.'), wrap = 60)
  45. self.toolId['3d'] = -1
  46. if haveVDigit:
  47. choices.append(_('Digitize'))
  48. if self.toolId['3d'] > -1:
  49. self.toolId['vdigit'] = 2
  50. else:
  51. self.toolId['vdigit'] = 1
  52. else:
  53. from vdigit.main import errorMsg
  54. log.WriteCmdLog(_('Vector digitizer not available'))
  55. log.WriteWarning(_('Reason: %s') % errorMsg)
  56. log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled '
  57. '(hopefully this will be fixed soon). '
  58. 'Please keep an eye out for updated versions of GRASS. '
  59. 'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60)
  60. self.toolId['vdigit'] = -1
  61. self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
  62. choices = choices,
  63. style = wx.CB_READONLY, size = (110, -1))
  64. self.combo.SetSelection(0)
  65. self.comboid = self.AddControl(self.combo)
  66. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  67. # realize the toolbar
  68. self.Realize()
  69. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  70. self.combo.Hide()
  71. self.combo.Show()
  72. self.action = { 'id' : self.pointer }
  73. self.defaultAction = { 'id' : self.pointer,
  74. 'bind' : self.parent.OnPointer }
  75. self.OnTool(None)
  76. self.EnableTool(self.zoomback, False)
  77. self.FixSize(width = 90)
  78. def _toolbarData(self):
  79. """!Toolbar data"""
  80. icons = Icons['displayWindow']
  81. return self._getToolbarData((('displaymap', icons['display'],
  82. self.parent.OnDraw),
  83. ('rendermap', icons['render'],
  84. self.parent.OnRender),
  85. ('erase', icons['erase'],
  86. self.parent.OnErase),
  87. (None, ),
  88. ('pointer', icons['pointer'],
  89. self.parent.OnPointer,
  90. wx.ITEM_CHECK),
  91. ('query', icons['query'],
  92. self.parent.OnQuery,
  93. wx.ITEM_CHECK),
  94. ('pan', icons['pan'],
  95. self.parent.OnPan,
  96. wx.ITEM_CHECK),
  97. ('zoomin', icons['zoomIn'],
  98. self.parent.OnZoomIn,
  99. wx.ITEM_CHECK),
  100. ('zoomout', icons['zoomOut'],
  101. self.parent.OnZoomOut,
  102. wx.ITEM_CHECK),
  103. ('zoomextent', icons['zoomExtent'],
  104. self.parent.OnZoomToMap),
  105. ('zoomback', icons['zoomBack'],
  106. self.parent.OnZoomBack),
  107. ('zoommenu', icons['zoomMenu'],
  108. self.parent.OnZoomMenu),
  109. (None, ),
  110. ('analyze', icons['analyze'],
  111. self.parent.OnAnalyze),
  112. (None, ),
  113. ('dec', icons['overlay'],
  114. self.parent.OnDecoration),
  115. (None, ),
  116. ('savefile', icons['saveFile'],
  117. self.parent.SaveToFile),
  118. ('printmap', icons['print'],
  119. self.parent.PrintMenu),
  120. (None, ))
  121. )
  122. def InsertTool(self, data):
  123. """!Insert tool to toolbar
  124. @param data toolbar data"""
  125. data = self._getToolbarData(data)
  126. for tool in data:
  127. self.CreateTool(*tool)
  128. self.Realize()
  129. self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
  130. self.parent._mgr.Update()
  131. def RemoveTool(self, tool):
  132. """!Remove tool from toolbar
  133. @param tool tool id"""
  134. self.DeleteTool(tool)
  135. self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize())
  136. self.parent._mgr.Update()
  137. def ChangeToolsDesc(self, mode2d):
  138. """!Change description of zoom tools for 2D/3D view"""
  139. if mode2d:
  140. set = 'displayWindow'
  141. else:
  142. set = 'nviz'
  143. for i, data in enumerate(self._data):
  144. for tool, toolname in (('zoomin', 'zoomIn'),('zoomout', 'zoomOut')):
  145. if data[0] == tool:
  146. tmp = list(data)
  147. tmp[4] = Icons[set][toolname].GetDesc()
  148. self._data[i] = tuple(tmp)
  149. def OnSelectTool(self, event):
  150. """!Select / enable tool available in tools list
  151. """
  152. tool = event.GetSelection()
  153. if tool == self.toolId['2d']:
  154. self.ExitToolbars()
  155. self.Enable2D(True)
  156. self.ChangeToolsDesc(mode2d = True)
  157. elif tool == self.toolId['3d'] and \
  158. not (self.parent.MapWindow3D and self.parent.IsPaneShown('3d')):
  159. self.ExitToolbars()
  160. self.parent.AddNviz()
  161. elif tool == self.toolId['vdigit'] and \
  162. not self.parent.GetToolbar('vdigit'):
  163. self.ExitToolbars()
  164. self.parent.AddToolbar("vdigit")
  165. self.parent.MapWindow.SetFocus()
  166. def ExitToolbars(self):
  167. if self.parent.GetToolbar('vdigit'):
  168. self.parent.toolbars['vdigit'].OnExit()
  169. if self.parent.GetLayerManager().IsPaneShown('toolbarNviz'):
  170. self.parent.RemoveNviz()
  171. def Enable2D(self, enabled):
  172. """!Enable/Disable 2D display mode specific tools"""
  173. for tool in (self.zoommenu,
  174. self.analyze,
  175. self.printmap):
  176. self.EnableTool(tool, enabled)