toolbars.py 54 KB

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