|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 """! 00002 @package mapdisp.toolbars 00003 00004 @brief Map display frame - toolbars 00005 00006 Classes: 00007 - toolbars::MapToolbar 00008 00009 (C) 2007-2011 by the GRASS Development Team 00010 00011 This program is free software under the GNU General Public License 00012 (>=v2). Read the file COPYING that comes with GRASS for details. 00013 00014 @author Michael Barton 00015 @author Jachym Cepicky 00016 @author Martin Landa <landa.martin gmail.com> 00017 """ 00018 00019 import wx 00020 00021 from gui_core.toolbars import BaseToolbar, BaseIcons 00022 from nviz.main import haveNviz 00023 from vdigit.main import haveVDigit 00024 from icons.icon import MetaIcon 00025 00026 MapIcons = { 00027 'query' : MetaIcon(img = 'info', 00028 label = _('Query raster/vector map(s)'), 00029 desc = _('Query selected raster/vector map(s)')), 00030 'addBarscale': MetaIcon(img = 'scalebar-add', 00031 label = _('Add scalebar and north arrow')), 00032 'addLegend' : MetaIcon(img = 'legend-add', 00033 label = _('Add legend')), 00034 'addNorthArrow': MetaIcon(img = 'north-arrow-add', 00035 label = _('North Arrow')), 00036 'analyze' : MetaIcon(img = 'layer-raster-analyze', 00037 label = _('Analyze map'), 00038 desc = _('Measuring, profiling, histogramming, ...')), 00039 'measure' : MetaIcon(img = 'measure-length', 00040 label = _('Measure distance')), 00041 'profile' : MetaIcon(img = 'layer-raster-profile', 00042 label = _('Profile surface map')), 00043 'scatter' : MetaIcon(img = 'layer-raster-profile', 00044 label = _("Create bivariate scatterplot of raster maps")), 00045 'addText' : MetaIcon(img = 'text-add', 00046 label = _('Add text layer')), 00047 'histogram' : MetaIcon(img = 'layer-raster-histogram', 00048 label = _('Create histogram of raster map')), 00049 } 00050 00051 NvizIcons = { 00052 'rotate' : MetaIcon(img = '3d-rotate', 00053 label = _('Rotate 3D scene'), 00054 desc = _('Drag with mouse to rotate 3D scene')), 00055 'flyThrough': MetaIcon(img = 'flythrough', 00056 label = _('Fly-through mode'), 00057 desc = _('Drag with mouse, hold Ctrl down for different mode' 00058 ' or Shift to accelerate')), 00059 'zoomIn' : BaseIcons['zoomIn'].SetLabel(desc = _('Click mouse to zoom')), 00060 'zoomOut' : BaseIcons['zoomOut'].SetLabel(desc = _('Click mouse to unzoom')) 00061 } 00062 00063 class MapToolbar(BaseToolbar): 00064 """!Map Display toolbar 00065 """ 00066 def __init__(self, parent, mapcontent): 00067 """!Map Display constructor 00068 00069 @param parent reference to MapFrame 00070 @param mapcontent reference to render.Map (registred by MapFrame) 00071 """ 00072 self.mapcontent = mapcontent # render.Map 00073 BaseToolbar.__init__(self, parent = parent) # MapFrame 00074 00075 self.InitToolbar(self._toolbarData()) 00076 00077 # optional tools 00078 choices = [ _('2D view'), ] 00079 self.toolId = { '2d' : 0 } 00080 if self.parent.GetLayerManager(): 00081 log = self.parent.GetLayerManager().GetLogWindow() 00082 00083 if haveNviz: 00084 choices.append(_('3D view')) 00085 self.toolId['3d'] = 1 00086 else: 00087 from nviz.main import errorMsg 00088 log.WriteCmdLog(_('3D view mode not available')) 00089 log.WriteWarning(_('Reason: %s') % str(errorMsg)) 00090 log.WriteLog(_('Note that the wxGUI\'s 3D view mode is currently disabled ' 00091 'on MS Windows (hopefully this will be fixed soon). ' 00092 'Please keep an eye out for updated versions of GRASS. ' 00093 'In the meantime you can use "NVIZ" from the File menu.'), wrap = 60) 00094 00095 self.toolId['3d'] = -1 00096 00097 if haveVDigit: 00098 choices.append(_('Digitize')) 00099 if self.toolId['3d'] > -1: 00100 self.toolId['vdigit'] = 2 00101 else: 00102 self.toolId['vdigit'] = 1 00103 else: 00104 from vdigit.main import errorMsg 00105 log.WriteCmdLog(_('Vector digitizer not available')) 00106 log.WriteWarning(_('Reason: %s') % errorMsg) 00107 log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled ' 00108 '(hopefully this will be fixed soon). ' 00109 'Please keep an eye out for updated versions of GRASS. ' 00110 'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60) 00111 00112 self.toolId['vdigit'] = -1 00113 00114 self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY, 00115 choices = choices, 00116 style = wx.CB_READONLY, size = (110, -1)) 00117 self.combo.SetSelection(0) 00118 00119 self.comboid = self.AddControl(self.combo) 00120 self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid) 00121 00122 # realize the toolbar 00123 self.Realize() 00124 00125 # workaround for Mac bug. May be fixed by 2.8.8, but not before then. 00126 self.combo.Hide() 00127 self.combo.Show() 00128 00129 self.action = { 'id' : self.pointer } 00130 self.defaultAction = { 'id' : self.pointer, 00131 'bind' : self.parent.OnPointer } 00132 00133 self.OnTool(None) 00134 00135 self.EnableTool(self.zoomBack, False) 00136 00137 self.FixSize(width = 90) 00138 00139 def _toolbarData(self): 00140 """!Toolbar data""" 00141 return self._getToolbarData((('displayMap', BaseIcons['display'], 00142 self.parent.OnDraw), 00143 ('renderMap', BaseIcons['render'], 00144 self.parent.OnRender), 00145 ('erase', BaseIcons['erase'], 00146 self.parent.OnErase), 00147 (None, ), 00148 ('pointer', BaseIcons['pointer'], 00149 self.parent.OnPointer, 00150 wx.ITEM_CHECK), 00151 ('query', MapIcons['query'], 00152 self.parent.OnQuery, 00153 wx.ITEM_CHECK), 00154 ('pan', BaseIcons['pan'], 00155 self.parent.OnPan, 00156 wx.ITEM_CHECK), 00157 ('zoomIn', BaseIcons['zoomIn'], 00158 self.parent.OnZoomIn, 00159 wx.ITEM_CHECK), 00160 ('zoomOut', BaseIcons['zoomOut'], 00161 self.parent.OnZoomOut, 00162 wx.ITEM_CHECK), 00163 ('zoomExtent', BaseIcons['zoomExtent'], 00164 self.parent.OnZoomToMap), 00165 ('zoomBack', BaseIcons['zoomBack'], 00166 self.parent.OnZoomBack), 00167 ('zoomMenu', BaseIcons['zoomMenu'], 00168 self.parent.OnZoomMenu), 00169 (None, ), 00170 ('analyze', MapIcons['analyze'], 00171 self.OnAnalyze), 00172 (None, ), 00173 ('overlay', BaseIcons['overlay'], 00174 self.OnDecoration), 00175 (None, ), 00176 ('saveFile', BaseIcons['saveFile'], 00177 self.parent.SaveToFile), 00178 ('printMap', BaseIcons['print'], 00179 self.parent.PrintMenu), 00180 (None, )) 00181 ) 00182 def InsertTool(self, data): 00183 """!Insert tool to toolbar 00184 00185 @param data toolbar data""" 00186 data = self._getToolbarData(data) 00187 for tool in data: 00188 self.CreateTool(*tool) 00189 self.Realize() 00190 00191 self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize()) 00192 self.parent._mgr.Update() 00193 00194 def RemoveTool(self, tool): 00195 """!Remove tool from toolbar 00196 00197 @param tool tool id""" 00198 self.DeleteTool(tool) 00199 00200 self.parent._mgr.GetPane('mapToolbar').BestSize(self.GetBestSize()) 00201 self.parent._mgr.Update() 00202 00203 def ChangeToolsDesc(self, mode2d): 00204 """!Change description of zoom tools for 2D/3D view""" 00205 if mode2d: 00206 icons = BaseIcons 00207 else: 00208 icons = NvizIcons 00209 for i, data in enumerate(self._data): 00210 for tool in (('zoomIn', 'zoomOut')): 00211 if data[0] == tool: 00212 tmp = list(data) 00213 tmp[4] = icons[tool].GetDesc() 00214 self._data[i] = tuple(tmp) 00215 00216 def OnSelectTool(self, event): 00217 """!Select / enable tool available in tools list 00218 """ 00219 tool = event.GetSelection() 00220 00221 if tool == self.toolId['2d']: 00222 self.ExitToolbars() 00223 self.Enable2D(True) 00224 self.ChangeToolsDesc(mode2d = True) 00225 00226 elif tool == self.toolId['3d'] and \ 00227 not (self.parent.MapWindow3D and self.parent.IsPaneShown('3d')): 00228 self.ExitToolbars() 00229 self.parent.AddNviz() 00230 00231 elif tool == self.toolId['vdigit'] and \ 00232 not self.parent.GetToolbar('vdigit'): 00233 self.ExitToolbars() 00234 self.parent.AddToolbar("vdigit") 00235 self.parent.MapWindow.SetFocus() 00236 00237 def OnAnalyze(self, event): 00238 """!Analysis tools menu 00239 """ 00240 self._onMenu(((MapIcons["measure"], self.parent.OnMeasure), 00241 (MapIcons["profile"], self.parent.OnProfile), 00242 (MapIcons["histogram"], self.parent.OnHistogram))) 00243 00244 def OnDecoration(self, event): 00245 """!Decorations overlay menu 00246 """ 00247 if self.parent.IsPaneShown('3d'): 00248 self._onMenu(((MapIcons["addNorthArrow"], self.parent.OnAddArrow), 00249 (MapIcons["addLegend"], self.parent.OnAddLegend), 00250 (MapIcons["addText"], self.parent.OnAddText))) 00251 else: 00252 self._onMenu(((MapIcons["addBarscale"], self.parent.OnAddBarscale), 00253 (MapIcons["addLegend"], self.parent.OnAddLegend), 00254 (MapIcons["addText"], self.parent.OnAddText))) 00255 00256 def ExitToolbars(self): 00257 if self.parent.GetToolbar('vdigit'): 00258 self.parent.toolbars['vdigit'].OnExit() 00259 if self.parent.GetLayerManager().IsPaneShown('toolbarNviz'): 00260 self.parent.RemoveNviz() 00261 00262 def Enable2D(self, enabled): 00263 """!Enable/Disable 2D display mode specific tools""" 00264 for tool in (self.zoomMenu, 00265 self.analyze, 00266 self.printMap): 00267 self.EnableTool(tool, enabled)