toolbars.py 56 KB

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