toolbars.py 52 KB

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