toolbars.py 53 KB

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