toolbars.py 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  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' : 'addLine',
  424. 'type' : 'point',
  425. 'id' : self.addPoint }
  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. ("addLine", icons["addLine"],
  447. self.OnAddLine,
  448. wx.ITEM_CHECK),
  449. ("addBoundary", icons["addBoundary"],
  450. self.OnAddBoundary,
  451. wx.ITEM_CHECK),
  452. ("addCentroid", icons["addCentroid"],
  453. self.OnAddCentroid,
  454. wx.ITEM_CHECK),
  455. ("addArea", icons["addArea"],
  456. self.OnAddArea,
  457. wx.ITEM_CHECK),
  458. ("moveVertex", icons["moveVertex"],
  459. self.OnMoveVertex,
  460. wx.ITEM_CHECK),
  461. ("addVertex", icons["addVertex"],
  462. self.OnAddVertex,
  463. wx.ITEM_CHECK),
  464. ("removeVertex", icons["removeVertex"],
  465. self.OnRemoveVertex,
  466. wx.ITEM_CHECK),
  467. ("editLine", icons["editLine"],
  468. self.OnEditLine,
  469. wx.ITEM_CHECK),
  470. ("moveLine", icons["moveLine"],
  471. self.OnMoveLine,
  472. wx.ITEM_CHECK),
  473. ("deleteLine", icons["deleteLine"],
  474. self.OnDeleteLine,
  475. wx.ITEM_CHECK),
  476. ("displayCats", icons["displayCats"],
  477. self.OnDisplayCats,
  478. wx.ITEM_CHECK),
  479. ("displayAttr", icons["displayAttr"],
  480. self.OnDisplayAttr,
  481. wx.ITEM_CHECK),
  482. ("additionalTools", icons["additionalTools"],
  483. self.OnAdditionalToolMenu,
  484. wx.ITEM_CHECK),
  485. (None, ),
  486. ("undo", icons["undo"],
  487. self.OnUndo),
  488. ("settings", icons["settings"],
  489. self.OnSettings),
  490. ("quit", icons["quit"],
  491. self.OnExit))
  492. )
  493. def OnTool(self, event):
  494. """!Tool selected -> disable selected tool in map toolbar"""
  495. id = self.parent.toolbars['map'].GetAction(type = 'id')
  496. self.parent.toolbars['map'].ToggleTool(id, False)
  497. # set cursor
  498. cursor = self.parent.cursors["cross"]
  499. self.parent.MapWindow.SetCursor(cursor)
  500. # pointer
  501. self.parent.OnPointer(None)
  502. if event:
  503. # deselect previously selected tool
  504. id = self.action.get('id', -1)
  505. if id != event.GetId():
  506. self.ToggleTool(self.action['id'], False)
  507. else:
  508. self.ToggleTool(self.action['id'], True)
  509. self.action['id'] = event.GetId()
  510. event.Skip()
  511. self.ToggleTool(self.action['id'], True)
  512. # clear tmp canvas
  513. if self.action['id'] != id:
  514. self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
  515. if self.digit and \
  516. len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
  517. # cancel action
  518. self.parent.MapWindow.OnMiddleDown(None)
  519. # set focus
  520. self.parent.MapWindow.SetFocus()
  521. def OnAddPoint(self, event):
  522. """!Add point to the vector map Laier"""
  523. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  524. self.action = { 'desc' : "addLine",
  525. 'type' : "point",
  526. 'id' : self.addPoint }
  527. self.parent.MapWindow.mouse['box'] = 'point'
  528. def OnAddLine(self, event):
  529. """!Add line to the vector map layer"""
  530. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  531. self.action = { 'desc' : "addLine",
  532. 'type' : "line",
  533. 'id' : self.addLine }
  534. self.parent.MapWindow.mouse['box'] = 'line'
  535. ### self.parent.MapWindow.polycoords = [] # reset temp line
  536. def OnAddBoundary(self, event):
  537. """!Add boundary to the vector map layer"""
  538. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  539. if self.action['desc'] != 'addLine' or \
  540. self.action['type'] != 'boundary':
  541. self.parent.MapWindow.polycoords = [] # reset temp line
  542. self.action = { 'desc' : "addLine",
  543. 'type' : "boundary",
  544. 'id' : self.addBoundary }
  545. self.parent.MapWindow.mouse['box'] = 'line'
  546. def OnAddCentroid(self, event):
  547. """!Add centroid to the vector map layer"""
  548. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  549. self.action = { 'desc' : "addLine",
  550. 'type' : "centroid",
  551. 'id' : self.addCentroid }
  552. self.parent.MapWindow.mouse['box'] = 'point'
  553. def OnAddArea(self, event):
  554. """!Add area to the vector map layer"""
  555. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  556. self.action = { 'desc' : "addLine",
  557. 'type' : "area",
  558. 'id' : self.addArea }
  559. self.parent.MapWindow.mouse['box'] = 'line'
  560. def OnExit (self, event=None):
  561. """!Quit digitization tool"""
  562. # stop editing of the currently selected map layer
  563. if self.mapLayer:
  564. self.StopEditing()
  565. # close dialogs if still open
  566. if self.settingsDialog:
  567. self.settingsDialog.OnCancel(None)
  568. # set default mouse settings
  569. self.parent.MapWindow.mouse['use'] = "pointer"
  570. self.parent.MapWindow.mouse['box'] = "point"
  571. self.parent.MapWindow.polycoords = []
  572. # disable the toolbar
  573. self.parent.RemoveToolbar("vdigit")
  574. def OnMoveVertex(self, event):
  575. """!Move line vertex"""
  576. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  577. self.action = { 'desc' : "moveVertex",
  578. 'id' : self.moveVertex }
  579. self.parent.MapWindow.mouse['box'] = 'point'
  580. def OnAddVertex(self, event):
  581. """!Add line vertex"""
  582. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  583. self.action = { 'desc' : "addVertex",
  584. 'id' : self.addVertex }
  585. self.parent.MapWindow.mouse['box'] = 'point'
  586. def OnRemoveVertex(self, event):
  587. """!Remove line vertex"""
  588. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  589. self.action = { 'desc' : "removeVertex",
  590. 'id' : self.removeVertex }
  591. self.parent.MapWindow.mouse['box'] = 'point'
  592. def OnEditLine(self, event):
  593. """!Edit line"""
  594. Debug.msg(2, "Digittoolbar.OnEditLine():")
  595. self.action = { 'desc' : "editLine",
  596. 'id' : self.editLine }
  597. self.parent.MapWindow.mouse['box'] = 'line'
  598. def OnMoveLine(self, event):
  599. """!Move line"""
  600. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  601. self.action = { 'desc' : "moveLine",
  602. 'id' : self.moveLine }
  603. self.parent.MapWindow.mouse['box'] = 'box'
  604. def OnDeleteLine(self, event):
  605. """!Delete line"""
  606. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  607. self.action = { 'desc' : "deleteLine",
  608. 'id' : self.deleteLine }
  609. self.parent.MapWindow.mouse['box'] = 'box'
  610. def OnDisplayCats(self, event):
  611. """!Display/update categories"""
  612. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  613. self.action = { 'desc' : "displayCats",
  614. 'id' : self.displayCats }
  615. self.parent.MapWindow.mouse['box'] = 'point'
  616. def OnDisplayAttr(self, event):
  617. """!Display/update attributes"""
  618. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  619. self.action = { 'desc' : "displayAttrs",
  620. 'id' : self.displayAttr }
  621. self.parent.MapWindow.mouse['box'] = 'point'
  622. def OnUndo(self, event):
  623. """!Undo previous changes"""
  624. self.digit.Undo()
  625. event.Skip()
  626. def EnableUndo(self, enable=True):
  627. """!Enable 'Undo' in toolbar
  628. @param enable False for disable
  629. """
  630. if enable:
  631. if self.GetToolEnabled(self.undo) is False:
  632. self.EnableTool(self.undo, True)
  633. else:
  634. if self.GetToolEnabled(self.undo) is True:
  635. self.EnableTool(self.undo, False)
  636. def OnSettings(self, event):
  637. """!Show settings dialog"""
  638. if self.digit is None:
  639. try:
  640. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  641. except SystemExit:
  642. self.digit = self.parent.MapWindow.digit = None
  643. if not self.settingsDialog:
  644. self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
  645. style = wx.DEFAULT_DIALOG_STYLE)
  646. self.settingsDialog.Show()
  647. def OnAdditionalToolMenu(self, event):
  648. """!Menu for additional tools"""
  649. point = wx.GetMousePosition()
  650. toolMenu = wx.Menu()
  651. for label, itype, handler, desc in (
  652. (_('Break selected lines/boundaries at intersection'),
  653. wx.ITEM_CHECK, self.OnBreak, "breakLine"),
  654. (_('Connect selected lines/boundaries'),
  655. wx.ITEM_CHECK, self.OnConnect, "connectLine"),
  656. (_('Copy categories'),
  657. wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
  658. (_('Copy features from (background) vector map'),
  659. wx.ITEM_CHECK, self.OnCopy, "copyLine"),
  660. (_('Duplicate attributes'),
  661. wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
  662. (_('Feature type conversion'),
  663. wx.ITEM_CHECK, self.OnTypeConversion, "typeConv"),
  664. (_('Flip selected lines/boundaries'),
  665. wx.ITEM_CHECK, self.OnFlip, "flipLine"),
  666. (_('Merge selected lines/boundaries'),
  667. wx.ITEM_CHECK, self.OnMerge, "mergeLine"),
  668. (_('Snap selected lines/boundaries (only to nodes)'),
  669. wx.ITEM_CHECK, self.OnSnap, "snapLine"),
  670. (_('Split line/boundary'),
  671. wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
  672. (_('Query features'),
  673. wx.ITEM_CHECK, self.OnQuery, "queryLine"),
  674. (_('Z bulk-labeling of 3D lines'),
  675. wx.ITEM_CHECK, self.OnZBulk, "zbulkLine")):
  676. # Add items to the menu
  677. item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
  678. text = label,
  679. kind = itype)
  680. toolMenu.AppendItem(item)
  681. self.parent.MapWindow.Bind(wx.EVT_MENU, handler, item)
  682. if self.action['desc'] == desc:
  683. item.Check(True)
  684. # Popup the menu. If an item is selected then its handler
  685. # will be called before PopupMenu returns.
  686. self.parent.MapWindow.PopupMenu(toolMenu)
  687. toolMenu.Destroy()
  688. if self.action['desc'] == 'addPoint':
  689. self.ToggleTool(self.additionalTools, False)
  690. def OnCopy(self, event):
  691. """!Copy selected features from (background) vector map"""
  692. if self.action['desc'] == 'copyLine': # select previous action
  693. self.ToggleTool(self.addPoint, True)
  694. self.ToggleTool(self.additionalTools, False)
  695. self.OnAddPoint(event)
  696. return
  697. Debug.msg(2, "Digittoolbar.OnCopy():")
  698. self.action = { 'desc' : "copyLine",
  699. 'id' : self.additionalTools }
  700. self.parent.MapWindow.mouse['box'] = 'box'
  701. def OnSplitLine(self, event):
  702. """!Split line"""
  703. if self.action['desc'] == 'splitLine': # select previous action
  704. self.ToggleTool(self.addPoint, True)
  705. self.ToggleTool(self.additionalTools, False)
  706. self.OnAddPoint(event)
  707. return
  708. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  709. self.action = { 'desc' : "splitLine",
  710. 'id' : self.additionalTools }
  711. self.parent.MapWindow.mouse['box'] = 'point'
  712. def OnCopyCats(self, event):
  713. """!Copy categories"""
  714. if self.action['desc'] == 'copyCats': # select previous action
  715. self.ToggleTool(self.addPoint, True)
  716. self.ToggleTool(self.copyCats, False)
  717. self.OnAddPoint(event)
  718. return
  719. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  720. self.action = { 'desc' : "copyCats",
  721. 'id' : self.additionalTools }
  722. self.parent.MapWindow.mouse['box'] = 'point'
  723. def OnCopyAttrb(self, event):
  724. """!Copy attributes"""
  725. if self.action['desc'] == 'copyAttrs': # select previous action
  726. self.ToggleTool(self.addPoint, True)
  727. self.ToggleTool(self.copyCats, False)
  728. self.OnAddPoint(event)
  729. return
  730. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  731. self.action = { 'desc' : "copyAttrs",
  732. 'id' : self.additionalTools }
  733. self.parent.MapWindow.mouse['box'] = 'point'
  734. def OnFlip(self, event):
  735. """!Flip selected lines/boundaries"""
  736. if self.action['desc'] == 'flipLine': # select previous action
  737. self.ToggleTool(self.addPoint, True)
  738. self.ToggleTool(self.additionalTools, False)
  739. self.OnAddPoint(event)
  740. return
  741. Debug.msg(2, "Digittoolbar.OnFlip():")
  742. self.action = { 'desc' : "flipLine",
  743. 'id' : self.additionalTools }
  744. self.parent.MapWindow.mouse['box'] = 'box'
  745. def OnMerge(self, event):
  746. """!Merge selected lines/boundaries"""
  747. if self.action['desc'] == 'mergeLine': # select previous action
  748. self.ToggleTool(self.addPoint, True)
  749. self.ToggleTool(self.additionalTools, False)
  750. self.OnAddPoint(event)
  751. return
  752. Debug.msg(2, "Digittoolbar.OnMerge():")
  753. self.action = { 'desc' : "mergeLine",
  754. 'id' : self.additionalTools }
  755. self.parent.MapWindow.mouse['box'] = 'box'
  756. def OnBreak(self, event):
  757. """!Break selected lines/boundaries"""
  758. if self.action['desc'] == 'breakLine': # select previous action
  759. self.ToggleTool(self.addPoint, True)
  760. self.ToggleTool(self.additionalTools, False)
  761. self.OnAddPoint(event)
  762. return
  763. Debug.msg(2, "Digittoolbar.OnBreak():")
  764. self.action = { 'desc' : "breakLine",
  765. 'id' : self.additionalTools }
  766. self.parent.MapWindow.mouse['box'] = 'box'
  767. def OnSnap(self, event):
  768. """!Snap selected features"""
  769. if self.action['desc'] == 'snapLine': # select previous action
  770. self.ToggleTool(self.addPoint, True)
  771. self.ToggleTool(self.additionalTools, False)
  772. self.OnAddPoint(event)
  773. return
  774. Debug.msg(2, "Digittoolbar.OnSnap():")
  775. self.action = { 'desc' : "snapLine",
  776. 'id' : self.additionalTools }
  777. self.parent.MapWindow.mouse['box'] = 'box'
  778. def OnConnect(self, event):
  779. """!Connect selected lines/boundaries"""
  780. if self.action['desc'] == 'connectLine': # select previous action
  781. self.ToggleTool(self.addPoint, True)
  782. self.ToggleTool(self.additionalTools, False)
  783. self.OnAddPoint(event)
  784. return
  785. Debug.msg(2, "Digittoolbar.OnConnect():")
  786. self.action = { 'desc' : "connectLine",
  787. 'id' : self.additionalTools }
  788. self.parent.MapWindow.mouse['box'] = 'box'
  789. def OnQuery(self, event):
  790. """!Query selected lines/boundaries"""
  791. if self.action['desc'] == 'queryLine': # select previous action
  792. self.ToggleTool(self.addPoint, True)
  793. self.ToggleTool(self.additionalTools, False)
  794. self.OnAddPoint(event)
  795. return
  796. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  797. UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
  798. self.action = { 'desc' : "queryLine",
  799. 'id' : self.additionalTools }
  800. self.parent.MapWindow.mouse['box'] = 'box'
  801. def OnZBulk(self, event):
  802. """!Z bulk-labeling selected lines/boundaries"""
  803. if not self.digit.IsVector3D():
  804. gcmd.GError(parent = self.parent,
  805. message = _("Vector map is not 3D. Operation canceled."))
  806. return
  807. if self.action['desc'] == 'zbulkLine': # select previous action
  808. self.ToggleTool(self.addPoint, True)
  809. self.ToggleTool(self.additionalTools, False)
  810. self.OnAddPoint(event)
  811. return
  812. Debug.msg(2, "Digittoolbar.OnZBulk():")
  813. self.action = { 'desc' : "zbulkLine",
  814. 'id' : self.additionalTools }
  815. self.parent.MapWindow.mouse['box'] = 'line'
  816. def OnTypeConversion(self, event):
  817. """!Feature type conversion
  818. Supported conversions:
  819. - point <-> centroid
  820. - line <-> boundary
  821. """
  822. if self.action['desc'] == 'typeConv': # select previous action
  823. self.ToggleTool(self.addPoint, True)
  824. self.ToggleTool(self.additionalTools, False)
  825. self.OnAddPoint(event)
  826. return
  827. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  828. self.action = { 'desc' : "typeConv",
  829. 'id' : self.additionalTools }
  830. self.parent.MapWindow.mouse['box'] = 'box'
  831. def OnSelectMap (self, event):
  832. """!Select vector map layer for editing
  833. If there is a vector map layer already edited, this action is
  834. firstly terminated. The map layer is closed. After this the
  835. selected map layer activated for editing.
  836. """
  837. if event.GetSelection() == 0: # create new vector map layer
  838. if self.mapLayer:
  839. openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
  840. else:
  841. openVectorMap = None
  842. dlg = gdialogs.CreateNewVector(self.parent,
  843. exceptMap = openVectorMap, log = self.log,
  844. cmd = (('v.edit',
  845. { 'tool' : 'create' },
  846. 'map')),
  847. disableAdd = True)
  848. if dlg and dlg.GetName():
  849. # add layer to map layer tree
  850. if self.layerTree:
  851. mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
  852. self.layerTree.AddLayer(ltype = 'vector',
  853. lname = mapName,
  854. lcmd = ['d.vect', 'map=%s' % mapName])
  855. vectLayers = self.UpdateListOfLayers(updateTool = True)
  856. selection = vectLayers.index(mapName)
  857. # create table ?
  858. if dlg.IsChecked('table'):
  859. lmgr = self.parent.GetLayerManager()
  860. if lmgr:
  861. lmgr.OnShowAttributeTable(None, selection = 'table')
  862. dlg.Destroy()
  863. else:
  864. self.combo.SetValue(_('Select vector map'))
  865. if dlg:
  866. dlg.Destroy()
  867. return
  868. else:
  869. selection = event.GetSelection() - 1 # first option is 'New vector map'
  870. # skip currently selected map
  871. if self.layers[selection] == self.mapLayer:
  872. return
  873. if self.mapLayer:
  874. # deactive map layer for editing
  875. self.StopEditing()
  876. # select the given map layer for editing
  877. self.StartEditing(self.layers[selection])
  878. event.Skip()
  879. def StartEditing (self, mapLayer):
  880. """!Start editing selected vector map layer.
  881. @param mapLayer MapLayer to be edited
  882. """
  883. # deactive layer
  884. self.mapcontent.ChangeLayerActive(mapLayer, False)
  885. # clean map canvas
  886. self.parent.MapWindow.EraseMap()
  887. # unset background map if needed
  888. if mapLayer:
  889. if UserSettings.Get(group = 'vdigit', key = 'bgmap',
  890. subkey = 'value', internal = True) == mapLayer.GetName():
  891. UserSettings.Set(group = 'vdigit', key = 'bgmap',
  892. subkey = 'value', value = '', internal = True)
  893. self.parent.statusbar.SetStatusText(_("Please wait, "
  894. "opening vector map <%s> for editing...") % mapLayer.GetName(),
  895. 0)
  896. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  897. self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
  898. self.mapLayer = mapLayer
  899. # open vector map
  900. if self.digit.OpenMap(mapLayer.GetName()) is None:
  901. self.mapLayer = None
  902. self.StopEditing()
  903. return False
  904. # update toolbar
  905. self.combo.SetValue(mapLayer.GetName())
  906. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  907. lmgr = self.parent.GetLayerManager()
  908. if lmgr:
  909. lmgr.toolbars['tools'].Enable('vdigit', enable = False)
  910. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  911. # change cursor
  912. if self.parent.MapWindow.mouse['use'] == 'pointer':
  913. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  914. if not self.parent.MapWindow.resize:
  915. self.parent.MapWindow.UpdateMap(render = True)
  916. opacity = mapLayer.GetOpacity(float = True)
  917. if opacity < 1.0:
  918. alpha = int(opacity * 255)
  919. self.digit.UpdateSettings(alpha)
  920. return True
  921. def StopEditing(self):
  922. """!Stop editing of selected vector map layer.
  923. @return True on success
  924. @return False on failure
  925. """
  926. self.combo.SetValue (_('Select vector map'))
  927. # save changes
  928. if self.mapLayer:
  929. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  930. if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
  931. if self.digit.GetUndoLevel() > -1:
  932. dlg = wx.MessageDialog(parent = self.parent,
  933. message = _("Do you want to save changes "
  934. "in vector map <%s>?") % self.mapLayer.GetName(),
  935. caption = _("Save changes?"),
  936. style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  937. if dlg.ShowModal() == wx.ID_NO:
  938. # revert changes
  939. self.digit.Undo(0)
  940. dlg.Destroy()
  941. self.parent.statusbar.SetStatusText(_("Please wait, "
  942. "closing and rebuilding topology of "
  943. "vector map <%s>...") % self.mapLayer.GetName(),
  944. 0)
  945. lmgr = self.parent.GetLayerManager()
  946. if lmgr:
  947. lmgr.toolbars['tools'].Enable('vdigit', enable = True)
  948. lmgr.notebook.SetSelectionByName('output')
  949. self.digit.CloseMap()
  950. if lmgr:
  951. lmgr.GetLogWindow().GetProgressBar().SetValue(0)
  952. lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
  953. self.mapLayer.GetName())
  954. # re-active layer
  955. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  956. if item and self.parent.tree.IsItemChecked(item):
  957. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  958. # change cursor
  959. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  960. self.parent.MapWindow.pdcVector = None
  961. # close dialogs
  962. for dialog in ('attributes', 'category'):
  963. if self.parent.dialogs[dialog]:
  964. self.parent.dialogs[dialog].Close()
  965. self.parent.dialogs[dialog] = None
  966. del self.digit
  967. del self.parent.MapWindow.digit
  968. self.mapLayer = None
  969. self.parent.MapWindow.redrawAll = True
  970. return True
  971. def UpdateListOfLayers (self, updateTool = False):
  972. """!
  973. Update list of available vector map layers.
  974. This list consists only editable layers (in the current mapset)
  975. @param updateTool True to update also toolbar
  976. """
  977. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  978. updateTool)
  979. layerNameSelected = None
  980. # name of currently selected layer
  981. if self.mapLayer:
  982. layerNameSelected = self.mapLayer.GetName()
  983. # select vector map layer in the current mapset
  984. layerNameList = []
  985. self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
  986. l_mapset = grass.gisenv()['MAPSET'])
  987. for layer in self.layers:
  988. if not layer.name in layerNameList: # do not duplicate layer
  989. layerNameList.append (layer.GetName())
  990. if updateTool: # update toolbar
  991. if not self.mapLayer:
  992. value = _('Select vector map')
  993. else:
  994. value = layerNameSelected
  995. if not self.comboid:
  996. self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
  997. choices = [_('New vector map'), ] + layerNameList, size = (80, -1),
  998. style = wx.CB_READONLY)
  999. self.comboid = self.InsertControl(0, self.combo)
  1000. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1001. else:
  1002. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1003. self.Realize()
  1004. return layerNameList
  1005. def GetLayer(self):
  1006. """!Get selected layer for editing -- MapLayer instance"""
  1007. return self.mapLayer
  1008. class ProfileToolbar(AbstractToolbar):
  1009. """!Toolbar for profiling raster map
  1010. """
  1011. def __init__(self, parent):
  1012. AbstractToolbar.__init__(self, parent)
  1013. self.InitToolbar(self._toolbarData())
  1014. # realize the toolbar
  1015. self.Realize()
  1016. def _toolbarData(self):
  1017. """!Toolbar data"""
  1018. icons = Icons['profile']
  1019. return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
  1020. self.parent.OnSelectRaster),
  1021. ('transect', icons["transect"],
  1022. self.parent.OnDrawTransect),
  1023. (None, ),
  1024. ('draw', icons["draw"],
  1025. self.parent.OnCreateProfile),
  1026. ('erase', Icons['displayWindow']["erase"],
  1027. self.parent.OnErase),
  1028. ('drag', Icons['displayWindow']['pan'],
  1029. self.parent.OnDrag),
  1030. ('zoom', Icons['displayWindow']['zoomIn'],
  1031. self.parent.OnZoom),
  1032. ('unzoom', Icons['displayWindow']['zoomBack'],
  1033. self.parent.OnRedraw),
  1034. (None, ),
  1035. ('datasave', icons["save"],
  1036. self.parent.SaveProfileToFile),
  1037. ('image', Icons['displayWindow']["saveFile"],
  1038. self.parent.SaveToFile),
  1039. ('print', Icons['displayWindow']["print"],
  1040. self.parent.PrintMenu),
  1041. (None, ),
  1042. ('settings', icons["options"],
  1043. self.parent.ProfileOptionsMenu),
  1044. ('quit', icons["quit"],
  1045. self.parent.OnQuit),
  1046. ))
  1047. class LMNvizToolbar(AbstractToolbar):
  1048. """!Nviz toolbar
  1049. """
  1050. def __init__(self, parent):
  1051. self.lmgr = parent
  1052. AbstractToolbar.__init__(self, parent)
  1053. # only one dialog can be open
  1054. self.settingsDialog = None
  1055. self.InitToolbar(self._toolbarData())
  1056. # realize the toolbar
  1057. self.Realize()
  1058. def _toolbarData(self):
  1059. """!Toolbar data"""
  1060. icons = Icons['nviz']
  1061. return self._getToolbarData((("nviz_cmd", icons['nviz_cmd'],
  1062. self.OnNvizCmd),
  1063. (None, ),
  1064. ("settings", icons["settings"],
  1065. self.OnSettings),
  1066. ("help", icons["help"],
  1067. self.OnHelp))
  1068. )
  1069. def OnNvizCmd(self, event):
  1070. """!Show nviz_cmd command"""
  1071. self.lmgr.GetLayerTree().GetMapDisplay().GetWindow().OnNvizCmd()
  1072. def OnHelp(self, event):
  1073. """!Show 3D view mode help"""
  1074. if not self.lmgr:
  1075. gcmd.RunCommand('g.manual',
  1076. entry = 'wxGUI.Nviz')
  1077. else:
  1078. log = self.lmgr.GetLogWindow()
  1079. log.RunCmd(['g.manual',
  1080. 'entry=wxGUI.Nviz'])
  1081. def OnSettings(self, event):
  1082. """!Show nviz notebook page"""
  1083. if not self.settingsDialog:
  1084. self.settingsDialog = NvizPreferencesDialog(parent = self.parent)
  1085. self.settingsDialog.Show()
  1086. class ModelToolbar(AbstractToolbar):
  1087. """!Graphical modeler toolbar (see gmodeler.py)
  1088. """
  1089. def __init__(self, parent):
  1090. AbstractToolbar.__init__(self, parent)
  1091. self.InitToolbar(self._toolbarData())
  1092. # realize the toolbar
  1093. self.Realize()
  1094. def _toolbarData(self):
  1095. """!Toolbar data"""
  1096. icons = Icons['modeler']
  1097. return self._getToolbarData((('new', icons['new'],
  1098. self.parent.OnModelNew),
  1099. ('open', icons['open'],
  1100. self.parent.OnModelOpen),
  1101. ('save', icons['save'],
  1102. self.parent.OnModelSave),
  1103. ('image', icons['toImage'],
  1104. self.parent.OnExportImage),
  1105. ('python', icons['toPython'],
  1106. self.parent.OnExportPython),
  1107. (None, ),
  1108. ('action', icons['actionAdd'],
  1109. self.parent.OnAddAction),
  1110. ('data', icons['dataAdd'],
  1111. self.parent.OnAddData),
  1112. ('relation', icons['relation'],
  1113. self.parent.OnDefineRelation),
  1114. (None, ),
  1115. ('redraw', icons['redraw'],
  1116. self.parent.OnCanvasRefresh),
  1117. ('validate', icons['validate'],
  1118. self.parent.OnValidateModel),
  1119. ('run', icons['run'],
  1120. self.parent.OnRunModel),
  1121. (None, ),
  1122. ("variables", icons['variables'],
  1123. self.parent.OnVariables),
  1124. ("settings", icons['settings'],
  1125. self.parent.OnPreferences),
  1126. ("help", Icons['misc']['help'],
  1127. self.parent.OnHelp),
  1128. (None, ),
  1129. ('quit', icons['quit'],
  1130. self.parent.OnCloseWindow))
  1131. )
  1132. class HistogramToolbar(AbstractToolbar):
  1133. """!Histogram toolbar (see histogram.py)
  1134. """
  1135. def __init__(self, parent):
  1136. AbstractToolbar.__init__(self, parent)
  1137. self.InitToolbar(self._toolbarData())
  1138. # realize the toolbar
  1139. self.Realize()
  1140. def _toolbarData(self):
  1141. """!Toolbar data"""
  1142. icons = Icons['displayWindow']
  1143. return self._getToolbarData((('histogram', icons["histogram"],
  1144. self.parent.OnOptions),
  1145. ('rendermao', icons["display"],
  1146. self.parent.OnRender),
  1147. ('erase', icons["erase"],
  1148. self.parent.OnErase),
  1149. ('font', Icons['misc']["font"],
  1150. self.parent.SetHistFont),
  1151. (None, ),
  1152. ('save', icons["saveFile"],
  1153. self.parent.SaveToFile),
  1154. ('hprint', icons["print"],
  1155. self.parent.PrintMenu),
  1156. (None, ),
  1157. ('quit', Icons['misc']["quit"],
  1158. self.parent.OnQuit))
  1159. )
  1160. class LMWorkspaceToolbar(AbstractToolbar):
  1161. """!Layer Manager `workspace` toolbar
  1162. """
  1163. def __init__(self, parent):
  1164. AbstractToolbar.__init__(self, parent)
  1165. self.InitToolbar(self._toolbarData())
  1166. # realize the toolbar
  1167. self.Realize()
  1168. def _toolbarData(self):
  1169. """!Toolbar data
  1170. """
  1171. icons = Icons['layerManager']
  1172. return self._getToolbarData((('newdisplay', icons["newdisplay"],
  1173. self.parent.OnNewDisplay),
  1174. ('newdisplay', icons["newdisplayWMS"],
  1175. self.parent.OnNewDisplayWMS),
  1176. (None, ),
  1177. ('workspaceNew', icons["workspaceNew"],
  1178. self.parent.OnWorkspaceNew),
  1179. ('workspaceOpen', icons["workspaceOpen"],
  1180. self.parent.OnWorkspaceOpen),
  1181. ('workspaceSave', icons["workspaceSave"],
  1182. self.parent.OnWorkspaceSave),
  1183. ))
  1184. class LMDataToolbar(AbstractToolbar):
  1185. """!Layer Manager `data` toolbar
  1186. """
  1187. def __init__(self, parent):
  1188. AbstractToolbar.__init__(self, parent)
  1189. self.InitToolbar(self._toolbarData())
  1190. # realize the toolbar
  1191. self.Realize()
  1192. def _toolbarData(self):
  1193. """!Toolbar data
  1194. """
  1195. icons = Icons['layerManager']
  1196. return self._getToolbarData((('addMulti', icons["addMulti"],
  1197. self.parent.OnAddMaps),
  1198. ('addrast', icons["addRast"],
  1199. self.parent.OnAddRaster),
  1200. ('rastmisc', icons["rastMisc"],
  1201. self.parent.OnAddRasterMisc),
  1202. ('addvect', icons["addVect"],
  1203. self.parent.OnAddVector),
  1204. ('vectmisc', icons["vectMisc"],
  1205. self.parent.OnAddVectorMisc),
  1206. ('addgrp', icons["addGroup"],
  1207. self.parent.OnAddGroup),
  1208. ('addovl', icons["addOverlay"],
  1209. self.parent.OnAddOverlay),
  1210. ('delcmd', icons["delCmd"],
  1211. self.parent.OnDeleteLayer),
  1212. ))
  1213. class LMToolsToolbar(AbstractToolbar):
  1214. """!Layer Manager `tools` toolbar
  1215. """
  1216. def __init__(self, parent):
  1217. AbstractToolbar.__init__(self, parent)
  1218. self.InitToolbar(self._toolbarData())
  1219. # realize the toolbar
  1220. self.Realize()
  1221. def _toolbarData(self):
  1222. """!Toolbar data
  1223. """
  1224. icons = Icons['layerManager']
  1225. return self._getToolbarData((('importMap', icons["import"],
  1226. self.parent.OnImportMenu),
  1227. (None, ),
  1228. ('mapCalc', icons["mapcalc"],
  1229. self.parent.OnMapCalculator),
  1230. ('georect', Icons["georectify"]["georectify"],
  1231. self.parent.OnGCPManager),
  1232. ('modeler', icons["modeler"],
  1233. self.parent.OnGModeler),
  1234. ('mapOutput', icons['mapOutput'],
  1235. self.parent.OnPsMap)
  1236. ))
  1237. class LMMiscToolbar(AbstractToolbar):
  1238. """!Layer Manager `misc` toolbar
  1239. """
  1240. def __init__(self, parent):
  1241. AbstractToolbar.__init__(self, parent)
  1242. self.InitToolbar(self._toolbarData())
  1243. # realize the toolbar
  1244. self.Realize()
  1245. def _toolbarData(self):
  1246. """!Toolbar data
  1247. """
  1248. icons = Icons['layerManager']
  1249. return self._getToolbarData((('settings', icons["settings"],
  1250. self.parent.OnPreferences),
  1251. ('help', Icons["misc"]["help"],
  1252. self.parent.OnHelp),
  1253. ))
  1254. class LMVectorToolbar(AbstractToolbar):
  1255. """!Layer Manager `vector` toolbar
  1256. """
  1257. def __init__(self, parent):
  1258. AbstractToolbar.__init__(self, parent)
  1259. self.InitToolbar(self._toolbarData())
  1260. # realize the toolbar
  1261. self.Realize()
  1262. def _toolbarData(self):
  1263. """!Toolbar data
  1264. """
  1265. icons = Icons['layerManager']
  1266. return self._getToolbarData((('vdigit', icons["vdigit"],
  1267. self.parent.OnVDigit),
  1268. ('attribute', icons["attrTable"],
  1269. self.parent.OnShowAttributeTable),
  1270. ))
  1271. class PsMapToolbar(AbstractToolbar):
  1272. def __init__(self, parent):
  1273. """!Toolbar Hardcopy Map Output Utility (psmap.py)
  1274. @param parent parent window
  1275. """
  1276. AbstractToolbar.__init__(self, parent)
  1277. self.InitToolbar(self._toolbarData())
  1278. self.Realize()
  1279. self.action = { 'id' : self.pointer }
  1280. self.defaultAction = { 'id' : self.pointer,
  1281. 'bind' : self.parent.OnPointer }
  1282. self.OnTool(None)
  1283. from psmap import haveImage
  1284. if not haveImage:
  1285. self.EnableTool(self.preview, False)
  1286. def _toolbarData(self):
  1287. """!Toolbar data
  1288. """
  1289. icons = Icons['psMap']
  1290. return self._getToolbarData((('loadFile', icons['scriptLoad'],
  1291. self.parent.OnLoadFile),
  1292. ('instructionFile', icons['scriptSave'],
  1293. self.parent.OnInstructionFile),
  1294. (None, ),
  1295. ('pagesetup', icons['pageSetup'],
  1296. self.parent.OnPageSetup),
  1297. (None, ),
  1298. ("pointer", Icons["displayWindow"]["pointer"],
  1299. self.parent.OnPointer, wx.ITEM_CHECK),
  1300. ('pan', Icons["displayWindow"]['pan'],
  1301. self.parent.OnPan, wx.ITEM_CHECK),
  1302. ("zoomin", Icons["displayWindow"]["zoomIn"],
  1303. self.parent.OnZoomIn, wx.ITEM_CHECK),
  1304. ("zoomout", Icons["displayWindow"]["zoomOut"],
  1305. self.parent.OnZoomOut, wx.ITEM_CHECK),
  1306. ('zoomAll', icons['fullExtent'],
  1307. self.parent.OnZoomAll),
  1308. (None, ),
  1309. ('addMap', icons['addMap'],
  1310. self.parent.OnAddMap, wx.ITEM_CHECK),
  1311. ('addRaster', icons['addRast'],
  1312. self.parent.OnAddRaster),
  1313. ('addVector', icons['addVect'],
  1314. self.parent.OnAddVect),
  1315. ("dec", Icons["displayWindow"]["overlay"],
  1316. self.parent.OnDecoration),
  1317. ("delete", icons["deleteObj"],
  1318. self.parent.OnDelete),
  1319. (None, ),
  1320. ("preview", icons["preview"],
  1321. self.parent.OnPreview),
  1322. ('generatePS', icons['psExport'],
  1323. self.parent.OnPSFile),
  1324. ('generatePDF', icons['pdfExport'],
  1325. self.parent.OnPDFFile),
  1326. (None, ),
  1327. ("help", Icons['misc']['help'],
  1328. self.parent.OnHelp),
  1329. ('quit', icons['quit'],
  1330. self.parent.OnCloseWindow))
  1331. )