toolbars.py 75 KB

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