toolbars.py 64 KB

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