toolbars.py 55 KB

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