toolbars.py 51 KB

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