toolbars.py 48 KB

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