toolbars.py 51 KB

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