toolbars.py 76 KB

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