toolbars.py 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. """
  2. MODULE: toolbar
  3. CLASSES:
  4. * AbstractToolbar
  5. * MapToolbar
  6. * GRToolbar
  7. * GCPToolbar
  8. * VDigitToolbar
  9. * ProfileToolbar
  10. * NvizToolbar
  11. PURPOSE: Toolbars for Map Display window
  12. AUTHORS: The GRASS Development Team
  13. Michael Barton, Martin Landa, Jachym Cepicky
  14. COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
  15. This program is free software under the GNU General Public
  16. License (>=v2). Read the file COPYING that comes with GRASS
  17. for details.
  18. """
  19. import wx
  20. import os, sys
  21. import globalvar
  22. import gcmd
  23. import grassenv
  24. import gdialogs
  25. import vdigit
  26. from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
  27. from debug import Debug as Debug
  28. from icon import Icons as Icons
  29. from preferences import globalSettings as UserSettings
  30. gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
  31. sys.path.append(gmpath)
  32. class AbstractToolbar(object):
  33. """Abstract toolbar class"""
  34. def __init__():
  35. pass
  36. def InitToolbar(self, parent, toolbar, toolData):
  37. """Initialize toolbar, i.e. add tools to the toolbar
  38. @return list of ids (of added tools)
  39. """
  40. for tool in toolData:
  41. self.CreateTool(parent, toolbar, *tool)
  42. self._toolbar = toolbar
  43. self._data = toolData
  44. def ToolbarData(self):
  45. """Toolbar data"""
  46. return None
  47. def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
  48. shortHelp, longHelp, handler):
  49. """Add tool to the toolbar
  50. @return id of tool
  51. """
  52. bmpDisabled=wx.NullBitmap
  53. if label:
  54. toolWin = toolbar.AddLabelTool(tool, label, bitmap,
  55. bmpDisabled, kind,
  56. shortHelp, longHelp)
  57. parent.Bind(wx.EVT_TOOL, handler, toolWin)
  58. else: # add separator
  59. toolbar.AddSeparator()
  60. return tool
  61. def GetToolbar(self):
  62. """Get toolbar widget reference"""
  63. return self._toolbar
  64. def EnableLongHelp(self, enable=True):
  65. """Enable/disable long help
  66. @param enable True for enable otherwise disable
  67. """
  68. for tool in self._data:
  69. if tool[0] == '': # separator
  70. continue
  71. if enable:
  72. self._toolbar.SetToolLongHelp(tool[0], tool[5])
  73. else:
  74. self._toolbar.SetToolLongHelp(tool[0], "")
  75. class MapToolbar(AbstractToolbar):
  76. """
  77. Main Map Display toolbar
  78. """
  79. def __init__(self, mapdisplay, map):
  80. self.mapcontent = map
  81. self.mapdisplay = mapdisplay
  82. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  83. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  84. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  85. # optional tools
  86. self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value='Tools',
  87. choices=['Digitize', 'Nviz'], style=wx.CB_READONLY, size=(90, -1))
  88. self.comboid = self.toolbar.AddControl(self.combo)
  89. self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  90. # realize the toolbar
  91. self.toolbar.Realize()
  92. #workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  93. self.combo.Hide()
  94. self.combo.Show()
  95. def ToolbarData(self):
  96. """Toolbar data"""
  97. self.displaymap = wx.NewId()
  98. self.rendermap = wx.NewId()
  99. self.erase = wx.NewId()
  100. self.pointer = wx.NewId()
  101. self.query = wx.NewId()
  102. self.pan = wx.NewId()
  103. self.zoomin = wx.NewId()
  104. self.zoomout = wx.NewId()
  105. self.zoomback = wx.NewId()
  106. self.zoommenu = wx.NewId()
  107. self.analyze = wx.NewId()
  108. self.dec = wx.NewId()
  109. self.savefile = wx.NewId()
  110. self.printmap = wx.NewId()
  111. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  112. return (
  113. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  114. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  115. self.mapdisplay.OnDraw),
  116. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  117. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  118. self.mapdisplay.OnRender),
  119. (self.erase, "erase", Icons["erase"].GetBitmap(),
  120. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  121. self.mapdisplay.OnErase),
  122. ("", "", "", "", "", "", ""),
  123. (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
  124. wx.ITEM_RADIO, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
  125. self.mapdisplay.OnPointer),
  126. (self.query, "queryDisplay", Icons["queryDisplay"].GetBitmap(),
  127. wx.ITEM_RADIO, Icons["queryDisplay"].GetLabel(), Icons["queryDisplay"].GetDesc(),
  128. self.mapdisplay.OnQuery),
  129. (self.pan, "pan", Icons["pan"].GetBitmap(),
  130. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  131. self.mapdisplay.OnPan),
  132. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  133. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  134. self.mapdisplay.OnZoomIn),
  135. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  136. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  137. self.mapdisplay.OnZoomOut),
  138. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  139. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  140. self.mapdisplay.OnZoomBack),
  141. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  142. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  143. self.mapdisplay.OnZoomMenu),
  144. ("", "", "", "", "", "", ""),
  145. (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
  146. wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
  147. self.mapdisplay.OnAnalyze),
  148. ("", "", "", "", "", "", ""),
  149. (self.dec, "overlay", Icons["overlay"].GetBitmap(),
  150. wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
  151. self.mapdisplay.OnDecoration),
  152. ("", "", "", "", "", "", ""),
  153. (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
  154. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  155. self.mapdisplay.SaveToFile),
  156. (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
  157. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  158. self.mapdisplay.PrintMenu),
  159. ("", "", "", "", "", "", "")
  160. )
  161. def OnSelectTool(self, event):
  162. """
  163. Select / enable tool available in tools list
  164. """
  165. tool = event.GetString()
  166. if tool == "Digitize" and not self.mapdisplay.toolbars['vdigit']:
  167. self.mapdisplay.AddToolbar("vdigit")
  168. elif tool == "Nviz" and not self.mapdisplay.toolbars['nviz']:
  169. self.mapdisplay.AddToolbar("nviz")
  170. def Enable2D(self, enabled):
  171. """Enable/Disable 2D display mode specific tools"""
  172. for tool in (self.pointer,
  173. self.query,
  174. self.pan,
  175. self.zoomin,
  176. self.zoomout,
  177. self.zoomback,
  178. self.zoommenu,
  179. self.analyze,
  180. self.dec,
  181. self.savefile,
  182. self.printmap):
  183. self.toolbar.EnableTool(tool, enabled)
  184. class GRToolbar(AbstractToolbar):
  185. """
  186. Georectification Display toolbar
  187. """
  188. def __init__(self, mapdisplay, map):
  189. self.mapcontent = map
  190. self.mapdisplay = mapdisplay
  191. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  192. # self.SetToolBar(self.toolbar)
  193. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  194. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  195. # realize the toolbar
  196. self.toolbar.Realize()
  197. def ToolbarData(self):
  198. """Toolbar data"""
  199. self.displaymap = wx.NewId()
  200. self.rendermap = wx.NewId()
  201. self.erase = wx.NewId()
  202. self.gcpset = wx.NewId()
  203. self.pan = wx.NewId()
  204. self.zoomin = wx.NewId()
  205. self.zoomout = wx.NewId()
  206. self.zoomback = wx.NewId()
  207. self.zoommenu = wx.NewId()
  208. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  209. return (
  210. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  211. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  212. self.mapdisplay.OnDraw),
  213. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  214. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  215. self.mapdisplay.OnRender),
  216. (self.erase, "erase", Icons["erase"].GetBitmap(),
  217. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  218. self.mapdisplay.OnErase),
  219. ("", "", "", "", "", "", ""),
  220. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  221. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  222. self.mapdisplay.OnPointer),
  223. (self.pan, "pan", Icons["pan"].GetBitmap(),
  224. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  225. self.mapdisplay.OnPan),
  226. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  227. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  228. self.mapdisplay.OnZoomIn),
  229. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  230. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  231. self.mapdisplay.OnZoomOut),
  232. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  233. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  234. self.mapdisplay.OnZoomBack),
  235. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  236. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  237. self.mapdisplay.OnZoomMenu),
  238. ("", "", "", "", "", "", ""),
  239. )
  240. class GCPToolbar(AbstractToolbar):
  241. """
  242. Toolbar for managing ground control points during georectification
  243. """
  244. def __init__(self, parent, tbframe):
  245. self.parent = parent # GCP
  246. self.tbframe = tbframe
  247. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  248. # self.SetToolBar(self.toolbar)
  249. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  250. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  251. # realize the toolbar
  252. self.toolbar.Realize()
  253. def ToolbarData(self):
  254. self.gcpSave = wx.NewId()
  255. self.gcpAdd = wx.NewId()
  256. self.gcpDelete = wx.NewId()
  257. self.gcpClear = wx.NewId()
  258. self.gcpReload = wx.NewId()
  259. self.rms = wx.NewId()
  260. self.georect = wx.NewId()
  261. self.settings = wx.NewId()
  262. self.quit = wx.NewId()
  263. return (
  264. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  265. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  266. self.parent.SaveGCPs),
  267. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  268. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  269. self.parent.AddGCP),
  270. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  271. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  272. self.parent.DeleteGCP),
  273. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  274. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  275. self.parent.ClearGCP),
  276. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  277. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  278. self.parent.ReloadGCPs),
  279. ("", "", "", "", "", "", ""),
  280. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  281. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  282. self.parent.OnRMS),
  283. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  284. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  285. self.parent.OnGeorect),
  286. ("", "", "", "", "", "", ""),
  287. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  288. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  289. self.parent.OnSettings),
  290. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  291. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  292. self.parent.OnQuit)
  293. )
  294. class VDigitToolbar(AbstractToolbar):
  295. """
  296. Toolbar for digitization
  297. """
  298. def __init__(self, parent, map, layerTree=None, log=None):
  299. self.mapcontent = map # Map class instance
  300. self.parent = parent # MapFrame
  301. self.layerTree = layerTree # reference to layer tree associated to map display
  302. self.log = log # log area
  303. # currently selected map layer for editing (reference to MapLayer instance)
  304. self.mapLayer = None
  305. # list of vector layers from Layer Manager (only in the current mapset)
  306. self.layers = []
  307. self.comboid = None
  308. # only one dialog can be open
  309. self.settingsDialog = None
  310. # create toolbars (two rows optionaly)
  311. self.toolbar = []
  312. self.numOfRows = 1 # number of rows for toolbar
  313. for row in range(0, self.numOfRows):
  314. self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
  315. self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
  316. self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
  317. # create toolbar
  318. if self.numOfRows == 1:
  319. rowdata=None
  320. else:
  321. rowdata = row
  322. self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
  323. # default action (digitize new point, line, etc.)
  324. self.action = { 'desc' : 'addLine',
  325. 'type' : 'point',
  326. 'id' : self.addPoint }
  327. # list of available vector maps
  328. self.UpdateListOfLayers(updateTool=True)
  329. # realize toolbar
  330. for row in range(0, self.numOfRows):
  331. self.toolbar[row].Realize()
  332. # disable undo/redo
  333. self.toolbar[0].EnableTool(self.undo, False)
  334. # toogle to pointer by default
  335. self.OnTool(None)
  336. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  337. self.toolbar[0].EnableTool(self.copyCats, False) # not implemented (TODO)
  338. self.toolbar[0].SetToolShortHelp(self.copyCats, _("Not implemented yet"))
  339. def ToolbarData(self, row=None):
  340. """
  341. Toolbar data
  342. """
  343. data = []
  344. if row is None or row == 0:
  345. self.addPoint = wx.NewId()
  346. self.addLine = wx.NewId()
  347. self.addBoundary = wx.NewId()
  348. self.addCentroid = wx.NewId()
  349. self.moveVertex = wx.NewId()
  350. self.addVertex = wx.NewId()
  351. self.removeVertex = wx.NewId()
  352. self.splitLine = wx.NewId()
  353. self.editLine = wx.NewId()
  354. self.moveLine = wx.NewId()
  355. self.deleteLine = wx.NewId()
  356. self.additionalTools = wx.NewId()
  357. self.displayCats = wx.NewId()
  358. self.displayAttr = wx.NewId()
  359. self.copyCats = wx.NewId()
  360. data = [("", "", "", "", "", "", ""),
  361. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  362. wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  363. self.OnAddPoint),
  364. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  365. wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  366. self.OnAddLine),
  367. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  368. wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  369. self.OnAddBoundary),
  370. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  371. wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  372. self.OnAddCentroid),
  373. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  374. wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  375. self.OnMoveVertex),
  376. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  377. wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  378. self.OnAddVertex),
  379. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  380. wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  381. self.OnRemoveVertex),
  382. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  383. wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  384. self.OnSplitLine),
  385. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  386. wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  387. self.OnEditLine),
  388. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  389. wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  390. self.OnMoveLine),
  391. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  392. wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  393. self.OnDeleteLine),
  394. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  395. wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  396. self.OnDisplayCats),
  397. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  398. wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  399. self.OnCopyCats),
  400. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  401. wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  402. self.OnDisplayAttr),
  403. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  404. wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
  405. Icons["digAdditionalTools"].GetDesc(),
  406. self.OnAdditionalToolMenu)]
  407. if row is None or row == 1:
  408. self.undo = wx.NewId()
  409. self.settings = wx.NewId()
  410. self.exit = wx.NewId()
  411. data.append(("", "", "", "", "", "", ""))
  412. data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  413. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  414. self.OnUndo))
  415. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  416. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  417. # self.OnRedo))
  418. data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  419. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  420. self.OnSettings))
  421. data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
  422. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  423. self.OnExit))
  424. return data
  425. def OnTool(self, event):
  426. """Tool selected -> toggle tool to pointer"""
  427. id = self.parent.toolbars['map'].pointer
  428. self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
  429. self.parent.toolbars['map'].mapdisplay.OnPointer(event)
  430. if event:
  431. # deselect previously selected tool
  432. if self.action.has_key('id'):
  433. self.toolbar[0].ToggleTool(self.action['id'], False)
  434. self.action['id'] = event.GetId()
  435. event.Skip()
  436. else:
  437. # initialize toolbar
  438. self.toolbar[0].ToggleTool(self.action['id'], True)
  439. def OnAddPoint(self, event):
  440. """Add point to the vector map Laier"""
  441. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  442. self.action = { 'desc' : "addLine",
  443. 'type' : "point",
  444. 'id' : self.addPoint }
  445. self.parent.MapWindow.mouse['box'] = 'point'
  446. def OnAddLine(self, event):
  447. """Add line to the vector map layer"""
  448. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  449. self.action = { 'desc' : "addLine",
  450. 'type' : "line",
  451. 'id' : self.addLine }
  452. self.parent.MapWindow.mouse['box'] = 'line'
  453. self.parent.MapWindow.polycoords = [] # reset temp line
  454. def OnAddBoundary(self, event):
  455. """Add boundary to the vector map layer"""
  456. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  457. self.action = { 'desc' : "addLine",
  458. 'type' : "boundary",
  459. 'id' : self.addBoundary }
  460. self.parent.MapWindow.mouse['box'] = 'line'
  461. self.parent.MapWindow.polycoords = [] # reset temp line
  462. def OnAddCentroid(self, event):
  463. """Add centroid to the vector map layer"""
  464. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  465. self.action = { 'desc' : "addLine",
  466. 'type' : "centroid",
  467. 'id' : self.addCentroid }
  468. self.parent.MapWindow.mouse['box'] = 'point'
  469. def OnExit (self, event=None):
  470. """Quit digitization tool"""
  471. # stop editing of the currently selected map layer
  472. if self.mapLayer:
  473. self.StopEditing()
  474. # close dialogs if still open
  475. if self.settingsDialog:
  476. self.settingsDialog.OnCancel(None)
  477. if self.parent.dialogs['category']:
  478. self.parent.dialogs['category'].OnCancel(None)
  479. if self.parent.dialogs['attributes']:
  480. self.parent.dialogs['attributes'].OnCancel(None)
  481. # disable the toolbar
  482. self.parent.RemoveToolbar ("vdigit")
  483. def OnMoveVertex(self, event):
  484. """Move line vertex"""
  485. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  486. self.action = { 'desc' : "moveVertex",
  487. 'id' : self.moveVertex }
  488. self.parent.MapWindow.mouse['box'] = 'point'
  489. def OnAddVertex(self, event):
  490. """Add line vertex"""
  491. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  492. self.action = { 'desc' : "addVertex",
  493. 'id' : self.addVertex }
  494. self.parent.MapWindow.mouse['box'] = 'point'
  495. def OnRemoveVertex(self, event):
  496. """Remove line vertex"""
  497. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  498. self.action = { 'desc' : "removeVertex",
  499. 'id' : self.removeVertex }
  500. self.parent.MapWindow.mouse['box'] = 'point'
  501. def OnSplitLine(self, event):
  502. """Split line"""
  503. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  504. self.action = { 'desc' : "splitLine",
  505. 'id' : self.splitLine }
  506. self.parent.MapWindow.mouse['box'] = 'point'
  507. def OnEditLine(self, event):
  508. """Edit line"""
  509. Debug.msg(2, "Digittoolbar.OnEditLine():")
  510. self.action = { 'desc' : "editLine",
  511. 'id' : self.editLine }
  512. self.parent.MapWindow.mouse['box'] = 'line'
  513. def OnMoveLine(self, event):
  514. """Move line"""
  515. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  516. self.action = { 'desc' : "moveLine",
  517. 'id' : self.moveLine }
  518. self.parent.MapWindow.mouse['box'] = 'box'
  519. def OnDeleteLine(self, event):
  520. """Delete line"""
  521. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  522. self.action = { 'desc' : "deleteLine",
  523. 'id' : self.deleteLine }
  524. self.parent.MapWindow.mouse['box'] = 'box'
  525. def OnDisplayCats(self, event):
  526. """Display/update categories"""
  527. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  528. self.action = { 'desc' : "displayCats",
  529. 'id' : self.displayCats }
  530. self.parent.MapWindow.mouse['box'] = 'point'
  531. def OnDisplayAttr(self, event):
  532. """Display/update attributes"""
  533. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  534. self.action = { 'desc' : "displayAttrs",
  535. 'id' : self.displayAttr }
  536. self.parent.MapWindow.mouse['box'] = 'point'
  537. def OnCopyCats(self, event):
  538. """Copy categories"""
  539. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  540. self.action = { 'desc' : "copyCats",
  541. 'id' : self.copyCats }
  542. self.parent.MapWindow.mouse['box'] = 'point'
  543. def OnUndo(self, event):
  544. """Undo previous changes"""
  545. self.parent.digit.Undo()
  546. event.Skip()
  547. def EnableUndo(self, enable=True):
  548. """Enable 'Undo' in toolbar
  549. @param enable False for disable
  550. """
  551. ### fix undo first...
  552. # if enable:
  553. # if self.toolbar[0].GetToolEnabled(self.undo) is False:
  554. # self.toolbar[0].EnableTool(self.undo, True)
  555. # else:
  556. # if self.toolbar[0].GetToolEnabled(self.undo) is True:
  557. # self.toolbar[0].EnableTool(self.undo, False)
  558. pass
  559. def OnSettings(self, event):
  560. """Show settings dialog"""
  561. if self.parent.digit is None:
  562. reload(vdigit)
  563. from vdigit import Digit as Digit
  564. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  565. if not self.settingsDialog:
  566. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  567. style=wx.DEFAULT_DIALOG_STYLE)
  568. self.settingsDialog.Show()
  569. def OnAdditionalToolMenu(self, event):
  570. """Menu for additional tools"""
  571. point = wx.GetMousePosition()
  572. toolMenu = wx.Menu()
  573. # Add items to the menu
  574. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  575. text=_('Copy features from (background) vector map'),
  576. kind=wx.ITEM_CHECK)
  577. toolMenu.AppendItem(copy)
  578. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  579. if self.action['desc'] == "copyLine":
  580. copy.Check(True)
  581. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  582. text=_('Flip selected lines/boundaries'),
  583. kind=wx.ITEM_CHECK)
  584. toolMenu.AppendItem(flip)
  585. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  586. if self.action['desc'] == "flipLine":
  587. flip.Check(True)
  588. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  589. text=_('Merge selected lines/boundaries'),
  590. kind=wx.ITEM_CHECK)
  591. toolMenu.AppendItem(merge)
  592. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  593. if self.action['desc'] == "mergeLine":
  594. merge.Check(True)
  595. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  596. text=_('Break selected lines/boundaries at intersection'),
  597. kind=wx.ITEM_CHECK)
  598. toolMenu.AppendItem(breakL)
  599. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  600. if self.action['desc'] == "breakLine":
  601. breakL.Check(True)
  602. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  603. text=_('Snap selected lines/boundaries (only to nodes)'),
  604. kind=wx.ITEM_CHECK)
  605. toolMenu.AppendItem(snap)
  606. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  607. if self.action['desc'] == "snapLine":
  608. snap.Check(True)
  609. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  610. text=_('Connect selected lines/boundaries'),
  611. kind=wx.ITEM_CHECK)
  612. toolMenu.AppendItem(connect)
  613. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  614. if self.action['desc'] == "connectLine":
  615. connect.Check(True)
  616. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  617. text=_('Query features'),
  618. kind=wx.ITEM_CHECK)
  619. toolMenu.AppendItem(query)
  620. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  621. if self.action['desc'] == "queryLine":
  622. query.Check(True)
  623. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  624. text=_('Z bulk-labeling of 3D lines'),
  625. kind=wx.ITEM_CHECK)
  626. toolMenu.AppendItem(zbulk)
  627. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  628. if self.action['desc'] == "zbulkLine":
  629. zbulk.Check(True)
  630. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  631. text=_('Feature type conversion'),
  632. kind=wx.ITEM_CHECK)
  633. toolMenu.AppendItem(typeconv)
  634. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  635. if self.action['desc'] == "typeConv":
  636. typeconv.Check(True)
  637. # Popup the menu. If an item is selected then its handler
  638. # will be called before PopupMenu returns.
  639. self.parent.MapWindow.PopupMenu(toolMenu)
  640. toolMenu.Destroy()
  641. if self.action['desc'] == 'addPoint':
  642. self.toolbar[0].ToggleTool(self.additionalTools, True)
  643. def OnCopy(self, event):
  644. """Copy selected features from (background) vector map"""
  645. if self.action['desc'] == 'copyLine': # select previous action
  646. self.toolbar[0].ToggleTool(self.addPoint, True)
  647. self.OnAddPoint(event)
  648. return
  649. Debug.msg(2, "Digittoolbar.OnCopy():")
  650. self.action = { 'desc' : "copyLine",
  651. 'id' : self.additionalTools }
  652. self.parent.MapWindow.mouse['box'] = 'box'
  653. def OnFlip(self, event):
  654. """Flip selected lines/boundaries"""
  655. if self.action['desc'] == 'flipLine': # select previous action
  656. self.toolbar[0].ToggleTool(self.addPoint, True)
  657. self.OnAddPoint(event)
  658. return
  659. Debug.msg(2, "Digittoolbar.OnFlip():")
  660. self.action = { 'desc' : "flipLine",
  661. 'id' : self.additionalTools }
  662. self.parent.MapWindow.mouse['box'] = 'box'
  663. def OnMerge(self, event):
  664. """Merge selected lines/boundaries"""
  665. if self.action['desc'] == 'mergeLine': # select previous action
  666. self.toolbar[0].ToggleTool(self.addPoint, True)
  667. self.OnAddPoint(event)
  668. return
  669. Debug.msg(2, "Digittoolbar.OnMerge():")
  670. self.action = { 'desc' : "mergeLine",
  671. 'id' : self.additionalTools }
  672. self.parent.MapWindow.mouse['box'] = 'box'
  673. def OnBreak(self, event):
  674. """Break selected lines/boundaries"""
  675. if self.action['desc'] == 'breakLine': # select previous action
  676. self.toolbar[0].ToggleTool(self.addPoint, True)
  677. self.OnAddPoint(event)
  678. return
  679. Debug.msg(2, "Digittoolbar.OnBreak():")
  680. self.action = { 'desc' : "breakLine",
  681. 'id' : self.additionalTools }
  682. self.parent.MapWindow.mouse['box'] = 'box'
  683. def OnSnap(self, event):
  684. """Snap selected features"""
  685. if self.action['desc'] == 'snapLine': # select previous action
  686. self.toolbar[0].ToggleTool(self.addPoint, True)
  687. self.OnAddPoint(event)
  688. return
  689. Debug.msg(2, "Digittoolbar.OnSnap():")
  690. self.action = { 'desc' : "snapLine",
  691. 'id' : self.additionalTools }
  692. self.parent.MapWindow.mouse['box'] = 'box'
  693. def OnConnect(self, event):
  694. """Connect selected lines/boundaries"""
  695. if self.action['desc'] == 'connectLine': # select previous action
  696. self.toolbar[0].ToggleTool(self.addPoint, True)
  697. self.OnAddPoint(event)
  698. return
  699. Debug.msg(2, "Digittoolbar.OnConnect():")
  700. self.action = { 'desc' : "connectLine",
  701. 'id' : self.additionalTools }
  702. self.parent.MapWindow.mouse['box'] = 'box'
  703. def OnQuery(self, event):
  704. """Query selected lines/boundaries"""
  705. if self.action['desc'] == 'queryLine': # select previous action
  706. self.toolbar[0].ToggleTool(self.addPoint, True)
  707. self.OnAddPoint(event)
  708. return
  709. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  710. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  711. self.action = { 'desc' : "queryLine",
  712. 'id' : self.additionalTools }
  713. self.parent.MapWindow.mouse['box'] = 'box'
  714. def OnZBulk(self, event):
  715. """Z bulk-labeling selected lines/boundaries"""
  716. if self.action['desc'] == 'zbulkLine': # select previous action
  717. self.toolbar[0].ToggleTool(self.addPoint, True)
  718. self.OnAddPoint(event)
  719. return
  720. Debug.msg(2, "Digittoolbar.OnZBulk():")
  721. self.action = { 'desc' : "zbulkLine",
  722. 'id' : self.additionalTools }
  723. self.parent.MapWindow.mouse['box'] = 'line'
  724. def OnTypeConversion(self, event):
  725. """Feature type conversion
  726. Supported conversions:
  727. - point <-> centroid
  728. - line <-> boundary
  729. """
  730. if self.action['desc'] == 'typeConv': # select previous action
  731. self.toolbar[0].ToggleTool(self.addPoint, True)
  732. self.OnAddPoint(event)
  733. return
  734. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  735. self.action = { 'desc' : "typeConv",
  736. 'id' : self.additionalTools }
  737. self.parent.MapWindow.mouse['box'] = 'box'
  738. def OnSelectMap (self, event):
  739. """
  740. Select vector map layer for editing
  741. If there is a vector map layer already edited, this action is
  742. firstly terminated. The map layer is closed. After this the
  743. selected map layer activated for editing.
  744. """
  745. if event.GetSelection() == 0: # create new vector map layer
  746. if self.mapLayer:
  747. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  748. else:
  749. openVectorMap = None
  750. mapName = gdialogs.CreateNewVector(self.parent,
  751. exceptMap=openVectorMap, log=self.log,
  752. cmdDef=(['v.edit', 'tool=create'], "map"))
  753. if mapName:
  754. # add layer to map layer tree
  755. if self.layerTree:
  756. self.layerTree.AddLayer(ltype='vector',
  757. lname=mapName,
  758. lchecked=True,
  759. lopacity=1.0,
  760. lcmd=['d.vect', 'map=%s' % mapName])
  761. vectLayers = self.UpdateListOfLayers(updateTool=True)
  762. selection = vectLayers.index(mapName)
  763. else:
  764. pass # TODO (no Layer Manager)
  765. else:
  766. self.combo.SetValue(_('Select vector map'))
  767. return
  768. else:
  769. selection = event.GetSelection() - 1 # first option is 'New vector map'
  770. # skip currently selected map
  771. if self.layers[selection] == self.mapLayer:
  772. return False
  773. if self.mapLayer:
  774. # deactive map layer for editing
  775. self.StopEditing()
  776. # select the given map layer for editing
  777. self.StartEditing(self.layers[selection])
  778. event.Skip()
  779. return True
  780. def StartEditing (self, mapLayer):
  781. """
  782. Start editing selected vector map layer.
  783. @param mapLayer reference to MapLayer instance
  784. """
  785. # reload vdigit module
  786. reload(vdigit)
  787. from vdigit import Digit as Digit
  788. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  789. self.mapLayer = mapLayer
  790. # open vector map
  791. try:
  792. self.parent.digit.SetMapName(mapLayer.GetName())
  793. except gcmd.DigitError, e:
  794. self.mapLayer = None
  795. print >> sys.stderr, e # wxMessageBox
  796. return False
  797. # update toolbar
  798. self.combo.SetValue(mapLayer.GetName())
  799. self.parent.toolbars['map'].combo.SetValue ('Digitize')
  800. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  801. # deactive layer
  802. self.mapcontent.ChangeLayerActive(mapLayer, False)
  803. # change cursor
  804. if self.parent.MapWindow.mouse['use'] == 'pointer':
  805. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  806. # create pseudoDC for drawing the map
  807. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  808. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  809. # self.parent.MapWindow.UpdateMap()
  810. if not self.parent.MapWindow.resize:
  811. self.parent.MapWindow.UpdateMap(render=True)
  812. return True
  813. def StopEditing (self):
  814. """Stop editing of selected vector map layer.
  815. @return True on success
  816. @return False on failure
  817. """
  818. if not self.mapLayer:
  819. return False
  820. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  821. self.combo.SetValue (_('Select vector map'))
  822. # save changes (only for vdigit)
  823. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  824. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  825. if self.parent.digit.GetUndoLevel() > 0:
  826. dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
  827. "in vector map <%s>?") % self.mapLayer.GetName(),
  828. caption=_("Save changes?"),
  829. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  830. if dlg.ShowModal() == wx.ID_NO:
  831. # revert changes
  832. self.parent.digit.Undo(0)
  833. dlg.Destroy()
  834. self.parent.digit.SetMapName(None) # -> close map
  835. # re-active layer
  836. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  837. if item and self.parent.tree.IsItemChecked(item):
  838. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  839. # change cursor
  840. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  841. # disable pseudodc for vector map layer
  842. self.parent.MapWindow.pdcVector = None
  843. self.parent.digit.driver.SetDevice(None)
  844. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  845. self.parent.digit = None
  846. self.mapLayer = None
  847. return True
  848. def UpdateListOfLayers (self, updateTool=False):
  849. """
  850. Update list of available vector map layers.
  851. This list consists only editable layers (in the current mapset)
  852. Optionaly also update toolbar
  853. """
  854. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  855. updateTool)
  856. layerNameSelected = None
  857. # name of currently selected layer
  858. if self.mapLayer:
  859. layerNameSelected = self.mapLayer.GetName()
  860. # select vector map layer in the current mapset
  861. layerNameList = []
  862. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  863. l_mapset=grassenv.GetGRASSVariable('MAPSET'))
  864. for layer in self.layers:
  865. if not layer.name in layerNameList: # do not duplicate layer
  866. layerNameList.append (layer.GetName())
  867. if updateTool: # update toolbar
  868. if not self.mapLayer:
  869. value = _('Select vector map')
  870. else:
  871. value = layerNameSelected
  872. if not self.comboid:
  873. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  874. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  875. style=wx.CB_READONLY)
  876. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  877. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  878. else:
  879. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  880. self.toolbar[self.numOfRows-1].Realize()
  881. return layerNameList
  882. def GetLayer(self):
  883. """Get selected layer for editing -- MapLayer instance"""
  884. return self.mapLayer
  885. def GetAction(self, type='desc'):
  886. """Get current action info"""
  887. return self.action[type]
  888. class ProfileToolbar(AbstractToolbar):
  889. """
  890. Toolbar for profiling raster map
  891. """
  892. def __init__(self, parent, mapdisplay, map):
  893. self.parent = parent
  894. self.mapcontent = map
  895. self.mapdisplay = mapdisplay
  896. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  897. # self.SetToolBar(self.toolbar)
  898. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  899. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  900. # realize the toolbar
  901. self.toolbar.Realize()
  902. def ToolbarData(self):
  903. """Toolbar data"""
  904. self.transect = wx.NewId()
  905. self.addraster = wx.NewId()
  906. self.draw = wx.NewId()
  907. self.options = wx.NewId()
  908. self.drag = wx.NewId()
  909. self.zoom = wx.NewId()
  910. self.unzoom = wx.NewId()
  911. self.erase = wx.NewId()
  912. self.save = wx.NewId()
  913. self.printer = wx.NewId()
  914. self.quit = wx.NewId()
  915. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  916. return (
  917. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  918. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  919. self.parent.OnDrawTransect),
  920. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  921. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  922. self.parent.OnSelectRaster),
  923. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  924. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  925. self.parent.OnCreateProfile),
  926. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  927. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  928. self.parent.ProfileOptionsMenu),
  929. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  930. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  931. self.parent.OnDrag),
  932. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  933. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  934. self.parent.OnZoom),
  935. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  936. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  937. self.parent.OnRedraw),
  938. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  939. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  940. self.parent.OnErase),
  941. ("", "", "", "", "", "", ""),
  942. (self.save, 'save', Icons["savefile"].GetBitmap(),
  943. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  944. self.parent.SaveToFile),
  945. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  946. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  947. self.parent.PrintMenu),
  948. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  949. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  950. self.parent.OnQuit),
  951. )
  952. class NvizToolbar(AbstractToolbar):
  953. """
  954. Nviz toolbar
  955. """
  956. def __init__(self, parent, map):
  957. self.parent = parent
  958. self.mapcontent = map
  959. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  960. # self.SetToolBar(self.toolbar)
  961. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  962. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  963. # realize the toolbar
  964. self.toolbar.Realize()
  965. def ToolbarData(self):
  966. """Toolbar data"""
  967. self.settings = wx.NewId()
  968. self.quit = wx.NewId()
  969. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  970. return (
  971. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  972. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  973. self.OnSettings),
  974. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  975. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  976. self.OnExit),
  977. )
  978. def OnSettings(self, event):
  979. win = self.parent.nvizToolWin
  980. if not win.IsShown():
  981. self.parent.nvizToolWin.Show()
  982. else:
  983. self.parent.nvizToolWin.Hide()
  984. def OnExit (self, event=None):
  985. """Quit nviz tool (swith to 2D mode)"""
  986. # disable the toolbar
  987. self.parent.RemoveToolbar ("nviz")