toolbars.py 76 KB

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