toolbars.py 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. """!
  2. @package toolbar
  3. @brief wxGUI toolbar widgets
  4. Classes:
  5. - AbstractToolbar
  6. - MapToolbar
  7. - GCPMapToolbar
  8. - GCPDisplayToolbar
  9. - VDigitToolbar
  10. - ProfileToolbar
  11. - NvizToolbar
  12. - ModelToolbar
  13. - HistogramToolbar
  14. - LayerManagerToolbar
  15. - ToolsToolbar
  16. - PsMapToolbar
  17. (C) 2007-2011 by the GRASS Development Team
  18. This program is free software under the GNU General Public License
  19. (>=v2). Read the file COPYING that comes with GRASS for details.
  20. @author Michael Barton
  21. @author Jachym Cepicky
  22. @author Martin Landa <landa.martin gmail.com>
  23. @author Anna Kratochvilova <anna.kratochvilova fsv.cvut.cz>
  24. """
  25. import os
  26. import sys
  27. import platform
  28. from grass.script import core as grass
  29. import wx
  30. import globalvar
  31. import gcmd
  32. import gdialogs
  33. from vdigit import VDigitSettingsDialog, haveVDigit, VDigit
  34. from debug import Debug
  35. from preferences import globalSettings as UserSettings
  36. from nviz import haveNviz
  37. from nviz_preferences import NvizPreferencesDialog
  38. sys.path.append(os.path.join(globalvar.ETCWXDIR, "icons"))
  39. from icon import Icons
  40. class AbstractToolbar(wx.ToolBar):
  41. """!Abstract toolbar class"""
  42. def __init__(self, parent):
  43. self.parent = parent
  44. wx.ToolBar.__init__(self, parent = self.parent, id = wx.ID_ANY)
  45. self.action = dict()
  46. self.Bind(wx.EVT_TOOL, self.OnTool)
  47. self.SetToolBitmapSize(globalvar.toolbarSize)
  48. def InitToolbar(self, toolData):
  49. """!Initialize toolbar, add tools to the toolbar
  50. """
  51. for tool in toolData:
  52. self.CreateTool(*tool)
  53. self._data = toolData
  54. def _toolbarData(self):
  55. """!Toolbar data (virtual)"""
  56. return None
  57. def CreateTool(self, tool, label, bitmap, kind,
  58. shortHelp, longHelp, handler):
  59. """!Add tool to the toolbar
  60. @return id of tool
  61. """
  62. bmpDisabled = wx.NullBitmap
  63. if label:
  64. Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
  65. (tool, label, bitmap))
  66. toolWin = self.AddLabelTool(tool, label, bitmap,
  67. bmpDisabled, kind,
  68. shortHelp, longHelp)
  69. self.Bind(wx.EVT_TOOL, handler, toolWin)
  70. else: # separator
  71. self.AddSeparator()
  72. return tool
  73. def EnableLongHelp(self, enable = True):
  74. """!Enable/disable long help
  75. @param enable True for enable otherwise disable
  76. """
  77. for tool in self._data:
  78. if tool[0] == '': # separator
  79. continue
  80. if enable:
  81. self.SetToolLongHelp(tool[0], tool[5])
  82. else:
  83. self.SetToolLongHelp(tool[0], "")
  84. def OnTool(self, event):
  85. """!Tool selected
  86. """
  87. if self.parent.GetName() == "GCPFrame":
  88. return
  89. if hasattr(self.parent, 'toolbars'):
  90. if self.parent.toolbars['vdigit']:
  91. # update vdigit toolbar (unselect currently selected tool)
  92. id = self.parent.toolbars['vdigit'].GetAction(type = 'id')
  93. self.parent.toolbars['vdigit'].ToggleTool(id, False)
  94. if event:
  95. # deselect previously selected tool
  96. id = self.action.get('id', -1)
  97. if id != event.GetId():
  98. self.ToggleTool(self.action['id'], False)
  99. else:
  100. self.ToggleTool(self.action['id'], True)
  101. self.action['id'] = event.GetId()
  102. event.Skip()
  103. else:
  104. # initialize toolbar
  105. self.ToggleTool(self.action['id'], True)
  106. def GetAction(self, type = 'desc'):
  107. """!Get current action info"""
  108. return self.action.get(type, '')
  109. def SelectDefault(self, event):
  110. """!Select default tool"""
  111. self.ToggleTool(self.defaultAction['id'], True)
  112. self.defaultAction['bind'](event)
  113. self.action = { 'id' : self.defaultAction['id'],
  114. 'desc' : self.defaultAction.get('desc', '') }
  115. def FixSize(self, width):
  116. """!Fix toolbar width on Windows
  117. @todo Determine why combobox causes problems here
  118. """
  119. if platform.system() == 'Windows':
  120. size = self.GetBestSize()
  121. self.SetSize((size[0] + width, size[1]))
  122. def Enable(self, tool, enable = True):
  123. """!Enable defined tool
  124. @param tool name
  125. @param enable True to enable otherwise disable tool
  126. """
  127. try:
  128. id = getattr(self, tool)
  129. except AttributeError:
  130. return
  131. self.EnableTool(id, enable)
  132. def _getToolbarData(self, data):
  133. """!Define tool
  134. """
  135. retData = list()
  136. for args in data:
  137. retData.append(self._defineTool(*args))
  138. return retData
  139. def _defineTool(self, key, name = None, icon = None, handler = None, item = wx.ITEM_NORMAL):
  140. """!Define tool
  141. """
  142. if key:
  143. return (key, name, icon.GetBitmap(),
  144. item, icon.GetLabel(), icon.GetDesc(),
  145. handler)
  146. return ("", "", "", "", "", "", "") # separator
  147. class MapToolbar(AbstractToolbar):
  148. """!Map Display toolbar
  149. """
  150. def __init__(self, parent, mapcontent):
  151. """!Map Display constructor
  152. @param parent reference to MapFrame
  153. @param mapcontent reference to render.Map (registred by MapFrame)
  154. """
  155. self.mapcontent = mapcontent # render.Map
  156. AbstractToolbar.__init__(self, parent = parent) # MapFrame
  157. self.InitToolbar(self._toolbarData())
  158. # optional tools
  159. choices = [ _('2D view'), ]
  160. self.toolId = { '2d' : 0 }
  161. if self.parent.GetLayerManager():
  162. log = self.parent.GetLayerManager().GetLogWindow()
  163. if haveNviz:
  164. if not self.parent.GetLayerManager().existNviz:
  165. choices.append(_('3D view'))
  166. self.toolId['3d'] = 1
  167. else:
  168. self.toolId['3d'] = -1
  169. else:
  170. from nviz import errorMsg
  171. log.WriteCmdLog(_('3D view mode not available'))
  172. log.WriteWarning(_('Reason: %s') % str(errorMsg))
  173. log.WriteLog(_('Note that the wxGUI\'s 3D view mode is currently disabled '
  174. 'on MS Windows (hopefully this will be fixed soon). '
  175. 'Please keep an eye out for updated versions of GRASS. '
  176. 'In the meantime you can use "NVIZ" from the File menu.'), wrap = 60)
  177. self.toolId['3d'] = -1
  178. if haveVDigit:
  179. choices.append(_('Digitize'))
  180. if self.toolId['3d'] > -1:
  181. self.toolId['vdigit'] = 2
  182. else:
  183. self.toolId['vdigit'] = 1
  184. else:
  185. from vdigit import errorMsg
  186. log.WriteCmdLog(_('Vector digitizer not available'))
  187. log.WriteWarning(_('Reason: %s') % errorMsg)
  188. log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled '
  189. '(hopefully this will be fixed soon). '
  190. 'Please keep an eye out for updated versions of GRASS. '
  191. 'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60)
  192. self.toolId['vdigit'] = -1
  193. self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
  194. choices = choices,
  195. style = wx.CB_READONLY, size = (90, -1))
  196. self.combo.SetSelection(0)
  197. self.comboid = self.AddControl(self.combo)
  198. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  199. # realize the toolbar
  200. self.Realize()
  201. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  202. self.combo.Hide()
  203. self.combo.Show()
  204. self.action = { 'id' : self.pointer }
  205. self.defaultAction = { 'id' : self.pointer,
  206. 'bind' : self.parent.OnPointer }
  207. self.OnTool(None)
  208. self.EnableTool(self.zoomback, False)
  209. self.FixSize(width = 90)
  210. def _toolbarData(self):
  211. """!Toolbar data"""
  212. self.displaymap = wx.NewId()
  213. self.rendermap = wx.NewId()
  214. self.erase = wx.NewId()
  215. self.pointer = wx.NewId()
  216. self.query = wx.NewId()
  217. self.pan = wx.NewId()
  218. self.zoomin = wx.NewId()
  219. self.zoomout = wx.NewId()
  220. self.zoomback = wx.NewId()
  221. self.zoommenu = wx.NewId()
  222. self.zoomextent = wx.NewId()
  223. self.analyze = wx.NewId()
  224. self.dec = wx.NewId()
  225. self.savefile = wx.NewId()
  226. self.printmap = wx.NewId()
  227. icons = Icons['displayWindow']
  228. return self._getToolbarData(((self.displaymap, 'display', icons['display'],
  229. self.parent.OnDraw),
  230. (self.rendermap, 'render', icons['render'],
  231. self.parent.OnRender),
  232. (self.erase, 'erase', icons['erase'],
  233. self.parent.OnErase),
  234. (None, ),
  235. (self.pointer, 'pointer', icons['pointer'],
  236. self.parent.OnPointer,
  237. wx.ITEM_CHECK),
  238. (self.query, 'query', icons['query'],
  239. self.parent.OnQuery,
  240. wx.ITEM_CHECK),
  241. (self.pan, 'pan', icons['pan'],
  242. self.parent.OnPan,
  243. wx.ITEM_CHECK),
  244. (self.zoomin, 'zoomIn', icons['zoomIn'],
  245. self.parent.OnZoomIn,
  246. wx.ITEM_CHECK),
  247. (self.zoomout, 'zoomOut', icons['zoomOut'],
  248. self.parent.OnZoomOut,
  249. wx.ITEM_CHECK),
  250. (self.zoomextent, 'zoomExtent', icons['zoomExtent'],
  251. self.parent.OnZoomToMap),
  252. (self.zoomback, 'zoomBack', icons['zoomBack'],
  253. self.parent.OnZoomBack),
  254. (self.zoommenu, 'zoomMenu', icons['zoomMenu'],
  255. self.parent.OnZoomMenu),
  256. (None, ),
  257. (self.analyze, 'analyze', icons['analyze'],
  258. self.parent.OnAnalyze),
  259. (None, ),
  260. (self.dec, 'overlay', icons['overlay'],
  261. self.parent.OnDecoration),
  262. (None, ),
  263. (self.savefile, 'saveFile', icons['saveFile'],
  264. self.parent.SaveToFile),
  265. (self.printmap, 'print', icons['print'],
  266. self.parent.PrintMenu),
  267. (None, ))
  268. )
  269. def OnSelectTool(self, event):
  270. """!Select / enable tool available in tools list
  271. """
  272. tool = event.GetSelection()
  273. if tool == self.toolId['2d']:
  274. self.ExitToolbars()
  275. self.Enable2D(True)
  276. elif tool == self.toolId['3d'] and \
  277. not self.parent.toolbars['nviz']:
  278. self.ExitToolbars()
  279. self.parent.AddToolbar("nviz")
  280. elif tool == self.toolId['vdigit'] and \
  281. not self.parent.toolbars['vdigit']:
  282. self.ExitToolbars()
  283. self.parent.AddToolbar("vdigit")
  284. self.parent.MapWindow.SetFocus()
  285. def ExitToolbars(self):
  286. if self.parent.toolbars['vdigit']:
  287. self.parent.toolbars['vdigit'].OnExit()
  288. if self.parent.toolbars['nviz']:
  289. self.parent.toolbars['nviz'].OnExit()
  290. def Enable2D(self, enabled):
  291. """!Enable/Disable 2D display mode specific tools"""
  292. for tool in (self.pointer,
  293. self.pan,
  294. self.zoomin,
  295. self.zoomout,
  296. self.zoomback,
  297. self.zoommenu,
  298. self.analyze,
  299. self.dec,
  300. self.printmap):
  301. self.EnableTool(tool, enabled)
  302. class GCPManToolbar(AbstractToolbar):
  303. """!Toolbar for managing ground control points
  304. @param parent reference to GCP widget
  305. """
  306. def __init__(self, parent):
  307. AbstractToolbar.__init__(self, parent)
  308. self.InitToolbar(self._toolbarData())
  309. # realize the toolbar
  310. self.Realize()
  311. def _toolbarData(self):
  312. self.gcpSave = wx.NewId()
  313. self.gcpReload = wx.NewId()
  314. self.gcpAdd = wx.NewId()
  315. self.gcpDelete = wx.NewId()
  316. self.gcpClear = wx.NewId()
  317. self.rms = wx.NewId()
  318. self.georect = wx.NewId()
  319. icons = Icons['georectify']
  320. return self._getToolbarData(((self.gcpSave, 'gcpSave', icons["gcpSave"],
  321. self.parent.SaveGCPs),
  322. (self.gcpReload, 'gcpReload', icons["gcpReload"],
  323. self.parent.ReloadGCPs),
  324. (None, ),
  325. (self.gcpAdd, 'gcpAdd', icons["gcpAdd"],
  326. self.parent.AddGCP),
  327. (self.gcpDelete, 'gcpDelete', icons["gcpDelete"],
  328. self.parent.DeleteGCP),
  329. (self.gcpClear, 'gcpClear', icons["gcpClear"],
  330. self.parent.ClearGCP),
  331. (None, ),
  332. (self.rms, 'gcpRms', icons["gcpRms"],
  333. self.parent.OnRMS),
  334. (self.georect, 'georectify', icons["georectify"],
  335. self.parent.OnGeorect))
  336. )
  337. class GCPDisplayToolbar(AbstractToolbar):
  338. """!GCP Display toolbar
  339. """
  340. def __init__(self, parent):
  341. """!GCP Display toolbar constructor
  342. """
  343. AbstractToolbar.__init__(self, parent)
  344. self.InitToolbar(self._toolbarData())
  345. # add tool to toggle active map window
  346. self.togglemapid = wx.NewId()
  347. self.togglemap = wx.Choice(parent = self, id = self.togglemapid,
  348. choices = [_('source'), _('target')],
  349. style = wx.CB_READONLY)
  350. self.InsertControl(10, self.togglemap)
  351. self.SetToolShortHelp(self.togglemapid, '%s %s %s' % (_('Set map canvas for '),
  352. Icons['displayWindow']["zoomBack"].GetLabel(),
  353. _(' / Zoom to map')))
  354. # realize the toolbar
  355. self.Realize()
  356. self.action = { 'id' : self.gcpset }
  357. self.defaultAction = { 'id' : self.gcpset,
  358. 'bind' : self.parent.OnPointer }
  359. self.OnTool(None)
  360. self.EnableTool(self.zoomback, False)
  361. def _toolbarData(self):
  362. """!Toolbar data"""
  363. self.displaymap = wx.NewId()
  364. self.rendermap = wx.NewId()
  365. self.erase = wx.NewId()
  366. self.gcpset = wx.NewId()
  367. self.pan = wx.NewId()
  368. self.zoomin = wx.NewId()
  369. self.zoomout = wx.NewId()
  370. self.zoomback = wx.NewId()
  371. self.zoomtomap = wx.NewId()
  372. self.zoommenu = wx.NewId()
  373. self.settings = wx.NewId()
  374. self.helpid = wx.NewId()
  375. self.quit = wx.NewId()
  376. icons = Icons['displayWindow']
  377. return self._getToolbarData(((self.displaymap, "display", icons["display"],
  378. self.parent.OnDraw),
  379. (self.rendermap, "render", icons["render"],
  380. self.parent.OnRender),
  381. (self.erase, "erase", icons["erase"],
  382. self.parent.OnErase),
  383. (None, ),
  384. (self.gcpset, "gcpSet", Icons["georectify"]["gcpSet"],
  385. self.parent.OnPointer),
  386. (self.pan, "pan", icons["pan"],
  387. self.parent.OnPan),
  388. (self.zoomin, "zoomIn", icons["zoomIn"],
  389. self.parent.OnZoomIn),
  390. (self.zoomout, "zoomOut", icons["zoomOut"],
  391. self.parent.OnZoomOut),
  392. (self.zoommenu, "zoomMenu", icons["zoomMenu"],
  393. self.parent.OnZoomMenuGCP),
  394. (None, ),
  395. (self.zoomback, "zoomBack", icons["zoomBack"],
  396. self.parent.OnZoomBack),
  397. (self.zoomtomap, "zoomtomap", icons["zoomExtent"],
  398. self.parent.OnZoomToMap),
  399. (None, ),
  400. (self.settings, 'settings', Icons["georectify"]["settings"],
  401. self.parent.OnSettings),
  402. (self.helpid, 'help', Icons["misc"]["help"],
  403. self.parent.OnHelp),
  404. (None, ),
  405. (self.quit, 'gcpQuit', Icons["georectify"]["quit"],
  406. self.parent.OnQuit))
  407. )
  408. class VDigitToolbar(AbstractToolbar):
  409. """!Toolbar for digitization
  410. """
  411. def __init__(self, parent, mapcontent, layerTree = None, log = None):
  412. self.mapcontent = mapcontent # Map class instance
  413. self.layerTree = layerTree # reference to layer tree associated to map display
  414. self.log = log # log area
  415. AbstractToolbar.__init__(self, parent)
  416. self.digit = None
  417. # currently selected map layer for editing (reference to MapLayer instance)
  418. self.mapLayer = None
  419. # list of vector layers from Layer Manager (only in the current mapset)
  420. self.layers = []
  421. self.comboid = None
  422. # only one dialog can be open
  423. self.settingsDialog = None
  424. # create toolbars (two rows optionally)
  425. self.InitToolbar(self._toolbarData())
  426. self.Bind(wx.EVT_TOOL, self.OnTool)
  427. # default action (digitize new point, line, etc.)
  428. self.action = { 'desc' : 'addLine',
  429. 'type' : 'point',
  430. 'id' : self.addPoint }
  431. # list of available vector maps
  432. self.UpdateListOfLayers(updateTool = True)
  433. # realize toolbar
  434. self.Realize()
  435. # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  436. self.combo.Hide()
  437. self.combo.Show()
  438. # disable undo/redo
  439. self.EnableTool(self.undo, False)
  440. # toogle to pointer by default
  441. self.OnTool(None)
  442. self.FixSize(width = 105)
  443. def _toolbarData(self):
  444. """!Toolbar data
  445. """
  446. data = []
  447. self.addPoint = wx.NewId()
  448. self.addLine = wx.NewId()
  449. self.addBoundary = wx.NewId()
  450. self.addCentroid = wx.NewId()
  451. self.addArea = wx.NewId()
  452. self.moveVertex = wx.NewId()
  453. self.addVertex = wx.NewId()
  454. self.removeVertex = wx.NewId()
  455. self.splitLine = wx.NewId()
  456. self.editLine = wx.NewId()
  457. self.moveLine = wx.NewId()
  458. self.deleteLine = wx.NewId()
  459. self.additionalTools = wx.NewId()
  460. self.displayCats = wx.NewId()
  461. self.displayAttr = wx.NewId()
  462. self.copyCats = wx.NewId()
  463. self.undo = wx.NewId()
  464. self.settings = wx.NewId()
  465. self.exit = wx.NewId()
  466. icons = Icons['vdigit']
  467. return self._getToolbarData(((None, ),
  468. (self.addPoint, "addPoint", icons["addPoint"],
  469. self.OnAddPoint),
  470. (self.addLine, "addLine", icons["addLine"],
  471. self.OnAddLine,
  472. wx.ITEM_CHECK),
  473. (self.addBoundary, "addBoundary", icons["addBoundary"],
  474. self.OnAddBoundary,
  475. wx.ITEM_CHECK),
  476. (self.addCentroid, "addCentroid", icons["addCentroid"],
  477. self.OnAddCentroid,
  478. wx.ITEM_CHECK),
  479. (self.addArea, "addArea", icons["addArea"],
  480. self.OnAddArea,
  481. wx.ITEM_CHECK),
  482. (self.moveVertex, "moveVertex", icons["moveVertex"],
  483. self.OnMoveVertex,
  484. wx.ITEM_CHECK),
  485. (self.addVertex, "addVertex", icons["addVertex"],
  486. self.OnAddVertex,
  487. wx.ITEM_CHECK),
  488. (self.removeVertex, "removeVertex", icons["removeVertex"],
  489. self.OnRemoveVertex,
  490. wx.ITEM_CHECK),
  491. (self.splitLine, "splitLine", icons["splitLine"],
  492. self.OnSplitLine,
  493. wx.ITEM_CHECK),
  494. (self.editLine, "editLine", icons["editLine"],
  495. self.OnEditLine,
  496. wx.ITEM_CHECK),
  497. (self.moveLine, "moveLine", icons["moveLine"],
  498. self.OnMoveLine,
  499. wx.ITEM_CHECK),
  500. (self.deleteLine, "deleteLine", icons["deleteLine"],
  501. self.OnDeleteLine,
  502. wx.ITEM_CHECK),
  503. (self.displayCats, "displayCats", icons["displayCats"],
  504. self.OnDisplayCats,
  505. wx.ITEM_CHECK),
  506. (self.copyCats, "copyCats", icons["copyCats"],
  507. self.OnCopyCA,
  508. wx.ITEM_CHECK),
  509. (self.displayAttr, "displayAttr", icons["displayAttr"],
  510. self.OnDisplayAttr,
  511. wx.ITEM_CHECK),
  512. (self.additionalTools, "additionalTools", icons["additionalTools"],
  513. self.OnAdditionalToolMenu,
  514. wx.ITEM_CHECK),
  515. (None, ),
  516. (self.undo, "undo", icons["undo"],
  517. self.OnUndo),
  518. (self.settings, "settings", icons["settings"],
  519. self.OnSettings),
  520. (self.exit, "quit", icons["quit"],
  521. self.OnExit))
  522. )
  523. def OnTool(self, event):
  524. """!Tool selected -> disable selected tool in map toolbar"""
  525. id = self.parent.toolbars['map'].GetAction(type = 'id')
  526. self.parent.toolbars['map'].ToggleTool(id, False)
  527. # set cursor
  528. cursor = self.parent.cursors["cross"]
  529. self.parent.MapWindow.SetCursor(cursor)
  530. # pointer
  531. self.parent.OnPointer(None)
  532. if event:
  533. # deselect previously selected tool
  534. id = self.action.get('id', -1)
  535. if id != event.GetId():
  536. self.ToggleTool(self.action['id'], False)
  537. else:
  538. self.ToggleTool(self.action['id'], True)
  539. self.action['id'] = event.GetId()
  540. event.Skip()
  541. self.ToggleTool(self.action['id'], True)
  542. # clear tmp canvas
  543. if self.action['id'] != id:
  544. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  545. if self.digit and \
  546. len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
  547. # cancel action
  548. self.parent.MapWindow.OnMiddleDown(None)
  549. # set focus
  550. self.parent.MapWindow.SetFocus()
  551. def OnAddPoint(self, event):
  552. """!Add point to the vector map Laier"""
  553. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  554. self.action = { 'desc' : "addLine",
  555. 'type' : "point",
  556. 'id' : self.addPoint }
  557. self.parent.MapWindow.mouse['box'] = 'point'
  558. def OnAddLine(self, event):
  559. """!Add line to the vector map layer"""
  560. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  561. self.action = { 'desc' : "addLine",
  562. 'type' : "line",
  563. 'id' : self.addLine }
  564. self.parent.MapWindow.mouse['box'] = 'line'
  565. ### self.parent.MapWindow.polycoords = [] # reset temp line
  566. def OnAddBoundary(self, event):
  567. """!Add boundary to the vector map layer"""
  568. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  569. if self.action['desc'] != 'addLine' or \
  570. self.action['type'] != 'boundary':
  571. self.parent.MapWindow.polycoords = [] # reset temp line
  572. self.action = { 'desc' : "addLine",
  573. 'type' : "boundary",
  574. 'id' : self.addBoundary }
  575. self.parent.MapWindow.mouse['box'] = 'line'
  576. def OnAddCentroid(self, event):
  577. """!Add centroid to the vector map layer"""
  578. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  579. self.action = { 'desc' : "addLine",
  580. 'type' : "centroid",
  581. 'id' : self.addCentroid }
  582. self.parent.MapWindow.mouse['box'] = 'point'
  583. def OnAddArea(self, event):
  584. """!Add area to the vector map layer"""
  585. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  586. self.action = { 'desc' : "addLine",
  587. 'type' : "area",
  588. 'id' : self.addArea }
  589. self.parent.MapWindow.mouse['box'] = 'line'
  590. def OnExit (self, event=None):
  591. """!Quit digitization tool"""
  592. # stop editing of the currently selected map layer
  593. if self.mapLayer:
  594. self.StopEditing()
  595. # close dialogs if still open
  596. if self.settingsDialog:
  597. self.settingsDialog.OnCancel(None)
  598. # set default mouse settings
  599. self.parent.MapWindow.mouse['use'] = "pointer"
  600. self.parent.MapWindow.mouse['box'] = "point"
  601. self.parent.MapWindow.polycoords = []
  602. # disable the toolbar
  603. self.parent.RemoveToolbar("vdigit")
  604. def OnMoveVertex(self, event):
  605. """!Move line vertex"""
  606. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  607. self.action = { 'desc' : "moveVertex",
  608. 'id' : self.moveVertex }
  609. self.parent.MapWindow.mouse['box'] = 'point'
  610. def OnAddVertex(self, event):
  611. """!Add line vertex"""
  612. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  613. self.action = { 'desc' : "addVertex",
  614. 'id' : self.addVertex }
  615. self.parent.MapWindow.mouse['box'] = 'point'
  616. def OnRemoveVertex(self, event):
  617. """!Remove line vertex"""
  618. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  619. self.action = { 'desc' : "removeVertex",
  620. 'id' : self.removeVertex }
  621. self.parent.MapWindow.mouse['box'] = 'point'
  622. def OnSplitLine(self, event):
  623. """!Split line"""
  624. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  625. self.action = { 'desc' : "splitLine",
  626. 'id' : self.splitLine }
  627. self.parent.MapWindow.mouse['box'] = 'point'
  628. def OnEditLine(self, event):
  629. """!Edit line"""
  630. Debug.msg(2, "Digittoolbar.OnEditLine():")
  631. self.action = { 'desc' : "editLine",
  632. 'id' : self.editLine }
  633. self.parent.MapWindow.mouse['box'] = 'line'
  634. def OnMoveLine(self, event):
  635. """!Move line"""
  636. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  637. self.action = { 'desc' : "moveLine",
  638. 'id' : self.moveLine }
  639. self.parent.MapWindow.mouse['box'] = 'box'
  640. def OnDeleteLine(self, event):
  641. """!Delete line"""
  642. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  643. self.action = { 'desc' : "deleteLine",
  644. 'id' : self.deleteLine }
  645. self.parent.MapWindow.mouse['box'] = 'box'
  646. def OnDisplayCats(self, event):
  647. """!Display/update categories"""
  648. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  649. self.action = { 'desc' : "displayCats",
  650. 'id' : self.displayCats }
  651. self.parent.MapWindow.mouse['box'] = 'point'
  652. def OnDisplayAttr(self, event):
  653. """!Display/update attributes"""
  654. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  655. self.action = { 'desc' : "displayAttrs",
  656. 'id' : self.displayAttr }
  657. self.parent.MapWindow.mouse['box'] = 'point'
  658. def OnCopyCA(self, event):
  659. """!Copy categories/attributes menu"""
  660. point = wx.GetMousePosition()
  661. toolMenu = wx.Menu()
  662. # Add items to the menu
  663. cats = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  664. text = _('Copy categories'),
  665. kind = wx.ITEM_CHECK)
  666. toolMenu.AppendItem(cats)
  667. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  668. if self.action['desc'] == "copyCats":
  669. cats.Check(True)
  670. attrb = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  671. text = _('Duplicate attributes'),
  672. kind = wx.ITEM_CHECK)
  673. toolMenu.AppendItem(attrb)
  674. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  675. if self.action['desc'] == "copyAttrs":
  676. attrb.Check(True)
  677. # Popup the menu. If an item is selected then its handler
  678. # will be called before PopupMenu returns.
  679. self.parent.MapWindow.PopupMenu(toolMenu)
  680. toolMenu.Destroy()
  681. if self.action['desc'] == "addPoint":
  682. self.ToggleTool(self.copyCats, False)
  683. def OnCopyCats(self, event):
  684. """!Copy categories"""
  685. if self.action['desc'] == 'copyCats': # select previous action
  686. self.ToggleTool(self.addPoint, True)
  687. self.ToggleTool(self.copyCats, False)
  688. self.OnAddPoint(event)
  689. return
  690. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  691. self.action = { 'desc' : "copyCats",
  692. 'id' : self.copyCats }
  693. self.parent.MapWindow.mouse['box'] = 'point'
  694. def OnCopyAttrb(self, event):
  695. if self.action['desc'] == 'copyAttrs': # select previous action
  696. self.ToggleTool(self.addPoint, True)
  697. self.ToggleTool(self.copyCats, False)
  698. self.OnAddPoint(event)
  699. return
  700. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  701. self.action = { 'desc' : "copyAttrs",
  702. 'id' : self.copyCats }
  703. self.parent.MapWindow.mouse['box'] = 'point'
  704. def OnUndo(self, event):
  705. """!Undo previous changes"""
  706. self.digit.Undo()
  707. event.Skip()
  708. def EnableUndo(self, enable=True):
  709. """!Enable 'Undo' in toolbar
  710. @param enable False for disable
  711. """
  712. if enable:
  713. if self.GetToolEnabled(self.undo) is False:
  714. self.EnableTool(self.undo, True)
  715. else:
  716. if self.GetToolEnabled(self.undo) is True:
  717. self.EnableTool(self.undo, False)
  718. def OnSettings(self, event):
  719. """!Show settings dialog"""
  720. if self.digit is None:
  721. try:
  722. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  723. except SystemExit:
  724. self.digit = self.parent.MapWindow.digit = None
  725. if not self.settingsDialog:
  726. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  727. style = wx.DEFAULT_DIALOG_STYLE)
  728. self.settingsDialog.Show()
  729. def OnAdditionalToolMenu(self, event):
  730. """!Menu for additional tools"""
  731. point = wx.GetMousePosition()
  732. toolMenu = wx.Menu()
  733. # Add items to the menu
  734. copy = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  735. text = _('Copy features from (background) vector map'),
  736. kind = wx.ITEM_CHECK)
  737. toolMenu.AppendItem(copy)
  738. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  739. if self.action['desc'] == "copyLine":
  740. copy.Check(True)
  741. flip = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  742. text = _('Flip selected lines/boundaries'),
  743. kind = wx.ITEM_CHECK)
  744. toolMenu.AppendItem(flip)
  745. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  746. if self.action['desc'] == "flipLine":
  747. flip.Check(True)
  748. merge = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  749. text = _('Merge selected lines/boundaries'),
  750. kind = wx.ITEM_CHECK)
  751. toolMenu.AppendItem(merge)
  752. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  753. if self.action['desc'] == "mergeLine":
  754. merge.Check(True)
  755. breakL = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  756. text = _('Break selected lines/boundaries at intersection'),
  757. kind = wx.ITEM_CHECK)
  758. toolMenu.AppendItem(breakL)
  759. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  760. if self.action['desc'] == "breakLine":
  761. breakL.Check(True)
  762. snap = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  763. text = _('Snap selected lines/boundaries (only to nodes)'),
  764. kind = wx.ITEM_CHECK)
  765. toolMenu.AppendItem(snap)
  766. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  767. if self.action['desc'] == "snapLine":
  768. snap.Check(True)
  769. connect = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  770. text = _('Connect selected lines/boundaries'),
  771. kind = wx.ITEM_CHECK)
  772. toolMenu.AppendItem(connect)
  773. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  774. if self.action['desc'] == "connectLine":
  775. connect.Check(True)
  776. query = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  777. text = _('Query features'),
  778. kind = wx.ITEM_CHECK)
  779. toolMenu.AppendItem(query)
  780. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  781. if self.action['desc'] == "queryLine":
  782. query.Check(True)
  783. zbulk = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  784. text = _('Z bulk-labeling of 3D lines'),
  785. kind = wx.ITEM_CHECK)
  786. toolMenu.AppendItem(zbulk)
  787. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  788. if self.action['desc'] == "zbulkLine":
  789. zbulk.Check(True)
  790. typeconv = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  791. text = _('Feature type conversion'),
  792. kind = wx.ITEM_CHECK)
  793. toolMenu.AppendItem(typeconv)
  794. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  795. if self.action['desc'] == "typeConv":
  796. typeconv.Check(True)
  797. # Popup the menu. If an item is selected then its handler
  798. # will be called before PopupMenu returns.
  799. self.parent.MapWindow.PopupMenu(toolMenu)
  800. toolMenu.Destroy()
  801. if self.action['desc'] == 'addPoint':
  802. self.ToggleTool(self.additionalTools, False)
  803. def OnCopy(self, event):
  804. """!Copy selected features from (background) vector map"""
  805. if self.action['desc'] == 'copyLine': # select previous action
  806. self.ToggleTool(self.addPoint, True)
  807. self.ToggleTool(self.additionalTools, False)
  808. self.OnAddPoint(event)
  809. return
  810. Debug.msg(2, "Digittoolbar.OnCopy():")
  811. self.action = { 'desc' : "copyLine",
  812. 'id' : self.additionalTools }
  813. self.parent.MapWindow.mouse['box'] = 'box'
  814. def OnFlip(self, event):
  815. """!Flip selected lines/boundaries"""
  816. if self.action['desc'] == 'flipLine': # select previous action
  817. self.ToggleTool(self.addPoint, True)
  818. self.ToggleTool(self.additionalTools, False)
  819. self.OnAddPoint(event)
  820. return
  821. Debug.msg(2, "Digittoolbar.OnFlip():")
  822. self.action = { 'desc' : "flipLine",
  823. 'id' : self.additionalTools }
  824. self.parent.MapWindow.mouse['box'] = 'box'
  825. def OnMerge(self, event):
  826. """!Merge selected lines/boundaries"""
  827. if self.action['desc'] == 'mergeLine': # select previous action
  828. self.ToggleTool(self.addPoint, True)
  829. self.ToggleTool(self.additionalTools, False)
  830. self.OnAddPoint(event)
  831. return
  832. Debug.msg(2, "Digittoolbar.OnMerge():")
  833. self.action = { 'desc' : "mergeLine",
  834. 'id' : self.additionalTools }
  835. self.parent.MapWindow.mouse['box'] = 'box'
  836. def OnBreak(self, event):
  837. """!Break selected lines/boundaries"""
  838. if self.action['desc'] == 'breakLine': # select previous action
  839. self.ToggleTool(self.addPoint, True)
  840. self.ToggleTool(self.additionalTools, False)
  841. self.OnAddPoint(event)
  842. return
  843. Debug.msg(2, "Digittoolbar.OnBreak():")
  844. self.action = { 'desc' : "breakLine",
  845. 'id' : self.additionalTools }
  846. self.parent.MapWindow.mouse['box'] = 'box'
  847. def OnSnap(self, event):
  848. """!Snap selected features"""
  849. if self.action['desc'] == 'snapLine': # 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.OnSnap():")
  855. self.action = { 'desc' : "snapLine",
  856. 'id' : self.additionalTools }
  857. self.parent.MapWindow.mouse['box'] = 'box'
  858. def OnConnect(self, event):
  859. """!Connect selected lines/boundaries"""
  860. if self.action['desc'] == 'connectLine': # select previous action
  861. self.ToggleTool(self.addPoint, True)
  862. self.ToggleTool(self.additionalTools, False)
  863. self.OnAddPoint(event)
  864. return
  865. Debug.msg(2, "Digittoolbar.OnConnect():")
  866. self.action = { 'desc' : "connectLine",
  867. 'id' : self.additionalTools }
  868. self.parent.MapWindow.mouse['box'] = 'box'
  869. def OnQuery(self, event):
  870. """!Query selected lines/boundaries"""
  871. if self.action['desc'] == 'queryLine': # select previous action
  872. self.ToggleTool(self.addPoint, True)
  873. self.ToggleTool(self.additionalTools, False)
  874. self.OnAddPoint(event)
  875. return
  876. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  877. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  878. self.action = { 'desc' : "queryLine",
  879. 'id' : self.additionalTools }
  880. self.parent.MapWindow.mouse['box'] = 'box'
  881. def OnZBulk(self, event):
  882. """!Z bulk-labeling selected lines/boundaries"""
  883. if not self.digit.IsVector3D():
  884. gcmd.GError(parent = self.parent,
  885. message = _("Vector map is not 3D. Operation canceled."))
  886. return
  887. if self.action['desc'] == 'zbulkLine': # select previous action
  888. self.ToggleTool(self.addPoint, True)
  889. self.ToggleTool(self.additionalTools, False)
  890. self.OnAddPoint(event)
  891. return
  892. Debug.msg(2, "Digittoolbar.OnZBulk():")
  893. self.action = { 'desc' : "zbulkLine",
  894. 'id' : self.additionalTools }
  895. self.parent.MapWindow.mouse['box'] = 'line'
  896. def OnTypeConversion(self, event):
  897. """!Feature type conversion
  898. Supported conversions:
  899. - point <-> centroid
  900. - line <-> boundary
  901. """
  902. if self.action['desc'] == 'typeConv': # select previous action
  903. self.ToggleTool(self.addPoint, True)
  904. self.ToggleTool(self.additionalTools, False)
  905. self.OnAddPoint(event)
  906. return
  907. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  908. self.action = { 'desc' : "typeConv",
  909. 'id' : self.additionalTools }
  910. self.parent.MapWindow.mouse['box'] = 'box'
  911. def OnSelectMap (self, event):
  912. """!Select vector map layer for editing
  913. If there is a vector map layer already edited, this action is
  914. firstly terminated. The map layer is closed. After this the
  915. selected map layer activated for editing.
  916. """
  917. if event.GetSelection() == 0: # create new vector map layer
  918. if self.mapLayer:
  919. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  920. else:
  921. openVectorMap = None
  922. mapName = gdialogs.CreateNewVector(self.parent,
  923. exceptMap = openVectorMap, log = self.log,
  924. cmd = (('v.edit',
  925. { 'tool' : 'create' },
  926. 'map')),
  927. disableAdd = True)[0]
  928. if mapName:
  929. # add layer to map layer tree
  930. if self.layerTree:
  931. self.layerTree.AddLayer(ltype = 'vector',
  932. lname = mapName,
  933. lchecked = True,
  934. lopacity = 1.0,
  935. lcmd = ['d.vect', 'map=%s' % mapName])
  936. vectLayers = self.UpdateListOfLayers(updateTool = True)
  937. selection = vectLayers.index(mapName)
  938. else:
  939. pass # TODO (no Layer Manager)
  940. else:
  941. self.combo.SetValue(_('Select vector map'))
  942. return
  943. else:
  944. selection = event.GetSelection() - 1 # first option is 'New vector map'
  945. # skip currently selected map
  946. if self.layers[selection] == self.mapLayer:
  947. return False
  948. if self.mapLayer:
  949. # deactive map layer for editing
  950. self.StopEditing()
  951. # select the given map layer for editing
  952. self.StartEditing(self.layers[selection])
  953. event.Skip()
  954. return True
  955. def StartEditing (self, mapLayer):
  956. """!Start editing selected vector map layer.
  957. @param mapLayer MapLayer to be edited
  958. """
  959. # deactive layer
  960. self.mapcontent.ChangeLayerActive(mapLayer, False)
  961. # clean map canvas
  962. self.parent.MapWindow.EraseMap()
  963. # unset background map if needed
  964. if mapLayer:
  965. if UserSettings.Get(group = 'vdigit', key = 'bgmap',
  966. subkey = 'value', internal = True) == mapLayer.GetName():
  967. UserSettings.Set(group = 'vdigit', key = 'bgmap',
  968. subkey = 'value', value = '', internal = True)
  969. self.parent.statusbar.SetStatusText(_("Please wait, "
  970. "opening vector map <%s> for editing...") % mapLayer.GetName(),
  971. 0)
  972. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  973. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  974. self.mapLayer = mapLayer
  975. # open vector map
  976. if self.digit.OpenMap(mapLayer.GetName()) is None:
  977. self.mapLayer = None
  978. self.StopEditing()
  979. return False
  980. # update toolbar
  981. self.combo.SetValue(mapLayer.GetName())
  982. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  983. lmgr = self.parent.GetLayerManager()
  984. if lmgr:
  985. lmgr.toolbars['tools'].Enable('vdigit', enable = False)
  986. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  987. # change cursor
  988. if self.parent.MapWindow.mouse['use'] == 'pointer':
  989. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  990. if not self.parent.MapWindow.resize:
  991. self.parent.MapWindow.UpdateMap(render = True)
  992. opacity = mapLayer.GetOpacity(float = True)
  993. if opacity < 1.0:
  994. alpha = int(opacity * 255)
  995. self.digit.UpdateSettings(alpha)
  996. return True
  997. def StopEditing(self):
  998. """!Stop editing of selected vector map layer.
  999. @return True on success
  1000. @return False on failure
  1001. """
  1002. self.combo.SetValue (_('Select vector map'))
  1003. # save changes
  1004. if self.mapLayer:
  1005. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  1006. if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
  1007. if self.digit.GetUndoLevel() > -1:
  1008. dlg = wx.MessageDialog(parent = self.parent,
  1009. message = _("Do you want to save changes "
  1010. "in vector map <%s>?") % self.mapLayer.GetName(),
  1011. caption = _("Save changes?"),
  1012. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  1013. if dlg.ShowModal() == wx.ID_NO:
  1014. # revert changes
  1015. self.digit.Undo(0)
  1016. dlg.Destroy()
  1017. self.parent.statusbar.SetStatusText(_("Please wait, "
  1018. "closing and rebuilding topology of "
  1019. "vector map <%s>...") % self.mapLayer.GetName(),
  1020. 0)
  1021. lmgr = self.parent.GetLayerManager()
  1022. if lmgr:
  1023. lmgr.toolbars['tools'].Enable('vdigit', enable = True)
  1024. lmgr.notebook.SetSelectionByName('console')
  1025. self.digit.CloseMap()
  1026. if lmgr:
  1027. lmgr.GetLogWindow().GetProgressBar().SetValue(0)
  1028. lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
  1029. self.mapLayer.GetName())
  1030. # re-active layer
  1031. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  1032. if item and self.parent.tree.IsItemChecked(item):
  1033. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  1034. # change cursor
  1035. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  1036. self.parent.MapWindow.pdcVector = None
  1037. # close dialogs
  1038. for dialog in ('attributes', 'category'):
  1039. if self.parent.dialogs[dialog]:
  1040. self.parent.dialogs[dialog].Close()
  1041. self.parent.dialogs[dialog] = None
  1042. del self.digit
  1043. del self.parent.MapWindow.digit
  1044. self.mapLayer = None
  1045. self.parent.MapWindow.redrawAll = True
  1046. return True
  1047. def UpdateListOfLayers (self, updateTool = False):
  1048. """!
  1049. Update list of available vector map layers.
  1050. This list consists only editable layers (in the current mapset)
  1051. Optionally also update toolbar
  1052. """
  1053. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  1054. updateTool)
  1055. layerNameSelected = None
  1056. # name of currently selected layer
  1057. if self.mapLayer:
  1058. layerNameSelected = self.mapLayer.GetName()
  1059. # select vector map layer in the current mapset
  1060. layerNameList = []
  1061. self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
  1062. l_mapset = grass.gisenv()['MAPSET'])
  1063. for layer in self.layers:
  1064. if not layer.name in layerNameList: # do not duplicate layer
  1065. layerNameList.append (layer.GetName())
  1066. if updateTool: # update toolbar
  1067. if not self.mapLayer:
  1068. value = _('Select vector map')
  1069. else:
  1070. value = layerNameSelected
  1071. if not self.comboid:
  1072. self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
  1073. choices = [_('New vector map'), ] + layerNameList, size = (115, -1),
  1074. style = wx.CB_READONLY)
  1075. self.comboid = self.InsertControl(0, self.combo)
  1076. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1077. else:
  1078. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1079. self.Realize()
  1080. return layerNameList
  1081. def GetLayer(self):
  1082. """!Get selected layer for editing -- MapLayer instance"""
  1083. return self.mapLayer
  1084. class ProfileToolbar(AbstractToolbar):
  1085. """!Toolbar for profiling raster map
  1086. """
  1087. def __init__(self, parent):
  1088. AbstractToolbar.__init__(self, parent)
  1089. self.InitToolbar(self._toolbarData())
  1090. # realize the toolbar
  1091. self.Realize()
  1092. def _toolbarData(self):
  1093. """!Toolbar data"""
  1094. self.transect = wx.NewId()
  1095. self.addraster = wx.NewId()
  1096. self.draw = wx.NewId()
  1097. self.options = wx.NewId()
  1098. self.drag = wx.NewId()
  1099. self.zoom = wx.NewId()
  1100. self.unzoom = wx.NewId()
  1101. self.erase = wx.NewId()
  1102. self.save = wx.NewId()
  1103. self.datasave = wx.NewId()
  1104. self.printer = wx.NewId()
  1105. self.quit = wx.NewId()
  1106. icons = Icons['profile']
  1107. return self._getToolbarData(((self.addraster, 'raster', Icons['layerManager']["addRast"],
  1108. self.parent.OnSelectRaster),
  1109. (self.transect, 'transect', icons["transect"],
  1110. self.parent.OnDrawTransect),
  1111. (None, ),
  1112. (self.draw, 'draw', icons["draw"],
  1113. self.parent.OnCreateProfile),
  1114. (self.erase, 'erase', Icons['displayWindow']["erase"],
  1115. self.parent.OnErase),
  1116. (self.drag, 'drag', Icons['displayWindow']['pan'],
  1117. self.parent.OnDrag),
  1118. (self.zoom, 'zoom', Icons['displayWindow']['zoomIn'],
  1119. self.parent.OnZoom),
  1120. (self.unzoom, 'unzoom', Icons['displayWindow']['zoomBack'],
  1121. self.parent.OnRedraw),
  1122. (None, ),
  1123. (self.datasave, 'save', icons["save"],
  1124. self.parent.SaveProfileToFile),
  1125. (self.save, 'image', Icons['displayWindow']["saveFile"],
  1126. self.parent.SaveToFile),
  1127. (self.printer, 'print', Icons['displayWindow']["print"],
  1128. self.parent.PrintMenu),
  1129. (None, ),
  1130. (self.options, 'options', icons["options"],
  1131. self.parent.ProfileOptionsMenu),
  1132. (self.quit, 'quit', icons["quit"],
  1133. self.parent.OnQuit),
  1134. ))
  1135. class NvizToolbar(AbstractToolbar):
  1136. """!Nviz toolbar
  1137. """
  1138. def __init__(self, parent, mapcontent):
  1139. self.mapcontent = mapcontent
  1140. self.lmgr = parent.GetLayerManager()
  1141. AbstractToolbar.__init__(self, parent)
  1142. # only one dialog can be open
  1143. self.settingsDialog = None
  1144. self.InitToolbar(self._toolbarData())
  1145. # realize the toolbar
  1146. self.Realize()
  1147. def _toolbarData(self):
  1148. """!Toolbar data"""
  1149. self.view = wx.NewId()
  1150. self.surface = wx.NewId()
  1151. self.vector = wx.NewId()
  1152. self.volume = wx.NewId()
  1153. self.light = wx.NewId()
  1154. self.fringe = wx.NewId()
  1155. self.settings = wx.NewId()
  1156. self.help = wx.NewId()
  1157. self.quit = wx.NewId()
  1158. icons = Icons['nviz']
  1159. return self._getToolbarData(((self.view, "view", icons["view"],
  1160. self.OnShowPage),
  1161. (None, ),
  1162. (self.surface, "surface", icons["surface"],
  1163. self.OnShowPage),
  1164. (self.vector, "vector", icons["vector"],
  1165. self.OnShowPage),
  1166. (self.volume, "volume", icons["volume"],
  1167. self.OnShowPage),
  1168. (None, ),
  1169. (self.light, "light", icons["light"],
  1170. self.OnShowPage),
  1171. (self.fringe, "fringe", icons["fringe"],
  1172. self.OnShowPage),
  1173. (None, ),
  1174. (self.settings, "settings", icons["settings"],
  1175. self.OnSettings),
  1176. (self.help, "help", Icons['misc']["help"],
  1177. self.OnHelp),
  1178. (None, ),
  1179. (self.quit, 'quit', icons["quit"],
  1180. self.OnExit))
  1181. )
  1182. def OnShowPage(self, event):
  1183. """!Go to the selected page"""
  1184. if not self.lmgr or not hasattr(self.lmgr, "nviz"):
  1185. event.Skip()
  1186. return
  1187. self.lmgr.notebook.SetSelectionByName('nviz')
  1188. eId = event.GetId()
  1189. if eId == self.view:
  1190. self.lmgr.nviz.SetPage('view')
  1191. elif eId == self.surface:
  1192. self.lmgr.nviz.SetPage('surface')
  1193. elif eId == self.surface:
  1194. self.lmgr.nviz.SetPage('surface')
  1195. elif eId == self.vector:
  1196. self.lmgr.nviz.SetPage('vector')
  1197. elif eId == self.volume:
  1198. self.lmgr.nviz.SetPage('volume')
  1199. elif eId == self.light:
  1200. self.lmgr.nviz.SetPage('light')
  1201. elif eId == self.fringe:
  1202. self.lmgr.nviz.SetPage('fringe')
  1203. self.lmgr.Raise()
  1204. def OnHelp(self, event):
  1205. """!Show 3D view mode help"""
  1206. if not self.lmgr:
  1207. gcmd.RunCommand('g.manual',
  1208. entry = 'wxGUI.Nviz')
  1209. else:
  1210. log = self.lmgr.GetLogWindow()
  1211. log.RunCmd(['g.manual',
  1212. 'entry=wxGUI.Nviz'])
  1213. def OnSettings(self, event):
  1214. """!Show nviz notebook page"""
  1215. if not self.settingsDialog:
  1216. self.settingsDialog = NvizPreferencesDialog(parent = self.parent)
  1217. self.settingsDialog.Show()
  1218. def OnExit (self, event = None):
  1219. """!Quit nviz tool (swith to 2D mode)"""
  1220. # set default mouse settings
  1221. self.parent.MapWindow.mouse['use'] = "pointer"
  1222. self.parent.MapWindow.mouse['box'] = "point"
  1223. self.parent.MapWindow.polycoords = []
  1224. # return to map layer page (gets rid of ugly exit bug)
  1225. self.lmgr.notebook.SetSelectionByName('layers')
  1226. # disable the toolbar
  1227. self.parent.RemoveToolbar("nviz")
  1228. class ModelToolbar(AbstractToolbar):
  1229. """!Graphical modeler toolbar (see gmodeler.py)
  1230. """
  1231. def __init__(self, parent):
  1232. AbstractToolbar.__init__(self, parent)
  1233. self.InitToolbar(self._toolbarData())
  1234. # realize the toolbar
  1235. self.Realize()
  1236. def _toolbarData(self):
  1237. """!Toolbar data"""
  1238. self.new = wx.NewId()
  1239. self.open = wx.NewId()
  1240. self.save = wx.NewId()
  1241. self.image = wx.NewId()
  1242. self.python = wx.NewId()
  1243. self.action = wx.NewId()
  1244. self.data = wx.NewId()
  1245. self.relation = wx.NewId()
  1246. self.run = wx.NewId()
  1247. self.validate = wx.NewId()
  1248. self.settings = wx.NewId()
  1249. self.variables = wx.NewId()
  1250. self.quit = wx.NewId()
  1251. self.redraw = wx.NewId()
  1252. self.help = wx.NewId()
  1253. icons = Icons['modeler']
  1254. return self._getToolbarData(((self.new, 'new', icons['new'],
  1255. self.parent.OnModelNew),
  1256. (self.open, 'open', icons['open'],
  1257. self.parent.OnModelOpen),
  1258. (self.save, 'save', icons['save'],
  1259. self.parent.OnModelSave),
  1260. (self.image, 'image', icons['toImage'],
  1261. self.parent.OnExportImage),
  1262. (self.python, 'python', icons['toPython'],
  1263. self.parent.OnExportPython),
  1264. (None, ),
  1265. (self.action, 'action', icons['actionAdd'],
  1266. self.parent.OnAddAction),
  1267. (self.data, 'data', icons['dataAdd'],
  1268. self.parent.OnAddData),
  1269. (self.relation, 'relation', icons['relation'],
  1270. self.parent.OnDefineRelation),
  1271. (None, ),
  1272. (self.redraw, 'redraw', icons['redraw'],
  1273. self.parent.OnCanvasRefresh),
  1274. (self.validate, 'validate', icons['validate'],
  1275. self.parent.OnValidateModel),
  1276. (self.run, 'run', icons['run'],
  1277. self.parent.OnRunModel),
  1278. (None, ),
  1279. (self.variables, "variables", icons['variables'],
  1280. self.parent.OnVariables),
  1281. (self.settings, "settings", icons['settings'],
  1282. self.parent.OnPreferences),
  1283. (self.help, "help", Icons['misc']['help'],
  1284. self.parent.OnHelp),
  1285. (None, ),
  1286. (self.quit, 'quit', icons['quit'],
  1287. self.parent.OnCloseWindow))
  1288. )
  1289. class HistogramToolbar(AbstractToolbar):
  1290. """!Histogram toolbar (see histogram.py)
  1291. """
  1292. def __init__(self, parent):
  1293. AbstractToolbar.__init__(self, parent)
  1294. self.InitToolbar(self._toolbarData())
  1295. # realize the toolbar
  1296. self.Realize()
  1297. def _toolbarData(self):
  1298. """!Toolbar data"""
  1299. self.histogram = wx.NewId()
  1300. self.rendermap = wx.NewId()
  1301. self.erase = wx.NewId()
  1302. self.font = wx.NewId()
  1303. self.save = wx.NewId()
  1304. self.hprint = wx.NewId()
  1305. self.quit = wx.NewId()
  1306. icons = Icons['displayWindow']
  1307. return self._getToolbarData(((self.histogram, 'histogram', icons["histogram"],
  1308. self.parent.OnOptions),
  1309. (self.rendermap, 'render', icons["display"],
  1310. self.parent.OnRender),
  1311. (self.erase, 'erase', icons["erase"],
  1312. self.parent.OnErase),
  1313. (self.font, 'font', Icons['misc']["font"],
  1314. self.parent.SetHistFont),
  1315. (None, ),
  1316. (self.save, 'save', icons["saveFile"],
  1317. self.parent.SaveToFile),
  1318. (self.hprint, 'print', icons["print"],
  1319. self.parent.PrintMenu),
  1320. (None, ),
  1321. (self.quit, 'quit', Icons['misc']["quit"],
  1322. self.parent.OnQuit))
  1323. )
  1324. class LayerManagerToolbar(AbstractToolbar):
  1325. """!Layer Manager toolbar (see wxgui.py)
  1326. """
  1327. def __init__(self, parent):
  1328. AbstractToolbar.__init__(self, parent)
  1329. self.InitToolbar(self._toolbarData())
  1330. # realize the toolbar
  1331. self.Realize()
  1332. def _toolbarData(self):
  1333. """!Toolbar data
  1334. """
  1335. self.newdisplay = wx.NewId()
  1336. self.workspaceLoad = wx.NewId()
  1337. self.workspaceOpen = wx.NewId()
  1338. self.workspaceSave = wx.NewId()
  1339. self.addrast = wx.NewId()
  1340. self.rastmisc = wx.NewId()
  1341. self.addvect = wx.NewId()
  1342. self.vectmisc = wx.NewId()
  1343. self.addgrp = wx.NewId()
  1344. self.addovl = wx.NewId()
  1345. self.delcmd = wx.NewId()
  1346. self.attribute = wx.NewId()
  1347. self.preferences = wx.NewId()
  1348. self.help = wx.NewId()
  1349. icons = Icons['layerManager']
  1350. return self._getToolbarData(((self.newdisplay, 'newdisplay', icons["newdisplay"],
  1351. self.parent.OnNewMenu),
  1352. (None, ),
  1353. (self.workspaceLoad, 'workspaceLoad', icons["workspaceLoad"],
  1354. self.parent.OnLoadMenu),
  1355. (self.workspaceOpen, 'workspaceOpen', icons["workspaceOpen"],
  1356. self.parent.OnWorkspaceOpen),
  1357. (self.workspaceSave, 'workspaceSave', icons["workspaceSave"],
  1358. self.parent.OnWorkspaceSave),
  1359. (None, ),
  1360. (self.addrast, 'addRast', icons["addRast"],
  1361. self.parent.OnAddRaster),
  1362. (self.rastmisc, 'rastMisc', icons["rastMisc"],
  1363. self.parent.OnAddRasterMisc),
  1364. (self.addvect, 'addVect', icons["addVect"],
  1365. self.parent.OnAddVector),
  1366. (self.vectmisc, 'vectMisc', icons["vectMisc"],
  1367. self.parent.OnAddVectorMisc),
  1368. (self.addgrp, 'addGroup', icons["addGroup"],
  1369. self.parent.OnAddGroup),
  1370. (self.addovl, 'addOverlay', icons["addOverlay"],
  1371. self.parent.OnAddOverlay),
  1372. (self.delcmd, 'delCmd', icons["delCmd"],
  1373. self.parent.OnDeleteLayer),
  1374. (None, ),
  1375. (self.attribute, 'attrTable', icons["attrTable"],
  1376. self.parent.OnShowAttributeTable),
  1377. (None, ),
  1378. (self.preferences, 'preferences', icons["settings"],
  1379. self.parent.OnPreferences),
  1380. (self.help, 'help', Icons["misc"]["help"],
  1381. self.parent.OnHelp),
  1382. ))
  1383. class ToolsToolbar(AbstractToolbar):
  1384. """!Layer Manager Tools toolbar (see wxgui.py)
  1385. """
  1386. def __init__(self, parent):
  1387. AbstractToolbar.__init__(self, parent)
  1388. self.InitToolbar(self._toolbarData())
  1389. # realize the toolbar
  1390. self.Realize()
  1391. def _toolbarData(self):
  1392. """!Toolbar data
  1393. """
  1394. self.georect = wx.NewId()
  1395. self.modeler = wx.NewId()
  1396. self.vdigit = wx.NewId()
  1397. self.mapOutput = wx.NewId()
  1398. self.mapCalc = wx.NewId()
  1399. icons = Icons['layerManager']
  1400. return self._getToolbarData(((self.mapCalc, 'mapCalc', icons["mapcalc"],
  1401. self.parent.OnMapCalculator),
  1402. (self.vdigit, 'vdigit', icons["vdigit"],
  1403. self.parent.OnVDigit),
  1404. (self.georect, 'georectify', Icons["georectify"]["georectify"],
  1405. self.parent.OnGCPManager),
  1406. (self.modeler, 'modeler', icons["modeler"],
  1407. self.parent.OnGModeler),
  1408. (self.mapOutput, 'mapOutput', icons['mapOutput'],
  1409. self.parent.OnPsMap)
  1410. ))
  1411. class PsMapToolbar(AbstractToolbar):
  1412. def __init__(self, parent):
  1413. """!Toolbar Hardcopy Map Output Utility (psmap.py)
  1414. @param parent parent window
  1415. """
  1416. AbstractToolbar.__init__(self, parent)
  1417. self.InitToolbar(self._toolbarData())
  1418. self.Realize()
  1419. self.action = { 'id' : self.pointer }
  1420. self.defaultAction = { 'id' : self.pointer,
  1421. 'bind' : self.parent.OnPointer }
  1422. self.OnTool(None)
  1423. from psmap import haveImage
  1424. if not haveImage:
  1425. self.EnableTool(self.preview, False)
  1426. def _toolbarData(self):
  1427. """!Toolbar data
  1428. """
  1429. self.quit = wx.NewId()
  1430. self.pagesetup = wx.NewId()
  1431. self.pointer = wx.NewId()
  1432. self.zoomIn = wx.NewId()
  1433. self.zoomOut = wx.NewId()
  1434. self.zoomAll = wx.NewId()
  1435. self.addMap = wx.NewId()
  1436. self.addRaster = wx.NewId()
  1437. self.addVector = wx.NewId()
  1438. self.dec = wx.NewId()
  1439. self.delete = wx.NewId()
  1440. self.preview = wx.NewId()
  1441. self.instructionFile = wx.NewId()
  1442. self.generatePS = wx.NewId()
  1443. self.generatePDF = wx.NewId()
  1444. self.loadFile = wx.NewId()
  1445. self.pan = wx.NewId()
  1446. self.help = wx.NewId()
  1447. icons = Icons['psMap']
  1448. return self._getToolbarData(((self.loadFile, 'loadFile', icons['scriptLoad'],
  1449. self.parent.OnLoadFile),
  1450. (self.instructionFile, 'psScript', icons['scriptSave'],
  1451. self.parent.OnInstructionFile),
  1452. (None, ),
  1453. (self.pagesetup, 'page setup', icons['pageSetup'],
  1454. self.parent.OnPageSetup),
  1455. (None, ),
  1456. (self.pointer, "pointer", Icons["displayWindow"]["pointer"],
  1457. self.parent.OnPointer, wx.ITEM_CHECK),
  1458. (self.pan, 'pan', Icons["displayWindow"]['pan'],
  1459. self.parent.OnPan, wx.ITEM_CHECK),
  1460. (self.zoomIn, "zoomin", Icons["displayWindow"]["zoomIn"],
  1461. self.parent.OnZoomIn, wx.ITEM_CHECK),
  1462. (self.zoomOut, "zoomout", Icons["displayWindow"]["zoomOut"],
  1463. self.parent.OnZoomOut, wx.ITEM_CHECK),
  1464. (self.zoomAll, 'full extent', icons['fullExtent'],
  1465. self.parent.OnZoomAll),
  1466. (None, ),
  1467. (self.addMap, 'add map', icons['addMap'],
  1468. self.parent.OnAddMap, wx.ITEM_CHECK),
  1469. (self.addRaster, 'add raster', icons['addRast'],
  1470. self.parent.OnAddRaster),
  1471. (self.addVector, 'add vect', icons['addVect'],
  1472. self.parent.OnAddVect),
  1473. (self.dec, "overlay", Icons["displayWindow"]["overlay"],
  1474. self.parent.OnDecoration),
  1475. (self.delete, "delete", icons["deleteObj"],
  1476. self.parent.OnDelete),
  1477. (None, ),
  1478. (self.preview, "preview", icons["preview"],
  1479. self.parent.OnPreview),
  1480. (self.generatePS, 'generatePS', icons['psExport'],
  1481. self.parent.OnPSFile),
  1482. ( self.generatePDF, 'generatePDF', icons['pdfExport'],
  1483. self.parent.OnPDFFile),
  1484. (None, ),
  1485. (self.help, "help", Icons['misc']['help'],
  1486. self.parent.OnHelp),
  1487. (self.quit, 'quit', icons['quit'],
  1488. self.parent.OnCloseWindow))
  1489. )