toolbars.py 51 KB

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