toolbars.py 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  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, "query", Icons["query"].GetBitmap(),
  156. wx.ITEM_CHECK, Icons["query"].GetLabel(), Icons["query"].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. def ToolbarData(self, row=None):
  366. """
  367. Toolbar data
  368. """
  369. data = []
  370. if row is None or row == 0:
  371. self.addPoint = wx.NewId()
  372. self.addLine = wx.NewId()
  373. self.addBoundary = wx.NewId()
  374. self.addCentroid = wx.NewId()
  375. self.moveVertex = wx.NewId()
  376. self.addVertex = wx.NewId()
  377. self.removeVertex = wx.NewId()
  378. self.splitLine = wx.NewId()
  379. self.editLine = wx.NewId()
  380. self.moveLine = wx.NewId()
  381. self.deleteLine = wx.NewId()
  382. self.additionalTools = wx.NewId()
  383. self.displayCats = wx.NewId()
  384. self.displayAttr = wx.NewId()
  385. self.copyCats = wx.NewId()
  386. data = [("", "", "", "", "", "", ""),
  387. (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
  388. wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
  389. self.OnAddPoint),
  390. (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
  391. wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
  392. self.OnAddLine),
  393. (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
  394. wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
  395. self.OnAddBoundary),
  396. (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
  397. wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
  398. self.OnAddCentroid),
  399. (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
  400. wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
  401. self.OnMoveVertex),
  402. (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
  403. wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
  404. self.OnAddVertex),
  405. (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
  406. wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
  407. self.OnRemoveVertex),
  408. (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
  409. wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
  410. self.OnSplitLine),
  411. (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
  412. wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
  413. self.OnEditLine),
  414. (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
  415. wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
  416. self.OnMoveLine),
  417. (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
  418. wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
  419. self.OnDeleteLine),
  420. (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
  421. wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
  422. self.OnDisplayCats),
  423. (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
  424. wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
  425. self.OnCopyCA),
  426. (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
  427. wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
  428. self.OnDisplayAttr),
  429. (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
  430. wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
  431. Icons["digAdditionalTools"].GetDesc(),
  432. self.OnAdditionalToolMenu)]
  433. if row is None or row == 1:
  434. self.undo = wx.NewId()
  435. self.settings = wx.NewId()
  436. self.exit = wx.NewId()
  437. data.append(("", "", "", "", "", "", ""))
  438. data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
  439. wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
  440. self.OnUndo))
  441. # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
  442. # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
  443. # self.OnRedo))
  444. data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
  445. wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
  446. self.OnSettings))
  447. data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
  448. wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
  449. self.OnExit))
  450. return data
  451. def OnTool(self, event):
  452. """Tool selected -> toggle tool to pointer"""
  453. id = self.parent.toolbars['map'].pointer
  454. self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
  455. self.parent.toolbars['map'].mapdisplay.OnPointer(event)
  456. if event:
  457. # deselect previously selected tool
  458. id = self.action.get('id', -1)
  459. if id != event.GetId():
  460. self.toolbar[0].ToggleTool(self.action['id'], False)
  461. else:
  462. self.toolbar[0].ToggleTool(self.action['id'], True)
  463. self.action['id'] = event.GetId()
  464. event.Skip()
  465. else:
  466. # initialize toolbar
  467. self.toolbar[0].ToggleTool(self.action['id'], True)
  468. def OnAddPoint(self, event):
  469. """Add point to the vector map Laier"""
  470. Debug.msg (2, "VDigitToolbar.OnAddPoint()")
  471. self.action = { 'desc' : "addLine",
  472. 'type' : "point",
  473. 'id' : self.addPoint }
  474. self.parent.MapWindow.mouse['box'] = 'point'
  475. def OnAddLine(self, event):
  476. """Add line to the vector map layer"""
  477. Debug.msg (2, "VDigitToolbar.OnAddLine()")
  478. self.action = { 'desc' : "addLine",
  479. 'type' : "line",
  480. 'id' : self.addLine }
  481. self.parent.MapWindow.mouse['box'] = 'line'
  482. self.parent.MapWindow.polycoords = [] # reset temp line
  483. def OnAddBoundary(self, event):
  484. """Add boundary to the vector map layer"""
  485. Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
  486. self.action = { 'desc' : "addLine",
  487. 'type' : "boundary",
  488. 'id' : self.addBoundary }
  489. self.parent.MapWindow.mouse['box'] = 'line'
  490. self.parent.MapWindow.polycoords = [] # reset temp line
  491. def OnAddCentroid(self, event):
  492. """Add centroid to the vector map layer"""
  493. Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
  494. self.action = { 'desc' : "addLine",
  495. 'type' : "centroid",
  496. 'id' : self.addCentroid }
  497. self.parent.MapWindow.mouse['box'] = 'point'
  498. def OnExit (self, event=None):
  499. """Quit digitization tool"""
  500. # stop editing of the currently selected map layer
  501. if self.mapLayer:
  502. self.StopEditing()
  503. # close dialogs if still open
  504. if self.settingsDialog:
  505. self.settingsDialog.OnCancel(None)
  506. if self.parent.dialogs['category']:
  507. self.parent.dialogs['category'].OnCancel(None)
  508. if self.parent.dialogs['attributes']:
  509. self.parent.dialogs['attributes'].OnCancel(None)
  510. # disable the toolbar
  511. self.parent.RemoveToolbar ("vdigit")
  512. def OnMoveVertex(self, event):
  513. """Move line vertex"""
  514. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  515. self.action = { 'desc' : "moveVertex",
  516. 'id' : self.moveVertex }
  517. self.parent.MapWindow.mouse['box'] = 'point'
  518. def OnAddVertex(self, event):
  519. """Add line vertex"""
  520. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  521. self.action = { 'desc' : "addVertex",
  522. 'id' : self.addVertex }
  523. self.parent.MapWindow.mouse['box'] = 'point'
  524. def OnRemoveVertex(self, event):
  525. """Remove line vertex"""
  526. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  527. self.action = { 'desc' : "removeVertex",
  528. 'id' : self.removeVertex }
  529. self.parent.MapWindow.mouse['box'] = 'point'
  530. def OnSplitLine(self, event):
  531. """Split line"""
  532. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  533. self.action = { 'desc' : "splitLine",
  534. 'id' : self.splitLine }
  535. self.parent.MapWindow.mouse['box'] = 'point'
  536. def OnEditLine(self, event):
  537. """Edit line"""
  538. Debug.msg(2, "Digittoolbar.OnEditLine():")
  539. self.action = { 'desc' : "editLine",
  540. 'id' : self.editLine }
  541. self.parent.MapWindow.mouse['box'] = 'line'
  542. def OnMoveLine(self, event):
  543. """Move line"""
  544. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  545. self.action = { 'desc' : "moveLine",
  546. 'id' : self.moveLine }
  547. self.parent.MapWindow.mouse['box'] = 'box'
  548. def OnDeleteLine(self, event):
  549. """Delete line"""
  550. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  551. self.action = { 'desc' : "deleteLine",
  552. 'id' : self.deleteLine }
  553. self.parent.MapWindow.mouse['box'] = 'box'
  554. def OnDisplayCats(self, event):
  555. """Display/update categories"""
  556. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  557. self.action = { 'desc' : "displayCats",
  558. 'id' : self.displayCats }
  559. self.parent.MapWindow.mouse['box'] = 'point'
  560. def OnDisplayAttr(self, event):
  561. """Display/update attributes"""
  562. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  563. self.action = { 'desc' : "displayAttrs",
  564. 'id' : self.displayAttr }
  565. self.parent.MapWindow.mouse['box'] = 'point'
  566. def OnCopyCA(self, event):
  567. """Copy categories/attributes menu"""
  568. point = wx.GetMousePosition()
  569. toolMenu = wx.Menu()
  570. # Add items to the menu
  571. cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  572. text=_('Copy categories'),
  573. kind=wx.ITEM_CHECK)
  574. toolMenu.AppendItem(cats)
  575. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  576. if self.action['desc'] == "copyCats":
  577. cats.Check(True)
  578. attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  579. text=_('Duplicate attributes'),
  580. kind=wx.ITEM_CHECK)
  581. toolMenu.AppendItem(attrb)
  582. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
  583. attrb.Enable(False) # Not implemeneted for vedit
  584. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  585. if self.action['desc'] == "copyAttrs":
  586. attrb.Check(True)
  587. # Popup the menu. If an item is selected then its handler
  588. # will be called before PopupMenu returns.
  589. self.parent.MapWindow.PopupMenu(toolMenu)
  590. toolMenu.Destroy()
  591. if self.action['desc'] == "addPoint":
  592. self.toolbar[0].ToggleTool(self.copyCats, False)
  593. def OnCopyCats(self, event):
  594. """Copy categories"""
  595. if self.action['desc'] == 'copyCats': # select previous action
  596. self.toolbar[0].ToggleTool(self.addPoint, True)
  597. self.toolbar[0].ToggleTool(self.copyCats, False)
  598. self.OnAddPoint(event)
  599. return
  600. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  601. self.action = { 'desc' : "copyCats",
  602. 'id' : self.copyCats }
  603. self.parent.MapWindow.mouse['box'] = 'point'
  604. def OnCopyAttrb(self, event):
  605. if self.action['desc'] == 'copyAttrs': # select previous action
  606. self.toolbar[0].ToggleTool(self.addPoint, True)
  607. self.toolbar[0].ToggleTool(self.copyCats, False)
  608. self.OnAddPoint(event)
  609. return
  610. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  611. self.action = { 'desc' : "copyAttrs",
  612. 'id' : self.copyCats }
  613. self.parent.MapWindow.mouse['box'] = 'point'
  614. def OnUndo(self, event):
  615. """Undo previous changes"""
  616. self.parent.digit.Undo()
  617. event.Skip()
  618. def EnableUndo(self, enable=True):
  619. """Enable 'Undo' in toolbar
  620. @param enable False for disable
  621. """
  622. ### fix undo first...
  623. # if enable:
  624. # if self.toolbar[0].GetToolEnabled(self.undo) is False:
  625. # self.toolbar[0].EnableTool(self.undo, True)
  626. # else:
  627. # if self.toolbar[0].GetToolEnabled(self.undo) is True:
  628. # self.toolbar[0].EnableTool(self.undo, False)
  629. pass
  630. def OnSettings(self, event):
  631. """Show settings dialog"""
  632. if self.parent.digit is None:
  633. reload(vdigit)
  634. from vdigit import Digit as Digit
  635. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  636. if not self.settingsDialog:
  637. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  638. style=wx.DEFAULT_DIALOG_STYLE)
  639. self.settingsDialog.Show()
  640. def OnAdditionalToolMenu(self, event):
  641. """Menu for additional tools"""
  642. point = wx.GetMousePosition()
  643. toolMenu = wx.Menu()
  644. # Add items to the menu
  645. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  646. text=_('Copy features from (background) vector map'),
  647. kind=wx.ITEM_CHECK)
  648. toolMenu.AppendItem(copy)
  649. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  650. if self.action['desc'] == "copyLine":
  651. copy.Check(True)
  652. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  653. text=_('Flip selected lines/boundaries'),
  654. kind=wx.ITEM_CHECK)
  655. toolMenu.AppendItem(flip)
  656. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  657. if self.action['desc'] == "flipLine":
  658. flip.Check(True)
  659. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  660. text=_('Merge selected lines/boundaries'),
  661. kind=wx.ITEM_CHECK)
  662. toolMenu.AppendItem(merge)
  663. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  664. if self.action['desc'] == "mergeLine":
  665. merge.Check(True)
  666. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  667. text=_('Break selected lines/boundaries at intersection'),
  668. kind=wx.ITEM_CHECK)
  669. toolMenu.AppendItem(breakL)
  670. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  671. if self.action['desc'] == "breakLine":
  672. breakL.Check(True)
  673. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  674. text=_('Snap selected lines/boundaries (only to nodes)'),
  675. kind=wx.ITEM_CHECK)
  676. toolMenu.AppendItem(snap)
  677. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  678. if self.action['desc'] == "snapLine":
  679. snap.Check(True)
  680. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  681. text=_('Connect selected lines/boundaries'),
  682. kind=wx.ITEM_CHECK)
  683. toolMenu.AppendItem(connect)
  684. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  685. if self.action['desc'] == "connectLine":
  686. connect.Check(True)
  687. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  688. text=_('Query features'),
  689. kind=wx.ITEM_CHECK)
  690. toolMenu.AppendItem(query)
  691. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  692. if self.action['desc'] == "queryLine":
  693. query.Check(True)
  694. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  695. text=_('Z bulk-labeling of 3D lines'),
  696. kind=wx.ITEM_CHECK)
  697. toolMenu.AppendItem(zbulk)
  698. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  699. if self.action['desc'] == "zbulkLine":
  700. zbulk.Check(True)
  701. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  702. text=_('Feature type conversion'),
  703. kind=wx.ITEM_CHECK)
  704. toolMenu.AppendItem(typeconv)
  705. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  706. if self.action['desc'] == "typeConv":
  707. typeconv.Check(True)
  708. # Popup the menu. If an item is selected then its handler
  709. # will be called before PopupMenu returns.
  710. self.parent.MapWindow.PopupMenu(toolMenu)
  711. toolMenu.Destroy()
  712. if self.action['desc'] == 'addPoint':
  713. self.toolbar[0].ToggleTool(self.additionalTools, False)
  714. def OnCopy(self, event):
  715. """Copy selected features from (background) vector map"""
  716. if self.action['desc'] == 'copyLine': # select previous action
  717. self.toolbar[0].ToggleTool(self.addPoint, True)
  718. self.toolbar[0].ToggleTool(self.additionalTools, False)
  719. self.OnAddPoint(event)
  720. return
  721. Debug.msg(2, "Digittoolbar.OnCopy():")
  722. self.action = { 'desc' : "copyLine",
  723. 'id' : self.additionalTools }
  724. self.parent.MapWindow.mouse['box'] = 'box'
  725. def OnFlip(self, event):
  726. """Flip selected lines/boundaries"""
  727. if self.action['desc'] == 'flipLine': # select previous action
  728. self.toolbar[0].ToggleTool(self.addPoint, True)
  729. self.toolbar[0].ToggleTool(self.additionalTools, False)
  730. self.OnAddPoint(event)
  731. return
  732. Debug.msg(2, "Digittoolbar.OnFlip():")
  733. self.action = { 'desc' : "flipLine",
  734. 'id' : self.additionalTools }
  735. self.parent.MapWindow.mouse['box'] = 'box'
  736. def OnMerge(self, event):
  737. """Merge selected lines/boundaries"""
  738. if self.action['desc'] == 'mergeLine': # select previous action
  739. self.toolbar[0].ToggleTool(self.addPoint, True)
  740. self.toolbar[0].ToggleTool(self.additionalTools, False)
  741. self.OnAddPoint(event)
  742. return
  743. Debug.msg(2, "Digittoolbar.OnMerge():")
  744. self.action = { 'desc' : "mergeLine",
  745. 'id' : self.additionalTools }
  746. self.parent.MapWindow.mouse['box'] = 'box'
  747. def OnBreak(self, event):
  748. """Break selected lines/boundaries"""
  749. if self.action['desc'] == 'breakLine': # select previous action
  750. self.toolbar[0].ToggleTool(self.addPoint, True)
  751. self.toolbar[0].ToggleTool(self.additionalTools, False)
  752. self.OnAddPoint(event)
  753. return
  754. Debug.msg(2, "Digittoolbar.OnBreak():")
  755. self.action = { 'desc' : "breakLine",
  756. 'id' : self.additionalTools }
  757. self.parent.MapWindow.mouse['box'] = 'box'
  758. def OnSnap(self, event):
  759. """Snap selected features"""
  760. if self.action['desc'] == 'snapLine': # select previous action
  761. self.toolbar[0].ToggleTool(self.addPoint, True)
  762. self.toolbar[0].ToggleTool(self.additionalTools, False)
  763. self.OnAddPoint(event)
  764. return
  765. Debug.msg(2, "Digittoolbar.OnSnap():")
  766. self.action = { 'desc' : "snapLine",
  767. 'id' : self.additionalTools }
  768. self.parent.MapWindow.mouse['box'] = 'box'
  769. def OnConnect(self, event):
  770. """Connect selected lines/boundaries"""
  771. if self.action['desc'] == 'connectLine': # select previous action
  772. self.toolbar[0].ToggleTool(self.addPoint, True)
  773. self.toolbar[0].ToggleTool(self.additionalTools, False)
  774. self.OnAddPoint(event)
  775. return
  776. Debug.msg(2, "Digittoolbar.OnConnect():")
  777. self.action = { 'desc' : "connectLine",
  778. 'id' : self.additionalTools }
  779. self.parent.MapWindow.mouse['box'] = 'box'
  780. def OnQuery(self, event):
  781. """Query selected lines/boundaries"""
  782. if self.action['desc'] == 'queryLine': # select previous action
  783. self.toolbar[0].ToggleTool(self.addPoint, True)
  784. self.toolbar[0].ToggleTool(self.additionalTools, False)
  785. self.OnAddPoint(event)
  786. return
  787. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  788. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  789. self.action = { 'desc' : "queryLine",
  790. 'id' : self.additionalTools }
  791. self.parent.MapWindow.mouse['box'] = 'box'
  792. def OnZBulk(self, event):
  793. """Z bulk-labeling selected lines/boundaries"""
  794. if self.action['desc'] == 'zbulkLine': # select previous action
  795. self.toolbar[0].ToggleTool(self.addPoint, True)
  796. self.toolbar[0].ToggleTool(self.additionalTools, False)
  797. self.OnAddPoint(event)
  798. return
  799. Debug.msg(2, "Digittoolbar.OnZBulk():")
  800. self.action = { 'desc' : "zbulkLine",
  801. 'id' : self.additionalTools }
  802. self.parent.MapWindow.mouse['box'] = 'line'
  803. def OnTypeConversion(self, event):
  804. """Feature type conversion
  805. Supported conversions:
  806. - point <-> centroid
  807. - line <-> boundary
  808. """
  809. if self.action['desc'] == 'typeConv': # select previous action
  810. self.toolbar[0].ToggleTool(self.addPoint, True)
  811. self.toolbar[0].ToggleTool(self.additionalTools, False)
  812. self.OnAddPoint(event)
  813. return
  814. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  815. self.action = { 'desc' : "typeConv",
  816. 'id' : self.additionalTools }
  817. self.parent.MapWindow.mouse['box'] = 'box'
  818. def OnSelectMap (self, event):
  819. """
  820. Select vector map layer for editing
  821. If there is a vector map layer already edited, this action is
  822. firstly terminated. The map layer is closed. After this the
  823. selected map layer activated for editing.
  824. """
  825. if event.GetSelection() == 0: # create new vector map layer
  826. if self.mapLayer:
  827. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  828. else:
  829. openVectorMap = None
  830. mapName = gdialogs.CreateNewVector(self.parent,
  831. exceptMap=openVectorMap, log=self.log,
  832. cmdDef=(['v.edit', 'tool=create'], "map"))
  833. if mapName:
  834. # add layer to map layer tree
  835. if self.layerTree:
  836. self.layerTree.AddLayer(ltype='vector',
  837. lname=mapName,
  838. lchecked=True,
  839. lopacity=1.0,
  840. lcmd=['d.vect', 'map=%s' % mapName])
  841. vectLayers = self.UpdateListOfLayers(updateTool=True)
  842. selection = vectLayers.index(mapName)
  843. else:
  844. pass # TODO (no Layer Manager)
  845. else:
  846. self.combo.SetValue(_('Select vector map'))
  847. return
  848. else:
  849. selection = event.GetSelection() - 1 # first option is 'New vector map'
  850. # skip currently selected map
  851. if self.layers[selection] == self.mapLayer:
  852. return False
  853. if self.mapLayer:
  854. # deactive map layer for editing
  855. self.StopEditing()
  856. # select the given map layer for editing
  857. self.StartEditing(self.layers[selection])
  858. event.Skip()
  859. return True
  860. def StartEditing (self, mapLayer):
  861. """
  862. Start editing selected vector map layer.
  863. @param mapLayer reference to MapLayer instance
  864. """
  865. # reload vdigit module
  866. reload(vdigit)
  867. from vdigit import Digit as Digit
  868. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  869. self.mapLayer = mapLayer
  870. # open vector map
  871. try:
  872. self.parent.digit.SetMapName(mapLayer.GetName())
  873. except gcmd.DigitError, e:
  874. self.mapLayer = None
  875. print >> sys.stderr, e # wxMessageBox
  876. return False
  877. # update toolbar
  878. self.combo.SetValue(mapLayer.GetName())
  879. self.parent.toolbars['map'].combo.SetValue ('Digitize')
  880. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  881. # deactive layer
  882. self.mapcontent.ChangeLayerActive(mapLayer, False)
  883. # change cursor
  884. if self.parent.MapWindow.mouse['use'] == 'pointer':
  885. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  886. # create pseudoDC for drawing the map
  887. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  888. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  889. # self.parent.MapWindow.UpdateMap()
  890. if not self.parent.MapWindow.resize:
  891. self.parent.MapWindow.UpdateMap(render=True)
  892. return True
  893. def StopEditing (self):
  894. """Stop editing of selected vector map layer.
  895. @return True on success
  896. @return False on failure
  897. """
  898. if not self.mapLayer:
  899. return False
  900. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  901. self.combo.SetValue (_('Select vector map'))
  902. # save changes (only for vdigit)
  903. if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
  904. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  905. if self.parent.digit.GetUndoLevel() > 0:
  906. dlg = wx.MessageDialog(parent=self.parent, message=_("Do you want to save changes "
  907. "in vector map <%s>?") % self.mapLayer.GetName(),
  908. caption=_("Save changes?"),
  909. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  910. if dlg.ShowModal() == wx.ID_NO:
  911. # revert changes
  912. self.parent.digit.Undo(0)
  913. dlg.Destroy()
  914. self.parent.digit.SetMapName(None) # -> close map
  915. # re-active layer
  916. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  917. if item and self.parent.tree.IsItemChecked(item):
  918. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  919. # change cursor
  920. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  921. # disable pseudodc for vector map layer
  922. self.parent.MapWindow.pdcVector = None
  923. self.parent.digit.driver.SetDevice(None)
  924. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  925. self.parent.digit = None
  926. self.mapLayer = None
  927. return True
  928. def UpdateListOfLayers (self, updateTool=False):
  929. """
  930. Update list of available vector map layers.
  931. This list consists only editable layers (in the current mapset)
  932. Optionaly also update toolbar
  933. """
  934. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  935. updateTool)
  936. layerNameSelected = None
  937. # name of currently selected layer
  938. if self.mapLayer:
  939. layerNameSelected = self.mapLayer.GetName()
  940. # select vector map layer in the current mapset
  941. layerNameList = []
  942. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  943. l_mapset=grassenv.GetGRASSVariable('MAPSET'))
  944. for layer in self.layers:
  945. if not layer.name in layerNameList: # do not duplicate layer
  946. layerNameList.append (layer.GetName())
  947. if updateTool: # update toolbar
  948. if not self.mapLayer:
  949. value = _('Select vector map')
  950. else:
  951. value = layerNameSelected
  952. if not self.comboid:
  953. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  954. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  955. style=wx.CB_READONLY)
  956. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  957. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  958. else:
  959. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  960. self.toolbar[self.numOfRows-1].Realize()
  961. return layerNameList
  962. def GetLayer(self):
  963. """Get selected layer for editing -- MapLayer instance"""
  964. return self.mapLayer
  965. class ProfileToolbar(AbstractToolbar):
  966. """
  967. Toolbar for profiling raster map
  968. """
  969. def __init__(self, parent, tbframe):
  970. self.parent = parent # GCP
  971. self.tbframe = tbframe
  972. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  973. # self.SetToolBar(self.toolbar)
  974. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  975. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  976. # realize the toolbar
  977. self.toolbar.Realize()
  978. def ToolbarData(self):
  979. """Toolbar data"""
  980. self.transect = wx.NewId()
  981. self.addraster = wx.NewId()
  982. self.draw = wx.NewId()
  983. self.options = wx.NewId()
  984. self.drag = wx.NewId()
  985. self.zoom = wx.NewId()
  986. self.unzoom = wx.NewId()
  987. self.erase = wx.NewId()
  988. self.save = wx.NewId()
  989. self.printer = wx.NewId()
  990. self.quit = wx.NewId()
  991. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  992. return (
  993. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  994. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  995. self.parent.OnDrawTransect),
  996. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  997. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  998. self.parent.OnSelectRaster),
  999. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1000. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1001. self.parent.OnCreateProfile),
  1002. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1003. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1004. self.parent.ProfileOptionsMenu),
  1005. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1006. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1007. self.parent.OnDrag),
  1008. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1009. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1010. self.parent.OnZoom),
  1011. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1012. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1013. self.parent.OnRedraw),
  1014. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1015. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1016. self.parent.OnErase),
  1017. ("", "", "", "", "", "", ""),
  1018. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1019. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1020. self.parent.SaveToFile),
  1021. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1022. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1023. self.parent.PrintMenu),
  1024. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1025. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1026. self.parent.OnQuit),
  1027. )
  1028. class NvizToolbar(AbstractToolbar):
  1029. """
  1030. Nviz toolbar
  1031. """
  1032. def __init__(self, parent, map):
  1033. self.parent = parent
  1034. self.mapcontent = map
  1035. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  1036. # self.SetToolBar(self.toolbar)
  1037. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1038. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  1039. # realize the toolbar
  1040. self.toolbar.Realize()
  1041. def ToolbarData(self):
  1042. """Toolbar data"""
  1043. self.settings = wx.NewId()
  1044. self.quit = wx.NewId()
  1045. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1046. return (
  1047. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1048. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1049. self.OnSettings),
  1050. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1051. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1052. self.OnExit),
  1053. )
  1054. def OnSettings(self, event):
  1055. win = self.parent.nvizToolWin
  1056. if not win.IsShown():
  1057. self.parent.nvizToolWin.Show()
  1058. else:
  1059. self.parent.nvizToolWin.Hide()
  1060. def OnExit (self, event=None):
  1061. """Quit nviz tool (swith to 2D mode)"""
  1062. # disable the toolbar
  1063. self.parent.RemoveToolbar ("nviz")