toolbars.py 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. """
  2. MODULE: toolbar
  3. CLASSES:
  4. * AbstractToolbar
  5. * MapToolbar
  6. * GRToolbar
  7. * GCPToolbar
  8. * VDigitToolbar
  9. * ProfileToolbar
  10. * NvizToolbar
  11. PURPOSE: Toolbars for Map Display window
  12. AUTHORS: The GRASS Development Team
  13. Michael Barton, Martin Landa, Jachym Cepicky
  14. COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
  15. This program is free software under the GNU General Public
  16. License (>=v2). Read the file COPYING that comes with GRASS
  17. for details.
  18. """
  19. import wx
  20. import os, sys
  21. import globalvar
  22. import gcmd
  23. import grassenv
  24. import gdialogs
  25. import vdigit
  26. from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
  27. from debug import Debug as Debug
  28. from icon import Icons as Icons
  29. from preferences import globalSettings as UserSettings
  30. gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
  31. sys.path.append(gmpath)
  32. class AbstractToolbar(object):
  33. """Abstract toolbar class"""
  34. def __init__():
  35. pass
  36. def InitToolbar(self, parent, toolbar, toolData):
  37. """Initialize toolbar, i.e. add tools to the toolbar
  38. @return list of ids (of added tools)
  39. """
  40. for tool in toolData:
  41. self.CreateTool(parent, toolbar, *tool)
  42. self._toolbar = toolbar
  43. self._data = toolData
  44. def ToolbarData(self):
  45. """Toolbar data"""
  46. return None
  47. def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
  48. shortHelp, longHelp, handler):
  49. """Add tool to the toolbar
  50. @return id of tool
  51. """
  52. bmpDisabled=wx.NullBitmap
  53. if label:
  54. toolWin = toolbar.AddLabelTool(tool, label, bitmap,
  55. bmpDisabled, kind,
  56. shortHelp, longHelp)
  57. parent.Bind(wx.EVT_TOOL, handler, toolWin)
  58. else: # add separator
  59. toolbar.AddSeparator()
  60. return tool
  61. def GetToolbar(self):
  62. """Get toolbar widget reference"""
  63. return self._toolbar
  64. def EnableLongHelp(self, enable=True):
  65. """Enable/disable long help
  66. @param enable True for enable otherwise disable
  67. """
  68. for tool in self._data:
  69. if tool[0] == '': # separator
  70. continue
  71. if enable:
  72. self._toolbar.SetToolLongHelp(tool[0], tool[5])
  73. else:
  74. self._toolbar.SetToolLongHelp(tool[0], "")
  75. class MapToolbar(AbstractToolbar):
  76. """
  77. Main Map Display toolbar
  78. """
  79. def __init__(self, mapdisplay, map):
  80. self.mapcontent = map
  81. self.mapdisplay = mapdisplay
  82. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  83. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  84. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  85. # optional tools
  86. self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value='Tools',
  87. choices=['Digitize', 'Nviz'], style=wx.CB_READONLY, size=(90, -1))
  88. self.comboid = self.toolbar.AddControl(self.combo)
  89. self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
  90. # realize the toolbar
  91. self.toolbar.Realize()
  92. #workaround for Mac bug. May be fixed by 2.8.8, but not before then.
  93. self.combo.Hide()
  94. self.combo.Show()
  95. def ToolbarData(self):
  96. """Toolbar data"""
  97. self.displaymap = wx.NewId()
  98. self.rendermap = wx.NewId()
  99. self.erase = wx.NewId()
  100. self.pointer = wx.NewId()
  101. self.query = wx.NewId()
  102. self.pan = wx.NewId()
  103. self.zoomin = wx.NewId()
  104. self.zoomout = wx.NewId()
  105. self.zoomback = wx.NewId()
  106. self.zoommenu = wx.NewId()
  107. self.analyze = wx.NewId()
  108. self.dec = wx.NewId()
  109. self.savefile = wx.NewId()
  110. self.printmap = wx.NewId()
  111. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  112. return (
  113. (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
  114. wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
  115. self.mapdisplay.OnDraw),
  116. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  117. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  118. self.mapdisplay.OnRender),
  119. (self.erase, "erase", Icons["erase"].GetBitmap(),
  120. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  121. self.mapdisplay.OnErase),
  122. ("", "", "", "", "", "", ""),
  123. (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
  124. wx.ITEM_RADIO, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
  125. self.mapdisplay.OnPointer),
  126. (self.query, "queryDisplay", Icons["queryDisplay"].GetBitmap(),
  127. wx.ITEM_RADIO, Icons["queryDisplay"].GetLabel(), Icons["queryDisplay"].GetDesc(),
  128. self.mapdisplay.OnQuery),
  129. (self.pan, "pan", Icons["pan"].GetBitmap(),
  130. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  131. self.mapdisplay.OnPan),
  132. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  133. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  134. self.mapdisplay.OnZoomIn),
  135. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  136. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  137. self.mapdisplay.OnZoomOut),
  138. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  139. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  140. self.mapdisplay.OnZoomBack),
  141. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  142. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  143. self.mapdisplay.OnZoomMenu),
  144. ("", "", "", "", "", "", ""),
  145. (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
  146. wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
  147. self.mapdisplay.OnAnalyze),
  148. ("", "", "", "", "", "", ""),
  149. (self.dec, "overlay", Icons["overlay"].GetBitmap(),
  150. wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
  151. self.mapdisplay.OnDecoration),
  152. ("", "", "", "", "", "", ""),
  153. (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
  154. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  155. self.mapdisplay.SaveToFile),
  156. (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
  157. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  158. self.mapdisplay.PrintMenu),
  159. ("", "", "", "", "", "", "")
  160. )
  161. def OnSelectTool(self, event):
  162. """
  163. Select / enable tool available in tools list
  164. """
  165. tool = event.GetString()
  166. if tool == "Digitize" and not self.mapdisplay.toolbars['vdigit']:
  167. self.mapdisplay.AddToolbar("vdigit")
  168. elif tool == "Nviz" and not self.mapdisplay.toolbars['nviz']:
  169. self.mapdisplay.AddToolbar("nviz")
  170. def Enable2D(self, enabled):
  171. """Enable/Disable 2D display mode specific tools"""
  172. for tool in (self.pointer,
  173. self.query,
  174. self.pan,
  175. self.zoomin,
  176. self.zoomout,
  177. self.zoomback,
  178. self.zoommenu,
  179. self.analyze,
  180. self.dec,
  181. self.savefile,
  182. self.printmap):
  183. self.toolbar.EnableTool(tool, enabled)
  184. class GRToolbar(AbstractToolbar):
  185. """
  186. Georectify Display toolbar
  187. """
  188. def __init__(self, mapdisplay, map):
  189. self.mapcontent = map
  190. self.mapdisplay = mapdisplay
  191. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  192. # self.SetToolBar(self.toolbar)
  193. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  194. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  195. # realize the toolbar
  196. self.toolbar.Realize()
  197. def ToolbarData(self):
  198. """Toolbar data"""
  199. self.displaymap = wx.NewId()
  200. self.rendermap = wx.NewId()
  201. self.erase = wx.NewId()
  202. self.gcpset = wx.NewId()
  203. self.pan = wx.NewId()
  204. self.zoomin = wx.NewId()
  205. self.zoomout = wx.NewId()
  206. self.zoomback = wx.NewId()
  207. self.zoommenu = 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.mapdisplay.OnDraw),
  213. (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
  214. wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
  215. self.mapdisplay.OnRender),
  216. (self.erase, "erase", Icons["erase"].GetBitmap(),
  217. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  218. self.mapdisplay.OnErase),
  219. ("", "", "", "", "", "", ""),
  220. (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
  221. wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
  222. self.mapdisplay.OnPointer),
  223. (self.pan, "pan", Icons["pan"].GetBitmap(),
  224. wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  225. self.mapdisplay.OnPan),
  226. (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
  227. wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  228. self.mapdisplay.OnZoomIn),
  229. (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
  230. wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
  231. self.mapdisplay.OnZoomOut),
  232. (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
  233. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  234. self.mapdisplay.OnZoomBack),
  235. (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
  236. wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
  237. self.mapdisplay.OnZoomMenu),
  238. )
  239. class GCPToolbar(AbstractToolbar):
  240. """
  241. Toolbar for digitization
  242. """
  243. def __init__(self, parent, mapdisplay, map):
  244. self.parent = parent # GCP
  245. self.mapcontent = map
  246. self.mapdisplay = mapdisplay
  247. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  248. # self.SetToolBar(self.toolbar)
  249. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  250. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  251. # realize the toolbar
  252. self.toolbar.Realize()
  253. def ToolbarData(self):
  254. self.gcpSave = wx.NewId()
  255. self.gcpAdd = wx.NewId()
  256. self.gcpDelete = wx.NewId()
  257. self.gcpClear = wx.NewId()
  258. self.gcpReload = wx.NewId()
  259. self.rms = wx.NewId()
  260. self.georect = wx.NewId()
  261. self.settings = wx.NewId()
  262. self.quit = wx.NewId()
  263. return (
  264. (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
  265. wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
  266. self.parent.SaveGCPs),
  267. (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
  268. wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
  269. self.parent.AddGCP),
  270. (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
  271. wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
  272. self.parent.DeleteGCP),
  273. (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
  274. wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
  275. self.parent.ClearGCP),
  276. (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
  277. wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
  278. self.parent.ReloadGCPs),
  279. ("", "", "", "", "", "", ""),
  280. (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
  281. wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
  282. self.parent.OnRMS),
  283. (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
  284. wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
  285. self.parent.OnGeorect),
  286. ("", "", "", "", "", "", ""),
  287. (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
  288. wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
  289. self.parent.OnSettings),
  290. (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
  291. wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
  292. self.parent.OnQuit)
  293. )
  294. class VDigitToolbar(AbstractToolbar):
  295. """
  296. Toolbar for digitization
  297. """
  298. def __init__(self, parent, map, layerTree=None):
  299. self.mapcontent = map # Map class instance
  300. self.parent = parent # MapFrame
  301. self.layerTree = layerTree # reference to layer tree associated to map display
  302. # selected map to digitize
  303. self.layerSelectedID = None
  304. self.layers = []
  305. # default action (digitize new point, line, etc.)
  306. self.action = "addLine"
  307. self.type = "point"
  308. self.addString = ""
  309. self.comboid = None
  310. # only one dialog can be open
  311. self.settingsDialog = None
  312. # create toolbars (two rows optionaly)
  313. self.toolbar = []
  314. self.numOfRows = 1 # number of rows for toolbar
  315. for row in range(0, self.numOfRows):
  316. self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
  317. self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
  318. self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
  319. # create toolbar
  320. if self.numOfRows == 1:
  321. rowdata=None
  322. else:
  323. rowdata = row
  324. self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
  325. # list of available vector maps
  326. self.UpdateListOfLayers(updateTool=True)
  327. # realize toolbar
  328. for row in range(0, self.numOfRows):
  329. self.toolbar[row].Realize()
  330. # disable undo/redo
  331. self.toolbar[0].EnableTool(self.undo, False)
  332. # toogle to pointer by default
  333. self.OnTool(None)
  334. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  335. self.toolbar[0].EnableTool(self.copyCats, False) # not implemented (TODO)
  336. self.toolbar[0].SetToolShortHelp(self.copyCats, _("Not implemented yet"))
  337. def ToolbarData(self, row=None):
  338. """
  339. Toolbar data
  340. """
  341. data = []
  342. if row is None or row == 0:
  343. self.addPoint = wx.NewId()
  344. self.addLine = wx.NewId()
  345. self.addBoundary = wx.NewId()
  346. self.addCentroid = wx.NewId()
  347. self.moveVertex = wx.NewId()
  348. self.addVertex = wx.NewId()
  349. self.removeVertex = wx.NewId()
  350. self.splitLine = wx.NewId()
  351. self.editLine = wx.NewId()
  352. self.moveLine = wx.NewId()
  353. self.deleteLine = wx.NewId()
  354. self.additionalTools = wx.NewId()
  355. self.displayCats = wx.NewId()
  356. self.displayAttr = wx.NewId()
  357. self.copyCats = wx.NewId()
  358. data = [("", "", "", "", "", "", ""),
  359. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  360. wx.ITEM_RADIO, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  361. self.OnAddPoint),
  362. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  363. wx.ITEM_RADIO, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  364. self.OnAddLine),
  365. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  366. wx.ITEM_RADIO, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  367. self.OnAddBoundary),
  368. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  369. wx.ITEM_RADIO, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  370. self.OnAddCentroid),
  371. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  372. wx.ITEM_RADIO, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  373. self.OnMoveVertex),
  374. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  375. wx.ITEM_RADIO, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  376. self.OnAddVertex),
  377. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  378. wx.ITEM_RADIO, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  379. self.OnRemoveVertex),
  380. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  381. wx.ITEM_RADIO, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  382. self.OnSplitLine),
  383. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  384. wx.ITEM_RADIO, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  385. self.OnEditLine),
  386. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  387. wx.ITEM_RADIO, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  388. self.OnMoveLine),
  389. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  390. wx.ITEM_RADIO, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  391. self.OnDeleteLine),
  392. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  393. wx.ITEM_RADIO, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  394. self.OnDisplayCats),
  395. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  396. wx.ITEM_RADIO, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  397. self.OnCopyCats),
  398. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  399. wx.ITEM_RADIO, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  400. self.OnDisplayAttr),
  401. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  402. wx.ITEM_RADIO, Icons["digAdditionalTools"].GetLabel(),
  403. Icons["digAdditionalTools"].GetDesc(),
  404. self.OnAdditionalToolMenu)]
  405. if row is None or row == 1:
  406. self.undo = wx.NewId()
  407. self.settings = wx.NewId()
  408. self.exit = wx.NewId()
  409. data.append(("", "", "", "", "", "", ""))
  410. data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  411. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  412. self.OnUndo))
  413. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  414. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  415. # self.OnRedo))
  416. data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  417. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  418. self.OnSettings))
  419. data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
  420. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  421. self.OnExit))
  422. return data
  423. def OnTool(self, event):
  424. """Tool selected -> toggle tool to pointer"""
  425. id = self.parent.toolbars['map'].pointer
  426. self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
  427. self.parent.toolbars['map'].mapdisplay.OnPointer(event)
  428. if event:
  429. event.Skip()
  430. def OnAddPoint(self, event):
  431. """Add point to the vector map Laier"""
  432. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  433. self.action = "addLine"
  434. self.type = "point"
  435. self.parent.MapWindow.mouse['box'] = 'point'
  436. def OnAddLine(self, event):
  437. """Add line to the vector map layer"""
  438. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  439. self.action = "addLine"
  440. self.type = "line"
  441. self.parent.MapWindow.mouse['box'] = 'line'
  442. self.parent.MapWindow.polycoords = [] # reset temp line
  443. def OnAddBoundary(self, event):
  444. """Add boundary to the vector map layer"""
  445. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  446. self.action = "addLine"
  447. self.type = "boundary"
  448. self.parent.MapWindow.mouse['box'] = 'line'
  449. self.parent.MapWindow.polycoords = [] # reset temp line
  450. def OnAddCentroid(self, event):
  451. """Add centroid to the vector map layer"""
  452. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  453. self.action = "addLine"
  454. self.type = "centroid"
  455. self.parent.MapWindow.mouse['box'] = 'point'
  456. def OnExit (self, event=None):
  457. """Quit digitization tool"""
  458. # stop editing of the currently selected map layer
  459. try:
  460. self.StopEditing(self.layers[self.layerSelectedID])
  461. except:
  462. pass
  463. # close dialogs if still open
  464. if self.settingsDialog:
  465. self.settingsDialog.OnCancel(None)
  466. if self.parent.dialogs['category']:
  467. self.parent.dialogs['category'].OnCancel(None)
  468. if self.parent.dialogs['attributes']:
  469. self.parent.dialogs['attributes'].OnCancel(None)
  470. # disable the toolbar
  471. self.parent.RemoveToolbar ("vdigit")
  472. def OnMoveVertex(self, event):
  473. """Move line vertex"""
  474. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  475. self.action = "moveVertex"
  476. self.parent.MapWindow.mouse['box'] = 'point'
  477. def OnAddVertex(self, event):
  478. """Add line vertex"""
  479. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  480. self.action = "addVertex"
  481. self.parent.MapWindow.mouse['box'] = 'point'
  482. def OnRemoveVertex(self, event):
  483. """Remove line vertex"""
  484. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  485. self.action = "removeVertex"
  486. self.parent.MapWindow.mouse['box'] = 'point'
  487. def OnSplitLine(self, event):
  488. """Split line"""
  489. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  490. self.action = "splitLine"
  491. self.parent.MapWindow.mouse['box'] = 'point'
  492. def OnEditLine(self, event):
  493. """Edit line"""
  494. Debug.msg(2, "Digittoolbar.OnEditLine():")
  495. self.action="editLine"
  496. self.parent.MapWindow.mouse['box'] = 'line'
  497. def OnMoveLine(self, event):
  498. """Move line"""
  499. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  500. self.action = "moveLine"
  501. self.parent.MapWindow.mouse['box'] = 'box'
  502. def OnDeleteLine(self, event):
  503. """Delete line"""
  504. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  505. self.action = "deleteLine"
  506. self.parent.MapWindow.mouse['box'] = 'box'
  507. def OnDisplayCats(self, event):
  508. """Display/update categories"""
  509. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  510. self.action="displayCats"
  511. self.parent.MapWindow.mouse['box'] = 'point'
  512. def OnDisplayAttr(self, event):
  513. """Display/update attributes"""
  514. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  515. self.action="displayAttrs"
  516. self.parent.MapWindow.mouse['box'] = 'point'
  517. def OnCopyCats(self, event):
  518. """Copy categories"""
  519. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  520. self.action="copyCats"
  521. self.parent.MapWindow.mouse['box'] = 'point'
  522. def OnUndo(self, event):
  523. """Undo previous changes"""
  524. self.parent.digit.Undo()
  525. event.Skip()
  526. def EnableUndo(self, enable=True):
  527. """Enable 'Undo' in toolbar
  528. @param enable False for disable
  529. """
  530. if enable:
  531. if self.toolbar[0].GetToolEnabled(self.undo) is False:
  532. self.toolbar[0].EnableTool(self.undo, True)
  533. else:
  534. if self.toolbar[0].GetToolEnabled(self.undo) is True:
  535. self.toolbar[0].EnableTool(self.undo, False)
  536. def OnSettings(self, event):
  537. """Show settings dialog"""
  538. if self.parent.digit is None:
  539. reload(vdigit)
  540. from vdigit import Digit as Digit
  541. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  542. if not self.settingsDialog:
  543. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  544. style=wx.DEFAULT_DIALOG_STYLE)
  545. self.settingsDialog.Show()
  546. def OnAdditionalToolMenu(self, event):
  547. """Menu for additional tools"""
  548. point = wx.GetMousePosition()
  549. toolMenu = wx.Menu()
  550. # Add items to the menu
  551. copy = wx.MenuItem(toolMenu, wx.ID_ANY, _('Copy features from (background) vector map'))
  552. toolMenu.AppendItem(copy)
  553. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  554. flip = wx.MenuItem(toolMenu, wx.ID_ANY, _('Flip selected lines/boundaries'))
  555. toolMenu.AppendItem(flip)
  556. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  557. merge = wx.MenuItem(toolMenu, wx.ID_ANY, _('Merge selected lines/boundaries'))
  558. toolMenu.AppendItem(merge)
  559. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  560. breakL = wx.MenuItem(toolMenu, wx.ID_ANY, _('Break selected lines/boundaries at intersection'))
  561. toolMenu.AppendItem(breakL)
  562. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  563. snap = wx.MenuItem(toolMenu, wx.ID_ANY, _('Snap selected lines/boundaries (only to nodes)'))
  564. toolMenu.AppendItem(snap)
  565. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  566. connect = wx.MenuItem(toolMenu, wx.ID_ANY, _('Connect two selected lines/boundaries'))
  567. toolMenu.AppendItem(connect)
  568. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  569. query = wx.MenuItem(toolMenu, wx.ID_ANY, _('Query tool'))
  570. toolMenu.AppendItem(query)
  571. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  572. zbulk = wx.MenuItem(toolMenu, wx.ID_ANY, _('Z bulk-labeling of 3D lines'))
  573. toolMenu.AppendItem(zbulk)
  574. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  575. typeconv = wx.MenuItem(toolMenu, wx.ID_ANY, _('Feature type conversion'))
  576. toolMenu.AppendItem(typeconv)
  577. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  578. # Popup the menu. If an item is selected then its handler
  579. # will be called before PopupMenu returns.
  580. self.parent.MapWindow.PopupMenu(toolMenu)
  581. toolMenu.Destroy()
  582. def OnCopy(self, event):
  583. """Copy selected features from (background) vector map"""
  584. Debug.msg(2, "Digittoolbar.OnCopy():")
  585. self.action="copyLine"
  586. self.parent.MapWindow.mouse['box'] = 'box'
  587. def OnFlip(self, event):
  588. """Flip selected lines/boundaries"""
  589. Debug.msg(2, "Digittoolbar.OnFlip():")
  590. self.action="flipLine"
  591. self.parent.MapWindow.mouse['box'] = 'box'
  592. def OnMerge(self, event):
  593. """Merge selected lines/boundaries"""
  594. Debug.msg(2, "Digittoolbar.OnMerge():")
  595. self.action="mergeLine"
  596. self.parent.MapWindow.mouse['box'] = 'box'
  597. def OnBreak(self, event):
  598. """Break selected lines/boundaries"""
  599. Debug.msg(2, "Digittoolbar.OnBreak():")
  600. self.action="breakLine"
  601. self.parent.MapWindow.mouse['box'] = 'box'
  602. def OnSnap(self, event):
  603. """Snap selected features"""
  604. Debug.msg(2, "Digittoolbar.OnSnap():")
  605. self.action="snapLine"
  606. self.parent.MapWindow.mouse['box'] = 'box'
  607. def OnConnect(self, event):
  608. """Connect selected lines/boundaries"""
  609. Debug.msg(2, "Digittoolbar.OnConnect():")
  610. self.action="connectLine"
  611. self.parent.MapWindow.mouse['box'] = 'point'
  612. def OnQuery(self, event):
  613. """Query selected lines/boundaries"""
  614. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  615. UserSettings.Get(group='vdigit', key='query', subkey='type'))
  616. self.action="queryLine"
  617. self.parent.MapWindow.mouse['box'] = 'box'
  618. def OnZBulk(self, event):
  619. """Z bulk-labeling selected lines/boundaries"""
  620. Debug.msg(2, "Digittoolbar.OnZBulk():")
  621. self.action="zbulkLine"
  622. self.parent.MapWindow.mouse['box'] = 'line'
  623. def OnTypeConversion(self, event):
  624. """Feature type conversion
  625. Supported conversions:
  626. - point <-> centroid
  627. - line <-> boundary
  628. """
  629. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  630. self.action="typeConv"
  631. self.parent.MapWindow.mouse['box'] = 'box'
  632. def OnSelectMap (self, event):
  633. """
  634. Select vector map layer for editing
  635. If there is a vector map layer already edited, this action is
  636. firstly terminated. The map layer is closed. After this the
  637. selected map layer activated for editing.
  638. """
  639. if event.GetSelection() == 0: # create new vector map layer
  640. if self.layerSelectedID is not None:
  641. openVectorMap = self.layers[self.layerSelectedID].name.split('@')[0]
  642. else:
  643. openVectorMap = None
  644. mapName = gdialogs.CreateNewVector(self.parent,
  645. exceptMap=openVectorMap)
  646. if mapName:
  647. # add layer to map layer tree
  648. if self.layerTree:
  649. self.layerTree.AddLayer(ltype='vector',
  650. lname=mapName,
  651. lchecked=True,
  652. lopacity=1.0,
  653. lcmd=['d.vect', 'map=%s' % mapName])
  654. vectLayers = self.UpdateListOfLayers(updateTool=True)
  655. selection = vectLayers.index(mapName)
  656. else:
  657. pass # TODO (no Layer Manager)
  658. else:
  659. self.combo.SetValue(_('Select vector map'))
  660. return
  661. else:
  662. selection = event.GetSelection() - 1 # first option is 'New vector map'
  663. if self.layerSelectedID == selection:
  664. return False
  665. if self.layerSelectedID != None: # deactive map layer for editing
  666. self.StopEditing(self.layers[self.layerSelectedID])
  667. # select the given map layer for editing
  668. self.layerSelectedID = selection
  669. self.StartEditing(self.layers[self.layerSelectedID])
  670. event.Skip()
  671. return True
  672. def StartEditing (self, layerSelected):
  673. """
  674. Start editing of selected vector map layer.
  675. @param layerSelectedId id of layer to be edited
  676. @return True on success
  677. @return False on error
  678. """
  679. reload(vdigit)
  680. from vdigit import Digit as Digit
  681. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  682. try:
  683. self.layerSelectedID = self.layers.index(layerSelected)
  684. mapLayer = self.layers[self.layerSelectedID]
  685. except:
  686. return False
  687. try:
  688. self.parent.digit.SetMapName(mapLayer.name)
  689. except gcmd.DigitError, e:
  690. self.layerSelectedID = None
  691. print >> sys.stderr, e # wxMessageBox
  692. return False
  693. # update toolbar
  694. self.combo.SetValue (layerSelected.name)
  695. self.parent.toolbars['map'].combo.SetValue ('Digitize')
  696. # set initial category number for new features (layer=1), etc.
  697. Debug.msg (4, "VDigitToolbar.StartEditing(): layerSelectedID=%d layer=%s" % \
  698. (self.layerSelectedID, mapLayer.name))
  699. # deactive layer
  700. self.mapcontent.ChangeLayerActive(mapLayer, False)
  701. # change cursor
  702. if self.parent.MapWindow.mouse['use'] == 'pointer':
  703. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  704. # create pseudoDC for drawing the map
  705. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  706. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  707. # self.parent.MapWindow.UpdateMap()
  708. if not self.parent.MapWindow.resize:
  709. self.parent.MapWindow.UpdateMap(render=True)
  710. return True
  711. def StopEditing (self, layerSelected):
  712. """
  713. Stop editing of selected vector map layer.
  714. """
  715. if self.layers[self.layerSelectedID] == layerSelected:
  716. self.layerSelectedID = None
  717. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % \
  718. (layerSelected.name))
  719. self.combo.SetValue (_('Select vector map'))
  720. # save changes (only for vdigit)
  721. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  722. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  723. if self.parent.digit.GetUndoLevel() > 0:
  724. dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
  725. "in vector map <%s>?") % layerSelected.name,
  726. caption=_("Save changes?"),
  727. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  728. if dlg.ShowModal() == wx.ID_NO:
  729. # revert changes
  730. self.parent.digit.Undo(0)
  731. dlg.Destroy()
  732. self.parent.digit.SetMapName(None) # -> close map
  733. # re-active layer
  734. item = self.parent.tree.FindItemByData('maplayer', layerSelected)
  735. if item and self.parent.tree.IsItemChecked(item):
  736. self.mapcontent.ChangeLayerActive(layerSelected, True)
  737. # change cursor
  738. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  739. # disable pseudodc for vector map layer
  740. self.parent.MapWindow.pdcVector = None
  741. self.parent.digit.driver.SetDevice(None)
  742. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  743. self.parent.digit = None
  744. return True
  745. return False
  746. def UpdateListOfLayers (self, updateTool=False):
  747. """
  748. Update list of available vector map layers.
  749. This list consists only editable layers (in the current mapset)
  750. Optionaly also update toolbar
  751. """
  752. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  753. updateTool)
  754. layerNameSelected = None
  755. if self.layerSelectedID != None: # name of currently selected layer
  756. layerNameSelected = self.layers[self.layerSelectedID].name
  757. # select vector map layer in the current mapset
  758. layerNameList = []
  759. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  760. l_mapset=grassenv.GetGRASSVariable('MAPSET'))
  761. for layer in self.layers:
  762. if not layer.name in layerNameList: # do not duplicate layer
  763. layerNameList.append (layer.name)
  764. if updateTool: # update toolbar
  765. if self.layerSelectedID == None:
  766. value = _('Select vector map')
  767. else:
  768. value = layerNameSelected
  769. if not self.comboid:
  770. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  771. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  772. style=wx.CB_READONLY)
  773. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  774. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  775. else:
  776. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  777. # update layer index
  778. try:
  779. self.layerSelectedID = layerNameList.index(value)
  780. except ValueError:
  781. self.layerSelectedID = None
  782. self.toolbar[self.numOfRows-1].Realize()
  783. return layerNameList
  784. class ProfileToolbar(AbstractToolbar):
  785. """
  786. Toolbar for digitization
  787. """
  788. def __init__(self, parent, mapdisplay, map):
  789. self.parent = parent
  790. self.mapcontent = map
  791. self.mapdisplay = mapdisplay
  792. self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
  793. # self.SetToolBar(self.toolbar)
  794. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  795. self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
  796. # realize the toolbar
  797. self.toolbar.Realize()
  798. def ToolbarData(self):
  799. """Toolbar data"""
  800. self.transect = wx.NewId()
  801. self.addraster = wx.NewId()
  802. self.draw = wx.NewId()
  803. self.options = wx.NewId()
  804. self.drag = wx.NewId()
  805. self.zoom = wx.NewId()
  806. self.unzoom = wx.NewId()
  807. self.erase = wx.NewId()
  808. self.save = wx.NewId()
  809. self.printer = wx.NewId()
  810. self.quit = wx.NewId()
  811. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  812. return (
  813. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  814. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  815. self.parent.OnDrawTransect),
  816. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  817. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  818. self.parent.OnSelectRaster),
  819. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  820. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  821. self.parent.OnCreateProfile),
  822. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  823. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  824. self.parent.ProfileOptionsMenu),
  825. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  826. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  827. self.parent.OnDrag),
  828. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  829. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  830. self.parent.OnZoom),
  831. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  832. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  833. self.parent.OnRedraw),
  834. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  835. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  836. self.parent.OnErase),
  837. ("", "", "", "", "", "", ""),
  838. (self.save, 'save', Icons["savefile"].GetBitmap(),
  839. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  840. self.parent.SaveToFile),
  841. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  842. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  843. self.parent.PrintMenu),
  844. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  845. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  846. self.parent.OnQuit),
  847. )
  848. class NvizToolbar(AbstractToolbar):
  849. """
  850. Nviz toolbar
  851. """
  852. def __init__(self, parent, map):
  853. self.parent = parent
  854. self.mapcontent = map
  855. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  856. # self.SetToolBar(self.toolbar)
  857. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  858. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  859. # realize the toolbar
  860. self.toolbar.Realize()
  861. def ToolbarData(self):
  862. """Toolbar data"""
  863. self.settings = wx.NewId()
  864. self.quit = wx.NewId()
  865. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  866. return (
  867. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  868. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  869. self.OnSettings),
  870. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  871. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  872. self.OnExit),
  873. )
  874. def OnSettings(self, event):
  875. win = self.parent.nvizToolWin
  876. if not win.IsShown():
  877. self.parent.nvizToolWin.Show()
  878. else:
  879. self.parent.nvizToolWin.Hide()
  880. def OnExit (self, event=None):
  881. """Quit nviz tool (swith to 2D mode)"""
  882. # disable the toolbar
  883. self.parent.RemoveToolbar ("nviz")