toolbars.py 72 KB

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