toolbars.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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 grass
  22. import globalvar
  23. import gcmd
  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. # set default mouse settings
  534. self.parent.MapWindow.mouse['use'] = "pointer"
  535. self.parent.MapWindow.mouse['box'] = "point"
  536. self.parent.MapWindow.polycoords = []
  537. def OnMoveVertex(self, event):
  538. """Move line vertex"""
  539. Debug.msg(2, "Digittoolbar.OnMoveVertex():")
  540. self.action = { 'desc' : "moveVertex",
  541. 'id' : self.moveVertex }
  542. self.parent.MapWindow.mouse['box'] = 'point'
  543. def OnAddVertex(self, event):
  544. """Add line vertex"""
  545. Debug.msg(2, "Digittoolbar.OnAddVertex():")
  546. self.action = { 'desc' : "addVertex",
  547. 'id' : self.addVertex }
  548. self.parent.MapWindow.mouse['box'] = 'point'
  549. def OnRemoveVertex(self, event):
  550. """Remove line vertex"""
  551. Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
  552. self.action = { 'desc' : "removeVertex",
  553. 'id' : self.removeVertex }
  554. self.parent.MapWindow.mouse['box'] = 'point'
  555. def OnSplitLine(self, event):
  556. """Split line"""
  557. Debug.msg(2, "Digittoolbar.OnSplitLine():")
  558. self.action = { 'desc' : "splitLine",
  559. 'id' : self.splitLine }
  560. self.parent.MapWindow.mouse['box'] = 'point'
  561. def OnEditLine(self, event):
  562. """Edit line"""
  563. Debug.msg(2, "Digittoolbar.OnEditLine():")
  564. self.action = { 'desc' : "editLine",
  565. 'id' : self.editLine }
  566. self.parent.MapWindow.mouse['box'] = 'line'
  567. def OnMoveLine(self, event):
  568. """Move line"""
  569. Debug.msg(2, "Digittoolbar.OnMoveLine():")
  570. self.action = { 'desc' : "moveLine",
  571. 'id' : self.moveLine }
  572. self.parent.MapWindow.mouse['box'] = 'box'
  573. def OnDeleteLine(self, event):
  574. """Delete line"""
  575. Debug.msg(2, "Digittoolbar.OnDeleteLine():")
  576. self.action = { 'desc' : "deleteLine",
  577. 'id' : self.deleteLine }
  578. self.parent.MapWindow.mouse['box'] = 'box'
  579. def OnDisplayCats(self, event):
  580. """Display/update categories"""
  581. Debug.msg(2, "Digittoolbar.OnDisplayCats():")
  582. self.action = { 'desc' : "displayCats",
  583. 'id' : self.displayCats }
  584. self.parent.MapWindow.mouse['box'] = 'point'
  585. def OnDisplayAttr(self, event):
  586. """Display/update attributes"""
  587. Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
  588. self.action = { 'desc' : "displayAttrs",
  589. 'id' : self.displayAttr }
  590. self.parent.MapWindow.mouse['box'] = 'point'
  591. def OnCopyCA(self, event):
  592. """Copy categories/attributes menu"""
  593. point = wx.GetMousePosition()
  594. toolMenu = wx.Menu()
  595. # Add items to the menu
  596. cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  597. text=_('Copy categories'),
  598. kind=wx.ITEM_CHECK)
  599. toolMenu.AppendItem(cats)
  600. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
  601. if self.action['desc'] == "copyCats":
  602. cats.Check(True)
  603. attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  604. text=_('Duplicate attributes'),
  605. kind=wx.ITEM_CHECK)
  606. toolMenu.AppendItem(attrb)
  607. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
  608. if self.action['desc'] == "copyAttrs":
  609. attrb.Check(True)
  610. # Popup the menu. If an item is selected then its handler
  611. # will be called before PopupMenu returns.
  612. self.parent.MapWindow.PopupMenu(toolMenu)
  613. toolMenu.Destroy()
  614. if self.action['desc'] == "addPoint":
  615. self.toolbar[0].ToggleTool(self.copyCats, False)
  616. def OnCopyCats(self, event):
  617. """Copy categories"""
  618. if self.action['desc'] == 'copyCats': # select previous action
  619. self.toolbar[0].ToggleTool(self.addPoint, True)
  620. self.toolbar[0].ToggleTool(self.copyCats, False)
  621. self.OnAddPoint(event)
  622. return
  623. Debug.msg(2, "Digittoolbar.OnCopyCats():")
  624. self.action = { 'desc' : "copyCats",
  625. 'id' : self.copyCats }
  626. self.parent.MapWindow.mouse['box'] = 'point'
  627. def OnCopyAttrb(self, event):
  628. if self.action['desc'] == 'copyAttrs': # select previous action
  629. self.toolbar[0].ToggleTool(self.addPoint, True)
  630. self.toolbar[0].ToggleTool(self.copyCats, False)
  631. self.OnAddPoint(event)
  632. return
  633. Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
  634. self.action = { 'desc' : "copyAttrs",
  635. 'id' : self.copyCats }
  636. self.parent.MapWindow.mouse['box'] = 'point'
  637. def OnUndo(self, event):
  638. """Undo previous changes"""
  639. self.parent.digit.Undo()
  640. event.Skip()
  641. def EnableUndo(self, enable=True):
  642. """Enable 'Undo' in toolbar
  643. @param enable False for disable
  644. """
  645. if enable:
  646. if self.toolbar[0].GetToolEnabled(self.undo) is False:
  647. self.toolbar[0].EnableTool(self.undo, True)
  648. else:
  649. if self.toolbar[0].GetToolEnabled(self.undo) is True:
  650. self.toolbar[0].EnableTool(self.undo, False)
  651. def OnSettings(self, event):
  652. """Show settings dialog"""
  653. if self.parent.digit is None:
  654. reload(vdigit)
  655. from vdigit import Digit as Digit
  656. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  657. if not self.settingsDialog:
  658. self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
  659. style=wx.DEFAULT_DIALOG_STYLE)
  660. self.settingsDialog.Show()
  661. def OnAdditionalToolMenu(self, event):
  662. """Menu for additional tools"""
  663. point = wx.GetMousePosition()
  664. toolMenu = wx.Menu()
  665. # Add items to the menu
  666. copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  667. text=_('Copy features from (background) vector map'),
  668. kind=wx.ITEM_CHECK)
  669. toolMenu.AppendItem(copy)
  670. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
  671. if self.action['desc'] == "copyLine":
  672. copy.Check(True)
  673. flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  674. text=_('Flip selected lines/boundaries'),
  675. kind=wx.ITEM_CHECK)
  676. toolMenu.AppendItem(flip)
  677. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
  678. if self.action['desc'] == "flipLine":
  679. flip.Check(True)
  680. merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  681. text=_('Merge selected lines/boundaries'),
  682. kind=wx.ITEM_CHECK)
  683. toolMenu.AppendItem(merge)
  684. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
  685. if self.action['desc'] == "mergeLine":
  686. merge.Check(True)
  687. breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  688. text=_('Break selected lines/boundaries at intersection'),
  689. kind=wx.ITEM_CHECK)
  690. toolMenu.AppendItem(breakL)
  691. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
  692. if self.action['desc'] == "breakLine":
  693. breakL.Check(True)
  694. snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  695. text=_('Snap selected lines/boundaries (only to nodes)'),
  696. kind=wx.ITEM_CHECK)
  697. toolMenu.AppendItem(snap)
  698. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
  699. if self.action['desc'] == "snapLine":
  700. snap.Check(True)
  701. connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  702. text=_('Connect selected lines/boundaries'),
  703. kind=wx.ITEM_CHECK)
  704. toolMenu.AppendItem(connect)
  705. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
  706. if self.action['desc'] == "connectLine":
  707. connect.Check(True)
  708. query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  709. text=_('Query features'),
  710. kind=wx.ITEM_CHECK)
  711. toolMenu.AppendItem(query)
  712. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
  713. if self.action['desc'] == "queryLine":
  714. query.Check(True)
  715. zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  716. text=_('Z bulk-labeling of 3D lines'),
  717. kind=wx.ITEM_CHECK)
  718. toolMenu.AppendItem(zbulk)
  719. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
  720. if self.action['desc'] == "zbulkLine":
  721. zbulk.Check(True)
  722. typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
  723. text=_('Feature type conversion'),
  724. kind=wx.ITEM_CHECK)
  725. toolMenu.AppendItem(typeconv)
  726. self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
  727. if self.action['desc'] == "typeConv":
  728. typeconv.Check(True)
  729. # Popup the menu. If an item is selected then its handler
  730. # will be called before PopupMenu returns.
  731. self.parent.MapWindow.PopupMenu(toolMenu)
  732. toolMenu.Destroy()
  733. if self.action['desc'] == 'addPoint':
  734. self.toolbar[0].ToggleTool(self.additionalTools, False)
  735. def OnCopy(self, event):
  736. """Copy selected features from (background) vector map"""
  737. if self.action['desc'] == 'copyLine': # select previous action
  738. self.toolbar[0].ToggleTool(self.addPoint, True)
  739. self.toolbar[0].ToggleTool(self.additionalTools, False)
  740. self.OnAddPoint(event)
  741. return
  742. Debug.msg(2, "Digittoolbar.OnCopy():")
  743. self.action = { 'desc' : "copyLine",
  744. 'id' : self.additionalTools }
  745. self.parent.MapWindow.mouse['box'] = 'box'
  746. def OnFlip(self, event):
  747. """Flip selected lines/boundaries"""
  748. if self.action['desc'] == 'flipLine': # select previous action
  749. self.toolbar[0].ToggleTool(self.addPoint, True)
  750. self.toolbar[0].ToggleTool(self.additionalTools, False)
  751. self.OnAddPoint(event)
  752. return
  753. Debug.msg(2, "Digittoolbar.OnFlip():")
  754. self.action = { 'desc' : "flipLine",
  755. 'id' : self.additionalTools }
  756. self.parent.MapWindow.mouse['box'] = 'box'
  757. def OnMerge(self, event):
  758. """Merge selected lines/boundaries"""
  759. if self.action['desc'] == 'mergeLine': # select previous action
  760. self.toolbar[0].ToggleTool(self.addPoint, True)
  761. self.toolbar[0].ToggleTool(self.additionalTools, False)
  762. self.OnAddPoint(event)
  763. return
  764. Debug.msg(2, "Digittoolbar.OnMerge():")
  765. self.action = { 'desc' : "mergeLine",
  766. 'id' : self.additionalTools }
  767. self.parent.MapWindow.mouse['box'] = 'box'
  768. def OnBreak(self, event):
  769. """Break selected lines/boundaries"""
  770. if self.action['desc'] == 'breakLine': # select previous action
  771. self.toolbar[0].ToggleTool(self.addPoint, True)
  772. self.toolbar[0].ToggleTool(self.additionalTools, False)
  773. self.OnAddPoint(event)
  774. return
  775. Debug.msg(2, "Digittoolbar.OnBreak():")
  776. self.action = { 'desc' : "breakLine",
  777. 'id' : self.additionalTools }
  778. self.parent.MapWindow.mouse['box'] = 'box'
  779. def OnSnap(self, event):
  780. """Snap selected features"""
  781. if self.action['desc'] == 'snapLine': # select previous action
  782. self.toolbar[0].ToggleTool(self.addPoint, True)
  783. self.toolbar[0].ToggleTool(self.additionalTools, False)
  784. self.OnAddPoint(event)
  785. return
  786. Debug.msg(2, "Digittoolbar.OnSnap():")
  787. self.action = { 'desc' : "snapLine",
  788. 'id' : self.additionalTools }
  789. self.parent.MapWindow.mouse['box'] = 'box'
  790. def OnConnect(self, event):
  791. """Connect selected lines/boundaries"""
  792. if self.action['desc'] == 'connectLine': # select previous action
  793. self.toolbar[0].ToggleTool(self.addPoint, True)
  794. self.toolbar[0].ToggleTool(self.additionalTools, False)
  795. self.OnAddPoint(event)
  796. return
  797. Debug.msg(2, "Digittoolbar.OnConnect():")
  798. self.action = { 'desc' : "connectLine",
  799. 'id' : self.additionalTools }
  800. self.parent.MapWindow.mouse['box'] = 'box'
  801. def OnQuery(self, event):
  802. """Query selected lines/boundaries"""
  803. if self.action['desc'] == 'queryLine': # select previous action
  804. self.toolbar[0].ToggleTool(self.addPoint, True)
  805. self.toolbar[0].ToggleTool(self.additionalTools, False)
  806. self.OnAddPoint(event)
  807. return
  808. Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
  809. UserSettings.Get(group='vdigit', key='query', subkey='selection'))
  810. self.action = { 'desc' : "queryLine",
  811. 'id' : self.additionalTools }
  812. self.parent.MapWindow.mouse['box'] = 'box'
  813. def OnZBulk(self, event):
  814. """Z bulk-labeling selected lines/boundaries"""
  815. if self.action['desc'] == 'zbulkLine': # select previous action
  816. self.toolbar[0].ToggleTool(self.addPoint, True)
  817. self.toolbar[0].ToggleTool(self.additionalTools, False)
  818. self.OnAddPoint(event)
  819. return
  820. Debug.msg(2, "Digittoolbar.OnZBulk():")
  821. self.action = { 'desc' : "zbulkLine",
  822. 'id' : self.additionalTools }
  823. self.parent.MapWindow.mouse['box'] = 'line'
  824. def OnTypeConversion(self, event):
  825. """Feature type conversion
  826. Supported conversions:
  827. - point <-> centroid
  828. - line <-> boundary
  829. """
  830. if self.action['desc'] == 'typeConv': # select previous action
  831. self.toolbar[0].ToggleTool(self.addPoint, True)
  832. self.toolbar[0].ToggleTool(self.additionalTools, False)
  833. self.OnAddPoint(event)
  834. return
  835. Debug.msg(2, "Digittoolbar.OnTypeConversion():")
  836. self.action = { 'desc' : "typeConv",
  837. 'id' : self.additionalTools }
  838. self.parent.MapWindow.mouse['box'] = 'box'
  839. def OnSelectMap (self, event):
  840. """
  841. Select vector map layer for editing
  842. If there is a vector map layer already edited, this action is
  843. firstly terminated. The map layer is closed. After this the
  844. selected map layer activated for editing.
  845. """
  846. if event.GetSelection() == 0: # create new vector map layer
  847. if self.mapLayer:
  848. openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
  849. else:
  850. openVectorMap = None
  851. mapName = gdialogs.CreateNewVector(self.parent,
  852. exceptMap=openVectorMap, log=self.log,
  853. cmdDef=(['v.edit', 'tool=create'], "map"),
  854. disableAdd=True)[0]
  855. if mapName:
  856. # add layer to map layer tree
  857. if self.layerTree:
  858. self.layerTree.AddLayer(ltype='vector',
  859. lname=mapName,
  860. lchecked=True,
  861. lopacity=1.0,
  862. lcmd=['d.vect', 'map=%s' % mapName])
  863. vectLayers = self.UpdateListOfLayers(updateTool=True)
  864. selection = vectLayers.index(mapName)
  865. else:
  866. pass # TODO (no Layer Manager)
  867. else:
  868. self.combo.SetValue(_('Select vector map'))
  869. return
  870. else:
  871. selection = event.GetSelection() - 1 # first option is 'New vector map'
  872. # skip currently selected map
  873. if self.layers[selection] == self.mapLayer:
  874. return False
  875. if self.mapLayer:
  876. # deactive map layer for editing
  877. self.StopEditing()
  878. # select the given map layer for editing
  879. self.StartEditing(self.layers[selection])
  880. event.Skip()
  881. return True
  882. def StartEditing (self, mapLayer):
  883. """
  884. Start editing selected vector map layer.
  885. @param mapLayer reference to MapLayer instance
  886. """
  887. # deactive layer
  888. self.mapcontent.ChangeLayerActive(mapLayer, False)
  889. # clean map canvas
  890. ### self.parent.MapWindow.EraseMap()
  891. # unset background map if needed
  892. if UserSettings.Get(group='vdigit', key='bgmap',
  893. subkey='value', internal=True) == mapLayer.GetName():
  894. UserSettings.Set(group='vdigit', key='bgmap',
  895. subkey='value', value='', internal=True)
  896. self.parent.statusbar.SetStatusText(_("Please wait, "
  897. "opening vector map <%s> for editing...") % \
  898. mapLayer.GetName(),
  899. 0)
  900. # reload vdigit module
  901. reload(vdigit)
  902. from vdigit import Digit as Digit
  903. self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
  904. self.mapLayer = mapLayer
  905. # open vector map
  906. try:
  907. self.parent.digit.SetMapName(mapLayer.GetName())
  908. except gcmd.DigitError, e:
  909. self.mapLayer = None
  910. print >> sys.stderr, e # wxMessageBox
  911. return False
  912. # update toolbar
  913. self.combo.SetValue(mapLayer.GetName())
  914. self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
  915. Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
  916. # change cursor
  917. if self.parent.MapWindow.mouse['use'] == 'pointer':
  918. self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
  919. # create pseudoDC for drawing the map
  920. self.parent.MapWindow.pdcVector = wx.PseudoDC()
  921. self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
  922. if not self.parent.MapWindow.resize:
  923. self.parent.MapWindow.UpdateMap(render=True)
  924. opacity = mapLayer.GetOpacity(float=True)
  925. if opacity < 1.0:
  926. alpha = int(opacity * 255)
  927. self.parent.digit.driver.UpdateSettings(alpha)
  928. return True
  929. def StopEditing (self):
  930. """Stop editing of selected vector map layer.
  931. @return True on success
  932. @return False on failure
  933. """
  934. if not self.mapLayer:
  935. return False
  936. Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
  937. self.combo.SetValue (_('Select vector map'))
  938. # save changes
  939. if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
  940. if self.parent.digit.GetUndoLevel() > 0:
  941. dlg = wx.MessageDialog(parent=self.parent,
  942. message=_("Do you want to save changes "
  943. "in vector map <%s>?") % self.mapLayer.GetName(),
  944. caption=_("Save changes?"),
  945. style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
  946. if dlg.ShowModal() == wx.ID_NO:
  947. # revert changes
  948. self.parent.digit.Undo(0)
  949. dlg.Destroy()
  950. self.parent.statusbar.SetStatusText(_("Please wait, "
  951. "closing and rebuilding topology of "
  952. "vector map <%s>...") % self.mapLayer.GetName(),
  953. 0)
  954. self.parent.digit.SetMapName(None) # -> close map
  955. # re-active layer
  956. item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
  957. if item and self.parent.tree.IsItemChecked(item):
  958. self.mapcontent.ChangeLayerActive(self.mapLayer, True)
  959. # change cursor
  960. self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
  961. # disable pseudodc for vector map layer
  962. self.parent.MapWindow.pdcVector = None
  963. self.parent.digit.driver.SetDevice(None)
  964. # close dialogs
  965. for dialog in ('attributes', 'category'):
  966. if self.parent.dialogs[dialog]:
  967. self.parent.dialogs[dialog].Close()
  968. self.parent.dialogs[dialog] = None
  969. self.parent.digit.__del__() # FIXME: destructor is not called here (del)
  970. self.parent.digit = None
  971. self.mapLayer = None
  972. return True
  973. def UpdateListOfLayers (self, updateTool=False):
  974. """
  975. Update list of available vector map layers.
  976. This list consists only editable layers (in the current mapset)
  977. Optionally also update toolbar
  978. """
  979. Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
  980. updateTool)
  981. layerNameSelected = None
  982. # name of currently selected layer
  983. if self.mapLayer:
  984. layerNameSelected = self.mapLayer.GetName()
  985. # select vector map layer in the current mapset
  986. layerNameList = []
  987. self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
  988. l_mapset=grass.gisenv()['MAPSET'])
  989. for layer in self.layers:
  990. if not layer.name in layerNameList: # do not duplicate layer
  991. layerNameList.append (layer.GetName())
  992. if updateTool: # update toolbar
  993. if not self.mapLayer:
  994. value = _('Select vector map')
  995. else:
  996. value = layerNameSelected
  997. if not self.comboid:
  998. self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
  999. choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
  1000. style=wx.CB_READONLY)
  1001. self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
  1002. self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
  1003. else:
  1004. self.combo.SetItems([_('New vector map'), ] + layerNameList)
  1005. self.toolbar[self.numOfRows-1].Realize()
  1006. return layerNameList
  1007. def GetLayer(self):
  1008. """Get selected layer for editing -- MapLayer instance"""
  1009. return self.mapLayer
  1010. class ProfileToolbar(AbstractToolbar):
  1011. """
  1012. Toolbar for profiling raster map
  1013. """
  1014. def __init__(self, parent, tbframe):
  1015. self.parent = parent # GCP
  1016. self.tbframe = tbframe
  1017. self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
  1018. # self.SetToolBar(self.toolbar)
  1019. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1020. self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
  1021. # realize the toolbar
  1022. self.toolbar.Realize()
  1023. def ToolbarData(self):
  1024. """Toolbar data"""
  1025. self.transect = wx.NewId()
  1026. self.addraster = wx.NewId()
  1027. self.draw = wx.NewId()
  1028. self.options = wx.NewId()
  1029. self.drag = wx.NewId()
  1030. self.zoom = wx.NewId()
  1031. self.unzoom = wx.NewId()
  1032. self.erase = wx.NewId()
  1033. self.save = wx.NewId()
  1034. self.printer = wx.NewId()
  1035. self.quit = wx.NewId()
  1036. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1037. return (
  1038. (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
  1039. wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
  1040. self.parent.OnSelectRaster),
  1041. (self.transect, 'transect', Icons["transect"].GetBitmap(),
  1042. wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
  1043. self.parent.OnDrawTransect),
  1044. (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
  1045. wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
  1046. self.parent.OnCreateProfile),
  1047. (self.options, 'options', Icons["profileopt"].GetBitmap(),
  1048. wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
  1049. self.parent.ProfileOptionsMenu),
  1050. (self.drag, 'drag', Icons['pan'].GetBitmap(),
  1051. wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
  1052. self.parent.OnDrag),
  1053. (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
  1054. wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
  1055. self.parent.OnZoom),
  1056. (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
  1057. wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
  1058. self.parent.OnRedraw),
  1059. (self.erase, 'erase', Icons["erase"].GetBitmap(),
  1060. wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
  1061. self.parent.OnErase),
  1062. ("", "", "", "", "", "", ""),
  1063. (self.save, 'save', Icons["savefile"].GetBitmap(),
  1064. wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
  1065. self.parent.SaveToFile),
  1066. (self.printer, 'print', Icons["printmap"].GetBitmap(),
  1067. wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
  1068. self.parent.PrintMenu),
  1069. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1070. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1071. self.parent.OnQuit),
  1072. )
  1073. class NvizToolbar(AbstractToolbar):
  1074. """
  1075. Nviz toolbar
  1076. """
  1077. def __init__(self, parent, map):
  1078. self.parent = parent
  1079. self.mapcontent = map
  1080. self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
  1081. # self.SetToolBar(self.toolbar)
  1082. self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
  1083. self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
  1084. # realize the toolbar
  1085. self.toolbar.Realize()
  1086. def ToolbarData(self):
  1087. """Toolbar data"""
  1088. self.settings = wx.NewId()
  1089. self.quit = wx.NewId()
  1090. # tool, label, bitmap, kind, shortHelp, longHelp, handler
  1091. return (
  1092. (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
  1093. wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
  1094. self.OnSettings),
  1095. (self.quit, 'quit', Icons["quit"].GetBitmap(),
  1096. wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
  1097. self.OnExit),
  1098. )
  1099. def OnSettings(self, event):
  1100. win = self.parent.nvizToolWin
  1101. if not win.IsShown():
  1102. self.parent.nvizToolWin.Show()
  1103. else:
  1104. self.parent.nvizToolWin.Hide()
  1105. def OnExit (self, event=None):
  1106. """Quit nviz tool (swith to 2D mode)"""
  1107. # disable the toolbar
  1108. self.parent.RemoveToolbar ("nviz")